CIRCT 24.0.0git
Loading...
Searching...
No Matches
MooreTypes.h
Go to the documentation of this file.
1//===- MooreTypes.h - Declare Moore dialect types ----------------*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the types for the Moore dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_MOORE_MOORETYPES_H
14#define CIRCT_DIALECT_MOORE_MOORETYPES_H
15
16#include "circt/Support/LLVM.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"
21#include "mlir/Interfaces/MemorySlotInterfaces.h"
22#include <variant>
23
24namespace circt {
25namespace moore {
26
27class ArrayType;
28class AssocArrayType;
29class ChandleType;
30class EventType;
31class IntType;
32class NetType;
33class OpenArrayType;
34class OpenUnpackedArrayType;
35class PackedType;
36class QueueType;
37class RealType;
38class RefType;
39class StringType;
40class StructType;
41class TimeType;
42class UnionType;
43class UnpackedType;
44class UnpackedArrayType;
45class UnpackedStructType;
46class UnpackedUnionType;
47class VoidType;
48class ClassHandleType;
49
50/// The number of values each bit of a type can assume.
51enum class Domain {
52 /// Two-valued types such as `bit` or `int`.
54 /// Four-valued types such as `logic` or `integer`.
56};
57
58/// The type of floating point / real number behind a RealType
59enum class RealWidth {
60 /// A standard 32-Bit floating point number ("float")
61 f32 = 32,
62 /// A 64-bit double-precision floation point number ("double")
63 f64 = 64
64};
65
66/// Check if a type is an `IntType` type of the given width.
67bool isIntType(Type type, unsigned width);
68/// Check if a type is an `IntType` type of the given domain.
69bool isIntType(Type type, Domain domain);
70/// Check if a type is an `IntType` type of the given width and domain.
71bool isIntType(Type type, unsigned width, Domain domain);
72/// Check if a type is a `RealType` type of the given width.
73bool isRealType(Type type, unsigned width);
74
75//===----------------------------------------------------------------------===//
76// Unpacked Type
77//===----------------------------------------------------------------------===//
78
79/// An unpacked SystemVerilog type.
80///
81/// Unpacked types are a second level of types in SystemVerilog. They extend a
82/// core unpacked type with a variety of unpacked dimensions, depending on which
83/// syntactic construct generated the type (variable or otherwise). The core
84/// unpacked types are:
85///
86/// - Packed types
87/// - Non-integer types: `shortreal`, `real`, `realtime`
88/// - Unpacked structs and unions
89/// - `string`, `chandle`, `event`
90/// - Virtual interfaces
91/// - Class types
92/// - Covergroups
93/// - Unpacked named types
94/// - Unpacked type references
95///
96/// The unpacked dimensions are:
97///
98/// - Unsized (`[]`)
99/// - Arrays (`[x]`)
100/// - Ranges (`[x:y]`)
101/// - Associative (`[T]` or `[*]`)
102/// - Queues (`[$]` or `[$:x]`)
103class UnpackedType : public Type {
104public:
105 static bool classof(Type type) {
106 return llvm::isa<PackedType, StringType, ChandleType, EventType, RealType,
107 UnpackedArrayType, OpenUnpackedArrayType, AssocArrayType,
108 QueueType, UnpackedStructType, UnpackedUnionType, RefType,
109 NetType, ClassHandleType>(type);
110 }
111
112 /// Get the value domain of this type.
113 Domain getDomain() const;
114
115 /// Get the size of this type in bits.
116 ///
117 /// Returns `None` if any of the type's dimensions is unsized, associative, or
118 /// a queue, or the core type itself has no known size.
119 std::optional<unsigned> getBitSize() const;
120
121 // Support parsing and printing of unpacked types in their prefix-stripped
122 // form.
123 static Type parse(mlir::AsmParser &odsParser);
124 void print(mlir::AsmPrinter &odsPrinter) const;
125
126protected:
127 using Type::Type;
128};
129
130//===----------------------------------------------------------------------===//
131// Packed Type
132//===----------------------------------------------------------------------===//
133
134/// A packed SystemVerilog type.
135///
136/// Packed types are the core types of SystemVerilog. They combine a core packed
137/// type with an optional sign and zero or more packed dimensions. The core
138/// packed types are:
139///
140/// - Integer vector types: `bit`, `logic`, `reg`
141/// - Integer atom types: `byte`, `shortint`, `int`, `longint`, `integer`,
142/// `time`
143/// - Packed structs and unions
144/// - Enums
145/// - Packed named types
146/// - Packed type references
147///
148/// The packed dimensions can be:
149///
150/// - Unsized (`[]`)
151/// - Ranges (`[x:y]`)
152///
153/// Note that every packed type is also a valid unpacked type. But unpacked
154/// types are *not* valid packed types.
155class PackedType : public UnpackedType {
156public:
157 static bool classof(Type type) {
158 return llvm::isa<VoidType, IntType, ArrayType, OpenArrayType, StructType,
159 UnionType, TimeType>(type);
160 }
161
162 /// Get the value domain of this type.
163 Domain getDomain() const;
164
165 /// Get the size of this type in bits.
166 ///
167 /// Returns `None` if any of the type's dimensions is unsized.
168 std::optional<unsigned> getBitSize() const;
169
170 /// Get the simple bit vector type equivalent to this packed type. Returns
171 /// null if the type does not have a known bit size.
172 IntType getSimpleBitVector() const;
173
174 /// Check if this is a `TimeType`, or an aggregate that contains a nested
175 /// `TimeType`.
176 bool containsTimeType() const;
177
178protected:
179 using UnpackedType::UnpackedType;
180};
181
182//===----------------------------------------------------------------------===//
183// Wrapper Type
184//===----------------------------------------------------------------------===//
185
186class WrapperType : public UnpackedType {
187public:
188 static bool classof(Type type) { return llvm::isa<RefType, NetType>(type); }
189
190 /// Get the wrapped type.
192
193 /// Get a wrapper of the same kind around a different nested type.
194 WrapperType withNestedType(UnpackedType nestedType) const;
195
196protected:
197 using UnpackedType::UnpackedType;
198};
199
200//===----------------------------------------------------------------------===//
201// Struct Members
202//===----------------------------------------------------------------------===//
203
204/// A member of a struct.
206 /// The name of this member.
207 StringAttr name;
208 /// The type of this member.
210
211 bool operator==(const StructLikeMember &other) const {
212 return name == other.name && type == other.type;
213 }
214};
215
216// NOLINTNEXTLINE(readability-identifier-naming)
217inline llvm::hash_code hash_value(const StructLikeMember &x) {
218 return llvm::hash_combine(x.name, x.type);
219}
220
221} // namespace moore
222} // namespace circt
223
224// Include generated types.
225#define GET_TYPEDEF_CLASSES
226#include "circt/Dialect/Moore/MooreTypes.h.inc"
227
228#endif // CIRCT_DIALECT_MOORE_MOORETYPES_H
A packed SystemVerilog type.
Definition MooreTypes.h:155
bool containsTimeType() const
Check if this is a TimeType, or an aggregate that contains a nested TimeType.
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)
Definition MooreTypes.h:157
IntType getSimpleBitVector() const
Get the simple bit vector type equivalent to this packed type.
An unpacked SystemVerilog type.
Definition MooreTypes.h:103
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)
Definition MooreTypes.h:105
static Type parse(mlir::AsmParser &odsParser)
void print(mlir::AsmPrinter &odsPrinter) const
static bool classof(Type type)
Definition MooreTypes.h:188
UnpackedType getNestedType() const
Get the wrapped type.
WrapperType withNestedType(UnpackedType nestedType) const
Get a wrapper of the same kind around a different nested type.
llvm::hash_code hash_value(const StructLikeMember &x)
Definition MooreTypes.h:217
bool isRealType(Type type, unsigned width)
Check if a type is a RealType type of the given width.
Domain
The number of values each bit of a type can assume.
Definition MooreTypes.h:51
@ FourValued
Four-valued types such as logic or integer.
Definition MooreTypes.h:55
@ TwoValued
Two-valued types such as bit or int.
Definition MooreTypes.h:53
bool isIntType(Type type, unsigned width)
Check if a type is an IntType type of the given width.
RealWidth
The type of floating point / real number behind a RealType.
Definition MooreTypes.h:59
@ f32
A standard 32-Bit floating point number ("float").
Definition MooreTypes.h:61
@ f64
A 64-bit double-precision floation point number ("double").
Definition MooreTypes.h:63
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
A member of a struct.
Definition MooreTypes.h:205
UnpackedType type
The type of this member.
Definition MooreTypes.h:209
StringAttr name
The name of this member.
Definition MooreTypes.h:207
bool operator==(const StructLikeMember &other) const
Definition MooreTypes.h:211