Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 1 | //===-- UpgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===// |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Reid Spencer and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 10 | // This file implements the bison parser for LLVM 1.9 assembly language. |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | %{ |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 15 | #include "ParserInternals.h" |
| 16 | #include <llvm/ADT/StringExtras.h> |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <list> |
| 19 | #include <utility> |
| 20 | #include <iostream> |
| 21 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 22 | #define YYERROR_VERBOSE 1 |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 23 | #define YYINCLUDED_STDLIB_H |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 24 | #define YYDEBUG 1 |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 25 | |
| 26 | int yylex(); // declaration" of xxx warnings. |
| 27 | int yyparse(); |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 28 | extern int yydebug; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 29 | |
| 30 | static std::string CurFilename; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 31 | static std::ostream *O = 0; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 32 | std::istream* LexInput = 0; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 33 | unsigned SizeOfPointer = 32; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 34 | |
| 35 | void UpgradeAssembly(const std::string &infile, std::istream& in, |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 36 | std::ostream &out, bool debug) |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 37 | { |
| 38 | Upgradelineno = 1; |
| 39 | CurFilename = infile; |
Reid Spencer | 96839be | 2006-11-30 16:50:26 +0000 | [diff] [blame] | 40 | LexInput = ∈ |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 41 | yydebug = debug; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 42 | O = &out; |
| 43 | |
| 44 | if (yyparse()) { |
| 45 | std::cerr << "Parse failed.\n"; |
| 46 | exit(1); |
| 47 | } |
| 48 | } |
| 49 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 50 | const char* getCastOpcode(TypeInfo& SrcTy, TypeInfo&DstTy) { |
| 51 | unsigned SrcBits = SrcTy.getBitWidth(); |
| 52 | unsigned DstBits = DstTy.getBitWidth(); |
| 53 | const char* opcode = "bitcast"; |
| 54 | // Run through the possibilities ... |
| 55 | if (DstTy.isIntegral()) { // Casting to integral |
| 56 | if (SrcTy.isIntegral()) { // Casting from integral |
| 57 | if (DstBits < SrcBits) |
| 58 | opcode = "trunc"; |
| 59 | else if (DstBits > SrcBits) { // its an extension |
| 60 | if (SrcTy.isSigned()) |
| 61 | opcode ="sext"; // signed -> SEXT |
| 62 | else |
| 63 | opcode = "zext"; // unsigned -> ZEXT |
| 64 | } else { |
| 65 | opcode = "bitcast"; // Same size, No-op cast |
| 66 | } |
| 67 | } else if (SrcTy.isFloatingPoint()) { // Casting from floating pt |
| 68 | if (DstTy.isSigned()) |
| 69 | opcode = "fptosi"; // FP -> sint |
| 70 | else |
| 71 | opcode = "fptoui"; // FP -> uint |
| 72 | } else if (SrcTy.isPacked()) { |
| 73 | assert(DstBits == SrcTy.getBitWidth() && |
| 74 | "Casting packed to integer of different width"); |
| 75 | opcode = "bitcast"; // same size, no-op cast |
| 76 | } else { |
| 77 | assert(SrcTy.isPointer() && |
| 78 | "Casting from a value that is not first-class type"); |
| 79 | opcode = "ptrtoint"; // ptr -> int |
| 80 | } |
| 81 | } else if (DstTy.isFloatingPoint()) { // Casting to floating pt |
| 82 | if (SrcTy.isIntegral()) { // Casting from integral |
| 83 | if (SrcTy.isSigned()) |
| 84 | opcode = "sitofp"; // sint -> FP |
| 85 | else |
| 86 | opcode = "uitofp"; // uint -> FP |
| 87 | } else if (SrcTy.isFloatingPoint()) { // Casting from floating pt |
| 88 | if (DstBits < SrcBits) { |
| 89 | opcode = "fptrunc"; // FP -> smaller FP |
| 90 | } else if (DstBits > SrcBits) { |
| 91 | opcode = "fpext"; // FP -> larger FP |
| 92 | } else { |
| 93 | opcode ="bitcast"; // same size, no-op cast |
| 94 | } |
| 95 | } else if (SrcTy.isPacked()) { |
| 96 | assert(DstBits == SrcTy.getBitWidth() && |
| 97 | "Casting packed to floating point of different width"); |
| 98 | opcode = "bitcast"; // same size, no-op cast |
| 99 | } else { |
| 100 | assert(0 && "Casting pointer or non-first class to float"); |
| 101 | } |
| 102 | } else if (DstTy.isPacked()) { |
| 103 | if (SrcTy.isPacked()) { |
| 104 | assert(DstTy.getBitWidth() == SrcTy.getBitWidth() && |
| 105 | "Casting packed to packed of different widths"); |
| 106 | opcode = "bitcast"; // packed -> packed |
| 107 | } else if (DstTy.getBitWidth() == SrcBits) { |
| 108 | opcode = "bitcast"; // float/int -> packed |
| 109 | } else { |
| 110 | assert(!"Illegal cast to packed (wrong type or size)"); |
| 111 | } |
| 112 | } else if (DstTy.isPointer()) { |
| 113 | if (SrcTy.isPointer()) { |
| 114 | opcode = "bitcast"; // ptr -> ptr |
| 115 | } else if (SrcTy.isIntegral()) { |
| 116 | opcode = "inttoptr"; // int -> ptr |
| 117 | } else { |
| 118 | assert(!"Casting pointer to other than pointer or int"); |
| 119 | } |
| 120 | } else { |
| 121 | assert(!"Casting to type that is not first-class"); |
| 122 | } |
| 123 | return opcode; |
| 124 | } |
| 125 | |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 126 | %} |
| 127 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 128 | %file-prefix="UpgradeParser" |
| 129 | |
| 130 | %union { |
| 131 | std::string* String; |
| 132 | TypeInfo Type; |
| 133 | ValueInfo Value; |
| 134 | ConstInfo Const; |
| 135 | } |
| 136 | |
| 137 | %token <Const> ESINT64VAL EUINT64VAL SINTVAL UINTVAL FPVAL TRUETOK FALSETOK |
| 138 | %token <Const> NULL_TOK UNDEF ZEROINITIALIZER |
| 139 | |
| 140 | %token <Type> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG |
| 141 | %token <Type> FLOAT DOUBLE LABEL OPAQUE |
| 142 | |
| 143 | %token <String> TYPE VAR_ID LABELSTR STRINGCONSTANT |
| 144 | %token <String> IMPLEMENTATION BEGINTOK ENDTOK |
| 145 | %token <String> DECLARE GLOBAL CONSTANT SECTION VOLATILE |
| 146 | %token <String> TO DOTDOTDOT CONST INTERNAL LINKONCE WEAK |
| 147 | %token <String> DLLIMPORT DLLEXPORT EXTERN_WEAK APPENDING |
| 148 | %token <String> NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG |
| 149 | %token <String> ALIGN |
| 150 | %token <String> DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT |
| 151 | %token <String> CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK |
| 152 | %token <String> X86_STDCALLCC_TOK X86_FASTCALLCC_TOK |
| 153 | %token <String> DATALAYOUT |
| 154 | %token <String> RET BR SWITCH INVOKE UNWIND UNREACHABLE |
| 155 | %token <String> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR |
| 156 | %token <String> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators |
| 157 | %token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR |
| 158 | %token <String> PHI_TOK SELECT SHL LSHR ASHR VAARG |
| 159 | %token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR |
| 160 | %token <String> CAST |
| 161 | |
| 162 | %type <String> OptAssign OptLinkage OptCallingConv OptAlign OptCAlign |
| 163 | %type <String> SectionString OptSection GlobalVarAttributes GlobalVarAttribute |
| 164 | %type <String> ArgTypeListI ConstExpr DefinitionList |
| 165 | %type <String> ConstPool TargetDefinition LibrariesDefinition LibList OptName |
| 166 | %type <String> ArgVal ArgListH ArgList FunctionHeaderH BEGIN FunctionHeader END |
| 167 | %type <String> Function FunctionProto BasicBlock TypeListI |
| 168 | %type <String> InstructionList BBTerminatorInst JumpTable Inst PHIList |
| 169 | %type <String> ValueRefList OptTailCall InstVal IndexList OptVolatile |
| 170 | %type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType |
| 171 | %type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock |
| 172 | %type <String> Name ValueRef ValueRefListE |
| 173 | %type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps ConstValueRef |
| 174 | |
| 175 | %type <String> ConstVector |
| 176 | |
| 177 | %type <Type> IntType SIntType UIntType FPType TypesV Types |
| 178 | %type <Type> PrimType UpRTypesV UpRTypes |
| 179 | |
| 180 | %type <Const> IntVal EInt64Val ConstVal |
| 181 | |
| 182 | %type <Value> ResolvedVal |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 183 | |
| 184 | %start Module |
| 185 | |
| 186 | %% |
| 187 | |
| 188 | // Handle constant integer size restriction and conversion... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 189 | IntVal : SINTVAL | UINTVAL |
| 190 | EInt64Val : ESINT64VAL | EUINT64VAL; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 191 | |
| 192 | // Operations that are notably excluded from this list include: |
| 193 | // RET, BR, & SWITCH because they end basic blocks and are treated specially. |
| 194 | ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM; |
| 195 | LogicalOps : AND | OR | XOR; |
| 196 | SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 197 | ShiftOps : SHL | LSHR | ASHR; |
| 198 | |
| 199 | // These are some types that allow classification if we only want a particular |
| 200 | // thing... for example, only a signed, unsigned, or integral type. |
| 201 | SIntType : LONG | INT | SHORT | SBYTE; |
| 202 | UIntType : ULONG | UINT | USHORT | UBYTE; |
| 203 | IntType : SIntType | UIntType; |
| 204 | FPType : FLOAT | DOUBLE; |
| 205 | |
| 206 | // OptAssign - Value producing statements have an optional assignment component |
| 207 | OptAssign : Name '=' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 208 | *$1 += " = "; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 209 | $$ = $1; |
| 210 | } |
| 211 | | /*empty*/ { |
| 212 | $$ = new std::string(""); |
| 213 | }; |
| 214 | |
| 215 | OptLinkage |
| 216 | : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT |
| 217 | | EXTERN_WEAK |
| 218 | | /*empty*/ { $$ = new std::string(""); } ; |
| 219 | |
| 220 | OptCallingConv |
| 221 | : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK |
| 222 | | X86_FASTCALLCC_TOK | CC_TOK EUINT64VAL |
| 223 | | /*empty*/ { $$ = new std::string(""); } ; |
| 224 | |
| 225 | // OptAlign/OptCAlign - An optional alignment, and an optional alignment with |
| 226 | // a comma before it. |
| 227 | OptAlign |
| 228 | : /*empty*/ { $$ = new std::string(); } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 229 | | ALIGN EUINT64VAL { *$1 += " " + *$2.cnst; delete $2.cnst; $$ = $1; }; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 230 | ; |
| 231 | OptCAlign |
| 232 | : /*empty*/ { $$ = new std::string(); } |
| 233 | | ',' ALIGN EUINT64VAL { |
| 234 | $2->insert(0, ", "); |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 235 | *$2 += " " + *$3.cnst; |
| 236 | delete $3.cnst; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 237 | $$ = $2; |
| 238 | }; |
| 239 | |
| 240 | SectionString |
| 241 | : SECTION STRINGCONSTANT { |
| 242 | *$1 += " " + *$2; |
| 243 | delete $2; |
| 244 | $$ = $1; |
| 245 | }; |
| 246 | |
| 247 | OptSection : /*empty*/ { $$ = new std::string(); } |
| 248 | | SectionString; |
| 249 | |
| 250 | GlobalVarAttributes |
| 251 | : /* empty */ { $$ = new std::string(); } |
| 252 | | ',' GlobalVarAttribute GlobalVarAttributes { |
| 253 | $2->insert(0, ", "); |
| 254 | if (!$3->empty()) |
| 255 | *$2 += " " + *$3; |
| 256 | delete $3; |
| 257 | $$ = $2; |
| 258 | }; |
| 259 | |
| 260 | GlobalVarAttribute |
| 261 | : SectionString |
| 262 | | ALIGN EUINT64VAL { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 263 | *$1 += " " + *$2.cnst; |
| 264 | delete $2.cnst; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 265 | $$ = $1; |
| 266 | }; |
| 267 | |
| 268 | //===----------------------------------------------------------------------===// |
| 269 | // Types includes all predefined types... except void, because it can only be |
| 270 | // used in specific contexts (function returning void for example). To have |
| 271 | // access to it, a user must explicitly use TypesV. |
| 272 | // |
| 273 | |
| 274 | // TypesV includes all of 'Types', but it also includes the void type. |
| 275 | TypesV : Types | VOID ; |
| 276 | UpRTypesV : UpRTypes | VOID ; |
| 277 | Types : UpRTypes ; |
| 278 | |
| 279 | // Derived types are added later... |
| 280 | // |
| 281 | PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 282 | PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL; |
| 283 | UpRTypes : OPAQUE | PrimType | SymbolicValueRef { |
| 284 | $$.newTy = $1; }; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 285 | |
| 286 | // Include derived types in the Types production. |
| 287 | // |
| 288 | UpRTypes : '\\' EUINT64VAL { // Type UpReference |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 289 | $2.cnst->insert(0, "\\"); |
| 290 | $$.newTy = $2.cnst; |
| 291 | $$.oldTy = OpaqueTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 292 | } |
| 293 | | UpRTypesV '(' ArgTypeListI ')' { // Function derived type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 294 | *$1.newTy += "( " + *$3 + " )"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 295 | delete $3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 296 | $$.newTy = $1.newTy; |
| 297 | $$.oldTy = FunctionTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 298 | } |
| 299 | | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 300 | $2.cnst->insert(0,"[ "); |
| 301 | *$2.cnst += " x " + *$4.newTy + " ]"; |
| 302 | delete $4.newTy; |
| 303 | $$.newTy = $2.cnst; |
| 304 | $$.oldTy = ArrayTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 305 | } |
| 306 | | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 307 | $2.cnst->insert(0,"< "); |
| 308 | *$2.cnst += " x " + *$4.newTy + " >"; |
| 309 | delete $4.newTy; |
| 310 | $$.newTy = $2.cnst; |
| 311 | $$.oldTy = PackedTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 312 | } |
| 313 | | '{' TypeListI '}' { // Structure type? |
| 314 | $2->insert(0, "{ "); |
| 315 | *$2 += " }"; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 316 | $$.newTy = $2; |
| 317 | $$.oldTy = StructTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 318 | } |
| 319 | | '{' '}' { // Empty structure type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 320 | $$.newTy = new std::string("{ }"); |
| 321 | $$.oldTy = StructTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 322 | } |
| 323 | | UpRTypes '*' { // Pointer type? |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 324 | *$1.newTy += '*'; |
| 325 | $1.oldTy = PointerTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 326 | $$ = $1; |
| 327 | }; |
| 328 | |
| 329 | // TypeList - Used for struct declarations and as a basis for function type |
| 330 | // declaration type lists |
| 331 | // |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 332 | TypeListI |
| 333 | : UpRTypes { |
| 334 | $$ = $1.newTy; |
| 335 | } |
| 336 | | TypeListI ',' UpRTypes { |
| 337 | *$1 += ", " + *$3.newTy; |
| 338 | delete $3.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 339 | $$ = $1; |
| 340 | }; |
| 341 | |
| 342 | // ArgTypeList - List of types for a function type declaration... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 343 | ArgTypeListI |
| 344 | : TypeListI |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 345 | | TypeListI ',' DOTDOTDOT { |
| 346 | *$1 += ", ..."; |
| 347 | delete $3; |
| 348 | $$ = $1; |
| 349 | } |
| 350 | | DOTDOTDOT { |
| 351 | $$ = $1; |
| 352 | } |
| 353 | | /*empty*/ { |
| 354 | $$ = new std::string(); |
| 355 | }; |
| 356 | |
| 357 | // ConstVal - The various declarations that go into the constant pool. This |
| 358 | // production is used ONLY to represent constants that show up AFTER a 'const', |
| 359 | // 'constant' or 'global' token at global scope. Constants that can be inlined |
| 360 | // into other expressions (such as integers and constexprs) are handled by the |
| 361 | // ResolvedVal, ValueRef and ConstValueRef productions. |
| 362 | // |
| 363 | ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 364 | $$.type = $1; |
| 365 | $$.cnst = new std::string(*$1.newTy); |
| 366 | *$$.cnst += " [ " + *$3 + " ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 367 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 368 | } |
| 369 | | Types '[' ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 370 | $$.type = $1; |
| 371 | $$.cnst = new std::string(*$1.newTy); |
| 372 | *$$.cnst += "[ ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 373 | } |
| 374 | | Types 'c' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 375 | $$.type = $1; |
| 376 | $$.cnst = new std::string(*$1.newTy); |
| 377 | *$$.cnst += " c" + *$3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 378 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 379 | } |
| 380 | | Types '<' ConstVector '>' { // Nonempty unsized arr |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 381 | $$.type = $1; |
| 382 | $$.cnst = new std::string(*$1.newTy); |
| 383 | *$$.cnst += " < " + *$3 + " >"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 384 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 385 | } |
| 386 | | Types '{' ConstVector '}' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 387 | $$.type = $1; |
| 388 | $$.cnst = new std::string(*$1.newTy); |
| 389 | *$$.cnst += " { " + *$3 + " }"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 390 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 391 | } |
| 392 | | Types '{' '}' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 393 | $$.type = $1; |
| 394 | $$.cnst = new std::string(*$1.newTy); |
| 395 | *$$.cnst += " [ ]"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 396 | } |
| 397 | | Types NULL_TOK { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 398 | $$.type = $1; |
| 399 | $$.cnst = new std::string(*$1.newTy); |
| 400 | *$$.cnst += " " + *$2.cnst; |
| 401 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 402 | } |
| 403 | | Types UNDEF { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 404 | $$.type = $1; |
| 405 | $$.cnst = new std::string(*$1.newTy); |
| 406 | *$$.cnst += " " + *$2.cnst; |
| 407 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 408 | } |
| 409 | | Types SymbolicValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 410 | $$.type = $1; |
| 411 | $$.cnst = new std::string(*$1.newTy); |
| 412 | *$$.cnst += " " + *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 413 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 414 | } |
| 415 | | Types ConstExpr { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 416 | $$.type = $1; |
| 417 | $$.cnst = new std::string(*$1.newTy); |
| 418 | *$$.cnst += " " + *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 419 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 420 | } |
| 421 | | Types ZEROINITIALIZER { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 422 | $$.type = $1; |
| 423 | $$.cnst = new std::string(*$1.newTy); |
| 424 | *$$.cnst += " " + *$2.cnst; |
| 425 | $2.destroy(); |
| 426 | } |
| 427 | | SIntType EInt64Val { // integral constants |
| 428 | $$.type = $1; |
| 429 | $$.cnst = new std::string(*$1.newTy); |
| 430 | *$$.cnst += " " + *$2.cnst; |
| 431 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 432 | } |
| 433 | | UIntType EUINT64VAL { // integral constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 434 | $$.type = $1; |
| 435 | $$.cnst = new std::string(*$1.newTy); |
| 436 | *$$.cnst += " " + *$2.cnst; |
| 437 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 438 | } |
| 439 | | BOOL TRUETOK { // Boolean constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 440 | $$.type = $1; |
| 441 | $$.cnst = new std::string(*$1.newTy); |
| 442 | *$$.cnst += " " + *$2.cnst; |
| 443 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 444 | } |
| 445 | | BOOL FALSETOK { // Boolean constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 446 | $$.type = $1; |
| 447 | $$.cnst = new std::string(*$1.newTy); |
| 448 | *$$.cnst += " " + *$2.cnst; |
| 449 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 450 | } |
| 451 | | FPType FPVAL { // Float & Double constants |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 452 | $$.type = $1; |
| 453 | $$.cnst = new std::string(*$1.newTy); |
| 454 | *$$.cnst += " " + *$2.cnst; |
| 455 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 459 | ConstExpr: CAST '(' ConstVal TO Types ')' { |
| 460 | // We must infer the cast opcode from the types of the operands. |
| 461 | const char *opcode = getCastOpcode($3.type, $5); |
| 462 | $$ = new std::string(opcode); |
| 463 | *$$ += "(" + *$3.cnst + " " + *$4 + " " + *$5.newTy + ")"; |
| 464 | delete $1; $3.destroy(); delete $4; $5.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 465 | } |
| 466 | | GETELEMENTPTR '(' ConstVal IndexList ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 467 | *$1 += "(" + *$3.cnst + " " + *$4 + ")"; |
| 468 | $$ = $1; |
| 469 | $3.destroy(); |
| 470 | delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 471 | } |
| 472 | | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 473 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 474 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 475 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 476 | } |
| 477 | | ArithmeticOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 478 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 479 | $3.destroy(); $5.destroy(); |
| 480 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 481 | } |
| 482 | | LogicalOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 483 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 484 | $3.destroy(); $5.destroy(); |
| 485 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 486 | } |
| 487 | | SetCondOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 488 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 489 | $3.destroy(); $5.destroy(); |
| 490 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 491 | } |
| 492 | | ShiftOps '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 493 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 494 | $3.destroy(); $5.destroy(); |
| 495 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 496 | } |
| 497 | | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 498 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")"; |
| 499 | $3.destroy(); $5.destroy(); |
| 500 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 501 | } |
| 502 | | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 503 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 504 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 505 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 506 | } |
| 507 | | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 508 | *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")"; |
| 509 | $3.destroy(); $5.destroy(); $7.destroy(); |
| 510 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | |
| 514 | // ConstVector - A list of comma separated constants. |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 515 | |
| 516 | ConstVector |
| 517 | : ConstVector ',' ConstVal { |
| 518 | *$1 += ", " + *$3.cnst; |
| 519 | $3.destroy(); |
| 520 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 521 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 522 | | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); } |
| 523 | ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 524 | |
| 525 | |
| 526 | // GlobalType - Match either GLOBAL or CONSTANT for global declarations... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 527 | GlobalType : GLOBAL | CONSTANT ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 528 | |
| 529 | |
| 530 | //===----------------------------------------------------------------------===// |
| 531 | // Rules to match Modules |
| 532 | //===----------------------------------------------------------------------===// |
| 533 | |
| 534 | // Module rule: Capture the result of parsing the whole file into a result |
| 535 | // variable... |
| 536 | // |
| 537 | Module : DefinitionList { |
| 538 | }; |
| 539 | |
| 540 | // DefinitionList - Top level definitions |
| 541 | // |
| 542 | DefinitionList : DefinitionList Function { |
| 543 | $$ = 0; |
| 544 | } |
| 545 | | DefinitionList FunctionProto { |
| 546 | *O << *$2 << "\n"; |
| 547 | delete $2; |
| 548 | $$ = 0; |
| 549 | } |
| 550 | | DefinitionList MODULE ASM_TOK AsmBlock { |
| 551 | *O << "module asm " << " " << *$4 << "\n"; |
| 552 | } |
| 553 | | DefinitionList IMPLEMENTATION { |
| 554 | *O << "implementation\n"; |
| 555 | } |
| 556 | | ConstPool { |
| 557 | }; |
| 558 | |
| 559 | // ConstPool - Constants with optional names assigned to them. |
| 560 | ConstPool : ConstPool OptAssign TYPE TypesV { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 561 | *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n"; |
| 562 | // delete $2; delete $3; $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 563 | $$ = 0; |
| 564 | } |
| 565 | | ConstPool FunctionProto { // Function prototypes can be in const pool |
| 566 | *O << *$2 << "\n"; |
| 567 | delete $2; |
| 568 | $$ = 0; |
| 569 | } |
| 570 | | ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool |
| 571 | *O << *$2 << " " << *$3 << " " << *$4 << "\n"; |
| 572 | delete $2; delete $3; delete $4; |
| 573 | $$ = 0; |
| 574 | } |
| 575 | | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 576 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " " |
| 577 | << *$6 << "\n"; |
| 578 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 579 | $$ = 0; |
| 580 | } |
| 581 | | ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 582 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 583 | << " " << *$6 << "\n"; |
| 584 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 585 | $$ = 0; |
| 586 | } |
| 587 | | ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 588 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 589 | << " " << *$6 << "\n"; |
| 590 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 591 | $$ = 0; |
| 592 | } |
| 593 | | ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 594 | *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy |
| 595 | << " " << *$6 << "\n"; |
| 596 | delete $2; delete $3; delete $4; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 597 | $$ = 0; |
| 598 | } |
| 599 | | ConstPool TARGET TargetDefinition { |
| 600 | *O << *$2 << " " << *$3 << "\n"; |
| 601 | delete $2; delete $3; |
| 602 | $$ = 0; |
| 603 | } |
| 604 | | ConstPool DEPLIBS '=' LibrariesDefinition { |
| 605 | *O << *$2 << " = " << *$4 << "\n"; |
| 606 | delete $2; delete $4; |
| 607 | $$ = 0; |
| 608 | } |
| 609 | | /* empty: end of list */ { |
| 610 | $$ = 0; |
| 611 | }; |
| 612 | |
| 613 | |
| 614 | AsmBlock : STRINGCONSTANT ; |
| 615 | |
| 616 | BigOrLittle : BIG | LITTLE |
| 617 | |
| 618 | TargetDefinition |
| 619 | : ENDIAN '=' BigOrLittle { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 620 | *$1 += " = " + *$3; |
| 621 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 622 | $$ = $1; |
| 623 | } |
| 624 | | POINTERSIZE '=' EUINT64VAL { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 625 | *$1 += " = " + *$3.cnst; |
| 626 | if (*$3.cnst == "64") |
| 627 | SizeOfPointer = 64; |
| 628 | $3.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 629 | $$ = $1; |
| 630 | } |
| 631 | | TRIPLE '=' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 632 | *$1 += " = " + *$3; |
| 633 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 634 | $$ = $1; |
| 635 | } |
| 636 | | DATALAYOUT '=' STRINGCONSTANT { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 637 | *$1 += " = " + *$3; |
| 638 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 639 | $$ = $1; |
| 640 | }; |
| 641 | |
| 642 | LibrariesDefinition |
| 643 | : '[' LibList ']' { |
| 644 | $2->insert(0, "[ "); |
| 645 | *$2 += " ]"; |
| 646 | $$ = $2; |
| 647 | }; |
| 648 | |
| 649 | LibList |
| 650 | : LibList ',' STRINGCONSTANT { |
| 651 | *$1 += ", " + *$3; |
| 652 | delete $3; |
| 653 | $$ = $1; |
| 654 | } |
| 655 | | STRINGCONSTANT |
| 656 | | /* empty: end of list */ { |
| 657 | $$ = new std::string(); |
| 658 | }; |
| 659 | |
| 660 | //===----------------------------------------------------------------------===// |
| 661 | // Rules to match Function Headers |
| 662 | //===----------------------------------------------------------------------===// |
| 663 | |
| 664 | Name : VAR_ID | STRINGCONSTANT; |
| 665 | OptName : Name | /*empty*/ { $$ = new std::string(); }; |
| 666 | |
| 667 | ArgVal : Types OptName { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 668 | $$ = $1.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 669 | if (!$2->empty()) |
| 670 | *$$ += " " + *$2; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 671 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | ArgListH : ArgListH ',' ArgVal { |
| 675 | *$1 += ", " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 676 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 677 | } |
| 678 | | ArgVal { |
| 679 | $$ = $1; |
| 680 | }; |
| 681 | |
| 682 | ArgList : ArgListH { |
| 683 | $$ = $1; |
| 684 | } |
| 685 | | ArgListH ',' DOTDOTDOT { |
| 686 | *$1 += ", ..."; |
| 687 | $$ = $1; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 688 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 689 | } |
| 690 | | DOTDOTDOT { |
| 691 | $$ = $1; |
| 692 | } |
| 693 | | /* empty */ { |
| 694 | $$ = new std::string(); |
| 695 | }; |
| 696 | |
| 697 | FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' |
| 698 | OptSection OptAlign { |
| 699 | if (!$1->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 700 | *$1 += " "; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 701 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 702 | *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")"; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 703 | if (!$7->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 704 | *$1 += " " + *$7; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 705 | } |
| 706 | if (!$8->empty()) { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 707 | *$1 += " " + *$8; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 708 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 709 | $2.destroy(); |
| 710 | delete $3; |
| 711 | delete $5; |
| 712 | delete $7; |
| 713 | delete $8; |
| 714 | $$ = $1; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 715 | }; |
| 716 | |
| 717 | BEGIN : BEGINTOK { |
| 718 | $$ = new std::string("begin"); |
| 719 | } |
| 720 | | '{' { |
| 721 | $$ = new std::string ("{"); |
| 722 | } |
| 723 | |
| 724 | FunctionHeader : OptLinkage FunctionHeaderH BEGIN { |
| 725 | if (!$1->empty()) { |
| 726 | *O << *$1 << " "; |
| 727 | } |
| 728 | *O << *$2 << " " << *$3 << "\n"; |
| 729 | delete $1; delete $2; delete $3; |
| 730 | $$ = 0; |
| 731 | }; |
| 732 | |
| 733 | END : ENDTOK { $$ = new std::string("end"); } |
| 734 | | '}' { $$ = new std::string("}"); }; |
| 735 | |
| 736 | Function : FunctionHeader BasicBlockList END { |
| 737 | if ($2) |
| 738 | *O << *$2; |
| 739 | *O << '\n' << *$3 << "\n"; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 740 | $$ = 0; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 741 | }; |
| 742 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 743 | FnDeclareLinkage |
| 744 | : /*default*/ { $$ = new std::string(); } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 745 | | DLLIMPORT |
| 746 | | EXTERN_WEAK |
| 747 | ; |
| 748 | |
| 749 | FunctionProto |
| 750 | : DECLARE FnDeclareLinkage FunctionHeaderH { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 751 | if (!$2->empty()) |
| 752 | *$1 += " " + *$2; |
| 753 | *$1 += " " + *$3; |
| 754 | delete $2; |
| 755 | delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 756 | $$ = $1; |
| 757 | }; |
| 758 | |
| 759 | //===----------------------------------------------------------------------===// |
| 760 | // Rules to match Basic Blocks |
| 761 | //===----------------------------------------------------------------------===// |
| 762 | |
| 763 | OptSideEffect : /* empty */ { |
| 764 | } |
| 765 | | SIDEEFFECT { |
| 766 | }; |
| 767 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 768 | ConstValueRef |
| 769 | : ESINT64VAL { $$ = $1.cnst; } |
| 770 | | EUINT64VAL { $$ = $1.cnst; } |
| 771 | | FPVAL { $$ = $1.cnst; } |
| 772 | | TRUETOK { $$ = $1.cnst; } |
| 773 | | FALSETOK { $$ = $1.cnst; } |
| 774 | | NULL_TOK { $$ = $1.cnst; } |
| 775 | | UNDEF { $$ = $1.cnst; } |
| 776 | | ZEROINITIALIZER { $$ = $1.cnst; } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 777 | | '<' ConstVector '>' { |
| 778 | $2->insert(0, "<"); |
| 779 | *$2 += ">"; |
| 780 | $$ = $2; |
| 781 | } |
| 782 | | ConstExpr |
| 783 | | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT { |
| 784 | if (!$2->empty()) { |
| 785 | *$1 += " " + *$2; |
| 786 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 787 | *$1 += " " + *$3 + ", " + *$5; |
| 788 | delete $2; delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 789 | $$ = $1; |
| 790 | }; |
| 791 | |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 792 | SymbolicValueRef : IntVal { $$ = $1.cnst; } | Name ; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 793 | |
| 794 | // ValueRef - A reference to a definition... either constant or symbolic |
| 795 | ValueRef : SymbolicValueRef | ConstValueRef; |
| 796 | |
| 797 | |
| 798 | // ResolvedVal - a <type> <value> pair. This is used only in cases where the |
| 799 | // type immediately preceeds the value reference, and allows complex constant |
| 800 | // pool references (for things like: 'ret [2 x int] [ int 12, int 42]') |
| 801 | ResolvedVal : Types ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 802 | $$.type = $1; |
| 803 | $$.val = new std::string(*$1.newTy + " "); |
| 804 | *$$.val += *$2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 805 | delete $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 806 | }; |
| 807 | |
| 808 | BasicBlockList : BasicBlockList BasicBlock { |
| 809 | } |
| 810 | | BasicBlock { // Do not allow functions with 0 basic blocks |
| 811 | }; |
| 812 | |
| 813 | |
| 814 | // Basic blocks are terminated by branching instructions: |
| 815 | // br, br/cc, switch, ret |
| 816 | // |
| 817 | BasicBlock : InstructionList OptAssign BBTerminatorInst { |
| 818 | *O << *$2 ; |
| 819 | }; |
| 820 | |
| 821 | InstructionList : InstructionList Inst { |
| 822 | *O << " " << *$2 << "\n"; |
| 823 | delete $2; |
| 824 | $$ = 0; |
| 825 | } |
| 826 | | /* empty */ { |
| 827 | $$ = 0; |
| 828 | } |
| 829 | | LABELSTR { |
| 830 | *O << *$1 << "\n"; |
| 831 | delete $1; |
| 832 | $$ = 0; |
| 833 | }; |
| 834 | |
| 835 | BBTerminatorInst : RET ResolvedVal { // Return with a result... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 836 | *O << " " << *$1 << " " << *$2.val << "\n"; |
| 837 | delete $1; $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 838 | $$ = 0; |
| 839 | } |
| 840 | | RET VOID { // Return with no result... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 841 | *O << " " << *$1 << " " << *$2.newTy << "\n"; |
| 842 | delete $1; $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 843 | $$ = 0; |
| 844 | } |
| 845 | | BR LABEL ValueRef { // Unconditional Branch... |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 846 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n"; |
| 847 | delete $1; $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 848 | $$ = 0; |
| 849 | } // Conditional Branch... |
| 850 | | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 851 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " |
| 852 | << *$5.newTy << " " << *$6 << ", " << *$8.newTy << " " << *$9 << "\n"; |
| 853 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; |
| 854 | $8.destroy(); delete $9; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 855 | $$ = 0; |
| 856 | } |
| 857 | | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 858 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " << *$5.newTy |
| 859 | << " " << *$6 << " [" << *$8 << " ]\n"; |
| 860 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; delete $8; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 861 | $$ = 0; |
| 862 | } |
| 863 | | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 864 | *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " |
| 865 | << *$5.newTy << " " << *$6 << "[]\n"; |
| 866 | delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 867 | $$ = 0; |
| 868 | } |
| 869 | | INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')' |
| 870 | TO LABEL ValueRef UNWIND LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 871 | *O << " " << *$1 << " " << *$2 << " " << *$3.newTy << " " << *$4 << " (" |
| 872 | << *$6 << ") " << *$8 << " " << *$9.newTy << " " << *$10 << " " |
| 873 | << *$11 << " " << *$12.newTy << " " << *$13 << "\n"; |
| 874 | delete $1; delete $2; $3.destroy(); delete $4; delete $6; delete $8; |
| 875 | $9.destroy(); delete $10; delete $11; $12.destroy(); delete $13; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 876 | $$ = 0; |
| 877 | } |
| 878 | | UNWIND { |
| 879 | *O << " " << *$1 << "\n"; |
| 880 | delete $1; |
| 881 | $$ = 0; |
| 882 | } |
| 883 | | UNREACHABLE { |
| 884 | *O << " " << *$1 << "\n"; |
| 885 | delete $1; |
| 886 | $$ = 0; |
| 887 | }; |
| 888 | |
| 889 | JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 890 | *$1 += *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6; |
| 891 | $2.destroy(); delete $3; $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 892 | $$ = $1; |
| 893 | } |
| 894 | | IntType ConstValueRef ',' LABEL ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 895 | $2->insert(0, *$1.newTy + " " ); |
| 896 | *$2 += ", " + *$4.newTy + " " + *$5; |
| 897 | $1.destroy(); $4.destroy(); delete $5; |
| 898 | $$ = $2; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 899 | }; |
| 900 | |
| 901 | Inst |
| 902 | : OptAssign InstVal { |
| 903 | *$1 += *$2; |
| 904 | delete $2; |
| 905 | $$ = $1; |
| 906 | }; |
| 907 | |
| 908 | PHIList |
| 909 | : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 910 | $3->insert(0, *$1.newTy + "["); |
| 911 | *$3 += "," + *$5 + "]"; |
| 912 | $1.destroy(); delete $5; |
| 913 | $$ = $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 914 | } |
| 915 | | PHIList ',' '[' ValueRef ',' ValueRef ']' { |
| 916 | *$1 += ", [" + *$4 + "," + *$6 + "]"; |
| 917 | delete $4; delete $6; |
| 918 | $$ = $1; |
| 919 | }; |
| 920 | |
| 921 | |
| 922 | ValueRefList |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 923 | : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); } |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 924 | | ValueRefList ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 925 | *$1 += ", " + *$3.val; |
| 926 | $3.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 927 | $$ = $1; |
| 928 | }; |
| 929 | |
| 930 | // ValueRefListE - Just like ValueRefList, except that it may also be empty! |
| 931 | ValueRefListE |
| 932 | : ValueRefList |
| 933 | | /*empty*/ { $$ = new std::string(); } |
| 934 | ; |
| 935 | |
| 936 | OptTailCall |
| 937 | : TAIL CALL { |
| 938 | *$1 += " " + *$2; |
| 939 | delete $2; |
| 940 | $$ = $1; |
| 941 | } |
| 942 | | CALL |
| 943 | ; |
| 944 | |
| 945 | InstVal : ArithmeticOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 946 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 947 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 948 | $$ = $1; |
| 949 | } |
| 950 | | LogicalOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 951 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 952 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 953 | $$ = $1; |
| 954 | } |
| 955 | | SetCondOps Types ValueRef ',' ValueRef { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 956 | *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5; |
| 957 | $2.destroy(); delete $3; delete $5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 958 | $$ = $1; |
| 959 | } |
| 960 | | NOT ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 961 | *$1 += " " + *$2.val; |
| 962 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 963 | $$ = $1; |
| 964 | } |
| 965 | | ShiftOps ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 966 | *$1 += " " + *$2.val + ", " + *$4.val; |
| 967 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 968 | $$ = $1; |
| 969 | } |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 970 | | CAST ResolvedVal TO Types { |
| 971 | const char *opcode = getCastOpcode($2.type, $4); |
| 972 | $$ = new std::string(opcode); |
| 973 | *$$ += *$2.val + " " + *$3 + " " + *$4.newTy; |
| 974 | delete $1; $2.destroy(); |
| 975 | delete $3; $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 976 | } |
| 977 | | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 978 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 979 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 980 | $$ = $1; |
| 981 | } |
| 982 | | VAARG ResolvedVal ',' Types { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 983 | *$1 += " " + *$2.val + ", " + *$4.newTy; |
| 984 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 985 | $$ = $1; |
| 986 | } |
| 987 | | EXTRACTELEMENT ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 988 | *$1 += " " + *$2.val + ", " + *$4.val; |
| 989 | $2.destroy(); $4.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 990 | $$ = $1; |
| 991 | } |
| 992 | | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 993 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 994 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 995 | $$ = $1; |
| 996 | } |
| 997 | | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 998 | *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val; |
| 999 | $2.destroy(); $4.destroy(); $6.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1000 | $$ = $1; |
| 1001 | } |
| 1002 | | PHI_TOK PHIList { |
| 1003 | *$1 += " " + *$2; |
| 1004 | delete $2; |
| 1005 | $$ = $1; |
| 1006 | } |
| 1007 | | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' { |
| 1008 | if (!$2->empty()) |
| 1009 | *$1 += " " + *$2; |
| 1010 | if (!$1->empty()) |
| 1011 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1012 | *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")"; |
| 1013 | delete $2; $3.destroy(); delete $4; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1014 | $$ = $1; |
| 1015 | } |
| 1016 | | MemoryInst ; |
| 1017 | |
| 1018 | |
| 1019 | // IndexList - List of indices for GEP based instructions... |
| 1020 | IndexList |
| 1021 | : ',' ValueRefList { |
| 1022 | $2->insert(0, ", "); |
| 1023 | $$ = $2; |
| 1024 | } |
| 1025 | | /* empty */ { $$ = new std::string(); } |
| 1026 | ; |
| 1027 | |
| 1028 | OptVolatile |
| 1029 | : VOLATILE |
| 1030 | | /* empty */ { $$ = new std::string(); } |
| 1031 | ; |
| 1032 | |
| 1033 | MemoryInst : MALLOC Types OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1034 | *$1 += " " + *$2.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1035 | if (!$3->empty()) |
| 1036 | *$1 += " " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1037 | $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1038 | $$ = $1; |
| 1039 | } |
| 1040 | | MALLOC Types ',' UINT ValueRef OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1041 | *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1042 | if (!$6->empty()) |
| 1043 | *$1 += " " + *$6; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1044 | $2.destroy(); $4.destroy(); delete $5; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1045 | $$ = $1; |
| 1046 | } |
| 1047 | | ALLOCA Types OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1048 | *$1 += " " + *$2.newTy; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1049 | if (!$3->empty()) |
| 1050 | *$1 += " " + *$3; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1051 | $2.destroy(); delete $3; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1052 | $$ = $1; |
| 1053 | } |
| 1054 | | ALLOCA Types ',' UINT ValueRef OptCAlign { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1055 | *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1056 | if (!$6->empty()) |
| 1057 | *$1 += " " + *$6; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1058 | $2.destroy(); $4.destroy(); delete $5; delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1059 | $$ = $1; |
| 1060 | } |
| 1061 | | FREE ResolvedVal { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1062 | *$1 += " " + *$2.val; |
| 1063 | $2.destroy(); |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1064 | $$ = $1; |
| 1065 | } |
| 1066 | | OptVolatile LOAD Types ValueRef { |
| 1067 | if (!$1->empty()) |
| 1068 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1069 | *$1 += *$2 + " " + *$3.newTy + " " + *$4; |
| 1070 | delete $2; $3.destroy(); delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1071 | $$ = $1; |
| 1072 | } |
| 1073 | | OptVolatile STORE ResolvedVal ',' Types ValueRef { |
| 1074 | if (!$1->empty()) |
| 1075 | *$1 += " "; |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1076 | *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6; |
| 1077 | delete $2; $3.destroy(); $5.destroy(); delete $6; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1078 | $$ = $1; |
| 1079 | } |
| 1080 | | GETELEMENTPTR Types ValueRef IndexList { |
Reid Spencer | e77e35e | 2006-12-01 20:26:20 +0000 | [diff] [blame^] | 1081 | *$1 += *$2.newTy + " " + *$3 + " " + *$4; |
| 1082 | $2.destroy(); delete $3; delete $4; |
Reid Spencer | e7c3c60 | 2006-11-30 06:36:44 +0000 | [diff] [blame] | 1083 | $$ = $1; |
| 1084 | }; |
| 1085 | |
| 1086 | %% |
| 1087 | |
| 1088 | int yyerror(const char *ErrorMsg) { |
| 1089 | std::string where |
| 1090 | = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename) |
| 1091 | + ":" + llvm::utostr((unsigned) Upgradelineno) + ": "; |
| 1092 | std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading "; |
| 1093 | if (yychar == YYEMPTY || yychar == 0) |
| 1094 | errMsg += "end-of-file."; |
| 1095 | else |
| 1096 | errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'"; |
| 1097 | std::cerr << errMsg << '\n'; |
| 1098 | exit(1); |
| 1099 | } |