1 //===-- UpgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the bison parser for LLVM 1.9 assembly language.
12 //===----------------------------------------------------------------------===//
15 #include "ParserInternals.h"
16 #include <llvm/ADT/StringExtras.h>
22 #define YYERROR_VERBOSE 1
23 #define YYINCLUDED_STDLIB_H
26 int yylex(); // declaration" of xxx warnings.
30 static std::string CurFilename;
31 static std::ostream *O = 0;
32 std::istream* LexInput = 0;
33 unsigned SizeOfPointer = 32;
35 void UpgradeAssembly(const std::string &infile, std::istream& in,
36 std::ostream &out, bool debug)
45 std::cerr << "Parse failed.\n";
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)
59 else if (DstBits > SrcBits) { // its an extension
61 opcode ="sext"; // signed -> SEXT
63 opcode = "zext"; // unsigned -> ZEXT
65 opcode = "bitcast"; // Same size, No-op cast
67 } else if (SrcTy.isFloatingPoint()) { // Casting from floating pt
69 opcode = "fptosi"; // FP -> sint
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
77 assert(SrcTy.isPointer() &&
78 "Casting from a value that is not first-class type");
79 opcode = "ptrtoint"; // ptr -> int
81 } else if (DstTy.isFloatingPoint()) { // Casting to floating pt
82 if (SrcTy.isIntegral()) { // Casting from integral
84 opcode = "sitofp"; // sint -> FP
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
93 opcode ="bitcast"; // same size, no-op cast
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
100 assert(0 && "Casting pointer or non-first class to float");
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
110 assert(!"Illegal cast to packed (wrong type or size)");
112 } else if (DstTy.isPointer()) {
113 if (SrcTy.isPointer()) {
114 opcode = "bitcast"; // ptr -> ptr
115 } else if (SrcTy.isIntegral()) {
116 opcode = "inttoptr"; // int -> ptr
118 assert(!"Casting pointer to other than pointer or int");
121 assert(!"Casting to type that is not first-class");
128 %file-prefix="UpgradeParser"
137 %token <Const> ESINT64VAL EUINT64VAL SINTVAL UINTVAL FPVAL TRUETOK FALSETOK
138 %token <Const> NULL_TOK UNDEF ZEROINITIALIZER
140 %token <Type> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
141 %token <Type> FLOAT DOUBLE LABEL OPAQUE
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
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
175 %type <String> ConstVector
177 %type <Type> IntType SIntType UIntType FPType TypesV Types
178 %type <Type> PrimType UpRTypesV UpRTypes
180 %type <Const> IntVal EInt64Val ConstVal
182 %type <Value> ResolvedVal
188 // Handle constant integer size restriction and conversion...
189 IntVal : SINTVAL | UINTVAL
190 EInt64Val : ESINT64VAL | EUINT64VAL;
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;
197 ShiftOps : SHL | LSHR | ASHR;
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;
206 // OptAssign - Value producing statements have an optional assignment component
207 OptAssign : Name '=' {
212 $$ = new std::string("");
216 : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT
218 | /*empty*/ { $$ = new std::string(""); } ;
221 : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK
223 | CC_TOK EUINT64VAL {
228 | /*empty*/ { $$ = new std::string(""); } ;
230 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
231 // a comma before it.
233 : /*empty*/ { $$ = new std::string(); }
234 | ALIGN EUINT64VAL { *$1 += " " + *$2.cnst; delete $2.cnst; $$ = $1; };
237 : /*empty*/ { $$ = new std::string(); }
238 | ',' ALIGN EUINT64VAL {
240 *$2 += " " + *$3.cnst;
246 : SECTION STRINGCONSTANT {
252 OptSection : /*empty*/ { $$ = new std::string(); }
256 : /* empty */ { $$ = new std::string(); }
257 | ',' GlobalVarAttribute GlobalVarAttributes {
268 *$1 += " " + *$2.cnst;
273 //===----------------------------------------------------------------------===//
274 // Types includes all predefined types... except void, because it can only be
275 // used in specific contexts (function returning void for example). To have
276 // access to it, a user must explicitly use TypesV.
279 // TypesV includes all of 'Types', but it also includes the void type.
280 TypesV : Types | VOID ;
281 UpRTypesV : UpRTypes | VOID ;
284 // Derived types are added later...
286 PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
287 PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL;
288 UpRTypes : OPAQUE | PrimType
290 $$.newTy = $1; $$.oldTy = OpaqueTy;
293 // Include derived types in the Types production.
295 UpRTypes : '\\' EUINT64VAL { // Type UpReference
296 $2.cnst->insert(0, "\\");
300 | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
301 *$1.newTy += "( " + *$3 + " )";
304 $$.oldTy = FunctionTy;
306 | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
307 $2.cnst->insert(0,"[ ");
308 *$2.cnst += " x " + *$4.newTy + " ]";
313 | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
314 $2.cnst->insert(0,"< ");
315 *$2.cnst += " x " + *$4.newTy + " >";
320 | '{' TypeListI '}' { // Structure type?
326 | '{' '}' { // Empty structure type?
327 $$.newTy = new std::string("{ }");
330 | UpRTypes '*' { // Pointer type?
332 $1.oldTy = PointerTy;
336 // TypeList - Used for struct declarations and as a basis for function type
337 // declaration type lists
343 | TypeListI ',' UpRTypes {
344 *$1 += ", " + *$3.newTy;
349 // ArgTypeList - List of types for a function type declaration...
352 | TypeListI ',' DOTDOTDOT {
361 $$ = new std::string();
364 // ConstVal - The various declarations that go into the constant pool. This
365 // production is used ONLY to represent constants that show up AFTER a 'const',
366 // 'constant' or 'global' token at global scope. Constants that can be inlined
367 // into other expressions (such as integers and constexprs) are handled by the
368 // ResolvedVal, ValueRef and ConstValueRef productions.
370 ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
372 $$.cnst = new std::string(*$1.newTy);
373 *$$.cnst += " [ " + *$3 + " ]";
378 $$.cnst = new std::string(*$1.newTy);
381 | Types 'c' STRINGCONSTANT {
383 $$.cnst = new std::string(*$1.newTy);
384 *$$.cnst += " c" + *$3;
387 | Types '<' ConstVector '>' { // Nonempty unsized arr
389 $$.cnst = new std::string(*$1.newTy);
390 *$$.cnst += " < " + *$3 + " >";
393 | Types '{' ConstVector '}' {
395 $$.cnst = new std::string(*$1.newTy);
396 *$$.cnst += " { " + *$3 + " }";
401 $$.cnst = new std::string(*$1.newTy);
406 $$.cnst = new std::string(*$1.newTy);
407 *$$.cnst += " " + *$2.cnst;
412 $$.cnst = new std::string(*$1.newTy);
413 *$$.cnst += " " + *$2.cnst;
416 | Types SymbolicValueRef {
418 $$.cnst = new std::string(*$1.newTy);
419 *$$.cnst += " " + *$2;
424 $$.cnst = new std::string(*$1.newTy);
425 *$$.cnst += " " + *$2;
428 | Types ZEROINITIALIZER {
430 $$.cnst = new std::string(*$1.newTy);
431 *$$.cnst += " " + *$2.cnst;
434 | SIntType EInt64Val { // integral constants
436 $$.cnst = new std::string(*$1.newTy);
437 *$$.cnst += " " + *$2.cnst;
440 | UIntType EUINT64VAL { // integral constants
442 $$.cnst = new std::string(*$1.newTy);
443 *$$.cnst += " " + *$2.cnst;
446 | BOOL TRUETOK { // Boolean constants
448 $$.cnst = new std::string(*$1.newTy);
449 *$$.cnst += " " + *$2.cnst;
452 | BOOL FALSETOK { // Boolean constants
454 $$.cnst = new std::string(*$1.newTy);
455 *$$.cnst += " " + *$2.cnst;
458 | FPType FPVAL { // Float & Double constants
460 $$.cnst = new std::string(*$1.newTy);
461 *$$.cnst += " " + *$2.cnst;
466 ConstExpr: CAST '(' ConstVal TO Types ')' {
467 // We must infer the cast opcode from the types of the operands.
468 const char *opcode = getCastOpcode($3.type, $5);
469 $$ = new std::string(opcode);
470 *$$ += "(" + *$3.cnst + " " + *$4 + " " + *$5.newTy + ")";
471 delete $1; $3.destroy(); delete $4; $5.destroy();
473 | GETELEMENTPTR '(' ConstVal IndexList ')' {
474 *$1 += "(" + *$3.cnst + " " + *$4 + ")";
479 | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
480 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
481 $3.destroy(); $5.destroy(); $7.destroy();
484 | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
485 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
486 $3.destroy(); $5.destroy();
489 | LogicalOps '(' ConstVal ',' ConstVal ')' {
490 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
491 $3.destroy(); $5.destroy();
494 | SetCondOps '(' ConstVal ',' ConstVal ')' {
495 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
496 $3.destroy(); $5.destroy();
499 | ShiftOps '(' ConstVal ',' ConstVal ')' {
500 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
501 $3.destroy(); $5.destroy();
504 | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
505 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
506 $3.destroy(); $5.destroy();
509 | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
510 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
511 $3.destroy(); $5.destroy(); $7.destroy();
514 | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
515 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
516 $3.destroy(); $5.destroy(); $7.destroy();
521 // ConstVector - A list of comma separated constants.
524 : ConstVector ',' ConstVal {
525 *$1 += ", " + *$3.cnst;
529 | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); }
533 // GlobalType - Match either GLOBAL or CONSTANT for global declarations...
534 GlobalType : GLOBAL | CONSTANT ;
537 //===----------------------------------------------------------------------===//
538 // Rules to match Modules
539 //===----------------------------------------------------------------------===//
541 // Module rule: Capture the result of parsing the whole file into a result
544 Module : DefinitionList {
547 // DefinitionList - Top level definitions
549 DefinitionList : DefinitionList Function {
552 | DefinitionList FunctionProto {
557 | DefinitionList MODULE ASM_TOK AsmBlock {
558 *O << "module asm " << " " << *$4 << "\n";
561 | DefinitionList IMPLEMENTATION {
562 *O << "implementation\n";
567 // ConstPool - Constants with optional names assigned to them.
568 ConstPool : ConstPool OptAssign TYPE TypesV {
569 *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n";
570 // delete $2; delete $3; $4.destroy();
573 | ConstPool FunctionProto { // Function prototypes can be in const pool
578 | ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool
579 *O << *$2 << " " << *$3 << " " << *$4 << "\n";
580 delete $2; delete $3; delete $4;
583 | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
584 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " "
586 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
589 | ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes {
590 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
591 << " " << *$6 << "\n";
592 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
595 | ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes {
596 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
597 << " " << *$6 << "\n";
598 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
601 | ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
602 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
603 << " " << *$6 << "\n";
604 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
607 | ConstPool TARGET TargetDefinition {
608 *O << *$2 << " " << *$3 << "\n";
609 delete $2; delete $3;
612 | ConstPool DEPLIBS '=' LibrariesDefinition {
613 *O << *$2 << " = " << *$4 << "\n";
614 delete $2; delete $4;
617 | /* empty: end of list */ {
622 AsmBlock : STRINGCONSTANT ;
624 BigOrLittle : BIG | LITTLE
627 : ENDIAN '=' BigOrLittle {
632 | POINTERSIZE '=' EUINT64VAL {
633 *$1 += " = " + *$3.cnst;
634 if (*$3.cnst == "64")
639 | TRIPLE '=' STRINGCONSTANT {
644 | DATALAYOUT '=' STRINGCONSTANT {
658 : LibList ',' STRINGCONSTANT {
664 | /* empty: end of list */ {
665 $$ = new std::string();
668 //===----------------------------------------------------------------------===//
669 // Rules to match Function Headers
670 //===----------------------------------------------------------------------===//
672 Name : VAR_ID | STRINGCONSTANT;
673 OptName : Name | /*empty*/ { $$ = new std::string(); };
675 ArgVal : Types OptName {
682 ArgListH : ArgListH ',' ArgVal {
693 | ArgListH ',' DOTDOTDOT {
701 | /* empty */ { $$ = new std::string(); };
703 FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
704 OptSection OptAlign {
708 *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")";
724 $$ = new std::string("begin");
727 $$ = new std::string ("{");
730 FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
734 *O << *$2 << " " << *$3 << "\n";
735 delete $1; delete $2; delete $3;
739 END : ENDTOK { $$ = new std::string("end"); }
740 | '}' { $$ = new std::string("}"); };
742 Function : FunctionHeader BasicBlockList END {
745 *O << '\n' << *$3 << "\n";
750 : /*default*/ { $$ = new std::string(); }
756 : DECLARE FnDeclareLinkage FunctionHeaderH {
765 //===----------------------------------------------------------------------===//
766 // Rules to match Basic Blocks
767 //===----------------------------------------------------------------------===//
769 OptSideEffect : /* empty */ { $$ = new std::string(); }
773 : ESINT64VAL { $$ = $1.cnst; }
774 | EUINT64VAL { $$ = $1.cnst; }
775 | FPVAL { $$ = $1.cnst; }
776 | TRUETOK { $$ = $1.cnst; }
777 | FALSETOK { $$ = $1.cnst; }
778 | NULL_TOK { $$ = $1.cnst; }
779 | UNDEF { $$ = $1.cnst; }
780 | ZEROINITIALIZER { $$ = $1.cnst; }
781 | '<' ConstVector '>' {
787 | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
791 *$1 += " " + *$3 + ", " + *$5;
792 delete $2; delete $3; delete $5;
796 SymbolicValueRef : IntVal { $$ = $1.cnst; } | Name ;
798 // ValueRef - A reference to a definition... either constant or symbolic
799 ValueRef : SymbolicValueRef | ConstValueRef;
802 // ResolvedVal - a <type> <value> pair. This is used only in cases where the
803 // type immediately preceeds the value reference, and allows complex constant
804 // pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
805 ResolvedVal : Types ValueRef {
807 $$.val = new std::string(*$1.newTy + " ");
812 BasicBlockList : BasicBlockList BasicBlock {
814 | BasicBlock { // Do not allow functions with 0 basic blocks
818 // Basic blocks are terminated by branching instructions:
819 // br, br/cc, switch, ret
821 BasicBlock : InstructionList BBTerminatorInst {
825 InstructionList : InstructionList Inst {
826 *O << " " << *$2 << "\n";
839 BBTerminatorInst : RET ResolvedVal { // Return with a result...
840 *O << " " << *$1 << " " << *$2.val << "\n";
841 delete $1; $2.destroy();
844 | RET VOID { // Return with no result...
845 *O << " " << *$1 << " " << *$2.newTy << "\n";
846 delete $1; $2.destroy();
849 | BR LABEL ValueRef { // Unconditional Branch...
850 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n";
851 delete $1; $2.destroy(); delete $3;
853 } // Conditional Branch...
854 | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
855 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
856 << *$5.newTy << " " << *$6 << ", " << *$8.newTy << " " << *$9 << "\n";
857 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
858 $8.destroy(); delete $9;
861 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
862 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " << *$5.newTy
863 << " " << *$6 << " [" << *$8 << " ]\n";
864 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; delete $8;
867 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
868 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
869 << *$5.newTy << " " << *$6 << "[]\n";
870 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
873 | OptAssign INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
874 TO LABEL ValueRef UNWIND LABEL ValueRef {
878 *O << *$2 << " " << *$3 << " " << *$4.newTy << " " << *$5 << " ("
879 << *$7 << ") " << *$9 << " " << *$10.newTy << " " << *$11 << " "
880 << *$12 << " " << *$13.newTy << " " << *$14 << "\n";
881 delete $1; delete $2; delete $3; $4.destroy(); delete $5; delete $7;
882 delete $9; $10.destroy(); delete $11; delete $12; $13.destroy();
887 *O << " " << *$1 << "\n";
892 *O << " " << *$1 << "\n";
897 JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
898 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6;
899 $2.destroy(); delete $3; $5.destroy(); delete $6;
902 | IntType ConstValueRef ',' LABEL ValueRef {
903 $2->insert(0, *$1.newTy + " " );
904 *$2 += ", " + *$4.newTy + " " + *$5;
905 $1.destroy(); $4.destroy(); delete $5;
910 : OptAssign InstVal {
917 : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
918 $3->insert(0, *$1.newTy + "[");
919 *$3 += "," + *$5 + "]";
920 $1.destroy(); delete $5;
923 | PHIList ',' '[' ValueRef ',' ValueRef ']' {
924 *$1 += ", [" + *$4 + "," + *$6 + "]";
925 delete $4; delete $6;
931 : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); }
932 | ValueRefList ',' ResolvedVal {
933 *$1 += ", " + *$3.val;
938 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
941 | /*empty*/ { $$ = new std::string(); }
953 InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
954 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
955 $2.destroy(); delete $3; delete $5;
958 | LogicalOps Types ValueRef ',' ValueRef {
959 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
960 $2.destroy(); delete $3; delete $5;
963 | SetCondOps Types ValueRef ',' ValueRef {
964 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
965 $2.destroy(); delete $3; delete $5;
969 *$1 += " " + *$2.val;
973 | ShiftOps ResolvedVal ',' ResolvedVal {
974 *$1 += " " + *$2.val + ", " + *$4.val;
975 $2.destroy(); $4.destroy();
978 | CAST ResolvedVal TO Types {
979 const char *opcode = getCastOpcode($2.type, $4);
980 $$ = new std::string(opcode);
981 *$$ += *$2.val + " " + *$3 + " " + *$4.newTy;
982 delete $1; $2.destroy();
983 delete $3; $4.destroy();
985 | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
986 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
987 $2.destroy(); $4.destroy(); $6.destroy();
990 | VAARG ResolvedVal ',' Types {
991 *$1 += " " + *$2.val + ", " + *$4.newTy;
992 $2.destroy(); $4.destroy();
995 | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
996 *$1 += " " + *$2.val + ", " + *$4.val;
997 $2.destroy(); $4.destroy();
1000 | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1001 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1002 $2.destroy(); $4.destroy(); $6.destroy();
1005 | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1006 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1007 $2.destroy(); $4.destroy(); $6.destroy();
1015 | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
1020 *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")";
1021 delete $2; $3.destroy(); delete $4; delete $6;
1027 // IndexList - List of indices for GEP based instructions...
1029 : ',' ValueRefList {
1030 $2->insert(0, ", ");
1033 | /* empty */ { $$ = new std::string(); }
1038 | /* empty */ { $$ = new std::string(); }
1041 MemoryInst : MALLOC Types OptCAlign {
1042 *$1 += " " + *$2.newTy;
1045 $2.destroy(); delete $3;
1048 | MALLOC Types ',' UINT ValueRef OptCAlign {
1049 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1052 $2.destroy(); $4.destroy(); delete $5; delete $6;
1055 | ALLOCA Types OptCAlign {
1056 *$1 += " " + *$2.newTy;
1059 $2.destroy(); delete $3;
1062 | ALLOCA Types ',' UINT ValueRef OptCAlign {
1063 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1066 $2.destroy(); $4.destroy(); delete $5; delete $6;
1069 | FREE ResolvedVal {
1070 *$1 += " " + *$2.val;
1074 | OptVolatile LOAD Types ValueRef {
1077 *$1 += *$2 + " " + *$3.newTy + " " + *$4;
1078 delete $2; $3.destroy(); delete $4;
1081 | OptVolatile STORE ResolvedVal ',' Types ValueRef {
1084 *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6;
1085 delete $2; $3.destroy(); $5.destroy(); delete $6;
1088 | GETELEMENTPTR Types ValueRef IndexList {
1089 *$1 += *$2.newTy + " " + *$3 + " " + *$4;
1090 $2.destroy(); delete $3; delete $4;
1096 int yyerror(const char *ErrorMsg) {
1098 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
1099 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
1100 std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
1101 if (yychar == YYEMPTY || yychar == 0)
1102 errMsg += "end-of-file.";
1104 errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
1105 std::cerr << errMsg << '\n';