MC/Lexer: Add 'Real' token type for floating point literals.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 24 Sep 2010 01:59:31 +0000 (01:59 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 24 Sep 2010 01:59:31 +0000 (01:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114718 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/MCAsmLexer.h
lib/MC/MCParser/AsmLexer.cpp
tools/llvm-mc/llvm-mc.cpp

index d690e810bd39f85c83c826e4d07c2432a7783256..b0039fe2babf34a269ab6ac3490d879d46221752 100644 (file)
@@ -33,6 +33,9 @@ public:
     // Integer values.
     Integer,
     
+    // Real values.
+    Real,
+    
     // Register values (stored in IntVal).  Only used by TargetAsmLexer.
     Register,
     
index 086df081a938f0ebebedb7880aca3fddd3b16c03..59da3817c18bd5d6b1097d1562bb4278fedcf42a 100644 (file)
@@ -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;
index 424cc08890d84ff60eeb6375f102f388b089d066..6622f94d89c14057c66440a5cfab9c8d05548944 100644 (file)
@@ -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;