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