CIRCT  19.0.0git
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 <variant>
22 
23 namespace circt {
24 namespace moore {
25 
26 /// The number of values each bit of a type can assume.
27 enum class Domain {
28  /// Two-valued types such as `bit` or `int`.
29  TwoValued,
30  /// Four-valued types such as `logic` or `integer`.
31  FourValued,
32 };
33 
34 /// Whether a type is signed or unsigned.
35 enum class Sign {
36  /// An `unsigned` type.
37  Unsigned,
38  /// A `signed` type.
39  Signed,
40 };
41 
42 /// Map a `Sign` to the corresponding keyword.
43 StringRef getKeywordFromSign(const Sign &sign);
44 /// Map the keywords `unsigned` and `signed` to the corresponding `Sign`.
45 std::optional<Sign> getSignFromKeyword(StringRef keyword);
46 
47 template <typename Os>
48 Os &operator<<(Os &os, const Sign &sign) {
49  os << getKeywordFromSign(sign);
50  return os;
51 }
52 
53 /// Which side is greater in a range `[a:b]`.
54 enum class RangeDir {
55  /// `a < b`
56  Up,
57  /// `a >= b`
58  Down,
59 };
60 
61 /// The `[a:b]` part in a vector/array type such as `logic [a:b]`.
62 struct Range {
63  /// The total number of bits, given as `|a-b|+1`.
64  unsigned size;
65  /// The direction of the vector, i.e. whether `a > b` or `a < b`.
67  /// The starting offset of the range.
68  int offset;
69 
70  /// Construct a range `[size-1:0]`.
71  explicit Range(unsigned size) : Range(size, RangeDir::Down, 0) {}
72 
73  /// Construct a range `[offset+size-1:offset]` if `dir` is `Down`, or
74  /// `[offset:offset+size-1]` if `dir` is `Up`.
75  Range(unsigned size, RangeDir dir, int offset)
76  : size(size), dir(dir), offset(offset) {}
77 
78  /// Construct a range [left:right]`, with the direction inferred as `Down` if
79  /// `left >= right`, or `Up` otherwise.
80  Range(int left, int right) {
81  if (left >= right) {
82  size = left + 1 - right;
84  offset = right;
85  } else {
86  size = right + 1 - left;
87  dir = RangeDir::Up;
88  offset = left;
89  }
90  }
91 
92  bool operator==(const Range &other) const {
93  return size == other.size && dir == other.dir && offset == other.offset;
94  }
95 
96  /// Get the `$left` dimension.
97  int left() const { return dir == RangeDir::Up ? low() : high(); }
98  /// Get the `$right` dimension.
99  int right() const { return dir == RangeDir::Up ? high() : low(); }
100  /// Get the `$low` dimension.
101  int low() const { return offset; }
102  /// Get the `$high` dimension.
103  int high() const { return offset + size - 1; }
104  /// Get the `$increment` size.
105  int increment() const { return dir == RangeDir::Up ? 1 : -1; }
106 
107  /// Format this range as a string.
108  std::string toString() const {
109  std::string buffer;
110  llvm::raw_string_ostream(buffer) << *this;
111  return buffer;
112  }
113 };
114 
115 // NOLINTNEXTLINE(readability-identifier-naming)
116 inline llvm::hash_code hash_value(const Range &x) {
117  return llvm::hash_combine(x.size, x.dir, x.offset);
118 }
119 
120 template <typename Os>
121 Os &operator<<(Os &os, const Range &range) {
122  os << range.left() << ":" << range.right();
123  return os;
124 }
125 
126 class PackedType;
127 
128 namespace detail {
129 struct DimStorage;
130 struct UnsizedDimStorage;
131 struct RangeDimStorage;
132 struct SizedDimStorage;
133 struct AssocDimStorage;
134 struct StructTypeStorage;
135 } // namespace detail
136 
137 /// Base class for all SystemVerilog types in the Moore dialect.
138 class SVType : public Type {
139 protected:
140  using Type::Type;
141 };
142 
143 //===----------------------------------------------------------------------===//
144 // Unpacked Type
145 //===----------------------------------------------------------------------===//
146 
147 class PackedType;
148 class StringType;
149 class ChandleType;
150 class EventType;
151 class RealType;
152 class UnpackedDim;
153 class UnpackedStructType;
154 
155 /// An unpacked SystemVerilog type.
156 ///
157 /// Unpacked types are a second level of types in SystemVerilog. They extend a
158 /// core unpacked type with a variety of unpacked dimensions, depending on which
159 /// syntactic construct generated the type (variable or otherwise). The core
160 /// unpacked types are:
161 ///
162 /// - Packed types
163 /// - Non-integer types: `shortreal`, `real`, `realtime`
164 /// - Unpacked structs and unions
165 /// - `string`, `chandle`, `event`
166 /// - Virtual interfaces
167 /// - Class types
168 /// - Covergroups
169 /// - Unpacked named types
170 /// - Unpacked type references
171 ///
172 /// The unpacked dimensions are:
173 ///
174 /// - Unsized (`[]`)
175 /// - Arrays (`[x]`)
176 /// - Ranges (`[x:y]`)
177 /// - Associative (`[T]` or `[*]`)
178 /// - Queues (`[$]` or `[$:x]`)
179 class UnpackedType : public SVType {
180 public:
181  static bool classof(Type type) {
182  return llvm::isa<PackedType>(type) || llvm::isa<StringType>(type) ||
183  llvm::isa<ChandleType>(type) || llvm::isa<EventType>(type) ||
184  llvm::isa<RealType>(type) || llvm::isa<UnpackedDim>(type) ||
185  llvm::isa<UnpackedStructType>(type);
186  }
187 
188  /// Get the value domain of this type.
189  Domain getDomain() const;
190 
191  /// Get the size of this type in bits.
192  ///
193  /// Returns `None` if any of the type's dimensions is unsized, associative, or
194  /// a queue, or the core type itself has no known size.
195  std::optional<unsigned> getBitSize() const;
196 
197 protected:
198  using SVType::SVType;
199 };
200 
201 //===----------------------------------------------------------------------===//
202 // Packed Type
203 //===----------------------------------------------------------------------===//
204 
205 class VoidType;
206 class IntType;
207 class PackedDim;
208 class PackedStructType;
209 
210 /// A packed SystemVerilog type.
211 ///
212 /// Packed types are the core types of SystemVerilog. They combine a core packed
213 /// type with an optional sign and zero or more packed dimensions. The core
214 /// packed types are:
215 ///
216 /// - Integer vector types: `bit`, `logic`, `reg`
217 /// - Integer atom types: `byte`, `shortint`, `int`, `longint`, `integer`,
218 /// `time`
219 /// - Packed structs and unions
220 /// - Enums
221 /// - Packed named types
222 /// - Packed type references
223 ///
224 /// The packed dimensions can be:
225 ///
226 /// - Unsized (`[]`)
227 /// - Ranges (`[x:y]`)
228 ///
229 /// Note that every packed type is also a valid unpacked type. But unpacked
230 /// types are *not* valid packed types.
231 class PackedType : public UnpackedType {
232 public:
233  static bool classof(Type type) {
234  return llvm::isa<VoidType>(type) || llvm::isa<IntType>(type) ||
235  llvm::isa<PackedDim>(type) || llvm::isa<PackedStructType>(type);
236  }
237 
238  /// Get the value domain of this type.
239  Domain getDomain() const;
240 
241  /// Get the size of this type in bits.
242  ///
243  /// Returns `None` if any of the type's dimensions is unsized.
244  std::optional<unsigned> getBitSize() const;
245 
246 protected:
247  using UnpackedType::UnpackedType;
248 };
249 
250 //===----------------------------------------------------------------------===//
251 // Packed Dimensions
252 //===----------------------------------------------------------------------===//
253 
254 class PackedRangeDim;
255 class PackedUnsizedDim;
256 
257 /// A packed dimension.
258 class PackedDim : public PackedType {
259 public:
260  static bool classof(Type type) {
261  return llvm::isa<PackedRangeDim>(type) || llvm::isa<PackedUnsizedDim>(type);
262  }
263 
264  /// Get the element type of the dimension. This is the `x` in `x[a:b]`.
265  PackedType getInner() const;
266 
267  /// Get the dimension's range, or `None` if it is unsized.
268  std::optional<Range> getRange() const;
269  /// Get the dimension's size, or `None` if it is unsized.
270  std::optional<unsigned> getSize() const;
271 
272 protected:
273  using PackedType::PackedType;
274  const detail::DimStorage *getImpl() const;
275 };
276 
277 /// A packed unsized dimension, like `[]`.
278 class PackedUnsizedDim : public Type::TypeBase<PackedUnsizedDim, PackedDim,
279  detail::UnsizedDimStorage,
280  ::mlir::TypeTrait::IsMutable> {
281 public:
282  static PackedUnsizedDim get(PackedType inner);
283 
284  static constexpr StringLiteral name = "moore.packed_unsized_dim";
285 
286 protected:
287  using Base::Base;
288  friend struct detail::DimStorage;
289 };
290 
291 /// A packed range dimension, like `[a:b]`.
293  : public Type::TypeBase<PackedRangeDim, PackedDim, detail::RangeDimStorage,
294  ::mlir::TypeTrait::IsMutable> {
295 public:
296  static PackedRangeDim get(PackedType inner, Range range);
297 
298  /// Get a packed range with arguments forwarded to the `Range` constructor.
299  /// See `Range::Range` for details.
300  template <typename... Args>
301  static PackedRangeDim get(PackedType inner, Args... args) {
302  return get(inner, Range(args...));
303  }
304 
305  /// Get the range of this dimension.
306  Range getRange() const;
307 
308  /// Allow implicit casts from `PackedRangeDim` to the actual range.
309  operator Range() const { return getRange(); }
310 
311  static constexpr StringLiteral name = "moore.packed_range_dim";
312 
313 protected:
314  using Base::Base;
315  friend struct detail::DimStorage;
316 };
317 
318 //===----------------------------------------------------------------------===//
319 // Unpacked Dimensions
320 //===----------------------------------------------------------------------===//
321 
322 class UnpackedUnsizedDim;
323 class UnpackedArrayDim;
324 class UnpackedRangeDim;
325 class UnpackedAssocDim;
326 class UnpackedQueueDim;
327 
328 /// An unpacked dimension.
329 class UnpackedDim : public UnpackedType {
330 public:
331  static bool classof(Type type) {
332  return llvm::isa<UnpackedUnsizedDim>(type) ||
333  llvm::isa<UnpackedArrayDim>(type) ||
334  llvm::isa<UnpackedRangeDim>(type) ||
335  llvm::isa<UnpackedAssocDim>(type) ||
336  llvm::isa<UnpackedQueueDim>(type);
337  }
338 
339  /// Get the element type of the dimension. This is the `x` in `x[a:b]`.
340  UnpackedType getInner() const;
341 
342 protected:
343  using UnpackedType::UnpackedType;
344  const detail::DimStorage *getImpl() const;
345 };
346 
347 /// An unpacked unsized dimension, like `[]`.
349  : public Type::TypeBase<UnpackedUnsizedDim, UnpackedDim,
350  detail::UnsizedDimStorage,
351  ::mlir::TypeTrait::IsMutable> {
352 public:
353  static UnpackedUnsizedDim get(UnpackedType inner);
354 
355  static constexpr StringLiteral name = "moore.unpacked_unsized_dim";
356 
357 protected:
358  using Base::Base;
359  friend struct detail::DimStorage;
360 };
361 
362 /// An unpacked array dimension, like `[a]`.
363 class UnpackedArrayDim : public Type::TypeBase<UnpackedArrayDim, UnpackedDim,
364  detail::SizedDimStorage,
365  ::mlir::TypeTrait::IsMutable> {
366 public:
367  static UnpackedArrayDim get(UnpackedType inner, unsigned size);
368 
369  /// Get the size of the array, i.e. the `a` in `[a]`.
370  unsigned getSize() const;
371 
372  static constexpr StringLiteral name = "moore.unpacked_array_dim";
373 
374 protected:
375  using Base::Base;
376  friend struct detail::DimStorage;
377 };
378 
379 /// An unpacked range dimension, like `[a:b]`.
380 class UnpackedRangeDim : public Type::TypeBase<UnpackedRangeDim, UnpackedDim,
381  detail::RangeDimStorage,
382  ::mlir::TypeTrait::IsMutable> {
383 public:
384  static UnpackedRangeDim get(UnpackedType inner, Range range);
385 
386  /// Get a packed range with arguments forwarded to the `Range` constructor.
387  /// See `Range::Range` for details.
388  template <typename... Args>
389  static UnpackedRangeDim get(UnpackedType inner, Args... args) {
390  return get(inner, Range(args...));
391  }
392 
393  /// Get the range of this dimension.
394  Range getRange() const;
395 
396  /// Allow implicit casts from `UnpackedRangeDim` to the actual range.
397  operator Range() const { return getRange(); }
398 
399  static constexpr StringLiteral name = "moore.unpacked_range_dim";
400 
401 protected:
402  using Base::Base;
403  friend struct detail::DimStorage;
404 };
405 
406 /// An unpacked associative dimension, like `[T]` or `[*]`.
407 ///
408 /// Associative arrays in SystemVerilog can have a concrete index type (`[T]`),
409 /// or a wildcard index type (`[*]`, §7.8.1). The latter is exceptionally
410 /// strange, as it applies only to integer indices, but supports arbitrarily
411 /// sized indices by always removing leading zeros from any index that is used
412 /// in the lookup. This is interesting if a `string` is used to index into such
413 /// an array, because strings are automatically cast to a bit vector of
414 /// equivalent size, which results in a sort-of string key lookup. However, note
415 /// that there are also dedicated semantics for using `string` as the actual
416 /// index type (§7.8.2).
417 ///
418 /// See IEEE 1800-2017 §7.8 "Associative arrays".
419 class UnpackedAssocDim : public Type::TypeBase<UnpackedAssocDim, UnpackedDim,
420  detail::AssocDimStorage,
421  ::mlir::TypeTrait::IsMutable> {
422 public:
423  static UnpackedAssocDim get(UnpackedType inner, UnpackedType indexType = {});
424 
425  /// Get the index type of the associative dimension. This returns either the
426  /// type `T` in a dimension `[T]`, or a null type in a dimension `[*]`.
427  UnpackedType getIndexType() const;
428 
429  static constexpr StringLiteral name = "moore.unpacked_assoc_dim";
430 
431 protected:
432  using Base::Base;
433  friend struct detail::DimStorage;
434 };
435 
436 /// An unpacked queue dimension with optional bound, like `[$]` or `[$:a]`.
437 class UnpackedQueueDim : public Type::TypeBase<UnpackedQueueDim, UnpackedDim,
438  detail::SizedDimStorage,
439  ::mlir::TypeTrait::IsMutable> {
440 public:
441  static UnpackedQueueDim get(UnpackedType inner,
442  std::optional<unsigned> bound = {});
443 
444  /// Get the bound of the queue, i.e. the `a` in `[$:a]`. Returns `None` if the
445  /// queue is unbounded.
446  std::optional<unsigned> getBound() const;
447 
448  static constexpr StringLiteral name = "moore.unpacked_queue_dim";
449 
450 protected:
451  using Base::Base;
452  friend struct detail::DimStorage;
453 };
454 
455 //===----------------------------------------------------------------------===//
456 // Packed and Unpacked Structs
457 //===----------------------------------------------------------------------===//
458 
459 /// Whether a struct is a `struct`, `union`, or `union tagged`.
460 enum class StructKind {
461  /// A `struct`.
462  Struct,
463  /// A `union`.
464  Union,
465  /// A `union tagged`.
466  TaggedUnion,
467 };
468 
469 /// Map a `StructKind` to the corresponding mnemonic.
470 StringRef getMnemonicFromStructKind(StructKind kind);
471 /// Map a mnemonic to the corresponding `StructKind`.
472 std::optional<StructKind> getStructKindFromMnemonic(StringRef mnemonic);
473 
474 template <typename Os>
475 Os &operator<<(Os &os, const StructKind &kind) {
476  static constexpr StringRef keywords[] = {"struct", "union", "union tagged"};
477  os << keywords[static_cast<unsigned>(kind)];
478  return os;
479 }
480 
481 /// A member of a struct.
482 struct StructMember {
483  /// The name of this member.
484  StringAttr name;
485  /// The type of this member.
487 
488  bool operator==(const StructMember &other) const {
489  return name == other.name && type == other.type;
490  }
491 };
492 
493 // NOLINTNEXTLINE(readability-identifier-naming)
494 inline llvm::hash_code hash_value(const StructMember &x) {
495  return llvm::hash_combine(x.name, x.type);
496 }
497 
498 /// A struct.
499 ///
500 /// This represents both packed and unpacked structs. Which one it is depends on
501 /// whether this struct is embedded in a `PackedStructType` or a
502 /// `UnpackedStructType`. For the packed version the struct members are
503 /// guaranteed to be packed types as well.
504 struct Struct {
505  /// Whether this is a `struct`, `union`, or `union tagged`.
507  /// The list of members.
508  SmallVector<StructMember, 4> members;
509  /// The value domain of this struct. If all members are two-valued, the
510  /// overall struct is two-valued. Otherwise the struct is four-valued.
512  /// The size of this struct in bits. This is `None` if any member type has an
513  /// unknown size. This is commonly the case for unpacked member types, or
514  /// dimensions with unknown size such as `[]` or `[$]`.
515  std::optional<unsigned> bitSize;
516 
517  /// Create a new struct.
518  Struct(StructKind kind, ArrayRef<StructMember> members);
519 };
520 
521 /// A packed struct.
522 class PackedStructType : public Type::TypeBase<PackedStructType, PackedType,
523  detail::StructTypeStorage,
524  ::mlir::TypeTrait::IsMutable> {
525 public:
526  static PackedStructType get(MLIRContext *context, StructKind kind,
527  ArrayRef<StructMember> members);
528  static PackedStructType get(MLIRContext *context, const Struct &strukt) {
529  return get(context, strukt.kind, strukt.members);
530  }
531 
532  /// Get the struct definition.
533  const Struct &getStruct() const;
534 
535  /// Allow implicit casts from `PackedStructType` to the actual struct
536  /// definition.
537  operator const Struct &() const { return getStruct(); }
538 
539  static constexpr StringLiteral name = "moore.packed_struct";
540 
541 protected:
542  using Base::Base;
543 };
544 
545 /// An unpacked struct.
547  : public Type::TypeBase<UnpackedStructType, UnpackedType,
548  detail::StructTypeStorage,
549  ::mlir::TypeTrait::IsMutable> {
550 public:
551  static UnpackedStructType get(MLIRContext *context, StructKind kind,
552  ArrayRef<StructMember> members);
553  static UnpackedStructType get(MLIRContext *context, const Struct &strukt) {
554  return get(context, strukt.kind, strukt.members);
555  }
556 
557  /// Get the struct definition.
558  const Struct &getStruct() const;
559 
560  /// Allow implicit casts from `UnpackedStructType` to the actual struct
561  /// definition.
562  operator const Struct &() const { return getStruct(); }
563 
564  static constexpr StringLiteral name = "moore.unpacked_struct";
565 
566 protected:
567  using Base::Base;
568 };
569 
570 } // namespace moore
571 } // namespace circt
572 
573 //===----------------------------------------------------------------------===//
574 // Hashing
575 //===----------------------------------------------------------------------===//
576 
577 namespace llvm {
578 
579 template <>
580 struct DenseMapInfo<circt::moore::Range> {
582  static inline Range getEmptyKey() { return Range(-1); }
583  static inline Range getTombstoneKey() { return Range(-2); }
584  static unsigned getHashValue(const Range &x) {
585  return circt::moore::hash_value(x);
586  }
587  static bool isEqual(const Range &lhs, const Range &rhs) { return lhs == rhs; }
588 };
589 
590 } // namespace llvm
591 
592 // Include generated types.
593 #define GET_TYPEDEF_CLASSES
594 #include "circt/Dialect/Moore/MooreTypes.h.inc"
595 
596 #endif // CIRCT_DIALECT_MOORE_MOORETYPES_H
A packed dimension.
Definition: MooreTypes.h:258
std::optional< Range > getRange() const
Get the dimension's range, or None if it is unsized.
Definition: MooreTypes.cpp:173
const detail::DimStorage * getImpl() const
Definition: MooreTypes.cpp:183
static bool classof(Type type)
Definition: MooreTypes.h:260
PackedType getInner() const
Get the element type of the dimension. This is the x in x[a:b].
Definition: MooreTypes.cpp:169
std::optional< unsigned > getSize() const
Get the dimension's size, or None if it is unsized.
Definition: MooreTypes.cpp:179
A packed range dimension, like [a:b].
Definition: MooreTypes.h:294
static constexpr StringLiteral name
Definition: MooreTypes.h:311
Range getRange() const
Get the range of this dimension.
Definition: MooreTypes.cpp:195
static PackedRangeDim get(PackedType inner, Args... args)
Get a packed range with arguments forwarded to the Range constructor.
Definition: MooreTypes.h:301
static PackedRangeDim get(PackedType inner, Range range)
Definition: MooreTypes.cpp:191
const Struct & getStruct() const
Get the struct definition.
Definition: MooreTypes.cpp:365
static PackedStructType get(MLIRContext *context, const Struct &strukt)
Definition: MooreTypes.h:528
static PackedStructType get(MLIRContext *context, StructKind kind, ArrayRef< StructMember > members)
Definition: MooreTypes.cpp:355
static constexpr StringLiteral name
Definition: MooreTypes.h:539
A packed SystemVerilog type.
Definition: MooreTypes.h:231
std::optional< unsigned > getBitSize() const
Get the size of this type in bits.
Definition: MooreTypes.cpp:107
Domain getDomain() const
Get the value domain of this type.
Definition: MooreTypes.cpp:98
static bool classof(Type type)
Definition: MooreTypes.h:233
A packed unsized dimension, like [].
Definition: MooreTypes.h:280
static constexpr StringLiteral name
Definition: MooreTypes.h:284
static PackedUnsizedDim get(PackedType inner)
Definition: MooreTypes.cpp:187
Base class for all SystemVerilog types in the Moore dialect.
Definition: MooreTypes.h:138
An unpacked array dimension, like [a].
Definition: MooreTypes.h:365
static UnpackedArrayDim get(UnpackedType inner, unsigned size)
Definition: MooreTypes.cpp:249
static constexpr StringLiteral name
Definition: MooreTypes.h:372
unsigned getSize() const
Get the size of the array, i.e. the a in [a].
Definition: MooreTypes.cpp:253
An unpacked associative dimension, like [T] or [*].
Definition: MooreTypes.h:421
static UnpackedAssocDim get(UnpackedType inner, UnpackedType indexType={})
Definition: MooreTypes.cpp:261
UnpackedType getIndexType() const
Get the index type of the associative dimension.
Definition: MooreTypes.cpp:266
static constexpr StringLiteral name
Definition: MooreTypes.h:429
An unpacked dimension.
Definition: MooreTypes.h:329
const detail::DimStorage * getImpl() const
Definition: MooreTypes.cpp:241
static bool classof(Type type)
Definition: MooreTypes.h:331
UnpackedType getInner() const
Get the element type of the dimension. This is the x in x[a:b].
Definition: MooreTypes.cpp:239
An unpacked queue dimension with optional bound, like [$] or [$:a].
Definition: MooreTypes.h:439
static UnpackedQueueDim get(UnpackedType inner, std::optional< unsigned > bound={})
Definition: MooreTypes.cpp:270
std::optional< unsigned > getBound() const
Get the bound of the queue, i.e.
Definition: MooreTypes.cpp:275
static constexpr StringLiteral name
Definition: MooreTypes.h:448
An unpacked range dimension, like [a:b].
Definition: MooreTypes.h:382
static UnpackedRangeDim get(UnpackedType inner, Args... args)
Get a packed range with arguments forwarded to the Range constructor.
Definition: MooreTypes.h:389
Range getRange() const
Get the range of this dimension.
Definition: MooreTypes.cpp:259
static constexpr StringLiteral name
Definition: MooreTypes.h:399
static UnpackedRangeDim get(UnpackedType inner, Range range)
Definition: MooreTypes.cpp:255
const Struct & getStruct() const
Get the struct definition.
Definition: MooreTypes.cpp:373
static UnpackedStructType get(MLIRContext *context, const Struct &strukt)
Definition: MooreTypes.h:553
static constexpr StringLiteral name
Definition: MooreTypes.h:564
static UnpackedStructType get(MLIRContext *context, StructKind kind, ArrayRef< StructMember > members)
Definition: MooreTypes.cpp:367
An unpacked SystemVerilog type.
Definition: MooreTypes.h:179
std::optional< unsigned > getBitSize() const
Get the size of this type in bits.
Definition: MooreTypes.cpp:74
Domain getDomain() const
Get the value domain of this type.
Definition: MooreTypes.cpp:65
static bool classof(Type type)
Definition: MooreTypes.h:181
An unpacked unsized dimension, like [].
Definition: MooreTypes.h:351
static UnpackedUnsizedDim get(UnpackedType inner)
Definition: MooreTypes.cpp:245
static constexpr StringLiteral name
Definition: MooreTypes.h:355
Domain
The number of values each bit of a type can assume.
Definition: MooreTypes.h:27
@ FourValued
Four-valued types such as logic or integer.
@ TwoValued
Two-valued types such as bit or int.
llvm::hash_code hash_value(const Range &x)
Definition: MooreTypes.h:116
RangeDir
Which side is greater in a range [a:b].
Definition: MooreTypes.h:54
Sign
Whether a type is signed or unsigned.
Definition: MooreTypes.h:35
@ Signed
A signed type.
@ Unsigned
An unsigned type.
StringRef getKeywordFromSign(const Sign &sign)
Map a Sign to the corresponding keyword.
Definition: MooreTypes.cpp:51
Os & operator<<(Os &os, const Sign &sign)
Definition: MooreTypes.h:48
StringRef getMnemonicFromStructKind(StructKind kind)
Map a StructKind to the corresponding mnemonic.
Definition: MooreTypes.cpp:286
std::optional< Sign > getSignFromKeyword(StringRef keyword)
Map the keywords unsigned and signed to the corresponding Sign.
StructKind
Whether a struct is a struct, union, or union tagged.
Definition: MooreTypes.h:460
@ TaggedUnion
A union tagged.
std::optional< StructKind > getStructKindFromMnemonic(StringRef mnemonic)
Map a mnemonic to the corresponding StructKind.
Definition: MooreTypes.cpp:298
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
The [a:b] part in a vector/array type such as logic [a:b].
Definition: MooreTypes.h:62
Range(unsigned size, RangeDir dir, int offset)
Construct a range [offset+size-1:offset] if dir is Down, or [offset:offset+size-1] if dir is Up.
Definition: MooreTypes.h:75
unsigned size
The total number of bits, given as |a-b|+1.
Definition: MooreTypes.h:64
int offset
The starting offset of the range.
Definition: MooreTypes.h:68
bool operator==(const Range &other) const
Definition: MooreTypes.h:92
int left() const
Get the $left dimension.
Definition: MooreTypes.h:97
int high() const
Get the $high dimension.
Definition: MooreTypes.h:103
RangeDir dir
The direction of the vector, i.e. whether a > b or a < b.
Definition: MooreTypes.h:66
std::string toString() const
Format this range as a string.
Definition: MooreTypes.h:108
Range(unsigned size)
Construct a range [size-1:0].
Definition: MooreTypes.h:71
int right() const
Get the $right dimension.
Definition: MooreTypes.h:99
int low() const
Get the $low dimension.
Definition: MooreTypes.h:101
int increment() const
Get the $increment size.
Definition: MooreTypes.h:105
Range(int left, int right)
Construct a range [left:right], with the direction inferred asDownif left >= right,...
Definition: MooreTypes.h:80
A member of a struct.
Definition: MooreTypes.h:482
StringAttr name
The name of this member.
Definition: MooreTypes.h:484
UnpackedType type
The type of this member.
Definition: MooreTypes.h:486
bool operator==(const StructMember &other) const
Definition: MooreTypes.h:488
std::optional< unsigned > bitSize
The size of this struct in bits.
Definition: MooreTypes.h:515
StructKind kind
Whether this is a struct, union, or union tagged.
Definition: MooreTypes.h:506
Struct(StructKind kind, ArrayRef< StructMember > members)
Create a new struct.
Definition: MooreTypes.cpp:306
Domain domain
The value domain of this struct.
Definition: MooreTypes.h:511
SmallVector< StructMember, 4 > members
The list of members.
Definition: MooreTypes.h:508
static bool isEqual(const Range &lhs, const Range &rhs)
Definition: MooreTypes.h:587
static unsigned getHashValue(const Range &x)
Definition: MooreTypes.h:584