CIRCT  20.0.0git
FIRRTL.cpp
Go to the documentation of this file.
1 //===- FIRRTL.cpp - C interface for the FIRRTL 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 //
9 // This file implements the C-API for FIRRTL dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "circt-c/Dialect/FIRRTL.h"
19 #include "mlir/CAPI/IR.h"
20 #include "mlir/CAPI/Registration.h"
21 #include "mlir/CAPI/Support.h"
22 #include "llvm/Support/JSON.h"
23 
24 using namespace circt;
25 using namespace firrtl;
26 
27 namespace json = llvm::json;
28 
29 //===----------------------------------------------------------------------===//
30 // Dialect API.
31 //===----------------------------------------------------------------------===//
32 
34  circt::firrtl::FIRRTLDialect)
35 
36 //===----------------------------------------------------------------------===//
37 // Type API.
38 //===----------------------------------------------------------------------===//
39 
40 bool firrtlTypeIsConst(MlirType type) { return isConst(unwrap(type)); }
41 
42 MlirType firrtlTypeGetConstType(MlirType type, bool isConst) {
43  return wrap(cast<FIRRTLBaseType>(unwrap(type)).getConstType(isConst));
44 }
45 
46 int64_t firrtlTypeGetBitWidth(MlirType type, bool ignoreFlip) {
47  return getBitWidth(cast<FIRRTLBaseType>(unwrap(type)), ignoreFlip)
48  .value_or(-1);
49 }
50 
51 bool firrtlTypeIsAUInt(MlirType type) { return isa<UIntType>(unwrap(type)); }
52 
53 MlirType firrtlTypeGetUInt(MlirContext ctx, int32_t width) {
54  return wrap(UIntType::get(unwrap(ctx), width));
55 }
56 
57 bool firrtlTypeIsASInt(MlirType type) { return isa<SIntType>(unwrap(type)); }
58 
59 MlirType firrtlTypeGetSInt(MlirContext ctx, int32_t width) {
60  return wrap(SIntType::get(unwrap(ctx), width));
61 }
62 
63 bool firrtlTypeIsAClock(MlirType type) { return isa<ClockType>(unwrap(type)); }
64 
65 MlirType firrtlTypeGetClock(MlirContext ctx) {
66  return wrap(ClockType::get(unwrap(ctx)));
67 }
68 
69 bool firrtlTypeIsAReset(MlirType type) { return isa<ResetType>(unwrap(type)); }
70 
71 MlirType firrtlTypeGetReset(MlirContext ctx) {
72  return wrap(ResetType::get(unwrap(ctx)));
73 }
74 
75 bool firrtlTypeIsAAsyncReset(MlirType type) {
76  return isa<AsyncResetType>(unwrap(type));
77 }
78 
79 MlirType firrtlTypeGetAsyncReset(MlirContext ctx) {
80  return wrap(AsyncResetType::get(unwrap(ctx)));
81 }
82 
83 bool firrtlTypeIsAAnalog(MlirType type) {
84  return isa<AnalogType>(unwrap(type));
85 }
86 
87 MlirType firrtlTypeGetAnalog(MlirContext ctx, int32_t width) {
88  return wrap(AnalogType::get(unwrap(ctx), width));
89 }
90 
91 bool firrtlTypeIsAVector(MlirType type) {
92  return isa<FVectorType>(unwrap(type));
93 }
94 
95 MlirType firrtlTypeGetVector(MlirContext ctx, MlirType element, size_t count) {
96  auto baseType = cast<FIRRTLBaseType>(unwrap(element));
97  assert(baseType && "element must be base type");
98 
99  return wrap(FVectorType::get(baseType, count));
100 }
101 
102 MlirType firrtlTypeGetVectorElement(MlirType vec) {
103  return wrap(cast<FVectorType>(unwrap(vec)).getElementType());
104 }
105 
106 size_t firrtlTypeGetVectorNumElements(MlirType vec) {
107  return cast<FVectorType>(unwrap(vec)).getNumElements();
108 }
109 
110 bool firrtlTypeIsABundle(MlirType type) {
111  return isa<BundleType>(unwrap(type));
112 }
113 
114 bool firrtlTypeIsAOpenBundle(MlirType type) {
115  return isa<OpenBundleType>(unwrap(type));
116 }
117 
118 MlirType firrtlTypeGetBundle(MlirContext ctx, size_t count,
119  const FIRRTLBundleField *fields) {
120  bool bundleCompatible = true;
121  SmallVector<OpenBundleType::BundleElement, 4> bundleFields;
122 
123  bundleFields.reserve(count);
124 
125  for (size_t i = 0; i < count; i++) {
126  auto field = fields[i];
127  auto type = cast<FIRRTLType>(unwrap(field.type));
128  bundleFields.emplace_back(unwrap(field.name), field.isFlip, type);
129  bundleCompatible &= isa<BundleType::ElementType>(type);
130  }
131 
132  // Try to emit base-only bundle.
133  if (bundleCompatible) {
134  auto bundleFieldsMapped = llvm::map_range(bundleFields, [](auto field) {
135  return BundleType::BundleElement{
136  field.name, field.isFlip, cast<BundleType::ElementType>(field.type)};
137  });
138  return wrap(
139  BundleType::get(unwrap(ctx), llvm::to_vector(bundleFieldsMapped)));
140  }
141  return wrap(OpenBundleType::get(unwrap(ctx), bundleFields));
142 }
143 
144 size_t firrtlTypeGetBundleNumFields(MlirType bundle) {
145  if (auto bundleType = dyn_cast<BundleType>(unwrap(bundle))) {
146  return bundleType.getNumElements();
147  } else if (auto bundleType = dyn_cast<OpenBundleType>(unwrap(bundle))) {
148  return bundleType.getNumElements();
149  } else {
150  llvm_unreachable("must be a bundle type");
151  }
152 }
153 
154 bool firrtlTypeGetBundleFieldByIndex(MlirType type, size_t index,
155  FIRRTLBundleField *field) {
156  auto unwrapped = unwrap(type);
157 
158  auto cvt = [field](auto element) {
159  field->name = wrap(element.name);
160  field->isFlip = element.isFlip;
161  field->type = wrap(element.type);
162  };
163  if (auto bundleType = dyn_cast<BundleType>(unwrapped)) {
164  cvt(bundleType.getElement(index));
165  return true;
166  } else if (auto bundleType = dyn_cast<OpenBundleType>(unwrapped)) {
167  cvt(bundleType.getElement(index));
168  return true;
169  }
170  return false;
171 }
172 
173 unsigned firrtlTypeGetBundleFieldIndex(MlirType type, MlirStringRef fieldName) {
174  std::optional<unsigned> fieldIndex;
175  if (auto bundleType = dyn_cast<BundleType>(unwrap(type))) {
176  fieldIndex = bundleType.getElementIndex(unwrap(fieldName));
177  } else if (auto bundleType = dyn_cast<OpenBundleType>(unwrap(type))) {
178  fieldIndex = bundleType.getElementIndex(unwrap(fieldName));
179  } else {
180  llvm_unreachable("must be a bundle type");
181  }
182  assert(fieldIndex.has_value() && "unknown field");
183  return fieldIndex.value();
184 }
185 
186 bool firrtlTypeIsARef(MlirType type) { return isa<RefType>(unwrap(type)); }
187 
188 MlirType firrtlTypeGetRef(MlirType target, bool forceable) {
189  auto baseType = dyn_cast<FIRRTLBaseType>(unwrap(target));
190  assert(baseType && "target must be base type");
191 
192  return wrap(RefType::get(baseType, forceable));
193 }
194 
195 bool firrtlTypeIsAAnyRef(MlirType type) {
196  return isa<AnyRefType>(unwrap(type));
197 }
198 
199 MlirType firrtlTypeGetAnyRef(MlirContext ctx) {
200  return wrap(AnyRefType::get(unwrap(ctx)));
201 }
202 
203 bool firrtlTypeIsAInteger(MlirType type) {
204  return isa<FIntegerType>(unwrap(type));
205 }
206 
207 MlirType firrtlTypeGetInteger(MlirContext ctx) {
208  return wrap(FIntegerType::get(unwrap(ctx)));
209 }
210 
211 bool firrtlTypeIsADouble(MlirType type) {
212  return isa<DoubleType>(unwrap(type));
213 }
214 
215 MlirType firrtlTypeGetDouble(MlirContext ctx) {
216  return wrap(DoubleType::get(unwrap(ctx)));
217 }
218 
219 bool firrtlTypeIsAString(MlirType type) {
220  return isa<StringType>(unwrap(type));
221 }
222 
223 MlirType firrtlTypeGetString(MlirContext ctx) {
224  return wrap(StringType::get(unwrap(ctx)));
225 }
226 
227 bool firrtlTypeIsABoolean(MlirType type) { return isa<BoolType>(unwrap(type)); }
228 
229 MlirType firrtlTypeGetBoolean(MlirContext ctx) {
230  return wrap(BoolType::get(unwrap(ctx)));
231 }
232 
233 bool firrtlTypeIsAPath(MlirType type) { return isa<PathType>(unwrap(type)); }
234 
235 MlirType firrtlTypeGetPath(MlirContext ctx) {
236  return wrap(PathType::get(unwrap(ctx)));
237 }
238 
239 bool firrtlTypeIsAList(MlirType type) { return isa<ListType>(unwrap(type)); }
240 
241 MlirType firrtlTypeGetList(MlirContext ctx, MlirType elementType) {
242  auto type = dyn_cast<PropertyType>(unwrap(elementType));
243  assert(type && "element must be property type");
244 
245  return wrap(ListType::get(unwrap(ctx), type));
246 }
247 
248 bool firrtlTypeIsAClass(MlirType type) { return isa<ClassType>(unwrap(type)); }
249 
250 MlirType firrtlTypeGetClass(MlirContext ctx, MlirAttribute name,
251  size_t numberOfElements,
252  const FIRRTLClassElement *elements) {
253  auto nameSymbol = dyn_cast<FlatSymbolRefAttr>(unwrap(name));
254  assert(nameSymbol && "name must be FlatSymbolRefAttr");
255 
256  SmallVector<ClassElement, 4> classElements;
257  classElements.reserve(numberOfElements);
258 
259  for (size_t i = 0; i < numberOfElements; i++) {
260  auto element = elements[i];
261  auto dir = element.direction == FIRRTL_DIRECTION_IN ? Direction::In
262  : Direction::Out;
263  classElements.emplace_back(unwrap(element.name), unwrap(element.type), dir);
264  }
265  return wrap(ClassType::get(unwrap(ctx), nameSymbol, classElements));
266 }
267 
268 MlirType firrtlTypeGetMaskType(MlirType type) {
269  auto baseType = type_dyn_cast<FIRRTLBaseType>(unwrap(type));
270  assert(baseType && "unexpected type, must be base type");
271  return wrap(baseType.getMaskType());
272 }
273 
274 //===----------------------------------------------------------------------===//
275 // Attribute API.
276 //===----------------------------------------------------------------------===//
277 
278 MlirAttribute firrtlAttrGetConvention(MlirContext ctx,
279  FIRRTLConvention convention) {
280  Convention value;
281 
282  switch (convention) {
284  value = Convention::Internal;
285  break;
287  value = Convention::Scalarized;
288  break;
289  }
290 
291  return wrap(ConventionAttr::get(unwrap(ctx), value));
292 }
293 
294 MlirAttribute firrtlAttrGetPortDirs(MlirContext ctx, size_t count,
295  const FIRRTLDirection *dirs) {
296  static_assert(FIRRTL_DIRECTION_IN ==
297  static_cast<std::underlying_type_t<Direction>>(Direction::In));
298  static_assert(FIRRTL_DIRECTION_OUT ==
299  static_cast<std::underlying_type_t<Direction>>(Direction::Out));
300 
301  // FIXME: The `reinterpret_cast` here may voilate strict aliasing rule. Is
302  // there a better way?
304  unwrap(ctx), ArrayRef(reinterpret_cast<const Direction *>(dirs), count)));
305 }
306 
307 MlirAttribute firrtlAttrGetParamDecl(MlirContext ctx, MlirIdentifier name,
308  MlirType type, MlirAttribute value) {
309  return wrap(ParamDeclAttr::get(unwrap(ctx), unwrap(name), unwrap(type),
310  unwrap(value)));
311 }
312 
313 MlirAttribute firrtlAttrGetNameKind(MlirContext ctx, FIRRTLNameKind nameKind) {
314  NameKindEnum value;
315 
316  switch (nameKind) {
318  value = NameKindEnum::DroppableName;
319  break;
321  value = NameKindEnum::InterestingName;
322  break;
323  }
324 
325  return wrap(NameKindEnumAttr::get(unwrap(ctx), value));
326 }
327 
328 MlirAttribute firrtlAttrGetRUW(MlirContext ctx, FIRRTLRUW ruw) {
329  RUWAttr value;
330 
331  switch (ruw) {
333  value = RUWAttr::Undefined;
334  break;
335  case FIRRTL_RUW_OLD:
336  value = RUWAttr::Old;
337  break;
338  case FIRRTL_RUW_NEW:
339  value = RUWAttr::New;
340  break;
341  }
342 
343  return wrap(RUWAttrAttr::get(unwrap(ctx), value));
344 }
345 
346 MlirAttribute firrtlAttrGetMemInit(MlirContext ctx, MlirIdentifier filename,
347  bool isBinary, bool isInline) {
348  return wrap(
349  MemoryInitAttr::get(unwrap(ctx), unwrap(filename), isBinary, isInline));
350 }
351 
352 MlirAttribute firrtlAttrGetMemDir(MlirContext ctx, FIRRTLMemDir dir) {
353  MemDirAttr value;
354 
355  switch (dir) {
357  value = MemDirAttr::Infer;
358  break;
359  case FIRRTL_MEM_DIR_READ:
360  value = MemDirAttr::Read;
361  break;
363  value = MemDirAttr::Write;
364  break;
366  value = MemDirAttr::ReadWrite;
367  break;
368  }
369 
370  return wrap(MemDirAttrAttr::get(unwrap(ctx), value));
371 }
372 
373 MlirAttribute firrtlAttrGetEventControl(MlirContext ctx,
374  FIRRTLEventControl eventControl) {
375  EventControl value;
376 
377  switch (eventControl) {
379  value = EventControl::AtPosEdge;
380  break;
382  value = EventControl::AtNegEdge;
383  break;
385  value = EventControl::AtEdge;
386  break;
387  }
388 
389  return wrap(EventControlAttr::get(unwrap(ctx), value));
390 }
391 
392 MlirAttribute firrtlAttrGetIntegerFromString(MlirType type, unsigned numBits,
393  MlirStringRef str, uint8_t radix) {
394  auto value = APInt{numBits, unwrap(str), radix};
395  return wrap(IntegerAttr::get(unwrap(type), value));
396 }
397 
399  Flow flowValue;
400 
401  switch (flow) {
403  flowValue = Flow::None;
404  break;
406  flowValue = Flow::Source;
407  break;
409  flowValue = Flow::Sink;
410  break;
412  flowValue = Flow::Duplex;
413  break;
414  }
415 
416  auto flowResult = firrtl::foldFlow(unwrap(value), flowValue);
417 
418  switch (flowResult) {
419  case Flow::None:
420  return FIRRTL_VALUE_FLOW_NONE;
421  case Flow::Source:
423  case Flow::Sink:
424  return FIRRTL_VALUE_FLOW_SINK;
425  case Flow::Duplex:
427  }
428  llvm_unreachable("invalid flow");
429 }
430 
432  MlirContext ctx, MlirStringRef annotationsStr,
433  MlirAttribute *importedAnnotationsArray) {
434  auto annotations = json::parse(unwrap(annotationsStr));
435  if (!annotations) {
436  return false;
437  }
438 
439  auto *ctxUnwrapped = unwrap(ctx);
440 
441  json::Path::Root root;
442  SmallVector<Attribute> annos;
443  if (!importAnnotationsFromJSONRaw(annotations.get(), annos, root,
444  ctxUnwrapped)) {
445  return false;
446  }
447 
448  *importedAnnotationsArray = wrap(ArrayAttr::get(ctxUnwrapped, annos));
449  return true;
450 }
assert(baseType &&"element must be base type")
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MlirType elementType
Definition: CHIRRTL.cpp:29
bool firrtlTypeIsAUInt(MlirType type)
Checks if this type is a unsigned integer type.
Definition: FIRRTL.cpp:51
bool firrtlTypeIsASInt(MlirType type)
Checks if this type is a signed integer type.
Definition: FIRRTL.cpp:57
bool firrtlTypeIsARef(MlirType type)
Checks if this type is a ref type.
Definition: FIRRTL.cpp:186
bool firrtlTypeIsAString(MlirType type)
Checks if this type is a property string type.
Definition: FIRRTL.cpp:219
MlirAttribute firrtlAttrGetMemDir(MlirContext ctx, FIRRTLMemDir dir)
Creates a MemDirAttr with the specified memory port direction.
Definition: FIRRTL.cpp:352
MlirType firrtlTypeGetAsyncReset(MlirContext ctx)
Creates an async reset type.
Definition: FIRRTL.cpp:79
MlirType firrtlTypeGetList(MlirContext ctx, MlirType elementType)
Creates a property list type with the specified element type.
Definition: FIRRTL.cpp:241
bool firrtlTypeIsAClass(MlirType type)
Checks if this type is a class type.
Definition: FIRRTL.cpp:248
bool firrtlTypeGetBundleFieldByIndex(MlirType type, size_t index, FIRRTLBundleField *field)
Returns the field at the specified index in the bundle type.
Definition: FIRRTL.cpp:154
MlirAttribute firrtlAttrGetIntegerFromString(MlirType type, unsigned numBits, MlirStringRef str, uint8_t radix)
Creates an IntegerAttr from a string representation of integer.
Definition: FIRRTL.cpp:392
MlirType firrtlTypeGetBoolean(MlirContext ctx)
Creates a property boolean type.
Definition: FIRRTL.cpp:229
MlirType firrtlTypeGetDouble(MlirContext ctx)
Creates a property double type.
Definition: FIRRTL.cpp:215
MlirType firrtlTypeGetPath(MlirContext ctx)
Creates a property path type.
Definition: FIRRTL.cpp:235
MlirType firrtlTypeGetConstType(MlirType type, bool isConst)
Returns a const or non-const version of this type.
Definition: FIRRTL.cpp:42
MlirType firrtlTypeGetString(MlirContext ctx)
Creates a property string type.
Definition: FIRRTL.cpp:223
bool firrtlTypeIsAClock(MlirType type)
Checks if this type is a clock type.
Definition: FIRRTL.cpp:63
MlirType firrtlTypeGetAnalog(MlirContext ctx, int32_t width)
Creates an analog type with the specified width.
Definition: FIRRTL.cpp:87
MlirType firrtlTypeGetInteger(MlirContext ctx)
Creates a property integer type.
Definition: FIRRTL.cpp:207
bool firrtlTypeIsAInteger(MlirType type)
Checks if this type is a property integer type.
Definition: FIRRTL.cpp:203
MlirAttribute firrtlAttrGetConvention(MlirContext ctx, FIRRTLConvention convention)
Creates an ConventionAttr with the specified value.
Definition: FIRRTL.cpp:278
MlirType firrtlTypeGetClock(MlirContext ctx)
Creates a clock type.
Definition: FIRRTL.cpp:65
MlirType firrtlTypeGetReset(MlirContext ctx)
Creates a reset type.
Definition: FIRRTL.cpp:71
bool firrtlTypeIsABundle(MlirType type)
Returns true if the specified type is a bundle type.
Definition: FIRRTL.cpp:110
MlirType firrtlTypeGetVector(MlirContext ctx, MlirType element, size_t count)
Creates a vector type with the specified element type and count.
Definition: FIRRTL.cpp:95
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FIRRTL, firrtl, circt::firrtl::FIRRTLDialect) bool firrtlTypeIsConst(MlirType type)
Definition: FIRRTL.cpp:33
bool firrtlImportAnnotationsFromJSONRaw(MlirContext ctx, MlirStringRef annotationsStr, MlirAttribute *importedAnnotationsArray)
Deserializes a JSON value into FIRRTL Annotations.
Definition: FIRRTL.cpp:431
bool firrtlTypeIsAPath(MlirType type)
Checks if this type is a property path type.
Definition: FIRRTL.cpp:233
MlirType firrtlTypeGetUInt(MlirContext ctx, int32_t width)
Creates a unsigned integer type with the specified width.
Definition: FIRRTL.cpp:53
MlirType firrtlTypeGetAnyRef(MlirContext ctx)
Creates an anyref type.
Definition: FIRRTL.cpp:199
MlirAttribute firrtlAttrGetPortDirs(MlirContext ctx, size_t count, const FIRRTLDirection *dirs)
Creates a DenseBoolArrayAttr with the specified port directions.
Definition: FIRRTL.cpp:294
bool firrtlTypeIsAReset(MlirType type)
Checks if this type is a reset type.
Definition: FIRRTL.cpp:69
MlirType firrtlTypeGetClass(MlirContext ctx, MlirAttribute name, size_t numberOfElements, const FIRRTLClassElement *elements)
Creates a class type with the specified name and elements.
Definition: FIRRTL.cpp:250
bool firrtlTypeIsAAnyRef(MlirType type)
Checks if this type is an anyref type.
Definition: FIRRTL.cpp:195
bool firrtlTypeIsAOpenBundle(MlirType type)
Returns true if the specified type is an open bundle type.
Definition: FIRRTL.cpp:114
MlirType firrtlTypeGetMaskType(MlirType type)
Returns this type with all ground types replaced with UInt<1>.
Definition: FIRRTL.cpp:268
MlirType firrtlTypeGetSInt(MlirContext ctx, int32_t width)
Creates a signed integer type with the specified width.
Definition: FIRRTL.cpp:59
MlirType firrtlTypeGetRef(MlirType target, bool forceable)
Creates a ref type.
Definition: FIRRTL.cpp:188
MlirType firrtlTypeGetBundle(MlirContext ctx, size_t count, const FIRRTLBundleField *fields)
Creates a bundle type with the specified fields.
Definition: FIRRTL.cpp:118
bool firrtlTypeIsAVector(MlirType type)
Checks if this type is a vector type.
Definition: FIRRTL.cpp:91
int64_t firrtlTypeGetBitWidth(MlirType type, bool ignoreFlip)
Gets the bit width for this type, returns -1 if unknown.
Definition: FIRRTL.cpp:46
MlirType firrtlTypeGetVectorElement(MlirType vec)
Returns the element type of a vector type.
Definition: FIRRTL.cpp:102
MlirAttribute firrtlAttrGetEventControl(MlirContext ctx, FIRRTLEventControl eventControl)
Creates a EventControlAttr with the specified value.
Definition: FIRRTL.cpp:373
bool firrtlTypeIsADouble(MlirType type)
Checks if this type is a property double type.
Definition: FIRRTL.cpp:211
bool firrtlTypeIsAList(MlirType type)
Checks if this type is a property list type.
Definition: FIRRTL.cpp:239
MlirAttribute firrtlAttrGetParamDecl(MlirContext ctx, MlirIdentifier name, MlirType type, MlirAttribute value)
Creates a ParamDeclAttr with the specified name, type, and value.
Definition: FIRRTL.cpp:307
MlirAttribute firrtlAttrGetMemInit(MlirContext ctx, MlirIdentifier filename, bool isBinary, bool isInline)
Creates a MemoryInitAttr with the specified memory initialization information.
Definition: FIRRTL.cpp:346
FIRRTLValueFlow firrtlValueFoldFlow(MlirValue value, FIRRTLValueFlow flow)
Computes the flow for a Value, value, as determined by the FIRRTL specification.
Definition: FIRRTL.cpp:398
MlirAttribute firrtlAttrGetRUW(MlirContext ctx, FIRRTLRUW ruw)
Creates a RUWAttr with the specified Read-Under-Write Behaviour.
Definition: FIRRTL.cpp:328
bool firrtlTypeIsAAsyncReset(MlirType type)
Checks if this type is an async reset type.
Definition: FIRRTL.cpp:75
MlirAttribute firrtlAttrGetNameKind(MlirContext ctx, FIRRTLNameKind nameKind)
Creates a NameKindEnumAttr with the specified name preservation semantic.
Definition: FIRRTL.cpp:313
bool firrtlTypeIsAAnalog(MlirType type)
Checks if this type is an analog type.
Definition: FIRRTL.cpp:83
bool firrtlTypeIsABoolean(MlirType type)
Checks if this type is a property boolean type.
Definition: FIRRTL.cpp:227
size_t firrtlTypeGetVectorNumElements(MlirType vec)
Returns the number of elements in a vector type.
Definition: FIRRTL.cpp:106
unsigned firrtlTypeGetBundleFieldIndex(MlirType type, MlirStringRef fieldName)
Returns the index of the field with the specified name in the bundle type.
Definition: FIRRTL.cpp:173
size_t firrtlTypeGetBundleNumFields(MlirType bundle)
Returns the number of fields in the bundle type.
Definition: FIRRTL.cpp:144
MLIR_CAPI_EXPORTED bool firrtlTypeIsConst(MlirType type)
Returns true if this is a const type whose value is guaranteed to be unchanging at circuit execution ...
FIRRTLValueFlow
Flow of value.
Definition: FIRRTL.h:75
@ FIRRTL_VALUE_FLOW_SOURCE
Definition: FIRRTL.h:77
@ FIRRTL_VALUE_FLOW_NONE
Definition: FIRRTL.h:76
@ FIRRTL_VALUE_FLOW_SINK
Definition: FIRRTL.h:78
@ FIRRTL_VALUE_FLOW_DUPLEX
Definition: FIRRTL.h:79
FIRRTLNameKind
Name preservation.
Definition: FIRRTL.h:43
@ FIRRTL_NAME_KIND_DROPPABLE_NAME
Definition: FIRRTL.h:44
@ FIRRTL_NAME_KIND_INTERESTING_NAME
Definition: FIRRTL.h:45
FIRRTLMemDir
Memory port direction.
Definition: FIRRTL.h:58
@ FIRRTL_MEM_DIR_INFER
Definition: FIRRTL.h:59
@ FIRRTL_MEM_DIR_READ
Definition: FIRRTL.h:60
@ FIRRTL_MEM_DIR_READ_WRITE
Definition: FIRRTL.h:62
@ FIRRTL_MEM_DIR_WRITE
Definition: FIRRTL.h:61
FIRRTLEventControl
Edge control trigger.
Definition: FIRRTL.h:67
@ FIRRTL_EVENT_CONTROL_AT_POS_EDGE
Definition: FIRRTL.h:68
@ FIRRTL_EVENT_CONTROL_AT_NEG_EDGE
Definition: FIRRTL.h:69
@ FIRRTL_EVENT_CONTROL_AT_EDGE
Definition: FIRRTL.h:70
FIRRTLDirection
Port direction.
Definition: FIRRTL.h:34
@ FIRRTL_DIRECTION_OUT
Definition: FIRRTL.h:36
@ FIRRTL_DIRECTION_IN
Definition: FIRRTL.h:35
FIRRTLRUW
Read-Under-Write behaviour.
Definition: FIRRTL.h:50
@ FIRRTL_RUW_OLD
Definition: FIRRTL.h:52
@ FIRRTL_RUW_UNDEFINED
Definition: FIRRTL.h:51
@ FIRRTL_RUW_NEW
Definition: FIRRTL.h:53
FIRRTLConvention
Module instantiation conventions.
Definition: FIRRTL.h:27
@ FIRRTL_CONVENTION_SCALARIZED
Definition: FIRRTL.h:29
@ FIRRTL_CONVENTION_INTERNAL
Definition: FIRRTL.h:28
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:113
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
mlir::DenseBoolArrayAttr packAttribute(MLIRContext *context, ArrayRef< Direction > directions)
Return a DenseBoolArrayAttr containing the packed representation of an array of directions.
Direction
This represents the direction of a single port.
Flow foldFlow(Value val, Flow accumulatedFlow=Flow::Source)
Compute the flow for a Value, val, as determined by the FIRRTL specification.
Definition: FIRRTLOps.cpp:212
bool isConst(Type type)
Returns true if this is a 'const' type whose value is guaranteed to be unchanging at circuit executio...
bool importAnnotationsFromJSONRaw(llvm::json::Value &value, SmallVectorImpl< Attribute > &annotations, llvm::json::Path path, MLIRContext *context)
Deserialize a JSON value into FIRRTL Annotations.
std::optional< int64_t > getBitWidth(FIRRTLBaseType type, bool ignoreFlip=false)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Describes a field in a bundle type.
Definition: FIRRTL.h:84
MlirType type
Definition: FIRRTL.h:87
MlirIdentifier name
Definition: FIRRTL.h:85
Describes an element in a class type.
Definition: FIRRTL.h:92
FIRRTLDirection direction
Definition: FIRRTL.h:95