blob: 98a21cabaaa581d0f45390e674aab30decd872a7 [file] [log] [blame]
Chris Lattner32eecb02006-02-14 05:14:46 +00001/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
2//
3// 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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the flex scanner for LLVM assembly languages files.
11//
12//===----------------------------------------------------------------------===*/
13
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"
29#include "llvm/Module.h"
Chris Lattner8e008322007-05-22 06:47:55 +000030#include "llvm/Support/MathExtras.h"
Chris Lattner32eecb02006-02-14 05:14:46 +000031#include <list>
32#include "llvmAsmParser.h"
33#include <cctype>
34#include <cstdlib>
35
36void set_scan_file(FILE * F){
37 yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) );
38}
39void set_scan_string (const char * str) {
40 yy_scan_string (str);
41}
42
Reid Spencer3ed469c2006-11-02 20:25:50 +000043// Construct a token value for a non-obsolete token
Chris Lattner32eecb02006-02-14 05:14:46 +000044#define RET_TOK(type, Enum, sym) \
Reid Spencera132e042006-12-03 05:46:11 +000045 llvmAsmlval.type = Instruction::Enum; \
46 return sym
47
Reid Spencer3ed469c2006-11-02 20:25:50 +000048// Construct a token value for an obsolete token
Reid Spencera132e042006-12-03 05:46:11 +000049#define RET_TY(CTYPE, SYM) \
50 llvmAsmlval.PrimType = CTYPE;\
Reid Spencer481169e2006-12-01 00:33:46 +000051 return SYM
Chris Lattner32eecb02006-02-14 05:14:46 +000052
53namespace llvm {
54
55// TODO: All of the static identifiers are figured out by the lexer,
56// these should be hashed to reduce the lexer size
57
58
59// atoull - Convert an ascii string of decimal digits into the unsigned long
60// long representation... this does not have to do input error checking,
61// because we know that the input will be matched by a suitable regex...
62//
63static uint64_t atoull(const char *Buffer) {
64 uint64_t Result = 0;
65 for (; *Buffer; Buffer++) {
66 uint64_t OldRes = Result;
67 Result *= 10;
68 Result += *Buffer-'0';
69 if (Result < OldRes) // Uh, oh, overflow detected!!!
Reid Spencer61c83e02006-08-18 08:43:06 +000070 GenerateError("constant bigger than 64 bits detected!");
Chris Lattner32eecb02006-02-14 05:14:46 +000071 }
72 return Result;
73}
74
75static uint64_t HexIntToVal(const char *Buffer) {
76 uint64_t Result = 0;
77 for (; *Buffer; ++Buffer) {
78 uint64_t OldRes = Result;
79 Result *= 16;
80 char C = *Buffer;
81 if (C >= '0' && C <= '9')
82 Result += C-'0';
83 else if (C >= 'A' && C <= 'F')
84 Result += C-'A'+10;
85 else if (C >= 'a' && C <= 'f')
86 Result += C-'a'+10;
87
88 if (Result < OldRes) // Uh, oh, overflow detected!!!
Reid Spencer61c83e02006-08-18 08:43:06 +000089 GenerateError("constant bigger than 64 bits detected!");
Chris Lattner32eecb02006-02-14 05:14:46 +000090 }
91 return Result;
92}
93
Dale Johannesenc72cd7e2007-09-11 18:33:39 +000094// HexToFP - Convert the ascii string in hexadecimal format to the floating
Chris Lattner32eecb02006-02-14 05:14:46 +000095// point representation of it.
96//
97static double HexToFP(const char *Buffer) {
Chris Lattner8e008322007-05-22 06:47:55 +000098 return BitsToDouble(HexIntToVal(Buffer)); // Cast Hex constant to double
Chris Lattner32eecb02006-02-14 05:14:46 +000099}
100
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000101static void HexToIntPair(const char *Buffer, uint64_t Pair[2]) {
102 Pair[0] = 0;
103 for (int i=0; i<16; i++, Buffer++) {
104 assert(*Buffer);
105 Pair[0] *= 16;
106 char C = *Buffer;
107 if (C >= '0' && C <= '9')
108 Pair[0] += C-'0';
109 else if (C >= 'A' && C <= 'F')
110 Pair[0] += C-'A'+10;
111 else if (C >= 'a' && C <= 'f')
112 Pair[0] += C-'a'+10;
113 }
114 Pair[1] = 0;
115 for (int i=0; i<16 && *Buffer; i++, Buffer++) {
116 Pair[1] *= 16;
117 char C = *Buffer;
118 if (C >= '0' && C <= '9')
119 Pair[1] += C-'0';
120 else if (C >= 'A' && C <= 'F')
121 Pair[1] += C-'A'+10;
122 else if (C >= 'a' && C <= 'f')
123 Pair[1] += C-'a'+10;
124 }
125 if (*Buffer)
126 GenerateError("constant bigger than 128 bits detected!");
127}
Chris Lattner32eecb02006-02-14 05:14:46 +0000128
129// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000130// appropriate character.
Reid Spencere2aa9612007-05-22 19:08:16 +0000131char *UnEscapeLexed(char *Buffer, char* EndBuffer) {
Chris Lattner32eecb02006-02-14 05:14:46 +0000132 char *BOut = Buffer;
133 for (char *BIn = Buffer; *BIn; ) {
Reid Spencere2aa9612007-05-22 19:08:16 +0000134 if (BIn[0] == '\\') {
135 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
136 *BOut++ = '\\'; // Two \ becomes one
137 BIn += 2;
138 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
139 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
140 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
141 BIn[3] = Tmp; // Restore character
142 BIn += 3; // Skip over handled chars
143 ++BOut;
144 } else {
145 *BOut++ = *BIn++;
146 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000147 } else {
148 *BOut++ = *BIn++;
149 }
150 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000151 return BOut;
152}
153
154} // End llvm namespace
155
156using namespace llvm;
157
158#define YY_NEVER_INTERACTIVE 1
159%}
160
161
162
163/* Comments start with a ; and go till end of line */
164Comment ;.*
165
Reid Spencer41dff5e2007-01-26 08:05:27 +0000166/* Local Values and Type identifiers start with a % sign */
167LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]*
168
169/* Global Value identifiers start with an @ sign */
170GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]*
Chris Lattner32eecb02006-02-14 05:14:46 +0000171
172/* Label identifiers end with a colon */
173Label [-a-zA-Z$._0-9]+:
174QuoteLabel \"[^\"]+\":
175
176/* Quoted names can contain any character except " and \ */
177StringConstant \"[^\"]*\"
Reid Spencer41dff5e2007-01-26 08:05:27 +0000178AtStringConstant @\"[^\"]*\"
Reid Spencered951ea2007-05-19 07:22:10 +0000179PctStringConstant %\"[^\"]*\"
Reid Spencer41dff5e2007-01-26 08:05:27 +0000180
181/* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */
182LocalVarID %[0-9]+
183GlobalVarID @[0-9]+
Chris Lattner32eecb02006-02-14 05:14:46 +0000184
Reid Spencer41dff5e2007-01-26 08:05:27 +0000185/* Integer types are specified with i and a bitwidth */
Reid Spencer4db20632007-01-12 07:28:27 +0000186IntegerType i[0-9]+
Reid Spencera54b7cb2007-01-12 07:05:14 +0000187
Reid Spencer41dff5e2007-01-26 08:05:27 +0000188/* E[PN]Integer: match positive and negative literal integer values. */
Chris Lattner32eecb02006-02-14 05:14:46 +0000189PInteger [0-9]+
190NInteger -[0-9]+
191
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000192/* FPConstant - A Floating point constant. Float and double only.
Chris Lattner32eecb02006-02-14 05:14:46 +0000193 */
194FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
195
196/* HexFPConstant - Floating point constant represented in IEEE format as a
197 * hexadecimal number for when exponential notation is not precise enough.
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000198 * Float and double only.
Chris Lattner32eecb02006-02-14 05:14:46 +0000199 */
200HexFPConstant 0x[0-9A-Fa-f]+
201
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000202/* F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
203 */
204HexFP80Constant 0xK[0-9A-Fa-f]+
205
206/* F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
207 */
208HexFP128Constant 0xL[0-9A-Fa-f]+
209
210/* PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
211 */
212HexPPC128Constant 0xM[0-9A-Fa-f]+
213
Chris Lattner32eecb02006-02-14 05:14:46 +0000214/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
215 * it to deal with 64 bit numbers.
216 */
217HexIntConstant [us]0x[0-9A-Fa-f]+
Reid Spencer38c91a92007-02-28 02:24:54 +0000218
Reid Spencerd8e616b2007-07-31 03:55:56 +0000219/* WSNL - shorthand for whitespace followed by newline */
220WSNL [ \r\t]*$
Chris Lattner32eecb02006-02-14 05:14:46 +0000221%%
222
223{Comment} { /* Ignore comments for now */ }
224
225begin { return BEGINTOK; }
226end { return ENDTOK; }
227true { return TRUETOK; }
228false { return FALSETOK; }
229declare { return DECLARE; }
Reid Spencer6fd36ab2006-12-29 20:35:03 +0000230define { return DEFINE; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000231global { return GLOBAL; }
232constant { return CONSTANT; }
233internal { return INTERNAL; }
234linkonce { return LINKONCE; }
235weak { return WEAK; }
236appending { return APPENDING; }
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000237dllimport { return DLLIMPORT; }
238dllexport { return DLLEXPORT; }
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000239hidden { return HIDDEN; }
Anton Korobeynikov6f9896f2007-04-29 18:35:00 +0000240protected { return PROTECTED; }
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000241extern_weak { return EXTERN_WEAK; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000242external { return EXTERNAL; }
Lauro Ramos Venancioc7635522007-04-12 18:32:50 +0000243thread_local { return THREAD_LOCAL; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000244zeroinitializer { return ZEROINITIALIZER; }
245\.\.\. { return DOTDOTDOT; }
246undef { return UNDEF; }
247null { return NULL_TOK; }
248to { return TO; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000249tail { return TAIL; }
250target { return TARGET; }
251triple { return TRIPLE; }
252deplibs { return DEPLIBS; }
Chris Lattner1ae022f2006-10-22 06:08:13 +0000253datalayout { return DATALAYOUT; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000254volatile { return VOLATILE; }
255align { return ALIGN; }
256section { return SECTION; }
Anton Korobeynikov77d0f972007-04-25 14:29:12 +0000257alias { return ALIAS; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000258module { return MODULE; }
259asm { return ASM_TOK; }
260sideeffect { return SIDEEFFECT; }
261
262cc { return CC_TOK; }
263ccc { return CCC_TOK; }
264fastcc { return FASTCC_TOK; }
265coldcc { return COLDCC_TOK; }
Anton Korobeynikovbcb97702006-09-17 20:25:45 +0000266x86_stdcallcc { return X86_STDCALLCC_TOK; }
267x86_fastcallcc { return X86_FASTCALLCC_TOK; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000268
Reid Spencerb8f85052007-07-31 03:50:36 +0000269signext { return SIGNEXT; }
270zeroext { return ZEROEXT; }
Reid Spencer832254e2007-02-02 02:16:23 +0000271inreg { return INREG; }
272sret { return SRET; }
Reid Spencer67d8ed92007-03-22 02:14:08 +0000273nounwind { return NOUNWIND; }
274noreturn { return NORETURN; }
Chris Lattnerce5f24e2007-07-05 17:26:49 +0000275noalias { return NOALIAS; }
Reid Spencerb8f85052007-07-31 03:50:36 +0000276byval { return BYVAL; }
277nest { return NEST; }
Anton Korobeynikovb9b977d2007-11-14 09:53:48 +0000278pure { return PURE; }
279const { return CONST; }
Reid Spencerb8f85052007-07-31 03:50:36 +0000280sext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
281 return SIGNEXT; }
282zext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
283 return ZEROEXT; }
Reid Spencer832254e2007-02-02 02:16:23 +0000284
Reid Spencera132e042006-12-03 05:46:11 +0000285void { RET_TY(Type::VoidTy, VOID); }
Reid Spencera132e042006-12-03 05:46:11 +0000286float { RET_TY(Type::FloatTy, FLOAT); }
287double { RET_TY(Type::DoubleTy,DOUBLE);}
Dale Johannesen320fc8a2007-08-03 01:03:46 +0000288x86_fp80 { RET_TY(Type::X86_FP80Ty, X86_FP80);}
Dale Johannesenea583102007-09-12 03:31:28 +0000289fp128 { RET_TY(Type::FP128Ty, FP128);}
290ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
Reid Spencera132e042006-12-03 05:46:11 +0000291label { RET_TY(Type::LabelTy, LABEL); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000292type { return TYPE; }
293opaque { return OPAQUE; }
Reid Spencera54b7cb2007-01-12 07:05:14 +0000294{IntegerType} { uint64_t NumBits = atoull(yytext+1);
295 if (NumBits < IntegerType::MIN_INT_BITS ||
296 NumBits > IntegerType::MAX_INT_BITS)
297 GenerateError("Bitwidth for integer type out of range!");
298 const Type* Ty = IntegerType::get(NumBits);
299 RET_TY(Ty, INTTYPE);
300 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000301
302add { RET_TOK(BinaryOpVal, Add, ADD); }
303sub { RET_TOK(BinaryOpVal, Sub, SUB); }
304mul { RET_TOK(BinaryOpVal, Mul, MUL); }
Reid Spencer3ed469c2006-11-02 20:25:50 +0000305udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
306sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
307fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
Reid Spencer3ed469c2006-11-02 20:25:50 +0000308urem { RET_TOK(BinaryOpVal, URem, UREM); }
309srem { RET_TOK(BinaryOpVal, SRem, SREM); }
310frem { RET_TOK(BinaryOpVal, FRem, FREM); }
Reid Spencer832254e2007-02-02 02:16:23 +0000311shl { RET_TOK(BinaryOpVal, Shl, SHL); }
312lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
313ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000314and { RET_TOK(BinaryOpVal, And, AND); }
315or { RET_TOK(BinaryOpVal, Or , OR ); }
316xor { RET_TOK(BinaryOpVal, Xor, XOR); }
Reid Spencera132e042006-12-03 05:46:11 +0000317icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
318fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
Reid Spencer832254e2007-02-02 02:16:23 +0000319
Reid Spencer6e18b7d2006-12-03 06:59:29 +0000320eq { return EQ; }
321ne { return NE; }
322slt { return SLT; }
323sgt { return SGT; }
324sle { return SLE; }
325sge { return SGE; }
326ult { return ULT; }
327ugt { return UGT; }
328ule { return ULE; }
329uge { return UGE; }
330oeq { return OEQ; }
331one { return ONE; }
332olt { return OLT; }
333ogt { return OGT; }
334ole { return OLE; }
335oge { return OGE; }
336ord { return ORD; }
337uno { return UNO; }
338ueq { return UEQ; }
339une { return UNE; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000340
341phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
342call { RET_TOK(OtherOpVal, Call, CALL); }
Reid Spencer3da59db2006-11-27 01:05:10 +0000343trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
344zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
345sext { RET_TOK(CastOpVal, SExt, SEXT); }
346fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
347fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
348uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
349sitofp { RET_TOK(CastOpVal, SIToFP, SITOFP); }
350fptoui { RET_TOK(CastOpVal, FPToUI, FPTOUI); }
351fptosi { RET_TOK(CastOpVal, FPToSI, FPTOSI); }
352inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
353ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
354bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000355select { RET_TOK(OtherOpVal, Select, SELECT); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000356va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
357ret { RET_TOK(TermOpVal, Ret, RET); }
358br { RET_TOK(TermOpVal, Br, BR); }
359switch { RET_TOK(TermOpVal, Switch, SWITCH); }
360invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
361unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
362unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); }
363
364malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
365alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); }
366free { RET_TOK(MemOpVal, Free, FREE); }
367load { RET_TOK(MemOpVal, Load, LOAD); }
368store { RET_TOK(MemOpVal, Store, STORE); }
369getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
370
371extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); }
372insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
Chris Lattnerd5efe842006-04-08 01:18:56 +0000373shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000374
375
Reid Spencer41dff5e2007-01-26 08:05:27 +0000376{LocalVarName} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000377 llvmAsmlval.StrVal = new std::string(yytext+1); // Skip %
Reid Spencer41dff5e2007-01-26 08:05:27 +0000378 return LOCALVAR;
379 }
380{GlobalVarName} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000381 llvmAsmlval.StrVal = new std::string(yytext+1); // Skip @
Reid Spencer41dff5e2007-01-26 08:05:27 +0000382 return GLOBALVAR;
Chris Lattner32eecb02006-02-14 05:14:46 +0000383 }
384{Label} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000385 yytext[yyleng-1] = 0; // nuke colon
386 llvmAsmlval.StrVal = new std::string(yytext);
Chris Lattner32eecb02006-02-14 05:14:46 +0000387 return LABELSTR;
388 }
389{QuoteLabel} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000390 yytext[yyleng-2] = 0; // nuke colon, end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000391 const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000392 llvmAsmlval.StrVal =
393 new std::string(yytext+1, EndChar - yytext - 1);
Chris Lattner32eecb02006-02-14 05:14:46 +0000394 return LABELSTR;
395 }
396
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000397{StringConstant} { yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000398 const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000399 llvmAsmlval.StrVal =
400 new std::string(yytext+1, EndChar - yytext - 1);
Chris Lattner32eecb02006-02-14 05:14:46 +0000401 return STRINGCONSTANT;
402 }
Reid Spencer41dff5e2007-01-26 08:05:27 +0000403{AtStringConstant} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000404 yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000405 const char* EndChar =
406 UnEscapeLexed(yytext+2, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000407 llvmAsmlval.StrVal =
408 new std::string(yytext+2, EndChar - yytext - 2);
Reid Spencer41dff5e2007-01-26 08:05:27 +0000409 return ATSTRINGCONSTANT;
410 }
Reid Spencered951ea2007-05-19 07:22:10 +0000411{PctStringConstant} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000412 yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000413 const char* EndChar =
414 UnEscapeLexed(yytext+2, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000415 llvmAsmlval.StrVal =
416 new std::string(yytext+2, EndChar - yytext - 2);
Reid Spencered951ea2007-05-19 07:22:10 +0000417 return PCTSTRINGCONSTANT;
418 }
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000419{PInteger} {
420 uint32_t numBits = ((yyleng * 64) / 19) + 1;
421 APInt Tmp(numBits, yytext, yyleng, 10);
Reid Spencer38c91a92007-02-28 02:24:54 +0000422 uint32_t activeBits = Tmp.getActiveBits();
423 if (activeBits > 0 && activeBits < numBits)
424 Tmp.trunc(activeBits);
425 if (Tmp.getBitWidth() > 64) {
426 llvmAsmlval.APIntVal = new APInt(Tmp);
427 return EUAPINTVAL;
428 } else {
429 llvmAsmlval.UInt64Val = Tmp.getZExtValue();
430 return EUINT64VAL;
431 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000432 }
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000433{NInteger} {
434 uint32_t numBits = (((yyleng-1) * 64) / 19) + 2;
435 APInt Tmp(numBits, yytext, yyleng, 10);
Reid Spencer38c91a92007-02-28 02:24:54 +0000436 uint32_t minBits = Tmp.getMinSignedBits();
437 if (minBits > 0 && minBits < numBits)
438 Tmp.trunc(minBits);
439 if (Tmp.getBitWidth() > 64) {
440 llvmAsmlval.APIntVal = new APInt(Tmp);
441 return ESAPINTVAL;
442 } else {
443 llvmAsmlval.SInt64Val = Tmp.getSExtValue();
444 return ESINT64VAL;
445 }
446 }
447
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000448{HexIntConstant} { int len = yyleng - 3;
Reid Spencer38c91a92007-02-28 02:24:54 +0000449 uint32_t bits = len * 4;
450 APInt Tmp(bits, yytext+3, len, 16);
451 uint32_t activeBits = Tmp.getActiveBits();
452 if (activeBits > 0 && activeBits < bits)
453 Tmp.trunc(activeBits);
454 if (Tmp.getBitWidth() > 64) {
455 llvmAsmlval.APIntVal = new APInt(Tmp);
456 return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
457 } else if (yytext[0] == 's') {
458 llvmAsmlval.SInt64Val = Tmp.getSExtValue();
459 return ESINT64VAL;
460 } else {
461 llvmAsmlval.UInt64Val = Tmp.getZExtValue();
462 return EUINT64VAL;
463 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000464 }
465
Reid Spencer41dff5e2007-01-26 08:05:27 +0000466{LocalVarID} {
Chris Lattner32eecb02006-02-14 05:14:46 +0000467 uint64_t Val = atoull(yytext+1);
468 if ((unsigned)Val != Val)
Reid Spencer61c83e02006-08-18 08:43:06 +0000469 GenerateError("Invalid value number (too large)!");
Chris Lattner32eecb02006-02-14 05:14:46 +0000470 llvmAsmlval.UIntVal = unsigned(Val);
Reid Spencer41dff5e2007-01-26 08:05:27 +0000471 return LOCALVAL_ID;
Chris Lattner32eecb02006-02-14 05:14:46 +0000472 }
Reid Spencer41dff5e2007-01-26 08:05:27 +0000473{GlobalVarID} {
474 uint64_t Val = atoull(yytext+1);
475 if ((unsigned)Val != Val)
476 GenerateError("Invalid value number (too large)!");
477 llvmAsmlval.UIntVal = unsigned(Val);
478 return GLOBALVAL_ID;
Chris Lattner32eecb02006-02-14 05:14:46 +0000479 }
480
Dale Johannesen43421b32007-09-06 18:13:44 +0000481{FPConstant} { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
Dale Johannesenea583102007-09-12 03:31:28 +0000482{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext+2));
Dale Johannesen43421b32007-09-06 18:13:44 +0000483 return FPVAL;
484 }
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000485{HexFP80Constant} { uint64_t Pair[2];
Dale Johannesenea583102007-09-12 03:31:28 +0000486 HexToIntPair(yytext+3, Pair);
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000487 llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
488 return FPVAL;
489 }
490{HexFP128Constant} { uint64_t Pair[2];
Dale Johannesenea583102007-09-12 03:31:28 +0000491 HexToIntPair(yytext+3, Pair);
Dale Johannesena471c2e2007-10-11 18:07:22 +0000492 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000493 return FPVAL;
494 }
495{HexPPC128Constant} { uint64_t Pair[2];
Dale Johannesenea583102007-09-12 03:31:28 +0000496 HexToIntPair(yytext+3, Pair);
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000497 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
498 return FPVAL;
499 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000500
501<<EOF>> {
502 /* Make sure to free the internal buffers for flex when we are
503 * done reading our input!
504 */
505 yy_delete_buffer(YY_CURRENT_BUFFER);
506 return EOF;
507 }
508
509[ \r\t\n] { /* Ignore whitespace */ }
510. { return yytext[0]; }
511
512%%