CIRCT 20.0.0git
Loading...
Searching...
No Matches
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
20namespace circt {
21namespace systemc {
22// Forward declarations.
23class IntBaseType;
24class UIntBaseType;
25class IntType;
26class UIntType;
27class BigIntType;
28class BigUIntType;
29class SignedType;
30class UnsignedType;
31class BitVectorBaseType;
32class BitVectorType;
33class LogicVectorBaseType;
34class LogicVectorType;
35
36namespace detail {
37// Forward declarations.
39
40/// A struct containing minimal information for a systemc module port. Thus, can
41/// be used as parameter in attributes or types.
42struct 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.
49Type 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.
53std::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.
63class ValueBaseType : public Type {
64public:
65 static bool classof(Type type) {
68 }
69
70 bool isSigned() { return mlir::isa<SignedType, IntBaseType>(*this); }
71
72protected:
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> {
83public:
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
92protected:
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.
101class IntType : public Type::TypeBase<IntType, IntBaseType,
102 systemc::detail::IntegerWidthStorage> {
103public:
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
110protected:
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> {
121public:
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
131protected:
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.
140class UIntType : public Type::TypeBase<UIntType, UIntBaseType,
141 systemc::detail::IntegerWidthStorage> {
142public:
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
150protected:
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> {
161public:
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
171protected:
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.
180class BigIntType : public Type::TypeBase<BigIntType, SignedType,
181 systemc::detail::IntegerWidthStorage> {
182public:
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
189protected:
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> {
200public:
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
210protected:
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> {
222public:
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
230protected:
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> {
244public:
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
253protected:
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> {
265public:
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
273protected:
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> {
283public:
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
292protected:
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> {
305public:
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
313protected:
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
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral name
static BigIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static BigUIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral name
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static BitVectorBaseType get(MLIRContext *context)
static constexpr StringLiteral name
static bool classof(Type type)
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral name
static constexpr StringLiteral getMnemonic()
static BitVectorType get(MLIRContext *context, unsigned width)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral name
static bool classof(Type type)
static constexpr StringLiteral getMnemonic()
static IntBaseType get(MLIRContext *context)
Represents a limited word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static constexpr StringLiteral getMnemonic()
static IntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral name
Represents a finite word-length bit vector in SystemC as described in IEEE 1666-2011 §7....
static LogicVectorBaseType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
Represents a finite word-length bit vector (of four-state values) in SystemC as described in IEEE 166...
static LogicVectorType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
Represents a finite word-length signed integer in SystemC as described in IEEE 1666-2011 §7....
static SignedType get(MLIRContext *context)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
static bool classof(Type type)
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static UIntBaseType get(MLIRContext *context)
static bool classof(Type type)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
Represents a limited word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static UIntType get(MLIRContext *context, unsigned width)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
Represents a finite word-length unsigned integer in SystemC as described in IEEE 1666-2011 §7....
static bool classof(Type type)
static constexpr StringLiteral getMnemonic()
static constexpr StringLiteral name
static UnsignedType get(MLIRContext *context)
This provides a common base class for all SystemC integers.
static bool classof(Type type)
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.
Integer Type Storage and Uniquing.
A struct containing minimal information for a systemc module port.