Chris Lattner | 32eecb0 | 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" |
Chris Lattner | 8e00832 | 2007-05-22 06:47:55 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 31 | #include <list> |
| 32 | #include "llvmAsmParser.h" |
| 33 | #include <cctype> |
| 34 | #include <cstdlib> |
| 35 | |
| 36 | void set_scan_file(FILE * F){ |
| 37 | yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) ); |
| 38 | } |
| 39 | void set_scan_string (const char * str) { |
| 40 | yy_scan_string (str); |
| 41 | } |
| 42 | |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 43 | // Construct a token value for a non-obsolete token |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 44 | #define RET_TOK(type, Enum, sym) \ |
Reid Spencer | a132e04 | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 45 | llvmAsmlval.type = Instruction::Enum; \ |
| 46 | return sym |
| 47 | |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 48 | // Construct a token value for an obsolete token |
Reid Spencer | a132e04 | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 49 | #define RET_TY(CTYPE, SYM) \ |
| 50 | llvmAsmlval.PrimType = CTYPE;\ |
Reid Spencer | 481169e | 2006-12-01 00:33:46 +0000 | [diff] [blame] | 51 | return SYM |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 52 | |
| 53 | namespace llvm { |
| 54 | |
| 55 | // TODO: All of the static identifiers are figured out by the lexer, |
| 56 | // these should be hashed to reduce the lexer size |
| 57 | |
| 58 | |
| 59 | // atoull - Convert an ascii string of decimal digits into the unsigned long |
| 60 | // long representation... this does not have to do input error checking, |
| 61 | // because we know that the input will be matched by a suitable regex... |
| 62 | // |
| 63 | static uint64_t atoull(const char *Buffer) { |
| 64 | uint64_t Result = 0; |
| 65 | for (; *Buffer; Buffer++) { |
| 66 | uint64_t OldRes = Result; |
| 67 | Result *= 10; |
| 68 | Result += *Buffer-'0'; |
| 69 | if (Result < OldRes) // Uh, oh, overflow detected!!! |
Reid Spencer | 61c83e0 | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 70 | GenerateError("constant bigger than 64 bits detected!"); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 71 | } |
| 72 | return Result; |
| 73 | } |
| 74 | |
| 75 | static uint64_t HexIntToVal(const char *Buffer) { |
| 76 | uint64_t Result = 0; |
| 77 | for (; *Buffer; ++Buffer) { |
| 78 | uint64_t OldRes = Result; |
| 79 | Result *= 16; |
| 80 | char C = *Buffer; |
| 81 | if (C >= '0' && C <= '9') |
| 82 | Result += C-'0'; |
| 83 | else if (C >= 'A' && C <= 'F') |
| 84 | Result += C-'A'+10; |
| 85 | else if (C >= 'a' && C <= 'f') |
| 86 | Result += C-'a'+10; |
| 87 | |
| 88 | if (Result < OldRes) // Uh, oh, overflow detected!!! |
Reid Spencer | 61c83e0 | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 89 | GenerateError("constant bigger than 64 bits detected!"); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 90 | } |
| 91 | return Result; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | // HexToFP - Convert the ascii string in hexidecimal format to the floating |
| 96 | // point representation of it. |
| 97 | // |
| 98 | static double HexToFP(const char *Buffer) { |
Chris Lattner | 8e00832 | 2007-05-22 06:47:55 +0000 | [diff] [blame] | 99 | return BitsToDouble(HexIntToVal(Buffer)); // Cast Hex constant to double |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | // UnEscapeLexed - Run through the specified buffer and change \xx codes to the |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 104 | // appropriate character. |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 105 | char *UnEscapeLexed(char *Buffer, char* EndBuffer) { |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 106 | char *BOut = Buffer; |
| 107 | for (char *BIn = Buffer; *BIn; ) { |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 108 | if (BIn[0] == '\\') { |
| 109 | if (BIn < EndBuffer-1 && BIn[1] == '\\') { |
| 110 | *BOut++ = '\\'; // Two \ becomes one |
| 111 | BIn += 2; |
| 112 | } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) { |
| 113 | char Tmp = BIn[3]; BIn[3] = 0; // Terminate string |
| 114 | *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number |
| 115 | BIn[3] = Tmp; // Restore character |
| 116 | BIn += 3; // Skip over handled chars |
| 117 | ++BOut; |
| 118 | } else { |
| 119 | *BOut++ = *BIn++; |
| 120 | } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 121 | } else { |
| 122 | *BOut++ = *BIn++; |
| 123 | } |
| 124 | } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 125 | return BOut; |
| 126 | } |
| 127 | |
| 128 | } // End llvm namespace |
| 129 | |
| 130 | using namespace llvm; |
| 131 | |
| 132 | #define YY_NEVER_INTERACTIVE 1 |
| 133 | %} |
| 134 | |
| 135 | |
| 136 | |
| 137 | /* Comments start with a ; and go till end of line */ |
| 138 | Comment ;.* |
| 139 | |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 140 | /* Local Values and Type identifiers start with a % sign */ |
| 141 | LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]* |
| 142 | |
| 143 | /* Global Value identifiers start with an @ sign */ |
| 144 | GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]* |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 145 | |
| 146 | /* Label identifiers end with a colon */ |
| 147 | Label [-a-zA-Z$._0-9]+: |
| 148 | QuoteLabel \"[^\"]+\": |
| 149 | |
| 150 | /* Quoted names can contain any character except " and \ */ |
| 151 | StringConstant \"[^\"]*\" |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 152 | AtStringConstant @\"[^\"]*\" |
Reid Spencer | ed951ea | 2007-05-19 07:22:10 +0000 | [diff] [blame] | 153 | PctStringConstant %\"[^\"]*\" |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 154 | |
| 155 | /* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */ |
| 156 | LocalVarID %[0-9]+ |
| 157 | GlobalVarID @[0-9]+ |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 158 | |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 159 | /* Integer types are specified with i and a bitwidth */ |
Reid Spencer | 4db2063 | 2007-01-12 07:28:27 +0000 | [diff] [blame] | 160 | IntegerType i[0-9]+ |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 161 | |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 162 | /* E[PN]Integer: match positive and negative literal integer values. */ |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 163 | PInteger [0-9]+ |
| 164 | NInteger -[0-9]+ |
| 165 | |
| 166 | /* FPConstant - A Floating point constant. |
| 167 | */ |
| 168 | FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)? |
| 169 | |
| 170 | /* HexFPConstant - Floating point constant represented in IEEE format as a |
| 171 | * hexadecimal number for when exponential notation is not precise enough. |
| 172 | */ |
| 173 | HexFPConstant 0x[0-9A-Fa-f]+ |
| 174 | |
| 175 | /* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing |
| 176 | * it to deal with 64 bit numbers. |
| 177 | */ |
| 178 | HexIntConstant [us]0x[0-9A-Fa-f]+ |
Reid Spencer | 38c91a9 | 2007-02-28 02:24:54 +0000 | [diff] [blame] | 179 | |
Reid Spencer | d8e616b | 2007-07-31 03:55:56 +0000 | [diff] [blame] | 180 | /* WSNL - shorthand for whitespace followed by newline */ |
| 181 | WSNL [ \r\t]*$ |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 182 | %% |
| 183 | |
| 184 | {Comment} { /* Ignore comments for now */ } |
| 185 | |
| 186 | begin { return BEGINTOK; } |
| 187 | end { return ENDTOK; } |
| 188 | true { return TRUETOK; } |
| 189 | false { return FALSETOK; } |
| 190 | declare { return DECLARE; } |
Reid Spencer | 6fd36ab | 2006-12-29 20:35:03 +0000 | [diff] [blame] | 191 | define { return DEFINE; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 192 | global { return GLOBAL; } |
| 193 | constant { return CONSTANT; } |
| 194 | internal { return INTERNAL; } |
| 195 | linkonce { return LINKONCE; } |
| 196 | weak { return WEAK; } |
| 197 | appending { return APPENDING; } |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 198 | dllimport { return DLLIMPORT; } |
| 199 | dllexport { return DLLEXPORT; } |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 200 | hidden { return HIDDEN; } |
Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 201 | protected { return PROTECTED; } |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 202 | extern_weak { return EXTERN_WEAK; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 203 | external { return EXTERNAL; } |
Lauro Ramos Venancio | c763552 | 2007-04-12 18:32:50 +0000 | [diff] [blame] | 204 | thread_local { return THREAD_LOCAL; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 205 | zeroinitializer { return ZEROINITIALIZER; } |
| 206 | \.\.\. { return DOTDOTDOT; } |
| 207 | undef { return UNDEF; } |
| 208 | null { return NULL_TOK; } |
| 209 | to { return TO; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 210 | tail { return TAIL; } |
| 211 | target { return TARGET; } |
| 212 | triple { return TRIPLE; } |
| 213 | deplibs { return DEPLIBS; } |
Chris Lattner | 1ae022f | 2006-10-22 06:08:13 +0000 | [diff] [blame] | 214 | datalayout { return DATALAYOUT; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 215 | volatile { return VOLATILE; } |
| 216 | align { return ALIGN; } |
| 217 | section { return SECTION; } |
Anton Korobeynikov | 77d0f97 | 2007-04-25 14:29:12 +0000 | [diff] [blame] | 218 | alias { return ALIAS; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 219 | module { return MODULE; } |
| 220 | asm { return ASM_TOK; } |
| 221 | sideeffect { return SIDEEFFECT; } |
| 222 | |
| 223 | cc { return CC_TOK; } |
| 224 | ccc { return CCC_TOK; } |
| 225 | fastcc { return FASTCC_TOK; } |
| 226 | coldcc { return COLDCC_TOK; } |
Anton Korobeynikov | bcb9770 | 2006-09-17 20:25:45 +0000 | [diff] [blame] | 227 | x86_stdcallcc { return X86_STDCALLCC_TOK; } |
| 228 | x86_fastcallcc { return X86_FASTCALLCC_TOK; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 229 | |
Reid Spencer | b8f8505 | 2007-07-31 03:50:36 +0000 | [diff] [blame] | 230 | signext { return SIGNEXT; } |
| 231 | zeroext { return ZEROEXT; } |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 232 | inreg { return INREG; } |
| 233 | sret { return SRET; } |
Reid Spencer | 67d8ed9 | 2007-03-22 02:14:08 +0000 | [diff] [blame] | 234 | nounwind { return NOUNWIND; } |
| 235 | noreturn { return NORETURN; } |
Chris Lattner | ce5f24e | 2007-07-05 17:26:49 +0000 | [diff] [blame] | 236 | noalias { return NOALIAS; } |
Reid Spencer | b8f8505 | 2007-07-31 03:50:36 +0000 | [diff] [blame] | 237 | byval { return BYVAL; } |
| 238 | nest { return NEST; } |
| 239 | sext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0 |
| 240 | return SIGNEXT; } |
| 241 | zext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0 |
| 242 | return ZEROEXT; } |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 243 | |
Reid Spencer | a132e04 | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 244 | void { RET_TY(Type::VoidTy, VOID); } |
Reid Spencer | a132e04 | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 245 | float { RET_TY(Type::FloatTy, FLOAT); } |
| 246 | double { RET_TY(Type::DoubleTy,DOUBLE);} |
| 247 | label { RET_TY(Type::LabelTy, LABEL); } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 248 | type { return TYPE; } |
| 249 | opaque { return OPAQUE; } |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 250 | {IntegerType} { uint64_t NumBits = atoull(yytext+1); |
| 251 | if (NumBits < IntegerType::MIN_INT_BITS || |
| 252 | NumBits > IntegerType::MAX_INT_BITS) |
| 253 | GenerateError("Bitwidth for integer type out of range!"); |
| 254 | const Type* Ty = IntegerType::get(NumBits); |
| 255 | RET_TY(Ty, INTTYPE); |
| 256 | } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 257 | |
| 258 | add { RET_TOK(BinaryOpVal, Add, ADD); } |
| 259 | sub { RET_TOK(BinaryOpVal, Sub, SUB); } |
| 260 | mul { RET_TOK(BinaryOpVal, Mul, MUL); } |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 261 | udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); } |
| 262 | sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); } |
| 263 | fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); } |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 264 | urem { RET_TOK(BinaryOpVal, URem, UREM); } |
| 265 | srem { RET_TOK(BinaryOpVal, SRem, SREM); } |
| 266 | frem { RET_TOK(BinaryOpVal, FRem, FREM); } |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 267 | shl { RET_TOK(BinaryOpVal, Shl, SHL); } |
| 268 | lshr { RET_TOK(BinaryOpVal, LShr, LSHR); } |
| 269 | ashr { RET_TOK(BinaryOpVal, AShr, ASHR); } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 270 | and { RET_TOK(BinaryOpVal, And, AND); } |
| 271 | or { RET_TOK(BinaryOpVal, Or , OR ); } |
| 272 | xor { RET_TOK(BinaryOpVal, Xor, XOR); } |
Reid Spencer | a132e04 | 2006-12-03 05:46:11 +0000 | [diff] [blame] | 273 | icmp { RET_TOK(OtherOpVal, ICmp, ICMP); } |
| 274 | fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); } |
Reid Spencer | 832254e | 2007-02-02 02:16:23 +0000 | [diff] [blame] | 275 | |
Reid Spencer | 6e18b7d | 2006-12-03 06:59:29 +0000 | [diff] [blame] | 276 | eq { return EQ; } |
| 277 | ne { return NE; } |
| 278 | slt { return SLT; } |
| 279 | sgt { return SGT; } |
| 280 | sle { return SLE; } |
| 281 | sge { return SGE; } |
| 282 | ult { return ULT; } |
| 283 | ugt { return UGT; } |
| 284 | ule { return ULE; } |
| 285 | uge { return UGE; } |
| 286 | oeq { return OEQ; } |
| 287 | one { return ONE; } |
| 288 | olt { return OLT; } |
| 289 | ogt { return OGT; } |
| 290 | ole { return OLE; } |
| 291 | oge { return OGE; } |
| 292 | ord { return ORD; } |
| 293 | uno { return UNO; } |
| 294 | ueq { return UEQ; } |
| 295 | une { return UNE; } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 296 | |
| 297 | phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); } |
| 298 | call { RET_TOK(OtherOpVal, Call, CALL); } |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 299 | trunc { RET_TOK(CastOpVal, Trunc, TRUNC); } |
| 300 | zext { RET_TOK(CastOpVal, ZExt, ZEXT); } |
| 301 | sext { RET_TOK(CastOpVal, SExt, SEXT); } |
| 302 | fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); } |
| 303 | fpext { RET_TOK(CastOpVal, FPExt, FPEXT); } |
| 304 | uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); } |
| 305 | sitofp { RET_TOK(CastOpVal, SIToFP, SITOFP); } |
| 306 | fptoui { RET_TOK(CastOpVal, FPToUI, FPTOUI); } |
| 307 | fptosi { RET_TOK(CastOpVal, FPToSI, FPTOSI); } |
| 308 | inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); } |
| 309 | ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); } |
| 310 | bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 311 | select { RET_TOK(OtherOpVal, Select, SELECT); } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 312 | va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); } |
| 313 | ret { RET_TOK(TermOpVal, Ret, RET); } |
| 314 | br { RET_TOK(TermOpVal, Br, BR); } |
| 315 | switch { RET_TOK(TermOpVal, Switch, SWITCH); } |
| 316 | invoke { RET_TOK(TermOpVal, Invoke, INVOKE); } |
| 317 | unwind { RET_TOK(TermOpVal, Unwind, UNWIND); } |
| 318 | unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); } |
| 319 | |
| 320 | malloc { RET_TOK(MemOpVal, Malloc, MALLOC); } |
| 321 | alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); } |
| 322 | free { RET_TOK(MemOpVal, Free, FREE); } |
| 323 | load { RET_TOK(MemOpVal, Load, LOAD); } |
| 324 | store { RET_TOK(MemOpVal, Store, STORE); } |
| 325 | getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); } |
| 326 | |
| 327 | extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); } |
| 328 | insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); } |
Chris Lattner | d5efe84 | 2006-04-08 01:18:56 +0000 | [diff] [blame] | 329 | shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 330 | |
| 331 | |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 332 | {LocalVarName} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 333 | llvmAsmlval.StrVal = new std::string(yytext+1); // Skip % |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 334 | return LOCALVAR; |
| 335 | } |
| 336 | {GlobalVarName} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 337 | llvmAsmlval.StrVal = new std::string(yytext+1); // Skip @ |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 338 | return GLOBALVAR; |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 339 | } |
| 340 | {Label} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 341 | yytext[yyleng-1] = 0; // nuke colon |
| 342 | llvmAsmlval.StrVal = new std::string(yytext); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 343 | return LABELSTR; |
| 344 | } |
| 345 | {QuoteLabel} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 346 | yytext[yyleng-2] = 0; // nuke colon, end quote |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 347 | const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng); |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 348 | llvmAsmlval.StrVal = |
| 349 | new std::string(yytext+1, EndChar - yytext - 1); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 350 | return LABELSTR; |
| 351 | } |
| 352 | |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 353 | {StringConstant} { yytext[yyleng-1] = 0; // nuke end quote |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 354 | const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng); |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 355 | llvmAsmlval.StrVal = |
| 356 | new std::string(yytext+1, EndChar - yytext - 1); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 357 | return STRINGCONSTANT; |
| 358 | } |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 359 | {AtStringConstant} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 360 | yytext[yyleng-1] = 0; // nuke end quote |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 361 | const char* EndChar = |
| 362 | UnEscapeLexed(yytext+2, yytext+yyleng); |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 363 | llvmAsmlval.StrVal = |
| 364 | new std::string(yytext+2, EndChar - yytext - 2); |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 365 | return ATSTRINGCONSTANT; |
| 366 | } |
Reid Spencer | ed951ea | 2007-05-19 07:22:10 +0000 | [diff] [blame] | 367 | {PctStringConstant} { |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 368 | yytext[yyleng-1] = 0; // nuke end quote |
Reid Spencer | e2aa961 | 2007-05-22 19:08:16 +0000 | [diff] [blame] | 369 | const char* EndChar = |
| 370 | UnEscapeLexed(yytext+2, yytext+yyleng); |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 371 | llvmAsmlval.StrVal = |
| 372 | new std::string(yytext+2, EndChar - yytext - 2); |
Reid Spencer | ed951ea | 2007-05-19 07:22:10 +0000 | [diff] [blame] | 373 | return PCTSTRINGCONSTANT; |
| 374 | } |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 375 | {PInteger} { |
| 376 | uint32_t numBits = ((yyleng * 64) / 19) + 1; |
| 377 | APInt Tmp(numBits, yytext, yyleng, 10); |
Reid Spencer | 38c91a9 | 2007-02-28 02:24:54 +0000 | [diff] [blame] | 378 | uint32_t activeBits = Tmp.getActiveBits(); |
| 379 | if (activeBits > 0 && activeBits < numBits) |
| 380 | Tmp.trunc(activeBits); |
| 381 | if (Tmp.getBitWidth() > 64) { |
| 382 | llvmAsmlval.APIntVal = new APInt(Tmp); |
| 383 | return EUAPINTVAL; |
| 384 | } else { |
| 385 | llvmAsmlval.UInt64Val = Tmp.getZExtValue(); |
| 386 | return EUINT64VAL; |
| 387 | } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 388 | } |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 389 | {NInteger} { |
| 390 | uint32_t numBits = (((yyleng-1) * 64) / 19) + 2; |
| 391 | APInt Tmp(numBits, yytext, yyleng, 10); |
Reid Spencer | 38c91a9 | 2007-02-28 02:24:54 +0000 | [diff] [blame] | 392 | uint32_t minBits = Tmp.getMinSignedBits(); |
| 393 | if (minBits > 0 && minBits < numBits) |
| 394 | Tmp.trunc(minBits); |
| 395 | if (Tmp.getBitWidth() > 64) { |
| 396 | llvmAsmlval.APIntVal = new APInt(Tmp); |
| 397 | return ESAPINTVAL; |
| 398 | } else { |
| 399 | llvmAsmlval.SInt64Val = Tmp.getSExtValue(); |
| 400 | return ESINT64VAL; |
| 401 | } |
| 402 | } |
| 403 | |
Reid Spencer | 0a8a16b | 2007-05-22 18:52:55 +0000 | [diff] [blame] | 404 | {HexIntConstant} { int len = yyleng - 3; |
Reid Spencer | 38c91a9 | 2007-02-28 02:24:54 +0000 | [diff] [blame] | 405 | uint32_t bits = len * 4; |
| 406 | APInt Tmp(bits, yytext+3, len, 16); |
| 407 | uint32_t activeBits = Tmp.getActiveBits(); |
| 408 | if (activeBits > 0 && activeBits < bits) |
| 409 | Tmp.trunc(activeBits); |
| 410 | if (Tmp.getBitWidth() > 64) { |
| 411 | llvmAsmlval.APIntVal = new APInt(Tmp); |
| 412 | return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL; |
| 413 | } else if (yytext[0] == 's') { |
| 414 | llvmAsmlval.SInt64Val = Tmp.getSExtValue(); |
| 415 | return ESINT64VAL; |
| 416 | } else { |
| 417 | llvmAsmlval.UInt64Val = Tmp.getZExtValue(); |
| 418 | return EUINT64VAL; |
| 419 | } |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 422 | {LocalVarID} { |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 423 | uint64_t Val = atoull(yytext+1); |
| 424 | if ((unsigned)Val != Val) |
Reid Spencer | 61c83e0 | 2006-08-18 08:43:06 +0000 | [diff] [blame] | 425 | GenerateError("Invalid value number (too large)!"); |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 426 | llvmAsmlval.UIntVal = unsigned(Val); |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 427 | return LOCALVAL_ID; |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 428 | } |
Reid Spencer | 41dff5e | 2007-01-26 08:05:27 +0000 | [diff] [blame] | 429 | {GlobalVarID} { |
| 430 | uint64_t Val = atoull(yytext+1); |
| 431 | if ((unsigned)Val != Val) |
| 432 | GenerateError("Invalid value number (too large)!"); |
| 433 | llvmAsmlval.UIntVal = unsigned(Val); |
| 434 | return GLOBALVAL_ID; |
Chris Lattner | 32eecb0 | 2006-02-14 05:14:46 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | {FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; } |
| 438 | {HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; } |
| 439 | |
| 440 | <<EOF>> { |
| 441 | /* Make sure to free the internal buffers for flex when we are |
| 442 | * done reading our input! |
| 443 | */ |
| 444 | yy_delete_buffer(YY_CURRENT_BUFFER); |
| 445 | return EOF; |
| 446 | } |
| 447 | |
| 448 | [ \r\t\n] { /* Ignore whitespace */ } |
| 449 | . { return yytext[0]; } |
| 450 | |
| 451 | %% |