10 #include "mlir/IR/OpImplementation.h"
12 using namespace circt;
13 using namespace debug;
20 ParseResult StructOp::parse(OpAsmParser &parser, OperationState &result) {
22 SmallVector<Attribute> names;
23 SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
24 std::string nameBuffer;
25 auto parseField = [&]() {
27 if (parser.parseString(&nameBuffer) || parser.parseColon() ||
28 parser.parseOperand(operands.emplace_back()))
33 if (parser.parseCommaSeparatedList(AsmParser::Delimiter::Braces, parseField))
37 if (parser.parseOptionalAttrDict(result.attributes))
41 SmallVector<Type> types;
42 if (!operands.empty()) {
43 if (parser.parseColon())
45 auto typesLoc = parser.getCurrentLocation();
46 if (parser.parseTypeList(types))
48 if (types.size() != operands.size())
49 return parser.emitError(typesLoc,
50 "number of fields and types must match");
54 for (
auto [operand, type] : llvm::zip(operands, types))
55 if (parser.resolveOperand(operand, type, result.operands))
59 result.addAttribute(
"names",
ArrayAttr::get(parser.getContext(), names));
64 void StructOp::print(OpAsmPrinter &printer) {
66 llvm::interleaveComma(llvm::zip(getFields(), getNames()), printer.getStream(),
68 auto [field, name] = pair;
69 printer.printAttribute(name);
71 printer.printOperand(field);
74 printer.printOptionalAttrDict(getOperation()->getAttrs(), {
"names"});
75 if (!getFields().
empty()) {
77 printer << getFields().getTypes();
85 ParseResult ArrayOp::parse(OpAsmParser &parser, OperationState &result) {
87 SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
88 if (parser.parseOperandList(operands, AsmParser::Delimiter::Square) ||
89 parser.parseOptionalAttrDict(result.attributes))
93 if (!operands.empty()) {
95 if (parser.parseColon() || parser.parseType(type))
97 for (
auto operand : operands)
98 if (parser.resolveOperand(operand, type, result.operands))
107 void ArrayOp::print(OpAsmPrinter &printer) {
109 printer << getElements();
111 printer.printOptionalAttrDict(getOperation()->getAttrs());
112 if (!getElements().
empty()) {
114 printer << getElements()[0].getType();
119 #define GET_OP_CLASSES
120 #include "circt/Dialect/Debug/Debug.cpp.inc"
122 void DebugDialect::registerOps() {
125 #include "circt/Dialect/Debug/Debug.cpp.inc"
static InstancePath empty
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.