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 <Type> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
138 %token <Type> FLOAT DOUBLE LABEL OPAQUE
139 %token <String> ESINT64VAL EUINT64VAL SINTVAL UINTVAL FPVAL
140 %token <String> NULL_TOK UNDEF ZEROINITIALIZER TRUETOK FALSETOK
141 %token <String> TYPE VAR_ID LABELSTR STRINGCONSTANT
142 %token <String> IMPLEMENTATION BEGINTOK ENDTOK
143 %token <String> DECLARE GLOBAL CONSTANT SECTION VOLATILE
144 %token <String> TO DOTDOTDOT CONST INTERNAL LINKONCE WEAK
145 %token <String> DLLIMPORT DLLEXPORT EXTERN_WEAK APPENDING
146 %token <String> NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG
147 %token <String> ALIGN
148 %token <String> DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
149 %token <String> CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
150 %token <String> X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
151 %token <String> DATALAYOUT
152 %token <String> RET BR SWITCH INVOKE UNWIND UNREACHABLE
153 %token <String> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
154 %token <String> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
155 %token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
156 %token <String> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
157 %token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
160 %type <String> OptAssign OptLinkage OptCallingConv OptAlign OptCAlign
161 %type <String> SectionString OptSection GlobalVarAttributes GlobalVarAttribute
162 %type <String> ArgTypeListI ConstExpr DefinitionList
163 %type <String> ConstPool TargetDefinition LibrariesDefinition LibList OptName
164 %type <String> ArgVal ArgListH ArgList FunctionHeaderH BEGIN FunctionHeader END
165 %type <String> Function FunctionProto BasicBlock TypeListI
166 %type <String> InstructionList BBTerminatorInst JumpTable Inst PHIList
167 %type <String> ValueRefList OptTailCall InstVal IndexList OptVolatile
168 %type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType
169 %type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock
170 %type <String> Name ValueRef ValueRefListE
171 %type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps ConstValueRef
173 %type <String> ConstVector
175 %type <Type> IntType SIntType UIntType FPType TypesV Types
176 %type <Type> PrimType UpRTypesV UpRTypes
178 %type <String> IntVal EInt64Val
179 %type <Const> ConstVal
181 %type <Value> ResolvedVal
187 // Handle constant integer size restriction and conversion...
188 IntVal : SINTVAL | UINTVAL ;
189 EInt64Val : ESINT64VAL | EUINT64VAL;
191 // Operations that are notably excluded from this list include:
192 // RET, BR, & SWITCH because they end basic blocks and are treated specially.
193 ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
194 LogicalOps : AND | OR | XOR;
195 SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
196 ShiftOps : SHL | SHR | ASHR | LSHR;
198 // These are some types that allow classification if we only want a particular
199 // thing... for example, only a signed, unsigned, or integral type.
200 SIntType : LONG | INT | SHORT | SBYTE;
201 UIntType : ULONG | UINT | USHORT | UBYTE;
202 IntType : SIntType | UIntType;
203 FPType : FLOAT | DOUBLE;
205 // OptAssign - Value producing statements have an optional assignment component
206 OptAssign : Name '=' {
211 $$ = new std::string("");
215 : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT
217 | /*empty*/ { $$ = new std::string(""); } ;
220 : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK
222 | CC_TOK EUINT64VAL {
227 | /*empty*/ { $$ = new std::string(""); } ;
229 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
230 // a comma before it.
232 : /*empty*/ { $$ = new std::string(); }
233 | ALIGN EUINT64VAL { *$1 += " " + *$2; delete $2; $$ = $1; };
236 : /*empty*/ { $$ = new std::string(); }
237 | ',' ALIGN EUINT64VAL {
245 : SECTION STRINGCONSTANT {
251 OptSection : /*empty*/ { $$ = new std::string(); }
255 : /* empty */ { $$ = new std::string(); }
256 | ',' GlobalVarAttribute GlobalVarAttributes {
272 //===----------------------------------------------------------------------===//
273 // Types includes all predefined types... except void, because it can only be
274 // used in specific contexts (function returning void for example). To have
275 // access to it, a user must explicitly use TypesV.
278 // TypesV includes all of 'Types', but it also includes the void type.
279 TypesV : Types | VOID ;
280 UpRTypesV : UpRTypes | VOID ;
283 // Derived types are added later...
285 PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
286 PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL;
287 UpRTypes : OPAQUE | PrimType
289 $$.newTy = $1; $$.oldTy = OpaqueTy;
292 // Include derived types in the Types production.
294 UpRTypes : '\\' EUINT64VAL { // Type UpReference
299 | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
300 *$1.newTy += "( " + *$3 + " )";
303 $$.oldTy = FunctionTy;
305 | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
307 *$2 += " x " + *$4.newTy + " ]";
312 | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
314 *$2 += " x " + *$4.newTy + " >";
319 | '{' TypeListI '}' { // Structure type?
325 | '{' '}' { // Empty structure type?
326 $$.newTy = new std::string("{ }");
329 | UpRTypes '*' { // Pointer type?
331 $1.oldTy = PointerTy;
335 // TypeList - Used for struct declarations and as a basis for function type
336 // declaration type lists
342 | TypeListI ',' UpRTypes {
343 *$1 += ", " + *$3.newTy;
348 // ArgTypeList - List of types for a function type declaration...
351 | TypeListI ',' DOTDOTDOT {
360 $$ = new std::string();
363 // ConstVal - The various declarations that go into the constant pool. This
364 // production is used ONLY to represent constants that show up AFTER a 'const',
365 // 'constant' or 'global' token at global scope. Constants that can be inlined
366 // into other expressions (such as integers and constexprs) are handled by the
367 // ResolvedVal, ValueRef and ConstValueRef productions.
369 ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
371 $$.cnst = new std::string(*$1.newTy);
372 *$$.cnst += " [ " + *$3 + " ]";
377 $$.cnst = new std::string(*$1.newTy);
380 | Types 'c' STRINGCONSTANT {
382 $$.cnst = new std::string(*$1.newTy);
383 *$$.cnst += " c" + *$3;
386 | Types '<' ConstVector '>' { // Nonempty unsized arr
388 $$.cnst = new std::string(*$1.newTy);
389 *$$.cnst += " < " + *$3 + " >";
392 | Types '{' ConstVector '}' {
394 $$.cnst = new std::string(*$1.newTy);
395 *$$.cnst += " { " + *$3 + " }";
400 $$.cnst = new std::string(*$1.newTy);
405 $$.cnst = new std::string(*$1.newTy);
406 *$$.cnst += " " + *$2;
411 $$.cnst = new std::string(*$1.newTy);
412 *$$.cnst += " " + *$2;
415 | Types SymbolicValueRef {
417 $$.cnst = new std::string(*$1.newTy);
418 *$$.cnst += " " + *$2;
423 $$.cnst = new std::string(*$1.newTy);
424 *$$.cnst += " " + *$2;
427 | Types ZEROINITIALIZER {
429 $$.cnst = new std::string(*$1.newTy);
430 *$$.cnst += " " + *$2;
433 | SIntType EInt64Val { // integral constants
435 $$.cnst = new std::string(*$1.newTy);
436 *$$.cnst += " " + *$2;
439 | UIntType EUINT64VAL { // integral constants
441 $$.cnst = new std::string(*$1.newTy);
442 *$$.cnst += " " + *$2;
445 | BOOL TRUETOK { // Boolean constants
447 $$.cnst = new std::string(*$1.newTy);
448 *$$.cnst += " " + *$2;
451 | BOOL FALSETOK { // Boolean constants
453 $$.cnst = new std::string(*$1.newTy);
454 *$$.cnst += " " + *$2;
457 | FPType FPVAL { // Float & Double constants
459 $$.cnst = new std::string(*$1.newTy);
460 *$$.cnst += " " + *$2;
465 ConstExpr: CAST '(' ConstVal TO Types ')' {
466 // We must infer the cast opcode from the types of the operands.
467 const char *opcode = getCastOpcode($3.type, $5);
468 $$ = new std::string(opcode);
469 *$$ += "(" + *$3.cnst + " " + *$4 + " " + *$5.newTy + ")";
470 delete $1; $3.destroy(); delete $4; $5.destroy();
472 | GETELEMENTPTR '(' ConstVal IndexList ')' {
473 *$1 += "(" + *$3.cnst + " " + *$4 + ")";
478 | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
479 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
480 $3.destroy(); $5.destroy(); $7.destroy();
483 | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
484 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
485 $3.destroy(); $5.destroy();
488 | LogicalOps '(' ConstVal ',' ConstVal ')' {
489 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
490 $3.destroy(); $5.destroy();
493 | SetCondOps '(' ConstVal ',' ConstVal ')' {
494 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
495 $3.destroy(); $5.destroy();
498 | ShiftOps '(' ConstVal ',' ConstVal ')' {
499 const char* shiftop = $1->c_str();
501 shiftop = ($3.type.isUnsigned()) ? "lshr" : "ashr";
502 $$ = new std::string(shiftop);
503 *$$ += "(" + *$3.cnst + "," + *$5.cnst + ")";
504 delete $1; $3.destroy(); $5.destroy();
506 | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
507 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
508 $3.destroy(); $5.destroy();
511 | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
512 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
513 $3.destroy(); $5.destroy(); $7.destroy();
516 | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
517 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
518 $3.destroy(); $5.destroy(); $7.destroy();
523 // ConstVector - A list of comma separated constants.
526 : ConstVector ',' ConstVal {
527 *$1 += ", " + *$3.cnst;
531 | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); }
535 // GlobalType - Match either GLOBAL or CONSTANT for global declarations...
536 GlobalType : GLOBAL | CONSTANT ;
539 //===----------------------------------------------------------------------===//
540 // Rules to match Modules
541 //===----------------------------------------------------------------------===//
543 // Module rule: Capture the result of parsing the whole file into a result
546 Module : DefinitionList {
549 // DefinitionList - Top level definitions
551 DefinitionList : DefinitionList Function {
554 | DefinitionList FunctionProto {
559 | DefinitionList MODULE ASM_TOK AsmBlock {
560 *O << "module asm " << " " << *$4 << "\n";
563 | DefinitionList IMPLEMENTATION {
564 *O << "implementation\n";
569 // ConstPool - Constants with optional names assigned to them.
570 ConstPool : ConstPool OptAssign TYPE TypesV {
571 *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n";
572 // delete $2; delete $3; $4.destroy();
575 | ConstPool FunctionProto { // Function prototypes can be in const pool
580 | ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool
581 *O << *$2 << " " << *$3 << " " << *$4 << "\n";
582 delete $2; delete $3; delete $4;
585 | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
586 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " "
588 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
591 | ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes {
592 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
593 << " " << *$6 << "\n";
594 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
597 | ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes {
598 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
599 << " " << *$6 << "\n";
600 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
603 | ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
604 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
605 << " " << *$6 << "\n";
606 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
609 | ConstPool TARGET TargetDefinition {
610 *O << *$2 << " " << *$3 << "\n";
611 delete $2; delete $3;
614 | ConstPool DEPLIBS '=' LibrariesDefinition {
615 *O << *$2 << " = " << *$4 << "\n";
616 delete $2; delete $4;
619 | /* empty: end of list */ {
624 AsmBlock : STRINGCONSTANT ;
626 BigOrLittle : BIG | LITTLE
629 : ENDIAN '=' BigOrLittle {
634 | POINTERSIZE '=' EUINT64VAL {
641 | TRIPLE '=' STRINGCONSTANT {
646 | DATALAYOUT '=' STRINGCONSTANT {
660 : LibList ',' STRINGCONSTANT {
666 | /* empty: end of list */ {
667 $$ = new std::string();
670 //===----------------------------------------------------------------------===//
671 // Rules to match Function Headers
672 //===----------------------------------------------------------------------===//
674 Name : VAR_ID | STRINGCONSTANT;
675 OptName : Name | /*empty*/ { $$ = new std::string(); };
677 ArgVal : Types OptName {
684 ArgListH : ArgListH ',' ArgVal {
695 | ArgListH ',' DOTDOTDOT {
703 | /* empty */ { $$ = new std::string(); };
705 FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
706 OptSection OptAlign {
710 *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")";
726 $$ = new std::string("begin");
729 $$ = new std::string ("{");
732 FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
736 *O << *$2 << " " << *$3 << "\n";
737 delete $1; delete $2; delete $3;
741 END : ENDTOK { $$ = new std::string("end"); }
742 | '}' { $$ = new std::string("}"); };
744 Function : FunctionHeader BasicBlockList END {
747 *O << '\n' << *$3 << "\n";
752 : /*default*/ { $$ = new std::string(); }
758 : DECLARE FnDeclareLinkage FunctionHeaderH {
767 //===----------------------------------------------------------------------===//
768 // Rules to match Basic Blocks
769 //===----------------------------------------------------------------------===//
771 OptSideEffect : /* empty */ { $$ = new std::string(); }
775 : ESINT64VAL | EUINT64VAL | FPVAL | TRUETOK | FALSETOK | NULL_TOK | UNDEF
777 | '<' ConstVector '>' {
783 | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
787 *$1 += " " + *$3 + ", " + *$5;
788 delete $2; delete $3; delete $5;
792 SymbolicValueRef : IntVal | Name ;
794 // ValueRef - A reference to a definition... either constant or symbolic
795 ValueRef : SymbolicValueRef | ConstValueRef;
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 {
803 $$.val = new std::string(*$1.newTy + " ");
808 BasicBlockList : BasicBlockList BasicBlock {
811 | BasicBlock { // Do not allow functions with 0 basic blocks
816 // Basic blocks are terminated by branching instructions:
817 // br, br/cc, switch, ret
819 BasicBlock : InstructionList BBTerminatorInst {
823 InstructionList : InstructionList Inst {
824 *O << " " << *$2 << "\n";
837 BBTerminatorInst : RET ResolvedVal { // Return with a result...
838 *O << " " << *$1 << " " << *$2.val << "\n";
839 delete $1; $2.destroy();
842 | RET VOID { // Return with no result...
843 *O << " " << *$1 << " " << *$2.newTy << "\n";
844 delete $1; $2.destroy();
847 | BR LABEL ValueRef { // Unconditional Branch...
848 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n";
849 delete $1; $2.destroy(); delete $3;
851 } // Conditional Branch...
852 | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
853 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
854 << *$5.newTy << " " << *$6 << ", " << *$8.newTy << " " << *$9 << "\n";
855 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
856 $8.destroy(); delete $9;
859 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
860 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " << *$5.newTy
861 << " " << *$6 << " [" << *$8 << " ]\n";
862 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; delete $8;
865 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
866 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
867 << *$5.newTy << " " << *$6 << "[]\n";
868 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
871 | OptAssign INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
872 TO LABEL ValueRef UNWIND LABEL ValueRef {
876 *O << *$2 << " " << *$3 << " " << *$4.newTy << " " << *$5 << " ("
877 << *$7 << ") " << *$9 << " " << *$10.newTy << " " << *$11 << " "
878 << *$12 << " " << *$13.newTy << " " << *$14 << "\n";
879 delete $1; delete $2; delete $3; $4.destroy(); delete $5; delete $7;
880 delete $9; $10.destroy(); delete $11; delete $12; $13.destroy();
885 *O << " " << *$1 << "\n";
890 *O << " " << *$1 << "\n";
895 JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
896 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6;
897 $2.destroy(); delete $3; $5.destroy(); delete $6;
900 | IntType ConstValueRef ',' LABEL ValueRef {
901 $2->insert(0, *$1.newTy + " " );
902 *$2 += ", " + *$4.newTy + " " + *$5;
903 $1.destroy(); $4.destroy(); delete $5;
908 : OptAssign InstVal {
915 : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
916 $3->insert(0, *$1.newTy + "[");
917 *$3 += "," + *$5 + "]";
918 $1.destroy(); delete $5;
921 | PHIList ',' '[' ValueRef ',' ValueRef ']' {
922 *$1 += ", [" + *$4 + "," + *$6 + "]";
923 delete $4; delete $6;
929 : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); }
930 | ValueRefList ',' ResolvedVal {
931 *$1 += ", " + *$3.val;
936 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
939 | /*empty*/ { $$ = new std::string(); }
951 InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
952 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
953 $2.destroy(); delete $3; delete $5;
956 | LogicalOps Types ValueRef ',' ValueRef {
957 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
958 $2.destroy(); delete $3; delete $5;
961 | SetCondOps Types ValueRef ',' ValueRef {
962 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
963 $2.destroy(); delete $3; delete $5;
967 *$1 += " " + *$2.val;
971 | ShiftOps ResolvedVal ',' ResolvedVal {
972 const char* shiftop = $1->c_str();
974 shiftop = ($2.type.isUnsigned()) ? "lshr" : "ashr";
975 $$ = new std::string(shiftop);
976 *$$ += " " + *$2.val + ", " + *$4.val;
977 delete $1; $2.destroy(); $4.destroy();
979 | CAST ResolvedVal TO Types {
980 const char *opcode = getCastOpcode($2.type, $4);
981 $$ = new std::string(opcode);
982 *$$ += *$2.val + " " + *$3 + " " + *$4.newTy;
983 delete $1; $2.destroy();
984 delete $3; $4.destroy();
986 | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
987 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
988 $2.destroy(); $4.destroy(); $6.destroy();
991 | VAARG ResolvedVal ',' Types {
992 *$1 += " " + *$2.val + ", " + *$4.newTy;
993 $2.destroy(); $4.destroy();
996 | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
997 *$1 += " " + *$2.val + ", " + *$4.val;
998 $2.destroy(); $4.destroy();
1001 | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1002 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1003 $2.destroy(); $4.destroy(); $6.destroy();
1006 | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1007 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1008 $2.destroy(); $4.destroy(); $6.destroy();
1016 | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
1021 *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")";
1022 delete $2; $3.destroy(); delete $4; delete $6;
1028 // IndexList - List of indices for GEP based instructions...
1030 : ',' ValueRefList {
1031 $2->insert(0, ", ");
1034 | /* empty */ { $$ = new std::string(); }
1039 | /* empty */ { $$ = new std::string(); }
1042 MemoryInst : MALLOC Types OptCAlign {
1043 *$1 += " " + *$2.newTy;
1046 $2.destroy(); delete $3;
1049 | MALLOC Types ',' UINT ValueRef OptCAlign {
1050 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1053 $2.destroy(); $4.destroy(); delete $5; delete $6;
1056 | ALLOCA Types OptCAlign {
1057 *$1 += " " + *$2.newTy;
1060 $2.destroy(); delete $3;
1063 | ALLOCA Types ',' UINT ValueRef OptCAlign {
1064 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1067 $2.destroy(); $4.destroy(); delete $5; delete $6;
1070 | FREE ResolvedVal {
1071 *$1 += " " + *$2.val;
1075 | OptVolatile LOAD Types ValueRef {
1078 *$1 += *$2 + " " + *$3.newTy + " " + *$4;
1079 delete $2; $3.destroy(); delete $4;
1082 | OptVolatile STORE ResolvedVal ',' Types ValueRef {
1085 *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6;
1086 delete $2; $3.destroy(); $5.destroy(); delete $6;
1089 | GETELEMENTPTR Types ValueRef IndexList {
1090 *$1 += *$2.newTy + " " + *$3 + " " + *$4;
1091 $2.destroy(); delete $3; delete $4;
1097 int yyerror(const char *ErrorMsg) {
1099 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
1100 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
1101 std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
1102 if (yychar == YYEMPTY || yychar == 0)
1103 errMsg += "end-of-file.";
1105 errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
1106 std::cerr << errMsg << '\n';