Allow llvm-upgrade to read from stdin. Configure the lexer for reading
[oota-llvm.git] / tools / llvm-upgrade / UpgradeLexer.l
1 /*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file implements the flex scanner for LLVM 1.9 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
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);
39 }
40
41 #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
52 // 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 */
64 Comment    ;.*
65
66 /* Variable(Value) identifiers start with a % sign */
67 VarID       %[-a-zA-Z$._][-a-zA-Z$._0-9]*
68
69 /* Label identifiers end with a colon */
70 Label       [-a-zA-Z$._0-9]+:
71 QuoteLabel \"[^\"]+\":
72
73 /* Quoted names can contain any character except " and \ */
74 StringConstant \"[^\"]*\"
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  */
80 EPInteger     %[0-9]+
81 ENInteger    %-[0-9]+
82
83
84 /* E[PN]Integer: match positive and negative literal integer values */
85 PInteger   [0-9]+
86 NInteger  -[0-9]+
87
88 /* FPConstant - A Floating point constant.
89  */
90 FPConstant [-+]?[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  */
95 HexFPConstant 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  */
100 HexIntConstant [us]0x[0-9A-Fa-f]+
101 %%
102
103 {Comment}       { /* Ignore comments for now */ }
104
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); }
125 to              { RET_TOK( TO); }
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); }
141
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); }
149
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); }
165
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); }
178 or              { RET_TOK( OR); }
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); }
186
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); }
196 br              { RET_TOK( BR); }
197 switch          { RET_TOK( SWITCH); }
198 invoke          { RET_TOK( INVOKE); }
199 unwind          { RET_TOK( UNWIND); }
200 unreachable     { RET_TOK( UNREACHABLE); }
201
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); }
208
209 extractelement  { RET_TOK( EXTRACTELEMENT); }
210 insertelement   { RET_TOK( INSERTELEMENT); }
211 shufflevector   { 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 %%