1 /*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the flex scanner for LLVM 1.9 assembly languages files.
12 //===----------------------------------------------------------------------===*/
14 %option prefix="Upgrade"
17 %option never-interactive
22 %option outfile="UpgradeLexer.cpp"
29 #include "ParserInternals.h"
30 #define YYSTYPE std::string*
31 #include "UpgradeParser.h"
35 static 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);
41 #define YY_INPUT(buf,result,max_size) \
43 if (LexInput->good() && !LexInput->eof()) { \
44 LexInput->read(buf,max_size); \
45 result = LexInput->gcount(); \
52 // Construct a token value for a non-obsolete token
53 #define RET_TOK(sym) \
54 Upgradelval = new std::string(yytext); \
58 #define YY_NEVER_INTERACTIVE 1
63 /* Comments start with a ; and go till end of line */
66 /* Variable(Value) identifiers start with a % sign */
67 VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]*
69 /* Label identifiers end with a colon */
70 Label [-a-zA-Z$._0-9]+:
71 QuoteLabel \"[^\"]+\":
73 /* Quoted names can contain any character except " and \ */
74 StringConstant \"[^\"]*\"
77 /* [PN]Integer: match positive and negative literal integer values that
78 * are preceeded by a '%' character. These represent unnamed variable slots.
84 /* E[PN]Integer: match positive and negative literal integer values */
88 /* FPConstant - A Floating point constant.
90 FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
92 /* HexFPConstant - Floating point constant represented in IEEE format as a
93 * hexadecimal number for when exponential notation is not precise enough.
95 HexFPConstant 0x[0-9A-Fa-f]+
97 /* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
98 * it to deal with 64 bit numbers.
100 HexIntConstant [us]0x[0-9A-Fa-f]+
103 {Comment} { /* Ignore comments for now */ }
105 begin { RET_TOK( BEGINTOK); }
106 end { RET_TOK( ENDTOK); }
107 true { RET_TOK( TRUETOK); }
108 false { RET_TOK( FALSETOK); }
109 declare { RET_TOK( DECLARE); }
110 global { RET_TOK( GLOBAL); }
111 constant { RET_TOK( CONSTANT); }
112 internal { RET_TOK( INTERNAL); }
113 linkonce { RET_TOK( LINKONCE); }
114 weak { RET_TOK( WEAK); }
115 appending { RET_TOK( APPENDING); }
116 dllimport { RET_TOK( DLLIMPORT); }
117 dllexport { RET_TOK( DLLEXPORT); }
118 extern_weak { RET_TOK( EXTERN_WEAK); }
119 external { RET_TOK( EXTERNAL); }
120 implementation { RET_TOK( IMPLEMENTATION); }
121 zeroinitializer { RET_TOK( ZEROINITIALIZER); }
122 \.\.\. { RET_TOK( DOTDOTDOT); }
123 undef { RET_TOK( UNDEF); }
124 null { RET_TOK( NULL_TOK); }
126 tail { RET_TOK( TAIL); }
127 target { RET_TOK( TARGET); }
128 triple { RET_TOK( TRIPLE); }
129 deplibs { RET_TOK( DEPLIBS); }
130 endian { RET_TOK( ENDIAN); }
131 pointersize { RET_TOK( POINTERSIZE); }
132 datalayout { RET_TOK( DATALAYOUT); }
133 little { RET_TOK( LITTLE); }
134 big { RET_TOK( BIG); }
135 volatile { RET_TOK( VOLATILE); }
136 align { RET_TOK( ALIGN); }
137 section { RET_TOK( SECTION); }
138 module { RET_TOK( MODULE); }
139 asm { RET_TOK( ASM_TOK); }
140 sideeffect { RET_TOK( SIDEEFFECT); }
142 cc { RET_TOK( CC_TOK); }
143 ccc { RET_TOK( CCC_TOK); }
144 csretcc { RET_TOK( CSRETCC_TOK); }
145 fastcc { RET_TOK( FASTCC_TOK); }
146 coldcc { RET_TOK( COLDCC_TOK); }
147 x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
148 x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
150 void { RET_TOK( VOID); }
151 bool { RET_TOK( BOOL); }
152 sbyte { RET_TOK( SBYTE); }
153 ubyte { RET_TOK( UBYTE); }
154 short { RET_TOK( SHORT); }
155 ushort { RET_TOK( USHORT); }
156 int { RET_TOK( INT); }
157 uint { RET_TOK( UINT); }
158 long { RET_TOK( LONG); }
159 ulong { RET_TOK( ULONG); }
160 float { RET_TOK( FLOAT); }
161 double { RET_TOK( DOUBLE); }
162 label { RET_TOK( LABEL); }
163 type { RET_TOK( TYPE); }
164 opaque { RET_TOK( OPAQUE); }
166 add { RET_TOK( ADD); }
167 sub { RET_TOK( SUB); }
168 mul { RET_TOK( MUL); }
169 div { RET_TOK( UDIV); }
170 udiv { RET_TOK( UDIV); }
171 sdiv { RET_TOK( SDIV); }
172 fdiv { RET_TOK( FDIV); }
173 rem { RET_TOK( UREM); }
174 urem { RET_TOK( UREM); }
175 srem { RET_TOK( SREM); }
176 frem { RET_TOK( FREM); }
177 and { RET_TOK( AND); }
179 xor { RET_TOK( XOR); }
180 setne { RET_TOK( SETNE); }
181 seteq { RET_TOK( SETEQ); }
182 setlt { RET_TOK( SETLT); }
183 setgt { RET_TOK( SETGT); }
184 setle { RET_TOK( SETLE); }
185 setge { RET_TOK( SETGE); }
187 phi { RET_TOK( PHI_TOK); }
188 call { RET_TOK( CALL); }
189 cast { RET_TOK( TRUNC); }
190 select { RET_TOK( SELECT); }
191 shl { RET_TOK( SHL); }
192 lshr { RET_TOK( LSHR); }
193 ashr { RET_TOK( ASHR); }
194 va_arg { RET_TOK( VAARG); }
195 ret { RET_TOK( RET); }
197 switch { RET_TOK( SWITCH); }
198 invoke { RET_TOK( INVOKE); }
199 unwind { RET_TOK( UNWIND); }
200 unreachable { RET_TOK( UNREACHABLE); }
202 malloc { RET_TOK( MALLOC); }
203 alloca { RET_TOK( ALLOCA); }
204 free { RET_TOK( FREE); }
205 load { RET_TOK( LOAD); }
206 store { RET_TOK( STORE); }
207 getelementptr { RET_TOK( GETELEMENTPTR); }
209 extractelement { RET_TOK( EXTRACTELEMENT); }
210 insertelement { RET_TOK( INSERTELEMENT); }
211 shufflevector { RET_TOK( SHUFFLEVECTOR); }
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); }
226 /* Make sure to free the internal buffers for flex when we are
227 * done reading our input!
229 yy_delete_buffer(YY_CURRENT_BUFFER);
233 [ \r\t\n] { /* Ignore whitespace */ }
234 . { return yytext[0]; }