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");
174 operator bool()
const {
return size > 0; }
179 llvm::raw_string_ostream(buffer) << *
this;
212 template <
typename Os>
215 os <<
"<<<NULL SBVT>>>";
220 os <<
" " << type.
sign;
222 os <<
" [" << type.
getRange() <<
"]";
326 assert(sbv &&
"getSimpleBitVector called on type that is no SBV");
345 "castToSimpleBitVector called on type that cannot be cast to an SBV");
352 format(llvm::raw_ostream &os,
353 llvm::function_ref<
void(llvm::raw_ostream &os)> around = {})
const;
355 void format(llvm::raw_ostream &os, StringRef around)
const {
356 format(os, [&](llvm::raw_ostream &os) { os << around; });
362 template <
typename... Args>
365 llvm::raw_string_ostream os(buffer);
371 using SVType::SVType;
376 std::enable_if_t<std::is_base_of<UnpackedType, Ty>::value,
bool> =
true>
377 llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, Ty type) {
388 class PackedIndirectType;
391 class PackedStructType;
447 void format(llvm::raw_ostream &os)
const;
450 using UnpackedType::UnpackedType;
459 :
public Type::TypeBase<VoidType, PackedType, DefaultTypeStorage> {
469 :
public Type::TypeBase<StringType, UnpackedType, DefaultTypeStorage> {
479 :
public Type::TypeBase<ChandleType, UnpackedType, DefaultTypeStorage> {
489 :
public Type::TypeBase<EventType, UnpackedType, DefaultTypeStorage> {
503 :
public Type::TypeBase<IntType, PackedType, detail::IntTypeStorage> {
545 std::optional<Sign> sign = {});
575 void format(llvm::raw_ostream &os)
const;
587 :
public Type::TypeBase<RealType, UnpackedType, detail::RealTypeStorage> {
623 class PackedNamedType;
625 class UnpackedNamedType;
626 class UnpackedRefType;
650 template <
class BaseTy>
654 using BaseTy::BaseTy;
686 template <
class ConcreteTy,
class BaseTy>
688 :
public Type::TypeBase<ConcreteTy, BaseTy, detail::IndirectTypeStorage> {
691 using Type::TypeBase<ConcreteTy,
BaseTy,
712 template <
class ConcreteTy,
class BaseTy>
714 :
public Type::TypeBase<ConcreteTy, BaseTy, detail::IndirectTypeStorage> {
717 using Type::TypeBase<ConcreteTy,
BaseTy,
749 :
public NamedTypeBase<PackedNamedType, PackedIndirectType> {
756 :
public NamedTypeBase<UnpackedNamedType, UnpackedIndirectType> {
769 :
public RefTypeBase<UnpackedRefType, UnpackedIndirectType> {
793 void format(llvm::raw_ostream &os)
const;
795 void formatDim(llvm::raw_ostream &os)
const;
806 std::optional<Range>
getRange()
const;
808 std::optional<unsigned>
getSize()
const;
811 using PackedType::PackedType;
817 detail::UnsizedDimStorage,
818 ::mlir::TypeTrait::IsMutable> {
829 :
public Type::TypeBase<PackedRangeDim, PackedDim, detail::RangeDimStorage,
830 ::mlir::TypeTrait::IsMutable> {
836 template <
typename... Args>
881 void format(llvm::raw_ostream &os,
882 llvm::function_ref<
void(llvm::raw_ostream &)> around = {})
const;
884 void formatDim(llvm::raw_ostream &os)
const;
895 using UnpackedType::UnpackedType;
896 const detail::DimStorage *
getImpl()
const;
901 :
public Type::TypeBase<UnpackedUnsizedDim, UnpackedDim,
902 detail::UnsizedDimStorage,
903 ::mlir::TypeTrait::IsMutable> {
914 detail::SizedDimStorage,
915 ::mlir::TypeTrait::IsMutable> {
929 detail::RangeDimStorage,
930 ::mlir::TypeTrait::IsMutable> {
936 template <
typename... Args>
966 detail::AssocDimStorage,
967 ::mlir::TypeTrait::IsMutable> {
982 detail::SizedDimStorage,
983 ::mlir::TypeTrait::IsMutable> {
986 std::optional<unsigned> bound = {});
990 std::optional<unsigned>
getBound()
const;
1003 :
public Type::TypeBase<EnumType, PackedType, detail::EnumTypeStorage> {
1022 void format(llvm::raw_ostream &os)
const;
1047 template <
typename Os>
1049 static constexpr StringRef keywords[] = {
"struct",
"union",
"union tagged"};
1050 os << keywords[static_cast<unsigned>(kind)];
1105 void format(llvm::raw_ostream &os,
bool packed =
false,
1106 std::optional<Sign> signing = {})
const;
1117 detail::StructTypeStorage,
1118 ::mlir::TypeTrait::IsMutable> {
1121 StringAttr name, Location loc,
1122 std::optional<Sign> sign = {});
1124 std::optional<Sign> sign = {}) {
1140 : std::optional<Sign>());
1153 :
public Type::TypeBase<UnpackedStructType, UnpackedType,
1154 detail::StructTypeStorage,
1155 ::mlir::TypeTrait::IsMutable> {
1158 StringAttr name, Location loc);
1188 struct DenseMapInfo<
circt::moore::Range> {
1201 #define GET_TYPEDEF_CLASSES
1202 #include "circt/Dialect/Moore/MooreTypes.h.inc"
assert(baseType &&"element must be base type")
static int64_t size(hw::ArrayType mType, capnp::schema::Field::Reader cField)
Returns the expected size of an array (capnp list) in 64-bit words.
static ChandleType get(MLIRContext *context)
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.
bool isBaseExplicit() const
Returns whether the base type was explicitly specified by the user.
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 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.
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.
A packed range dimension, like [a:b].
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.
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.
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 PackedUnsizedDim get(PackedType inner)
StringRef getKeyword() const
Get the keyword (like bit) for this type.
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 StringType get(MLIRContext *context)
An unpacked array dimension, like [a].
static UnpackedArrayDim get(UnpackedType inner, unsigned size)
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.
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.
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.
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 UnpackedRangeDim get(UnpackedType inner, Range range)
An unpacked named type. See NamedTypeBase for details.
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 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 VoidType get(MLIRContext *context)
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.
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()