16 #include "mlir/IR/Builders.h"
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "mlir/IR/DialectImplementation.h"
19 #include "llvm/ADT/TypeSwitch.h"
24 #define GET_ATTRDEF_CLASSES
25 #include "circt/Dialect/OM/OMAttributes.cpp.inc"
27 Type circt::om::ReferenceAttr::getType() {
31 Type circt::om::SymbolRefAttr::getType() {
35 Type circt::om::ListAttr::getType() {
39 Type circt::om::MapAttr::getType() {
49 circt::om::SymbolRefAttr
58 return success(llvm::all_of(elements, [&](mlir::Attribute attr) {
59 auto typedAttr = llvm::dyn_cast<mlir::TypedAttr>(attr);
62 <<
"an element of a list attribute must be a typed attr but got "
67 emitError() <<
"an element of a list attribute must have a type "
68 <<
elementType <<
" but got " << typedAttr.getType();
79 mlir::DictionaryAttr elements) {
80 for (
auto attr : elements) {
81 auto typedAttr = llvm::dyn_cast<mlir::TypedAttr>(attr.getValue());
84 <<
"a value of a map attribute must be a typed attr but got "
86 if (typedAttr.getType() != valueType)
87 return emitError() <<
"a value of a map attribute must have a type "
88 << valueType <<
" but field " << attr.getName()
89 <<
" has " << typedAttr.getType();
94 void PathAttr::print(AsmPrinter &odsPrinter)
const {
96 llvm::interleaveComma(getPath(), odsPrinter, [&](
PathElement element) {
97 odsPrinter.printKeywordOrString(element.
module);
99 odsPrinter.printKeywordOrString(element.
instance);
104 Attribute PathAttr::parse(AsmParser &odsParser, Type odsType) {
105 auto *context = odsParser.getContext();
106 SmallVector<PathElement> path;
107 if (odsParser.parseCommaSeparatedList(
108 OpAsmParser::Delimiter::Square, [&]() -> ParseResult {
110 std::string instance;
111 if (odsParser.parseKeywordOrString(&module) ||
112 odsParser.parseColon() ||
113 odsParser.parseKeywordOrString(&instance))
115 path.emplace_back(StringAttr::get(context, module),
116 StringAttr::get(context, instance));
124 ArrayRef<PathElement> path) {
128 Type circt::om::IntegerAttr::getType() {
132 void circt::om::OMDialect::registerAttributes() {
134 #define GET_ATTRDEF_LIST
135 #include "circt/Dialect/OM/OMAttributes.cpp.inc"
static LogicalResult verify(Value clock, bool eventExists, mlir::Location loc)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
A module name, and the name of an instance inside that module.
mlir::StringAttr instance