13 #ifndef CIRCT_DIALECT_MOORE_MOORETYPES_H
14 #define CIRCT_DIALECT_MOORE_MOORETYPES_H
17 #include "mlir/IR/Attributes.h"
18 #include "mlir/IR/BuiltinAttributes.h"
19 #include "mlir/IR/Location.h"
20 #include "mlir/IR/Types.h"
47 template <
typename Os>
110 llvm::raw_string_ostream(buffer) << *
this;
120 template <
typename Os>
122 os << range.
left() <<
":" << range.
right();
145 assert(
size > 0 &&
"SBVT requires non-zero size");
164 type.explicitSize =
false;
165 type.usedAtom =
false;
183 operator bool()
const {
return size > 0; }
188 llvm::raw_string_ostream(buffer) << *
this;
221 template <
typename Os>
224 os <<
"<<<NULL SBVT>>>";
229 os <<
" " << type.
sign;
231 os <<
" [" << type.
getRange() <<
"]";
335 assert(sbv &&
"getSimpleBitVector called on type that is no SBV");
354 "castToSimpleBitVector called on type that cannot be cast to an SBV");
361 format(llvm::raw_ostream &os,
362 llvm::function_ref<
void(llvm::raw_ostream &os)> around = {})
const;
364 void format(llvm::raw_ostream &os, StringRef around)
const {
365 format(os, [&](llvm::raw_ostream &os) { os << around; });
371 template <
typename... Args>
374 llvm::raw_string_ostream os(buffer);
380 using SVType::SVType;
385 std::enable_if_t<std::is_base_of<UnpackedType, Ty>::value,
bool> =
true>
386 llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, Ty type) {
397 class PackedIndirectType;
400 class PackedStructType;
456 void format(llvm::raw_ostream &os)
const;
459 using UnpackedType::UnpackedType;
468 :
public Type::TypeBase<VoidType, PackedType, DefaultTypeStorage> {
472 static constexpr StringLiteral
name =
"moore.void";
480 :
public Type::TypeBase<StringType, UnpackedType, DefaultTypeStorage> {
484 static constexpr StringLiteral
name =
"moore.string";
492 :
public Type::TypeBase<ChandleType, UnpackedType, DefaultTypeStorage> {
496 static constexpr StringLiteral
name =
"moore.chandle";
504 :
public Type::TypeBase<EventType, UnpackedType, DefaultTypeStorage> {
508 static constexpr StringLiteral
name =
"moore.event";
520 :
public Type::TypeBase<IntType, PackedType, detail::IntTypeStorage> {
564 std::optional<Sign> sign = {});
594 void format(llvm::raw_ostream &os)
const;
596 static constexpr StringLiteral
name =
"moore.int";
608 :
public Type::TypeBase<RealType, UnpackedType, detail::RealTypeStorage> {
636 static constexpr StringLiteral
name =
"moore.real";
673 template <
class BaseTy>
677 using BaseTy::BaseTy;
709 template <
class ConcreteTy,
class BaseTy>
711 :
public Type::TypeBase<ConcreteTy, BaseTy, detail::IndirectTypeStorage> {
714 using Type::TypeBase<ConcreteTy,
BaseTy,
735 template <
class ConcreteTy,
class BaseTy>
737 :
public Type::TypeBase<ConcreteTy, BaseTy, detail::IndirectTypeStorage> {
740 using Type::TypeBase<ConcreteTy,
BaseTy,
772 :
public NamedTypeBase<PackedNamedType, PackedIndirectType> {
774 static constexpr StringLiteral
name =
"moore.packed_named";
782 :
public NamedTypeBase<UnpackedNamedType, UnpackedIndirectType> {
784 static constexpr StringLiteral
name =
"moore.unpacked_named";
793 static constexpr StringLiteral
name =
"moore.packed_ref";
801 :
public RefTypeBase<UnpackedRefType, UnpackedIndirectType> {
803 static constexpr StringLiteral
name =
"moore.unpacked_ref";
828 void format(llvm::raw_ostream &os)
const;
830 void formatDim(llvm::raw_ostream &os)
const;
841 std::optional<Range>
getRange()
const;
843 std::optional<unsigned>
getSize()
const;
846 using PackedType::PackedType;
852 detail::UnsizedDimStorage,
853 ::mlir::TypeTrait::IsMutable> {
857 static constexpr StringLiteral
name =
"moore.packed_unsized_dim";
866 :
public Type::TypeBase<PackedRangeDim, PackedDim, detail::RangeDimStorage,
867 ::mlir::TypeTrait::IsMutable> {
873 template <
typename... Args>
884 static constexpr StringLiteral
name =
"moore.packed_range_dim";
920 void format(llvm::raw_ostream &os,
921 llvm::function_ref<
void(llvm::raw_ostream &)> around = {})
const;
923 void formatDim(llvm::raw_ostream &os)
const;
934 using UnpackedType::UnpackedType;
935 const detail::DimStorage *
getImpl()
const;
940 :
public Type::TypeBase<UnpackedUnsizedDim, UnpackedDim,
941 detail::UnsizedDimStorage,
942 ::mlir::TypeTrait::IsMutable> {
946 static constexpr StringLiteral
name =
"moore.unpacked_unsized_dim";
955 detail::SizedDimStorage,
956 ::mlir::TypeTrait::IsMutable> {
963 static constexpr StringLiteral
name =
"moore.unpacked_array_dim";
972 detail::RangeDimStorage,
973 ::mlir::TypeTrait::IsMutable> {
979 template <
typename... Args>
990 static constexpr StringLiteral
name =
"moore.unpacked_range_dim";
1011 detail::AssocDimStorage,
1012 ::mlir::TypeTrait::IsMutable> {
1020 static constexpr StringLiteral
name =
"moore.unpacked_assoc_dim";
1029 detail::SizedDimStorage,
1030 ::mlir::TypeTrait::IsMutable> {
1033 std::optional<unsigned> bound = {});
1037 std::optional<unsigned>
getBound()
const;
1039 static constexpr StringLiteral
name =
"moore.unpacked_queue_dim";
1052 :
public Type::TypeBase<EnumType, PackedType, detail::EnumTypeStorage> {
1071 void format(llvm::raw_ostream &os)
const;
1073 static constexpr StringLiteral
name =
"moore.enum";
1098 template <
typename Os>
1100 static constexpr StringRef keywords[] = {
"struct",
"union",
"union tagged"};
1101 os << keywords[static_cast<unsigned>(kind)];
1156 void format(llvm::raw_ostream &os,
bool packed =
false,
1157 std::optional<Sign> signing = {})
const;
1168 detail::StructTypeStorage,
1169 ::mlir::TypeTrait::IsMutable> {
1172 StringAttr
name, Location loc,
1173 std::optional<Sign> sign = {});
1175 std::optional<Sign> sign = {}) {
1191 : std::optional<Sign>());
1198 static constexpr StringLiteral
name =
"moore.packed_struct";
1206 :
public Type::TypeBase<UnpackedStructType, UnpackedType,
1207 detail::StructTypeStorage,
1208 ::mlir::TypeTrait::IsMutable> {
1211 StringAttr
name, Location loc);
1227 static constexpr StringLiteral
name =
"moore.unpacked_struct";
1243 struct DenseMapInfo<
circt::moore::Range> {
1256 #define GET_TYPEDEF_CLASSES
1257 #include "circt/Dialect/Moore/MooreTypes.h.inc"
assert(baseType &&"element must be base type")
static ChandleType get(MLIRContext *context)
static constexpr StringLiteral name
StringAttr getName() const
Get the name of the surrounding typedef, if this enum is embedded in a typedef.
PackedType getBase() const
Get the base type of the enumeration.
static EnumType get(StringAttr name, Location loc, PackedType base={})
void format(llvm::raw_ostream &os) const
Format this enum in SystemVerilog syntax.
Location getLoc() const
Get the location in the source text where the enum was declared.
static constexpr StringLiteral name
bool isBaseExplicit() const
Returns whether the base type was explicitly specified by the user.
static constexpr StringLiteral name
static EventType get(MLIRContext *context)
Common base class for name and type reference indirections.
BaseTy resolved() const
Resolve one level of name or type reference indirection.
BaseTy getInner() const
Get the type this indirection wraps.
IndirectTypeBase< PackedType > Base
Location getLoc() const
Get the location in the source text where the indirection was generated.
BaseTy fullyResolved() const
Resolve all name or type reference indirections.
An integer vector or atom type.
Sign getDefaultSign() const
Get the default sign for this type.
Sign getSign() const
Get the sign of this type.
Domain getDomain() const
Get the value domain for this type.
static IntType getLogic(MLIRContext *context)
Create a logic type.
static Kind getAtomForDomain(Domain domain)
Get the integer type that corresponds to a single bit of the given domain.
static IntType getTime(MLIRContext *context)
Create a time type.
static std::optional< Kind > getKindFromDomainAndSize(Domain domain, unsigned size)
Get the integer type that corresponds to a domain and bit size.
Kind getKind() const
Get the concrete integer vector or atom type.
static IntType getInt(MLIRContext *context)
Create a int type.
bool isSignExplicit() const
Whether the sign of the type was specified explicitly.
static IntType get(MLIRContext *context, Kind kind, std::optional< Sign > sign={})
unsigned getBitSize() const
Get the size of this type.
static std::optional< Kind > getKindFromKeyword(StringRef keyword)
Get the integer type that corresponds to a keyword (like bit).
StringRef getKeyword() const
Get the keyword (like bit) for this type.
static constexpr StringLiteral name
void format(llvm::raw_ostream &os) const
Format this type in SystemVerilog syntax.
typename BaseTy::InnerType InnerType
NamedTypeBase< PackedNamedType, PackedIndirectType > NamedBase
StringAttr getName() const
Get the name assigned to the wrapped type.
static ConcreteTy get(InnerType inner, StringAttr name, Location loc)
static ConcreteTy get(InnerType inner, StringRef name, Location loc)
std::optional< Range > getRange() const
Get the dimension's range, or None if it is unsized.
void formatDim(llvm::raw_ostream &os) const
Format just the dimension part, [...].
const detail::DimStorage * getImpl() const
static bool classof(Type type)
PackedType resolved() const
Resolve one level of name or type reference indirection.
PackedType getInner() const
Get the element type of the dimension. This is the x in x[a:b].
void format(llvm::raw_ostream &os) const
Format this type in SystemVerilog syntax.
std::optional< unsigned > getSize() const
Get the dimension's size, or None if it is unsized.
PackedType fullyResolved() const
Resolve all name or type reference indirections.
A packed type indirection. See IndirectTypeBase for details.
static bool classof(Type type)
A packed named type. See NamedTypeBase for details.
static constexpr StringLiteral name
A packed range dimension, like [a:b].
static constexpr StringLiteral name
Range getRange() const
Get the range of this dimension.
static PackedRangeDim get(PackedType inner, Args... args)
Get a packed range with arguments forwarded to the Range constructor.
static PackedRangeDim get(PackedType inner, Range range)
A packed named type. See NamedTypeBase for details.
static constexpr StringLiteral name
void format(llvm::raw_ostream &os) const
Format this struct in SystemVerilog syntax.
const Struct & getStruct() const
Get the struct definition.
static PackedStructType get(const Struct &strukt, std::optional< Sign > sign={})
static PackedStructType get(StructKind kind, ArrayRef< StructMember > members, StringAttr name, Location loc, std::optional< Sign > sign={})
Sign getSign() const
Get the sign of this struct.
bool isSignExplicit() const
Returns whether the sign was explicitly mentioned by the user.
static constexpr StringLiteral name
A packed SystemVerilog type.
Sign getSign() const
Get the sign for this type.
PackedType resolved() const
Resolve one level of name or type reference indirection.
std::optional< unsigned > getBitSize() const
Get the size of this type in bits.
Domain getDomain() const
Get the value domain of this type.
static bool classof(Type type)
void format(llvm::raw_ostream &os) const
Format this type in SystemVerilog syntax into an output stream.
PackedType fullyResolved() const
Resolve all name or type reference indirections.
A packed unsized dimension, like [].
static constexpr StringLiteral name
static PackedUnsizedDim get(PackedType inner)
StringRef getKeyword() const
Get the keyword (like bit) for this type.
static constexpr StringLiteral name
static std::optional< Kind > getKindFromKeyword(StringRef keyword)
Get the integer type that corresponds to a keyword (like bit).
static RealType get(MLIRContext *context, Kind kind)
unsigned getBitSize() const
Get the size of this type.
Kind getKind() const
Get the concrete integer vector or atom type.
static ConcreteTy get(InnerType inner, Location loc)
RefTypeBase< PackedRefType, PackedIndirectType > RefBase
typename BaseTy::InnerType InnerType
Base class for all SystemVerilog types in the Moore dialect.
static constexpr StringLiteral name
static StringType get(MLIRContext *context)
An unpacked array dimension, like [a].
static UnpackedArrayDim get(UnpackedType inner, unsigned size)
static constexpr StringLiteral name
unsigned getSize() const
Get the size of the array, i.e. the a in [a].
An unpacked associative dimension, like [T] or [*].
static UnpackedAssocDim get(UnpackedType inner, UnpackedType indexType={})
UnpackedType getIndexType() const
Get the index type of the associative dimension.
static constexpr StringLiteral name
UnpackedType resolved() const
Resolve one level of name or type reference indirection.
void format(llvm::raw_ostream &os, llvm::function_ref< void(llvm::raw_ostream &)> around={}) const
Format this type in SystemVerilog syntax.
const detail::DimStorage * getImpl() const
UnpackedType fullyResolved() const
Resolve all name or type reference indirections.
static bool classof(Type type)
void formatDim(llvm::raw_ostream &os) const
Format just the dimension part, [...].
UnpackedType getInner() const
Get the element type of the dimension. This is the x in x[a:b].
An unpacked type indirection. See IndirectTypeBase for details.
static bool classof(Type type)
An unpacked named type. See NamedTypeBase for details.
static constexpr StringLiteral name
An unpacked queue dimension with optional bound, like [$] or [$:a].
static UnpackedQueueDim get(UnpackedType inner, std::optional< unsigned > bound={})
std::optional< unsigned > getBound() const
Get the bound of the queue, i.e.
static constexpr StringLiteral name
An unpacked range dimension, like [a:b].
static UnpackedRangeDim get(UnpackedType inner, Args... args)
Get a packed range with arguments forwarded to the Range constructor.
Range getRange() const
Get the range of this dimension.
static constexpr StringLiteral name
static UnpackedRangeDim get(UnpackedType inner, Range range)
An unpacked named type. See NamedTypeBase for details.
static constexpr StringLiteral name
const Struct & getStruct() const
Get the struct definition.
void format(llvm::raw_ostream &os) const
Format this struct in SystemVerilog syntax.
static UnpackedStructType get(const Struct &strukt)
static constexpr StringLiteral name
static UnpackedStructType get(StructKind kind, ArrayRef< StructMember > members, StringAttr name, Location loc)
An unpacked SystemVerilog type.
UnpackedType resolved() const
Resolve one level of name or type reference indirection.
SimpleBitVectorType getSimpleBitVectorOrNull() const
Get this type as a simple bit vector, if it is one.
SimpleBitVectorType castToSimpleBitVectorOrNull() const
Cast this type to a simple bit vector.
UnpackedType fullyResolved() const
Resolve all name or type reference indirections.
std::optional< unsigned > getBitSize() const
Get the size of this type in bits.
Domain getDomain() const
Get the value domain of this type.
Sign getSign() const
Get the sign for this type.
bool isSimpleBitVector() const
Check whether this is a simple bit vector type.
SimpleBitVectorType castToSimpleBitVector() const
Cast this type to a simple bit vector.
std::string toString(Args... args) const
Format this type in SystemVerilog syntax into a string.
static bool classof(Type type)
SimpleBitVectorType getSimpleBitVector() const
Get this type as a simple bit vector.
void format(llvm::raw_ostream &os, llvm::function_ref< void(llvm::raw_ostream &os)> around={}) const
Format this type in SystemVerilog syntax into an output stream.
void format(llvm::raw_ostream &os, StringRef around) const
bool isCastableToSimpleBitVector() const
Check whether this type can be cast to a simple bit vector type.
An unpacked unsized dimension, like [].
static UnpackedUnsizedDim get(UnpackedType inner)
static constexpr StringLiteral name
static VoidType get(MLIRContext *context)
static constexpr StringLiteral name
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
UnpackedType getIndirectTypeInner(const TypeStorage *impl)
StringAttr getIndirectTypeName(const TypeStorage *impl)
Location getIndirectTypeLoc(const TypeStorage *impl)
Domain
The number of values each bit of a type can assume.
@ FourValued
Four-valued types such as logic or integer.
@ TwoValued
Two-valued types such as bit or int.
llvm::hash_code hash_value(const Range &x)
RangeDir
Which side is greater in a range [a:b].
Sign
Whether a type is signed or unsigned.
@ Unsigned
An unsigned type.
StringRef getKeywordFromSign(const Sign &sign)
Map a Sign to the corresponding keyword.
Os & operator<<(Os &os, const Sign &sign)
StringRef getMnemonicFromStructKind(StructKind kind)
Map a StructKind to the corresponding mnemonic.
StructKind
Whether a struct is a struct, union, or union tagged.
@ TaggedUnion
A union tagged.
std::optional< StructKind > getStructKindFromMnemonic(StringRef mnemonic)
Map a mnemonic to the corresponding StructKind.
std::optional< Sign > getSignFromKeyword(StringRef keyword)
Map the keywords unsigned and signed to the corresponding Sign.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
The [a:b] part in a vector/array type such as logic [a:b].
Range(unsigned size, RangeDir dir, int offset)
Construct a range [offset+size-1:offset] if dir is Down, or [offset:offset+size-1] if dir is Up.
unsigned size
The total number of bits, given as |a-b|+1.
int offset
The starting offset of the range.
bool operator==(const Range &other) const
int left() const
Get the $left dimension.
int high() const
Get the $high dimension.
RangeDir dir
The direction of the vector, i.e. whether a > b or a < b.
std::string toString() const
Format this range as a string.
Range(unsigned size)
Construct a range [size-1:0].
int right() const
Get the $right dimension.
int low() const
Get the $low dimension.
int increment() const
Get the $increment size.
Range(int left, int right)
Construct a range [left:right], with the direction inferred asDownif left >= right,...
A simple bit vector type.
std::string toString() const
Format this simple bit vector type as a string.
SimpleBitVectorType(Domain domain, Sign sign, unsigned size, bool usedAtom=false, bool explicitSign=false, bool explicitSize=true)
Create a new SBVT with the given domain, sign, and size.
unsigned size
The size of the vector.
bool explicitSize
Whether the single-bit vector had an explicit range in the source text.
bool isSigned() const
Check whether the type is signed.
bool usedAtom
Whether the type used an integer atom like int in the source text.
bool explicitSign
Whether the sign was explicit in the source text.
PackedType getType(MLIRContext *context) const
Convert this SBVT to an actual type.
SimpleBitVectorType toSingleBit() const
Get a single bit version of this type by setting its size to 1.
bool isEquivalent(const SimpleBitVectorType &other) const
Check whether this type is equivalent to another.
Range getRange() const
Get the range of the type.
bool operator==(const SimpleBitVectorType &other) const
SimpleBitVectorType()
Create a null SBVT.
Domain domain
The domain, which dictates whether this is a bit or logic vector.
bool isUnsigned() const
Check whether the type is unsigned.
Location loc
The location in the source text where this member was declared.
StringAttr name
The name of this member.
UnpackedType type
The type of this member.
bool operator==(const StructMember &other) const
std::optional< unsigned > bitSize
The size of this struct in bits.
StructKind kind
Whether this is a struct, union, or union tagged.
StringAttr name
The name of the surrounding typedef, if this struct is embedded in a typedef.
Location loc
The location in the source text where the struct was declared.
void format(llvm::raw_ostream &os, bool packed=false, std::optional< Sign > signing={}) const
Format this struct in SystemVerilog syntax.
Domain domain
The value domain of this struct.
SmallVector< StructMember, 4 > members
The list of members.
Struct(StructKind kind, ArrayRef< StructMember > members, StringAttr name, Location loc)
Create a new struct.
static bool isEqual(const Range &lhs, const Range &rhs)
static Range getTombstoneKey()
static unsigned getHashValue(const Range &x)
static Range getEmptyKey()