add string literals.
authorChris Lattner <sabre@nondot.org>
Sun, 21 Jun 2009 19:56:35 +0000 (19:56 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 21 Jun 2009 19:56:35 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73858 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-mc/AsmLexer.cpp
tools/llvm-mc/AsmLexer.h
tools/llvm-mc/llvm-mc.cpp

index 4a68d0d354c8571c49b12b477eb9c3d6f9e59e61..f29075ace4875596733b2d8e52a1572fc5f64e77 100644 (file)
@@ -77,7 +77,7 @@ asmtok::TokKind AsmLexer::LexIdentifier() {
   while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
          *CurPtr == '.' || *CurPtr == '@')
     ++CurPtr;
   while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
          *CurPtr == '.' || *CurPtr == '@')
     ++CurPtr;
-  CurStrVal.assign(TokStart, CurPtr);   // Skip %
+  CurStrVal.assign(TokStart, CurPtr);   // Include %
   return asmtok::Identifier;
 }
 
   return asmtok::Identifier;
 }
 
@@ -194,6 +194,28 @@ asmtok::TokKind AsmLexer::LexDigit() {
   return asmtok::IntVal;
 }
 
   return asmtok::IntVal;
 }
 
+/// LexQuote: String: "..."
+asmtok::TokKind AsmLexer::LexQuote() {
+  int CurChar = getNextChar();
+  // TODO: does gas allow multiline string constants?
+  while (CurChar != '"') {
+    if (CurChar == '\\') {
+      // Allow \", etc.
+      CurChar = getNextChar();
+    }
+    
+    if (CurChar == EOF) {
+      PrintError(TokStart, "unterminated string constant");
+      return asmtok::Eof;
+    }
+
+    CurChar = getNextChar();
+  }
+  
+  CurStrVal.assign(TokStart, CurPtr);   // include quotes.
+  return asmtok::String;
+}
+
 
 asmtok::TokKind AsmLexer::LexToken() {
   TokStart = CurPtr;
 
 asmtok::TokKind AsmLexer::LexToken() {
   TokStart = CurPtr;
@@ -228,6 +250,7 @@ asmtok::TokKind AsmLexer::LexToken() {
   case '%': return LexPercent();
   case '/': return LexSlash();
   case '#': return LexHash();
   case '%': return LexPercent();
   case '/': return LexSlash();
   case '#': return LexHash();
+  case '"': return LexQuote();
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
     return LexDigit();
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
     return LexDigit();
index 9e694c7a3010363b67f418b2c76d3d60c8177b70..c5d1722e491db90e06932e76286f55791b8c1d6f 100644 (file)
@@ -28,10 +28,15 @@ namespace asmtok {
     // Markers
     Eof, Error,
 
     // Markers
     Eof, Error,
 
+    // String values.
     Identifier,
     Register,
     Identifier,
     Register,
+    String,
+    
+    // Integer values.
     IntVal,
     
     IntVal,
     
+    // No-value.
     EndOfStatement,
     Colon,
     Plus,
     EndOfStatement,
     Colon,
     Plus,
@@ -70,7 +75,8 @@ public:
   asmtok::TokKind getKind() const { return CurKind; }
   
   const std::string &getCurStrVal() const {
   asmtok::TokKind getKind() const { return CurKind; }
   
   const std::string &getCurStrVal() const {
-    assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register) &&
+    assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
+            CurKind == asmtok::String) &&
            "This token doesn't have a string value");
     return CurStrVal;
   }
            "This token doesn't have a string value");
     return CurStrVal;
   }
@@ -95,6 +101,7 @@ private:
   asmtok::TokKind LexSlash();
   asmtok::TokKind LexHash();
   asmtok::TokKind LexDigit();
   asmtok::TokKind LexSlash();
   asmtok::TokKind LexHash();
   asmtok::TokKind LexDigit();
+  asmtok::TokKind LexQuote();
 };
   
 } // end namespace llvm
 };
   
 } // end namespace llvm
index 20f353ca670923461ec8fe339a1f6e00744f1498..7a179e83ff6a66ad71a11adf37ee4fcd760b8d97 100644 (file)
@@ -82,6 +82,9 @@ static int AssembleInput(const char *ProgName) {
     case asmtok::Register:
       outs() << "register: " << Lexer.getCurStrVal() << '\n';
       break;
     case asmtok::Register:
       outs() << "register: " << Lexer.getCurStrVal() << '\n';
       break;
+    case asmtok::String:
+      outs() << "string: " << Lexer.getCurStrVal() << '\n';
+      break;
     case asmtok::IntVal:
       outs() << "int: " << Lexer.getCurIntVal() << '\n';
       break;
     case asmtok::IntVal:
       outs() << "int: " << Lexer.getCurIntVal() << '\n';
       break;