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"
27Type circt::om::ReferenceAttr::getType() {
28 return ReferenceType::get(getContext());
31Type circt::om::SymbolRefAttr::getType() {
32 return SymbolRefType::get(getContext());
35Type circt::om::ListAttr::getType() {
36 return ListType::get(getContext(), getElementType());
39Type circt::om::MapAttr::getType() {
40 return MapType::get(getContext(), StringType::get(getContext()),
44circt::om::SymbolRefAttr circt::om::SymbolRefAttr::get(mlir::Operation *op) {
45 return om::SymbolRefAttr::get(op->getContext(),
46 mlir::FlatSymbolRefAttr::get(op));
49circt::om::SymbolRefAttr
50circt::om::SymbolRefAttr::get(mlir::StringAttr symName) {
51 return om::SymbolRefAttr::get(symName.getContext(),
52 mlir::FlatSymbolRefAttr::get(symName));
56circt::om::ListAttr::verify(function_ref<InFlightDiagnostic()> emitError,
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();
77circt::om::MapAttr::verify(function_ref<InFlightDiagnostic()> emitError,
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();
94void PathAttr::print(AsmPrinter &odsPrinter)
const {
96 llvm::interleaveComma(getPath(), odsPrinter, [&](
PathElement element) {
97 odsPrinter.printKeywordOrString(element.module);
99 odsPrinter.printKeywordOrString(element.
instance);
104Attribute 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));
120 return PathAttr::get(context, path);
123LogicalResult PathAttr::verify(function_ref<mlir::InFlightDiagnostic()>,
124 ArrayRef<PathElement> path) {
128Type circt::om::IntegerAttr::getType() {
129 return OMIntegerType::get(getContext());
132void circt::om::OMDialect::registerAttributes() {
134#define GET_ATTRDEF_LIST
135#include "circt/Dialect/OM/OMAttributes.cpp.inc"
A module name, and the name of an instance inside that module.
mlir::StringAttr mlir::StringAttr instance