diff options
-rw-r--r-- | include/llvm/MC/MCParser/MCAsmLexer.h | 3 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmLexer.cpp | 29 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 3 |
3 files changed, 30 insertions, 5 deletions
diff --git a/include/llvm/MC/MCParser/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h index d690e81..b0039fe 100644 --- a/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/include/llvm/MC/MCParser/MCAsmLexer.h @@ -33,6 +33,9 @@ public: // Integer values. Integer, + // Real values. + Real, + // Register values (stored in IntVal). Only used by TargetAsmLexer. Register, diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp index 086df08..59da381 100644 --- a/lib/MC/MCParser/AsmLexer.cpp +++ b/lib/MC/MCParser/AsmLexer.cpp @@ -65,9 +65,21 @@ int AsmLexer::getNextChar() { } /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* +static bool IsIdentifierChar(char c) { + return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@'; +} AsmToken AsmLexer::LexIdentifier() { - while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || - *CurPtr == '.' || *CurPtr == '@') + // Check for floating point literals. + if (CurPtr[-1] == '.' && isdigit(*CurPtr)) { + while (isdigit(*CurPtr)) + ++CurPtr; + if (!IsIdentifierChar(*CurPtr)) { + return AsmToken(AsmToken::Real, + StringRef(TokStart, CurPtr - TokStart)); + } + } + + while (IsIdentifierChar(*CurPtr)) ++CurPtr; // Handle . as a special case. @@ -124,7 +136,6 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { CurPtr += 3; } - /// LexDigit: First character is [0-9]. /// Local Label: [0-9][:] /// Forward/Backward Label: [0-9][fb] @@ -132,13 +143,21 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { /// Octal integer: 0[0-7]+ /// Hex integer: 0x[0-9a-fA-F]+ /// Decimal integer: [1-9][0-9]* -/// TODO: FP literal. AsmToken AsmLexer::LexDigit() { // Decimal integer: [1-9][0-9]* if (CurPtr[-1] != '0') { while (isdigit(*CurPtr)) ++CurPtr; - + + // Check for floating point literals. + if (*CurPtr == '.') { + ++CurPtr; + while (isdigit(*CurPtr)) + ++CurPtr; + + return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart)); + } + StringRef Result(TokStart, CurPtr - TokStart); long long Value; diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 424cc08..6622f94 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -208,6 +208,9 @@ static int AsLexInput(const char *ProgName) { case AsmToken::Integer: Out->os() << "int: " << Lexer.getTok().getString() << '\n'; break; + case AsmToken::Real: + Out->os() << "real: " << Lexer.getTok().getString() << '\n'; + break; case AsmToken::Register: Out->os() << "register: " << Lexer.getTok().getRegVal() << '\n'; break; |