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