10 #include "llvm/ADT/SmallString.h"
12 using namespace circt;
16 if (!parser.parseOptionalKeyword(
"name")) {
18 if (parser.parseString(&str))
20 attr = parser.getBuilder().getStringAttr(str);
25 auto resultName = parser.getResultName(0).first;
26 if (!resultName.empty() &&
isdigit(resultName[0]))
28 attr = parser.getBuilder().getStringAttr(resultName);
33 NamedAttrList &attrs) {
34 if (parser.parseOptionalAttrDict(attrs))
42 if (attrs.get(
"name"))
46 auto resultName = parser.getResultName(0).first;
47 if (!resultName.empty() &&
isdigit(resultName[0]))
49 auto nameAttr = parser.getBuilder().getStringAttr(resultName);
50 auto *context = parser.getBuilder().getContext();
57 SmallString<32> resultNameStr;
58 llvm::raw_svector_ostream tmpStream(resultNameStr);
59 printer.printOperand(op->getResult(0), tmpStream);
60 auto actualName = tmpStream.str().drop_front();
64 auto expectedName = attr.getValue();
66 if (actualName == expectedName ||
67 (expectedName.empty() &&
isdigit(actualName[0])))
70 printer <<
" name " << attr;
75 ArrayRef<StringRef> extraElides) {
76 SmallVector<StringRef, 2> elides(extraElides.begin(), extraElides.end());
78 printer.printOptionalAttrDict(attrs.getValue(), elides);
83 SmallVectorImpl<StringRef> &elides) {
84 SmallString<32> resultNameStr;
85 llvm::raw_svector_ostream tmpStream(resultNameStr);
86 printer.printOperand(op->getResult(0), tmpStream);
87 auto actualName = tmpStream.str().drop_front();
88 auto expectedName = attrs.getAs<StringAttr>(
"name").getValue();
90 if (actualName == expectedName ||
91 (expectedName.empty() &&
isdigit(actualName[0])))
92 elides.push_back(
"name");
97 if (parser.parseType(lhs))
101 if (parser.parseOptionalComma()) {
104 if (parser.parseType(rhs))
119 StringRef trueKeyword,
120 StringRef falseKeyword) {
121 if (succeeded(parser.parseOptionalKeyword(trueKeyword))) {
123 }
else if (succeeded(parser.parseOptionalKeyword(falseKeyword))) {
126 return parser.emitError(parser.getCurrentLocation())
127 <<
"expected keyword \"" << trueKeyword <<
"\" or \"" << falseKeyword
134 BoolAttr attr, StringRef trueKeyword,
135 StringRef falseKeyword) {
137 printer << trueKeyword;
139 printer << falseKeyword;
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ParseResult parseKeywordBool(OpAsmParser &parser, BoolAttr &attr, StringRef trueKeyword, StringRef falseKeyword)
Parse a boolean as one of two keywords.
void printOptionalBinaryOpTypes(OpAsmPrinter &p, Operation *op, Type lhs, Type rhs)
Print/parse binary operands type only when types are different.
void elideImplicitSSAName(OpAsmPrinter &printer, Operation *op, DictionaryAttr attrs, SmallVectorImpl< StringRef > &elides)
Check if the name attribute in attrs matches the SSA name of the operation's first result.
ParseResult parseImplicitSSAName(OpAsmParser &parser, StringAttr &attr)
Parse an implicit SSA name string attribute.
void printKeywordBool(OpAsmPrinter &printer, Operation *op, BoolAttr attr, StringRef trueKeyword, StringRef falseKeyword)
Print a boolean as one of two keywords.
bool inferImplicitSSAName(OpAsmParser &parser, NamedAttrList &attrs)
Ensure that attrs contains a name attribute by inferring its value from the SSA name of the operation...
void printImplicitSSAName(OpAsmPrinter &p, Operation *op, StringAttr attr)
Print an implicit SSA name string attribute.
ParseResult parseOptionalBinaryOpTypes(OpAsmParser &parser, Type &lhs, Type &rhs)