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