10#include "mlir/IR/OpImplementation.h"
11#include "llvm/ADT/DenseSet.h"
21ParseResult StructOp::parse(OpAsmParser &parser, OperationState &result) {
23 SmallVector<Attribute> names;
24 SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
25 std::string nameBuffer;
26 auto parseField = [&]() {
28 if (parser.parseString(&nameBuffer) || parser.parseColon() ||
29 parser.parseOperand(operands.emplace_back()))
31 names.push_back(StringAttr::get(parser.getContext(), nameBuffer));
34 if (parser.parseCommaSeparatedList(AsmParser::Delimiter::Braces, parseField))
38 if (parser.parseOptionalAttrDict(result.attributes))
42 SmallVector<Type> types;
43 if (!operands.empty()) {
44 if (parser.parseColon())
46 auto typesLoc = parser.getCurrentLocation();
47 if (parser.parseTypeList(types))
49 if (types.size() != operands.size())
50 return parser.emitError(typesLoc,
51 "number of fields and types must match");
55 for (
auto [operand, type] :
llvm::zip(operands, types))
56 if (parser.resolveOperand(operand, type, result.operands))
60 result.addAttribute(
"names", ArrayAttr::get(parser.getContext(), names));
61 result.addTypes(StructType::get(parser.getContext()));
65void StructOp::print(OpAsmPrinter &printer) {
67 llvm::interleaveComma(llvm::zip(getFields(), getNames()), printer.getStream(),
69 auto [field, name] = pair;
70 printer.printAttribute(name);
72 printer.printOperand(field);
75 printer.printOptionalAttrDict(getOperation()->getAttrs(), {
"names"});
76 if (!getFields().
empty()) {
78 printer << getFields().getTypes();
86ParseResult ArrayOp::parse(OpAsmParser &parser, OperationState &result) {
88 SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
89 if (parser.parseOperandList(operands, AsmParser::Delimiter::Square) ||
90 parser.parseOptionalAttrDict(result.attributes))
94 if (!operands.empty()) {
96 if (parser.parseColon() || parser.parseType(type))
98 for (
auto operand : operands)
99 if (parser.resolveOperand(operand, type, result.operands))
104 result.addTypes(ArrayType::get(parser.getContext()));
108void ArrayOp::print(OpAsmPrinter &printer) {
110 printer << getElements();
112 printer.printOptionalAttrDict(getOperation()->getAttrs());
113 if (!getElements().
empty()) {
115 printer << getElements()[0].getType();
122#define GET_OP_CLASSES
123#include "circt/Dialect/Debug/Debug.cpp.inc"
125void DebugDialect::registerOps() {
128#include "circt/Dialect/Debug/Debug.cpp.inc"
136LogicalResult ValueOp::verify() {
138 if (!llvm::all_of(getResult().getUsers(), [](Operation *user) {
139 return isa<VariableOp, StructOp, ArrayOp>(user);
142 "must only be used as an operand of dbg.variable, dbg.struct, or "
152LogicalResult EnumOp::verify() {
153 if (getVariantsMap().
empty())
154 return emitOpError(
"variantsMap must not be empty");
156 llvm::SmallDenseSet<int64_t> seenValues{};
157 for (
auto namedAttr : getVariantsMap()) {
158 auto intAttr = dyn_cast<IntegerAttr>(namedAttr.getValue());
160 return emitOpError(
"variantsMap entry '")
161 << namedAttr.getName().getValue()
162 <<
"' must be an IntegerAttr, got " << namedAttr.getValue();
163 if (!intAttr.getType().isSignlessInteger())
164 return emitOpError() <<
"variant '" << namedAttr.getName().getValue()
165 <<
"' must have a signless integer value";
166 auto value = intAttr.getInt();
167 if (!seenValues.insert(value).second)
168 return emitOpError(
"duplicate enum value ") << value;
static InstancePath empty
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.