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