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