| 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 | %{ | 
| Reid Spencer | 6ee573f | 2007-01-05 17:18:58 +0000 | [diff] [blame] | 28 | #include "UpgradeInternals.h" | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 29 | #include "llvm/Module.h" | 
|  | 30 | #include <list> | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 31 | #include "UpgradeParser.h" | 
|  | 32 | #include <cctype> | 
|  | 33 | #include <cstdlib> | 
|  | 34 |  | 
| Reid Spencer | 3867383 | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 35 | #define YY_INPUT(buf,result,max_size) \ | 
|  | 36 | { \ | 
|  | 37 | if (LexInput->good() && !LexInput->eof()) { \ | 
|  | 38 | LexInput->read(buf,max_size); \ | 
|  | 39 | result = LexInput->gcount(); \ | 
|  | 40 | } else {\ | 
|  | 41 | result = YY_NULL; \ | 
|  | 42 | } \ | 
|  | 43 | } | 
|  | 44 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 45 | #define YY_NEVER_INTERACTIVE 1 | 
| Reid Spencer | 3867383 | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 46 |  | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 47 | // Construct a token value for a non-obsolete token | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 48 | #define RET_TOK(type, Enum, sym) \ | 
|  | 49 | Upgradelval.type = Enum; \ | 
| Reid Spencer | 2daa578 | 2006-12-01 20:26:20 +0000 | [diff] [blame] | 50 | return sym | 
|  | 51 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 52 | #define RET_TY(sym,NewTY,sign) \ | 
|  | 53 | Upgradelval.PrimType.T = NewTY; \ | 
|  | 54 | Upgradelval.PrimType.S = sign; \ | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 55 | return sym | 
|  | 56 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 57 | namespace llvm { | 
|  | 58 |  | 
|  | 59 | // TODO: All of the static identifiers are figured out by the lexer, | 
|  | 60 | // these should be hashed to reduce the lexer size | 
|  | 61 |  | 
|  | 62 | // UnEscapeLexed - Run through the specified buffer and change \xx codes to the | 
|  | 63 | // appropriate character.  If AllowNull is set to false, a \00 value will cause | 
|  | 64 | // an exception to be thrown. | 
|  | 65 | // | 
|  | 66 | // If AllowNull is set to true, the return value of the function points to the | 
|  | 67 | // last character of the string in memory. | 
|  | 68 | // | 
|  | 69 | char *UnEscapeLexed(char *Buffer, bool AllowNull) { | 
|  | 70 | char *BOut = Buffer; | 
|  | 71 | for (char *BIn = Buffer; *BIn; ) { | 
|  | 72 | if (BIn[0] == '\\' && isxdigit(BIn[1]) && isxdigit(BIn[2])) { | 
|  | 73 | char Tmp = BIn[3]; BIn[3] = 0;     // Terminate string | 
|  | 74 | *BOut = (char)strtol(BIn+1, 0, 16);  // Convert to number | 
|  | 75 | if (!AllowNull && !*BOut) | 
|  | 76 | error("String literal cannot accept \\00 escape!"); | 
|  | 77 |  | 
|  | 78 | BIn[3] = Tmp;                  // Restore character | 
|  | 79 | BIn += 3;                      // Skip over handled chars | 
|  | 80 | ++BOut; | 
|  | 81 | } else { | 
|  | 82 | *BOut++ = *BIn++; | 
|  | 83 | } | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | return BOut; | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | // atoull - Convert an ascii string of decimal digits into the unsigned long | 
|  | 90 | // long representation... this does not have to do input error checking, | 
|  | 91 | // because we know that the input will be matched by a suitable regex... | 
|  | 92 | // | 
|  | 93 | static uint64_t atoull(const char *Buffer) { | 
|  | 94 | uint64_t Result = 0; | 
|  | 95 | for (; *Buffer; Buffer++) { | 
|  | 96 | uint64_t OldRes = Result; | 
|  | 97 | Result *= 10; | 
|  | 98 | Result += *Buffer-'0'; | 
|  | 99 | if (Result < OldRes)   // Uh, oh, overflow detected!!! | 
|  | 100 | error("constant bigger than 64 bits detected!"); | 
|  | 101 | } | 
|  | 102 | return Result; | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | static uint64_t HexIntToVal(const char *Buffer) { | 
|  | 106 | uint64_t Result = 0; | 
|  | 107 | for (; *Buffer; ++Buffer) { | 
|  | 108 | uint64_t OldRes = Result; | 
|  | 109 | Result *= 16; | 
|  | 110 | char C = *Buffer; | 
|  | 111 | if (C >= '0' && C <= '9') | 
|  | 112 | Result += C-'0'; | 
|  | 113 | else if (C >= 'A' && C <= 'F') | 
|  | 114 | Result += C-'A'+10; | 
|  | 115 | else if (C >= 'a' && C <= 'f') | 
|  | 116 | Result += C-'a'+10; | 
|  | 117 |  | 
|  | 118 | if (Result < OldRes)   // Uh, oh, overflow detected!!! | 
|  | 119 | error("constant bigger than 64 bits detected!"); | 
|  | 120 | } | 
|  | 121 | return Result; | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 |  | 
|  | 125 | // HexToFP - Convert the ascii string in hexidecimal format to the floating | 
|  | 126 | // point representation of it. | 
|  | 127 | // | 
|  | 128 | static double HexToFP(const char *Buffer) { | 
|  | 129 | // Behave nicely in the face of C TBAA rules... see: | 
|  | 130 | // http://www.nullstone.com/htmls/category/aliastyp.htm | 
|  | 131 | union { | 
|  | 132 | uint64_t UI; | 
|  | 133 | double FP; | 
|  | 134 | } UIntToFP; | 
|  | 135 | UIntToFP.UI = HexIntToVal(Buffer); | 
|  | 136 |  | 
|  | 137 | assert(sizeof(double) == sizeof(uint64_t) && | 
|  | 138 | "Data sizes incompatible on this target!"); | 
|  | 139 | return UIntToFP.FP;   // Cast Hex constant to double | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 |  | 
|  | 143 | } // End llvm namespace | 
|  | 144 |  | 
|  | 145 | using namespace llvm; | 
|  | 146 |  | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 147 | %} | 
|  | 148 |  | 
|  | 149 |  | 
|  | 150 |  | 
|  | 151 | /* Comments start with a ; and go till end of line */ | 
|  | 152 | Comment    ;.* | 
|  | 153 |  | 
|  | 154 | /* Variable(Value) identifiers start with a % sign */ | 
|  | 155 | VarID       %[-a-zA-Z$._][-a-zA-Z$._0-9]* | 
|  | 156 |  | 
|  | 157 | /* Label identifiers end with a colon */ | 
|  | 158 | Label       [-a-zA-Z$._0-9]+: | 
|  | 159 | QuoteLabel \"[^\"]+\": | 
|  | 160 |  | 
|  | 161 | /* Quoted names can contain any character except " and \ */ | 
|  | 162 | StringConstant \"[^\"]*\" | 
|  | 163 |  | 
|  | 164 |  | 
|  | 165 | /* [PN]Integer: match positive and negative literal integer values that | 
|  | 166 | * are preceeded by a '%' character.  These represent unnamed variable slots. | 
|  | 167 | */ | 
|  | 168 | EPInteger     %[0-9]+ | 
|  | 169 | ENInteger    %-[0-9]+ | 
|  | 170 |  | 
|  | 171 |  | 
|  | 172 | /* E[PN]Integer: match positive and negative literal integer values */ | 
|  | 173 | PInteger   [0-9]+ | 
|  | 174 | NInteger  -[0-9]+ | 
|  | 175 |  | 
|  | 176 | /* FPConstant - A Floating point constant. | 
|  | 177 | */ | 
|  | 178 | FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)? | 
|  | 179 |  | 
|  | 180 | /* HexFPConstant - Floating point constant represented in IEEE format as a | 
|  | 181 | *  hexadecimal number for when exponential notation is not precise enough. | 
|  | 182 | */ | 
|  | 183 | HexFPConstant 0x[0-9A-Fa-f]+ | 
|  | 184 |  | 
|  | 185 | /* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing | 
|  | 186 | * it to deal with 64 bit numbers. | 
|  | 187 | */ | 
|  | 188 | HexIntConstant [us]0x[0-9A-Fa-f]+ | 
|  | 189 | %% | 
|  | 190 |  | 
|  | 191 | {Comment}       { /* Ignore comments for now */ } | 
|  | 192 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 193 | begin           { return BEGINTOK; } | 
|  | 194 | end             { return ENDTOK; } | 
|  | 195 | true            { return TRUETOK;  } | 
|  | 196 | false           { return FALSETOK; } | 
|  | 197 | declare         { return DECLARE; } | 
|  | 198 | global          { return GLOBAL; } | 
|  | 199 | constant        { return CONSTANT; } | 
|  | 200 | internal        { return INTERNAL; } | 
|  | 201 | linkonce        { return LINKONCE; } | 
|  | 202 | weak            { return WEAK; } | 
|  | 203 | appending       { return APPENDING; } | 
|  | 204 | dllimport       { return DLLIMPORT; } | 
|  | 205 | dllexport       { return DLLEXPORT; } | 
|  | 206 | extern_weak     { return EXTERN_WEAK; } | 
|  | 207 | uninitialized   { return EXTERNAL; }    /* Deprecated, turn into external */ | 
|  | 208 | external        { return EXTERNAL; } | 
|  | 209 | implementation  { return IMPLEMENTATION; } | 
|  | 210 | zeroinitializer { return ZEROINITIALIZER; } | 
|  | 211 | \.\.\.          { return DOTDOTDOT; } | 
|  | 212 | undef           { return UNDEF; } | 
|  | 213 | null            { return NULL_TOK; } | 
|  | 214 | to              { return TO; } | 
|  | 215 | except          { return EXCEPT; } | 
|  | 216 | not             { return NOT; }  /* Deprecated, turned into XOR */ | 
|  | 217 | tail            { return TAIL; } | 
|  | 218 | target          { return TARGET; } | 
|  | 219 | triple          { return TRIPLE; } | 
|  | 220 | deplibs         { return DEPLIBS; } | 
|  | 221 | endian          { return ENDIAN; } | 
|  | 222 | pointersize     { return POINTERSIZE; } | 
|  | 223 | datalayout      { return DATALAYOUT; } | 
|  | 224 | little          { return LITTLE; } | 
|  | 225 | big             { return BIG; } | 
|  | 226 | volatile        { return VOLATILE; } | 
|  | 227 | align           { return ALIGN;  } | 
|  | 228 | section         { return SECTION; } | 
|  | 229 | module          { return MODULE; } | 
|  | 230 | asm             { return ASM_TOK; } | 
|  | 231 | sideeffect      { return SIDEEFFECT; } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 232 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 233 | cc              { return CC_TOK; } | 
|  | 234 | ccc             { return CCC_TOK; } | 
|  | 235 | csretcc         { return CSRETCC_TOK; } | 
|  | 236 | fastcc          { return FASTCC_TOK; } | 
|  | 237 | coldcc          { return COLDCC_TOK; } | 
|  | 238 | x86_stdcallcc   { return X86_STDCALLCC_TOK; } | 
|  | 239 | x86_fastcallcc  { return X86_FASTCALLCC_TOK; } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 240 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 241 | sbyte           { RET_TY(SBYTE,  Type::Int8Ty,  Signed);  } | 
|  | 242 | ubyte           { RET_TY(UBYTE,  Type::Int8Ty,  Unsigned); } | 
|  | 243 | short           { RET_TY(SHORT,  Type::Int16Ty, Signed);  } | 
|  | 244 | ushort          { RET_TY(USHORT, Type::Int16Ty, Unsigned); } | 
|  | 245 | int             { RET_TY(INT,    Type::Int32Ty, Signed);  } | 
|  | 246 | uint            { RET_TY(UINT,   Type::Int32Ty, Unsigned); } | 
|  | 247 | long            { RET_TY(LONG,   Type::Int64Ty, Signed);  } | 
|  | 248 | ulong           { RET_TY(ULONG,  Type::Int64Ty, Unsigned); } | 
|  | 249 | void            { RET_TY(VOID,   Type::VoidTy,  Signless  ); } | 
|  | 250 | bool            { RET_TY(BOOL,   Type::Int1Ty,  Unsigned  ); } | 
|  | 251 | float           { RET_TY(FLOAT,  Type::FloatTy, Signless ); } | 
|  | 252 | double          { RET_TY(DOUBLE, Type::DoubleTy,Signless); } | 
|  | 253 | label           { RET_TY(LABEL,  Type::LabelTy, Signless ); } | 
|  | 254 | type            { return TYPE;   } | 
|  | 255 | opaque          { return OPAQUE; } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 256 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 257 | add             { RET_TOK(BinaryOpVal, AddOp, ADD); } | 
|  | 258 | sub             { RET_TOK(BinaryOpVal, SubOp, SUB); } | 
|  | 259 | mul             { RET_TOK(BinaryOpVal, MulOp, MUL); } | 
|  | 260 | div             { RET_TOK(BinaryOpVal, DivOp,  DIV); } | 
|  | 261 | udiv            { RET_TOK(BinaryOpVal, UDivOp, UDIV); } | 
|  | 262 | sdiv            { RET_TOK(BinaryOpVal, SDivOp, SDIV); } | 
|  | 263 | fdiv            { RET_TOK(BinaryOpVal, FDivOp, FDIV); } | 
|  | 264 | rem             { RET_TOK(BinaryOpVal, RemOp,  REM); } | 
|  | 265 | urem            { RET_TOK(BinaryOpVal, URemOp, UREM); } | 
|  | 266 | srem            { RET_TOK(BinaryOpVal, SRemOp, SREM); } | 
|  | 267 | frem            { RET_TOK(BinaryOpVal, FRemOp, FREM); } | 
|  | 268 | and             { RET_TOK(BinaryOpVal, AndOp, AND); } | 
|  | 269 | or              { RET_TOK(BinaryOpVal, OrOp , OR ); } | 
|  | 270 | xor             { RET_TOK(BinaryOpVal, XorOp, XOR); } | 
|  | 271 | setne           { RET_TOK(BinaryOpVal, SetNE, SETNE); } | 
|  | 272 | seteq           { RET_TOK(BinaryOpVal, SetEQ, SETEQ); } | 
|  | 273 | setlt           { RET_TOK(BinaryOpVal, SetLT, SETLT); } | 
|  | 274 | setgt           { RET_TOK(BinaryOpVal, SetGT, SETGT); } | 
|  | 275 | setle           { RET_TOK(BinaryOpVal, SetLE, SETLE); } | 
|  | 276 | setge           { RET_TOK(BinaryOpVal, SetGE, SETGE); } | 
|  | 277 | icmp            { RET_TOK(OtherOpVal, ICmpOp, ICMP); } | 
|  | 278 | fcmp            { RET_TOK(OtherOpVal, FCmpOp, FCMP); } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 279 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 280 | eq              { return EQ; } | 
|  | 281 | ne              { return NE; } | 
|  | 282 | slt             { return SLT; } | 
|  | 283 | sgt             { return SGT; } | 
|  | 284 | sle             { return SLE; } | 
|  | 285 | sge             { return SGE; } | 
|  | 286 | ult             { return ULT; } | 
|  | 287 | ugt             { return UGT; } | 
|  | 288 | ule             { return ULE; } | 
|  | 289 | uge             { return UGE; } | 
|  | 290 | oeq             { return OEQ; } | 
|  | 291 | one             { return ONE; } | 
|  | 292 | olt             { return OLT; } | 
|  | 293 | ogt             { return OGT; } | 
|  | 294 | ole             { return OLE; } | 
|  | 295 | oge             { return OGE; } | 
|  | 296 | ord             { return ORD; } | 
|  | 297 | uno             { return UNO; } | 
|  | 298 | ueq             { return UEQ; } | 
|  | 299 | une             { return UNE; } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 300 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 301 | phi             { RET_TOK(OtherOpVal, PHIOp, PHI_TOK); } | 
|  | 302 | call            { RET_TOK(OtherOpVal, CallOp, CALL); } | 
|  | 303 | cast            { RET_TOK(CastOpVal, CastOp, CAST);  } | 
|  | 304 | trunc           { RET_TOK(CastOpVal, TruncOp, TRUNC); } | 
|  | 305 | zext            { RET_TOK(CastOpVal, ZExtOp , ZEXT); } | 
|  | 306 | sext            { RET_TOK(CastOpVal, SExtOp, SEXT); } | 
|  | 307 | fptrunc         { RET_TOK(CastOpVal, FPTruncOp, FPTRUNC); } | 
|  | 308 | fpext           { RET_TOK(CastOpVal, FPExtOp, FPEXT); } | 
|  | 309 | fptoui          { RET_TOK(CastOpVal, FPToUIOp, FPTOUI); } | 
|  | 310 | fptosi          { RET_TOK(CastOpVal, FPToSIOp, FPTOSI); } | 
|  | 311 | uitofp          { RET_TOK(CastOpVal, UIToFPOp, UITOFP); } | 
|  | 312 | sitofp          { RET_TOK(CastOpVal, SIToFPOp, SITOFP); } | 
|  | 313 | ptrtoint        { RET_TOK(CastOpVal, PtrToIntOp, PTRTOINT); } | 
|  | 314 | inttoptr        { RET_TOK(CastOpVal, IntToPtrOp, INTTOPTR); } | 
|  | 315 | bitcast         { RET_TOK(CastOpVal, BitCastOp, BITCAST); } | 
|  | 316 | select          { RET_TOK(OtherOpVal, SelectOp, SELECT); } | 
|  | 317 | shl             { RET_TOK(OtherOpVal, ShlOp, SHL); } | 
|  | 318 | shr             { RET_TOK(OtherOpVal, ShrOp, SHR); } | 
|  | 319 | lshr            { RET_TOK(OtherOpVal, LShrOp, LSHR); } | 
|  | 320 | ashr            { RET_TOK(OtherOpVal, AShrOp, ASHR); } | 
|  | 321 | vanext          { return VANEXT_old; } | 
|  | 322 | vaarg           { return VAARG_old; } | 
|  | 323 | va_arg          { RET_TOK(OtherOpVal, VAArg , VAARG); } | 
|  | 324 | ret             { RET_TOK(TermOpVal, RetOp, RET); } | 
|  | 325 | br              { RET_TOK(TermOpVal, BrOp, BR); } | 
|  | 326 | switch          { RET_TOK(TermOpVal, SwitchOp, SWITCH); } | 
|  | 327 | invoke          { RET_TOK(TermOpVal, InvokeOp, INVOKE); } | 
|  | 328 | unwind          { return UNWIND; } | 
|  | 329 | unreachable     { RET_TOK(TermOpVal, UnreachableOp, UNREACHABLE); } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 330 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 331 | malloc          { RET_TOK(MemOpVal, MallocOp, MALLOC); } | 
|  | 332 | alloca          { RET_TOK(MemOpVal, AllocaOp, ALLOCA); } | 
|  | 333 | free            { RET_TOK(MemOpVal, FreeOp, FREE); } | 
|  | 334 | load            { RET_TOK(MemOpVal, LoadOp, LOAD); } | 
|  | 335 | store           { RET_TOK(MemOpVal, StoreOp, STORE); } | 
|  | 336 | getelementptr   { RET_TOK(MemOpVal, GetElementPtrOp, GETELEMENTPTR); } | 
|  | 337 |  | 
|  | 338 | extractelement  { RET_TOK(OtherOpVal, ExtractElementOp, EXTRACTELEMENT); } | 
|  | 339 | insertelement   { RET_TOK(OtherOpVal, InsertElementOp, INSERTELEMENT); } | 
|  | 340 | shufflevector   { RET_TOK(OtherOpVal, ShuffleVectorOp, SHUFFLEVECTOR); } | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 341 |  | 
|  | 342 |  | 
| Reid Spencer | 00a7c7f | 2007-01-26 08:18:34 +0000 | [diff] [blame^] | 343 | {VarID}         { | 
|  | 344 | UnEscapeLexed(yytext+1); | 
|  | 345 | Upgradelval.StrVal = strdup(yytext+1);             // Skip % | 
|  | 346 | return VAR_ID; | 
|  | 347 | } | 
|  | 348 | {Label}         { | 
|  | 349 | yytext[strlen(yytext)-1] = 0;  // nuke colon | 
|  | 350 | UnEscapeLexed(yytext); | 
|  | 351 | Upgradelval.StrVal = strdup(yytext); | 
|  | 352 | return LABELSTR; | 
|  | 353 | } | 
|  | 354 | {QuoteLabel}    { | 
|  | 355 | yytext[strlen(yytext)-2] = 0;  // nuke colon, end quote | 
|  | 356 | UnEscapeLexed(yytext+1); | 
|  | 357 | Upgradelval.StrVal = strdup(yytext+1); | 
|  | 358 | return LABELSTR; | 
|  | 359 | } | 
|  | 360 |  | 
|  | 361 | {StringConstant} { // Note that we cannot unescape a string constant here!  The | 
|  | 362 | // string constant might contain a \00 which would not be | 
|  | 363 | // understood by the string stuff.  It is valid to make a | 
|  | 364 | // [sbyte] c"Hello World\00" constant, for example. | 
|  | 365 | // | 
|  | 366 | yytext[strlen(yytext)-1] = 0;           // nuke end quote | 
|  | 367 | Upgradelval.StrVal = strdup(yytext+1);  // Nuke start quote | 
|  | 368 | return STRINGCONSTANT; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 |  | 
|  | 372 | {PInteger}      { Upgradelval.UInt64Val = atoull(yytext); return EUINT64VAL; } | 
|  | 373 | {NInteger}      { | 
|  | 374 | uint64_t Val = atoull(yytext+1); | 
|  | 375 | // +1:  we have bigger negative range | 
|  | 376 | if (Val > (uint64_t)INT64_MAX+1) | 
|  | 377 | error("Constant too large for signed 64 bits!"); | 
|  | 378 | Upgradelval.SInt64Val = -Val; | 
|  | 379 | return ESINT64VAL; | 
|  | 380 | } | 
|  | 381 | {HexIntConstant} { | 
|  | 382 | Upgradelval.UInt64Val = HexIntToVal(yytext+3); | 
|  | 383 | return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL; | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | {EPInteger}     { | 
|  | 387 | uint64_t Val = atoull(yytext+1); | 
|  | 388 | if ((unsigned)Val != Val) | 
|  | 389 | error("Invalid value number (too large)!"); | 
|  | 390 | Upgradelval.UIntVal = unsigned(Val); | 
|  | 391 | return UINTVAL; | 
|  | 392 | } | 
|  | 393 | {ENInteger}     { | 
|  | 394 | uint64_t Val = atoull(yytext+2); | 
|  | 395 | // +1:  we have bigger negative range | 
|  | 396 | if (Val > (uint64_t)INT32_MAX+1) | 
|  | 397 | error("Constant too large for signed 32 bits!"); | 
|  | 398 | Upgradelval.SIntVal = (int)-Val; | 
|  | 399 | return SINTVAL; | 
|  | 400 | } | 
|  | 401 |  | 
|  | 402 | {FPConstant}    { Upgradelval.FPVal = atof(yytext); return FPVAL; } | 
|  | 403 | {HexFPConstant} { Upgradelval.FPVal = HexToFP(yytext); return FPVAL; } | 
|  | 404 |  | 
|  | 405 | <<EOF>>         { | 
| Reid Spencer | 8e60eec | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 406 | /* Make sure to free the internal buffers for flex when we are | 
|  | 407 | * done reading our input! | 
|  | 408 | */ | 
|  | 409 | yy_delete_buffer(YY_CURRENT_BUFFER); | 
|  | 410 | return EOF; | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | [ \r\t\n]       { /* Ignore whitespace */ } | 
|  | 414 | .               { return yytext[0]; } | 
|  | 415 |  | 
|  | 416 | %% |