blob: 12fa39f00922ef9407ea525b7dc4c5c33173cd86 [file] [log] [blame]
Chris Lattnera8058742007-11-18 02:57:27 +00001//===- TGLexer.cpp - Lexer for TableGen -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnera8058742007-11-18 02:57:27 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Implement the Lexer for TableGen.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner6aaca042007-11-18 05:25:45 +000014#include "TGLexer.h"
Benjamin Kramerd1e17032010-09-27 17:42:11 +000015#include "llvm/ADT/Twine.h"
Chris Lattner099e1982009-06-21 03:36:54 +000016#include "llvm/Support/SourceMgr.h"
Chris Lattnera8058742007-11-18 02:57:27 +000017#include "llvm/Support/MemoryBuffer.h"
Chuck Rose III8b0ec642007-11-21 19:36:25 +000018#include "llvm/Config/config.h"
Chris Lattnera8058742007-11-18 02:57:27 +000019#include <cctype>
Duncan Sands4520dd22008-10-08 07:23:46 +000020#include <cstdio>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000021#include <cstdlib>
22#include <cstring>
Dan Gohman63f97202008-10-17 01:33:43 +000023#include <cerrno>
Chris Lattnera8058742007-11-18 02:57:27 +000024using namespace llvm;
25
Chris Lattner8070ea32009-06-21 03:41:50 +000026TGLexer::TGLexer(SourceMgr &SM) : SrcMgr(SM) {
Chris Lattneraa739d22009-03-13 07:05:43 +000027 CurBuffer = 0;
28 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattnera8058742007-11-18 02:57:27 +000029 CurPtr = CurBuf->getBufferStart();
Chris Lattner56a9fcf2007-11-19 07:43:52 +000030 TokStart = 0;
Chris Lattnera8058742007-11-18 02:57:27 +000031}
32
Chris Lattner1e3a8a42009-06-21 03:39:35 +000033SMLoc TGLexer::getLoc() const {
34 return SMLoc::getFromPointer(TokStart);
Chris Lattner1c8ae592009-03-13 16:01:53 +000035}
36
Chris Lattnera8058742007-11-18 02:57:27 +000037
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000038/// ReturnError - Set the error to the specified string at the specified
Chris Lattnerf4601652007-11-22 20:49:04 +000039/// location. This is defined to always return tgtok::Error.
Benjamin Kramerd1e17032010-09-27 17:42:11 +000040tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000041 PrintError(Loc, Msg);
Chris Lattnerf4601652007-11-22 20:49:04 +000042 return tgtok::Error;
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000043}
Chris Lattnera8058742007-11-18 02:57:27 +000044
Chris Lattnera8058742007-11-18 02:57:27 +000045
Benjamin Kramerd1e17032010-09-27 17:42:11 +000046void TGLexer::PrintError(const char *Loc, const Twine &Msg) const {
Daniel Dunbar3fb76832009-06-30 00:49:23 +000047 SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
Chris Lattner1c8ae592009-03-13 16:01:53 +000048}
49
Benjamin Kramerd1e17032010-09-27 17:42:11 +000050void TGLexer::PrintError(SMLoc Loc, const Twine &Msg) const {
Daniel Dunbar3fb76832009-06-30 00:49:23 +000051 SrcMgr.PrintMessage(Loc, Msg, "error");
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000052}
53
Chris Lattner1c8ae592009-03-13 16:01:53 +000054
Chris Lattnera8058742007-11-18 02:57:27 +000055int TGLexer::getNextChar() {
56 char CurChar = *CurPtr++;
57 switch (CurChar) {
58 default:
Chris Lattnerc1819182007-11-18 05:48:46 +000059 return (unsigned char)CurChar;
Chris Lattneraa739d22009-03-13 07:05:43 +000060 case 0: {
Chris Lattnera8058742007-11-18 02:57:27 +000061 // A nul character in the stream is either the end of the current buffer or
62 // a random nul in the file. Disambiguate that here.
63 if (CurPtr-1 != CurBuf->getBufferEnd())
64 return 0; // Just whitespace.
65
66 // If this is the end of an included file, pop the parent file off the
67 // include stack.
Chris Lattner1e3a8a42009-06-21 03:39:35 +000068 SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
69 if (ParentIncludeLoc != SMLoc()) {
Chris Lattneraa739d22009-03-13 07:05:43 +000070 CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
71 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattner1c8ae592009-03-13 16:01:53 +000072 CurPtr = ParentIncludeLoc.getPointer();
Chris Lattnera8058742007-11-18 02:57:27 +000073 return getNextChar();
74 }
75
76 // Otherwise, return end of file.
77 --CurPtr; // Another call to lex will return EOF again.
78 return EOF;
Chris Lattneraa739d22009-03-13 07:05:43 +000079 }
Chris Lattnera8058742007-11-18 02:57:27 +000080 case '\n':
81 case '\r':
82 // Handle the newline character by ignoring it and incrementing the line
83 // count. However, be careful about 'dos style' files with \n\r in them.
84 // Only treat a \n\r or \r\n as a single line.
85 if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
86 *CurPtr != CurChar)
Chris Lattnerc1819182007-11-18 05:48:46 +000087 ++CurPtr; // Eat the two char newline sequence.
Chris Lattnera8058742007-11-18 02:57:27 +000088 return '\n';
89 }
90}
91
Chris Lattnerf4601652007-11-22 20:49:04 +000092tgtok::TokKind TGLexer::LexToken() {
Chris Lattner56a9fcf2007-11-19 07:43:52 +000093 TokStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +000094 // This always consumes at least one character.
95 int CurChar = getNextChar();
96
97 switch (CurChar) {
98 default:
Chris Lattnerc2b08752010-10-05 22:59:29 +000099 // Handle letters: [a-zA-Z_#]
David Greene065f2592009-05-05 16:28:25 +0000100 if (isalpha(CurChar) || CurChar == '_' || CurChar == '#')
Chris Lattnera8058742007-11-18 02:57:27 +0000101 return LexIdentifier();
102
Chris Lattnerf4601652007-11-22 20:49:04 +0000103 // Unknown character, emit an error.
104 return ReturnError(TokStart, "Unexpected character");
105 case EOF: return tgtok::Eof;
106 case ':': return tgtok::colon;
107 case ';': return tgtok::semi;
108 case '.': return tgtok::period;
109 case ',': return tgtok::comma;
110 case '<': return tgtok::less;
111 case '>': return tgtok::greater;
112 case ']': return tgtok::r_square;
113 case '{': return tgtok::l_brace;
114 case '}': return tgtok::r_brace;
115 case '(': return tgtok::l_paren;
116 case ')': return tgtok::r_paren;
117 case '=': return tgtok::equal;
118 case '?': return tgtok::question;
119
Chris Lattnera8058742007-11-18 02:57:27 +0000120 case 0:
121 case ' ':
122 case '\t':
123 case '\n':
124 case '\r':
125 // Ignore whitespace.
126 return LexToken();
127 case '/':
128 // If this is the start of a // comment, skip until the end of the line or
129 // the end of the buffer.
130 if (*CurPtr == '/')
131 SkipBCPLComment();
132 else if (*CurPtr == '*') {
133 if (SkipCComment())
Chris Lattnerf4601652007-11-22 20:49:04 +0000134 return tgtok::Error;
135 } else // Otherwise, this is an error.
136 return ReturnError(TokStart, "Unexpected character");
Chris Lattnera8058742007-11-18 02:57:27 +0000137 return LexToken();
138 case '-': case '+':
139 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
140 case '7': case '8': case '9':
141 return LexNumber();
142 case '"': return LexString();
143 case '$': return LexVarName();
144 case '[': return LexBracket();
145 case '!': return LexExclaim();
146 }
147}
148
149/// LexString - Lex "[^"]*"
Chris Lattnerf4601652007-11-22 20:49:04 +0000150tgtok::TokKind TGLexer::LexString() {
Chris Lattnera8058742007-11-18 02:57:27 +0000151 const char *StrStart = CurPtr;
152
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000153 CurStrVal = "";
154
Chris Lattnera8058742007-11-18 02:57:27 +0000155 while (*CurPtr != '"') {
156 // If we hit the end of the buffer, report an error.
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000157 if (*CurPtr == 0 && CurPtr == CurBuf->getBufferEnd())
158 return ReturnError(StrStart, "End of file in string literal");
159
160 if (*CurPtr == '\n' || *CurPtr == '\r')
161 return ReturnError(StrStart, "End of line in string literal");
Chris Lattnera8058742007-11-18 02:57:27 +0000162
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000163 if (*CurPtr != '\\') {
164 CurStrVal += *CurPtr++;
165 continue;
166 }
167
Chris Lattnera8058742007-11-18 02:57:27 +0000168 ++CurPtr;
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000169
170 switch (*CurPtr) {
171 case '\\': case '\'': case '"':
172 // These turn into their literal character.
173 CurStrVal += *CurPtr++;
174 break;
Chris Lattnere023bb62009-03-13 21:23:43 +0000175 case 't':
Chris Lattner7f3b28a2009-03-13 21:33:17 +0000176 CurStrVal += '\t';
Chris Lattnere023bb62009-03-13 21:23:43 +0000177 ++CurPtr;
178 break;
179 case 'n':
Chris Lattner7f3b28a2009-03-13 21:33:17 +0000180 CurStrVal += '\n';
Chris Lattnere023bb62009-03-13 21:23:43 +0000181 ++CurPtr;
182 break;
183
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000184 case '\n':
185 case '\r':
186 return ReturnError(CurPtr, "escaped newlines not supported in tblgen");
187
188 // If we hit the end of the buffer, report an error.
189 case '\0':
190 if (CurPtr == CurBuf->getBufferEnd())
191 return ReturnError(StrStart, "End of file in string literal");
192 // FALL THROUGH
193 default:
194 return ReturnError(CurPtr, "invalid escape in string literal");
195 }
Chris Lattnera8058742007-11-18 02:57:27 +0000196 }
197
Chris Lattnera8058742007-11-18 02:57:27 +0000198 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000199 return tgtok::StrVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000200}
201
Chris Lattnerf4601652007-11-22 20:49:04 +0000202tgtok::TokKind TGLexer::LexVarName() {
Chris Lattnera8058742007-11-18 02:57:27 +0000203 if (!isalpha(CurPtr[0]) && CurPtr[0] != '_')
Chris Lattnerf4601652007-11-22 20:49:04 +0000204 return ReturnError(TokStart, "Invalid variable name");
Chris Lattnera8058742007-11-18 02:57:27 +0000205
206 // Otherwise, we're ok, consume the rest of the characters.
207 const char *VarNameStart = CurPtr++;
208
209 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_')
210 ++CurPtr;
211
Chris Lattnerf4601652007-11-22 20:49:04 +0000212 CurStrVal.assign(VarNameStart, CurPtr);
213 return tgtok::VarName;
Chris Lattnera8058742007-11-18 02:57:27 +0000214}
215
216
Chris Lattnerf4601652007-11-22 20:49:04 +0000217tgtok::TokKind TGLexer::LexIdentifier() {
Chris Lattnerc2b08752010-10-05 22:59:29 +0000218 // The first letter is [a-zA-Z_#].
Chris Lattnerf4601652007-11-22 20:49:04 +0000219 const char *IdentStart = TokStart;
Chris Lattnera8058742007-11-18 02:57:27 +0000220
Chris Lattnerc2b08752010-10-05 22:59:29 +0000221 // Match the rest of the identifier regex: [0-9a-zA-Z_#]*
222 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_' ||
223 *CurPtr == '#')
224 ++CurPtr;
David Greene065f2592009-05-05 16:28:25 +0000225
Chris Lattnera8058742007-11-18 02:57:27 +0000226
227 // Check to see if this identifier is a keyword.
228 unsigned Len = CurPtr-IdentStart;
229
Chris Lattnerf4601652007-11-22 20:49:04 +0000230 if (Len == 3 && !memcmp(IdentStart, "int", 3)) return tgtok::Int;
231 if (Len == 3 && !memcmp(IdentStart, "bit", 3)) return tgtok::Bit;
232 if (Len == 4 && !memcmp(IdentStart, "bits", 4)) return tgtok::Bits;
233 if (Len == 6 && !memcmp(IdentStart, "string", 6)) return tgtok::String;
234 if (Len == 4 && !memcmp(IdentStart, "list", 4)) return tgtok::List;
235 if (Len == 4 && !memcmp(IdentStart, "code", 4)) return tgtok::Code;
236 if (Len == 3 && !memcmp(IdentStart, "dag", 3)) return tgtok::Dag;
Chris Lattnera8058742007-11-18 02:57:27 +0000237
Chris Lattnerf4601652007-11-22 20:49:04 +0000238 if (Len == 5 && !memcmp(IdentStart, "class", 5)) return tgtok::Class;
239 if (Len == 3 && !memcmp(IdentStart, "def", 3)) return tgtok::Def;
240 if (Len == 4 && !memcmp(IdentStart, "defm", 4)) return tgtok::Defm;
241 if (Len == 10 && !memcmp(IdentStart, "multiclass", 10))
242 return tgtok::MultiClass;
243 if (Len == 5 && !memcmp(IdentStart, "field", 5)) return tgtok::Field;
244 if (Len == 3 && !memcmp(IdentStart, "let", 3)) return tgtok::Let;
245 if (Len == 2 && !memcmp(IdentStart, "in", 2)) return tgtok::In;
Chris Lattnera8058742007-11-18 02:57:27 +0000246
247 if (Len == 7 && !memcmp(IdentStart, "include", 7)) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000248 if (LexInclude()) return tgtok::Error;
249 return Lex();
Chris Lattnera8058742007-11-18 02:57:27 +0000250 }
251
Chris Lattnerf4601652007-11-22 20:49:04 +0000252 CurStrVal.assign(IdentStart, CurPtr);
253 return tgtok::Id;
Chris Lattnera8058742007-11-18 02:57:27 +0000254}
255
256/// LexInclude - We just read the "include" token. Get the string token that
257/// comes next and enter the include.
258bool TGLexer::LexInclude() {
259 // The token after the include must be a string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000260 tgtok::TokKind Tok = LexToken();
261 if (Tok == tgtok::Error) return true;
262 if (Tok != tgtok::StrVal) {
263 PrintError(getLoc(), "Expected filename after include");
Chris Lattnera8058742007-11-18 02:57:27 +0000264 return true;
265 }
266
267 // Get the string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000268 std::string Filename = CurStrVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000269
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000270
271 CurBuffer = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr));
Chris Lattnerd926e042009-06-21 05:33:06 +0000272 if (CurBuffer == -1) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000273 PrintError(getLoc(), "Could not find include file '" + Filename + "'");
Chris Lattnera8058742007-11-18 02:57:27 +0000274 return true;
275 }
276
277 // Save the line number and lex buffer of the includer.
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000278 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattnera8058742007-11-18 02:57:27 +0000279 CurPtr = CurBuf->getBufferStart();
280 return false;
281}
282
283void TGLexer::SkipBCPLComment() {
284 ++CurPtr; // skip the second slash.
285 while (1) {
286 switch (*CurPtr) {
287 case '\n':
288 case '\r':
289 return; // Newline is end of comment.
290 case 0:
291 // If this is the end of the buffer, end the comment.
292 if (CurPtr == CurBuf->getBufferEnd())
293 return;
294 break;
295 }
296 // Otherwise, skip the character.
297 ++CurPtr;
298 }
299}
300
301/// SkipCComment - This skips C-style /**/ comments. The only difference from C
302/// is that we allow nesting.
303bool TGLexer::SkipCComment() {
304 ++CurPtr; // skip the star.
305 unsigned CommentDepth = 1;
306
307 while (1) {
308 int CurChar = getNextChar();
309 switch (CurChar) {
310 case EOF:
Chris Lattnerf4601652007-11-22 20:49:04 +0000311 PrintError(TokStart, "Unterminated comment!");
Chris Lattnera8058742007-11-18 02:57:27 +0000312 return true;
313 case '*':
314 // End of the comment?
315 if (CurPtr[0] != '/') break;
316
317 ++CurPtr; // End the */.
318 if (--CommentDepth == 0)
319 return false;
320 break;
321 case '/':
322 // Start of a nested comment?
323 if (CurPtr[0] != '*') break;
324 ++CurPtr;
325 ++CommentDepth;
326 break;
327 }
328 }
329}
330
331/// LexNumber - Lex:
332/// [-+]?[0-9]+
333/// 0x[0-9a-fA-F]+
334/// 0b[01]+
Chris Lattnerf4601652007-11-22 20:49:04 +0000335tgtok::TokKind TGLexer::LexNumber() {
Chris Lattnera8058742007-11-18 02:57:27 +0000336 if (CurPtr[-1] == '0') {
337 if (CurPtr[0] == 'x') {
338 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000339 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000340 while (isxdigit(CurPtr[0]))
341 ++CurPtr;
342
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000343 // Requires at least one hex digit.
344 if (CurPtr == NumStart)
Chris Lattner4226bb02009-06-21 19:22:49 +0000345 return ReturnError(TokStart, "Invalid hexadecimal number");
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000346
Dan Gohman63f97202008-10-17 01:33:43 +0000347 errno = 0;
Chris Lattnerf4601652007-11-22 20:49:04 +0000348 CurIntVal = strtoll(NumStart, 0, 16);
Dan Gohman63f97202008-10-17 01:33:43 +0000349 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000350 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000351 if (errno == ERANGE) {
352 errno = 0;
353 CurIntVal = (int64_t)strtoull(NumStart, 0, 16);
354 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000355 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000356 if (errno == ERANGE)
Chris Lattner4226bb02009-06-21 19:22:49 +0000357 return ReturnError(TokStart, "Hexadecimal number out of range");
Dan Gohman63f97202008-10-17 01:33:43 +0000358 }
Chris Lattnerf4601652007-11-22 20:49:04 +0000359 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000360 } else if (CurPtr[0] == 'b') {
361 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000362 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000363 while (CurPtr[0] == '0' || CurPtr[0] == '1')
364 ++CurPtr;
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000365
366 // Requires at least one binary digit.
367 if (CurPtr == NumStart)
368 return ReturnError(CurPtr-2, "Invalid binary number");
Chris Lattnerf4601652007-11-22 20:49:04 +0000369 CurIntVal = strtoll(NumStart, 0, 2);
370 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000371 }
372 }
373
374 // Check for a sign without a digit.
Chris Lattnerf4601652007-11-22 20:49:04 +0000375 if (!isdigit(CurPtr[0])) {
376 if (CurPtr[-1] == '-')
377 return tgtok::minus;
378 else if (CurPtr[-1] == '+')
379 return tgtok::plus;
Chris Lattnera8058742007-11-18 02:57:27 +0000380 }
381
382 while (isdigit(CurPtr[0]))
383 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000384 CurIntVal = strtoll(TokStart, 0, 10);
385 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000386}
387
388/// LexBracket - We just read '['. If this is a code block, return it,
389/// otherwise return the bracket. Match: '[' and '[{ ( [^}]+ | }[^]] )* }]'
Chris Lattnerf4601652007-11-22 20:49:04 +0000390tgtok::TokKind TGLexer::LexBracket() {
Chris Lattnera8058742007-11-18 02:57:27 +0000391 if (CurPtr[0] != '{')
Chris Lattnerf4601652007-11-22 20:49:04 +0000392 return tgtok::l_square;
Chris Lattnera8058742007-11-18 02:57:27 +0000393 ++CurPtr;
394 const char *CodeStart = CurPtr;
395 while (1) {
396 int Char = getNextChar();
397 if (Char == EOF) break;
398
399 if (Char != '}') continue;
400
401 Char = getNextChar();
402 if (Char == EOF) break;
403 if (Char == ']') {
Chris Lattnerf4601652007-11-22 20:49:04 +0000404 CurStrVal.assign(CodeStart, CurPtr-2);
405 return tgtok::CodeFragment;
Chris Lattnera8058742007-11-18 02:57:27 +0000406 }
407 }
408
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000409 return ReturnError(CodeStart-2, "Unterminated Code Block");
Chris Lattnera8058742007-11-18 02:57:27 +0000410}
411
412/// LexExclaim - Lex '!' and '![a-zA-Z]+'.
Chris Lattnerf4601652007-11-22 20:49:04 +0000413tgtok::TokKind TGLexer::LexExclaim() {
Chris Lattnera8058742007-11-18 02:57:27 +0000414 if (!isalpha(*CurPtr))
Chris Lattnerf4601652007-11-22 20:49:04 +0000415 return ReturnError(CurPtr-1, "Invalid \"!operator\"");
Chris Lattnera8058742007-11-18 02:57:27 +0000416
417 const char *Start = CurPtr++;
418 while (isalpha(*CurPtr))
419 ++CurPtr;
420
421 // Check to see which operator this is.
422 unsigned Len = CurPtr-Start;
423
David Greenec7cafcd2009-04-22 20:18:10 +0000424 if (Len == 3 && !memcmp(Start, "con", 3)) return tgtok::XConcat;
425 if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA;
426 if (Len == 3 && !memcmp(Start, "srl", 3)) return tgtok::XSRL;
427 if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL;
David Greene6786d5e2010-01-05 19:11:42 +0000428 if (Len == 2 && !memcmp(Start, "eq", 2)) return tgtok::XEq;
David Greenec7cafcd2009-04-22 20:18:10 +0000429 if (Len == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
David Greene4afc5092009-05-14 21:54:42 +0000430 if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
David Greenebeb31a52009-05-14 22:23:47 +0000431 if (Len == 7 && !memcmp(Start, "foreach", 7)) return tgtok::XForEach;
David Greenee6c27de2009-05-14 21:22:49 +0000432 if (Len == 4 && !memcmp(Start, "cast", 4)) return tgtok::XCast;
David Greene5f9f9ba2009-05-14 22:38:31 +0000433 if (Len == 3 && !memcmp(Start, "car", 3)) return tgtok::XCar;
434 if (Len == 3 && !memcmp(Start, "cdr", 3)) return tgtok::XCdr;
435 if (Len == 4 && !memcmp(Start, "null", 4)) return tgtok::XNull;
David Greene9bea7c82009-05-14 23:26:46 +0000436 if (Len == 2 && !memcmp(Start, "if", 2)) return tgtok::XIf;
David Greened418c1b2009-05-14 20:54:48 +0000437
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000438 return ReturnError(Start-1, "Unknown operator");
Chris Lattnera8058742007-11-18 02:57:27 +0000439}
440