blob: 89374d0c3fb960e9d1201a71dcd6f8da8812b347 [file] [log] [blame]
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +00001//===- AsmLexer.cpp - Lexer for Assembly Files ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class implements the lexer for assembly files.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner5b0e01c2010-01-22 01:58:08 +000014#include "llvm/MC/MCParser/AsmLexer.h"
Sean Callanan7a77eae2010-01-21 00:19:58 +000015#include "llvm/Support/SMLoc.h"
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000016#include "llvm/Support/MemoryBuffer.h"
Kevin Enderbyf92f9902009-09-04 21:45:34 +000017#include "llvm/MC/MCAsmInfo.h"
Nick Lewycky0de20af2010-12-19 20:43:38 +000018#include <cctype>
Chris Lattnerd0765612009-06-21 19:21:25 +000019#include <cerrno>
Duncan Sands376c6f12009-06-22 06:59:32 +000020#include <cstdio>
Chris Lattner99f0b602009-06-21 19:43:50 +000021#include <cstdlib>
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000022using namespace llvm;
23
Sean Callanan7a77eae2010-01-21 00:19:58 +000024AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) {
25 CurBuf = NULL;
26 CurPtr = NULL;
Chris Lattner4c501fc2009-06-24 00:33:19 +000027}
28
29AsmLexer::~AsmLexer() {
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000030}
31
Sean Callanan7a77eae2010-01-21 00:19:58 +000032void AsmLexer::setBuffer(const MemoryBuffer *buf, const char *ptr) {
33 CurBuf = buf;
Jim Grosbach01af6c42011-02-11 19:05:56 +000034
Sean Callanan7a77eae2010-01-21 00:19:58 +000035 if (ptr)
36 CurPtr = ptr;
37 else
38 CurPtr = CurBuf->getBufferStart();
Jim Grosbach01af6c42011-02-11 19:05:56 +000039
Sean Callanan7a77eae2010-01-21 00:19:58 +000040 TokStart = 0;
41}
42
Chris Lattnerd0765612009-06-21 19:21:25 +000043/// ReturnError - Set the error to the specified string at the specified
Daniel Dunbarf2dcd772009-07-28 16:08:33 +000044/// location. This is defined to always return AsmToken::Error.
Daniel Dunbar8368f4e2009-07-28 03:00:54 +000045AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
Sean Callanan70855e42010-01-20 22:18:24 +000046 SetError(SMLoc::getFromPointer(Loc), Msg);
Jim Grosbach01af6c42011-02-11 19:05:56 +000047
Daniel Dunbarf2dcd772009-07-28 16:08:33 +000048 return AsmToken(AsmToken::Error, StringRef(Loc, 0));
Chris Lattnerd0765612009-06-21 19:21:25 +000049}
50
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000051int AsmLexer::getNextChar() {
52 char CurChar = *CurPtr++;
53 switch (CurChar) {
54 default:
55 return (unsigned char)CurChar;
Sean Callanan7a77eae2010-01-21 00:19:58 +000056 case 0:
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000057 // A nul character in the stream is either the end of the current buffer or
58 // a random nul in the file. Disambiguate that here.
59 if (CurPtr-1 != CurBuf->getBufferEnd())
60 return 0; // Just whitespace.
Jim Grosbach01af6c42011-02-11 19:05:56 +000061
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000062 // Otherwise, return end of file.
Jim Grosbach01af6c42011-02-11 19:05:56 +000063 --CurPtr; // Another call to lex will return EOF again.
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000064 return EOF;
65 }
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +000066}
67
Daniel Dunbard116d8a2010-09-27 20:12:52 +000068/// LexFloatLiteral: [0-9]*[.][0-9]*([eE][+-]?[0-9]*)?
69///
70/// The leading integral digit sequence and dot should have already been
71/// consumed, some or all of the fractional digit sequence *can* have been
72/// consumed.
73AsmToken AsmLexer::LexFloatLiteral() {
74 // Skip the fractional digit sequence.
75 while (isdigit(*CurPtr))
76 ++CurPtr;
77
78 // Check for exponent; we intentionally accept a slighlty wider set of
79 // literals here and rely on the upstream client to reject invalid ones (e.g.,
80 // "1e+").
81 if (*CurPtr == 'e' || *CurPtr == 'E') {
82 ++CurPtr;
83 if (*CurPtr == '-' || *CurPtr == '+')
84 ++CurPtr;
85 while (isdigit(*CurPtr))
86 ++CurPtr;
87 }
88
89 return AsmToken(AsmToken::Real,
90 StringRef(TokStart, CurPtr - TokStart));
91}
92
Daniel Dunbarb0ceb762010-05-06 14:46:38 +000093/// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
Daniel Dunbar3068a932010-09-24 01:59:31 +000094static bool IsIdentifierChar(char c) {
95 return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@';
96}
Daniel Dunbar8368f4e2009-07-28 03:00:54 +000097AsmToken AsmLexer::LexIdentifier() {
Daniel Dunbar3068a932010-09-24 01:59:31 +000098 // Check for floating point literals.
99 if (CurPtr[-1] == '.' && isdigit(*CurPtr)) {
Daniel Dunbard116d8a2010-09-27 20:12:52 +0000100 // Disambiguate a .1243foo identifier from a floating literal.
Daniel Dunbar3068a932010-09-24 01:59:31 +0000101 while (isdigit(*CurPtr))
102 ++CurPtr;
Daniel Dunbard116d8a2010-09-27 20:12:52 +0000103 if (*CurPtr == 'e' || *CurPtr == 'E' || !IsIdentifierChar(*CurPtr))
104 return LexFloatLiteral();
Daniel Dunbar3068a932010-09-24 01:59:31 +0000105 }
106
107 while (IsIdentifierChar(*CurPtr))
Chris Lattnerd0765612009-06-21 19:21:25 +0000108 ++CurPtr;
Jim Grosbach01af6c42011-02-11 19:05:56 +0000109
Chris Lattner6b55cb92010-04-14 04:40:28 +0000110 // Handle . as a special case.
Daniel Dunbarb0ceb762010-05-06 14:46:38 +0000111 if (CurPtr == TokStart+1 && TokStart[0] == '.')
112 return AsmToken(AsmToken::Dot, StringRef(TokStart, 1));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000113
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000114 return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
Chris Lattnerd0765612009-06-21 19:21:25 +0000115}
116
Chris Lattnerd0765612009-06-21 19:21:25 +0000117/// LexSlash: Slash: /
118/// C-Style Comment: /* ... */
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000119AsmToken AsmLexer::LexSlash() {
Daniel Dunbar6b22f9c2009-06-29 21:58:22 +0000120 switch (*CurPtr) {
121 case '*': break; // C style comment.
122 case '/': return ++CurPtr, LexLineComment();
Daniel Dunbar7484d2c2010-10-25 20:18:53 +0000123 default: return AsmToken(AsmToken::Slash, StringRef(CurPtr-1, 1));
Daniel Dunbar6b22f9c2009-06-29 21:58:22 +0000124 }
Chris Lattnerd0765612009-06-21 19:21:25 +0000125
126 // C Style comment.
127 ++CurPtr; // skip the star.
128 while (1) {
129 int CurChar = getNextChar();
130 switch (CurChar) {
131 case EOF:
Chris Lattnerb0133452009-06-21 20:16:42 +0000132 return ReturnError(TokStart, "unterminated comment");
Chris Lattnerd0765612009-06-21 19:21:25 +0000133 case '*':
134 // End of the comment?
135 if (CurPtr[0] != '/') break;
Jim Grosbach01af6c42011-02-11 19:05:56 +0000136
Chris Lattnerd0765612009-06-21 19:21:25 +0000137 ++CurPtr; // End the */.
138 return LexToken();
139 }
140 }
141}
142
Daniel Dunbar6b22f9c2009-06-29 21:58:22 +0000143/// LexLineComment: Comment: #[^\n]*
144/// : //[^\n]*
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000145AsmToken AsmLexer::LexLineComment() {
146 // FIXME: This is broken if we happen to a comment at the end of a file, which
147 // was .included, and which doesn't end with a newline.
Chris Lattnerd0765612009-06-21 19:21:25 +0000148 int CurChar = getNextChar();
149 while (CurChar != '\n' && CurChar != '\n' && CurChar != EOF)
150 CurChar = getNextChar();
Jim Grosbach01af6c42011-02-11 19:05:56 +0000151
Chris Lattnerd0765612009-06-21 19:21:25 +0000152 if (CurChar == EOF)
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000153 return AsmToken(AsmToken::Eof, StringRef(CurPtr, 0));
154 return AsmToken(AsmToken::EndOfStatement, StringRef(CurPtr, 0));
Chris Lattnerd0765612009-06-21 19:21:25 +0000155}
156
Chris Lattner02db8f62010-08-24 00:43:25 +0000157static void SkipIgnoredIntegerSuffix(const char *&CurPtr) {
158 if (CurPtr[0] == 'L' && CurPtr[1] == 'L')
159 CurPtr += 2;
160 if (CurPtr[0] == 'U' && CurPtr[1] == 'L' && CurPtr[2] == 'L')
161 CurPtr += 3;
162}
163
Chris Lattnerd0765612009-06-21 19:21:25 +0000164/// LexDigit: First character is [0-9].
165/// Local Label: [0-9][:]
166/// Forward/Backward Label: [0-9][fb]
167/// Binary integer: 0b[01]+
168/// Octal integer: 0[0-7]+
169/// Hex integer: 0x[0-9a-fA-F]+
170/// Decimal integer: [1-9][0-9]*
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000171AsmToken AsmLexer::LexDigit() {
Chris Lattnerd0765612009-06-21 19:21:25 +0000172 // Decimal integer: [1-9][0-9]*
Daniel Dunbarce17f722010-09-24 17:10:26 +0000173 if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
Chris Lattnerd0765612009-06-21 19:21:25 +0000174 while (isdigit(*CurPtr))
175 ++CurPtr;
Daniel Dunbar3068a932010-09-24 01:59:31 +0000176
177 // Check for floating point literals.
Daniel Dunbard116d8a2010-09-27 20:12:52 +0000178 if (*CurPtr == '.' || *CurPtr == 'e') {
Daniel Dunbar3068a932010-09-24 01:59:31 +0000179 ++CurPtr;
Daniel Dunbard116d8a2010-09-27 20:12:52 +0000180 return LexFloatLiteral();
Daniel Dunbar3068a932010-09-24 01:59:31 +0000181 }
182
Chris Lattnere6494012010-01-22 07:34:12 +0000183 StringRef Result(TokStart, CurPtr - TokStart);
Chris Lattner02db8f62010-08-24 00:43:25 +0000184
Chris Lattnere6494012010-01-22 07:34:12 +0000185 long long Value;
Chris Lattner341b1d22010-03-13 19:25:13 +0000186 if (Result.getAsInteger(10, Value)) {
Chris Lattner03a102b2010-12-25 21:36:35 +0000187 // Allow positive values that are too large to fit into a signed 64-bit
188 // integer, but that do fit in an unsigned one, we just convert them over.
189 unsigned long long UValue;
190 if (Result.getAsInteger(10, UValue))
191 return ReturnError(TokStart, "invalid decimal number");
192 Value = (long long)UValue;
Chris Lattner341b1d22010-03-13 19:25:13 +0000193 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000194
Chris Lattner02db8f62010-08-24 00:43:25 +0000195 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
196 // suffixes on integer literals.
197 SkipIgnoredIntegerSuffix(CurPtr);
Jim Grosbach01af6c42011-02-11 19:05:56 +0000198
Chris Lattnere6494012010-01-22 07:34:12 +0000199 return AsmToken(AsmToken::Integer, Result, Value);
Chris Lattnerd0765612009-06-21 19:21:25 +0000200 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000201
Chris Lattnerd0765612009-06-21 19:21:25 +0000202 if (*CurPtr == 'b') {
203 ++CurPtr;
Kevin Enderby0510b482010-05-17 23:08:19 +0000204 // See if we actually have "0b" as part of something like "jmp 0b\n"
Kevin Enderby7bcc9e92010-05-18 18:09:20 +0000205 if (!isdigit(CurPtr[0])) {
Kevin Enderby0510b482010-05-17 23:08:19 +0000206 --CurPtr;
207 StringRef Result(TokStart, CurPtr - TokStart);
Kevin Enderby0510b482010-05-17 23:08:19 +0000208 return AsmToken(AsmToken::Integer, Result, 0);
209 }
Chris Lattnerd0765612009-06-21 19:21:25 +0000210 const char *NumStart = CurPtr;
211 while (CurPtr[0] == '0' || CurPtr[0] == '1')
212 ++CurPtr;
Jim Grosbach01af6c42011-02-11 19:05:56 +0000213
Chris Lattnerd0765612009-06-21 19:21:25 +0000214 // Requires at least one binary digit.
215 if (CurPtr == NumStart)
Chris Lattnere6494012010-01-22 07:34:12 +0000216 return ReturnError(TokStart, "Invalid binary number");
Jim Grosbach01af6c42011-02-11 19:05:56 +0000217
Chris Lattnere6494012010-01-22 07:34:12 +0000218 StringRef Result(TokStart, CurPtr - TokStart);
Jim Grosbach01af6c42011-02-11 19:05:56 +0000219
Chris Lattnere6494012010-01-22 07:34:12 +0000220 long long Value;
Chris Lattner02db8f62010-08-24 00:43:25 +0000221 if (Result.substr(2).getAsInteger(2, Value))
Chris Lattnere6494012010-01-22 07:34:12 +0000222 return ReturnError(TokStart, "Invalid binary number");
Jim Grosbach01af6c42011-02-11 19:05:56 +0000223
Chris Lattner02db8f62010-08-24 00:43:25 +0000224 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
225 // suffixes on integer literals.
226 SkipIgnoredIntegerSuffix(CurPtr);
Jim Grosbach01af6c42011-02-11 19:05:56 +0000227
Chris Lattnere6494012010-01-22 07:34:12 +0000228 return AsmToken(AsmToken::Integer, Result, Value);
Chris Lattnerd0765612009-06-21 19:21:25 +0000229 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000230
Chris Lattnerd0765612009-06-21 19:21:25 +0000231 if (*CurPtr == 'x') {
232 ++CurPtr;
233 const char *NumStart = CurPtr;
234 while (isxdigit(CurPtr[0]))
235 ++CurPtr;
Jim Grosbach01af6c42011-02-11 19:05:56 +0000236
Chris Lattnerd0765612009-06-21 19:21:25 +0000237 // Requires at least one hex digit.
238 if (CurPtr == NumStart)
239 return ReturnError(CurPtr-2, "Invalid hexadecimal number");
Chris Lattner6401c882010-01-22 01:17:12 +0000240
241 unsigned long long Result;
242 if (StringRef(TokStart, CurPtr - TokStart).getAsInteger(0, Result))
Chris Lattnere6494012010-01-22 07:34:12 +0000243 return ReturnError(TokStart, "Invalid hexadecimal number");
Jim Grosbach01af6c42011-02-11 19:05:56 +0000244
Chris Lattner02db8f62010-08-24 00:43:25 +0000245 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
246 // suffixes on integer literals.
247 SkipIgnoredIntegerSuffix(CurPtr);
Jim Grosbach01af6c42011-02-11 19:05:56 +0000248
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000249 return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
Chris Lattner6401c882010-01-22 01:17:12 +0000250 (int64_t)Result);
Chris Lattnerd0765612009-06-21 19:21:25 +0000251 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000252
Chris Lattnerd0765612009-06-21 19:21:25 +0000253 // Must be an octal number, it starts with 0.
254 while (*CurPtr >= '0' && *CurPtr <= '7')
255 ++CurPtr;
Jim Grosbach01af6c42011-02-11 19:05:56 +0000256
Chris Lattnere6494012010-01-22 07:34:12 +0000257 StringRef Result(TokStart, CurPtr - TokStart);
258 long long Value;
259 if (Result.getAsInteger(8, Value))
260 return ReturnError(TokStart, "Invalid octal number");
Jim Grosbach01af6c42011-02-11 19:05:56 +0000261
Chris Lattner02db8f62010-08-24 00:43:25 +0000262 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
263 // suffixes on integer literals.
264 SkipIgnoredIntegerSuffix(CurPtr);
Jim Grosbach01af6c42011-02-11 19:05:56 +0000265
Chris Lattnere6494012010-01-22 07:34:12 +0000266 return AsmToken(AsmToken::Integer, Result, Value);
Chris Lattnerd0765612009-06-21 19:21:25 +0000267}
268
Roman Divacky71d29162010-12-18 08:56:37 +0000269/// LexSingleQuote: Integer: 'b'
270AsmToken AsmLexer::LexSingleQuote() {
271 int CurChar = getNextChar();
272
273 if (CurChar == '\\')
274 CurChar = getNextChar();
275
276 if (CurChar == EOF)
277 return ReturnError(TokStart, "unterminated single quote");
278
279 CurChar = getNextChar();
280
281 if (CurChar != '\'')
282 return ReturnError(TokStart, "single quote way too long");
283
284 // The idea here being that 'c' is basically just an integral
285 // constant.
286 StringRef Res = StringRef(TokStart,CurPtr - TokStart);
287 long long Value;
288
289 if (Res.startswith("\'\\")) {
290 char theChar = Res[2];
291 switch (theChar) {
292 default: Value = theChar; break;
293 case '\'': Value = '\''; break;
294 case 't': Value = '\t'; break;
295 case 'n': Value = '\n'; break;
296 case 'b': Value = '\b'; break;
297 }
298 } else
299 Value = TokStart[1];
300
Jim Grosbach01af6c42011-02-11 19:05:56 +0000301 return AsmToken(AsmToken::Integer, Res, Value);
Roman Divacky71d29162010-12-18 08:56:37 +0000302}
303
304
Chris Lattner419a9742009-06-21 19:56:35 +0000305/// LexQuote: String: "..."
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000306AsmToken AsmLexer::LexQuote() {
Chris Lattner419a9742009-06-21 19:56:35 +0000307 int CurChar = getNextChar();
308 // TODO: does gas allow multiline string constants?
309 while (CurChar != '"') {
310 if (CurChar == '\\') {
311 // Allow \", etc.
312 CurChar = getNextChar();
313 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000314
Chris Lattner2adc9e72009-06-21 21:22:11 +0000315 if (CurChar == EOF)
316 return ReturnError(TokStart, "unterminated string constant");
Chris Lattner419a9742009-06-21 19:56:35 +0000317
318 CurChar = getNextChar();
319 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000320
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000321 return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
Chris Lattner419a9742009-06-21 19:56:35 +0000322}
323
Chris Lattnercb307a272009-08-10 01:39:42 +0000324StringRef AsmLexer::LexUntilEndOfStatement() {
325 TokStart = CurPtr;
326
Kevin Enderbyecd879a2009-09-16 18:08:00 +0000327 while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
Duncan Sands41b4a6b2010-07-12 08:16:59 +0000328 *CurPtr != ';' && // End of statement marker.
Chris Lattnercb307a272009-08-10 01:39:42 +0000329 *CurPtr != '\n' &&
330 *CurPtr != '\r' &&
Kevin Enderbyf92f9902009-09-04 21:45:34 +0000331 (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
Chris Lattnercb307a272009-08-10 01:39:42 +0000332 ++CurPtr;
Kevin Enderbyf92f9902009-09-04 21:45:34 +0000333 }
Chris Lattnercb307a272009-08-10 01:39:42 +0000334 return StringRef(TokStart, CurPtr-TokStart);
335}
Chris Lattnerd0765612009-06-21 19:21:25 +0000336
Kevin Enderbyecd879a2009-09-16 18:08:00 +0000337bool AsmLexer::isAtStartOfComment(char Char) {
Chris Lattner10a1cfd2009-09-27 19:38:39 +0000338 // FIXME: This won't work for multi-character comment indicators like "//".
339 return Char == *MAI.getCommentString();
Kevin Enderbyecd879a2009-09-16 18:08:00 +0000340}
341
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000342AsmToken AsmLexer::LexToken() {
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000343 TokStart = CurPtr;
344 // This always consumes at least one character.
345 int CurChar = getNextChar();
Jim Grosbach01af6c42011-02-11 19:05:56 +0000346
Kevin Enderbyecd879a2009-09-16 18:08:00 +0000347 if (isAtStartOfComment(CurChar))
348 return LexLineComment();
Kevin Enderbyf92f9902009-09-04 21:45:34 +0000349
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000350 switch (CurChar) {
351 default:
Daniel Dunbarb0ceb762010-05-06 14:46:38 +0000352 // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
353 if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')
Chris Lattnerd0765612009-06-21 19:21:25 +0000354 return LexIdentifier();
Jim Grosbach01af6c42011-02-11 19:05:56 +0000355
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000356 // Unknown character, emit an error.
Chris Lattnerb0133452009-06-21 20:16:42 +0000357 return ReturnError(TokStart, "invalid character in input");
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000358 case EOF: return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000359 case 0:
360 case ' ':
361 case '\t':
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000362 // Ignore whitespace.
363 return LexToken();
Chris Lattnerd0765612009-06-21 19:21:25 +0000364 case '\n': // FALL THROUGH.
365 case '\r': // FALL THROUGH.
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000366 case ';': return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
367 case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
368 case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
369 case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));
370 case '~': return AsmToken(AsmToken::Tilde, StringRef(TokStart, 1));
371 case '(': return AsmToken(AsmToken::LParen, StringRef(TokStart, 1));
372 case ')': return AsmToken(AsmToken::RParen, StringRef(TokStart, 1));
Kevin Enderby9c0f7fc2009-09-04 22:40:31 +0000373 case '[': return AsmToken(AsmToken::LBrac, StringRef(TokStart, 1));
374 case ']': return AsmToken(AsmToken::RBrac, StringRef(TokStart, 1));
375 case '{': return AsmToken(AsmToken::LCurly, StringRef(TokStart, 1));
376 case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1));
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000377 case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
378 case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
Daniel Dunbarb0ceb762010-05-06 14:46:38 +0000379 case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
Matt Flemingec9d6fa2010-05-21 11:36:59 +0000380 case '@': return AsmToken(AsmToken::At, StringRef(TokStart, 1));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000381 case '=':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000382 if (*CurPtr == '=')
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000383 return ++CurPtr, AsmToken(AsmToken::EqualEqual, StringRef(TokStart, 2));
384 return AsmToken(AsmToken::Equal, StringRef(TokStart, 1));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000385 case '|':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000386 if (*CurPtr == '|')
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000387 return ++CurPtr, AsmToken(AsmToken::PipePipe, StringRef(TokStart, 2));
388 return AsmToken(AsmToken::Pipe, StringRef(TokStart, 1));
389 case '^': return AsmToken(AsmToken::Caret, StringRef(TokStart, 1));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000390 case '&':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000391 if (*CurPtr == '&')
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000392 return ++CurPtr, AsmToken(AsmToken::AmpAmp, StringRef(TokStart, 2));
393 return AsmToken(AsmToken::Amp, StringRef(TokStart, 1));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000394 case '!':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000395 if (*CurPtr == '=')
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000396 return ++CurPtr, AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2));
397 return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
Kevin Enderby7d912182009-09-03 17:15:07 +0000398 case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
Chris Lattnerd0765612009-06-21 19:21:25 +0000399 case '/': return LexSlash();
Kevin Enderbyf92f9902009-09-04 21:45:34 +0000400 case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
Roman Divacky71d29162010-12-18 08:56:37 +0000401 case '\'': return LexSingleQuote();
Chris Lattner419a9742009-06-21 19:56:35 +0000402 case '"': return LexQuote();
Chris Lattnerd0765612009-06-21 19:21:25 +0000403 case '0': case '1': case '2': case '3': case '4':
404 case '5': case '6': case '7': case '8': case '9':
405 return LexDigit();
Chris Lattnerf97d8bb2009-06-23 05:57:07 +0000406 case '<':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000407 switch (*CurPtr) {
Jim Grosbach01af6c42011-02-11 19:05:56 +0000408 case '<': return ++CurPtr, AsmToken(AsmToken::LessLess,
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000409 StringRef(TokStart, 2));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000410 case '=': return ++CurPtr, AsmToken(AsmToken::LessEqual,
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000411 StringRef(TokStart, 2));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000412 case '>': return ++CurPtr, AsmToken(AsmToken::LessGreater,
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000413 StringRef(TokStart, 2));
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000414 default: return AsmToken(AsmToken::Less, StringRef(TokStart, 1));
Chris Lattnerf97d8bb2009-06-23 05:57:07 +0000415 }
Chris Lattnerf97d8bb2009-06-23 05:57:07 +0000416 case '>':
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +0000417 switch (*CurPtr) {
Jim Grosbach01af6c42011-02-11 19:05:56 +0000418 case '>': return ++CurPtr, AsmToken(AsmToken::GreaterGreater,
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000419 StringRef(TokStart, 2));
Jim Grosbach01af6c42011-02-11 19:05:56 +0000420 case '=': return ++CurPtr, AsmToken(AsmToken::GreaterEqual,
Daniel Dunbar8368f4e2009-07-28 03:00:54 +0000421 StringRef(TokStart, 2));
Daniel Dunbarf2dcd772009-07-28 16:08:33 +0000422 default: return AsmToken(AsmToken::Greater, StringRef(TokStart, 1));
Chris Lattnerf97d8bb2009-06-23 05:57:07 +0000423 }
Jim Grosbach01af6c42011-02-11 19:05:56 +0000424
Chris Lattnerd0765612009-06-21 19:21:25 +0000425 // TODO: Quoted identifiers (objc methods etc)
426 // local labels: [0-9][:]
427 // Forward/backward labels: [0-9][fb]
428 // Integers, fp constants, character constants.
Chris Lattnerc8dfbcb2009-06-21 07:19:10 +0000429 }
Duncan Sands376c6f12009-06-22 06:59:32 +0000430}