Support several new upgrades:
[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 "ParserInternals.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.Type.newTy = new std::string(NewTY); \
52   Upgradelval.Type.oldTy = OldTY; \
53   Upgradelval.Type.elemTy = VoidTy; \
54   return sym
55
56 #define YY_NEVER_INTERACTIVE 1
57 %}
58
59
60
61 /* Comments start with a ; and go till end of line */
62 Comment    ;.*
63
64 /* Variable(Value) identifiers start with a % sign */
65 VarID       %[-a-zA-Z$._][-a-zA-Z$._0-9]*
66
67 /* Label identifiers end with a colon */
68 Label       [-a-zA-Z$._0-9]+:
69 QuoteLabel \"[^\"]+\":
70
71 /* Quoted names can contain any character except " and \ */
72 StringConstant \"[^\"]*\"
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  */
78 EPInteger     %[0-9]+
79 ENInteger    %-[0-9]+
80
81
82 /* E[PN]Integer: match positive and negative literal integer values */
83 PInteger   [0-9]+
84 NInteger  -[0-9]+
85
86 /* FPConstant - A Floating point constant.
87  */
88 FPConstant [-+]?[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  */
93 HexFPConstant 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  */
98 HexIntConstant [us]0x[0-9A-Fa-f]+
99 %%
100
101 {Comment}       { /* Ignore comments for now */ }
102
103 begin           { RET_TOK( BEGINTOK); }
104 end             { RET_TOK( ENDTOK); }
105 true            { RET_TOK( TRUETOK);  }
106 false           { RET_TOK( FALSETOK); }
107 declare         { RET_TOK( DECLARE); }
108 global          { RET_TOK( GLOBAL); }
109 constant        { RET_TOK( CONSTANT); }
110 internal        { RET_TOK( INTERNAL); }
111 linkonce        { RET_TOK( LINKONCE); }
112 weak            { RET_TOK( WEAK); }
113 appending       { RET_TOK( APPENDING); }
114 dllimport       { RET_TOK( DLLIMPORT); }
115 dllexport       { RET_TOK( DLLEXPORT); }
116 extern_weak     { RET_TOK( EXTERN_WEAK); }
117 external        { RET_TOK( EXTERNAL); }
118 uninitialized   { RET_TOK( UNINITIALIZED); }  // alias for external
119 implementation  { RET_TOK( IMPLEMENTATION); }
120 zeroinitializer { RET_TOK( ZEROINITIALIZER); }
121 \.\.\.          { RET_TOK( DOTDOTDOT); }
122 undef           { RET_TOK( UNDEF); }
123 null            { RET_TOK( NULL_TOK); }
124 to              { RET_TOK( TO); }
125 tail            { RET_TOK( TAIL); }
126 target          { RET_TOK( TARGET); }
127 triple          { RET_TOK( TRIPLE); }
128 deplibs         { RET_TOK( DEPLIBS); }
129 endian          { RET_TOK( ENDIAN); }
130 pointersize     { RET_TOK( POINTERSIZE); }
131 datalayout      { RET_TOK( DATALAYOUT); }
132 little          { RET_TOK( LITTLE); }
133 big             { RET_TOK( BIG); }
134 volatile        { RET_TOK( VOLATILE); }
135 align           { RET_TOK( ALIGN);  }
136 section         { RET_TOK( SECTION); }
137 module          { RET_TOK( MODULE); }
138 asm             { RET_TOK( ASM_TOK); }
139 sideeffect      { RET_TOK( SIDEEFFECT); }
140
141 cc              { RET_TOK( CC_TOK); }
142 ccc             { RET_TOK( CCC_TOK); }
143 csretcc         { RET_TOK( CSRETCC_TOK); }
144 fastcc          { RET_TOK( FASTCC_TOK); }
145 coldcc          { RET_TOK( COLDCC_TOK); }
146 x86_stdcallcc   { RET_TOK( X86_STDCALLCC_TOK); }
147 x86_fastcallcc  { RET_TOK( X86_FASTCALLCC_TOK); }
148
149 void            { RET_TY(VOID,VoidTy,"void",false); }
150 bool            { RET_TY(BOOL,BoolTy,"bool",false); }
151 sbyte           { RET_TY(SBYTE,SByteTy,"sbyte",true); }
152 ubyte           { RET_TY(UBYTE,UByteTy,"ubyte",false); }
153 short           { RET_TY(SHORT,ShortTy,"short",true); }
154 ushort          { RET_TY(USHORT,UShortTy,"ushort",false); }
155 int             { RET_TY(INT,IntTy,"int",true);   }
156 uint            { RET_TY(UINT,UIntTy,"uint",false);  }
157 long            { RET_TY(LONG,LongTy,"long",true);  }
158 ulong           { RET_TY(ULONG,ULongTy,"ulong",false); }
159 float           { RET_TY(FLOAT,FloatTy,"float",false); }
160 double          { RET_TY(DOUBLE,DoubleTy,"double",false); }
161 label           { RET_TY(LABEL,LabelTy,"label",false); }
162 opaque          { RET_TOK(OPAQUE); }
163 type            { RET_TOK(TYPE);   }
164
165 add             { RET_TOK( ADD); }
166 sub             { RET_TOK( SUB); }
167 mul             { RET_TOK( MUL); }
168 div             { RET_TOK( DIV); }
169 udiv            { RET_TOK( UDIV); }
170 sdiv            { RET_TOK( SDIV); }
171 fdiv            { RET_TOK( FDIV); }
172 rem             { RET_TOK( REM);  }
173 urem            { RET_TOK( UREM); }
174 srem            { RET_TOK( SREM); }
175 frem            { RET_TOK( FREM); }
176 and             { RET_TOK( AND); }
177 or              { RET_TOK( OR); }
178 xor             { RET_TOK( XOR); }
179 setne           { RET_TOK( SETNE); }
180 seteq           { RET_TOK( SETEQ); }
181 setlt           { RET_TOK( SETLT); }
182 setgt           { RET_TOK( SETGT); }
183 setle           { RET_TOK( SETLE); }
184 setge           { RET_TOK( SETGE); }
185
186 phi             { RET_TOK( PHI_TOK); }
187 call            { RET_TOK( CALL); }
188 cast            { RET_TOK( CAST); }
189 trunc           { RET_TOK( TRUNC); }
190 zext            { RET_TOK( ZEXT); }
191 sext            { RET_TOK( SEXT); }
192 fptrunc         { RET_TOK( FPTRUNC); }
193 fpext           { RET_TOK( FPEXT); }
194 fptoui          { RET_TOK( FPTOUI); }
195 fptosi          { RET_TOK( FPTOSI); }
196 uitofp          { RET_TOK( UITOFP); }
197 sitofp          { RET_TOK( SITOFP); }
198 ptrtoint        { RET_TOK( PTRTOINT); }
199 inttoptr        { RET_TOK( INTTOPTR); }
200 bitcast         { RET_TOK( BITCAST); }
201 select          { RET_TOK( SELECT); }
202 shl             { RET_TOK( SHL); }
203 shr             { RET_TOK( SHR); }
204 ashr            { RET_TOK( ASHR); }
205 lshr            { RET_TOK( LSHR); }
206 va_arg          { RET_TOK( VAARG); }
207 ret             { RET_TOK( RET); }
208 br              { RET_TOK( BR); }
209 switch          { RET_TOK( SWITCH); }
210 invoke          { RET_TOK( INVOKE); }
211 unwind          { RET_TOK( UNWIND); }
212 except          { RET_TOK( EXCEPT); } // alias for unwind
213 unreachable     { RET_TOK( UNREACHABLE); }
214
215 malloc          { RET_TOK( MALLOC); }
216 alloca          { RET_TOK( ALLOCA); }
217 free            { RET_TOK( FREE); }
218 load            { RET_TOK( LOAD); }
219 store           { RET_TOK( STORE); }
220 getelementptr   { RET_TOK( GETELEMENTPTR); }
221
222 extractelement  { RET_TOK( EXTRACTELEMENT); }
223 insertelement   { RET_TOK( INSERTELEMENT); }
224 shufflevector   { RET_TOK( SHUFFLEVECTOR); }
225
226
227 {VarID}          { RET_TOK( VAR_ID); }
228 {Label}          { RET_TOK( LABELSTR); }
229 {QuoteLabel}     { RET_TOK( LABELSTR); }
230 {StringConstant} { RET_TOK( STRINGCONSTANT ); }
231 {PInteger}       { RET_TOK( EUINT64VAL ); }
232 {NInteger}       { RET_TOK( ESINT64VAL ); }
233 {HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
234 {EPInteger}      { RET_TOK( UINTVAL); }
235 {ENInteger}      { RET_TOK( SINTVAL); }
236 {FPConstant}     { RET_TOK( FPVAL); }
237 {HexFPConstant}  { RET_TOK( FPVAL); }
238 <<EOF>>          {
239                   /* Make sure to free the internal buffers for flex when we are
240                    * done reading our input!
241                    */
242                   yy_delete_buffer(YY_CURRENT_BUFFER);
243                   return EOF;
244                 }
245
246 [ \r\t\n]       { /* Ignore whitespace */ }
247 .               { return yytext[0]; }
248
249 %%