blob: d58f4615488231765e49b598ef0a32b82cc73aab [file] [log] [blame]
Reid Spencer96839be2006-11-30 16:50:26 +00001/*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
Reid Spencere7c3c602006-11-30 06:36:44 +00002//
3// The LLVM Compiler Infrastructure
4//
Reid Spencer96839be2006-11-30 16:50:26 +00005// This file was developed by Reid Spencer and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
Reid Spencere7c3c602006-11-30 06:36:44 +00007//
8//===----------------------------------------------------------------------===//
9//
Reid Spencer96839be2006-11-30 16:50:26 +000010// This file implements the flex scanner for LLVM 1.9 assembly languages files.
Reid Spencere7c3c602006-11-30 06:36:44 +000011//
12//===----------------------------------------------------------------------===*/
13
14%option prefix="Upgrade"
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="UpgradeLexer.cpp"
23%option ecs
24%option noreject
25%option noyymore
26
27%{
28
Reid Spencer319a7302007-01-05 17:20:02 +000029#include "UpgradeInternals.h"
Reid Spencere7c3c602006-11-30 06:36:44 +000030#include "UpgradeParser.h"
31#include <cctype>
32#include <cstdlib>
33
Reid Spencer96839be2006-11-30 16:50:26 +000034#define YY_INPUT(buf,result,max_size) \
35{ \
36 if (LexInput->good() && !LexInput->eof()) { \
37 LexInput->read(buf,max_size); \
38 result = LexInput->gcount(); \
39 } else {\
40 result = YY_NULL; \
41 } \
42}
43
44
Reid Spencere7c3c602006-11-30 06:36:44 +000045// Construct a token value for a non-obsolete token
46#define RET_TOK(sym) \
Reid Spencere77e35e2006-12-01 20:26:20 +000047 Upgradelval.String = new std::string(yytext); \
48 return sym
49
50#define RET_TY(sym,OldTY,NewTY,sign) \
Reid Spencerb6673a92007-01-15 02:41:46 +000051 Upgradelval.Ty = getType(NewTY, OldTY); \
Reid Spencere7c3c602006-11-30 06:36:44 +000052 return sym
53
54#define YY_NEVER_INTERACTIVE 1
55%}
56
57
58
59/* Comments start with a ; and go till end of line */
60Comment ;.*
61
62/* Variable(Value) identifiers start with a % sign */
63VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
64
65/* Label identifiers end with a colon */
66Label [-a-zA-Z$._0-9]+:
67QuoteLabel \"[^\"]+\":
68
69/* Quoted names can contain any character except " and \ */
70StringConstant \"[^\"]*\"
71
72
73/* [PN]Integer: match positive and negative literal integer values that
74 * are preceeded by a '%' character. These represent unnamed variable slots.
75 */
76EPInteger %[0-9]+
77ENInteger %-[0-9]+
78
79
80/* E[PN]Integer: match positive and negative literal integer values */
81PInteger [0-9]+
82NInteger -[0-9]+
83
84/* FPConstant - A Floating point constant.
85 */
86FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
87
88/* HexFPConstant - Floating point constant represented in IEEE format as a
89 * hexadecimal number for when exponential notation is not precise enough.
90 */
91HexFPConstant 0x[0-9A-Fa-f]+
92
93/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
94 * it to deal with 64 bit numbers.
95 */
96HexIntConstant [us]0x[0-9A-Fa-f]+
97%%
98
99{Comment} { /* Ignore comments for now */ }
100
101begin { RET_TOK( BEGINTOK); }
102end { RET_TOK( ENDTOK); }
103true { RET_TOK( TRUETOK); }
104false { RET_TOK( FALSETOK); }
105declare { RET_TOK( DECLARE); }
106global { RET_TOK( GLOBAL); }
107constant { RET_TOK( CONSTANT); }
108internal { RET_TOK( INTERNAL); }
109linkonce { RET_TOK( LINKONCE); }
110weak { RET_TOK( WEAK); }
111appending { RET_TOK( APPENDING); }
112dllimport { RET_TOK( DLLIMPORT); }
113dllexport { RET_TOK( DLLEXPORT); }
114extern_weak { RET_TOK( EXTERN_WEAK); }
115external { RET_TOK( EXTERNAL); }
Reid Spencer78720742006-12-02 20:21:22 +0000116uninitialized { RET_TOK( UNINITIALIZED); } // alias for external
Reid Spencere7c3c602006-11-30 06:36:44 +0000117implementation { RET_TOK( IMPLEMENTATION); }
118zeroinitializer { RET_TOK( ZEROINITIALIZER); }
119\.\.\. { RET_TOK( DOTDOTDOT); }
120undef { RET_TOK( UNDEF); }
121null { RET_TOK( NULL_TOK); }
122to { RET_TOK( TO); }
123tail { RET_TOK( TAIL); }
124target { RET_TOK( TARGET); }
125triple { RET_TOK( TRIPLE); }
126deplibs { RET_TOK( DEPLIBS); }
127endian { RET_TOK( ENDIAN); }
128pointersize { RET_TOK( POINTERSIZE); }
129datalayout { RET_TOK( DATALAYOUT); }
130little { RET_TOK( LITTLE); }
131big { RET_TOK( BIG); }
132volatile { RET_TOK( VOLATILE); }
133align { RET_TOK( ALIGN); }
134section { RET_TOK( SECTION); }
135module { RET_TOK( MODULE); }
136asm { RET_TOK( ASM_TOK); }
137sideeffect { RET_TOK( SIDEEFFECT); }
138
139cc { RET_TOK( CC_TOK); }
140ccc { RET_TOK( CCC_TOK); }
141csretcc { RET_TOK( CSRETCC_TOK); }
142fastcc { RET_TOK( FASTCC_TOK); }
143coldcc { RET_TOK( COLDCC_TOK); }
144x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
145x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
146
Reid Spencere77e35e2006-12-01 20:26:20 +0000147void { RET_TY(VOID,VoidTy,"void",false); }
Reid Spencer195a32e52007-01-13 04:40:16 +0000148bool { RET_TY(BOOL,BoolTy,"i1",false); }
Reid Spencer71d2ec92006-12-31 06:02:26 +0000149sbyte { RET_TY(SBYTE,SByteTy,"i8",true); }
150ubyte { RET_TY(UBYTE,UByteTy,"i8",false); }
151short { RET_TY(SHORT,ShortTy,"i16",true); }
152ushort { RET_TY(USHORT,UShortTy,"i16",false); }
153int { RET_TY(INT,IntTy,"i32",true); }
154uint { RET_TY(UINT,UIntTy,"i32",false); }
155long { RET_TY(LONG,LongTy,"i64",true); }
156ulong { RET_TY(ULONG,ULongTy,"i64",false); }
157i8 { RET_TY(UBYTE,UByteTy,"i8",false); }
158i16 { RET_TY(USHORT,UShortTy,"i16",false); }
159i32 { RET_TY(UINT,UIntTy,"i32",false); }
160i64 { RET_TY(ULONG,ULongTy,"i64",false); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000161float { RET_TY(FLOAT,FloatTy,"float",false); }
162double { RET_TY(DOUBLE,DoubleTy,"double",false); }
163label { RET_TY(LABEL,LabelTy,"label",false); }
Reid Spencera50d5962006-12-02 04:11:07 +0000164opaque { RET_TOK(OPAQUE); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000165type { RET_TOK(TYPE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000166
167add { RET_TOK( ADD); }
168sub { RET_TOK( SUB); }
169mul { RET_TOK( MUL); }
Reid Spencer78720742006-12-02 20:21:22 +0000170div { RET_TOK( DIV); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000171udiv { RET_TOK( UDIV); }
172sdiv { RET_TOK( SDIV); }
173fdiv { RET_TOK( FDIV); }
Reid Spencer78720742006-12-02 20:21:22 +0000174rem { RET_TOK( REM); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000175urem { RET_TOK( UREM); }
176srem { RET_TOK( SREM); }
177frem { RET_TOK( FREM); }
178and { RET_TOK( AND); }
179or { RET_TOK( OR); }
180xor { RET_TOK( XOR); }
181setne { RET_TOK( SETNE); }
182seteq { RET_TOK( SETEQ); }
183setlt { RET_TOK( SETLT); }
184setgt { RET_TOK( SETGT); }
185setle { RET_TOK( SETLE); }
186setge { RET_TOK( SETGE); }
Reid Spencer229e9362006-12-02 22:14:11 +0000187icmp { RET_TOK(ICMP); }
188fcmp { RET_TOK(FCMP); }
189eq { RET_TOK(EQ); }
190ne { RET_TOK(NE); }
191slt { RET_TOK(SLT); }
192sgt { RET_TOK(SGT); }
193sle { RET_TOK(SLE); }
194sge { RET_TOK(SGE); }
195oeq { RET_TOK(OEQ); }
196one { RET_TOK(ONE); }
197olt { RET_TOK(OLT); }
198ogt { RET_TOK(OGT); }
199ole { RET_TOK(OLE); }
200oge { RET_TOK(OGE); }
201ord { RET_TOK(ORD); }
202uno { RET_TOK(UNO); }
203ueq { RET_TOK(UEQ); }
204une { RET_TOK(UNE); }
205ult { RET_TOK(ULT); }
206ugt { RET_TOK(UGT); }
207ule { RET_TOK(ULE); }
208uge { RET_TOK(UGE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000209
210phi { RET_TOK( PHI_TOK); }
211call { RET_TOK( CALL); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000212cast { RET_TOK( CAST); }
Reid Spencerfcb5df82006-12-01 22:34:43 +0000213trunc { RET_TOK( TRUNC); }
214zext { RET_TOK( ZEXT); }
215sext { RET_TOK( SEXT); }
216fptrunc { RET_TOK( FPTRUNC); }
217fpext { RET_TOK( FPEXT); }
218fptoui { RET_TOK( FPTOUI); }
219fptosi { RET_TOK( FPTOSI); }
220uitofp { RET_TOK( UITOFP); }
221sitofp { RET_TOK( SITOFP); }
222ptrtoint { RET_TOK( PTRTOINT); }
223inttoptr { RET_TOK( INTTOPTR); }
224bitcast { RET_TOK( BITCAST); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000225select { RET_TOK( SELECT); }
226shl { RET_TOK( SHL); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000227shr { RET_TOK( SHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000228ashr { RET_TOK( ASHR); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000229lshr { RET_TOK( LSHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000230va_arg { RET_TOK( VAARG); }
231ret { RET_TOK( RET); }
232br { RET_TOK( BR); }
233switch { RET_TOK( SWITCH); }
234invoke { RET_TOK( INVOKE); }
235unwind { RET_TOK( UNWIND); }
Reid Spencer78720742006-12-02 20:21:22 +0000236except { RET_TOK( EXCEPT); } // alias for unwind
Reid Spencere7c3c602006-11-30 06:36:44 +0000237unreachable { RET_TOK( UNREACHABLE); }
238
239malloc { RET_TOK( MALLOC); }
240alloca { RET_TOK( ALLOCA); }
241free { RET_TOK( FREE); }
242load { RET_TOK( LOAD); }
243store { RET_TOK( STORE); }
244getelementptr { RET_TOK( GETELEMENTPTR); }
245
246extractelement { RET_TOK( EXTRACTELEMENT); }
247insertelement { RET_TOK( INSERTELEMENT); }
248shufflevector { RET_TOK( SHUFFLEVECTOR); }
249
250
251{VarID} { RET_TOK( VAR_ID); }
252{Label} { RET_TOK( LABELSTR); }
253{QuoteLabel} { RET_TOK( LABELSTR); }
254{StringConstant} { RET_TOK( STRINGCONSTANT ); }
255{PInteger} { RET_TOK( EUINT64VAL ); }
256{NInteger} { RET_TOK( ESINT64VAL ); }
257{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
258{EPInteger} { RET_TOK( UINTVAL); }
259{ENInteger} { RET_TOK( SINTVAL); }
260{FPConstant} { RET_TOK( FPVAL); }
261{HexFPConstant} { RET_TOK( FPVAL); }
262<<EOF>> {
263 /* Make sure to free the internal buffers for flex when we are
264 * done reading our input!
265 */
266 yy_delete_buffer(YY_CURRENT_BUFFER);
267 return EOF;
268 }
269
270[ \r\t\n] { /* Ignore whitespace */ }
271. { return yytext[0]; }
272
273%%