[llvm-commits] CVS: llvm/lib/AsmParser/Lexer.l
Reid Spencer
reid at x10sys.com
Tue Feb 27 18:24:44 PST 2007
Changes in directory llvm/lib/AsmParser:
Lexer.l updated: 1.98 -> 1.99
---
Log message:
Implement arbitrary integer constants through the use of APInt values.
Positive, negative, and hexadecimal integer constants will now return an
APInt for values having > 64 bits of precision.
---
Diffs of the changes: (+46 -14)
Lexer.l | 60 ++++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 46 insertions(+), 14 deletions(-)
Index: llvm/lib/AsmParser/Lexer.l
diff -u llvm/lib/AsmParser/Lexer.l:1.98 llvm/lib/AsmParser/Lexer.l:1.99
--- llvm/lib/AsmParser/Lexer.l:1.98 Thu Feb 1 20:16:22 2007
+++ llvm/lib/AsmParser/Lexer.l Tue Feb 27 20:24:27 2007
@@ -186,6 +186,7 @@
* it to deal with 64 bit numbers.
*/
HexIntConstant [us]0x[0-9A-Fa-f]+
+
%%
{Comment} { /* Ignore comments for now */ }
@@ -361,20 +362,51 @@
return ATSTRINGCONSTANT;
}
-
-
-{PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; }
-{NInteger} {
- uint64_t Val = atoull(yytext+1);
- // +1: we have bigger negative range
- if (Val > (uint64_t)INT64_MAX+1)
- GenerateError("Constant too large for signed 64 bits!");
- llvmAsmlval.SInt64Val = -Val;
- return ESINT64VAL;
- }
-{HexIntConstant} {
- llvmAsmlval.UInt64Val = HexIntToVal(yytext+3);
- return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL;
+{PInteger} { int len = strlen(yytext);
+ uint32_t numBits = ((len * 64) / 19) + 1;
+ APInt Tmp(numBits, yytext, len, 10);
+ uint32_t activeBits = Tmp.getActiveBits();
+ if (activeBits > 0 && activeBits < numBits)
+ Tmp.trunc(activeBits);
+ if (Tmp.getBitWidth() > 64) {
+ llvmAsmlval.APIntVal = new APInt(Tmp);
+ return EUAPINTVAL;
+ } else {
+ llvmAsmlval.UInt64Val = Tmp.getZExtValue();
+ return EUINT64VAL;
+ }
+ }
+{NInteger} { int len = strlen(yytext);
+ uint32_t numBits = (((len-1) * 64) / 19) + 1;
+ APInt Tmp(numBits, yytext, len, 10);
+ uint32_t minBits = Tmp.getMinSignedBits();
+ if (minBits > 0 && minBits < numBits)
+ Tmp.trunc(minBits);
+ if (Tmp.getBitWidth() > 64) {
+ llvmAsmlval.APIntVal = new APInt(Tmp);
+ return ESAPINTVAL;
+ } else {
+ llvmAsmlval.SInt64Val = Tmp.getSExtValue();
+ return ESINT64VAL;
+ }
+ }
+
+{HexIntConstant} { int len = strlen(yytext+3) - 3;
+ uint32_t bits = len * 4;
+ APInt Tmp(bits, yytext+3, len, 16);
+ uint32_t activeBits = Tmp.getActiveBits();
+ if (activeBits > 0 && activeBits < bits)
+ Tmp.trunc(activeBits);
+ if (Tmp.getBitWidth() > 64) {
+ llvmAsmlval.APIntVal = new APInt(Tmp);
+ return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
+ } else if (yytext[0] == 's') {
+ llvmAsmlval.SInt64Val = Tmp.getSExtValue();
+ return ESINT64VAL;
+ } else {
+ llvmAsmlval.UInt64Val = Tmp.getZExtValue();
+ return EUINT64VAL;
+ }
}
{LocalVarID} {
More information about the llvm-commits
mailing list