14 #include "llvm/ADT/TypeSwitch.h"
15 #include "llvm/Support/Format.h"
27 if (value.getBitWidth() < 1)
28 return emitError() <<
"bit-width must be at least 1, but got "
29 << value.getBitWidth();
34 unsigned width = getValue().getBitWidth();
36 StringRef pref = prefix ?
"#" :
"";
38 getValue().toString(toPrint, 16,
false,
false,
false);
42 return (pref +
"x" + Twine(leadingZeros) + toPrint).str();
45 getValue().toString(toPrint, 2,
false,
false,
false);
48 return (pref +
"b" + Twine(leadingZeros) + toPrint).str();
52 static FailureOr<APInt>
59 return emitError() <<
"expected at least one digit";
62 return APInt(value.size() - 2, std::string(value.begin() + 2, value.end()),
66 return APInt((value.size() - 2) * 4,
67 std::string(value.begin() + 2, value.end()), 16);
69 return emitError() <<
"expected either 'b' or 'x'";
75 assert(succeeded(maybeValue) &&
"string must have SMT-LIB format");
83 if (failed(maybeValue))
86 return Base::getChecked(
emitError, context, *maybeValue);
91 return Base::get(context, APInt(width, value));
98 if (width < 64 && value >= (UINT64_C(1) << width)) {
99 emitError() <<
"value does not fit in a bit-vector of desired width";
102 return Base::getChecked(
emitError, context, APInt(width, value));
114 if (!odsType || !llvm::isa<BitVectorType>(odsType)) {
115 odsParser.
emitError(loc) <<
"explicit bit-vector type required";
119 unsigned width = llvm::cast<BitVectorType>(odsType).getWidth();
121 if (width > val.getBitWidth()) {
125 val = val.sext(width);
126 }
else if (width < val.getBitWidth()) {
129 unsigned neededBits =
130 val.isNegative() ? val.getSignificantBits() : val.getActiveBits();
131 if (width < neededBits) {
133 <<
"integer value out of range for given bit-vector type " << odsType;
136 val = val.trunc(width);
146 odsPrinter <<
"<" << getValue() <<
">";
157 #define GET_ATTRDEF_CLASSES
158 #include "mlir/Dialect/SMT/IR/SMTAttributes.cpp.inc"
160 void SMTDialect::registerAttributes() {
162 #define GET_ATTRDEF_LIST
163 #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,...