16#include "mlir/IR/Builders.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/TypeSwitch.h"
23#define GET_ATTRDEF_CLASSES
24#include "circt/Dialect/OM/OMAttributes.cpp.inc"
26Type circt::om::ReferenceAttr::getType() {
27 return ReferenceType::get(getContext());
30Type circt::om::SymbolRefAttr::getType() {
31 return SymbolRefType::get(getContext());
34Type circt::om::ListAttr::getType() {
35 return ListType::get(getContext(), getElementType());
38circt::om::SymbolRefAttr circt::om::SymbolRefAttr::get(mlir::Operation *op) {
39 return om::SymbolRefAttr::get(op->getContext(),
40 mlir::FlatSymbolRefAttr::get(op));
43circt::om::SymbolRefAttr
44circt::om::SymbolRefAttr::get(mlir::StringAttr symName) {
45 return om::SymbolRefAttr::get(symName.getContext(),
46 mlir::FlatSymbolRefAttr::get(symName));
50circt::om::ListAttr::verify(function_ref<InFlightDiagnostic()> emitError,
52 return success(llvm::all_of(elements, [&](mlir::Attribute attr) {
53 auto typedAttr = llvm::dyn_cast<mlir::TypedAttr>(attr);
56 <<
"an element of a list attribute must be a typed attr but got "
61 emitError() <<
"an element of a list attribute must have a type "
62 <<
elementType <<
" but got " << typedAttr.getType();
70void PathAttr::print(AsmPrinter &odsPrinter)
const {
72 llvm::interleaveComma(getPath(), odsPrinter, [&](
PathElement element) {
73 odsPrinter.printKeywordOrString(element.module);
75 odsPrinter.printKeywordOrString(element.
instance);
80Attribute PathAttr::parse(AsmParser &odsParser, Type odsType) {
81 auto *context = odsParser.getContext();
82 SmallVector<PathElement> path;
83 if (odsParser.parseCommaSeparatedList(
84 OpAsmParser::Delimiter::Square, [&]() -> ParseResult {
87 if (odsParser.parseKeywordOrString(&module) ||
88 odsParser.parseColon() ||
89 odsParser.parseKeywordOrString(&instance))
91 path.emplace_back(StringAttr::get(context, module),
92 StringAttr::get(context, instance));
96 return PathAttr::get(context, path);
99LogicalResult PathAttr::verify(function_ref<mlir::InFlightDiagnostic()>,
100 ArrayRef<PathElement> path) {
104Type circt::om::IntegerAttr::getType() {
105 return OMIntegerType::get(getContext());
108void circt::om::OMDialect::registerAttributes() {
110#define GET_ATTRDEF_LIST
111#include "circt/Dialect/OM/OMAttributes.cpp.inc"
A module name, and the name of an instance inside that module.
mlir::StringAttr mlir::StringAttr instance