14 #include "llvm/ADT/TypeSwitch.h"
26 if (value.getBitWidth() < 1)
27 return emitError() <<
"bit-width must be at least 1, but got "
28 << value.getBitWidth();
33 unsigned width = getValue().getBitWidth();
35 StringRef pref = prefix ?
"#" :
"";
37 getValue().toString(toPrint, 16,
false,
false,
false);
41 return (pref +
"x" + Twine(leadingZeros) + toPrint).str();
44 getValue().toString(toPrint, 2,
false,
false,
false);
47 return (pref +
"b" + Twine(leadingZeros) + toPrint).str();
51 static FailureOr<APInt>
58 return emitError() <<
"expected at least one digit";
61 return APInt(value.size() - 2, std::string(value.begin() + 2, value.end()),
65 return APInt((value.size() - 2) * 4,
66 std::string(value.begin() + 2, value.end()), 16);
68 return emitError() <<
"expected either 'b' or 'x'";
74 assert(succeeded(maybeValue) &&
"string must have SMT-LIB format");
85 return Base::getChecked(
emitError, context, *maybeValue);
90 return Base::get(context, APInt(width, value));
97 if (width < 64 && value >= (UINT64_C(1) << width)) {
98 emitError() <<
"value does not fit in a bit-vector of desired width";
101 return Base::getChecked(
emitError, context, APInt(width, value));
113 if (!odsType || !llvm::isa<BitVectorType>(odsType)) {
114 odsParser.
emitError(loc) <<
"explicit bit-vector type required";
118 unsigned width = llvm::cast<BitVectorType>(odsType).getWidth();
120 if (width > val.getBitWidth()) {
124 val = val.sext(width);
125 }
else if (width < val.getBitWidth()) {
128 unsigned neededBits =
129 val.isNegative() ? val.getSignificantBits() : val.getActiveBits();
130 if (width < neededBits) {
132 <<
"integer value out of range for given bit-vector type " << odsType;
135 val = val.trunc(width);
145 odsPrinter <<
"<" << getValue() <<
">";
156 #define GET_ATTRDEF_CLASSES
157 #include "mlir/Dialect/SMT/IR/SMTAttributes.cpp.inc"
159 void SMTDialect::registerAttributes() {
161 #define GET_ATTRDEF_LIST
162 #include "mlir/Dialect/SMT/IR/SMTAttributes.cpp.inc"
static StringRef getValueAsString(const Init *init)
static unsigned getBitWidth(Type type)
static MLIRContext * getContext(OpFoldResult val)
static FailureOr< APInt > parseBitVectorString(function_ref< InFlightDiagnostic()> emitError, StringRef value)
Parse an SMT-LIB formatted bit-vector string.
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
This base class exposes generic asm parser hooks, usable across the various derived parsers.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseGreater()=0
Parse a '>' token.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
This class represents a diagnostic that is inflight and set to be reported.
MLIRContext is the top-level object for a collection of MLIR operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...