17#include "mlir/IR/Builders.h"
18#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/DialectImplementation.h"
20#include "llvm/ADT/TypeSwitch.h"
30 if (
auto array = hw::type_dyn_cast<hw::ArrayType>(type))
31 return array.getElementType();
32 if (
auto array = hw::type_dyn_cast<hw::UnpackedArrayType>(type))
33 return array.getElementType();
44 if (isa<hw::IntType, IntegerType, hw::EnumType>(type))
47 if (
auto array = dyn_cast<hw::ArrayType>(type))
50 if (
auto t = dyn_cast<hw::StructType>(type))
51 return llvm::all_of(t.getElements(),
52 [](
auto f) { return isPackedType(f.type); });
54 if (
auto t = dyn_cast<hw::UnionType>(type))
55 return llvm::all_of(t.getElements(),
56 [](
auto m) { return isPackedType(m.type); });
68 if (
auto inout = dyn_cast_or_null<InOutType>(type))
69 return inout.getElementType();
80 if (
auto net = dyn_cast_or_null<NetType>(type))
81 return net.getElementType();
87 type = hw::getCanonicalType(type);
88 while (
auto uarray = dyn_cast<hw::UnpackedArrayType>(type))
89 type = uarray.getElementType();
98LogicalResult NetType::verify(function_ref<InFlightDiagnostic()> emitError,
100 if (isa_and_present<NetType, VarType>(
elementType))
101 return emitError() <<
"sv.net element type may not be itself an sv.net or "
107 <<
"sv.net element type must have a packed base type, but got "
108 << packedElementType;
120 if (
auto var = dyn_cast_or_null<VarType>(type))
121 return var.getElementType();
129 if (
auto uarray = dyn_cast<hw::UnpackedArrayType>(type))
141LogicalResult VarType::verify(function_ref<InFlightDiagnostic()> emitError,
143 if (isa_and_present<VarType, NetType>(
elementType))
144 return emitError() <<
"sv.var element type may not be itself an sv.var or "
147 return emitError() <<
"sv.var element type must be a valid value type, "
158#define GET_TYPEDEF_CLASSES
159#include "circt/Dialect/SV/SVTypes.cpp.inc"
161void SVDialect::registerTypes() {
163#define GET_TYPEDEF_LIST
164#include "circt/Dialect/SV/SVTypes.cpp.inc"
static bool isValidVarElementTypeImpl(Type type)
static bool isPackedType(Type type)
Return true if the specified type has a packed layout, i.e.
static Type stripUnpackedDimensions(Type type)
Return the innermost non-unpacked element type.
mlir::Type getVarElementType(mlir::Type type)
Return the element type of a VarType or null if the operand isn't a Var type.
bool isValidNetElementType(mlir::Type type)
Return true if a type is a valid element type of a NetType.
mlir::Type getAnyHWArrayElementType(mlir::Type type)
Return the element type of an ArrayType or UnpackedArrayType, or null if the operand isn't an array.
mlir::Type getNetElementType(mlir::Type type)
Return the element type of a NetType or null if the operand isn't a Net type.
mlir::Type getInOutElementType(mlir::Type type)
Return the element type of an InOutType or null if the operand isn't an InOut type.
bool isValidVarElementType(mlir::Type type)
Return true if a type is a valid element type of a VarType.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.