16#include "mlir/IR/DialectImplementation.h"
17#include "llvm/ADT/TypeSwitch.h"
22using mlir::AsmPrinter;
28Attribute FVIntegerAttr::parse(AsmParser &p, Type) {
33 if (p.parseLess() ||
parseFVInt(p, value) || p.parseColon() ||
34 p.getCurrentLocation(&widthLoc) || p.parseInteger(width) ||
41 if (width < neededBits) {
42 p.emitError(widthLoc) <<
"integer literal requires at least " << neededBits
43 <<
" bits, but attribute specifies only " << width;
47 return FVIntegerAttr::get(p.getContext(), value.
sextOrTrunc(width));
50void FVIntegerAttr::print(AsmPrinter &p)
const {
53 p <<
" : " << getValue().getBitWidth() <<
">";
60#define GET_ATTRDEF_CLASSES
61#include "circt/Dialect/Moore/MooreAttributes.cpp.inc"
63void MooreDialect::registerAttributes() {
65#define GET_ATTRDEF_LIST
66#include "circt/Dialect/Moore/MooreAttributes.cpp.inc"
Four-valued arbitrary precision integers.
FVInt sextOrTrunc(unsigned bitWidth) const
Truncate or sign-extend to a target bit width.
bool isNegative() const
Determine whether the integer interpreted as a signed number would be negative.
unsigned getSignificantBits() const
Compute the minimum bit width necessary to accurately represent this integer's value and sign.
unsigned getActiveBits() const
Compute the number of active bits in the value.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void printFVInt(AsmPrinter &p, const FVInt &value)
Print a four-valued integer usign an AsmPrinter.
ParseResult parseFVInt(AsmParser &p, FVInt &result)
Parse a four-valued integer using an AsmParser.