blob: 08dfd8f33558536b1e2ef3753d79066274ac08c7 (
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
|
/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the flex scanner for LLVM 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 "ParserInternals.h"
#define YYSTYPE std::string*
#include "UpgradeParser.h"
#include <cctype>
#include <cstdlib>
void set_scan_bytes (const char * str, size_t len) {
Upgrade_scan_bytes (str, len);
}
static void trim(std::string& str) {
size_t startpos = str.find_first_not_of(" \t\n\r",0);
if (startpos != std::string::npos)
str.erase(0,startpos);
}
// Construct a token value for a non-obsolete token
#define RET_TOK(sym) \
Upgradelval = new std::string(yytext); \
trim(*Upgradelval); \
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); }
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_TOK( VOID); }
bool { RET_TOK( BOOL); }
sbyte { RET_TOK( SBYTE); }
ubyte { RET_TOK( UBYTE); }
short { RET_TOK( SHORT); }
ushort { RET_TOK( USHORT); }
int { RET_TOK( INT); }
uint { RET_TOK( UINT); }
long { RET_TOK( LONG); }
ulong { RET_TOK( ULONG); }
float { RET_TOK( FLOAT); }
double { RET_TOK( DOUBLE); }
label { RET_TOK( LABEL); }
type { RET_TOK( TYPE); }
opaque { RET_TOK( OPAQUE); }
add { RET_TOK( ADD); }
sub { RET_TOK( SUB); }
mul { RET_TOK( MUL); }
div { RET_TOK( UDIV); }
udiv { RET_TOK( UDIV); }
sdiv { RET_TOK( SDIV); }
fdiv { RET_TOK( FDIV); }
rem { RET_TOK( UREM); }
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); }
phi { RET_TOK( PHI_TOK); }
call { RET_TOK( CALL); }
cast { RET_TOK( TRUNC); }
select { RET_TOK( SELECT); }
shl { RET_TOK( SHL); }
lshr { RET_TOK( LSHR); }
ashr { RET_TOK( ASHR); }
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); }
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]; }
%%
|