10 #include "slang/syntax/AllSyntax.h"
12 using namespace circt;
13 using namespace ImportVerilog;
20 TypeVisitor(
Context &context, Location loc) : context(context), loc(loc) {}
23 Type getSimpleBitVectorType(
const slang::ast::IntegralType &type) {
25 type.isFourState ? Domain::FourValued
30 Type visit(
const slang::ast::ScalarType &type) {
31 return getSimpleBitVectorType(type);
34 Type visit(
const slang::ast::FloatingType &type) {
38 Type visit(
const slang::ast::PredefinedIntegerType &type) {
39 return getSimpleBitVectorType(type);
42 Type visit(
const slang::ast::PackedArrayType &type) {
44 if (type.elementType.as_if<slang::ast::ScalarType>())
45 return getSimpleBitVectorType(type);
48 auto innerType = type.elementType.visit(*
this);
52 auto packedInnerType = cast<moore::PackedType>(
innerType);
54 packedInnerType,
moore::Range(type.range.left, type.range.right));
57 Type visit(
const slang::ast::QueueType &type) {
58 auto innerType = type.elementType.visit(*
this);
65 Type visit(
const slang::ast::AssociativeArrayType &type) {
66 auto innerType = type.elementType.visit(*
this);
69 auto indexType = type.indexType->visit(*
this);
73 cast<moore::UnpackedType>(indexType));
76 Type visit(
const slang::ast::FixedSizeUnpackedArrayType &type) {
77 auto innerType = type.elementType.visit(*
this);
85 Type visit(
const slang::ast::DynamicArrayType &type) {
86 auto innerType = type.elementType.visit(*
this);
93 Type visit(
const slang::ast::TypeAliasType &type) {
95 return type.targetType.getType().visit(*
this);
99 Type visit(
const slang::ast::EnumType &type) {
101 return type.baseType.visit(*
this);
105 LogicalResult collectMembers(
const slang::ast::Scope &structType,
106 SmallVectorImpl<moore::StructMember> &members,
107 bool enforcePacked) {
108 for (
auto &field : structType.membersOfType<slang::ast::FieldSymbol>()) {
116 members.push_back({name, cast<moore::UnpackedType>(
innerType)});
122 Type visit(
const slang::ast::PackedStructType &type) {
123 SmallVector<moore::StructMember> members;
124 if (failed(collectMembers(type, members,
true)))
130 Type visit(
const slang::ast::UnpackedStructType &type) {
131 SmallVector<moore::StructMember> members;
132 if (failed(collectMembers(type, members,
false)))
139 template <
typename T>
140 Type visit(T &&node) {
141 auto d = mlir::emitError(loc,
"unsupported type: ")
143 d.attachNote() << node.template as<slang::ast::Type>().toString();
154 return type.visit(TypeVisitor(*
this, loc));
159 if (
auto *ts = type.getTypeSyntax())
assert(baseType &&"element must be base type")
constexpr const char * toString(Flow flow)
static PackedRangeDim get(PackedType inner, Range range)
static PackedStructType get(MLIRContext *context, StructKind kind, ArrayRef< StructMember > members)
static UnpackedAssocDim get(UnpackedType inner, UnpackedType indexType={})
static UnpackedQueueDim get(UnpackedType inner, std::optional< unsigned > bound={})
static UnpackedRangeDim get(UnpackedType inner, Range range)
static UnpackedStructType get(MLIRContext *context, StructKind kind, ArrayRef< StructMember > members)
static UnpackedUnsizedDim get(UnpackedType inner)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
mlir::Type innerType(mlir::Type type)
Domain
The number of values each bit of a type can assume.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
A helper class to facilitate the conversion from a Slang AST to MLIR operations.
Type convertType(const slang::ast::Type &type, LocationAttr loc={})
Convert a slang type into an MLIR type.
MLIRContext * getContext()
Return the MLIR context.
Location convertLocation(slang::SourceLocation loc)
Convert a slang SourceLocation into an MLIR Location.
The [a:b] part in a vector/array type such as logic [a:b].