12 #include "mlir/IR/Builders.h"
13 #include "mlir/IR/DialectImplementation.h"
14 #include "llvm/ADT/TypeSwitch.h"
17 using namespace circt;
18 using namespace firrtl;
20 #define GET_ATTRDEF_CLASSES
21 #include "circt/Dialect/FIRRTL/FIRRTLAttributes.cpp.inc"
34 llvm_unreachable(
"unknown direction");
38 ArrayRef<Direction> directions) {
40 auto size = directions.size();
41 APInt portDirections(size, 0);
42 for (
size_t i = 0; i != size; ++i)
44 portDirections.setBit(i);
49 assert(directions.getType().isSignlessInteger() &&
50 "Direction attributes must be signless integers");
51 auto value = directions.getValue();
52 auto size =
value.getBitWidth();
53 SmallVector<Direction> result;
55 for (
size_t i = 0; i != size; ++i)
65 void FIRRTLDialect::registerAttributes() {
67 #define GET_ATTRDEF_LIST
68 #include "circt/Dialect/FIRRTL/FIRRTLAttributes.cpp.inc"
76 Attribute ParamDeclAttr::parse(AsmParser &p, Type trailing) {
83 if (p.parseLess() || p.parseString(&name) || p.parseColonType(type))
86 if (succeeded(p.parseOptionalEqual())) {
87 if (p.parseAttribute(
value, type))
99 void ParamDeclAttr::print(AsmPrinter &p)
const {
100 p <<
"<" <<
getName() <<
": " << getType();
103 p.printAttributeWithoutType(getValue());
assert(baseType &&"element must be base type")
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
IntegerAttr packAttribute(MLIRContext *context, ArrayRef< Direction > directions)
Return a IntegerAttr containing the packed representation of an array of directions.
StringRef toString(Direction direction)
Direction flip(Direction direction)
Flip a port direction.
SmallVector< Direction > unpackAttribute(IntegerAttr directions)
Turn a packed representation of port attributes into a vector that can be worked with.
Direction get(bool isOutput)
Return an output direction if isOutput is true, otherwise return an input direction.
Direction
This represents the direction of a single port.
T & operator<<(T &os, FIRVersion version)
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...