For PR950:
[oota-llvm.git] / tools / llvm-upgrade / UpgradeLexer.l.cvs
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,"i8",true); }
152 ubyte           { RET_TY(UBYTE,UByteTy,"i8",false); }
153 short           { RET_TY(SHORT,ShortTy,"i16",true); }
154 ushort          { RET_TY(USHORT,UShortTy,"i16",false); }
155 int             { RET_TY(INT,IntTy,"i32",true);   }
156 uint            { RET_TY(UINT,UIntTy,"i32",false);  }
157 long            { RET_TY(LONG,LongTy,"i64",true);  }
158 ulong           { RET_TY(ULONG,ULongTy,"i64",false); }
159 i8              { RET_TY(UBYTE,UByteTy,"i8",false); }
160 i16             { RET_TY(USHORT,UShortTy,"i16",false); }
161 i32             { RET_TY(UINT,UIntTy,"i32",false); }
162 i64             { RET_TY(ULONG,ULongTy,"i64",false); }
163 float           { RET_TY(FLOAT,FloatTy,"float",false); }
164 double          { RET_TY(DOUBLE,DoubleTy,"double",false); }
165 label           { RET_TY(LABEL,LabelTy,"label",false); }
166 opaque          { RET_TOK(OPAQUE); }
167 type            { RET_TOK(TYPE);   }
168
169 add             { RET_TOK( ADD); }
170 sub             { RET_TOK( SUB); }
171 mul             { RET_TOK( MUL); }
172 div             { RET_TOK( DIV); }
173 udiv            { RET_TOK( UDIV); }
174 sdiv            { RET_TOK( SDIV); }
175 fdiv            { RET_TOK( FDIV); }
176 rem             { RET_TOK( REM);  }
177 urem            { RET_TOK( UREM); }
178 srem            { RET_TOK( SREM); }
179 frem            { RET_TOK( FREM); }
180 and             { RET_TOK( AND); }
181 or              { RET_TOK( OR); }
182 xor             { RET_TOK( XOR); }
183 setne           { RET_TOK( SETNE); }
184 seteq           { RET_TOK( SETEQ); }
185 setlt           { RET_TOK( SETLT); }
186 setgt           { RET_TOK( SETGT); }
187 setle           { RET_TOK( SETLE); }
188 setge           { RET_TOK( SETGE); }
189 icmp            { RET_TOK(ICMP); }
190 fcmp            { RET_TOK(FCMP); }
191 eq              { RET_TOK(EQ); }
192 ne              { RET_TOK(NE); }
193 slt             { RET_TOK(SLT); }
194 sgt             { RET_TOK(SGT); }
195 sle             { RET_TOK(SLE); }
196 sge             { RET_TOK(SGE); }
197 oeq             { RET_TOK(OEQ); }
198 one             { RET_TOK(ONE); }
199 olt             { RET_TOK(OLT); }
200 ogt             { RET_TOK(OGT); }
201 ole             { RET_TOK(OLE); }
202 oge             { RET_TOK(OGE); }
203 ord             { RET_TOK(ORD); }
204 uno             { RET_TOK(UNO); }
205 ueq             { RET_TOK(UEQ); }
206 une             { RET_TOK(UNE); }
207 ult             { RET_TOK(ULT); }
208 ugt             { RET_TOK(UGT); }
209 ule             { RET_TOK(ULE); }
210 uge             { RET_TOK(UGE); }
211
212 phi             { RET_TOK( PHI_TOK); }
213 call            { RET_TOK( CALL); }
214 cast            { RET_TOK( CAST); }
215 trunc           { RET_TOK( TRUNC); }
216 zext            { RET_TOK( ZEXT); }
217 sext            { RET_TOK( SEXT); }
218 fptrunc         { RET_TOK( FPTRUNC); }
219 fpext           { RET_TOK( FPEXT); }
220 fptoui          { RET_TOK( FPTOUI); }
221 fptosi          { RET_TOK( FPTOSI); }
222 uitofp          { RET_TOK( UITOFP); }
223 sitofp          { RET_TOK( SITOFP); }
224 ptrtoint        { RET_TOK( PTRTOINT); }
225 inttoptr        { RET_TOK( INTTOPTR); }
226 bitcast         { RET_TOK( BITCAST); }
227 select          { RET_TOK( SELECT); }
228 shl             { RET_TOK( SHL); }
229 shr             { RET_TOK( SHR); }
230 ashr            { RET_TOK( ASHR); }
231 lshr            { RET_TOK( LSHR); }
232 va_arg          { RET_TOK( VAARG); }
233 ret             { RET_TOK( RET); }
234 br              { RET_TOK( BR); }
235 switch          { RET_TOK( SWITCH); }
236 invoke          { RET_TOK( INVOKE); }
237 unwind          { RET_TOK( UNWIND); }
238 except          { RET_TOK( EXCEPT); } // alias for unwind
239 unreachable     { RET_TOK( UNREACHABLE); }
240
241 malloc          { RET_TOK( MALLOC); }
242 alloca          { RET_TOK( ALLOCA); }
243 free            { RET_TOK( FREE); }
244 load            { RET_TOK( LOAD); }
245 store           { RET_TOK( STORE); }
246 getelementptr   { RET_TOK( GETELEMENTPTR); }
247
248 extractelement  { RET_TOK( EXTRACTELEMENT); }
249 insertelement   { RET_TOK( INSERTELEMENT); }
250 shufflevector   { 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 %%