blob: 2cf7c51dac6fe66347aa8bddefc875a92ecb5e3f [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); }
151sbyte { RET_TY(SBYTE,SByteTy,"sbyte",true); }
152ubyte { RET_TY(UBYTE,UByteTy,"ubyte",false); }
153short { RET_TY(SHORT,ShortTy,"short",true); }
154ushort { RET_TY(USHORT,UShortTy,"ushort",false); }
155int { RET_TY(INT,IntTy,"int",true); }
156uint { RET_TY(UINT,UIntTy,"uint",false); }
157long { RET_TY(LONG,LongTy,"long",true); }
158ulong { RET_TY(ULONG,ULongTy,"ulong",false); }
159float { RET_TY(FLOAT,FloatTy,"float",false); }
160double { RET_TY(DOUBLE,DoubleTy,"double",false); }
161label { RET_TY(LABEL,LabelTy,"label",false); }
Reid Spencera50d5962006-12-02 04:11:07 +0000162opaque { RET_TOK(OPAQUE); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000163type { RET_TOK(TYPE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000164
165add { RET_TOK( ADD); }
166sub { RET_TOK( SUB); }
167mul { RET_TOK( MUL); }
Reid Spencer78720742006-12-02 20:21:22 +0000168div { RET_TOK( DIV); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000169udiv { RET_TOK( UDIV); }
170sdiv { RET_TOK( SDIV); }
171fdiv { RET_TOK( FDIV); }
Reid Spencer78720742006-12-02 20:21:22 +0000172rem { RET_TOK( REM); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000173urem { RET_TOK( UREM); }
174srem { RET_TOK( SREM); }
175frem { RET_TOK( FREM); }
176and { RET_TOK( AND); }
177or { RET_TOK( OR); }
178xor { RET_TOK( XOR); }
179setne { RET_TOK( SETNE); }
180seteq { RET_TOK( SETEQ); }
181setlt { RET_TOK( SETLT); }
182setgt { RET_TOK( SETGT); }
183setle { RET_TOK( SETLE); }
184setge { RET_TOK( SETGE); }
Reid Spencer229e9362006-12-02 22:14:11 +0000185icmp { RET_TOK(ICMP); }
186fcmp { RET_TOK(FCMP); }
187eq { RET_TOK(EQ); }
188ne { RET_TOK(NE); }
189slt { RET_TOK(SLT); }
190sgt { RET_TOK(SGT); }
191sle { RET_TOK(SLE); }
192sge { RET_TOK(SGE); }
193oeq { RET_TOK(OEQ); }
194one { RET_TOK(ONE); }
195olt { RET_TOK(OLT); }
196ogt { RET_TOK(OGT); }
197ole { RET_TOK(OLE); }
198oge { RET_TOK(OGE); }
199ord { RET_TOK(ORD); }
200uno { RET_TOK(UNO); }
201ueq { RET_TOK(UEQ); }
202une { RET_TOK(UNE); }
203ult { RET_TOK(ULT); }
204ugt { RET_TOK(UGT); }
205ule { RET_TOK(ULE); }
206uge { RET_TOK(UGE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000207
208phi { RET_TOK( PHI_TOK); }
209call { RET_TOK( CALL); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000210cast { RET_TOK( CAST); }
Reid Spencerfcb5df82006-12-01 22:34:43 +0000211trunc { RET_TOK( TRUNC); }
212zext { RET_TOK( ZEXT); }
213sext { RET_TOK( SEXT); }
214fptrunc { RET_TOK( FPTRUNC); }
215fpext { RET_TOK( FPEXT); }
216fptoui { RET_TOK( FPTOUI); }
217fptosi { RET_TOK( FPTOSI); }
218uitofp { RET_TOK( UITOFP); }
219sitofp { RET_TOK( SITOFP); }
220ptrtoint { RET_TOK( PTRTOINT); }
221inttoptr { RET_TOK( INTTOPTR); }
222bitcast { RET_TOK( BITCAST); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000223select { RET_TOK( SELECT); }
224shl { RET_TOK( SHL); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000225shr { RET_TOK( SHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000226ashr { RET_TOK( ASHR); }
Reid Spencerf7bde222006-12-01 22:26:37 +0000227lshr { RET_TOK( LSHR); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000228va_arg { RET_TOK( VAARG); }
229ret { RET_TOK( RET); }
230br { RET_TOK( BR); }
231switch { RET_TOK( SWITCH); }
232invoke { RET_TOK( INVOKE); }
233unwind { RET_TOK( UNWIND); }
Reid Spencer78720742006-12-02 20:21:22 +0000234except { RET_TOK( EXCEPT); } // alias for unwind
Reid Spencere7c3c602006-11-30 06:36:44 +0000235unreachable { RET_TOK( UNREACHABLE); }
236
237malloc { RET_TOK( MALLOC); }
238alloca { RET_TOK( ALLOCA); }
239free { RET_TOK( FREE); }
240load { RET_TOK( LOAD); }
241store { RET_TOK( STORE); }
242getelementptr { RET_TOK( GETELEMENTPTR); }
243
244extractelement { RET_TOK( EXTRACTELEMENT); }
245insertelement { RET_TOK( INSERTELEMENT); }
246shufflevector { RET_TOK( SHUFFLEVECTOR); }
247
248
249{VarID} { RET_TOK( VAR_ID); }
250{Label} { RET_TOK( LABELSTR); }
251{QuoteLabel} { RET_TOK( LABELSTR); }
252{StringConstant} { RET_TOK( STRINGCONSTANT ); }
253{PInteger} { RET_TOK( EUINT64VAL ); }
254{NInteger} { RET_TOK( ESINT64VAL ); }
255{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
256{EPInteger} { RET_TOK( UINTVAL); }
257{ENInteger} { RET_TOK( SINTVAL); }
258{FPConstant} { RET_TOK( FPVAL); }
259{HexFPConstant} { RET_TOK( FPVAL); }
260<<EOF>> {
261 /* Make sure to free the internal buffers for flex when we are
262 * done reading our input!
263 */
264 yy_delete_buffer(YY_CURRENT_BUFFER);
265 return EOF;
266 }
267
268[ \r\t\n] { /* Ignore whitespace */ }
269. { return yytext[0]; }
270
271%%