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