| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 1 | /*===-- 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="llvmAsm" | 
|  | 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="Lexer.cpp" | 
|  | 23 | %option ecs | 
|  | 24 | %option noreject | 
|  | 25 | %option noyymore | 
|  | 26 |  | 
|  | 27 | %{ | 
|  | 28 | #include "ParserInternals.h" | 
|  | 29 | #include "llvm/Module.h" | 
|  | 30 | #include <list> | 
|  | 31 | #include "llvmAsmParser.h" | 
|  | 32 | #include <cctype> | 
|  | 33 | #include <cstdlib> | 
|  | 34 |  | 
|  | 35 | void set_scan_file(FILE * F){ | 
|  | 36 | yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) ); | 
|  | 37 | } | 
|  | 38 | void set_scan_string (const char * str) { | 
|  | 39 | yy_scan_string (str); | 
|  | 40 | } | 
|  | 41 |  | 
| Reid Spencer | de46e48 | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 42 | // Construct a token value for a non-obsolete token | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 43 | #define RET_TOK(type, Enum, sym) \ | 
| Reid Spencer | e2c32da | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 44 | llvmAsmlval.type = Instruction::Enum; \ | 
|  | 45 | return sym | 
|  | 46 |  | 
| Reid Spencer | de46e48 | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 47 | // Construct a token value for an obsolete token | 
| Reid Spencer | e2c32da | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 48 | #define RET_TY(CTYPE, SYM) \ | 
|  | 49 | llvmAsmlval.PrimType = CTYPE;\ | 
| Reid Spencer | d5e1944 | 2006-12-01 00:33:46 +0000 | [diff] [blame] | 50 | return SYM | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | namespace llvm { | 
|  | 53 |  | 
|  | 54 | // TODO: All of the static identifiers are figured out by the lexer, | 
|  | 55 | // these should be hashed to reduce the lexer size | 
|  | 56 |  | 
|  | 57 |  | 
|  | 58 | // atoull - Convert an ascii string of decimal digits into the unsigned long | 
|  | 59 | // long representation... this does not have to do input error checking, | 
|  | 60 | // because we know that the input will be matched by a suitable regex... | 
|  | 61 | // | 
|  | 62 | static uint64_t atoull(const char *Buffer) { | 
|  | 63 | uint64_t Result = 0; | 
|  | 64 | for (; *Buffer; Buffer++) { | 
|  | 65 | uint64_t OldRes = Result; | 
|  | 66 | Result *= 10; | 
|  | 67 | Result += *Buffer-'0'; | 
|  | 68 | if (Result < OldRes)   // Uh, oh, overflow detected!!! | 
| Reid Spencer | 713eedc | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 69 | GenerateError("constant bigger than 64 bits detected!"); | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 70 | } | 
|  | 71 | return Result; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | static uint64_t HexIntToVal(const char *Buffer) { | 
|  | 75 | uint64_t Result = 0; | 
|  | 76 | for (; *Buffer; ++Buffer) { | 
|  | 77 | uint64_t OldRes = Result; | 
|  | 78 | Result *= 16; | 
|  | 79 | char C = *Buffer; | 
|  | 80 | if (C >= '0' && C <= '9') | 
|  | 81 | Result += C-'0'; | 
|  | 82 | else if (C >= 'A' && C <= 'F') | 
|  | 83 | Result += C-'A'+10; | 
|  | 84 | else if (C >= 'a' && C <= 'f') | 
|  | 85 | Result += C-'a'+10; | 
|  | 86 |  | 
|  | 87 | if (Result < OldRes)   // Uh, oh, overflow detected!!! | 
| Reid Spencer | 713eedc | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 88 | GenerateError("constant bigger than 64 bits detected!"); | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 89 | } | 
|  | 90 | return Result; | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 |  | 
|  | 94 | // HexToFP - Convert the ascii string in hexidecimal format to the floating | 
|  | 95 | // point representation of it. | 
|  | 96 | // | 
|  | 97 | static double HexToFP(const char *Buffer) { | 
|  | 98 | // Behave nicely in the face of C TBAA rules... see: | 
|  | 99 | // http://www.nullstone.com/htmls/category/aliastyp.htm | 
|  | 100 | union { | 
|  | 101 | uint64_t UI; | 
|  | 102 | double FP; | 
|  | 103 | } UIntToFP; | 
|  | 104 | UIntToFP.UI = HexIntToVal(Buffer); | 
|  | 105 |  | 
|  | 106 | assert(sizeof(double) == sizeof(uint64_t) && | 
|  | 107 | "Data sizes incompatible on this target!"); | 
|  | 108 | return UIntToFP.FP;   // Cast Hex constant to double | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 |  | 
|  | 112 | // UnEscapeLexed - Run through the specified buffer and change \xx codes to the | 
|  | 113 | // appropriate character.  If AllowNull is set to false, a \00 value will cause | 
|  | 114 | // an exception to be thrown. | 
|  | 115 | // | 
|  | 116 | // If AllowNull is set to true, the return value of the function points to the | 
|  | 117 | // last character of the string in memory. | 
|  | 118 | // | 
|  | 119 | char *UnEscapeLexed(char *Buffer, bool AllowNull) { | 
|  | 120 | char *BOut = Buffer; | 
|  | 121 | for (char *BIn = Buffer; *BIn; ) { | 
|  | 122 | if (BIn[0] == '\\' && isxdigit(BIn[1]) && isxdigit(BIn[2])) { | 
|  | 123 | char Tmp = BIn[3]; BIn[3] = 0;     // Terminate string | 
|  | 124 | *BOut = (char)strtol(BIn+1, 0, 16);  // Convert to number | 
|  | 125 | if (!AllowNull && !*BOut) | 
| Reid Spencer | 713eedc | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 126 | GenerateError("String literal cannot accept \\00 escape!"); | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 127 |  | 
|  | 128 | BIn[3] = Tmp;                  // Restore character | 
|  | 129 | BIn += 3;                      // Skip over handled chars | 
|  | 130 | ++BOut; | 
|  | 131 | } else { | 
|  | 132 | *BOut++ = *BIn++; | 
|  | 133 | } | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | return BOut; | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | } // End llvm namespace | 
|  | 140 |  | 
|  | 141 | using namespace llvm; | 
|  | 142 |  | 
|  | 143 | #define YY_NEVER_INTERACTIVE 1 | 
|  | 144 | %} | 
|  | 145 |  | 
|  | 146 |  | 
|  | 147 |  | 
|  | 148 | /* Comments start with a ; and go till end of line */ | 
|  | 149 | Comment    ;.* | 
|  | 150 |  | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 151 | /* Local Values and Type identifiers start with a % sign */ | 
|  | 152 | LocalVarName       %[-a-zA-Z$._][-a-zA-Z$._0-9]* | 
|  | 153 |  | 
|  | 154 | /* Global Value identifiers start with an @ sign */ | 
|  | 155 | GlobalVarName       @[-a-zA-Z$._][-a-zA-Z$._0-9]* | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 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 \"[^\"]*\" | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 163 | AtStringConstant @\"[^\"]*\" | 
|  | 164 |  | 
|  | 165 | /* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */ | 
|  | 166 | LocalVarID     %[0-9]+ | 
|  | 167 | GlobalVarID    @[0-9]+ | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 168 |  | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 169 | /* Integer types are specified with i and a bitwidth */ | 
| Reid Spencer | b20ef92 | 2007-01-12 07:28:27 +0000 | [diff] [blame] | 170 | IntegerType i[0-9]+ | 
| Reid Spencer | 7a9c62b | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 171 |  | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 172 | /* E[PN]Integer: match positive and negative literal integer values. */ | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 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 |  | 
|  | 193 | begin           { return BEGINTOK; } | 
|  | 194 | end             { return ENDTOK; } | 
|  | 195 | true            { return TRUETOK;  } | 
|  | 196 | false           { return FALSETOK; } | 
|  | 197 | declare         { return DECLARE; } | 
| Reid Spencer | dc0a3a2 | 2006-12-29 20:35:03 +0000 | [diff] [blame] | 198 | define          { return DEFINE; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 199 | global          { return GLOBAL; } | 
|  | 200 | constant        { return CONSTANT; } | 
|  | 201 | internal        { return INTERNAL; } | 
|  | 202 | linkonce        { return LINKONCE; } | 
|  | 203 | weak            { return WEAK; } | 
|  | 204 | appending       { return APPENDING; } | 
| Anton Korobeynikov | d61d39e | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 205 | dllimport       { return DLLIMPORT; } | 
|  | 206 | dllexport       { return DLLEXPORT; } | 
| Anton Korobeynikov | a0554d9 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 207 | hidden          { return HIDDEN; } | 
| Anton Korobeynikov | d61d39e | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 208 | extern_weak     { return EXTERN_WEAK; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 209 | external        { return EXTERNAL; } | 
|  | 210 | implementation  { return IMPLEMENTATION; } | 
|  | 211 | zeroinitializer { return ZEROINITIALIZER; } | 
|  | 212 | \.\.\.          { return DOTDOTDOT; } | 
|  | 213 | undef           { return UNDEF; } | 
|  | 214 | null            { return NULL_TOK; } | 
|  | 215 | to              { return TO; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 216 | tail            { return TAIL; } | 
|  | 217 | target          { return TARGET; } | 
|  | 218 | triple          { return TRIPLE; } | 
|  | 219 | deplibs         { return DEPLIBS; } | 
| Chris Lattner | 7d1d034 | 2006-10-22 06:08:13 +0000 | [diff] [blame] | 220 | datalayout      { return DATALAYOUT; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 221 | volatile        { return VOLATILE; } | 
|  | 222 | align           { return ALIGN;  } | 
|  | 223 | section         { return SECTION; } | 
|  | 224 | module          { return MODULE; } | 
|  | 225 | asm             { return ASM_TOK; } | 
|  | 226 | sideeffect      { return SIDEEFFECT; } | 
|  | 227 |  | 
|  | 228 | cc              { return CC_TOK; } | 
|  | 229 | ccc             { return CCC_TOK; } | 
|  | 230 | fastcc          { return FASTCC_TOK; } | 
|  | 231 | coldcc          { return COLDCC_TOK; } | 
| Anton Korobeynikov | 6f7072c | 2006-09-17 20:25:45 +0000 | [diff] [blame] | 232 | x86_stdcallcc   { return X86_STDCALLCC_TOK; } | 
|  | 233 | x86_fastcallcc  { return X86_FASTCALLCC_TOK; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 234 |  | 
| Reid Spencer | 2341c22 | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 235 | inreg           { return INREG; } | 
|  | 236 | sret            { return SRET;  } | 
|  | 237 |  | 
| Reid Spencer | e2c32da | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 238 | void            { RET_TY(Type::VoidTy,  VOID);  } | 
| Reid Spencer | e2c32da | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 239 | float           { RET_TY(Type::FloatTy, FLOAT); } | 
|  | 240 | double          { RET_TY(Type::DoubleTy,DOUBLE);} | 
|  | 241 | label           { RET_TY(Type::LabelTy, LABEL); } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 242 | type            { return TYPE;   } | 
|  | 243 | opaque          { return OPAQUE; } | 
| Reid Spencer | 7a9c62b | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 244 | {IntegerType}   { uint64_t NumBits = atoull(yytext+1); | 
|  | 245 | if (NumBits < IntegerType::MIN_INT_BITS || | 
|  | 246 | NumBits > IntegerType::MAX_INT_BITS) | 
|  | 247 | GenerateError("Bitwidth for integer type out of range!"); | 
|  | 248 | const Type* Ty = IntegerType::get(NumBits); | 
|  | 249 | RET_TY(Ty, INTTYPE); | 
|  | 250 | } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 251 |  | 
|  | 252 | add             { RET_TOK(BinaryOpVal, Add, ADD); } | 
|  | 253 | sub             { RET_TOK(BinaryOpVal, Sub, SUB); } | 
|  | 254 | mul             { RET_TOK(BinaryOpVal, Mul, MUL); } | 
| Reid Spencer | de46e48 | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 255 | udiv            { RET_TOK(BinaryOpVal, UDiv, UDIV); } | 
|  | 256 | sdiv            { RET_TOK(BinaryOpVal, SDiv, SDIV); } | 
|  | 257 | fdiv            { RET_TOK(BinaryOpVal, FDiv, FDIV); } | 
| Reid Spencer | de46e48 | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 258 | urem            { RET_TOK(BinaryOpVal, URem, UREM); } | 
|  | 259 | srem            { RET_TOK(BinaryOpVal, SRem, SREM); } | 
|  | 260 | frem            { RET_TOK(BinaryOpVal, FRem, FREM); } | 
| Reid Spencer | 2341c22 | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 261 | shl             { RET_TOK(BinaryOpVal, Shl, SHL); } | 
|  | 262 | lshr            { RET_TOK(BinaryOpVal, LShr, LSHR); } | 
|  | 263 | ashr            { RET_TOK(BinaryOpVal, AShr, ASHR); } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 264 | and             { RET_TOK(BinaryOpVal, And, AND); } | 
|  | 265 | or              { RET_TOK(BinaryOpVal, Or , OR ); } | 
|  | 266 | xor             { RET_TOK(BinaryOpVal, Xor, XOR); } | 
| Reid Spencer | e2c32da | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 267 | icmp            { RET_TOK(OtherOpVal,  ICmp,  ICMP); } | 
|  | 268 | fcmp            { RET_TOK(OtherOpVal,  FCmp,  FCMP); } | 
| Reid Spencer | 2341c22 | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 269 |  | 
| Reid Spencer | 1960ef3 | 2006-12-03 06:59:29 +0000 | [diff] [blame] | 270 | eq              { return EQ;  } | 
|  | 271 | ne              { return NE;  } | 
|  | 272 | slt             { return SLT; } | 
|  | 273 | sgt             { return SGT; } | 
|  | 274 | sle             { return SLE; } | 
|  | 275 | sge             { return SGE; } | 
|  | 276 | ult             { return ULT; } | 
|  | 277 | ugt             { return UGT; } | 
|  | 278 | ule             { return ULE; } | 
|  | 279 | uge             { return UGE; } | 
|  | 280 | oeq             { return OEQ; } | 
|  | 281 | one             { return ONE; } | 
|  | 282 | olt             { return OLT; } | 
|  | 283 | ogt             { return OGT; } | 
|  | 284 | ole             { return OLE; } | 
|  | 285 | oge             { return OGE; } | 
|  | 286 | ord             { return ORD; } | 
|  | 287 | uno             { return UNO; } | 
|  | 288 | ueq             { return UEQ; } | 
|  | 289 | une             { return UNE; } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 290 |  | 
|  | 291 | phi             { RET_TOK(OtherOpVal, PHI, PHI_TOK); } | 
|  | 292 | call            { RET_TOK(OtherOpVal, Call, CALL); } | 
| Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 293 | trunc           { RET_TOK(CastOpVal, Trunc, TRUNC); } | 
|  | 294 | zext            { RET_TOK(CastOpVal, ZExt, ZEXT); } | 
|  | 295 | sext            { RET_TOK(CastOpVal, SExt, SEXT); } | 
|  | 296 | fptrunc         { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); } | 
|  | 297 | fpext           { RET_TOK(CastOpVal, FPExt, FPEXT); } | 
|  | 298 | uitofp          { RET_TOK(CastOpVal, UIToFP, UITOFP); } | 
|  | 299 | sitofp          { RET_TOK(CastOpVal, SIToFP, SITOFP); } | 
|  | 300 | fptoui          { RET_TOK(CastOpVal, FPToUI, FPTOUI); } | 
|  | 301 | fptosi          { RET_TOK(CastOpVal, FPToSI, FPTOSI); } | 
|  | 302 | inttoptr        { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); } | 
|  | 303 | ptrtoint        { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); } | 
|  | 304 | bitcast         { RET_TOK(CastOpVal, BitCast, BITCAST); } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 305 | select          { RET_TOK(OtherOpVal, Select, SELECT); } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 306 | va_arg          { RET_TOK(OtherOpVal, VAArg , VAARG); } | 
|  | 307 | ret             { RET_TOK(TermOpVal, Ret, RET); } | 
|  | 308 | br              { RET_TOK(TermOpVal, Br, BR); } | 
|  | 309 | switch          { RET_TOK(TermOpVal, Switch, SWITCH); } | 
|  | 310 | invoke          { RET_TOK(TermOpVal, Invoke, INVOKE); } | 
|  | 311 | unwind          { RET_TOK(TermOpVal, Unwind, UNWIND); } | 
|  | 312 | unreachable     { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); } | 
|  | 313 |  | 
|  | 314 | malloc          { RET_TOK(MemOpVal, Malloc, MALLOC); } | 
|  | 315 | alloca          { RET_TOK(MemOpVal, Alloca, ALLOCA); } | 
|  | 316 | free            { RET_TOK(MemOpVal, Free, FREE); } | 
|  | 317 | load            { RET_TOK(MemOpVal, Load, LOAD); } | 
|  | 318 | store           { RET_TOK(MemOpVal, Store, STORE); } | 
|  | 319 | getelementptr   { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); } | 
|  | 320 |  | 
|  | 321 | extractelement  { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); } | 
|  | 322 | insertelement   { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); } | 
| Chris Lattner | 9ff96a7 | 2006-04-08 01:18:56 +0000 | [diff] [blame] | 323 | shufflevector   { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); } | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 324 |  | 
|  | 325 |  | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 326 | {LocalVarName}  { | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 327 | UnEscapeLexed(yytext+1); | 
|  | 328 | llvmAsmlval.StrVal = strdup(yytext+1);             // Skip % | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 329 | return LOCALVAR; | 
|  | 330 | } | 
|  | 331 | {GlobalVarName} { | 
|  | 332 | UnEscapeLexed(yytext+1); | 
|  | 333 | llvmAsmlval.StrVal = strdup(yytext+1);             // Skip @ | 
|  | 334 | return GLOBALVAR; | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 335 | } | 
|  | 336 | {Label}         { | 
|  | 337 | yytext[strlen(yytext)-1] = 0;  // nuke colon | 
|  | 338 | UnEscapeLexed(yytext); | 
|  | 339 | llvmAsmlval.StrVal = strdup(yytext); | 
|  | 340 | return LABELSTR; | 
|  | 341 | } | 
|  | 342 | {QuoteLabel}    { | 
|  | 343 | yytext[strlen(yytext)-2] = 0;  // nuke colon, end quote | 
|  | 344 | UnEscapeLexed(yytext+1); | 
|  | 345 | llvmAsmlval.StrVal = strdup(yytext+1); | 
|  | 346 | return LABELSTR; | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | {StringConstant} { // Note that we cannot unescape a string constant here!  The | 
|  | 350 | // string constant might contain a \00 which would not be | 
|  | 351 | // understood by the string stuff.  It is valid to make a | 
|  | 352 | // [sbyte] c"Hello World\00" constant, for example. | 
|  | 353 | // | 
|  | 354 | yytext[strlen(yytext)-1] = 0;           // nuke end quote | 
|  | 355 | llvmAsmlval.StrVal = strdup(yytext+1);  // Nuke start quote | 
|  | 356 | return STRINGCONSTANT; | 
|  | 357 | } | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 358 | {AtStringConstant} { | 
|  | 359 | yytext[strlen(yytext)-1] = 0;           // nuke end quote | 
|  | 360 | llvmAsmlval.StrVal = strdup(yytext+2);  // Nuke @, quote | 
|  | 361 | return ATSTRINGCONSTANT; | 
|  | 362 | } | 
|  | 363 |  | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 364 |  | 
|  | 365 |  | 
|  | 366 | {PInteger}      { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; } | 
|  | 367 | {NInteger}      { | 
|  | 368 | uint64_t Val = atoull(yytext+1); | 
|  | 369 | // +1:  we have bigger negative range | 
|  | 370 | if (Val > (uint64_t)INT64_MAX+1) | 
| Reid Spencer | 713eedc | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 371 | GenerateError("Constant too large for signed 64 bits!"); | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 372 | llvmAsmlval.SInt64Val = -Val; | 
|  | 373 | return ESINT64VAL; | 
|  | 374 | } | 
|  | 375 | {HexIntConstant} { | 
|  | 376 | llvmAsmlval.UInt64Val = HexIntToVal(yytext+3); | 
|  | 377 | return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL; | 
|  | 378 | } | 
|  | 379 |  | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 380 | {LocalVarID}     { | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 381 | uint64_t Val = atoull(yytext+1); | 
|  | 382 | if ((unsigned)Val != Val) | 
| Reid Spencer | 713eedc | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 383 | GenerateError("Invalid value number (too large)!"); | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 384 | llvmAsmlval.UIntVal = unsigned(Val); | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 385 | return LOCALVAL_ID; | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 386 | } | 
| Reid Spencer | 8d6d4b8e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 387 | {GlobalVarID}   { | 
|  | 388 | uint64_t Val = atoull(yytext+1); | 
|  | 389 | if ((unsigned)Val != Val) | 
|  | 390 | GenerateError("Invalid value number (too large)!"); | 
|  | 391 | llvmAsmlval.UIntVal = unsigned(Val); | 
|  | 392 | return GLOBALVAL_ID; | 
| Chris Lattner | 0242688 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 393 | } | 
|  | 394 |  | 
|  | 395 | {FPConstant}    { llvmAsmlval.FPVal = atof(yytext); return FPVAL; } | 
|  | 396 | {HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; } | 
|  | 397 |  | 
|  | 398 | <<EOF>>         { | 
|  | 399 | /* Make sure to free the internal buffers for flex when we are | 
|  | 400 | * done reading our input! | 
|  | 401 | */ | 
|  | 402 | yy_delete_buffer(YY_CURRENT_BUFFER); | 
|  | 403 | return EOF; | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | [ \r\t\n]       { /* Ignore whitespace */ } | 
|  | 407 | .               { return yytext[0]; } | 
|  | 408 |  | 
|  | 409 | %% |