blob: 04bbf3815205a7c3a9993d96559acc7d31a7cf68 [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"
Chris Lattner099e1982009-06-21 03:36:54 +000015#include "llvm/Support/SourceMgr.h"
Chris Lattnera8058742007-11-18 02:57:27 +000016#include "llvm/Support/Streams.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.
40tgtok::TokKind TGLexer::ReturnError(const char *Loc, const std::string &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
Chris Lattner1c8ae592009-03-13 16:01:53 +000046void TGLexer::PrintError(const char *Loc, const std::string &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
Chris Lattner1e3a8a42009-06-21 03:39:35 +000050void TGLexer::PrintError(SMLoc Loc, const std::string &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:
99 // 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 Lattnera8058742007-11-18 02:57:27 +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
221 // Match the rest of the identifier regex: [0-9a-zA-Z_]*
David Greene065f2592009-05-05 16:28:25 +0000222 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_'
223 || *CurPtr == '#') {
224 // If this contains a '#', make sure it's value
225 if (*CurPtr == '#') {
226 if (strncmp(CurPtr, "#NAME#", 6) != 0) {
227 return tgtok::Error;
228 }
229 CurPtr += 6;
230 }
231 else {
232 ++CurPtr;
233 }
234 }
235
Chris Lattnera8058742007-11-18 02:57:27 +0000236
237 // Check to see if this identifier is a keyword.
238 unsigned Len = CurPtr-IdentStart;
239
Chris Lattnerf4601652007-11-22 20:49:04 +0000240 if (Len == 3 && !memcmp(IdentStart, "int", 3)) return tgtok::Int;
241 if (Len == 3 && !memcmp(IdentStart, "bit", 3)) return tgtok::Bit;
242 if (Len == 4 && !memcmp(IdentStart, "bits", 4)) return tgtok::Bits;
243 if (Len == 6 && !memcmp(IdentStart, "string", 6)) return tgtok::String;
244 if (Len == 4 && !memcmp(IdentStart, "list", 4)) return tgtok::List;
245 if (Len == 4 && !memcmp(IdentStart, "code", 4)) return tgtok::Code;
246 if (Len == 3 && !memcmp(IdentStart, "dag", 3)) return tgtok::Dag;
Chris Lattnera8058742007-11-18 02:57:27 +0000247
Chris Lattnerf4601652007-11-22 20:49:04 +0000248 if (Len == 5 && !memcmp(IdentStart, "class", 5)) return tgtok::Class;
249 if (Len == 3 && !memcmp(IdentStart, "def", 3)) return tgtok::Def;
250 if (Len == 4 && !memcmp(IdentStart, "defm", 4)) return tgtok::Defm;
251 if (Len == 10 && !memcmp(IdentStart, "multiclass", 10))
252 return tgtok::MultiClass;
253 if (Len == 5 && !memcmp(IdentStart, "field", 5)) return tgtok::Field;
254 if (Len == 3 && !memcmp(IdentStart, "let", 3)) return tgtok::Let;
255 if (Len == 2 && !memcmp(IdentStart, "in", 2)) return tgtok::In;
Chris Lattnera8058742007-11-18 02:57:27 +0000256
257 if (Len == 7 && !memcmp(IdentStart, "include", 7)) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000258 if (LexInclude()) return tgtok::Error;
259 return Lex();
Chris Lattnera8058742007-11-18 02:57:27 +0000260 }
261
Chris Lattnerf4601652007-11-22 20:49:04 +0000262 CurStrVal.assign(IdentStart, CurPtr);
263 return tgtok::Id;
Chris Lattnera8058742007-11-18 02:57:27 +0000264}
265
266/// LexInclude - We just read the "include" token. Get the string token that
267/// comes next and enter the include.
268bool TGLexer::LexInclude() {
269 // The token after the include must be a string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000270 tgtok::TokKind Tok = LexToken();
271 if (Tok == tgtok::Error) return true;
272 if (Tok != tgtok::StrVal) {
273 PrintError(getLoc(), "Expected filename after include");
Chris Lattnera8058742007-11-18 02:57:27 +0000274 return true;
275 }
276
277 // Get the string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000278 std::string Filename = CurStrVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000279
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000280
281 CurBuffer = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr));
Chris Lattnerd926e042009-06-21 05:33:06 +0000282 if (CurBuffer == -1) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000283 PrintError(getLoc(), "Could not find include file '" + Filename + "'");
Chris Lattnera8058742007-11-18 02:57:27 +0000284 return true;
285 }
286
287 // Save the line number and lex buffer of the includer.
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000288 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattnera8058742007-11-18 02:57:27 +0000289 CurPtr = CurBuf->getBufferStart();
290 return false;
291}
292
293void TGLexer::SkipBCPLComment() {
294 ++CurPtr; // skip the second slash.
295 while (1) {
296 switch (*CurPtr) {
297 case '\n':
298 case '\r':
299 return; // Newline is end of comment.
300 case 0:
301 // If this is the end of the buffer, end the comment.
302 if (CurPtr == CurBuf->getBufferEnd())
303 return;
304 break;
305 }
306 // Otherwise, skip the character.
307 ++CurPtr;
308 }
309}
310
311/// SkipCComment - This skips C-style /**/ comments. The only difference from C
312/// is that we allow nesting.
313bool TGLexer::SkipCComment() {
314 ++CurPtr; // skip the star.
315 unsigned CommentDepth = 1;
316
317 while (1) {
318 int CurChar = getNextChar();
319 switch (CurChar) {
320 case EOF:
Chris Lattnerf4601652007-11-22 20:49:04 +0000321 PrintError(TokStart, "Unterminated comment!");
Chris Lattnera8058742007-11-18 02:57:27 +0000322 return true;
323 case '*':
324 // End of the comment?
325 if (CurPtr[0] != '/') break;
326
327 ++CurPtr; // End the */.
328 if (--CommentDepth == 0)
329 return false;
330 break;
331 case '/':
332 // Start of a nested comment?
333 if (CurPtr[0] != '*') break;
334 ++CurPtr;
335 ++CommentDepth;
336 break;
337 }
338 }
339}
340
341/// LexNumber - Lex:
342/// [-+]?[0-9]+
343/// 0x[0-9a-fA-F]+
344/// 0b[01]+
Chris Lattnerf4601652007-11-22 20:49:04 +0000345tgtok::TokKind TGLexer::LexNumber() {
Chris Lattnera8058742007-11-18 02:57:27 +0000346 if (CurPtr[-1] == '0') {
347 if (CurPtr[0] == 'x') {
348 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000349 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000350 while (isxdigit(CurPtr[0]))
351 ++CurPtr;
352
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000353 // Requires at least one hex digit.
354 if (CurPtr == NumStart)
Chris Lattner4226bb02009-06-21 19:22:49 +0000355 return ReturnError(TokStart, "Invalid hexadecimal number");
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000356
Dan Gohman63f97202008-10-17 01:33:43 +0000357 errno = 0;
Chris Lattnerf4601652007-11-22 20:49:04 +0000358 CurIntVal = strtoll(NumStart, 0, 16);
Dan Gohman63f97202008-10-17 01:33:43 +0000359 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000360 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000361 if (errno == ERANGE) {
362 errno = 0;
363 CurIntVal = (int64_t)strtoull(NumStart, 0, 16);
364 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000365 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000366 if (errno == ERANGE)
Chris Lattner4226bb02009-06-21 19:22:49 +0000367 return ReturnError(TokStart, "Hexadecimal number out of range");
Dan Gohman63f97202008-10-17 01:33:43 +0000368 }
Chris Lattnerf4601652007-11-22 20:49:04 +0000369 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000370 } else if (CurPtr[0] == 'b') {
371 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000372 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000373 while (CurPtr[0] == '0' || CurPtr[0] == '1')
374 ++CurPtr;
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000375
376 // Requires at least one binary digit.
377 if (CurPtr == NumStart)
378 return ReturnError(CurPtr-2, "Invalid binary number");
Chris Lattnerf4601652007-11-22 20:49:04 +0000379 CurIntVal = strtoll(NumStart, 0, 2);
380 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000381 }
382 }
383
384 // Check for a sign without a digit.
Chris Lattnerf4601652007-11-22 20:49:04 +0000385 if (!isdigit(CurPtr[0])) {
386 if (CurPtr[-1] == '-')
387 return tgtok::minus;
388 else if (CurPtr[-1] == '+')
389 return tgtok::plus;
Chris Lattnera8058742007-11-18 02:57:27 +0000390 }
391
392 while (isdigit(CurPtr[0]))
393 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000394 CurIntVal = strtoll(TokStart, 0, 10);
395 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000396}
397
398/// LexBracket - We just read '['. If this is a code block, return it,
399/// otherwise return the bracket. Match: '[' and '[{ ( [^}]+ | }[^]] )* }]'
Chris Lattnerf4601652007-11-22 20:49:04 +0000400tgtok::TokKind TGLexer::LexBracket() {
Chris Lattnera8058742007-11-18 02:57:27 +0000401 if (CurPtr[0] != '{')
Chris Lattnerf4601652007-11-22 20:49:04 +0000402 return tgtok::l_square;
Chris Lattnera8058742007-11-18 02:57:27 +0000403 ++CurPtr;
404 const char *CodeStart = CurPtr;
405 while (1) {
406 int Char = getNextChar();
407 if (Char == EOF) break;
408
409 if (Char != '}') continue;
410
411 Char = getNextChar();
412 if (Char == EOF) break;
413 if (Char == ']') {
Chris Lattnerf4601652007-11-22 20:49:04 +0000414 CurStrVal.assign(CodeStart, CurPtr-2);
415 return tgtok::CodeFragment;
Chris Lattnera8058742007-11-18 02:57:27 +0000416 }
417 }
418
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000419 return ReturnError(CodeStart-2, "Unterminated Code Block");
Chris Lattnera8058742007-11-18 02:57:27 +0000420}
421
422/// LexExclaim - Lex '!' and '![a-zA-Z]+'.
Chris Lattnerf4601652007-11-22 20:49:04 +0000423tgtok::TokKind TGLexer::LexExclaim() {
Chris Lattnera8058742007-11-18 02:57:27 +0000424 if (!isalpha(*CurPtr))
Chris Lattnerf4601652007-11-22 20:49:04 +0000425 return ReturnError(CurPtr-1, "Invalid \"!operator\"");
Chris Lattnera8058742007-11-18 02:57:27 +0000426
427 const char *Start = CurPtr++;
428 while (isalpha(*CurPtr))
429 ++CurPtr;
430
431 // Check to see which operator this is.
432 unsigned Len = CurPtr-Start;
433
David Greenec7cafcd2009-04-22 20:18:10 +0000434 if (Len == 3 && !memcmp(Start, "con", 3)) return tgtok::XConcat;
435 if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA;
436 if (Len == 3 && !memcmp(Start, "srl", 3)) return tgtok::XSRL;
437 if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL;
438 if (Len == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
439 if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat;
David Greene4afc5092009-05-14 21:54:42 +0000440 if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
David Greenebeb31a52009-05-14 22:23:47 +0000441 if (Len == 7 && !memcmp(Start, "foreach", 7)) return tgtok::XForEach;
David Greenee6c27de2009-05-14 21:22:49 +0000442 if (Len == 4 && !memcmp(Start, "cast", 4)) return tgtok::XCast;
David Greene5f9f9ba2009-05-14 22:38:31 +0000443 if (Len == 3 && !memcmp(Start, "car", 3)) return tgtok::XCar;
444 if (Len == 3 && !memcmp(Start, "cdr", 3)) return tgtok::XCdr;
445 if (Len == 4 && !memcmp(Start, "null", 4)) return tgtok::XNull;
David Greene9bea7c82009-05-14 23:26:46 +0000446 if (Len == 2 && !memcmp(Start, "if", 2)) return tgtok::XIf;
David Greened418c1b2009-05-14 20:54:48 +0000447
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000448 return ReturnError(Start-1, "Unknown operator");
Chris Lattnera8058742007-11-18 02:57:27 +0000449}
450