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::VoidType &type) {
34 Type visit(
const slang::ast::ScalarType &type) {
35 return getSimpleBitVectorType(type);
38 Type visit(
const slang::ast::FloatingType &type) {
42 Type visit(
const slang::ast::PredefinedIntegerType &type) {
43 return getSimpleBitVectorType(type);
46 Type visit(
const slang::ast::PackedArrayType &type) {
48 if (type.elementType.as_if<slang::ast::ScalarType>())
49 return getSimpleBitVectorType(type);
52 auto innerType = type.elementType.visit(*
this);
60 Type visit(
const slang::ast::QueueType &type) {
61 auto innerType = type.elementType.visit(*
this);
68 Type visit(
const slang::ast::AssociativeArrayType &type) {
69 auto innerType = type.elementType.visit(*
this);
72 auto indexType = type.indexType->visit(*
this);
76 cast<moore::UnpackedType>(indexType));
79 Type visit(
const slang::ast::FixedSizeUnpackedArrayType &type) {
80 auto innerType = type.elementType.visit(*
this);
87 Type visit(
const slang::ast::DynamicArrayType &type) {
88 auto innerType = type.elementType.visit(*
this);
96 Type visit(
const slang::ast::TypeAliasType &type) {
98 return type.targetType.getType().visit(*
this);
102 Type visit(
const slang::ast::EnumType &type) {
104 return type.baseType.visit(*
this);
109 collectMembers(
const slang::ast::Scope &structType,
110 SmallVectorImpl<moore::StructLikeMember> &members) {
111 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::StructLikeMember> members;
124 if (failed(collectMembers(type, members)))
129 Type visit(
const slang::ast::UnpackedStructType &type) {
130 SmallVector<moore::StructLikeMember> members;
131 if (failed(collectMembers(type, members)))
136 Type visit(
const slang::ast::PackedUnionType &type) {
137 SmallVector<moore::StructLikeMember> members;
138 if (failed(collectMembers(type, members)))
143 Type visit(
const slang::ast::UnpackedUnionType &type) {
144 SmallVector<moore::StructLikeMember> members;
145 if (failed(collectMembers(type, members)))
150 Type visit(
const slang::ast::StringType &type) {
155 template <
typename T>
156 Type visit(T &&node) {
157 auto d = mlir::emitError(loc,
"unsupported type: ")
159 d.attachNote() << node.template as<slang::ast::Type>().toString();
170 return type.visit(TypeVisitor(*
this, loc));
175 if (
auto *ts = type.getTypeSyntax())
const char * toString(Flow flow)
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.