25 bool parse(Option &O, StringRef, StringRef Arg, APInt &Val) {
27 return O.error(
"empty integer literal");
29 if (!all_of(Arg, [](
char c) {
return isDigit(c); })) {
30 return O.error(
"arg must be in base 10 (digits).");
33 assert(std::cmp_less_equal(Arg.size(), std::numeric_limits<unsigned>::max()));
34 unsigned bits = std::max(1u, 4u * (
unsigned)Arg.size());
35 APInt tmp(bits, Arg, 10);
36 unsigned active = tmp.getActiveBits();
40 Val = tmp.zextOrTrunc(active);
48 const Option &O,
const APInt &V, OptionValue<APInt> Default,
size_t GlobalWidth
50 std::string Cur = llvm::toString(V, 10,
false);
52 std::string Def =
"<unspecified>";
53 if (Default.hasValue()) {
54 const APInt &D = Default.getValue();
55 Def = llvm::toString(D, 10,
false);
58 printOptionName(O, GlobalWidth);
59 llvm::outs() << Cur <<
" (default: " << Def <<
")\n";