diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-28 02:24:27 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-28 02:24:27 +0000 |
commit | c34ebfbcfd3e0209ffab35fbe36991b4a2f43d3a (patch) | |
tree | 4a02a70597c690ab52f76d3c4f2a5d26574d422b /lib/AsmParser | |
parent | f231004a1c9f2b064c1daeb04a2d3db800c1b1c9 (diff) | |
download | external_llvm-c34ebfbcfd3e0209ffab35fbe36991b4a2f43d3a.zip external_llvm-c34ebfbcfd3e0209ffab35fbe36991b4a2f43d3a.tar.gz external_llvm-c34ebfbcfd3e0209ffab35fbe36991b4a2f43d3a.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/Lexer.l | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index e5e8256..2950b18 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -186,6 +186,7 @@ HexFPConstant 0x[0-9A-Fa-f]+ * it to deal with 64 bit numbers. */ HexIntConstant [us]0x[0-9A-Fa-f]+ + %% {Comment} { /* Ignore comments for now */ } @@ -361,20 +362,51 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); } 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; +{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; + } } -{HexIntConstant} { - llvmAsmlval.UInt64Val = HexIntToVal(yytext+3); - return yytext[0] == 's' ? ESINT64VAL : 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} { |