Add support for lexing single quotes like 'c'.
authorRoman Divacky <rdivacky@freebsd.org>
Sat, 18 Dec 2010 08:56:37 +0000 (08:56 +0000)
committerRoman Divacky <rdivacky@freebsd.org>
Sat, 18 Dec 2010 08:56:37 +0000 (08:56 +0000)
This fixed 8615.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122150 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/AsmLexer.h
lib/MC/MCParser/AsmLexer.cpp
test/MC/AsmParser/directive_values.s

index 266416880922eafd5f9d0ccba9f67ac2d8fad586..99caebfab7f5d58106dd3408b3862afcb401a837 100644 (file)
@@ -60,6 +60,7 @@ private:
   AsmToken LexSlash();
   AsmToken LexLineComment();
   AsmToken LexDigit();
+  AsmToken LexSingleQuote();
   AsmToken LexQuote();
   AsmToken LexFloatLiteral();
 };
index 867cb208cec419415555c0c257edabb46d869874..085d519406de558da7f6cef08bb1075e4ea0615d 100644 (file)
@@ -265,6 +265,42 @@ AsmToken AsmLexer::LexDigit() {
   return AsmToken(AsmToken::Integer, Result, Value);
 }
 
+/// LexSingleQuote: Integer: 'b'
+AsmToken AsmLexer::LexSingleQuote() {
+  int CurChar = getNextChar();
+
+  if (CurChar == '\\')
+    CurChar = getNextChar();
+
+  if (CurChar == EOF)
+    return ReturnError(TokStart, "unterminated single quote");
+
+  CurChar = getNextChar();
+
+  if (CurChar != '\'')
+    return ReturnError(TokStart, "single quote way too long");
+
+  // The idea here being that 'c' is basically just an integral
+  // constant.
+  StringRef Res = StringRef(TokStart,CurPtr - TokStart);
+  long long Value;
+
+  if (Res.startswith("\'\\")) {
+    char theChar = Res[2];
+    switch (theChar) {
+      default: Value = theChar; break;
+      case '\'': Value = '\''; break;
+      case 't': Value = '\t'; break;
+      case 'n': Value = '\n'; break;
+      case 'b': Value = '\b'; break;
+    }
+  } else
+    Value = TokStart[1];
+
+  return AsmToken(AsmToken::Integer, Res, Value); 
+}
+
+
 /// LexQuote: String: "..."
 AsmToken AsmLexer::LexQuote() {
   int CurChar = getNextChar();
@@ -361,6 +397,7 @@ AsmToken AsmLexer::LexToken() {
   case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
   case '/': return LexSlash();
   case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
+  case '\'': return LexSingleQuote();
   case '"': return LexQuote();
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
index c222a304848e926eb2214754c363448b904c916f..98259bdb29d50bccb3b48eb27e0fd1397a49ef0b 100644 (file)
@@ -40,3 +40,19 @@ TEST5:
         .value 8
 # CHECK: TEST5:
 # CHECK: .short 8
+
+TEST6:
+        .byte 'c'
+        .byte '\''
+        .byte '\\'
+        .byte '\#'
+        .byte '\t'
+        .byte '\n'
+
+# CHECK: TEST6
+# CHECK:        .byte   99
+# CHECK:        .byte   39
+# CHECK:        .byte   92
+# CHECK:        .byte   35
+# CHECK:        .byte   9
+# CHECK:        .byte   10