summaryrefslogtreecommitdiff
path: root/lib/MC/MCParser/AsmLexer.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-02-14 16:23:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-02-14 16:23:08 +0000
commite186d7191c2cf95753a9790b1490df8a07416daa (patch)
treee7981a5eb55f3aab67652edafb7dc5a12f6f1b60 /lib/MC/MCParser/AsmLexer.cpp
parent5464c301c4472f54f700e171750fc51d39a0f4b8 (diff)
downloadllvm-e186d7191c2cf95753a9790b1490df8a07416daa.tar.gz
llvm-e186d7191c2cf95753a9790b1490df8a07416daa.tar.bz2
llvm-e186d7191c2cf95753a9790b1490df8a07416daa.tar.xz
Revert r15266. This fixes llvm.org/pr15266.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175173 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCParser/AsmLexer.cpp')
-rw-r--r--lib/MC/MCParser/AsmLexer.cpp59
1 files changed, 19 insertions, 40 deletions
diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp
index 8fcc264d68..530e94e8d3 100644
--- a/lib/MC/MCParser/AsmLexer.cpp
+++ b/lib/MC/MCParser/AsmLexer.cpp
@@ -179,48 +179,26 @@ static unsigned doLookAhead(const char *&CurPtr, unsigned DefaultRadix) {
}
}
bool isHex = *LookAhead == 'h' || *LookAhead == 'H';
- bool isBinary = LookAhead[-1] == 'b' || LookAhead[-1] == 'B';
- CurPtr = (isBinary || isHex || !FirstHex) ? LookAhead : FirstHex;
+ CurPtr = isHex || !FirstHex ? LookAhead : FirstHex;
if (isHex)
return 16;
- if (isBinary) {
- --CurPtr;
- return 2;
- }
return DefaultRadix;
}
/// LexDigit: First character is [0-9].
/// Local Label: [0-9][:]
-/// Forward/Backward Label: [0-9]+f or [0-9]b
-/// Binary integer: 0b[01]+ or [01][bB]
+/// Forward/Backward Label: [0-9][fb]
+/// Binary integer: 0b[01]+
/// Octal integer: 0[0-7]+
/// Hex integer: 0x[0-9a-fA-F]+ or [0x]?[0-9][0-9a-fA-F]*[hH]
/// Decimal integer: [1-9][0-9]*
AsmToken AsmLexer::LexDigit() {
-
- // Backward Label: [0-9]b
- if (*CurPtr == 'b') {
- // See if we actually have "0b" as part of something like "jmp 0b\n"
- if (!isdigit(CurPtr[1])) {
- long long Value;
- StringRef Result(TokStart, CurPtr - TokStart);
- if (Result.getAsInteger(10, Value))
- return ReturnError(TokStart, "invalid backward label");
-
- return AsmToken(AsmToken::Integer, Result, Value);
- }
- }
-
- // Binary integer: 1[01]*[bB]
// Decimal integer: [1-9][0-9]*
- // Hexidecimal integer: [1-9][0-9a-fA-F]*[hH]
if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
unsigned Radix = doLookAhead(CurPtr, 10);
- bool isDecimal = Radix == 10;
-
+ bool isHex = Radix == 16;
// Check for floating point literals.
- if (isDecimal && (*CurPtr == '.' || *CurPtr == 'e')) {
+ if (!isHex && (*CurPtr == '.' || *CurPtr == 'e')) {
++CurPtr;
return LexFloatLiteral();
}
@@ -233,7 +211,7 @@ AsmToken AsmLexer::LexDigit() {
// integer, but that do fit in an unsigned one, we just convert them over.
unsigned long long UValue;
if (Result.getAsInteger(Radix, UValue))
- return ReturnError(TokStart, isDecimal ? "invalid decimal number" :
+ return ReturnError(TokStart, !isHex ? "invalid decimal number" :
"invalid hexdecimal number");
Value = (long long)UValue;
}
@@ -249,9 +227,15 @@ AsmToken AsmLexer::LexDigit() {
return AsmToken(AsmToken::Integer, Result, Value);
}
- // Binary integer: 0b[01]+
if (*CurPtr == 'b') {
- const char *NumStart = ++CurPtr;
+ ++CurPtr;
+ // See if we actually have "0b" as part of something like "jmp 0b\n"
+ if (!isdigit(CurPtr[0])) {
+ --CurPtr;
+ StringRef Result(TokStart, CurPtr - TokStart);
+ return AsmToken(AsmToken::Integer, Result, 0);
+ }
+ const char *NumStart = CurPtr;
while (CurPtr[0] == '0' || CurPtr[0] == '1')
++CurPtr;
@@ -272,7 +256,6 @@ AsmToken AsmLexer::LexDigit() {
return AsmToken(AsmToken::Integer, Result, Value);
}
- // Hex integer: 0x[0-9a-fA-F]+
if (*CurPtr == 'x') {
++CurPtr;
const char *NumStart = CurPtr;
@@ -299,21 +282,17 @@ AsmToken AsmLexer::LexDigit() {
(int64_t)Result);
}
- // Binary: 0[01]*[Bb], but not 0b.
- // Octal: 0[0-7]*
- // Hexidecimal: [0][0-9a-fA-F]*[hH]
+ // Either octal or hexidecimal.
long long Value;
unsigned Radix = doLookAhead(CurPtr, 8);
- bool isBinary = Radix == 2;
- bool isOctal = Radix == 8;
+ bool isHex = Radix == 16;
StringRef Result(TokStart, CurPtr - TokStart);
if (Result.getAsInteger(Radix, Value))
- return ReturnError(TokStart, isOctal ? "invalid octal number" :
- isBinary ? "invalid binary number" :
+ return ReturnError(TokStart, !isHex ? "invalid octal number" :
"invalid hexdecimal number");
- // Consume the [bB][hH].
- if (Radix == 2 || Radix == 16)
+ // Consume the [hH].
+ if (Radix == 16)
++CurPtr;
// The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL