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