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