summaryrefslogtreecommitdiff
path: root/tools/llvm-upgrade/UpgradeLexer.l.cvs
blob: 5b575606ce127b96ebace1574cb74cce8529eff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the 
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file implements the flex scanner for LLVM 1.9 assembly languages files.
//
//===----------------------------------------------------------------------===*/

%option prefix="Upgrade"
%option yylineno
%option nostdinit
%option never-interactive
%option batch
%option noyywrap
%option nodefault
%option 8bit
%option outfile="UpgradeLexer.cpp"
%option ecs
%option noreject
%option noyymore

%{

#include "UpgradeInternals.h"
#include "UpgradeParser.h"
#include <cctype>
#include <cstdlib>

#define YY_INPUT(buf,result,max_size) \
{ \
  if (LexInput->good() && !LexInput->eof()) { \
    LexInput->read(buf,max_size); \
    result = LexInput->gcount(); \
  } else {\
    result = YY_NULL; \
  } \
}


// Construct a token value for a non-obsolete token
#define RET_TOK(sym) \
  Upgradelval.String = new std::string(yytext); \
  return sym

#define RET_TY(sym,OldTY,NewTY,sign) \
  Upgradelval.Type = TypeInfo::get(NewTY, OldTY); \
  return sym

#define YY_NEVER_INTERACTIVE 1
%}



/* Comments start with a ; and go till end of line */
Comment    ;.*

/* Variable(Value) identifiers start with a % sign */
VarID       %[-a-zA-Z$._][-a-zA-Z$._0-9]*

/* Label identifiers end with a colon */
Label       [-a-zA-Z$._0-9]+:
QuoteLabel \"[^\"]+\":

/* Quoted names can contain any character except " and \ */
StringConstant \"[^\"]*\"


/* [PN]Integer: match positive and negative literal integer values that
 * are preceeded by a '%' character.  These represent unnamed variable slots.
 */
EPInteger     %[0-9]+
ENInteger    %-[0-9]+


/* E[PN]Integer: match positive and negative literal integer values */
PInteger   [0-9]+
NInteger  -[0-9]+

/* FPConstant - A Floating point constant.
 */
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?

/* HexFPConstant - Floating point constant represented in IEEE format as a
 *  hexadecimal number for when exponential notation is not precise enough.
 */
HexFPConstant 0x[0-9A-Fa-f]+

/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
 * it to deal with 64 bit numbers.
 */
HexIntConstant [us]0x[0-9A-Fa-f]+
%%

{Comment}       { /* Ignore comments for now */ }

begin           { RET_TOK( BEGINTOK); }
end             { RET_TOK( ENDTOK); }
true            { RET_TOK( TRUETOK);  }
false           { RET_TOK( FALSETOK); }
declare         { RET_TOK( DECLARE); }
global          { RET_TOK( GLOBAL); }
constant        { RET_TOK( CONSTANT); }
internal        { RET_TOK( INTERNAL); }
linkonce        { RET_TOK( LINKONCE); }
weak            { RET_TOK( WEAK); }
appending       { RET_TOK( APPENDING); }
dllimport       { RET_TOK( DLLIMPORT); }
dllexport       { RET_TOK( DLLEXPORT); }
extern_weak     { RET_TOK( EXTERN_WEAK); }
external        { RET_TOK( EXTERNAL); }
uninitialized   { RET_TOK( UNINITIALIZED); }  // alias for external
implementation  { RET_TOK( IMPLEMENTATION); }
zeroinitializer { RET_TOK( ZEROINITIALIZER); }
\.\.\.          { RET_TOK( DOTDOTDOT); }
undef           { RET_TOK( UNDEF); }
null            { RET_TOK( NULL_TOK); }
to              { RET_TOK( TO); }
tail            { RET_TOK( TAIL); }
target          { RET_TOK( TARGET); }
triple          { RET_TOK( TRIPLE); }
deplibs         { RET_TOK( DEPLIBS); }
endian          { RET_TOK( ENDIAN); }
pointersize     { RET_TOK( POINTERSIZE); }
datalayout      { RET_TOK( DATALAYOUT); }
little          { RET_TOK( LITTLE); }
big             { RET_TOK( BIG); }
volatile        { RET_TOK( VOLATILE); }
align           { RET_TOK( ALIGN);  }
section         { RET_TOK( SECTION); }
module          { RET_TOK( MODULE); }
asm             { RET_TOK( ASM_TOK); }
sideeffect      { RET_TOK( SIDEEFFECT); }

cc              { RET_TOK( CC_TOK); }
ccc             { RET_TOK( CCC_TOK); }
csretcc         { RET_TOK( CSRETCC_TOK); }
fastcc          { RET_TOK( FASTCC_TOK); }
coldcc          { RET_TOK( COLDCC_TOK); }
x86_stdcallcc   { RET_TOK( X86_STDCALLCC_TOK); }
x86_fastcallcc  { RET_TOK( X86_FASTCALLCC_TOK); }

void            { RET_TY(VOID,VoidTy,"void",false); }
bool            { RET_TY(BOOL,BoolTy,"bool",false); }
sbyte           { RET_TY(SBYTE,SByteTy,"i8",true); }
ubyte           { RET_TY(UBYTE,UByteTy,"i8",false); }
short           { RET_TY(SHORT,ShortTy,"i16",true); }
ushort          { RET_TY(USHORT,UShortTy,"i16",false); }
int             { RET_TY(INT,IntTy,"i32",true);   }
uint            { RET_TY(UINT,UIntTy,"i32",false);  }
long            { RET_TY(LONG,LongTy,"i64",true);  }
ulong           { RET_TY(ULONG,ULongTy,"i64",false); }
i8              { RET_TY(UBYTE,UByteTy,"i8",false); }
i16             { RET_TY(USHORT,UShortTy,"i16",false); }
i32             { RET_TY(UINT,UIntTy,"i32",false); }
i64             { RET_TY(ULONG,ULongTy,"i64",false); }
float           { RET_TY(FLOAT,FloatTy,"float",false); }
double          { RET_TY(DOUBLE,DoubleTy,"double",false); }
label           { RET_TY(LABEL,LabelTy,"label",false); }
opaque          { RET_TOK(OPAQUE); }
type            { RET_TOK(TYPE);   }

add             { RET_TOK( ADD); }
sub             { RET_TOK( SUB); }
mul             { RET_TOK( MUL); }
div             { RET_TOK( DIV); }
udiv            { RET_TOK( UDIV); }
sdiv            { RET_TOK( SDIV); }
fdiv            { RET_TOK( FDIV); }
rem             { RET_TOK( REM);  }
urem            { RET_TOK( UREM); }
srem            { RET_TOK( SREM); }
frem            { RET_TOK( FREM); }
and             { RET_TOK( AND); }
or              { RET_TOK( OR); }
xor             { RET_TOK( XOR); }
setne           { RET_TOK( SETNE); }
seteq           { RET_TOK( SETEQ); }
setlt           { RET_TOK( SETLT); }
setgt           { RET_TOK( SETGT); }
setle           { RET_TOK( SETLE); }
setge           { RET_TOK( SETGE); }
icmp            { RET_TOK(ICMP); }
fcmp            { RET_TOK(FCMP); }
eq              { RET_TOK(EQ); }
ne              { RET_TOK(NE); }
slt             { RET_TOK(SLT); }
sgt             { RET_TOK(SGT); }
sle             { RET_TOK(SLE); }
sge             { RET_TOK(SGE); }
oeq             { RET_TOK(OEQ); }
one             { RET_TOK(ONE); }
olt             { RET_TOK(OLT); }
ogt             { RET_TOK(OGT); }
ole             { RET_TOK(OLE); }
oge             { RET_TOK(OGE); }
ord             { RET_TOK(ORD); }
uno             { RET_TOK(UNO); }
ueq             { RET_TOK(UEQ); }
une             { RET_TOK(UNE); }
ult             { RET_TOK(ULT); }
ugt             { RET_TOK(UGT); }
ule             { RET_TOK(ULE); }
uge             { RET_TOK(UGE); }

phi             { RET_TOK( PHI_TOK); }
call            { RET_TOK( CALL); }
cast            { RET_TOK( CAST); }
trunc           { RET_TOK( TRUNC); }
zext            { RET_TOK( ZEXT); }
sext            { RET_TOK( SEXT); }
fptrunc         { RET_TOK( FPTRUNC); }
fpext           { RET_TOK( FPEXT); }
fptoui          { RET_TOK( FPTOUI); }
fptosi          { RET_TOK( FPTOSI); }
uitofp          { RET_TOK( UITOFP); }
sitofp          { RET_TOK( SITOFP); }
ptrtoint        { RET_TOK( PTRTOINT); }
inttoptr        { RET_TOK( INTTOPTR); }
bitcast         { RET_TOK( BITCAST); }
select          { RET_TOK( SELECT); }
shl             { RET_TOK( SHL); }
shr             { RET_TOK( SHR); }
ashr            { RET_TOK( ASHR); }
lshr            { RET_TOK( LSHR); }
va_arg          { RET_TOK( VAARG); }
ret             { RET_TOK( RET); }
br              { RET_TOK( BR); }
switch          { RET_TOK( SWITCH); }
invoke          { RET_TOK( INVOKE); }
unwind          { RET_TOK( UNWIND); }
except          { RET_TOK( EXCEPT); } // alias for unwind
unreachable     { RET_TOK( UNREACHABLE); }

malloc          { RET_TOK( MALLOC); }
alloca          { RET_TOK( ALLOCA); }
free            { RET_TOK( FREE); }
load            { RET_TOK( LOAD); }
store           { RET_TOK( STORE); }
getelementptr   { RET_TOK( GETELEMENTPTR); }

extractelement  { RET_TOK( EXTRACTELEMENT); }
insertelement   { RET_TOK( INSERTELEMENT); }
shufflevector   { RET_TOK( SHUFFLEVECTOR); }


{VarID}          { RET_TOK( VAR_ID); }
{Label}          { RET_TOK( LABELSTR); }
{QuoteLabel}     { RET_TOK( LABELSTR); }
{StringConstant} { RET_TOK( STRINGCONSTANT ); }
{PInteger}       { RET_TOK( EUINT64VAL ); }
{NInteger}       { RET_TOK( ESINT64VAL ); }
{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
{EPInteger}      { RET_TOK( UINTVAL); }
{ENInteger}      { RET_TOK( SINTVAL); }
{FPConstant}     { RET_TOK( FPVAL); }
{HexFPConstant}  { RET_TOK( FPVAL); }
<<EOF>>          {
                  /* Make sure to free the internal buffers for flex when we are
                   * done reading our input!
                   */
                  yy_delete_buffer(YY_CURRENT_BUFFER);
                  return EOF;
                }

[ \r\t\n]       { /* Ignore whitespace */ }
.               { return yytext[0]; }

%%