blob: 293220a3d66ab5472ae24f70a3c22856a66834ce [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 Spencere7c3c602006-11-30 06:36:44 +000053 return sym
54
55#define YY_NEVER_INTERACTIVE 1
56%}
57
58
59
60/* Comments start with a ; and go till end of line */
61Comment ;.*
62
63/* Variable(Value) identifiers start with a % sign */
64VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
65
66/* Label identifiers end with a colon */
67Label [-a-zA-Z$._0-9]+:
68QuoteLabel \"[^\"]+\":
69
70/* Quoted names can contain any character except " and \ */
71StringConstant \"[^\"]*\"
72
73
74/* [PN]Integer: match positive and negative literal integer values that
75 * are preceeded by a '%' character. These represent unnamed variable slots.
76 */
77EPInteger %[0-9]+
78ENInteger %-[0-9]+
79
80
81/* E[PN]Integer: match positive and negative literal integer values */
82PInteger [0-9]+
83NInteger -[0-9]+
84
85/* FPConstant - A Floating point constant.
86 */
87FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
88
89/* HexFPConstant - Floating point constant represented in IEEE format as a
90 * hexadecimal number for when exponential notation is not precise enough.
91 */
92HexFPConstant 0x[0-9A-Fa-f]+
93
94/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
95 * it to deal with 64 bit numbers.
96 */
97HexIntConstant [us]0x[0-9A-Fa-f]+
98%%
99
100{Comment} { /* Ignore comments for now */ }
101
102begin { RET_TOK( BEGINTOK); }
103end { RET_TOK( ENDTOK); }
104true { RET_TOK( TRUETOK); }
105false { RET_TOK( FALSETOK); }
106declare { RET_TOK( DECLARE); }
107global { RET_TOK( GLOBAL); }
108constant { RET_TOK( CONSTANT); }
109internal { RET_TOK( INTERNAL); }
110linkonce { RET_TOK( LINKONCE); }
111weak { RET_TOK( WEAK); }
112appending { RET_TOK( APPENDING); }
113dllimport { RET_TOK( DLLIMPORT); }
114dllexport { RET_TOK( DLLEXPORT); }
115extern_weak { RET_TOK( EXTERN_WEAK); }
116external { RET_TOK( EXTERNAL); }
117implementation { RET_TOK( IMPLEMENTATION); }
118zeroinitializer { RET_TOK( ZEROINITIALIZER); }
119\.\.\. { RET_TOK( DOTDOTDOT); }
120undef { RET_TOK( UNDEF); }
121null { RET_TOK( NULL_TOK); }
122to { RET_TOK( TO); }
123tail { RET_TOK( TAIL); }
124target { RET_TOK( TARGET); }
125triple { RET_TOK( TRIPLE); }
126deplibs { RET_TOK( DEPLIBS); }
127endian { RET_TOK( ENDIAN); }
128pointersize { RET_TOK( POINTERSIZE); }
129datalayout { RET_TOK( DATALAYOUT); }
130little { RET_TOK( LITTLE); }
131big { RET_TOK( BIG); }
132volatile { RET_TOK( VOLATILE); }
133align { RET_TOK( ALIGN); }
134section { RET_TOK( SECTION); }
135module { RET_TOK( MODULE); }
136asm { RET_TOK( ASM_TOK); }
137sideeffect { RET_TOK( SIDEEFFECT); }
138
139cc { RET_TOK( CC_TOK); }
140ccc { RET_TOK( CCC_TOK); }
141csretcc { RET_TOK( CSRETCC_TOK); }
142fastcc { RET_TOK( FASTCC_TOK); }
143coldcc { RET_TOK( COLDCC_TOK); }
144x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
145x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
146
Reid Spencere77e35e2006-12-01 20:26:20 +0000147void { RET_TY(VOID,VoidTy,"void",false); }
148bool { RET_TY(BOOL,BoolTy,"bool",false); }
149sbyte { RET_TY(SBYTE,SByteTy,"sbyte",true); }
150ubyte { RET_TY(UBYTE,UByteTy,"ubyte",false); }
151short { RET_TY(SHORT,ShortTy,"short",true); }
152ushort { RET_TY(USHORT,UShortTy,"ushort",false); }
153int { RET_TY(INT,IntTy,"int",true); }
154uint { RET_TY(UINT,UIntTy,"uint",false); }
155long { RET_TY(LONG,LongTy,"long",true); }
156ulong { RET_TY(ULONG,ULongTy,"ulong",false); }
157float { RET_TY(FLOAT,FloatTy,"float",false); }
158double { RET_TY(DOUBLE,DoubleTy,"double",false); }
159label { RET_TY(LABEL,LabelTy,"label",false); }
160opaque { RET_TY(OPAQUE,OpaqueTy,"opaque",false); }
161type { RET_TOK(TYPE); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000162
163add { RET_TOK( ADD); }
164sub { RET_TOK( SUB); }
165mul { RET_TOK( MUL); }
166div { RET_TOK( UDIV); }
167udiv { RET_TOK( UDIV); }
168sdiv { RET_TOK( SDIV); }
169fdiv { RET_TOK( FDIV); }
170rem { RET_TOK( UREM); }
171urem { RET_TOK( UREM); }
172srem { RET_TOK( SREM); }
173frem { RET_TOK( FREM); }
174and { RET_TOK( AND); }
175or { RET_TOK( OR); }
176xor { RET_TOK( XOR); }
177setne { RET_TOK( SETNE); }
178seteq { RET_TOK( SETEQ); }
179setlt { RET_TOK( SETLT); }
180setgt { RET_TOK( SETGT); }
181setle { RET_TOK( SETLE); }
182setge { RET_TOK( SETGE); }
183
184phi { RET_TOK( PHI_TOK); }
185call { RET_TOK( CALL); }
Reid Spencere77e35e2006-12-01 20:26:20 +0000186cast { RET_TOK( CAST); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000187select { RET_TOK( SELECT); }
188shl { RET_TOK( SHL); }
189lshr { RET_TOK( LSHR); }
190ashr { RET_TOK( ASHR); }
191va_arg { RET_TOK( VAARG); }
192ret { RET_TOK( RET); }
193br { RET_TOK( BR); }
194switch { RET_TOK( SWITCH); }
195invoke { RET_TOK( INVOKE); }
196unwind { RET_TOK( UNWIND); }
Reid Spencer16244f42006-12-01 21:10:07 +0000197except { RET_TOK( UNWIND); }
Reid Spencere7c3c602006-11-30 06:36:44 +0000198unreachable { RET_TOK( UNREACHABLE); }
199
200malloc { RET_TOK( MALLOC); }
201alloca { RET_TOK( ALLOCA); }
202free { RET_TOK( FREE); }
203load { RET_TOK( LOAD); }
204store { RET_TOK( STORE); }
205getelementptr { RET_TOK( GETELEMENTPTR); }
206
207extractelement { RET_TOK( EXTRACTELEMENT); }
208insertelement { RET_TOK( INSERTELEMENT); }
209shufflevector { RET_TOK( SHUFFLEVECTOR); }
210
211
212{VarID} { RET_TOK( VAR_ID); }
213{Label} { RET_TOK( LABELSTR); }
214{QuoteLabel} { RET_TOK( LABELSTR); }
215{StringConstant} { RET_TOK( STRINGCONSTANT ); }
216{PInteger} { RET_TOK( EUINT64VAL ); }
217{NInteger} { RET_TOK( ESINT64VAL ); }
218{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
219{EPInteger} { RET_TOK( UINTVAL); }
220{ENInteger} { RET_TOK( SINTVAL); }
221{FPConstant} { RET_TOK( FPVAL); }
222{HexFPConstant} { RET_TOK( FPVAL); }
223<<EOF>> {
224 /* Make sure to free the internal buffers for flex when we are
225 * done reading our input!
226 */
227 yy_delete_buffer(YY_CURRENT_BUFFER);
228 return EOF;
229 }
230
231[ \r\t\n] { /* Ignore whitespace */ }
232. { return yytext[0]; }
233
234%%