For PR1113:
[oota-llvm.git] / tools / llvm-upgrade / UpgradeLexer.l
1 /*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the 
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file implements the flex scanner for LLVM 1.9 assembly languages files.
11 //
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 "UpgradeInternals.h"
30 #include "UpgradeParser.h"
31 #include <cctype>
32 #include <cstdlib>
33
34 #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
45 // Construct a token value for a non-obsolete token
46 #define RET_TOK(sym) \
47   Upgradelval.String = new std::string(yytext); \
48   return sym
49
50 #define RET_TY(sym,OldTY,NewTY,sign) \
51   Upgradelval.Ty = getType(NewTY, OldTY); \
52   return sym
53
54 #define YY_NEVER_INTERACTIVE 1
55 %}
56
57
58
59 /* Comments start with a ; and go till end of line */
60 Comment    ;.*
61
62 /* Variable(Value) identifiers start with a % sign */
63 VarID       %[-a-zA-Z$._][-a-zA-Z$._0-9]*
64
65 /* Label identifiers end with a colon */
66 Label       [-a-zA-Z$._0-9]+:
67 QuoteLabel \"[^\"]+\":
68
69 /* Quoted names can contain any character except " and \ */
70 StringConstant \"[^\"]*\"
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  */
76 EPInteger     %[0-9]+
77 ENInteger    %-[0-9]+
78
79
80 /* E[PN]Integer: match positive and negative literal integer values */
81 PInteger   [0-9]+
82 NInteger  -[0-9]+
83
84 /* FPConstant - A Floating point constant.
85  */
86 FPConstant [-+]?[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  */
91 HexFPConstant 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  */
96 HexIntConstant [us]0x[0-9A-Fa-f]+
97 %%
98
99 {Comment}       { /* Ignore comments for now */ }
100
101 begin           { RET_TOK( BEGINTOK); }
102 end             { RET_TOK( ENDTOK); }
103 true            { RET_TOK( TRUETOK);  }
104 false           { RET_TOK( FALSETOK); }
105 declare         { RET_TOK( DECLARE); }
106 global          { RET_TOK( GLOBAL); }
107 constant        { RET_TOK( CONSTANT); }
108 internal        { RET_TOK( INTERNAL); }
109 linkonce        { RET_TOK( LINKONCE); }
110 weak            { RET_TOK( WEAK); }
111 appending       { RET_TOK( APPENDING); }
112 dllimport       { RET_TOK( DLLIMPORT); }
113 dllexport       { RET_TOK( DLLEXPORT); }
114 extern_weak     { RET_TOK( EXTERN_WEAK); }
115 external        { RET_TOK( EXTERNAL); }
116 uninitialized   { RET_TOK( UNINITIALIZED); }  // alias for external
117 implementation  { RET_TOK( IMPLEMENTATION); }
118 zeroinitializer { RET_TOK( ZEROINITIALIZER); }
119 \.\.\.          { RET_TOK( DOTDOTDOT); }
120 undef           { RET_TOK( UNDEF); }
121 null            { RET_TOK( NULL_TOK); }
122 to              { RET_TOK( TO); }
123 tail            { RET_TOK( TAIL); }
124 target          { RET_TOK( TARGET); }
125 triple          { RET_TOK( TRIPLE); }
126 deplibs         { RET_TOK( DEPLIBS); }
127 endian          { RET_TOK( ENDIAN); }
128 pointersize     { RET_TOK( POINTERSIZE); }
129 datalayout      { RET_TOK( DATALAYOUT); }
130 little          { RET_TOK( LITTLE); }
131 big             { RET_TOK( BIG); }
132 volatile        { RET_TOK( VOLATILE); }
133 align           { RET_TOK( ALIGN);  }
134 section         { RET_TOK( SECTION); }
135 module          { RET_TOK( MODULE); }
136 asm             { RET_TOK( ASM_TOK); }
137 sideeffect      { RET_TOK( SIDEEFFECT); }
138
139 cc              { RET_TOK( CC_TOK); }
140 ccc             { RET_TOK( CCC_TOK); }
141 csretcc         { RET_TOK( CSRETCC_TOK); }
142 fastcc          { RET_TOK( FASTCC_TOK); }
143 coldcc          { RET_TOK( COLDCC_TOK); }
144 x86_stdcallcc   { RET_TOK( X86_STDCALLCC_TOK); }
145 x86_fastcallcc  { RET_TOK( X86_FASTCALLCC_TOK); }
146
147 void            { RET_TY(VOID,VoidTy,"void",false); }
148 bool            { RET_TY(BOOL,BoolTy,"i1",false); }
149 sbyte           { RET_TY(SBYTE,SByteTy,"i8",true); }
150 ubyte           { RET_TY(UBYTE,UByteTy,"i8",false); }
151 short           { RET_TY(SHORT,ShortTy,"i16",true); }
152 ushort          { RET_TY(USHORT,UShortTy,"i16",false); }
153 int             { RET_TY(INT,IntTy,"i32",true);   }
154 uint            { RET_TY(UINT,UIntTy,"i32",false);  }
155 long            { RET_TY(LONG,LongTy,"i64",true);  }
156 ulong           { RET_TY(ULONG,ULongTy,"i64",false); }
157 i8              { RET_TY(UBYTE,UByteTy,"i8",false); }
158 i16             { RET_TY(USHORT,UShortTy,"i16",false); }
159 i32             { RET_TY(UINT,UIntTy,"i32",false); }
160 i64             { RET_TY(ULONG,ULongTy,"i64",false); }
161 float           { RET_TY(FLOAT,FloatTy,"float",false); }
162 double          { RET_TY(DOUBLE,DoubleTy,"double",false); }
163 label           { RET_TY(LABEL,LabelTy,"label",false); }
164 opaque          { RET_TOK(OPAQUE); }
165 type            { RET_TOK(TYPE);   }
166
167 add             { RET_TOK( ADD); }
168 sub             { RET_TOK( SUB); }
169 mul             { RET_TOK( MUL); }
170 div             { RET_TOK( DIV); }
171 udiv            { RET_TOK( UDIV); }
172 sdiv            { RET_TOK( SDIV); }
173 fdiv            { RET_TOK( FDIV); }
174 rem             { RET_TOK( REM);  }
175 urem            { RET_TOK( UREM); }
176 srem            { RET_TOK( SREM); }
177 frem            { RET_TOK( FREM); }
178 and             { RET_TOK( AND); }
179 or              { RET_TOK( OR); }
180 xor             { RET_TOK( XOR); }
181 setne           { RET_TOK( SETNE); }
182 seteq           { RET_TOK( SETEQ); }
183 setlt           { RET_TOK( SETLT); }
184 setgt           { RET_TOK( SETGT); }
185 setle           { RET_TOK( SETLE); }
186 setge           { RET_TOK( SETGE); }
187 icmp            { RET_TOK(ICMP); }
188 fcmp            { RET_TOK(FCMP); }
189 eq              { RET_TOK(EQ); }
190 ne              { RET_TOK(NE); }
191 slt             { RET_TOK(SLT); }
192 sgt             { RET_TOK(SGT); }
193 sle             { RET_TOK(SLE); }
194 sge             { RET_TOK(SGE); }
195 oeq             { RET_TOK(OEQ); }
196 one             { RET_TOK(ONE); }
197 olt             { RET_TOK(OLT); }
198 ogt             { RET_TOK(OGT); }
199 ole             { RET_TOK(OLE); }
200 oge             { RET_TOK(OGE); }
201 ord             { RET_TOK(ORD); }
202 uno             { RET_TOK(UNO); }
203 ueq             { RET_TOK(UEQ); }
204 une             { RET_TOK(UNE); }
205 ult             { RET_TOK(ULT); }
206 ugt             { RET_TOK(UGT); }
207 ule             { RET_TOK(ULE); }
208 uge             { RET_TOK(UGE); }
209
210 phi             { RET_TOK( PHI_TOK); }
211 call            { RET_TOK( CALL); }
212 cast            { RET_TOK( CAST); }
213 trunc           { RET_TOK( TRUNC); }
214 zext            { RET_TOK( ZEXT); }
215 sext            { RET_TOK( SEXT); }
216 fptrunc         { RET_TOK( FPTRUNC); }
217 fpext           { RET_TOK( FPEXT); }
218 fptoui          { RET_TOK( FPTOUI); }
219 fptosi          { RET_TOK( FPTOSI); }
220 uitofp          { RET_TOK( UITOFP); }
221 sitofp          { RET_TOK( SITOFP); }
222 ptrtoint        { RET_TOK( PTRTOINT); }
223 inttoptr        { RET_TOK( INTTOPTR); }
224 bitcast         { RET_TOK( BITCAST); }
225 select          { RET_TOK( SELECT); }
226 shl             { RET_TOK( SHL); }
227 shr             { RET_TOK( SHR); }
228 ashr            { RET_TOK( ASHR); }
229 lshr            { RET_TOK( LSHR); }
230 va_arg          { RET_TOK( VAARG); }
231 ret             { RET_TOK( RET); }
232 br              { RET_TOK( BR); }
233 switch          { RET_TOK( SWITCH); }
234 invoke          { RET_TOK( INVOKE); }
235 unwind          { RET_TOK( UNWIND); }
236 except          { RET_TOK( EXCEPT); } // alias for unwind
237 unreachable     { RET_TOK( UNREACHABLE); }
238
239 malloc          { RET_TOK( MALLOC); }
240 alloca          { RET_TOK( ALLOCA); }
241 free            { RET_TOK( FREE); }
242 load            { RET_TOK( LOAD); }
243 store           { RET_TOK( STORE); }
244 getelementptr   { RET_TOK( GETELEMENTPTR); }
245
246 extractelement  { RET_TOK( EXTRACTELEMENT); }
247 insertelement   { RET_TOK( INSERTELEMENT); }
248 shufflevector   { 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 %%