CIRCT  19.0.0git
SystemCTypes.h
Go to the documentation of this file.
1 //===- SystemCTypes.h - Declare SystemC 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 SystemC dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_SYSTEMC_SYSTEMCTYPES_H
14 #define CIRCT_DIALECT_SYSTEMC_SYSTEMCTYPES_H
15 
17 #include "mlir/IR/Attributes.h"
18 #include "mlir/IR/Types.h"
19 
20 namespace circt {
21 namespace systemc {
22 // Forward declarations.
23 class IntBaseType;
24 class UIntBaseType;
25 class IntType;
26 class UIntType;
27 class BigIntType;
28 class BigUIntType;
29 class SignedType;
30 class UnsignedType;
31 class BitVectorBaseType;
32 class BitVectorType;
33 class LogicVectorBaseType;
34 class LogicVectorType;
35 
36 namespace detail {
37 // Forward declarations.
38 struct IntegerWidthStorage;
39 
40 /// A struct containing minimal information for a systemc module port. Thus, can
41 /// be used as parameter in attributes or types.
42 struct PortInfo {
43  mlir::StringAttr name;
44  mlir::Type type;
45 };
46 } // namespace detail
47 
48 /// Get the type wrapped by a signal or port (in, inout, out) type.
49 Type getSignalBaseType(Type type);
50 
51 /// Return the bitwidth of a type. SystemC types with a dynamic bit-width and
52 /// unsupported types result in a None return value.
53 std::optional<size_t> getBitWidth(Type type);
54 
55 //===----------------------------------------------------------------------===//
56 // Integer types
57 //===----------------------------------------------------------------------===//
58 
59 /// This provides a common base class for all SystemC integers.
60 /// It represents the sc_value_base class described in IEEE 1666-2011 §7.4.
61 /// Note that this is an abstract type that cannot be instantiated but can only
62 /// be used as a base class and for type checks.
63 class ValueBaseType : public Type {
64 public:
65  static bool classof(Type type) {
66  return llvm::isa<SignedType, UnsignedType, IntBaseType, UIntBaseType,
68  }
69 
70  bool isSigned() { return mlir::isa<SignedType, IntBaseType>(*this); }
71 
72 protected:
73  using Type::Type;
74 };
75 
76 /// Represents a limited word-length signed integer in SystemC as described in
77 /// IEEE 1666-2011 §7.5.2. The word-length is not known statically, but is
78 /// constant over the lifetime of the value. The maximum supported bit-width
79 /// is 64 bits such that it can be stored in native C integers. It is the base
80 /// class of 'IntType'.
82  : public Type::TypeBase<IntBaseType, ValueBaseType, DefaultTypeStorage> {
83 public:
84  static bool classof(Type type) {
85  return type.getTypeID() == getTypeID() || llvm::isa<IntType>(type);
86  }
87  static IntBaseType get(MLIRContext *context);
88  static constexpr StringLiteral getMnemonic() { return "int_base"; }
89 
90  static constexpr StringLiteral name = "systemc.int_base";
91 
92 protected:
93  using Base::Base;
94 };
95 
96 /// Represents a limited word-length signed integer in SystemC as described in
97 /// IEEE 1666-2011 §7.5.4. It is allowed at all places where 'IntBaseType' is
98 /// allowed as it inherits and preserved all its functionality as described in
99 /// IEEE 1666-2011 §7.5.4.1. The difference is that the bit-width has to be
100 /// passed as a template argument and is thus known at compile-time.
101 class IntType : public Type::TypeBase<IntType, IntBaseType,
102  systemc::detail::IntegerWidthStorage> {
103 public:
104  static IntType get(MLIRContext *context, unsigned width);
105  unsigned getWidth();
106  static constexpr StringLiteral getMnemonic() { return "int"; }
107 
108  static constexpr StringLiteral name = "systemc.int";
109 
110 protected:
111  using Base::Base;
112 };
113 
114 /// Represents a limited word-length unsigned integer in SystemC as described in
115 /// IEEE 1666-2011 §7.5.3. The word-length is not known statically, but is
116 /// constant over the lifetime of the value. The maximum supported bit-width
117 /// is 64 bits such that it can be stored in native C integers. It is the base
118 /// class of 'UIntType'.
120  : public Type::TypeBase<UIntBaseType, ValueBaseType, DefaultTypeStorage> {
121 public:
122  static bool classof(Type type) {
123  return type.getTypeID() == getTypeID() || llvm::isa<UIntType>(type);
124  }
125  static UIntBaseType get(MLIRContext *context);
126 
127  static constexpr StringLiteral getMnemonic() { return "uint_base"; }
128 
129  static constexpr StringLiteral name = "systemc.uint_base";
130 
131 protected:
132  using Base::Base;
133 };
134 
135 /// Represents a limited word-length unsigned integer in SystemC as described in
136 /// IEEE 1666-2011 §7.5.5. It is allowed at all places where 'IntBaseType' is
137 /// allowed as it inherits and preserved all its functionality as described in
138 /// IEEE 1666-2011 §7.5.5.1. The difference is that the bit-width has to be
139 /// passed as a template argument and is thus known at compile-time.
140 class UIntType : public Type::TypeBase<UIntType, UIntBaseType,
141  systemc::detail::IntegerWidthStorage> {
142 public:
143  static UIntType get(MLIRContext *context, unsigned width);
144  unsigned getWidth();
145 
146  static constexpr StringLiteral getMnemonic() { return "uint"; }
147 
148  static constexpr StringLiteral name = "systemc.uint";
149 
150 protected:
151  using Base::Base;
152 };
153 
154 /// Represents a finite word-length signed integer in SystemC as described in
155 /// IEEE 1666-2011 §7.6.3. The word-length is not known statically, but is
156 /// constant over the lifetime of the value. It supports arbitrary precision
157 /// integers, but is often limited to 512 bits (implementation dependent) for
158 /// performance reasons. It is the base class of 'BigIntType'.
160  : public Type::TypeBase<SignedType, ValueBaseType, DefaultTypeStorage> {
161 public:
162  static bool classof(Type type) {
163  return type.getTypeID() == getTypeID() || llvm::isa<BigIntType>(type);
164  }
165  static SignedType get(MLIRContext *context);
166 
167  static constexpr StringLiteral getMnemonic() { return "signed"; }
168 
169  static constexpr StringLiteral name = "systemc.signed";
170 
171 protected:
172  using Base::Base;
173 };
174 
175 /// Represents a finite word-length signed integer in SystemC as described in
176 /// IEEE 1666-2011 §7.6.5. It is allowed at all places where 'SignedType' is
177 /// allowed as it inherits and preserved all its functionality as described in
178 /// IEEE 1666-2011 §7.6.5.1. The difference is that the bit-width has to be
179 /// passed as a template argument and is thus known at compile-time.
180 class BigIntType : public Type::TypeBase<BigIntType, SignedType,
181  systemc::detail::IntegerWidthStorage> {
182 public:
183  static BigIntType get(MLIRContext *context, unsigned width);
184  unsigned getWidth();
185  static constexpr StringLiteral getMnemonic() { return "bigint"; }
186 
187  static constexpr StringLiteral name = "systemc.bigint";
188 
189 protected:
190  using Base::Base;
191 };
192 
193 /// Represents a finite word-length unsigned integer in SystemC as described in
194 /// IEEE 1666-2011 §7.6.4. The word-length is not known statically, but is
195 /// constant over the lifetime of the value. It supports arbitrary precision
196 /// integers, but is often limited to 512 bits (implementation dependent) for
197 /// performance reasons. It is the base class of 'BigUIntType'.
199  : public Type::TypeBase<UnsignedType, ValueBaseType, DefaultTypeStorage> {
200 public:
201  static bool classof(Type type) {
202  return type.getTypeID() == getTypeID() || llvm::isa<BigUIntType>(type);
203  }
204  static UnsignedType get(MLIRContext *context);
205 
206  static constexpr StringLiteral getMnemonic() { return "unsigned"; }
207 
208  static constexpr StringLiteral name = "systemc.unsigned";
209 
210 protected:
211  using Base::Base;
212 };
213 
214 /// Represents a finite word-length unsigned integer in SystemC as described in
215 /// IEEE 1666-2011 §7.6.6. It is allowed at all places where 'UnsignedType' is
216 /// allowed as it inherits and preserved all its functionality as described in
217 /// IEEE 1666-2011 §7.6.6.1. The difference is that the bit-width has to be
218 /// passed as a template argument and is thus known at compile-time.
220  : public Type::TypeBase<BigUIntType, UnsignedType,
221  systemc::detail::IntegerWidthStorage> {
222 public:
223  static BigUIntType get(MLIRContext *context, unsigned width);
224  unsigned getWidth();
225 
226  static constexpr StringLiteral getMnemonic() { return "biguint"; }
227 
228  static constexpr StringLiteral name = "systemc.biguint";
229 
230 protected:
231  using Base::Base;
232 };
233 
234 //===----------------------------------------------------------------------===//
235 // Bit-vector types
236 //===----------------------------------------------------------------------===//
237 
238 /// Represents a finite word-length bit vector in SystemC as described in
239 /// IEEE 1666-2011 §7.9.3. The word-length is not known statically, but is
240 /// constant over the lifetime of the value. It is the base class of
241 /// 'BitVectorType'.
243  : public Type::TypeBase<BitVectorBaseType, Type, DefaultTypeStorage> {
244 public:
245  static bool classof(Type type) {
246  return type.getTypeID() == getTypeID() || llvm::isa<BitVectorType>(type);
247  }
248  static BitVectorBaseType get(MLIRContext *context);
249  static constexpr StringLiteral getMnemonic() { return "bv_base"; }
250 
251  static constexpr StringLiteral name = "systemc.bv_base";
252 
253 protected:
254  using Base::Base;
255 };
256 
257 /// Represents a finite word-length bit vector in SystemC as described in
258 /// IEEE 1666-2011 §7.9.5. It is allowed at all places where 'BitVectorBaseType'
259 /// is allowed as it inherits and preserved all its functionality as described
260 /// in IEEE 1666-2011 §7.9.5.1. The difference is that the bit-width has to be
261 /// passed as a template argument and is thus known at compile-time.
263  : public Type::TypeBase<BitVectorType, BitVectorBaseType,
264  systemc::detail::IntegerWidthStorage> {
265 public:
266  static BitVectorType get(MLIRContext *context, unsigned width);
267  unsigned getWidth();
268 
269  static constexpr StringLiteral getMnemonic() { return "bv"; }
270 
271  static constexpr StringLiteral name = "systemc.bv";
272 
273 protected:
274  using Base::Base;
275 };
276 
277 /// Represents a finite word-length bit vector in SystemC as described in
278 /// IEEE 1666-2011 §7.9.4. The word-length is not known statically, but is
279 /// constant over the lifetime of the value. Each bit is of type 'LogicType'
280 /// and thus four-valued. It is the base class of 'LogicVectorType'.
282  : public Type::TypeBase<LogicVectorBaseType, Type, DefaultTypeStorage> {
283 public:
284  static bool classof(Type type) {
285  return type.getTypeID() == getTypeID() || llvm::isa<LogicVectorType>(type);
286  }
287  static LogicVectorBaseType get(MLIRContext *context);
288  static constexpr StringLiteral getMnemonic() { return "lv_base"; }
289 
290  static constexpr StringLiteral name = "systemc.lv_base";
291 
292 protected:
293  using Base::Base;
294 };
295 
296 /// Represents a finite word-length bit vector (of four-state values) in SystemC
297 /// as described in IEEE 1666-2011 §7.9.6. It is allowed at all places where
298 /// 'LogicVectorBaseType' is allowed as it inherits and preserved all its
299 /// functionality as described in IEEE 1666-2011 §7.9.6.1. The difference is
300 /// that the bit-width has to be passed as a template argument and is thus known
301 /// at compile-time.
303  : public Type::TypeBase<LogicVectorType, LogicVectorBaseType,
304  systemc::detail::IntegerWidthStorage> {
305 public:
306  static LogicVectorType get(MLIRContext *context, unsigned width);
307  unsigned getWidth();
308 
309  static constexpr StringLiteral getMnemonic() { return "lv"; }
310 
311  static constexpr StringLiteral name = "systemc.lv";
312 
313 protected:
314  using Base::Base;
315 };
316 
317 } // namespace systemc
318 } // namespace circt
319 
320 // Include generated types.
321 #define GET_TYPEDEF_CLASSES
322 #include "circt/Dialect/SystemC/SystemCTypes.h.inc"
323 
324 #endif // CIRCT_DIALECT_SYSTEMC_SYSTEMCTYPES_H
int32_t width
Definition: FIRRTL.cpp:36
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:181
static constexpr StringLiteral name
Definition: SystemCTypes.h:187
static BigIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:185
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:221
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:226
static BigUIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral name
Definition: SystemCTypes.h:228
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:243
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:249
static BitVectorBaseType get(MLIRContext *context)
static constexpr StringLiteral name
Definition: SystemCTypes.h:251
static bool classof(Type type)
Definition: SystemCTypes.h:245
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:264
static constexpr StringLiteral name
Definition: SystemCTypes.h:271
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:269
static BitVectorType get(MLIRContext *context, unsigned width)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:82
static constexpr StringLiteral name
Definition: SystemCTypes.h:90
static bool classof(Type type)
Definition: SystemCTypes.h:84
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:88
static IntBaseType get(MLIRContext *context)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:102
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:106
static IntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral name
Definition: SystemCTypes.h:108
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:282
static LogicVectorBaseType get(MLIRContext *context)
static bool classof(Type type)
Definition: SystemCTypes.h:284
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:288
static constexpr StringLiteral name
Definition: SystemCTypes.h:290
Represents a finite word-length bit vector (of four-state values) in SystemC as described in IEEE 166...
Definition: SystemCTypes.h:304
static LogicVectorType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:309
static constexpr StringLiteral name
Definition: SystemCTypes.h:311
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:160
static SignedType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:167
static constexpr StringLiteral name
Definition: SystemCTypes.h:169
static bool classof(Type type)
Definition: SystemCTypes.h:162
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:120
static UIntBaseType get(MLIRContext *context)
static bool classof(Type type)
Definition: SystemCTypes.h:122
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:127
static constexpr StringLiteral name
Definition: SystemCTypes.h:129
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:141
static UIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:146
static constexpr StringLiteral name
Definition: SystemCTypes.h:148
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
Definition: SystemCTypes.h:199
static bool classof(Type type)
Definition: SystemCTypes.h:201
static constexpr StringLiteral getMnemonic()
Definition: SystemCTypes.h:206
static constexpr StringLiteral name
Definition: SystemCTypes.h:208
static UnsignedType get(MLIRContext *context)
This provides a common base class for all SystemC integers.
Definition: SystemCTypes.h:63
static bool classof(Type type)
Definition: SystemCTypes.h:65
StringAttr getTypeID(Type t)
Definition: ESIPasses.cpp:26
Type getSignalBaseType(Type type)
Get the type wrapped by a signal or port (in, inout, out) type.
std::optional< size_t > getBitWidth(Type type)
Return the bitwidth of a type.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Integer Type Storage and Uniquing.
A struct containing minimal information for a systemc module port.
Definition: SystemCTypes.h:42