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
222 | X86_FASTCALLCC_TOK | CC_TOK EUINT64VAL
223 | /*empty*/ { $$ = new std::string(""); } ;
225 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
226 // a comma before it.
228 : /*empty*/ { $$ = new std::string(); }
229 | ALIGN EUINT64VAL { *$1 += " " + *$2.cnst; delete $2.cnst; $$ = $1; };
232 : /*empty*/ { $$ = new std::string(); }
233 | ',' ALIGN EUINT64VAL {
235 *$2 += " " + *$3.cnst;
241 : SECTION STRINGCONSTANT {
247 OptSection : /*empty*/ { $$ = new std::string(); }
251 : /* empty */ { $$ = new std::string(); }
252 | ',' GlobalVarAttribute GlobalVarAttributes {
263 *$1 += " " + *$2.cnst;
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.
274 // TypesV includes all of 'Types', but it also includes the void type.
275 TypesV : Types | VOID ;
276 UpRTypesV : UpRTypes | VOID ;
279 // Derived types are added later...
281 PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
282 PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL;
283 UpRTypes : OPAQUE | PrimType | SymbolicValueRef {
286 // Include derived types in the Types production.
288 UpRTypes : '\\' EUINT64VAL { // Type UpReference
289 $2.cnst->insert(0, "\\");
293 | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
294 *$1.newTy += "( " + *$3 + " )";
297 $$.oldTy = FunctionTy;
299 | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
300 $2.cnst->insert(0,"[ ");
301 *$2.cnst += " x " + *$4.newTy + " ]";
306 | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
307 $2.cnst->insert(0,"< ");
308 *$2.cnst += " x " + *$4.newTy + " >";
313 | '{' TypeListI '}' { // Structure type?
319 | '{' '}' { // Empty structure type?
320 $$.newTy = new std::string("{ }");
323 | UpRTypes '*' { // Pointer type?
325 $1.oldTy = PointerTy;
329 // TypeList - Used for struct declarations and as a basis for function type
330 // declaration type lists
336 | TypeListI ',' UpRTypes {
337 *$1 += ", " + *$3.newTy;
342 // ArgTypeList - List of types for a function type declaration...
345 | TypeListI ',' DOTDOTDOT {
354 $$ = new std::string();
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.
363 ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
365 $$.cnst = new std::string(*$1.newTy);
366 *$$.cnst += " [ " + *$3 + " ]";
371 $$.cnst = new std::string(*$1.newTy);
374 | Types 'c' STRINGCONSTANT {
376 $$.cnst = new std::string(*$1.newTy);
377 *$$.cnst += " c" + *$3;
380 | Types '<' ConstVector '>' { // Nonempty unsized arr
382 $$.cnst = new std::string(*$1.newTy);
383 *$$.cnst += " < " + *$3 + " >";
386 | Types '{' ConstVector '}' {
388 $$.cnst = new std::string(*$1.newTy);
389 *$$.cnst += " { " + *$3 + " }";
394 $$.cnst = new std::string(*$1.newTy);
399 $$.cnst = new std::string(*$1.newTy);
400 *$$.cnst += " " + *$2.cnst;
405 $$.cnst = new std::string(*$1.newTy);
406 *$$.cnst += " " + *$2.cnst;
409 | Types SymbolicValueRef {
411 $$.cnst = new std::string(*$1.newTy);
412 *$$.cnst += " " + *$2;
417 $$.cnst = new std::string(*$1.newTy);
418 *$$.cnst += " " + *$2;
421 | Types ZEROINITIALIZER {
423 $$.cnst = new std::string(*$1.newTy);
424 *$$.cnst += " " + *$2.cnst;
427 | SIntType EInt64Val { // integral constants
429 $$.cnst = new std::string(*$1.newTy);
430 *$$.cnst += " " + *$2.cnst;
433 | UIntType EUINT64VAL { // integral constants
435 $$.cnst = new std::string(*$1.newTy);
436 *$$.cnst += " " + *$2.cnst;
439 | BOOL TRUETOK { // Boolean constants
441 $$.cnst = new std::string(*$1.newTy);
442 *$$.cnst += " " + *$2.cnst;
445 | BOOL FALSETOK { // Boolean constants
447 $$.cnst = new std::string(*$1.newTy);
448 *$$.cnst += " " + *$2.cnst;
451 | FPType FPVAL { // Float & Double constants
453 $$.cnst = new std::string(*$1.newTy);
454 *$$.cnst += " " + *$2.cnst;
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();
466 | GETELEMENTPTR '(' ConstVal IndexList ')' {
467 *$1 += "(" + *$3.cnst + " " + *$4 + ")";
472 | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
473 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
474 $3.destroy(); $5.destroy(); $7.destroy();
477 | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
478 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
479 $3.destroy(); $5.destroy();
482 | LogicalOps '(' ConstVal ',' ConstVal ')' {
483 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
484 $3.destroy(); $5.destroy();
487 | SetCondOps '(' ConstVal ',' ConstVal ')' {
488 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
489 $3.destroy(); $5.destroy();
492 | ShiftOps '(' ConstVal ',' ConstVal ')' {
493 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
494 $3.destroy(); $5.destroy();
497 | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
498 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
499 $3.destroy(); $5.destroy();
502 | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
503 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
504 $3.destroy(); $5.destroy(); $7.destroy();
507 | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
508 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
509 $3.destroy(); $5.destroy(); $7.destroy();
514 // ConstVector - A list of comma separated constants.
517 : ConstVector ',' ConstVal {
518 *$1 += ", " + *$3.cnst;
522 | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); }
526 // GlobalType - Match either GLOBAL or CONSTANT for global declarations...
527 GlobalType : GLOBAL | CONSTANT ;
530 //===----------------------------------------------------------------------===//
531 // Rules to match Modules
532 //===----------------------------------------------------------------------===//
534 // Module rule: Capture the result of parsing the whole file into a result
537 Module : DefinitionList {
540 // DefinitionList - Top level definitions
542 DefinitionList : DefinitionList Function {
545 | DefinitionList FunctionProto {
550 | DefinitionList MODULE ASM_TOK AsmBlock {
551 *O << "module asm " << " " << *$4 << "\n";
553 | DefinitionList IMPLEMENTATION {
554 *O << "implementation\n";
559 // ConstPool - Constants with optional names assigned to them.
560 ConstPool : ConstPool OptAssign TYPE TypesV {
561 *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n";
562 // delete $2; delete $3; $4.destroy();
565 | ConstPool FunctionProto { // Function prototypes can be in const pool
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;
575 | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
576 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " "
578 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
581 | ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes {
582 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
583 << " " << *$6 << "\n";
584 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
587 | ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes {
588 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
589 << " " << *$6 << "\n";
590 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
593 | ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
594 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
595 << " " << *$6 << "\n";
596 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
599 | ConstPool TARGET TargetDefinition {
600 *O << *$2 << " " << *$3 << "\n";
601 delete $2; delete $3;
604 | ConstPool DEPLIBS '=' LibrariesDefinition {
605 *O << *$2 << " = " << *$4 << "\n";
606 delete $2; delete $4;
609 | /* empty: end of list */ {
614 AsmBlock : STRINGCONSTANT ;
616 BigOrLittle : BIG | LITTLE
619 : ENDIAN '=' BigOrLittle {
624 | POINTERSIZE '=' EUINT64VAL {
625 *$1 += " = " + *$3.cnst;
626 if (*$3.cnst == "64")
631 | TRIPLE '=' STRINGCONSTANT {
636 | DATALAYOUT '=' STRINGCONSTANT {
650 : LibList ',' STRINGCONSTANT {
656 | /* empty: end of list */ {
657 $$ = new std::string();
660 //===----------------------------------------------------------------------===//
661 // Rules to match Function Headers
662 //===----------------------------------------------------------------------===//
664 Name : VAR_ID | STRINGCONSTANT;
665 OptName : Name | /*empty*/ { $$ = new std::string(); };
667 ArgVal : Types OptName {
674 ArgListH : ArgListH ',' ArgVal {
685 | ArgListH ',' DOTDOTDOT {
694 $$ = new std::string();
697 FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
698 OptSection OptAlign {
702 *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")";
718 $$ = new std::string("begin");
721 $$ = new std::string ("{");
724 FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
728 *O << *$2 << " " << *$3 << "\n";
729 delete $1; delete $2; delete $3;
733 END : ENDTOK { $$ = new std::string("end"); }
734 | '}' { $$ = new std::string("}"); };
736 Function : FunctionHeader BasicBlockList END {
739 *O << '\n' << *$3 << "\n";
744 : /*default*/ { $$ = new std::string(); }
750 : DECLARE FnDeclareLinkage FunctionHeaderH {
759 //===----------------------------------------------------------------------===//
760 // Rules to match Basic Blocks
761 //===----------------------------------------------------------------------===//
763 OptSideEffect : /* empty */ {
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; }
777 | '<' ConstVector '>' {
783 | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
787 *$1 += " " + *$3 + ", " + *$5;
788 delete $2; delete $3; delete $5;
792 SymbolicValueRef : IntVal { $$ = $1.cnst; } | 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 {
810 | BasicBlock { // Do not allow functions with 0 basic blocks
814 // Basic blocks are terminated by branching instructions:
815 // br, br/cc, switch, ret
817 BasicBlock : InstructionList OptAssign BBTerminatorInst {
821 InstructionList : InstructionList Inst {
822 *O << " " << *$2 << "\n";
835 BBTerminatorInst : RET ResolvedVal { // Return with a result...
836 *O << " " << *$1 << " " << *$2.val << "\n";
837 delete $1; $2.destroy();
840 | RET VOID { // Return with no result...
841 *O << " " << *$1 << " " << *$2.newTy << "\n";
842 delete $1; $2.destroy();
845 | BR LABEL ValueRef { // Unconditional Branch...
846 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n";
847 delete $1; $2.destroy(); delete $3;
849 } // Conditional Branch...
850 | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
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;
857 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
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;
863 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
864 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
865 << *$5.newTy << " " << *$6 << "[]\n";
866 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
869 | INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
870 TO LABEL ValueRef UNWIND LABEL ValueRef {
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;
879 *O << " " << *$1 << "\n";
884 *O << " " << *$1 << "\n";
889 JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
890 *$1 += *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6;
891 $2.destroy(); delete $3; $5.destroy(); delete $6;
894 | IntType ConstValueRef ',' LABEL ValueRef {
895 $2->insert(0, *$1.newTy + " " );
896 *$2 += ", " + *$4.newTy + " " + *$5;
897 $1.destroy(); $4.destroy(); delete $5;
902 : OptAssign InstVal {
909 : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
910 $3->insert(0, *$1.newTy + "[");
911 *$3 += "," + *$5 + "]";
912 $1.destroy(); delete $5;
915 | PHIList ',' '[' ValueRef ',' ValueRef ']' {
916 *$1 += ", [" + *$4 + "," + *$6 + "]";
917 delete $4; delete $6;
923 : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); }
924 | ValueRefList ',' ResolvedVal {
925 *$1 += ", " + *$3.val;
930 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
933 | /*empty*/ { $$ = new std::string(); }
945 InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
946 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
947 $2.destroy(); delete $3; delete $5;
950 | LogicalOps Types ValueRef ',' ValueRef {
951 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
952 $2.destroy(); delete $3; delete $5;
955 | SetCondOps Types ValueRef ',' ValueRef {
956 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
957 $2.destroy(); delete $3; delete $5;
961 *$1 += " " + *$2.val;
965 | ShiftOps ResolvedVal ',' ResolvedVal {
966 *$1 += " " + *$2.val + ", " + *$4.val;
967 $2.destroy(); $4.destroy();
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();
977 | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
978 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
979 $2.destroy(); $4.destroy(); $6.destroy();
982 | VAARG ResolvedVal ',' Types {
983 *$1 += " " + *$2.val + ", " + *$4.newTy;
984 $2.destroy(); $4.destroy();
987 | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
988 *$1 += " " + *$2.val + ", " + *$4.val;
989 $2.destroy(); $4.destroy();
992 | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
993 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
994 $2.destroy(); $4.destroy(); $6.destroy();
997 | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
998 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
999 $2.destroy(); $4.destroy(); $6.destroy();
1007 | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
1012 *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")";
1013 delete $2; $3.destroy(); delete $4; delete $6;
1019 // IndexList - List of indices for GEP based instructions...
1021 : ',' ValueRefList {
1022 $2->insert(0, ", ");
1025 | /* empty */ { $$ = new std::string(); }
1030 | /* empty */ { $$ = new std::string(); }
1033 MemoryInst : MALLOC Types OptCAlign {
1034 *$1 += " " + *$2.newTy;
1037 $2.destroy(); delete $3;
1040 | MALLOC Types ',' UINT ValueRef OptCAlign {
1041 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1044 $2.destroy(); $4.destroy(); delete $5; delete $6;
1047 | ALLOCA Types OptCAlign {
1048 *$1 += " " + *$2.newTy;
1051 $2.destroy(); delete $3;
1054 | ALLOCA Types ',' UINT ValueRef OptCAlign {
1055 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1058 $2.destroy(); $4.destroy(); delete $5; delete $6;
1061 | FREE ResolvedVal {
1062 *$1 += " " + *$2.val;
1066 | OptVolatile LOAD Types ValueRef {
1069 *$1 += *$2 + " " + *$3.newTy + " " + *$4;
1070 delete $2; $3.destroy(); delete $4;
1073 | OptVolatile STORE ResolvedVal ',' Types ValueRef {
1076 *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6;
1077 delete $2; $3.destroy(); $5.destroy(); delete $6;
1080 | GETELEMENTPTR Types ValueRef IndexList {
1081 *$1 += *$2.newTy + " " + *$3 + " " + *$4;
1082 $2.destroy(); delete $3; delete $4;
1088 int yyerror(const char *ErrorMsg) {
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.";
1096 errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
1097 std::cerr << errMsg << '\n';