Chris Lattner | 699f1eb | 2002-08-14 17:12:33 +0000 | [diff] [blame] | 1 | /*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===// |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 2 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 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. |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 7 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the flex scanner for LLVM assembly languages files. |
| 11 | // |
Chris Lattner | 699f1eb | 2002-08-14 17:12:33 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===*/ |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 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" |
Chris Lattner | b9bcbb5 | 2003-04-22 19:07:06 +0000 | [diff] [blame] | 29 | #include "llvm/Module.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 30 | #include <list> |
| 31 | #include "llvmAsmParser.h" |
Brian Gaeke | 778fab2 | 2003-10-10 19:12:08 +0000 | [diff] [blame] | 32 | #include <cctype> |
| 33 | #include <cstdlib> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 6184feb | 2005-05-20 03:25:47 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 42 | #define RET_TOK(type, Enum, sym) \ |
| 43 | llvmAsmlval.type = Instruction::Enum; return sym |
| 44 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 45 | namespace llvm { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 46 | |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 47 | // TODO: All of the static identifiers are figured out by the lexer, |
Chris Lattner | e1fe875 | 2001-09-07 16:32:43 +0000 | [diff] [blame] | 48 | // these should be hashed to reduce the lexer size |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | // atoull - Convert an ascii string of decimal digits into the unsigned long |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 52 | // long representation... this does not have to do input error checking, |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 53 | // because we know that the input will be matched by a suitable regex... |
| 54 | // |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 55 | static uint64_t atoull(const char *Buffer) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 56 | uint64_t Result = 0; |
| 57 | for (; *Buffer; Buffer++) { |
| 58 | uint64_t OldRes = Result; |
| 59 | Result *= 10; |
| 60 | Result += *Buffer-'0'; |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 61 | if (Result < OldRes) // Uh, oh, overflow detected!!! |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 62 | ThrowException("constant bigger than 64 bits detected!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 63 | } |
| 64 | return Result; |
| 65 | } |
| 66 | |
Chris Lattner | 3e8ba10 | 2003-04-17 22:17:32 +0000 | [diff] [blame] | 67 | static uint64_t HexIntToVal(const char *Buffer) { |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 68 | uint64_t Result = 0; |
| 69 | for (; *Buffer; ++Buffer) { |
| 70 | uint64_t OldRes = Result; |
| 71 | Result *= 16; |
| 72 | char C = *Buffer; |
| 73 | if (C >= '0' && C <= '9') |
| 74 | Result += C-'0'; |
| 75 | else if (C >= 'A' && C <= 'F') |
| 76 | Result += C-'A'+10; |
| 77 | else if (C >= 'a' && C <= 'f') |
| 78 | Result += C-'a'+10; |
| 79 | |
| 80 | if (Result < OldRes) // Uh, oh, overflow detected!!! |
| 81 | ThrowException("constant bigger than 64 bits detected!"); |
| 82 | } |
Chris Lattner | 3e8ba10 | 2003-04-17 22:17:32 +0000 | [diff] [blame] | 83 | return Result; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | // HexToFP - Convert the ascii string in hexidecimal format to the floating |
| 88 | // point representation of it. |
| 89 | // |
| 90 | static double HexToFP(const char *Buffer) { |
Chris Lattner | b55679d | 2002-04-07 08:31:26 +0000 | [diff] [blame] | 91 | // Behave nicely in the face of C TBAA rules... see: |
| 92 | // http://www.nullstone.com/htmls/category/aliastyp.htm |
Chris Lattner | 7a5a1f7 | 2003-04-22 20:20:28 +0000 | [diff] [blame] | 93 | union { |
| 94 | uint64_t UI; |
| 95 | double FP; |
| 96 | } UIntToFP; |
| 97 | UIntToFP.UI = HexIntToVal(Buffer); |
| 98 | |
| 99 | assert(sizeof(double) == sizeof(uint64_t) && |
| 100 | "Data sizes incompatible on this target!"); |
| 101 | return UIntToFP.FP; // Cast Hex constant to double |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 105 | // UnEscapeLexed - Run through the specified buffer and change \xx codes to the |
| 106 | // appropriate character. If AllowNull is set to false, a \00 value will cause |
| 107 | // an exception to be thrown. |
| 108 | // |
| 109 | // If AllowNull is set to true, the return value of the function points to the |
| 110 | // last character of the string in memory. |
| 111 | // |
Chris Lattner | bcafcce | 2002-07-25 06:17:42 +0000 | [diff] [blame] | 112 | char *UnEscapeLexed(char *Buffer, bool AllowNull) { |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 113 | char *BOut = Buffer; |
| 114 | for (char *BIn = Buffer; *BIn; ) { |
| 115 | if (BIn[0] == '\\' && isxdigit(BIn[1]) && isxdigit(BIn[2])) { |
| 116 | char Tmp = BIn[3]; BIn[3] = 0; // Terminate string |
Chris Lattner | a8101c1 | 2005-01-08 20:07:03 +0000 | [diff] [blame] | 117 | *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 118 | if (!AllowNull && !*BOut) |
| 119 | ThrowException("String literal cannot accept \\00 escape!"); |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 121 | BIn[3] = Tmp; // Restore character |
| 122 | BIn += 3; // Skip over handled chars |
| 123 | ++BOut; |
| 124 | } else { |
| 125 | *BOut++ = *BIn++; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return BOut; |
| 130 | } |
| 131 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 132 | } // End llvm namespace |
| 133 | |
| 134 | using namespace llvm; |
| 135 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 136 | #define YY_NEVER_INTERACTIVE 1 |
| 137 | %} |
| 138 | |
| 139 | |
| 140 | |
| 141 | /* Comments start with a ; and go till end of line */ |
| 142 | Comment ;.* |
| 143 | |
Chris Lattner | e181564 | 2001-07-15 06:35:53 +0000 | [diff] [blame] | 144 | /* Variable(Value) identifiers start with a % sign */ |
Chris Lattner | 9a88d27 | 2001-12-04 04:31:30 +0000 | [diff] [blame] | 145 | VarID %[-a-zA-Z$._][-a-zA-Z$._0-9]* |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 146 | |
| 147 | /* Label identifiers end with a colon */ |
Chris Lattner | 9a88d27 | 2001-12-04 04:31:30 +0000 | [diff] [blame] | 148 | Label [-a-zA-Z$._0-9]+: |
Alkis Evlogimenos | d82ef51 | 2004-12-10 05:40:19 +0000 | [diff] [blame] | 149 | QuoteLabel \"[^\"]+\": |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 150 | |
| 151 | /* Quoted names can contain any character except " and \ */ |
Chris Lattner | 99e7ab7 | 2003-10-18 05:53:13 +0000 | [diff] [blame] | 152 | StringConstant \"[^\"]*\" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 153 | |
| 154 | |
| 155 | /* [PN]Integer: match positive and negative literal integer values that |
| 156 | * are preceeded by a '%' character. These represent unnamed variable slots. |
| 157 | */ |
| 158 | EPInteger %[0-9]+ |
| 159 | ENInteger %-[0-9]+ |
| 160 | |
| 161 | |
| 162 | /* E[PN]Integer: match positive and negative literal integer values */ |
| 163 | PInteger [0-9]+ |
| 164 | NInteger -[0-9]+ |
| 165 | |
Chris Lattner | 3d52b2f | 2001-07-15 00:17:01 +0000 | [diff] [blame] | 166 | /* FPConstant - A Floating point constant. |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 167 | */ |
Chris Lattner | 1e2c614 | 2001-11-01 22:06:08 +0000 | [diff] [blame] | 168 | FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)? |
Chris Lattner | 3d52b2f | 2001-07-15 00:17:01 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 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]+ |
Chris Lattner | 3e8ba10 | 2003-04-17 22:17:32 +0000 | [diff] [blame] | 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]+ |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 179 | %% |
| 180 | |
| 181 | {Comment} { /* Ignore comments for now */ } |
| 182 | |
| 183 | begin { return BEGINTOK; } |
Chris Lattner | 9b02cc3 | 2002-05-03 18:23:48 +0000 | [diff] [blame] | 184 | end { return ENDTOK; } |
Chris Lattner | 91ef460 | 2004-03-31 03:49:47 +0000 | [diff] [blame] | 185 | true { return TRUETOK; } |
| 186 | false { return FALSETOK; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 187 | declare { return DECLARE; } |
Chris Lattner | 70cc339 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 188 | global { return GLOBAL; } |
Chris Lattner | 1781aca | 2001-09-18 04:00:54 +0000 | [diff] [blame] | 189 | constant { return CONSTANT; } |
Chris Lattner | dda7196 | 2001-11-26 18:54:16 +0000 | [diff] [blame] | 190 | internal { return INTERNAL; } |
Chris Lattner | 4ad02e7 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 191 | linkonce { return LINKONCE; } |
Chris Lattner | f797cab | 2003-10-10 04:54:02 +0000 | [diff] [blame] | 192 | weak { return WEAK; } |
Chris Lattner | 4ad02e7 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 193 | appending { return APPENDING; } |
Chris Lattner | 08c0e6a | 2002-10-06 22:45:09 +0000 | [diff] [blame] | 194 | uninitialized { return EXTERNAL; } /* Deprecated, turn into external */ |
| 195 | external { return EXTERNAL; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 196 | implementation { return IMPLEMENTATION; } |
Chris Lattner | f460048 | 2003-06-28 20:01:34 +0000 | [diff] [blame] | 197 | zeroinitializer { return ZEROINITIALIZER; } |
Chris Lattner | 8b81bf5 | 2001-07-25 22:47:46 +0000 | [diff] [blame] | 198 | \.\.\. { return DOTDOTDOT; } |
Chris Lattner | 16710e9 | 2004-10-16 18:17:13 +0000 | [diff] [blame] | 199 | undef { return UNDEF; } |
Chris Lattner | 1a1cb11 | 2001-09-30 22:46:54 +0000 | [diff] [blame] | 200 | null { return NULL_TOK; } |
Chris Lattner | 5efbbc2 | 2001-10-13 06:37:14 +0000 | [diff] [blame] | 201 | to { return TO; } |
Chris Lattner | a58e3a1 | 2004-02-08 21:48:25 +0000 | [diff] [blame] | 202 | except { RET_TOK(TermOpVal, Unwind, UNWIND); } |
Chris Lattner | 699f1eb | 2002-08-14 17:12:33 +0000 | [diff] [blame] | 203 | not { return NOT; } /* Deprecated, turned into XOR */ |
Chris Lattner | c28ade4 | 2005-05-06 06:20:33 +0000 | [diff] [blame] | 204 | tail { return TAIL; } |
Chris Lattner | b9bcbb5 | 2003-04-22 19:07:06 +0000 | [diff] [blame] | 205 | target { return TARGET; } |
Reid Spencer | 3cd2fe3 | 2004-07-25 17:56:00 +0000 | [diff] [blame] | 206 | triple { return TRIPLE; } |
| 207 | deplibs { return DEPLIBS; } |
Chris Lattner | b9bcbb5 | 2003-04-22 19:07:06 +0000 | [diff] [blame] | 208 | endian { return ENDIAN; } |
| 209 | pointersize { return POINTERSIZE; } |
| 210 | little { return LITTLE; } |
| 211 | big { return BIG; } |
Chris Lattner | 15c9c03 | 2003-09-08 18:20:29 +0000 | [diff] [blame] | 212 | volatile { return VOLATILE; } |
Chris Lattner | b7d08a5 | 2005-11-12 00:11:30 +0000 | [diff] [blame] | 213 | align { return ALIGN; } |
| 214 | section { return SECTION; } |
Chris Lattner | 71cdba3 | 2006-01-24 00:40:17 +0000 | [diff] [blame] | 215 | module { return MODULE; } |
Chris Lattner | ee45477 | 2006-01-23 23:05:15 +0000 | [diff] [blame] | 216 | asm { return ASM_TOK; } |
Chris Lattner | aa2c853 | 2006-01-25 22:26:43 +0000 | [diff] [blame] | 217 | sideeffect { return SIDEEFFECT; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 218 | |
Chris Lattner | a8e8f16 | 2005-05-06 20:27:19 +0000 | [diff] [blame] | 219 | cc { return CC_TOK; } |
| 220 | ccc { return CCC_TOK; } |
| 221 | fastcc { return FASTCC_TOK; } |
| 222 | coldcc { return COLDCC_TOK; } |
| 223 | |
Chris Lattner | e1fe875 | 2001-09-07 16:32:43 +0000 | [diff] [blame] | 224 | void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; } |
| 225 | bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; } |
| 226 | sbyte { llvmAsmlval.PrimType = Type::SByteTy ; return SBYTE; } |
| 227 | ubyte { llvmAsmlval.PrimType = Type::UByteTy ; return UBYTE; } |
| 228 | short { llvmAsmlval.PrimType = Type::ShortTy ; return SHORT; } |
| 229 | ushort { llvmAsmlval.PrimType = Type::UShortTy; return USHORT; } |
| 230 | int { llvmAsmlval.PrimType = Type::IntTy ; return INT; } |
| 231 | uint { llvmAsmlval.PrimType = Type::UIntTy ; return UINT; } |
| 232 | long { llvmAsmlval.PrimType = Type::LongTy ; return LONG; } |
| 233 | ulong { llvmAsmlval.PrimType = Type::ULongTy ; return ULONG; } |
| 234 | float { llvmAsmlval.PrimType = Type::FloatTy ; return FLOAT; } |
| 235 | double { llvmAsmlval.PrimType = Type::DoubleTy; return DOUBLE; } |
Chris Lattner | e1fe875 | 2001-09-07 16:32:43 +0000 | [diff] [blame] | 236 | label { llvmAsmlval.PrimType = Type::LabelTy ; return LABEL; } |
Reid Spencer | 77f4d86 | 2004-07-04 12:17:44 +0000 | [diff] [blame] | 237 | type { return TYPE; } |
Chris Lattner | 4e4cae8 | 2002-04-04 19:22:17 +0000 | [diff] [blame] | 238 | opaque { return OPAQUE; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 239 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 240 | add { RET_TOK(BinaryOpVal, Add, ADD); } |
| 241 | sub { RET_TOK(BinaryOpVal, Sub, SUB); } |
| 242 | mul { RET_TOK(BinaryOpVal, Mul, MUL); } |
| 243 | div { RET_TOK(BinaryOpVal, Div, DIV); } |
| 244 | rem { RET_TOK(BinaryOpVal, Rem, REM); } |
Chris Lattner | 42c9e77 | 2001-10-20 09:32:59 +0000 | [diff] [blame] | 245 | and { RET_TOK(BinaryOpVal, And, AND); } |
| 246 | or { RET_TOK(BinaryOpVal, Or , OR ); } |
| 247 | xor { RET_TOK(BinaryOpVal, Xor, XOR); } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 248 | setne { RET_TOK(BinaryOpVal, SetNE, SETNE); } |
| 249 | seteq { RET_TOK(BinaryOpVal, SetEQ, SETEQ); } |
| 250 | setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); } |
| 251 | setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); } |
| 252 | setle { RET_TOK(BinaryOpVal, SetLE, SETLE); } |
| 253 | setge { RET_TOK(BinaryOpVal, SetGE, SETGE); } |
| 254 | |
Chris Lattner | 3b237fc | 2003-10-19 21:34:28 +0000 | [diff] [blame] | 255 | phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); } |
Chris Lattner | 027dcc5 | 2001-07-08 21:10:27 +0000 | [diff] [blame] | 256 | call { RET_TOK(OtherOpVal, Call, CALL); } |
| 257 | cast { RET_TOK(OtherOpVal, Cast, CAST); } |
Chris Lattner | 76f0ff3 | 2004-03-12 05:51:36 +0000 | [diff] [blame] | 258 | select { RET_TOK(OtherOpVal, Select, SELECT); } |
Chris Lattner | 027dcc5 | 2001-07-08 21:10:27 +0000 | [diff] [blame] | 259 | shl { RET_TOK(OtherOpVal, Shl, SHL); } |
| 260 | shr { RET_TOK(OtherOpVal, Shr, SHR); } |
Andrew Lenharth | 558bc88 | 2005-06-18 18:34:52 +0000 | [diff] [blame] | 261 | vanext { return VANEXT_old; } |
| 262 | vaarg { return VAARG_old; } |
| 263 | va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 264 | ret { RET_TOK(TermOpVal, Ret, RET); } |
| 265 | br { RET_TOK(TermOpVal, Br, BR); } |
| 266 | switch { RET_TOK(TermOpVal, Switch, SWITCH); } |
Chris Lattner | 5efbbc2 | 2001-10-13 06:37:14 +0000 | [diff] [blame] | 267 | invoke { RET_TOK(TermOpVal, Invoke, INVOKE); } |
Chris Lattner | 36143fc | 2003-09-08 18:54:55 +0000 | [diff] [blame] | 268 | unwind { RET_TOK(TermOpVal, Unwind, UNWIND); } |
Chris Lattner | 16710e9 | 2004-10-16 18:17:13 +0000 | [diff] [blame] | 269 | unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 270 | |
| 271 | malloc { RET_TOK(MemOpVal, Malloc, MALLOC); } |
| 272 | alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); } |
| 273 | free { RET_TOK(MemOpVal, Free, FREE); } |
| 274 | load { RET_TOK(MemOpVal, Load, LOAD); } |
| 275 | store { RET_TOK(MemOpVal, Store, STORE); } |
Chris Lattner | ab5ac6b | 2001-07-08 23:22:50 +0000 | [diff] [blame] | 276 | getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 277 | |
Robert Bocchino | 9c62b56 | 2006-01-10 19:04:32 +0000 | [diff] [blame] | 278 | extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); } |
Robert Bocchino | 2def1b3 | 2006-01-17 20:06:25 +0000 | [diff] [blame] | 279 | insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); } |
Chris Lattner | 4c94908 | 2006-04-08 01:18:35 +0000 | [diff] [blame] | 280 | shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); } |
Robert Bocchino | 9c62b56 | 2006-01-10 19:04:32 +0000 | [diff] [blame] | 281 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 283 | {VarID} { |
| 284 | UnEscapeLexed(yytext+1); |
| 285 | llvmAsmlval.StrVal = strdup(yytext+1); // Skip % |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 286 | return VAR_ID; |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 287 | } |
| 288 | {Label} { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 289 | yytext[strlen(yytext)-1] = 0; // nuke colon |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 290 | UnEscapeLexed(yytext); |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 291 | llvmAsmlval.StrVal = strdup(yytext); |
| 292 | return LABELSTR; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 293 | } |
Chris Lattner | c6c9772 | 2004-12-10 05:27:29 +0000 | [diff] [blame] | 294 | {QuoteLabel} { |
| 295 | yytext[strlen(yytext)-2] = 0; // nuke colon, end quote |
| 296 | UnEscapeLexed(yytext+1); |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 297 | llvmAsmlval.StrVal = strdup(yytext+1); |
| 298 | return LABELSTR; |
Chris Lattner | c6c9772 | 2004-12-10 05:27:29 +0000 | [diff] [blame] | 299 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 300 | |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 301 | {StringConstant} { // Note that we cannot unescape a string constant here! The |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 302 | // string constant might contain a \00 which would not be |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 303 | // understood by the string stuff. It is valid to make a |
| 304 | // [sbyte] c"Hello World\00" constant, for example. |
| 305 | // |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 306 | yytext[strlen(yytext)-1] = 0; // nuke end quote |
| 307 | llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote |
| 308 | return STRINGCONSTANT; |
Chris Lattner | 93750fa | 2001-07-28 17:48:55 +0000 | [diff] [blame] | 309 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 310 | |
| 311 | |
| 312 | {PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; } |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 313 | {NInteger} { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 314 | uint64_t Val = atoull(yytext+1); |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 315 | // +1: we have bigger negative range |
| 316 | if (Val > (uint64_t)INT64_MAX+1) |
| 317 | ThrowException("Constant too large for signed 64 bits!"); |
| 318 | llvmAsmlval.SInt64Val = -Val; |
| 319 | return ESINT64VAL; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 320 | } |
Chris Lattner | 3e8ba10 | 2003-04-17 22:17:32 +0000 | [diff] [blame] | 321 | {HexIntConstant} { |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 322 | llvmAsmlval.UInt64Val = HexIntToVal(yytext+3); |
Chris Lattner | 3e8ba10 | 2003-04-17 22:17:32 +0000 | [diff] [blame] | 323 | return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL; |
| 324 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 325 | |
Chris Lattner | a8101c1 | 2005-01-08 20:07:03 +0000 | [diff] [blame] | 326 | {EPInteger} { |
| 327 | uint64_t Val = atoull(yytext+1); |
| 328 | if ((unsigned)Val != Val) |
| 329 | ThrowException("Invalid value number (too large)!"); |
| 330 | llvmAsmlval.UIntVal = unsigned(Val); |
| 331 | return UINTVAL; |
| 332 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 333 | {ENInteger} { |
| 334 | uint64_t Val = atoull(yytext+2); |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 335 | // +1: we have bigger negative range |
| 336 | if (Val > (uint64_t)INT32_MAX+1) |
| 337 | ThrowException("Constant too large for signed 32 bits!"); |
Chris Lattner | a8101c1 | 2005-01-08 20:07:03 +0000 | [diff] [blame] | 338 | llvmAsmlval.SIntVal = (int)-Val; |
Misha Brukman | 5a2a382 | 2005-05-10 22:02:28 +0000 | [diff] [blame] | 339 | return SINTVAL; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Chris Lattner | 3d52b2f | 2001-07-15 00:17:01 +0000 | [diff] [blame] | 342 | {FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; } |
Chris Lattner | 275da86 | 2002-04-07 08:10:41 +0000 | [diff] [blame] | 343 | {HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 344 | |
Chris Lattner | e151259 | 2004-03-19 23:34:33 +0000 | [diff] [blame] | 345 | <<EOF>> { |
| 346 | /* Make sure to free the internal buffers for flex when we are |
| 347 | * done reading our input! |
| 348 | */ |
| 349 | yy_delete_buffer(YY_CURRENT_BUFFER); |
| 350 | return EOF; |
| 351 | } |
| 352 | |
Chris Lattner | a0846a3 | 2004-05-27 17:49:14 +0000 | [diff] [blame] | 353 | [ \r\t\n] { /* Ignore whitespace */ } |
Chris Lattner | e1fe875 | 2001-09-07 16:32:43 +0000 | [diff] [blame] | 354 | . { return yytext[0]; } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 355 | |
| 356 | %% |
Chris Lattner | 2fecc0f | 2006-02-15 07:02:59 +0000 | [diff] [blame] | 357 | |