[llvm-commits] [llvm] r73858 - in /llvm/trunk/tools/llvm-mc: AsmLexer.cpp AsmLexer.h llvm-mc.cpp

Chris Lattner sabre at nondot.org
Sun Jun 21 12:56:35 PDT 2009


Author: lattner
Date: Sun Jun 21 14:56:35 2009
New Revision: 73858

URL: http://llvm.org/viewvc/llvm-project?rev=73858&view=rev
Log:
add string literals.

Modified:
    llvm/trunk/tools/llvm-mc/AsmLexer.cpp
    llvm/trunk/tools/llvm-mc/AsmLexer.h
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=73858&r1=73857&r2=73858&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Sun Jun 21 14:56:35 2009
@@ -77,7 +77,7 @@
   while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
          *CurPtr == '.' || *CurPtr == '@')
     ++CurPtr;
-  CurStrVal.assign(TokStart, CurPtr);   // Skip %
+  CurStrVal.assign(TokStart, CurPtr);   // Include %
   return asmtok::Identifier;
 }
 
@@ -194,6 +194,28 @@
   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;
@@ -228,6 +250,7 @@
   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();

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=73858&r1=73857&r2=73858&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Sun Jun 21 14:56:35 2009
@@ -28,10 +28,15 @@
     // Markers
     Eof, Error,
 
+    // String values.
     Identifier,
     Register,
+    String,
+    
+    // Integer values.
     IntVal,
     
+    // No-value.
     EndOfStatement,
     Colon,
     Plus,
@@ -70,7 +75,8 @@
   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;
   }
@@ -95,6 +101,7 @@
   asmtok::TokKind LexSlash();
   asmtok::TokKind LexHash();
   asmtok::TokKind LexDigit();
+  asmtok::TokKind LexQuote();
 };
   
 } // end namespace llvm

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=73858&r1=73857&r2=73858&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Sun Jun 21 14:56:35 2009
@@ -82,6 +82,9 @@
     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;





More information about the llvm-commits mailing list