blob: 717e583291c3b220f1fb0256b2b4c8b950b5bf2f [file] [log] [blame]
Chris Lattnerdb3b2022002-08-14 17:12:33 +00001/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
Misha Brukman8b477072005-05-10 22:02:28 +00002//
John Criswell29265fe2003-10-21 15:17:13 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman8b477072005-05-10 22:02:28 +00007//
John Criswell29265fe2003-10-21 15:17:13 +00008//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +00009//
10// This file implements the flex scanner for LLVM assembly languages files.
11//
Chris Lattnerdb3b2022002-08-14 17:12:33 +000012//===----------------------------------------------------------------------===*/
Chris Lattner2f7c9632001-06-06 20:29:01 +000013
14%option prefix="llvmAsm"
15%option yylineno
16%option nostdinit
17%option never-interactive
18%option batch
19%option noyywrap
20%option nodefault
21%option 8bit
22%option outfile="Lexer.cpp"
23%option ecs
24%option noreject
25%option noyymore
26
27%{
28#include "ParserInternals.h"
Chris Lattner20126132003-04-22 19:07:06 +000029#include "llvm/Module.h"
Chris Lattner2f7c9632001-06-06 20:29:01 +000030#include <list>
31#include "llvmAsmParser.h"
Brian Gaekebc127092003-10-10 19:12:08 +000032#include <cctype>
33#include <cstdlib>
Chris Lattner2f7c9632001-06-06 20:29:01 +000034
Chris Lattner416a0d42005-05-20 03:25:47 +000035void set_scan_file(FILE * F){
36 yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) );
37}
38void set_scan_string (const char * str) {
39 yy_scan_string (str);
40}
41
Reid Spencer7e80b0b2006-10-26 06:15:43 +000042// Construct a token value for a non-obsolete token
Chris Lattner2f7c9632001-06-06 20:29:01 +000043#define RET_TOK(type, Enum, sym) \
Reid Spencer7e80b0b2006-10-26 06:15:43 +000044 llvmAsmlval.type.opcode = Instruction::Enum; \
45 llvmAsmlval.type.obsolete = false; \
46 return sym
47
48// Construct a token value for an obsolete token
49#define RET_TOK_OBSOLETE(type, Enum, sym) \
50 llvmAsmlval.type.opcode = Instruction::Enum; \
51 llvmAsmlval.type.obsolete = true; \
52 return sym
53
Reid Spencer9f4448a2006-11-19 23:07:00 +000054// Construct a token value for a non-obsolete type
55#define RET_TY(CType, sym) \
56 llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \
57 llvmAsmlval.TypeVal.signedness = isSignless; \
58 return sym
59
60// Construct a token value for an obsolete token
61#define RET_TY_OBSOLETE(CType, sign, sym) \
62 llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \
63 llvmAsmlval.TypeVal.signedness = sign; \
64 return sym
Chris Lattner2f7c9632001-06-06 20:29:01 +000065
Brian Gaeke960707c2003-11-11 22:41:34 +000066namespace llvm {
Chris Lattner2f7c9632001-06-06 20:29:01 +000067
Misha Brukman8b477072005-05-10 22:02:28 +000068// TODO: All of the static identifiers are figured out by the lexer,
Chris Lattner47af30c2001-09-07 16:32:43 +000069// these should be hashed to reduce the lexer size
Chris Lattner2f7c9632001-06-06 20:29:01 +000070
71
72// atoull - Convert an ascii string of decimal digits into the unsigned long
Misha Brukman8b477072005-05-10 22:02:28 +000073// long representation... this does not have to do input error checking,
Chris Lattner2f7c9632001-06-06 20:29:01 +000074// because we know that the input will be matched by a suitable regex...
75//
Chris Lattner1b343742002-04-07 08:10:41 +000076static uint64_t atoull(const char *Buffer) {
Chris Lattner2f7c9632001-06-06 20:29:01 +000077 uint64_t Result = 0;
78 for (; *Buffer; Buffer++) {
79 uint64_t OldRes = Result;
80 Result *= 10;
81 Result += *Buffer-'0';
Chris Lattner1b343742002-04-07 08:10:41 +000082 if (Result < OldRes) // Uh, oh, overflow detected!!!
Reid Spencer713eedc2006-08-18 08:43:06 +000083 GenerateError("constant bigger than 64 bits detected!");
Chris Lattner2f7c9632001-06-06 20:29:01 +000084 }
85 return Result;
86}
87
Chris Lattnere509bd42003-04-17 22:17:32 +000088static uint64_t HexIntToVal(const char *Buffer) {
Chris Lattner1b343742002-04-07 08:10:41 +000089 uint64_t Result = 0;
90 for (; *Buffer; ++Buffer) {
91 uint64_t OldRes = Result;
92 Result *= 16;
93 char C = *Buffer;
94 if (C >= '0' && C <= '9')
95 Result += C-'0';
96 else if (C >= 'A' && C <= 'F')
97 Result += C-'A'+10;
98 else if (C >= 'a' && C <= 'f')
99 Result += C-'a'+10;
100
101 if (Result < OldRes) // Uh, oh, overflow detected!!!
Reid Spencer713eedc2006-08-18 08:43:06 +0000102 GenerateError("constant bigger than 64 bits detected!");
Chris Lattner1b343742002-04-07 08:10:41 +0000103 }
Chris Lattnere509bd42003-04-17 22:17:32 +0000104 return Result;
105}
106
107
108// HexToFP - Convert the ascii string in hexidecimal format to the floating
109// point representation of it.
110//
111static double HexToFP(const char *Buffer) {
Chris Lattnerb99f4792002-04-07 08:31:26 +0000112 // Behave nicely in the face of C TBAA rules... see:
113 // http://www.nullstone.com/htmls/category/aliastyp.htm
Chris Lattner62fa7432003-04-22 20:20:28 +0000114 union {
115 uint64_t UI;
116 double FP;
117 } UIntToFP;
118 UIntToFP.UI = HexIntToVal(Buffer);
119
120 assert(sizeof(double) == sizeof(uint64_t) &&
121 "Data sizes incompatible on this target!");
122 return UIntToFP.FP; // Cast Hex constant to double
Chris Lattner1b343742002-04-07 08:10:41 +0000123}
124
Chris Lattner2f7c9632001-06-06 20:29:01 +0000125
Chris Lattner26e50dc2001-07-28 17:48:55 +0000126// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
127// appropriate character. If AllowNull is set to false, a \00 value will cause
128// an exception to be thrown.
129//
130// If AllowNull is set to true, the return value of the function points to the
131// last character of the string in memory.
132//
Chris Lattnere6801392002-07-25 06:17:42 +0000133char *UnEscapeLexed(char *Buffer, bool AllowNull) {
Chris Lattner26e50dc2001-07-28 17:48:55 +0000134 char *BOut = Buffer;
135 for (char *BIn = Buffer; *BIn; ) {
136 if (BIn[0] == '\\' && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
137 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
Chris Lattnerfa66dc72005-01-08 20:07:03 +0000138 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
Chris Lattner26e50dc2001-07-28 17:48:55 +0000139 if (!AllowNull && !*BOut)
Reid Spencer713eedc2006-08-18 08:43:06 +0000140 GenerateError("String literal cannot accept \\00 escape!");
Misha Brukman8b477072005-05-10 22:02:28 +0000141
Chris Lattner26e50dc2001-07-28 17:48:55 +0000142 BIn[3] = Tmp; // Restore character
143 BIn += 3; // Skip over handled chars
144 ++BOut;
145 } else {
146 *BOut++ = *BIn++;
147 }
148 }
149
150 return BOut;
151}
152
Brian Gaeke960707c2003-11-11 22:41:34 +0000153} // End llvm namespace
154
155using namespace llvm;
156
Chris Lattner2f7c9632001-06-06 20:29:01 +0000157#define YY_NEVER_INTERACTIVE 1
158%}
159
160
161
162/* Comments start with a ; and go till end of line */
163Comment ;.*
164
Chris Lattner17f729e2001-07-15 06:35:53 +0000165/* Variable(Value) identifiers start with a % sign */
Chris Lattner1366b302001-12-04 04:31:30 +0000166VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
Chris Lattner2f7c9632001-06-06 20:29:01 +0000167
168/* Label identifiers end with a colon */
Chris Lattner1366b302001-12-04 04:31:30 +0000169Label [-a-zA-Z$._0-9]+:
Alkis Evlogimenosa93b4522004-12-10 05:40:19 +0000170QuoteLabel \"[^\"]+\":
Chris Lattner2f7c9632001-06-06 20:29:01 +0000171
172/* Quoted names can contain any character except " and \ */
Chris Lattner0079e7d2003-10-18 05:53:13 +0000173StringConstant \"[^\"]*\"
Chris Lattner2f7c9632001-06-06 20:29:01 +0000174
175
176/* [PN]Integer: match positive and negative literal integer values that
177 * are preceeded by a '%' character. These represent unnamed variable slots.
178 */
179EPInteger %[0-9]+
180ENInteger %-[0-9]+
181
182
183/* E[PN]Integer: match positive and negative literal integer values */
184PInteger [0-9]+
185NInteger -[0-9]+
186
Chris Lattner212f70d2001-07-15 00:17:01 +0000187/* FPConstant - A Floating point constant.
Chris Lattner1b343742002-04-07 08:10:41 +0000188 */
Chris Lattner50f68ac2001-11-01 22:06:08 +0000189FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
Chris Lattner212f70d2001-07-15 00:17:01 +0000190
Chris Lattner1b343742002-04-07 08:10:41 +0000191/* HexFPConstant - Floating point constant represented in IEEE format as a
192 * hexadecimal number for when exponential notation is not precise enough.
193 */
194HexFPConstant 0x[0-9A-Fa-f]+
Chris Lattnere509bd42003-04-17 22:17:32 +0000195
196/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
197 * it to deal with 64 bit numbers.
198 */
199HexIntConstant [us]0x[0-9A-Fa-f]+
Chris Lattner2f7c9632001-06-06 20:29:01 +0000200%%
201
202{Comment} { /* Ignore comments for now */ }
203
204begin { return BEGINTOK; }
Chris Lattner1e1a9b42002-05-03 18:23:48 +0000205end { return ENDTOK; }
Chris Lattnerc0ba90e2004-03-31 03:49:47 +0000206true { return TRUETOK; }
207false { return FALSETOK; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000208declare { return DECLARE; }
Chris Lattnerda975502001-09-10 07:58:01 +0000209global { return GLOBAL; }
Chris Lattner7fb14f52001-09-18 04:00:54 +0000210constant { return CONSTANT; }
Chris Lattner841d8b92001-11-26 18:54:16 +0000211internal { return INTERNAL; }
Chris Lattner379a8d22003-04-16 20:28:45 +0000212linkonce { return LINKONCE; }
Chris Lattnerf4120d92003-10-10 04:54:02 +0000213weak { return WEAK; }
Chris Lattner379a8d22003-04-16 20:28:45 +0000214appending { return APPENDING; }
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000215dllimport { return DLLIMPORT; }
216dllexport { return DLLEXPORT; }
217extern_weak { return EXTERN_WEAK; }
Chris Lattnere2dd92b2002-10-06 22:45:09 +0000218uninitialized { return EXTERNAL; } /* Deprecated, turn into external */
219external { return EXTERNAL; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000220implementation { return IMPLEMENTATION; }
Chris Lattner79694012003-06-28 20:01:34 +0000221zeroinitializer { return ZEROINITIALIZER; }
Chris Lattner42b5a8a2001-07-25 22:47:46 +0000222\.\.\. { return DOTDOTDOT; }
Chris Lattner4ff31492004-10-16 18:17:13 +0000223undef { return UNDEF; }
Chris Lattnerfbdec252001-09-30 22:46:54 +0000224null { return NULL_TOK; }
Chris Lattner3d4b2902001-10-13 06:37:14 +0000225to { return TO; }
Chris Lattner17235712004-02-08 21:48:25 +0000226except { RET_TOK(TermOpVal, Unwind, UNWIND); }
Chris Lattnerdb3b2022002-08-14 17:12:33 +0000227not { return NOT; } /* Deprecated, turned into XOR */
Chris Lattnerca4d4bd2005-05-06 06:20:33 +0000228tail { return TAIL; }
Chris Lattner20126132003-04-22 19:07:06 +0000229target { return TARGET; }
Reid Spencer4add9192004-07-25 17:56:00 +0000230triple { return TRIPLE; }
231deplibs { return DEPLIBS; }
Chris Lattner20126132003-04-22 19:07:06 +0000232endian { return ENDIAN; }
233pointersize { return POINTERSIZE; }
Chris Lattnerfd3d29a2006-10-22 06:07:41 +0000234datalayout { return DATALAYOUT; }
Chris Lattner20126132003-04-22 19:07:06 +0000235little { return LITTLE; }
236big { return BIG; }
Chris Lattner8b1680e2003-09-08 18:20:29 +0000237volatile { return VOLATILE; }
Chris Lattner9da804d2005-11-12 00:11:30 +0000238align { return ALIGN; }
239section { return SECTION; }
Chris Lattner3acaf5c2006-01-24 00:40:17 +0000240module { return MODULE; }
Chris Lattnerf09741f2006-01-23 23:05:15 +0000241asm { return ASM_TOK; }
Chris Lattnera02d6032006-01-25 22:26:43 +0000242sideeffect { return SIDEEFFECT; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000243
Chris Lattner53bdd312005-05-06 20:27:19 +0000244cc { return CC_TOK; }
245ccc { return CCC_TOK; }
Chris Lattner21cffff2006-05-19 21:28:34 +0000246csretcc { return CSRETCC_TOK; }
Chris Lattner53bdd312005-05-06 20:27:19 +0000247fastcc { return FASTCC_TOK; }
248coldcc { return COLDCC_TOK; }
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +0000249x86_stdcallcc { return X86_STDCALLCC_TOK; }
250x86_fastcallcc { return X86_FASTCALLCC_TOK; }
Chris Lattner53bdd312005-05-06 20:27:19 +0000251
Reid Spencer9f4448a2006-11-19 23:07:00 +0000252void { RET_TY(Type::VoidTy, VOID); }
253bool { RET_TY(Type::BoolTy, BOOL); }
254sbyte { RET_TY_OBSOLETE(Type::SByteTy, isSigned, SBYTE); }
255ubyte { RET_TY_OBSOLETE(Type::UByteTy, isUnsigned, UBYTE); }
256short { RET_TY_OBSOLETE(Type::ShortTy, isSigned, SHORT); }
257ushort { RET_TY_OBSOLETE(Type::UShortTy,isUnsigned, USHORT); }
258int { RET_TY_OBSOLETE(Type::IntTy, isSigned, INT); }
259uint { RET_TY_OBSOLETE(Type::UIntTy, isUnsigned, UINT); }
260long { RET_TY_OBSOLETE(Type::LongTy, isSigned, LONG); }
261ulong { RET_TY_OBSOLETE(Type::ULongTy, isUnsigned, ULONG); }
262float { RET_TY(Type::FloatTy, FLOAT); }
263double { RET_TY(Type::DoubleTy, DOUBLE); }
264label { RET_TY(Type::LabelTy, LABEL); }
Reid Spencere258e942004-07-04 12:17:44 +0000265type { return TYPE; }
Chris Lattnerf269b9d2002-04-04 19:22:17 +0000266opaque { return OPAQUE; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000267
Chris Lattner2f7c9632001-06-06 20:29:01 +0000268add { RET_TOK(BinaryOpVal, Add, ADD); }
269sub { RET_TOK(BinaryOpVal, Sub, SUB); }
270mul { RET_TOK(BinaryOpVal, Mul, MUL); }
Reid Spencer7e80b0b2006-10-26 06:15:43 +0000271div { RET_TOK_OBSOLETE(BinaryOpVal, UDiv, UDIV); }
272udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
273sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
274fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
Reid Spencer7eb55b32006-11-02 01:53:59 +0000275rem { RET_TOK_OBSOLETE(BinaryOpVal, URem, UREM); }
276urem { RET_TOK(BinaryOpVal, URem, UREM); }
277srem { RET_TOK(BinaryOpVal, SRem, SREM); }
278frem { RET_TOK(BinaryOpVal, FRem, FREM); }
Chris Lattnerc27b1d72001-10-20 09:32:59 +0000279and { RET_TOK(BinaryOpVal, And, AND); }
280or { RET_TOK(BinaryOpVal, Or , OR ); }
281xor { RET_TOK(BinaryOpVal, Xor, XOR); }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000282setne { RET_TOK(BinaryOpVal, SetNE, SETNE); }
283seteq { RET_TOK(BinaryOpVal, SetEQ, SETEQ); }
284setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); }
285setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); }
286setle { RET_TOK(BinaryOpVal, SetLE, SETLE); }
287setge { RET_TOK(BinaryOpVal, SetGE, SETGE); }
288
Chris Lattnerb94550e2003-10-19 21:34:28 +0000289phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
Chris Lattnerd8bebcd2001-07-08 21:10:27 +0000290call { RET_TOK(OtherOpVal, Call, CALL); }
291cast { RET_TOK(OtherOpVal, Cast, CAST); }
Chris Lattner6536f0c2004-03-12 05:51:36 +0000292select { RET_TOK(OtherOpVal, Select, SELECT); }
Chris Lattnerd8bebcd2001-07-08 21:10:27 +0000293shl { RET_TOK(OtherOpVal, Shl, SHL); }
Reid Spencerfdff9382006-11-08 06:47:33 +0000294shr { RET_TOK_OBSOLETE(OtherOpVal, LShr, LSHR); }
295lshr { RET_TOK(OtherOpVal, LShr, LSHR); }
296ashr { RET_TOK(OtherOpVal, AShr, ASHR); }
Andrew Lenharth9144ec42005-06-18 18:34:52 +0000297vanext { return VANEXT_old; }
298vaarg { return VAARG_old; }
299va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000300ret { RET_TOK(TermOpVal, Ret, RET); }
301br { RET_TOK(TermOpVal, Br, BR); }
302switch { RET_TOK(TermOpVal, Switch, SWITCH); }
Chris Lattner3d4b2902001-10-13 06:37:14 +0000303invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
Chris Lattner9c58cf62003-09-08 18:54:55 +0000304unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
Chris Lattner4ff31492004-10-16 18:17:13 +0000305unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000306
307malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
308alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); }
309free { RET_TOK(MemOpVal, Free, FREE); }
310load { RET_TOK(MemOpVal, Load, LOAD); }
311store { RET_TOK(MemOpVal, Store, STORE); }
Chris Lattner62ecb4a2001-07-08 23:22:50 +0000312getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000313
Robert Bocchinoaa1cf542006-01-10 19:04:32 +0000314extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); }
Robert Bocchinofdf9e412006-01-17 20:06:25 +0000315insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
Chris Lattner8ec3c2e2006-04-08 01:18:35 +0000316shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
Robert Bocchinoaa1cf542006-01-10 19:04:32 +0000317
Chris Lattner2f7c9632001-06-06 20:29:01 +0000318
Chris Lattner26e50dc2001-07-28 17:48:55 +0000319{VarID} {
320 UnEscapeLexed(yytext+1);
321 llvmAsmlval.StrVal = strdup(yytext+1); // Skip %
Misha Brukman8b477072005-05-10 22:02:28 +0000322 return VAR_ID;
Chris Lattner26e50dc2001-07-28 17:48:55 +0000323 }
324{Label} {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000325 yytext[strlen(yytext)-1] = 0; // nuke colon
Chris Lattner26e50dc2001-07-28 17:48:55 +0000326 UnEscapeLexed(yytext);
Misha Brukman8b477072005-05-10 22:02:28 +0000327 llvmAsmlval.StrVal = strdup(yytext);
328 return LABELSTR;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000329 }
Chris Lattnerfcec9d62004-12-10 05:27:29 +0000330{QuoteLabel} {
331 yytext[strlen(yytext)-2] = 0; // nuke colon, end quote
332 UnEscapeLexed(yytext+1);
Misha Brukman8b477072005-05-10 22:02:28 +0000333 llvmAsmlval.StrVal = strdup(yytext+1);
334 return LABELSTR;
Chris Lattnerfcec9d62004-12-10 05:27:29 +0000335 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000336
Chris Lattner26e50dc2001-07-28 17:48:55 +0000337{StringConstant} { // Note that we cannot unescape a string constant here! The
Misha Brukman8b477072005-05-10 22:02:28 +0000338 // string constant might contain a \00 which would not be
Chris Lattner26e50dc2001-07-28 17:48:55 +0000339 // understood by the string stuff. It is valid to make a
340 // [sbyte] c"Hello World\00" constant, for example.
341 //
Misha Brukman8b477072005-05-10 22:02:28 +0000342 yytext[strlen(yytext)-1] = 0; // nuke end quote
343 llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote
344 return STRINGCONSTANT;
Chris Lattner26e50dc2001-07-28 17:48:55 +0000345 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000346
347
348{PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; }
Misha Brukman8b477072005-05-10 22:02:28 +0000349{NInteger} {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000350 uint64_t Val = atoull(yytext+1);
Misha Brukman8b477072005-05-10 22:02:28 +0000351 // +1: we have bigger negative range
352 if (Val > (uint64_t)INT64_MAX+1)
Reid Spencer713eedc2006-08-18 08:43:06 +0000353 GenerateError("Constant too large for signed 64 bits!");
Misha Brukman8b477072005-05-10 22:02:28 +0000354 llvmAsmlval.SInt64Val = -Val;
355 return ESINT64VAL;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000356 }
Chris Lattnere509bd42003-04-17 22:17:32 +0000357{HexIntConstant} {
Misha Brukman8b477072005-05-10 22:02:28 +0000358 llvmAsmlval.UInt64Val = HexIntToVal(yytext+3);
Chris Lattnere509bd42003-04-17 22:17:32 +0000359 return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL;
360 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000361
Chris Lattnerfa66dc72005-01-08 20:07:03 +0000362{EPInteger} {
363 uint64_t Val = atoull(yytext+1);
364 if ((unsigned)Val != Val)
Reid Spencer713eedc2006-08-18 08:43:06 +0000365 GenerateError("Invalid value number (too large)!");
Chris Lattnerfa66dc72005-01-08 20:07:03 +0000366 llvmAsmlval.UIntVal = unsigned(Val);
367 return UINTVAL;
368 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000369{ENInteger} {
370 uint64_t Val = atoull(yytext+2);
Misha Brukman8b477072005-05-10 22:02:28 +0000371 // +1: we have bigger negative range
372 if (Val > (uint64_t)INT32_MAX+1)
Reid Spencer713eedc2006-08-18 08:43:06 +0000373 GenerateError("Constant too large for signed 32 bits!");
Chris Lattnerfa66dc72005-01-08 20:07:03 +0000374 llvmAsmlval.SIntVal = (int)-Val;
Misha Brukman8b477072005-05-10 22:02:28 +0000375 return SINTVAL;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000376 }
377
Chris Lattner212f70d2001-07-15 00:17:01 +0000378{FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; }
Chris Lattner1b343742002-04-07 08:10:41 +0000379{HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000380
Chris Lattner3922d602004-03-19 23:34:33 +0000381<<EOF>> {
382 /* Make sure to free the internal buffers for flex when we are
383 * done reading our input!
384 */
385 yy_delete_buffer(YY_CURRENT_BUFFER);
386 return EOF;
387 }
388
Chris Lattner604e19e2004-05-27 17:49:14 +0000389[ \r\t\n] { /* Ignore whitespace */ }
Chris Lattner47af30c2001-09-07 16:32:43 +0000390. { return yytext[0]; }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000391
392%%