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();
61 auto expectedName = attr.getValue();
63 if (actualName == expectedName ||
64 (expectedName.empty() &&
isdigit(actualName[0])))
67 printer <<
" name " << attr;
72 ArrayRef<StringRef> extraElides) {
73 SmallVector<StringRef, 2> elides(extraElides.begin(), extraElides.end());
75 printer.printOptionalAttrDict(attrs.getValue(), elides);
80 SmallVectorImpl<StringRef> &elides) {
81 SmallString<32> resultNameStr;
82 llvm::raw_svector_ostream tmpStream(resultNameStr);
83 printer.printOperand(op->getResult(0), tmpStream);
84 auto actualName = tmpStream.str().drop_front();
85 auto expectedName = attrs.getAs<StringAttr>(
"name").getValue();
87 if (actualName == expectedName ||
88 (expectedName.empty() &&
isdigit(actualName[0])))
89 elides.push_back(
"name");
94 if (parser.parseType(lhs))
98 if (parser.parseOptionalComma()) {
101 if (parser.parseType(rhs))
116 StringRef trueKeyword,
117 StringRef falseKeyword) {
118 if (succeeded(parser.parseOptionalKeyword(trueKeyword))) {
120 }
else if (succeeded(parser.parseOptionalKeyword(falseKeyword))) {
123 return parser.emitError(parser.getCurrentLocation())
124 <<
"expected keyword \"" << trueKeyword <<
"\" or \"" << falseKeyword
131 BoolAttr attr, StringRef trueKeyword,
132 StringRef falseKeyword) {
134 printer << trueKeyword;
136 printer << falseKeyword;
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
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)