1 /*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the flex scanner for LLVM 1.9 assembly languages files.
12 //===----------------------------------------------------------------------===*/
14 %option prefix="Upgrade"
17 %option never-interactive
22 %option outfile="UpgradeLexer.cpp"
29 #include "ParserInternals.h"
30 #include "UpgradeParser.h"
34 #define YY_INPUT(buf,result,max_size) \
36 if (LexInput->good() && !LexInput->eof()) { \
37 LexInput->read(buf,max_size); \
38 result = LexInput->gcount(); \
45 // Construct a token value for a non-obsolete token
46 #define RET_TOK(sym) \
47 Upgradelval.String = new std::string(yytext); \
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; \
56 #define YY_NEVER_INTERACTIVE 1
61 /* Comments start with a ; and go till end of line */
64 /* Variable(Value) identifiers start with a % sign */
65 VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
67 /* Label identifiers end with a colon */
68 Label [-a-zA-Z$._0-9]+:
69 QuoteLabel \"[^\"]+\":
71 /* Quoted names can contain any character except " and \ */
72 StringConstant \"[^\"]*\"
75 /* [PN]Integer: match positive and negative literal integer values that
76 * are preceeded by a '%' character. These represent unnamed variable slots.
82 /* E[PN]Integer: match positive and negative literal integer values */
86 /* FPConstant - A Floating point constant.
88 FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
90 /* HexFPConstant - Floating point constant represented in IEEE format as a
91 * hexadecimal number for when exponential notation is not precise enough.
93 HexFPConstant 0x[0-9A-Fa-f]+
95 /* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
96 * it to deal with 64 bit numbers.
98 HexIntConstant [us]0x[0-9A-Fa-f]+
101 {Comment} { /* Ignore comments for now */ }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
248 extractelement { RET_TOK( EXTRACTELEMENT); }
249 insertelement { RET_TOK( INSERTELEMENT); }
250 shufflevector { RET_TOK( SHUFFLEVECTOR); }
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); }
265 /* Make sure to free the internal buffers for flex when we are
266 * done reading our input!
268 yy_delete_buffer(YY_CURRENT_BUFFER);
272 [ \r\t\n] { /* Ignore whitespace */ }
273 . { return yytext[0]; }