blob: 8ffca760fde2a4fc85f3945d15e47b10cdd2d4d2 [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
29#include "ParserInternals.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) \
51 Upgradelval.Type.newTy = new std::string(NewTY); \
52 Upgradelval.Type.oldTy = OldTY; \
Reid Spencer78720742006-12-02 20:21:22 +000053 Upgradelval.Type.elemTy = VoidTy; \
Reid Spencere7c3c602006-11-30 06:36:44 +000054 return sym
55
56#define YY_NEVER_INTERACTIVE 1
57%}
58
59
60
61/* Comments start with a ; and go till end of line */
62Comment ;.*
63
64/* Variable(Value) identifiers start with a % sign */
65VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
66
67/* Label identifiers end with a colon */
68Label [-a-zA-Z$._0-9]+:
69QuoteLabel \"[^\"]+\":
70
71/* Quoted names can contain any character except " and \ */
72StringConstant \"[^\"]*\"
73
74
75/* [PN]Integer: match positive and negative literal integer values that
76 * are preceeded by a '%' character. These represent unnamed variable slots.
77 */
78EPInteger %[0-9]+
79ENInteger %-[0-9]+
80
81
82/* E[PN]Integer: match positive and negative literal integer values */
83PInteger [0-9]+
84NInteger -[0-9]+
85
86/* FPConstant - A Floating point constant.
87 */
88FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
89
90/* HexFPConstant - Floating point constant represented in IEEE format as a
91 * hexadecimal number for when exponential notation is not precise enough.
92 */
93HexFPConstant 0x[0-9A-Fa-f]+
94
95/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
96 * it to deal with 64 bit numbers.
97 */
98HexIntConstant [us]0x[0-9A-Fa-f]+
99%%
100
101{Comment} { /* Ignore comments for now */ }
102
103begin { RET_TOK( BEGINTOK); }
104end { RET_TOK( ENDTOK); }
105true { RET_TOK( TRUETOK); }
106false { RET_TOK( FALSETOK); }
107declare { RET_TOK( DECLARE); }
108global { RET_TOK( GLOBAL); }
109constant { RET_TOK( CONSTANT); }
110internal { RET_TOK( INTERNAL); }
111linkonce { RET_TOK( LINKONCE); }
112weak { RET_TOK( WEAK); }
113appending { RET_TOK( APPENDING); }
114dllimport { RET_TOK( DLLIMPORT); }
115dllexport { RET_TOK( DLLEXPORT); }
116extern_weak { RET_TOK( EXTERN_WEAK); }
117external { RET_TOK( EXTERNAL); }
Reid Spencer78720742006-12-02 20:21:22 +0000118uninitialized { RET_TOK( UNINITIALIZED); } // alias for external
Reid Spencere7c3c602006-11-30 06:36:44 +0000119implementation { RET_TOK( IMPLEMENTATION); }
120zeroinitializer { RET_TOK( ZEROINITIALIZER); }
121\.\.\. { RET_TOK( DOTDOTDOT); }
122undef { RET_TOK( UNDEF); }
123null { RET_TOK( NULL_TOK); }
124to { RET_TOK( TO); }
125tail { RET_TOK( TAIL); }
126target { RET_TOK( TARGET); }
127triple { RET_TOK( TRIPLE); }
128deplibs { RET_TOK( DEPLIBS); }
129endian { RET_TOK( ENDIAN); }
130pointersize { RET_TOK( POINTERSIZE); }
131datalayout { RET_TOK( DATALAYOUT); }
132little { RET_TOK( LITTLE); }
133big { RET_TOK( BIG); }
134volatile { RET_TOK( VOLATILE); }
135align { RET_TOK( ALIGN); }
136section { RET_TOK( SECTION); }
137module { RET_TOK( MODULE); }
138asm { RET_TOK( ASM_TOK); }
139sideeffect { RET_TOK( SIDEEFFECT); }
140
141cc { RET_TOK( CC_TOK); }
142ccc { RET_TOK( CCC_TOK); }
143csretcc { RET_TOK( CSRETCC_TOK); }
144fastcc { RET_TOK( FASTCC_TOK); }
145coldcc { RET_TOK( COLDCC_TOK); }
146x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
147x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
148
Reid Spencere77e35e2006-12-01 20:26:20 +0000149void { RET_TY(VOID,VoidTy,"void",false); }
150bool { RET_TY(BOOL,BoolTy,"bool",false); }
Reid Spencer71d2ec92006-12-31 06:02:26 +0000151sbyte { RET_TY(SBYTE,SByteTy,"i8",true); }
152ubyte { RET_TY(UBYTE,UByteTy,"i8",false); }
153short { RET_TY(SHORT,ShortTy,"i16",true); }
154ushort { RET_TY(USHORT,UShortTy,"i16",false); }
155int { RET_TY(INT,IntTy,"i32",true); }
156uint { RET_TY(UINT,UIntTy,"i32",false); }
157long { RET_TY(LONG,LongTy,"i64",true); }
158ulong { RET_TY(ULONG,ULongTy,"i64",false); }
159i8 { RET_TY(UBYTE,UByteTy,"i8",false); }
160i16 { RET_TY(USHORT,UShortTy,"i16",false); }
161i32 { RET_TY(UINT,UIntTy,"i32",false); }
162i64 { RET_TY(ULONG,ULongTy,"i64",false); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000163float { RET_TY(FLOAT,FloatTy,"float",false); }
164double { RET_TY(DOUBLE,DoubleTy,"double",false); }
165label { RET_TY(LABEL,LabelTy,"label",false); }
Reid Spencera50d5962006-12-02 04:11:07 +0000166opaque { RET_TOK(OPAQUE); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000167type { RET_TOK(TYPE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000168
169add { RET_TOK( ADD); }
170sub { RET_TOK( SUB); }
171mul { RET_TOK( MUL); }
Reid Spencer78720742006-12-02 20:21:22 +0000172div { RET_TOK( DIV); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000173udiv { RET_TOK( UDIV); }
174sdiv { RET_TOK( SDIV); }
175fdiv { RET_TOK( FDIV); }
Reid Spencer78720742006-12-02 20:21:22 +0000176rem { RET_TOK( REM); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000177urem { RET_TOK( UREM); }
178srem { RET_TOK( SREM); }
179frem { RET_TOK( FREM); }
180and { RET_TOK( AND); }
181or { RET_TOK( OR); }
182xor { RET_TOK( XOR); }
183setne { RET_TOK( SETNE); }
184seteq { RET_TOK( SETEQ); }
185setlt { RET_TOK( SETLT); }
186setgt { RET_TOK( SETGT); }
187setle { RET_TOK( SETLE); }
188setge { RET_TOK( SETGE); }
Reid Spencer229e9362006-12-02 22:14:11 +0000189icmp { RET_TOK(ICMP); }
190fcmp { RET_TOK(FCMP); }
191eq { RET_TOK(EQ); }
192ne { RET_TOK(NE); }
193slt { RET_TOK(SLT); }
194sgt { RET_TOK(SGT); }
195sle { RET_TOK(SLE); }
196sge { RET_TOK(SGE); }
197oeq { RET_TOK(OEQ); }
198one { RET_TOK(ONE); }
199olt { RET_TOK(OLT); }
200ogt { RET_TOK(OGT); }
201ole { RET_TOK(OLE); }
202oge { RET_TOK(OGE); }
203ord { RET_TOK(ORD); }
204uno { RET_TOK(UNO); }
205ueq { RET_TOK(UEQ); }
206une { RET_TOK(UNE); }
207ult { RET_TOK(ULT); }
208ugt { RET_TOK(UGT); }
209ule { RET_TOK(ULE); }
210uge { RET_TOK(UGE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000211
212phi { RET_TOK( PHI_TOK); }
213call { RET_TOK( CALL); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000214cast { RET_TOK( CAST); }
Reid Spencerfcb5df82006-12-01 22:34:43 +0000215trunc { RET_TOK( TRUNC); }
216zext { RET_TOK( ZEXT); }
217sext { RET_TOK( SEXT); }
218fptrunc { RET_TOK( FPTRUNC); }
219fpext { RET_TOK( FPEXT); }
220fptoui { RET_TOK( FPTOUI); }
221fptosi { RET_TOK( FPTOSI); }
222uitofp { RET_TOK( UITOFP); }
223sitofp { RET_TOK( SITOFP); }
224ptrtoint { RET_TOK( PTRTOINT); }
225inttoptr { RET_TOK( INTTOPTR); }
226bitcast { RET_TOK( BITCAST); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000227select { RET_TOK( SELECT); }
228shl { RET_TOK( SHL); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000229shr { RET_TOK( SHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000230ashr { RET_TOK( ASHR); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000231lshr { RET_TOK( LSHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000232va_arg { RET_TOK( VAARG); }
233ret { RET_TOK( RET); }
234br { RET_TOK( BR); }
235switch { RET_TOK( SWITCH); }
236invoke { RET_TOK( INVOKE); }
237unwind { RET_TOK( UNWIND); }
Reid Spencer78720742006-12-02 20:21:22 +0000238except { RET_TOK( EXCEPT); } // alias for unwind
Reid Spencere7c3c602006-11-30 06:36:44 +0000239unreachable { RET_TOK( UNREACHABLE); }
240
241malloc { RET_TOK( MALLOC); }
242alloca { RET_TOK( ALLOCA); }
243free { RET_TOK( FREE); }
244load { RET_TOK( LOAD); }
245store { RET_TOK( STORE); }
246getelementptr { RET_TOK( GETELEMENTPTR); }
247
248extractelement { RET_TOK( EXTRACTELEMENT); }
249insertelement { RET_TOK( INSERTELEMENT); }
250shufflevector { RET_TOK( SHUFFLEVECTOR); }
251
252
253{VarID} { RET_TOK( VAR_ID); }
254{Label} { RET_TOK( LABELSTR); }
255{QuoteLabel} { RET_TOK( LABELSTR); }
256{StringConstant} { RET_TOK( STRINGCONSTANT ); }
257{PInteger} { RET_TOK( EUINT64VAL ); }
258{NInteger} { RET_TOK( ESINT64VAL ); }
259{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
260{EPInteger} { RET_TOK( UINTVAL); }
261{ENInteger} { RET_TOK( SINTVAL); }
262{FPConstant} { RET_TOK( FPVAL); }
263{HexFPConstant} { RET_TOK( FPVAL); }
264<<EOF>> {
265 /* Make sure to free the internal buffers for flex when we are
266 * done reading our input!
267 */
268 yy_delete_buffer(YY_CURRENT_BUFFER);
269 return EOF;
270 }
271
272[ \r\t\n] { /* Ignore whitespace */ }
273. { return yytext[0]; }
274
275%%