[llvm-commits] [llvm] r122150 - in /llvm/trunk: include/llvm/MC/MCParser/AsmLexer.h lib/MC/MCParser/AsmLexer.cpp test/MC/AsmParser/directive_values.s
Roman Divacky
rdivacky at freebsd.org
Sat Dec 18 00:56:37 PST 2010
Author: rdivacky
Date: Sat Dec 18 02:56:37 2010
New Revision: 122150
URL: http://llvm.org/viewvc/llvm-project?rev=122150&view=rev
Log:
Add support for lexing single quotes like 'c'.
This fixed 8615.
Modified:
llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
llvm/trunk/test/MC/AsmParser/directive_values.s
Modified: llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h?rev=122150&r1=122149&r2=122150&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h Sat Dec 18 02:56:37 2010
@@ -60,6 +60,7 @@
AsmToken LexSlash();
AsmToken LexLineComment();
AsmToken LexDigit();
+ AsmToken LexSingleQuote();
AsmToken LexQuote();
AsmToken LexFloatLiteral();
};
Modified: llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmLexer.cpp?rev=122150&r1=122149&r2=122150&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmLexer.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmLexer.cpp Sat Dec 18 02:56:37 2010
@@ -265,6 +265,42 @@
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 @@
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':
Modified: llvm/trunk/test/MC/AsmParser/directive_values.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_values.s?rev=122150&r1=122149&r2=122150&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_values.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_values.s Sat Dec 18 02:56:37 2010
@@ -40,3 +40,19 @@
.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
More information about the llvm-commits
mailing list