CIRCT  19.0.0git
Moore.cpp
Go to the documentation of this file.
1 //===- Moore.h - C interface for the Moore dialect ------------------------===//
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 
12 #include "mlir/CAPI/IR.h"
13 #include "mlir/CAPI/Registration.h"
14 #include "mlir/CAPI/Support.h"
15 
16 using namespace circt;
17 using namespace circt::moore;
18 
19 //===----------------------------------------------------------------------===//
20 // Dialect
21 //===----------------------------------------------------------------------===//
22 
23 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Moore, moore, MooreDialect)
24 
25 //===----------------------------------------------------------------------===//
26 // Types
27 //===----------------------------------------------------------------------===//
28 
29 static std::optional<Sign> convertMooreSign(enum MooreSign sign) {
30  switch (sign) {
32  return Sign::Signed;
34  return Sign::Unsigned;
36  return {};
37  }
38  llvm_unreachable("All cases should be covered.");
39 }
40 
42  switch (kind) {
44  return IntType::Kind::Bit;
46  return IntType::Kind::Logic;
48  return IntType::Kind::Reg;
49 
51  return IntType::Kind::Byte;
53  return IntType::Kind::ShortInt;
55  return IntType::Kind::Int;
57  return IntType::Kind::LongInt;
59  return IntType::Kind::Integer;
61  return IntType::Kind::Time;
62  }
63  llvm_unreachable("All cases should be covered.");
64 }
65 
67  switch (kind) {
74  }
75  llvm_unreachable("All cases should be covered.");
76 }
77 
78 /// Create a void type.
79 MlirType mooreVoidTypeGet(MlirContext ctx) {
80  return wrap(VoidType::get(unwrap(ctx)));
81 }
82 
83 /// Create a string type.
84 MlirType mooreStringTypeGet(MlirContext ctx) {
85  return wrap(StringType::get(unwrap(ctx)));
86 }
87 
88 /// Create a chandle type.
89 MlirType mooreChandleTypeGet(MlirContext ctx) {
90  return wrap(ChandleType::get(unwrap(ctx)));
91 }
92 
93 /// Create a event type.
94 MlirType mooreEventTypeGet(MlirContext ctx) {
95  return wrap(EventType::get(unwrap(ctx)));
96 }
97 
98 /// Create an int type.
99 MlirType mooreIntTypeGet(MlirContext ctx, enum MooreIntKind kind,
100  enum MooreSign sign) {
101  return wrap(IntType::get(unwrap(ctx), convertMooreIntKind(kind),
102  convertMooreSign(sign)));
103 }
104 
105 /// Create a `logic` type.
106 MlirType mooreIntTypeGetLogic(MlirContext ctx) {
107  return wrap(IntType::getLogic(unwrap(ctx)));
108 }
109 
110 /// Create an `int` type.
111 MlirType mooreIntTypeGetInt(MlirContext ctx) {
112  return wrap(IntType::getInt(unwrap(ctx)));
113 }
114 
115 /// Create a `time` type.
116 MlirType mooreIntTypeGetTime(MlirContext ctx) {
117  return wrap(IntType::getTime(unwrap(ctx)));
118 }
119 
120 /// Create a real type.
121 MlirType mooreRealTypeGet(MlirContext ctx, enum MooreRealKind kind) {
122  return wrap(RealType::get(unwrap(ctx), convertMooreRealKind(kind)));
123 }
124 
125 /// Create a packed unsized dimension type.
126 MlirType moorePackedUnsizedDimTypeGet(MlirType inner) {
127  return wrap(PackedUnsizedDim::get(cast<PackedType>(unwrap(inner))));
128 }
129 
130 /// Create a packed range dimension type.
131 MlirType moorePackedRangeDimTypeGet(MlirType inner, unsigned size, bool upDir,
132  int offset) {
133  RangeDir dir = upDir ? RangeDir::Up : RangeDir::Down;
134  return wrap(
135  PackedRangeDim::get(cast<PackedType>(unwrap(inner)), size, dir, offset));
136 }
137 
138 /// Create a unpacked unsized dimension type.
139 MlirType mooreUnpackedUnsizedDimTypeGet(MlirType inner) {
140  return wrap(UnpackedUnsizedDim::get(cast<UnpackedType>(unwrap(inner))));
141 }
142 
143 /// Create a unpacked array dimension type.
144 MlirType mooreUnpackedArrayDimTypeGet(MlirType inner, unsigned size) {
145  return wrap(UnpackedArrayDim::get(cast<UnpackedType>(unwrap(inner)), size));
146 }
147 
148 /// Create a unpacked range dimension type.
149 MlirType mooreUnpackedRangeDimTypeGet(MlirType inner, unsigned size, bool upDir,
150  int offset) {
151  RangeDir dir = upDir ? RangeDir::Up : RangeDir::Down;
152  return wrap(UnpackedRangeDim::get(cast<UnpackedType>(unwrap(inner)), size,
153  dir, offset));
154 }
155 
156 /// Create a unpacked assoc dimension type without index.
157 MlirType mooreUnpackedAssocDimTypeGet(MlirType inner) {
158  return wrap(UnpackedAssocDim::get(cast<UnpackedType>(unwrap(inner))));
159 }
160 
161 /// Create a unpacked assoc dimension type with index.
163  MlirType indexType) {
164  return wrap(UnpackedAssocDim::get(cast<UnpackedType>(unwrap(inner)),
165  cast<UnpackedType>(unwrap(indexType))));
166 }
167 
168 /// Create a unpacked queue dimension type without bound.
169 MlirType mooreUnpackedQueueDimTypeGet(MlirType inner) {
170  return wrap(UnpackedQueueDim::get(cast<UnpackedType>(unwrap(inner))));
171 }
172 
173 /// Create a unpacked queue dimension type with bound.
174 MlirType mooreUnpackedQueueDimTypeGetWithBound(MlirType inner, unsigned bound) {
175  return wrap(UnpackedQueueDim::get(cast<UnpackedType>(unwrap(inner)), bound));
176 }
177 
178 /// Create a simple bit-vector type.
179 MlirType mooreSimpleBitVectorTypeGet(MlirContext ctx, bool isFourValued,
180  bool isSigned, unsigned size) {
181  Domain domain = isFourValued ? Domain::FourValued : Domain::TwoValued;
182  Sign sign = isSigned ? Sign::Signed : Sign::Unsigned;
183  return wrap(SimpleBitVectorType(domain, sign, size).getType(unwrap(ctx)));
184 }
185 
186 /// Checks whether the passed UnpackedType is a four-valued type.
187 bool mooreIsFourValuedType(MlirType type) {
188  return cast<UnpackedType>(unwrap(type)).getDomain() == Domain::FourValued;
189 }
190 
191 /// Checks whether the passed type is a simple bit-vector.
192 bool mooreIsSimpleBitVectorType(MlirType type) {
193  return cast<UnpackedType>(unwrap(type)).isSimpleBitVector();
194 }
195 
196 /// Returns the size of a simple bit-vector type in bits.
197 unsigned mooreGetSimpleBitVectorSize(MlirType type) {
198  return cast<UnpackedType>(unwrap(type)).getSimpleBitVector().size;
199 }
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
MlirType mooreRealTypeGet(MlirContext ctx, enum MooreRealKind kind)
Create a real type.
Definition: Moore.cpp:121
static std::optional< Sign > convertMooreSign(enum MooreSign sign)
Definition: Moore.cpp:29
MlirType mooreVoidTypeGet(MlirContext ctx)
Create a void type.
Definition: Moore.cpp:79
bool mooreIsSimpleBitVectorType(MlirType type)
Checks whether the passed type is a simple bit-vector.
Definition: Moore.cpp:192
MlirType mooreUnpackedAssocDimTypeGet(MlirType inner)
Create a unpacked assoc dimension type without index.
Definition: Moore.cpp:157
MlirType mooreChandleTypeGet(MlirContext ctx)
Create a chandle type.
Definition: Moore.cpp:89
MlirType moorePackedRangeDimTypeGet(MlirType inner, unsigned size, bool upDir, int offset)
Create a packed range dimension type.
Definition: Moore.cpp:131
MlirType mooreUnpackedQueueDimTypeGet(MlirType inner)
Create a unpacked queue dimension type without bound.
Definition: Moore.cpp:169
MlirType mooreIntTypeGet(MlirContext ctx, enum MooreIntKind kind, enum MooreSign sign)
Create an int type.
Definition: Moore.cpp:99
static IntType::Kind convertMooreIntKind(enum MooreIntKind kind)
Definition: Moore.cpp:41
unsigned mooreGetSimpleBitVectorSize(MlirType type)
Returns the size of a simple bit-vector type in bits.
Definition: Moore.cpp:197
bool mooreIsFourValuedType(MlirType type)
Checks whether the passed UnpackedType is a four-valued type.
Definition: Moore.cpp:187
MlirType mooreUnpackedUnsizedDimTypeGet(MlirType inner)
Create a unpacked unsized dimension type.
Definition: Moore.cpp:139
MlirType mooreEventTypeGet(MlirContext ctx)
Create a event type.
Definition: Moore.cpp:94
MlirType mooreUnpackedRangeDimTypeGet(MlirType inner, unsigned size, bool upDir, int offset)
Create a unpacked range dimension type.
Definition: Moore.cpp:149
MlirType mooreIntTypeGetLogic(MlirContext ctx)
Create a logic type.
Definition: Moore.cpp:106
MlirType moorePackedUnsizedDimTypeGet(MlirType inner)
Create a packed unsized dimension type.
Definition: Moore.cpp:126
MlirType mooreUnpackedArrayDimTypeGet(MlirType inner, unsigned size)
Create a unpacked array dimension type.
Definition: Moore.cpp:144
MlirType mooreIntTypeGetInt(MlirContext ctx)
Create an int type.
Definition: Moore.cpp:111
MlirType mooreStringTypeGet(MlirContext ctx)
Create a string type.
Definition: Moore.cpp:84
MlirType mooreUnpackedQueueDimTypeGetWithBound(MlirType inner, unsigned bound)
Create a unpacked queue dimension type with bound.
Definition: Moore.cpp:174
static RealType::Kind convertMooreRealKind(enum MooreRealKind kind)
Definition: Moore.cpp:66
MlirType mooreIntTypeGetTime(MlirContext ctx)
Create a time type.
Definition: Moore.cpp:116
MlirType mooreUnpackedAssocDimTypeGetWithIndex(MlirType inner, MlirType indexType)
Create a unpacked assoc dimension type with index.
Definition: Moore.cpp:162
MlirType mooreSimpleBitVectorTypeGet(MlirContext ctx, bool isFourValued, bool isSigned, unsigned size)
Create a simple bit-vector type.
Definition: Moore.cpp:179
MooreIntKind
Definition: Moore.h:28
@ MooreByte
A byte.
Definition: Moore.h:39
@ MooreInteger
An integer.
Definition: Moore.h:47
@ MooreLongInt
A longint.
Definition: Moore.h:45
@ MooreTime
A time.
Definition: Moore.h:49
@ MooreShortInt
A shortint.
Definition: Moore.h:41
@ MooreLogic
A logic.
Definition: Moore.h:33
@ MooreInt
An int.
Definition: Moore.h:43
@ MooreReg
A reg.
Definition: Moore.h:35
@ MooreBit
A bit.
Definition: Moore.h:31
MooreSign
Definition: Moore.h:61
@ MooreUnsigned
Explicitly marked to be unsigned.
Definition: Moore.h:65
@ MooreNone
No sign is explicitly given.
Definition: Moore.h:63
@ MooreSigned
Explicitly marked to be signed.
Definition: Moore.h:67
MooreRealKind
Definition: Moore.h:52
@ MooreReal
A real.
Definition: Moore.h:56
@ MooreRealTime
A realtime.
Definition: Moore.h:58
@ MooreShortReal
A shortreal.
Definition: Moore.h:54
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:96
static IntType get(MLIRContext *context, Kind kind)
Definition: MooreTypes.cpp:332
static IntType getLogic(MLIRContext *context)
Create a logic type.
Definition: MooreTypes.h:381
static IntType getTime(MLIRContext *context)
Create a time type.
Definition: MooreTypes.h:387
static IntType getInt(MLIRContext *context)
Create a int type.
Definition: MooreTypes.h:384
static PackedRangeDim get(PackedType inner, Range range)
Definition: MooreTypes.cpp:472
static PackedUnsizedDim get(PackedType inner)
Definition: MooreTypes.cpp:468
static RealType get(MLIRContext *context, Kind kind)
Definition: MooreTypes.cpp:396
@ ShortReal
A shortreal.
Definition: MooreTypes.h:415
@ RealTime
A realtime.
Definition: MooreTypes.h:419
static UnpackedArrayDim get(UnpackedType inner, unsigned size)
Definition: MooreTypes.cpp:530
static UnpackedAssocDim get(UnpackedType inner, UnpackedType indexType={})
Definition: MooreTypes.cpp:542
static UnpackedQueueDim get(UnpackedType inner, std::optional< unsigned > bound={})
Definition: MooreTypes.cpp:551
static UnpackedRangeDim get(UnpackedType inner, Range range)
Definition: MooreTypes.cpp:536
static UnpackedUnsizedDim get(UnpackedType inner)
Definition: MooreTypes.cpp:526
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
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.
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.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
A simple bit vector type.
Definition: MooreTypes.h:134