15#include "mlir/IR/Builders.h"
16#include "mlir/IR/DialectImplementation.h"
17#include "llvm/ADT/TypeSwitch.h"
23 return TypeSwitch<Type, Type>(type)
24 .Case<InputType, OutputType, InOutType, SignalType>(
25 [](
auto ty) {
return ty.getBaseType(); })
26 .Default([](
auto ty) {
return Type(); });
30 return llvm::TypeSwitch<Type, std::optional<size_t>>(type)
33 [](
auto ty) {
return ty.getWidth(); })
34 .Case<LogicType>([](
auto ty) {
return 1; })
35 .Default([](
auto ty) {
return std::nullopt; });
46 return llvm::hash_combine(pi.
name, pi.
type);
58Type ModuleType::parse(AsmParser &odsParser) {
59 if (odsParser.parseLess())
63 if (odsParser.parseKeyword(&moduleName))
66 SmallVector<ModuleType::PortInfo> ports;
68 if (odsParser.parseCommaSeparatedList(
69 AsmParser::Delimiter::Paren, [&]() -> ParseResult {
72 if (odsParser.parseKeyword(&name) || odsParser.parseColon() ||
73 odsParser.parseType(port.type))
76 port.name = StringAttr::get(odsParser.getContext(), name);
77 ports.push_back(port);
83 if (odsParser.parseGreater())
86 return ModuleType::getChecked(
87 UnknownLoc::get(odsParser.getContext()), odsParser.getContext(),
88 StringAttr::get(odsParser.getContext(), moduleName), ports);
93void ModuleType::print(AsmPrinter &odsPrinter)
const {
94 odsPrinter <<
'<' << getModuleName().getValue() <<
'(';
95 llvm::interleaveComma(getPorts(), odsPrinter, [&](
auto port) {
96 odsPrinter << port.name.getValue() <<
": " << port.type;
117 return llvm::hash_value(key);
140 return Base::get(context);
144 return Base::get(context, width);
150 return Base::get(context);
154 return Base::get(context, width);
161 return Base::get(context, width);
166 return Base::get(context);
170 return Base::get(context, width);
180 return Base::get(context);
184 return Base::get(context, width);
190 return Base::get(context);
194 return Base::get(context, width);
203#define GET_TYPEDEF_CLASSES
204#include "circt/Dialect/SystemC/SystemCTypes.cpp.inc"
206void SystemCDialect::registerTypes() {
208#define GET_TYPEDEF_LIST
209#include "circt/Dialect/SystemC/SystemCTypes.cpp.inc"
220template <
typename Ty>
224 auto *ctxt = parser.getContext();
226 if (parser.parseLess() || parser.parseInteger(width) || parser.parseGreater())
229 type = Ty::get(ctxt, width);
235 llvm::SMLoc loc, Type &type) {
236 auto *ctxt = parser.getContext();
263 return parseIntegerOrBitVector<IntType>(parser, type);
265 return parseIntegerOrBitVector<UIntType>(parser, type);
267 return parseIntegerOrBitVector<BigIntType>(parser, type);
269 return parseIntegerOrBitVector<BigUIntType>(parser, type);
271 return parseIntegerOrBitVector<BitVectorType>(parser, type);
273 return parseIntegerOrBitVector<LogicVectorType>(parser, type);
279 return TypeSwitch<Type, LogicalResult>(type)
282 printer << ty.getMnemonic() <<
"<" << ty.getWidth() <<
">";
287 printer << ty.getMnemonic();
290 .Default([](
auto ty) {
return failure(); });
294Type SystemCDialect::parseType(DialectAsmParser &parser)
const {
296 llvm::SMLoc loc = parser.getCurrentLocation();
299 mlir::OptionalParseResult result =
300 generatedTypeParser(parser, &mnemonic, type);
301 if (result.has_value() && !result.value())
305 if (result.has_value() && !result.value())
308 parser.emitError(loc) <<
"unknown type `" << mnemonic
309 <<
"` in dialect `systemc`";
314void SystemCDialect::printType(Type type, DialectAsmPrinter &printer)
const {
315 if (succeeded(generatedTypePrinter(type, printer)) ||
319 assert(
false &&
"no printer for unknown `systemc` dialect type");
320 printer <<
"<<UnknownType>>";
assert(baseType &&"element must be base type")
static LogicalResult customTypePrinter(Type type, AsmPrinter &os)
Print a type with a custom printer implementation.
static OptionalParseResult customTypeParser(AsmParser &parser, StringRef name, Type &result)
Parse a type with a custom parser implementation.
static LogicalResult parseIntegerOrBitVector(DialectAsmParser &parser, Type &type)
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static BigIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static BigUIntType get(MLIRContext *context, unsigned width)
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static BitVectorBaseType get(MLIRContext *context)
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static BitVectorType get(MLIRContext *context, unsigned width)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static IntBaseType get(MLIRContext *context)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static IntType get(MLIRContext *context, unsigned width)
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static LogicVectorBaseType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
Represents a finite word-length bit vector (of four-state values) in SystemC as described in IEEE 166...
static LogicVectorType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static SignedType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static UIntBaseType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static UIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static UnsignedType get(MLIRContext *context)
bool operator==(const PortInfo &a, const PortInfo &b)
llvm::hash_code hash_value(const PortInfo &pi)
Type getSignalBaseType(Type type)
Get the type wrapped by a signal or port (in, inout, out) type.
std::optional< size_t > getBitWidth(Type type)
Return the bitwidth of a type.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Integer Type Storage and Uniquing.
bool operator==(const KeyTy &key) const
unsigned KeyTy
The hash key used for uniquing.
static llvm::hash_code hashKey(const KeyTy &key)
static IntegerWidthStorage * construct(mlir::TypeStorageAllocator &allocator, KeyTy key)
IntegerWidthStorage(unsigned width)
A struct containing minimal information for a systemc module port.