blob: 5acbbacf60fdb7ce2b69edbcb0d1b45890c5bc4d [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; }
278sext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
279 return SIGNEXT; }
280zext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
281 return ZEROEXT; }
Reid Spencer832254e2007-02-02 02:16:23 +0000282
Reid Spencera132e042006-12-03 05:46:11 +0000283void { RET_TY(Type::VoidTy, VOID); }
Reid Spencera132e042006-12-03 05:46:11 +0000284float { RET_TY(Type::FloatTy, FLOAT); }
285double { RET_TY(Type::DoubleTy,DOUBLE);}
Dale Johannesen320fc8a2007-08-03 01:03:46 +0000286x86_fp80 { RET_TY(Type::X86_FP80Ty, X86_FP80);}
287fp128 { RET_TY(Type::FP128Ty, FP128);}
288ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
Reid Spencera132e042006-12-03 05:46:11 +0000289label { RET_TY(Type::LabelTy, LABEL); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000290type { return TYPE; }
291opaque { return OPAQUE; }
Reid Spencera54b7cb2007-01-12 07:05:14 +0000292{IntegerType} { uint64_t NumBits = atoull(yytext+1);
293 if (NumBits < IntegerType::MIN_INT_BITS ||
294 NumBits > IntegerType::MAX_INT_BITS)
295 GenerateError("Bitwidth for integer type out of range!");
296 const Type* Ty = IntegerType::get(NumBits);
297 RET_TY(Ty, INTTYPE);
298 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000299
300add { RET_TOK(BinaryOpVal, Add, ADD); }
301sub { RET_TOK(BinaryOpVal, Sub, SUB); }
302mul { RET_TOK(BinaryOpVal, Mul, MUL); }
Reid Spencer3ed469c2006-11-02 20:25:50 +0000303udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
304sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
305fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
Reid Spencer3ed469c2006-11-02 20:25:50 +0000306urem { RET_TOK(BinaryOpVal, URem, UREM); }
307srem { RET_TOK(BinaryOpVal, SRem, SREM); }
308frem { RET_TOK(BinaryOpVal, FRem, FREM); }
Reid Spencer832254e2007-02-02 02:16:23 +0000309shl { RET_TOK(BinaryOpVal, Shl, SHL); }
310lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
311ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000312and { RET_TOK(BinaryOpVal, And, AND); }
313or { RET_TOK(BinaryOpVal, Or , OR ); }
314xor { RET_TOK(BinaryOpVal, Xor, XOR); }
Reid Spencera132e042006-12-03 05:46:11 +0000315icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
316fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
Reid Spencer832254e2007-02-02 02:16:23 +0000317
Reid Spencer6e18b7d2006-12-03 06:59:29 +0000318eq { return EQ; }
319ne { return NE; }
320slt { return SLT; }
321sgt { return SGT; }
322sle { return SLE; }
323sge { return SGE; }
324ult { return ULT; }
325ugt { return UGT; }
326ule { return ULE; }
327uge { return UGE; }
328oeq { return OEQ; }
329one { return ONE; }
330olt { return OLT; }
331ogt { return OGT; }
332ole { return OLE; }
333oge { return OGE; }
334ord { return ORD; }
335uno { return UNO; }
336ueq { return UEQ; }
337une { return UNE; }
Chris Lattner32eecb02006-02-14 05:14:46 +0000338
339phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
340call { RET_TOK(OtherOpVal, Call, CALL); }
Reid Spencer3da59db2006-11-27 01:05:10 +0000341trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
342zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
343sext { RET_TOK(CastOpVal, SExt, SEXT); }
344fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
345fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
346uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
347sitofp { RET_TOK(CastOpVal, SIToFP, SITOFP); }
348fptoui { RET_TOK(CastOpVal, FPToUI, FPTOUI); }
349fptosi { RET_TOK(CastOpVal, FPToSI, FPTOSI); }
350inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
351ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
352bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000353select { RET_TOK(OtherOpVal, Select, SELECT); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000354va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
355ret { RET_TOK(TermOpVal, Ret, RET); }
356br { RET_TOK(TermOpVal, Br, BR); }
357switch { RET_TOK(TermOpVal, Switch, SWITCH); }
358invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
359unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
360unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); }
361
362malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
363alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); }
364free { RET_TOK(MemOpVal, Free, FREE); }
365load { RET_TOK(MemOpVal, Load, LOAD); }
366store { RET_TOK(MemOpVal, Store, STORE); }
367getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
368
369extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); }
370insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
Chris Lattnerd5efe842006-04-08 01:18:56 +0000371shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
Chris Lattner32eecb02006-02-14 05:14:46 +0000372
373
Reid Spencer41dff5e2007-01-26 08:05:27 +0000374{LocalVarName} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000375 llvmAsmlval.StrVal = new std::string(yytext+1); // Skip %
Reid Spencer41dff5e2007-01-26 08:05:27 +0000376 return LOCALVAR;
377 }
378{GlobalVarName} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000379 llvmAsmlval.StrVal = new std::string(yytext+1); // Skip @
Reid Spencer41dff5e2007-01-26 08:05:27 +0000380 return GLOBALVAR;
Chris Lattner32eecb02006-02-14 05:14:46 +0000381 }
382{Label} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000383 yytext[yyleng-1] = 0; // nuke colon
384 llvmAsmlval.StrVal = new std::string(yytext);
Chris Lattner32eecb02006-02-14 05:14:46 +0000385 return LABELSTR;
386 }
387{QuoteLabel} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000388 yytext[yyleng-2] = 0; // nuke colon, end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000389 const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000390 llvmAsmlval.StrVal =
391 new std::string(yytext+1, EndChar - yytext - 1);
Chris Lattner32eecb02006-02-14 05:14:46 +0000392 return LABELSTR;
393 }
394
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000395{StringConstant} { yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000396 const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000397 llvmAsmlval.StrVal =
398 new std::string(yytext+1, EndChar - yytext - 1);
Chris Lattner32eecb02006-02-14 05:14:46 +0000399 return STRINGCONSTANT;
400 }
Reid Spencer41dff5e2007-01-26 08:05:27 +0000401{AtStringConstant} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000402 yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000403 const char* EndChar =
404 UnEscapeLexed(yytext+2, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000405 llvmAsmlval.StrVal =
406 new std::string(yytext+2, EndChar - yytext - 2);
Reid Spencer41dff5e2007-01-26 08:05:27 +0000407 return ATSTRINGCONSTANT;
408 }
Reid Spencered951ea2007-05-19 07:22:10 +0000409{PctStringConstant} {
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000410 yytext[yyleng-1] = 0; // nuke end quote
Reid Spencere2aa9612007-05-22 19:08:16 +0000411 const char* EndChar =
412 UnEscapeLexed(yytext+2, yytext+yyleng);
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000413 llvmAsmlval.StrVal =
414 new std::string(yytext+2, EndChar - yytext - 2);
Reid Spencered951ea2007-05-19 07:22:10 +0000415 return PCTSTRINGCONSTANT;
416 }
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000417{PInteger} {
418 uint32_t numBits = ((yyleng * 64) / 19) + 1;
419 APInt Tmp(numBits, yytext, yyleng, 10);
Reid Spencer38c91a92007-02-28 02:24:54 +0000420 uint32_t activeBits = Tmp.getActiveBits();
421 if (activeBits > 0 && activeBits < numBits)
422 Tmp.trunc(activeBits);
423 if (Tmp.getBitWidth() > 64) {
424 llvmAsmlval.APIntVal = new APInt(Tmp);
425 return EUAPINTVAL;
426 } else {
427 llvmAsmlval.UInt64Val = Tmp.getZExtValue();
428 return EUINT64VAL;
429 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000430 }
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000431{NInteger} {
432 uint32_t numBits = (((yyleng-1) * 64) / 19) + 2;
433 APInt Tmp(numBits, yytext, yyleng, 10);
Reid Spencer38c91a92007-02-28 02:24:54 +0000434 uint32_t minBits = Tmp.getMinSignedBits();
435 if (minBits > 0 && minBits < numBits)
436 Tmp.trunc(minBits);
437 if (Tmp.getBitWidth() > 64) {
438 llvmAsmlval.APIntVal = new APInt(Tmp);
439 return ESAPINTVAL;
440 } else {
441 llvmAsmlval.SInt64Val = Tmp.getSExtValue();
442 return ESINT64VAL;
443 }
444 }
445
Reid Spencer0a8a16b2007-05-22 18:52:55 +0000446{HexIntConstant} { int len = yyleng - 3;
Reid Spencer38c91a92007-02-28 02:24:54 +0000447 uint32_t bits = len * 4;
448 APInt Tmp(bits, yytext+3, len, 16);
449 uint32_t activeBits = Tmp.getActiveBits();
450 if (activeBits > 0 && activeBits < bits)
451 Tmp.trunc(activeBits);
452 if (Tmp.getBitWidth() > 64) {
453 llvmAsmlval.APIntVal = new APInt(Tmp);
454 return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
455 } else if (yytext[0] == 's') {
456 llvmAsmlval.SInt64Val = Tmp.getSExtValue();
457 return ESINT64VAL;
458 } else {
459 llvmAsmlval.UInt64Val = Tmp.getZExtValue();
460 return EUINT64VAL;
461 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000462 }
463
Reid Spencer41dff5e2007-01-26 08:05:27 +0000464{LocalVarID} {
Chris Lattner32eecb02006-02-14 05:14:46 +0000465 uint64_t Val = atoull(yytext+1);
466 if ((unsigned)Val != Val)
Reid Spencer61c83e02006-08-18 08:43:06 +0000467 GenerateError("Invalid value number (too large)!");
Chris Lattner32eecb02006-02-14 05:14:46 +0000468 llvmAsmlval.UIntVal = unsigned(Val);
Reid Spencer41dff5e2007-01-26 08:05:27 +0000469 return LOCALVAL_ID;
Chris Lattner32eecb02006-02-14 05:14:46 +0000470 }
Reid Spencer41dff5e2007-01-26 08:05:27 +0000471{GlobalVarID} {
472 uint64_t Val = atoull(yytext+1);
473 if ((unsigned)Val != Val)
474 GenerateError("Invalid value number (too large)!");
475 llvmAsmlval.UIntVal = unsigned(Val);
476 return GLOBALVAL_ID;
Chris Lattner32eecb02006-02-14 05:14:46 +0000477 }
478
Dale Johannesen43421b32007-09-06 18:13:44 +0000479{FPConstant} { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
480{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext));
481 return FPVAL;
482 }
Dale Johannesenc72cd7e2007-09-11 18:33:39 +0000483{HexFP80Constant} { uint64_t Pair[2];
484 HexToIntPair(yytext, Pair);
485 llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
486 return FPVAL;
487 }
488{HexFP128Constant} { uint64_t Pair[2];
489 HexToIntPair(yytext, Pair);
490 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
491 return FPVAL;
492 }
493{HexPPC128Constant} { uint64_t Pair[2];
494 HexToIntPair(yytext, Pair);
495 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
496 return FPVAL;
497 }
Chris Lattner32eecb02006-02-14 05:14:46 +0000498
499<<EOF>> {
500 /* Make sure to free the internal buffers for flex when we are
501 * done reading our input!
502 */
503 yy_delete_buffer(YY_CURRENT_BUFFER);
504 return EOF;
505 }
506
507[ \r\t\n] { /* Ignore whitespace */ }
508. { return yytext[0]; }
509
510%%