Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 14 | #include "AsmLexer.h" |
| 15 | #include "llvm/Support/SourceMgr.h" |
| 16 | #include "llvm/Support/MemoryBuffer.h" |
Chris Lattner | bcd0b8d | 2009-06-23 00:24:36 +0000 | [diff] [blame] | 17 | #include "llvm/Config/config.h" // for strtoull. |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 18 | #include <cerrno> |
Duncan Sands | 66b9f29 | 2009-06-22 06:59:32 +0000 | [diff] [blame] | 19 | #include <cstdio> |
Chris Lattner | 4506bd2 | 2009-06-21 19:43:50 +0000 | [diff] [blame] | 20 | #include <cstdlib> |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 23 | AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) { |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 24 | CurBuffer = 0; |
| 25 | CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); |
| 26 | CurPtr = CurBuf->getBufferStart(); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 27 | CurTok = AsmToken(asmtok::Error, StringRef(CurPtr, 0)); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 28 | TokStart = 0; |
Chris Lattner | faf32c1 | 2009-06-24 00:33:19 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | AsmLexer::~AsmLexer() { |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 34 | SMLoc AsmLexer::getLoc() const { |
| 35 | return SMLoc::getFromPointer(TokStart); |
| 36 | } |
| 37 | |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 38 | void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg, |
| 39 | const char *Type) const { |
| 40 | SrcMgr.PrintMessage(Loc, Msg, Type); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 43 | /// ReturnError - Set the error to the specified string at the specified |
| 44 | /// location. This is defined to always return asmtok::Error. |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 45 | AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 46 | SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error"); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 47 | return AsmToken(asmtok::Error, StringRef(Loc, 0)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 50 | /// EnterIncludeFile - Enter the specified file. This prints an error and |
| 51 | /// returns true on failure. |
| 52 | bool AsmLexer::EnterIncludeFile(const std::string &Filename) { |
| 53 | int NewBuf = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr)); |
| 54 | if (NewBuf == -1) |
| 55 | return true; |
| 56 | |
| 57 | // Save the line number and lex buffer of the includer. |
| 58 | CurBuffer = NewBuf; |
| 59 | CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); |
| 60 | CurPtr = CurBuf->getBufferStart(); |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 65 | int AsmLexer::getNextChar() { |
| 66 | char CurChar = *CurPtr++; |
| 67 | switch (CurChar) { |
| 68 | default: |
| 69 | return (unsigned char)CurChar; |
| 70 | case 0: { |
| 71 | // A nul character in the stream is either the end of the current buffer or |
| 72 | // a random nul in the file. Disambiguate that here. |
| 73 | if (CurPtr-1 != CurBuf->getBufferEnd()) |
| 74 | return 0; // Just whitespace. |
| 75 | |
| 76 | // If this is the end of an included file, pop the parent file off the |
| 77 | // include stack. |
| 78 | SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); |
| 79 | if (ParentIncludeLoc != SMLoc()) { |
| 80 | CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc); |
| 81 | CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); |
| 82 | CurPtr = ParentIncludeLoc.getPointer(); |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 83 | |
| 84 | // Reset the token start pointer to the start of the new file. |
| 85 | TokStart = CurPtr; |
| 86 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 87 | return getNextChar(); |
| 88 | } |
| 89 | |
| 90 | // Otherwise, return end of file. |
| 91 | --CurPtr; // Another call to lex will return EOF again. |
| 92 | return EOF; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 97 | /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 98 | AsmToken AsmLexer::LexIdentifier() { |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 99 | while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || |
| 100 | *CurPtr == '.' || *CurPtr == '@') |
| 101 | ++CurPtr; |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 102 | return AsmToken(asmtok::Identifier, StringRef(TokStart, CurPtr - TokStart)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /// LexPercent: Register: %[a-zA-Z0-9]+ |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 106 | AsmToken AsmLexer::LexPercent() { |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 107 | if (!isalnum(*CurPtr)) |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 108 | return AsmToken(asmtok::Percent, StringRef(CurPtr, 1)); // Single %. |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 110 | while (isalnum(*CurPtr)) |
| 111 | ++CurPtr; |
Chris Lattner | faf32c1 | 2009-06-24 00:33:19 +0000 | [diff] [blame] | 112 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 113 | return AsmToken(asmtok::Register, StringRef(TokStart, CurPtr - TokStart)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /// LexSlash: Slash: / |
| 117 | /// C-Style Comment: /* ... */ |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 118 | AsmToken AsmLexer::LexSlash() { |
Daniel Dunbar | 383a4a8 | 2009-06-29 21:58:22 +0000 | [diff] [blame] | 119 | switch (*CurPtr) { |
| 120 | case '*': break; // C style comment. |
| 121 | case '/': return ++CurPtr, LexLineComment(); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 122 | default: return AsmToken(asmtok::Slash, StringRef(CurPtr, 1)); |
Daniel Dunbar | 383a4a8 | 2009-06-29 21:58:22 +0000 | [diff] [blame] | 123 | } |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 124 | |
| 125 | // C Style comment. |
| 126 | ++CurPtr; // skip the star. |
| 127 | while (1) { |
| 128 | int CurChar = getNextChar(); |
| 129 | switch (CurChar) { |
| 130 | case EOF: |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 131 | return ReturnError(TokStart, "unterminated comment"); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 132 | case '*': |
| 133 | // End of the comment? |
| 134 | if (CurPtr[0] != '/') break; |
| 135 | |
| 136 | ++CurPtr; // End the */. |
| 137 | return LexToken(); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
Daniel Dunbar | 383a4a8 | 2009-06-29 21:58:22 +0000 | [diff] [blame] | 142 | /// LexLineComment: Comment: #[^\n]* |
| 143 | /// : //[^\n]* |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 144 | AsmToken AsmLexer::LexLineComment() { |
| 145 | // FIXME: This is broken if we happen to a comment at the end of a file, which |
| 146 | // was .included, and which doesn't end with a newline. |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 147 | int CurChar = getNextChar(); |
| 148 | while (CurChar != '\n' && CurChar != '\n' && CurChar != EOF) |
| 149 | CurChar = getNextChar(); |
| 150 | |
| 151 | if (CurChar == EOF) |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 152 | return AsmToken(asmtok::Eof, StringRef(CurPtr, 0)); |
| 153 | return AsmToken(asmtok::EndOfStatement, StringRef(CurPtr, 0)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | |
| 157 | /// LexDigit: First character is [0-9]. |
| 158 | /// Local Label: [0-9][:] |
| 159 | /// Forward/Backward Label: [0-9][fb] |
| 160 | /// Binary integer: 0b[01]+ |
| 161 | /// Octal integer: 0[0-7]+ |
| 162 | /// Hex integer: 0x[0-9a-fA-F]+ |
| 163 | /// Decimal integer: [1-9][0-9]* |
| 164 | /// TODO: FP literal. |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 165 | AsmToken AsmLexer::LexDigit() { |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 166 | if (*CurPtr == ':') |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 167 | return ReturnError(TokStart, "FIXME: local label not implemented"); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 168 | if (*CurPtr == 'f' || *CurPtr == 'b') |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 169 | return ReturnError(TokStart, "FIXME: directional label not implemented"); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 170 | |
| 171 | // Decimal integer: [1-9][0-9]* |
| 172 | if (CurPtr[-1] != '0') { |
| 173 | while (isdigit(*CurPtr)) |
| 174 | ++CurPtr; |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 175 | return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart), |
| 176 | strtoll(TokStart, 0, 10)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | if (*CurPtr == 'b') { |
| 180 | ++CurPtr; |
| 181 | const char *NumStart = CurPtr; |
| 182 | while (CurPtr[0] == '0' || CurPtr[0] == '1') |
| 183 | ++CurPtr; |
| 184 | |
| 185 | // Requires at least one binary digit. |
| 186 | if (CurPtr == NumStart) |
| 187 | return ReturnError(CurPtr-2, "Invalid binary number"); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 188 | return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart), |
| 189 | strtoll(NumStart, 0, 2)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if (*CurPtr == 'x') { |
| 193 | ++CurPtr; |
| 194 | const char *NumStart = CurPtr; |
| 195 | while (isxdigit(CurPtr[0])) |
| 196 | ++CurPtr; |
| 197 | |
| 198 | // Requires at least one hex digit. |
| 199 | if (CurPtr == NumStart) |
| 200 | return ReturnError(CurPtr-2, "Invalid hexadecimal number"); |
| 201 | |
| 202 | errno = 0; |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 203 | if (errno == EINVAL) |
| 204 | return ReturnError(CurPtr-2, "Invalid hexadecimal number"); |
| 205 | if (errno == ERANGE) { |
| 206 | errno = 0; |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 207 | if (errno == EINVAL) |
| 208 | return ReturnError(CurPtr-2, "Invalid hexadecimal number"); |
| 209 | if (errno == ERANGE) |
| 210 | return ReturnError(CurPtr-2, "Hexadecimal number out of range"); |
| 211 | } |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 212 | return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart), |
| 213 | (int64_t) strtoull(NumStart, 0, 16)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | // Must be an octal number, it starts with 0. |
| 217 | while (*CurPtr >= '0' && *CurPtr <= '7') |
| 218 | ++CurPtr; |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 219 | return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart), |
| 220 | strtoll(TokStart, 0, 8)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | 10a907d | 2009-06-21 19:56:35 +0000 | [diff] [blame] | 223 | /// LexQuote: String: "..." |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 224 | AsmToken AsmLexer::LexQuote() { |
Chris Lattner | 10a907d | 2009-06-21 19:56:35 +0000 | [diff] [blame] | 225 | int CurChar = getNextChar(); |
| 226 | // TODO: does gas allow multiline string constants? |
| 227 | while (CurChar != '"') { |
| 228 | if (CurChar == '\\') { |
| 229 | // Allow \", etc. |
| 230 | CurChar = getNextChar(); |
| 231 | } |
| 232 | |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 233 | if (CurChar == EOF) |
| 234 | return ReturnError(TokStart, "unterminated string constant"); |
Chris Lattner | 10a907d | 2009-06-21 19:56:35 +0000 | [diff] [blame] | 235 | |
| 236 | CurChar = getNextChar(); |
| 237 | } |
| 238 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 239 | return AsmToken(asmtok::String, StringRef(TokStart, CurPtr - TokStart)); |
Chris Lattner | 10a907d | 2009-06-21 19:56:35 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 242 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 243 | AsmToken AsmLexer::LexToken() { |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 244 | TokStart = CurPtr; |
| 245 | // This always consumes at least one character. |
| 246 | int CurChar = getNextChar(); |
| 247 | |
| 248 | switch (CurChar) { |
| 249 | default: |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 250 | // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* |
| 251 | if (isalpha(CurChar) || CurChar == '_' || CurChar == '.') |
| 252 | return LexIdentifier(); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 253 | |
| 254 | // Unknown character, emit an error. |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 255 | return ReturnError(TokStart, "invalid character in input"); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 256 | case EOF: return AsmToken(asmtok::Eof, StringRef(TokStart, 0)); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 257 | case 0: |
| 258 | case ' ': |
| 259 | case '\t': |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 260 | // Ignore whitespace. |
| 261 | return LexToken(); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 262 | case '\n': // FALL THROUGH. |
| 263 | case '\r': // FALL THROUGH. |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 264 | case ';': return AsmToken(asmtok::EndOfStatement, StringRef(TokStart, 1)); |
| 265 | case ':': return AsmToken(asmtok::Colon, StringRef(TokStart, 1)); |
| 266 | case '+': return AsmToken(asmtok::Plus, StringRef(TokStart, 1)); |
| 267 | case '-': return AsmToken(asmtok::Minus, StringRef(TokStart, 1)); |
| 268 | case '~': return AsmToken(asmtok::Tilde, StringRef(TokStart, 1)); |
| 269 | case '(': return AsmToken(asmtok::LParen, StringRef(TokStart, 1)); |
| 270 | case ')': return AsmToken(asmtok::RParen, StringRef(TokStart, 1)); |
| 271 | case '*': return AsmToken(asmtok::Star, StringRef(TokStart, 1)); |
| 272 | case ',': return AsmToken(asmtok::Comma, StringRef(TokStart, 1)); |
| 273 | case '$': return AsmToken(asmtok::Dollar, StringRef(TokStart, 1)); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 274 | case '=': |
| 275 | if (*CurPtr == '=') |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 276 | return ++CurPtr, AsmToken(asmtok::EqualEqual, StringRef(TokStart, 2)); |
| 277 | return AsmToken(asmtok::Equal, StringRef(TokStart, 1)); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 278 | case '|': |
| 279 | if (*CurPtr == '|') |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 280 | return ++CurPtr, AsmToken(asmtok::PipePipe, StringRef(TokStart, 2)); |
| 281 | return AsmToken(asmtok::Pipe, StringRef(TokStart, 1)); |
| 282 | case '^': return AsmToken(asmtok::Caret, StringRef(TokStart, 1)); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 283 | case '&': |
| 284 | if (*CurPtr == '&') |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 285 | return ++CurPtr, AsmToken(asmtok::AmpAmp, StringRef(TokStart, 2)); |
| 286 | return AsmToken(asmtok::Amp, StringRef(TokStart, 1)); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 287 | case '!': |
| 288 | if (*CurPtr == '=') |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 289 | return ++CurPtr, AsmToken(asmtok::ExclaimEqual, StringRef(TokStart, 2)); |
| 290 | return AsmToken(asmtok::Exclaim, StringRef(TokStart, 1)); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 291 | case '%': return LexPercent(); |
| 292 | case '/': return LexSlash(); |
Daniel Dunbar | 383a4a8 | 2009-06-29 21:58:22 +0000 | [diff] [blame] | 293 | case '#': return LexLineComment(); |
Chris Lattner | 10a907d | 2009-06-21 19:56:35 +0000 | [diff] [blame] | 294 | case '"': return LexQuote(); |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 295 | case '0': case '1': case '2': case '3': case '4': |
| 296 | case '5': case '6': case '7': case '8': case '9': |
| 297 | return LexDigit(); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 298 | case '<': |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 299 | switch (*CurPtr) { |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 300 | case '<': return ++CurPtr, AsmToken(asmtok::LessLess, |
| 301 | StringRef(TokStart, 2)); |
| 302 | case '=': return ++CurPtr, AsmToken(asmtok::LessEqual, |
| 303 | StringRef(TokStart, 2)); |
| 304 | case '>': return ++CurPtr, AsmToken(asmtok::LessGreater, |
| 305 | StringRef(TokStart, 2)); |
| 306 | default: return AsmToken(asmtok::Less, StringRef(TokStart, 1)); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 307 | } |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 308 | case '>': |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 309 | switch (*CurPtr) { |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame^] | 310 | case '>': return ++CurPtr, AsmToken(asmtok::GreaterGreater, |
| 311 | StringRef(TokStart, 2)); |
| 312 | case '=': return ++CurPtr, AsmToken(asmtok::GreaterEqual, |
| 313 | StringRef(TokStart, 2)); |
| 314 | default: return AsmToken(asmtok::Greater, StringRef(TokStart, 1)); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 315 | } |
Chris Lattner | 4651bca | 2009-06-21 19:21:25 +0000 | [diff] [blame] | 316 | |
| 317 | // TODO: Quoted identifiers (objc methods etc) |
| 318 | // local labels: [0-9][:] |
| 319 | // Forward/backward labels: [0-9][fb] |
| 320 | // Integers, fp constants, character constants. |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 321 | } |
Duncan Sands | 66b9f29 | 2009-06-22 06:59:32 +0000 | [diff] [blame] | 322 | } |