15 #include "mlir/IR/Builders.h"
17 using namespace circt;
24 LogicalResult InstanceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
26 symbolTable.lookupNearestSymbolFrom(*
this, getModuleNameAttr());
27 if (module ==
nullptr)
28 return emitError(
"unknown symbol name '") << getModuleName() <<
"'";
31 if (!isa<SVModuleOp>(module))
32 return emitError(
"symbol '")
34 <<
"' must reference a 'moore.module', but got a '"
35 << module->getName() <<
"' instead";
45 setNameFn(getResult(),
getName());
53 setNameFn(getResult(),
getName());
60 void ConstantOp::print(OpAsmPrinter &p) {
62 p.printAttributeWithoutType(getValueAttr());
63 p.printOptionalAttrDict((*this)->getAttrs(), {
"value"});
65 p.printType(getType());
68 ParseResult ConstantOp::parse(OpAsmParser &parser, OperationState &result) {
71 auto valueLoc = parser.getCurrentLocation();
73 if (parser.parseInteger(value) ||
74 parser.parseOptionalAttrDict(result.attributes) || parser.parseColon())
79 if (parser.parseType(type))
83 if (type.getWidth() > value.getBitWidth()) {
87 value = value.sext(type.getWidth());
88 }
else if (type.getWidth() < value.getBitWidth()) {
92 value.isNegative() ? value.getSignificantBits() : value.getActiveBits();
93 if (type.getWidth() < neededBits)
94 return parser.emitError(valueLoc,
95 "constant out of range for result type ")
97 value = value.trunc(type.getWidth());
104 result.addAttribute(
"value", attrValue);
105 result.addTypes(type);
109 LogicalResult ConstantOp::verify() {
110 auto attrWidth = getValue().getBitWidth();
111 auto typeWidth = getType().getWidth();
112 if (attrWidth != typeWidth)
113 return emitError(
"attribute width ")
114 << attrWidth <<
" does not match return type's width " << typeWidth;
118 void ConstantOp::build(OpBuilder &
builder, OperationState &result, IntType type,
119 const APInt &value) {
120 assert(type.getWidth() == value.getBitWidth() &&
121 "APInt width must match type width");
123 builder.getIntegerAttr(
builder.getIntegerType(type.getWidth()), value));
130 void ConstantOp::build(OpBuilder &
builder, OperationState &result, IntType type,
133 APInt(type.getWidth(), (uint64_t)value,
true));
141 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
142 DictionaryAttr attrs, mlir::OpaqueProperties properties,
143 mlir::RegionRange regions, SmallVectorImpl<Type> &results) {
146 for (
auto operand : operands) {
147 auto type = cast<IntType>(operand.getType());
150 width += type.getWidth();
160 OpFoldResult ConversionOp::fold(FoldAdaptor adaptor) {
162 if (getInput().getType() == getResult().getType())
171 OpFoldResult BoolCastOp::fold(FoldAdaptor adaptor) {
173 if (getInput().getType() == getResult().getType())
183 #define GET_OP_CLASSES
184 #include "circt/Dialect/Moore/Moore.cpp.inc"
185 #include "circt/Dialect/Moore/MooreEnums.cpp.inc"
assert(baseType &&"element must be base type")
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
LogicalResult inferReturnTypes(MLIRContext *context, std::optional< Location > loc, ValueRange operands, DictionaryAttr attrs, mlir::OpaqueProperties properties, mlir::RegionRange regions, SmallVectorImpl< Type > &results, llvm::function_ref< FIRRTLType(ValueRange, ArrayRef< NamedAttribute >, std::optional< Location >)> callback)
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
void getAsmResultNames(OpAsmSetValueNameFn setNameFn, StringRef instanceName, ArrayAttr resultNames, ValueRange results)
Suggest a name for each result value based on the saved result names attribute.
Domain
The number of values each bit of a type can assume.
@ FourValued
Four-valued types such as logic or integer.
@ TwoValued
Two-valued types such as bit or int.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn