aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCParser/AsmLexer.cpp
diff options
context:
space:
mode:
authorEric Astor <epastor@google.com>2020-09-23 13:57:43 -0400
committerEric Astor <epastor@google.com>2020-09-23 13:59:34 -0400
commitb901b6ab173ac77edfe97e0dbd138410b940b4bc (patch)
treee7153606927dd90d849746a215f705d15756bcd7 /llvm/lib/MC/MCParser/AsmLexer.cpp
parent7a3c643c35590df67716dfe3e3c60195ae385e43 (diff)
downloadllvm-b901b6ab173ac77edfe97e0dbd138410b940b4bc.zip
llvm-b901b6ab173ac77edfe97e0dbd138410b940b4bc.tar.gz
llvm-b901b6ab173ac77edfe97e0dbd138410b940b4bc.tar.bz2
Revert "[ms] [llvm-ml] Add support for .radix directive, and accept all radix specifiers"
This reverts commit 5dd1b6d612655c9006ba97a8b6487ded80719b48.
Diffstat (limited to 'llvm/lib/MC/MCParser/AsmLexer.cpp')
-rw-r--r--llvm/lib/MC/MCParser/AsmLexer.cpp122
1 files changed, 21 insertions, 101 deletions
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp
index 2099079..5a571c7 100644
--- a/llvm/lib/MC/MCParser/AsmLexer.cpp
+++ b/llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -18,7 +18,6 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCParser/MCAsmLexer.h"
-#include "llvm/Support/Compiler.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SaveAndRestore.h"
#include <cassert>
@@ -272,13 +271,6 @@ static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix,
return DefaultRadix;
}
-static const char *findLastDigit(const char *CurPtr, unsigned DefaultRadix) {
- while (hexDigitValue(*CurPtr) < DefaultRadix) {
- ++CurPtr;
- }
- return CurPtr;
-}
-
static AsmToken intToken(StringRef Ref, APInt &Value)
{
if (Value.isIntN(64))
@@ -286,21 +278,6 @@ static AsmToken intToken(StringRef Ref, APInt &Value)
return AsmToken(AsmToken::BigNum, Ref, Value);
}
-static std::string radixName(unsigned Radix) {
- switch (Radix) {
- case 2:
- return "binary";
- case 8:
- return "octal";
- case 10:
- return "decimal";
- case 16:
- return "hexadecimal";
- default:
- return "base-" + std::to_string(Radix);
- }
-}
-
/// LexDigit: First character is [0-9].
/// Local Label: [0-9][:]
/// Forward/Backward Label: [0-9][fb]
@@ -309,46 +286,16 @@ static std::string radixName(unsigned Radix) {
/// 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() {
- // MASM-flavor binary integer: [01]+[yY] (if DefaultRadix < 16, [bByY])
- // MASM-flavor octal integer: [0-7]+[oOqQ]
- // MASM-flavor decimal integer: [0-9]+[tT] (if DefaultRadix < 16, [dDtT])
+ // MASM-flavor binary integer: [01]+[bB]
// MASM-flavor hexadecimal integer: [0-9][0-9a-fA-F]*[hH]
if (LexMasmIntegers && isdigit(CurPtr[-1])) {
- const char *FirstNonBinary =
- (CurPtr[-1] != '0' && CurPtr[-1] != '1') ? CurPtr - 1 : nullptr;
- const char *FirstNonDecimal =
- (CurPtr[-1] < '0' || CurPtr[-1] > '9') ? CurPtr - 1 : nullptr;
+ const char *FirstNonBinary = (CurPtr[-1] != '0' && CurPtr[-1] != '1') ?
+ CurPtr - 1 : nullptr;
const char *OldCurPtr = CurPtr;
while (isHexDigit(*CurPtr)) {
- switch (*CurPtr) {
- default:
- if (!FirstNonDecimal) {
- FirstNonDecimal = CurPtr;
- }
- LLVM_FALLTHROUGH;
- case '9':
- case '8':
- case '7':
- case '6':
- case '5':
- case '4':
- case '3':
- case '2':
- if (!FirstNonBinary) {
- FirstNonBinary = CurPtr;
- }
- break;
- case '1':
- case '0':
- break;
- }
- ++CurPtr;
- }
- if (*CurPtr == '.') {
- // MASM float literals (other than hex floats) always contain a ".", and
- // are always written in decimal.
+ if (*CurPtr != '0' && *CurPtr != '1' && !FirstNonBinary)
+ FirstNonBinary = CurPtr;
++CurPtr;
- return LexFloatLiteral();
}
unsigned Radix = 0;
@@ -356,61 +303,28 @@ AsmToken AsmLexer::LexDigit() {
// hexadecimal number
++CurPtr;
Radix = 16;
- } else if (*CurPtr == 't' || *CurPtr == 'T') {
- // decimal number
- ++CurPtr;
- Radix = 10;
- } else if (*CurPtr == 'o' || *CurPtr == 'O' || *CurPtr == 'q' ||
- *CurPtr == 'Q') {
- // octal number
- ++CurPtr;
- Radix = 8;
- } else if (*CurPtr == 'y' || *CurPtr == 'Y') {
- // binary number
- ++CurPtr;
- Radix = 2;
- } else if (FirstNonDecimal && FirstNonDecimal + 1 == CurPtr &&
- DefaultRadix < 14 &&
- (*FirstNonDecimal == 'd' || *FirstNonDecimal == 'D')) {
- Radix = 10;
} else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
- DefaultRadix < 12 &&
- (*FirstNonBinary == 'b' || *FirstNonBinary == 'B')) {
+ (*FirstNonBinary == 'b' || *FirstNonBinary == 'B'))
Radix = 2;
- }
- if (Radix) {
+ if (Radix == 2 || Radix == 16) {
StringRef Result(TokStart, CurPtr - TokStart);
APInt Value(128, 0, true);
if (Result.drop_back().getAsInteger(Radix, Value))
- return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
+ return ReturnError(TokStart, Radix == 2 ? "invalid binary number" :
+ "invalid hexdecimal number");
// MSVC accepts and ignores type suffices on integer literals.
SkipIgnoredIntegerSuffix(CurPtr);
return intToken(Result, Value);
- }
+ }
- // default-radix integers, or floating point numbers, fall through
+ // octal/decimal integers, or floating point numbers, fall through
CurPtr = OldCurPtr;
}
- // MASM default-radix integers: [0-9a-fA-F]+
- // (All other integer literals have a radix specifier.)
- if (LexMasmIntegers) {
- CurPtr = findLastDigit(CurPtr, 16);
- StringRef Result(TokStart, CurPtr - TokStart);
-
- APInt Value(128, 0, true);
- if (Result.getAsInteger(DefaultRadix, Value)) {
- return ReturnError(TokStart,
- "invalid " + radixName(DefaultRadix) + " number");
- }
-
- return intToken(Result, Value);
- }
-
// Decimal integer: [1-9][0-9]*
if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
unsigned Radix = doHexLookAhead(CurPtr, 10, LexMasmIntegers);
@@ -425,9 +339,13 @@ AsmToken AsmLexer::LexDigit() {
StringRef Result(TokStart, CurPtr - TokStart);
APInt Value(128, 0, true);
- if (Result.getAsInteger(Radix, Value)) {
- return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
- }
+ if (Result.getAsInteger(Radix, Value))
+ return ReturnError(TokStart, !isHex ? "invalid decimal number" :
+ "invalid hexdecimal number");
+
+ // Consume the [hH].
+ if (LexMasmIntegers && Radix == 16)
+ ++CurPtr;
// The darwin/x86 (and x86-64) assembler accepts and ignores type
// suffices on integer literals.
@@ -498,9 +416,11 @@ AsmToken AsmLexer::LexDigit() {
// Either octal or hexadecimal.
APInt Value(128, 0, true);
unsigned Radix = doHexLookAhead(CurPtr, 8, LexMasmIntegers);
+ bool isHex = Radix == 16;
StringRef Result(TokStart, CurPtr - TokStart);
if (Result.getAsInteger(Radix, Value))
- return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
+ return ReturnError(TokStart, !isHex ? "invalid octal number" :
+ "invalid hexdecimal number");
// Consume the [hH].
if (Radix == 16)