22#ifndef CIRCT_SUPPORT_FORMATINTEGER_H
23#define CIRCT_SUPPORT_FORMATINTEGER_H
25#include "llvm/ADT/APInt.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/Support/MathExtras.h"
28#include "llvm/Support/raw_ostream.h"
40 return isSigned ? 2 : 1;
44 const double baseConversionFactor = 0.30103;
45 unsigned digits = std::ceil(bits * baseConversionFactor);
46 return isSigned ? digits + 1 : digits;
58 return llvm::divideCeil(bits, 3);
60 return llvm::divideCeil(bits, 4);
75inline void formatInteger(llvm::raw_ostream &os,
const llvm::APInt &value,
76 unsigned radix,
bool isUpperCase,
bool isLeftAligned,
78 std::optional<int32_t> specifierWidth,
80 llvm::SmallVector<char, 32> digits;
81 value.toString(digits, radix, isSigned,
false,
85 specifierWidth.has_value() && *specifierWidth >= 0
86 ?
static_cast<unsigned>(*specifierWidth)
89 fieldWidth > digits.size() ? fieldWidth - digits.size() : 0;
92 llvm::SmallVector<char, 32> padding(padWidth,
' ');
93 os << digits << padding;
95 llvm::SmallVector<char, 32> padding(padWidth, paddingChar);
96 os << padding << digits;
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
unsigned getDecimalDigitWidth(unsigned bits, bool isSigned)
Number of decimal digits required to print the largest value of an integer type of the given bit widt...
unsigned getNaturalIntegerWidth(unsigned bits, unsigned radix, bool isSigned)
Natural field width of an integer type printed in the given radix: the number of digits required to p...
void formatInteger(llvm::raw_ostream &os, const llvm::APInt &value, unsigned radix, bool isUpperCase, bool isLeftAligned, char paddingChar, std::optional< int32_t > specifierWidth, bool isSigned)
Format value in the given radix and emit it to os, padded to a field width.