12#include "mlir/IR/Builders.h"
13#include "mlir/IR/DialectImplementation.h"
14#include "llvm/ADT/StringSet.h"
15#include "llvm/ADT/TypeSwitch.h"
20#define GET_TYPEDEF_CLASSES
21#include "circt/Dialect/RTG/IR/RTGTypes.cpp.inc"
27LogicalResult DictType::verify(function_ref<InFlightDiagnostic()> emitError,
28 ArrayRef<DictEntry> entries) {
30 for (
auto entry : entries) {
31 if (entry.name.empty())
32 return emitError() <<
"empty strings not allowed as entry names";
34 if (last && entry.name.getValue() <= last.getValue())
35 return emitError() <<
"dictionary must be sorted by names and contain no "
36 "duplicates, first violation at entry '"
37 << entry.name.getValue() <<
"'";
45Type DictType::parse(AsmParser &p) {
46 SmallVector<DictEntry> entries;
47 auto loc = p.getCurrentLocation();
49 auto parseResult = p.parseCommaSeparatedList(
50 mlir::AsmParser::Delimiter::LessGreater, [&]() -> ParseResult {
53 loc = p.getCurrentLocation();
55 if (p.parseKeywordOrString(&name) || p.parseColon() ||
60 entry.name = StringAttr::get(p.getContext(), name);
62 entries.emplace_back(entry);
66 if (failed(parseResult))
69 auto emitError = [&]() {
return p.emitError(loc); };
74 return getChecked(emitError, p.getContext(), entries);
78StructType::verifySymbolUses(Operation *op,
79 SymbolTableCollection &symbolTable)
const {
80 if (!symbolTable.lookupNearestSymbolFrom<StructDeclOp>(op, getDeclaration()))
81 return op->emitOpError()
82 <<
"references unknown struct declaration " << getDeclaration();
87VariantType::verifySymbolUses(Operation *op,
88 SymbolTableCollection &symbolTable)
const {
89 if (!symbolTable.lookupNearestSymbolFrom<VariantDeclOp>(op, getDeclaration()))
90 return op->emitOpError()
91 <<
"references unknown variant declaration " << getDeclaration();
95void DictType::print(AsmPrinter &p)
const {
97 llvm::interleaveComma(getEntries(), p, [&](
auto entry) {
98 p.printKeywordOrString(entry.name.getValue());
99 p <<
": " << entry.type;
104bool DictType::entryTypesMatch(TypeRange types)
const {
105 return llvm::equal(getEntries(), types,
106 [](
const DictEntry &entry,
const Type &type) {
107 return entry.type == type;
111void circt::rtg::RTGDialect::registerTypes() {
113#define GET_TYPEDEF_LIST
114#include "circt/Dialect/RTG/IR/RTGTypes.cpp.inc"
false return failure()
Parse an optional keyword or string and set instance into 'result'.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.