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
158 %token <String> CAST TRUNC ZEXT SEXT FPTRUNC FPEXT FPTOUI FPTOSI UITOFP SITOFP
159 %token <String> PTRTOINT INTTOPTR BITCAST
161 %type <String> OptAssign OptLinkage OptCallingConv OptAlign OptCAlign
162 %type <String> SectionString OptSection GlobalVarAttributes GlobalVarAttribute
163 %type <String> ArgTypeListI ConstExpr DefinitionList
164 %type <String> ConstPool TargetDefinition LibrariesDefinition LibList OptName
165 %type <String> ArgVal ArgListH ArgList FunctionHeaderH BEGIN FunctionHeader END
166 %type <String> Function FunctionProto BasicBlock TypeListI
167 %type <String> InstructionList BBTerminatorInst JumpTable Inst PHIList
168 %type <String> ValueRefList OptTailCall InstVal IndexList OptVolatile
169 %type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType
170 %type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock
171 %type <String> Name ValueRef ValueRefListE ConstValueRef
172 %type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps CastOps
174 %type <String> ConstVector
176 %type <Type> IntType SIntType UIntType FPType TypesV Types
177 %type <Type> PrimType UpRTypesV UpRTypes
179 %type <String> IntVal EInt64Val
180 %type <Const> 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 | SHR | ASHR | LSHR;
198 CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | FPTOUI | FPTOSI |
199 UITOFP | SITOFP | PTRTOINT | INTTOPTR | BITCAST | CAST
202 // These are some types that allow classification if we only want a particular
203 // thing... for example, only a signed, unsigned, or integral type.
204 SIntType : LONG | INT | SHORT | SBYTE;
205 UIntType : ULONG | UINT | USHORT | UBYTE;
206 IntType : SIntType | UIntType;
207 FPType : FLOAT | DOUBLE;
209 // OptAssign - Value producing statements have an optional assignment component
210 OptAssign : Name '=' {
215 $$ = new std::string("");
219 : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT
221 | /*empty*/ { $$ = new std::string(""); } ;
224 : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK
226 | CC_TOK EUINT64VAL {
231 | /*empty*/ { $$ = new std::string(""); } ;
233 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
234 // a comma before it.
236 : /*empty*/ { $$ = new std::string(); }
237 | ALIGN EUINT64VAL { *$1 += " " + *$2; delete $2; $$ = $1; };
240 : /*empty*/ { $$ = new std::string(); }
241 | ',' ALIGN EUINT64VAL {
249 : SECTION STRINGCONSTANT {
255 OptSection : /*empty*/ { $$ = new std::string(); }
259 : /* empty */ { $$ = new std::string(); }
260 | ',' GlobalVarAttribute GlobalVarAttributes {
276 //===----------------------------------------------------------------------===//
277 // Types includes all predefined types... except void, because it can only be
278 // used in specific contexts (function returning void for example). To have
279 // access to it, a user must explicitly use TypesV.
282 // TypesV includes all of 'Types', but it also includes the void type.
283 TypesV : Types | VOID ;
284 UpRTypesV : UpRTypes | VOID ;
287 // Derived types are added later...
289 PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
290 PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL;
291 UpRTypes : OPAQUE | PrimType
293 $$.newTy = $1; $$.oldTy = OpaqueTy;
296 // Include derived types in the Types production.
298 UpRTypes : '\\' EUINT64VAL { // Type UpReference
303 | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
304 *$1.newTy += "( " + *$3 + " )";
307 $$.oldTy = FunctionTy;
309 | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
311 *$2 += " x " + *$4.newTy + " ]";
316 | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
318 *$2 += " x " + *$4.newTy + " >";
323 | '{' TypeListI '}' { // Structure type?
329 | '{' '}' { // Empty structure type?
330 $$.newTy = new std::string("{ }");
333 | UpRTypes '*' { // Pointer type?
335 $1.oldTy = PointerTy;
339 // TypeList - Used for struct declarations and as a basis for function type
340 // declaration type lists
346 | TypeListI ',' UpRTypes {
347 *$1 += ", " + *$3.newTy;
352 // ArgTypeList - List of types for a function type declaration...
355 | TypeListI ',' DOTDOTDOT {
364 $$ = new std::string();
367 // ConstVal - The various declarations that go into the constant pool. This
368 // production is used ONLY to represent constants that show up AFTER a 'const',
369 // 'constant' or 'global' token at global scope. Constants that can be inlined
370 // into other expressions (such as integers and constexprs) are handled by the
371 // ResolvedVal, ValueRef and ConstValueRef productions.
373 ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
375 $$.cnst = new std::string(*$1.newTy);
376 *$$.cnst += " [ " + *$3 + " ]";
381 $$.cnst = new std::string(*$1.newTy);
384 | Types 'c' STRINGCONSTANT {
386 $$.cnst = new std::string(*$1.newTy);
387 *$$.cnst += " c" + *$3;
390 | Types '<' ConstVector '>' { // Nonempty unsized arr
392 $$.cnst = new std::string(*$1.newTy);
393 *$$.cnst += " < " + *$3 + " >";
396 | Types '{' ConstVector '}' {
398 $$.cnst = new std::string(*$1.newTy);
399 *$$.cnst += " { " + *$3 + " }";
404 $$.cnst = new std::string(*$1.newTy);
409 $$.cnst = new std::string(*$1.newTy);
410 *$$.cnst += " " + *$2;
415 $$.cnst = new std::string(*$1.newTy);
416 *$$.cnst += " " + *$2;
419 | Types SymbolicValueRef {
421 $$.cnst = new std::string(*$1.newTy);
422 *$$.cnst += " " + *$2;
427 $$.cnst = new std::string(*$1.newTy);
428 *$$.cnst += " " + *$2;
431 | Types ZEROINITIALIZER {
433 $$.cnst = new std::string(*$1.newTy);
434 *$$.cnst += " " + *$2;
437 | SIntType EInt64Val { // integral constants
439 $$.cnst = new std::string(*$1.newTy);
440 *$$.cnst += " " + *$2;
443 | UIntType EUINT64VAL { // integral constants
445 $$.cnst = new std::string(*$1.newTy);
446 *$$.cnst += " " + *$2;
449 | BOOL TRUETOK { // Boolean constants
451 $$.cnst = new std::string(*$1.newTy);
452 *$$.cnst += " " + *$2;
455 | BOOL FALSETOK { // Boolean constants
457 $$.cnst = new std::string(*$1.newTy);
458 *$$.cnst += " " + *$2;
461 | FPType FPVAL { // Float & Double constants
463 $$.cnst = new std::string(*$1.newTy);
464 *$$.cnst += " " + *$2;
469 ConstExpr: CastOps '(' ConstVal TO Types ')' {
470 // We must infer the cast opcode from the types of the operands.
471 const char *opcode = $1->c_str();
473 opcode = getCastOpcode($3.type, $5);
474 $$ = new std::string(opcode);
475 *$$ += "(" + *$3.cnst + " " + *$4 + " " + *$5.newTy + ")";
476 delete $1; $3.destroy(); delete $4; $5.destroy();
478 | GETELEMENTPTR '(' ConstVal IndexList ')' {
479 *$1 += "(" + *$3.cnst + " " + *$4 + ")";
484 | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
485 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
486 $3.destroy(); $5.destroy(); $7.destroy();
489 | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
490 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
491 $3.destroy(); $5.destroy();
494 | LogicalOps '(' ConstVal ',' ConstVal ')' {
495 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
496 $3.destroy(); $5.destroy();
499 | SetCondOps '(' ConstVal ',' ConstVal ')' {
500 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
501 $3.destroy(); $5.destroy();
504 | ShiftOps '(' ConstVal ',' ConstVal ')' {
505 const char* shiftop = $1->c_str();
507 shiftop = ($3.type.isUnsigned()) ? "lshr" : "ashr";
508 $$ = new std::string(shiftop);
509 *$$ += "(" + *$3.cnst + "," + *$5.cnst + ")";
510 delete $1; $3.destroy(); $5.destroy();
512 | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
513 *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
514 $3.destroy(); $5.destroy();
517 | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
518 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
519 $3.destroy(); $5.destroy(); $7.destroy();
522 | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
523 *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
524 $3.destroy(); $5.destroy(); $7.destroy();
529 // ConstVector - A list of comma separated constants.
532 : ConstVector ',' ConstVal {
533 *$1 += ", " + *$3.cnst;
537 | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); }
541 // GlobalType - Match either GLOBAL or CONSTANT for global declarations...
542 GlobalType : GLOBAL | CONSTANT ;
545 //===----------------------------------------------------------------------===//
546 // Rules to match Modules
547 //===----------------------------------------------------------------------===//
549 // Module rule: Capture the result of parsing the whole file into a result
552 Module : DefinitionList {
555 // DefinitionList - Top level definitions
557 DefinitionList : DefinitionList Function {
560 | DefinitionList FunctionProto {
565 | DefinitionList MODULE ASM_TOK AsmBlock {
566 *O << "module asm " << " " << *$4 << "\n";
569 | DefinitionList IMPLEMENTATION {
570 *O << "implementation\n";
575 // ConstPool - Constants with optional names assigned to them.
576 ConstPool : ConstPool OptAssign TYPE TypesV {
577 *O << *$2 << " " << *$3 << " " << *$4.newTy << "\n";
578 // delete $2; delete $3; $4.destroy();
581 | ConstPool FunctionProto { // Function prototypes can be in const pool
586 | ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool
587 *O << *$2 << " " << *$3 << " " << *$4 << "\n";
588 delete $2; delete $3; delete $4;
591 | ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
592 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.cnst << " "
594 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
597 | ConstPool OptAssign EXTERNAL 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 DLLIMPORT 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 OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
610 *O << *$2 << " " << *$3 << " " << *$4 << " " << *$5.newTy
611 << " " << *$6 << "\n";
612 delete $2; delete $3; delete $4; $5.destroy(); delete $6;
615 | ConstPool TARGET TargetDefinition {
616 *O << *$2 << " " << *$3 << "\n";
617 delete $2; delete $3;
620 | ConstPool DEPLIBS '=' LibrariesDefinition {
621 *O << *$2 << " = " << *$4 << "\n";
622 delete $2; delete $4;
625 | /* empty: end of list */ {
630 AsmBlock : STRINGCONSTANT ;
632 BigOrLittle : BIG | LITTLE
635 : ENDIAN '=' BigOrLittle {
640 | POINTERSIZE '=' EUINT64VAL {
647 | TRIPLE '=' STRINGCONSTANT {
652 | DATALAYOUT '=' STRINGCONSTANT {
666 : LibList ',' STRINGCONSTANT {
672 | /* empty: end of list */ {
673 $$ = new std::string();
676 //===----------------------------------------------------------------------===//
677 // Rules to match Function Headers
678 //===----------------------------------------------------------------------===//
680 Name : VAR_ID | STRINGCONSTANT;
681 OptName : Name | /*empty*/ { $$ = new std::string(); };
683 ArgVal : Types OptName {
690 ArgListH : ArgListH ',' ArgVal {
701 | ArgListH ',' DOTDOTDOT {
709 | /* empty */ { $$ = new std::string(); };
711 FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
712 OptSection OptAlign {
716 *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")";
732 $$ = new std::string("begin");
735 $$ = new std::string ("{");
738 FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
742 *O << *$2 << " " << *$3 << "\n";
743 delete $1; delete $2; delete $3;
747 END : ENDTOK { $$ = new std::string("end"); }
748 | '}' { $$ = new std::string("}"); };
750 Function : FunctionHeader BasicBlockList END {
753 *O << '\n' << *$3 << "\n";
758 : /*default*/ { $$ = new std::string(); }
764 : DECLARE FnDeclareLinkage FunctionHeaderH {
773 //===----------------------------------------------------------------------===//
774 // Rules to match Basic Blocks
775 //===----------------------------------------------------------------------===//
777 OptSideEffect : /* empty */ { $$ = new std::string(); }
781 : ESINT64VAL | EUINT64VAL | FPVAL | TRUETOK | FALSETOK | NULL_TOK | UNDEF
783 | '<' ConstVector '>' {
789 | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
793 *$1 += " " + *$3 + ", " + *$5;
794 delete $2; delete $3; delete $5;
798 SymbolicValueRef : IntVal | Name ;
800 // ValueRef - A reference to a definition... either constant or symbolic
801 ValueRef : SymbolicValueRef | ConstValueRef;
804 // ResolvedVal - a <type> <value> pair. This is used only in cases where the
805 // type immediately preceeds the value reference, and allows complex constant
806 // pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
807 ResolvedVal : Types ValueRef {
809 $$.val = new std::string(*$1.newTy + " ");
814 BasicBlockList : BasicBlockList BasicBlock {
817 | BasicBlock { // Do not allow functions with 0 basic blocks
822 // Basic blocks are terminated by branching instructions:
823 // br, br/cc, switch, ret
825 BasicBlock : InstructionList BBTerminatorInst {
829 InstructionList : InstructionList Inst {
830 *O << " " << *$2 << "\n";
843 BBTerminatorInst : RET ResolvedVal { // Return with a result...
844 *O << " " << *$1 << " " << *$2.val << "\n";
845 delete $1; $2.destroy();
848 | RET VOID { // Return with no result...
849 *O << " " << *$1 << " " << *$2.newTy << "\n";
850 delete $1; $2.destroy();
853 | BR LABEL ValueRef { // Unconditional Branch...
854 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << "\n";
855 delete $1; $2.destroy(); delete $3;
857 } // Conditional Branch...
858 | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
859 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
860 << *$5.newTy << " " << *$6 << ", " << *$8.newTy << " " << *$9 << "\n";
861 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
862 $8.destroy(); delete $9;
865 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
866 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", " << *$5.newTy
867 << " " << *$6 << " [" << *$8 << " ]\n";
868 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6; delete $8;
871 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
872 *O << " " << *$1 << " " << *$2.newTy << " " << *$3 << ", "
873 << *$5.newTy << " " << *$6 << "[]\n";
874 delete $1; $2.destroy(); delete $3; $5.destroy(); delete $6;
877 | OptAssign INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
878 TO LABEL ValueRef UNWIND LABEL ValueRef {
882 *O << *$2 << " " << *$3 << " " << *$4.newTy << " " << *$5 << " ("
883 << *$7 << ") " << *$9 << " " << *$10.newTy << " " << *$11 << " "
884 << *$12 << " " << *$13.newTy << " " << *$14 << "\n";
885 delete $1; delete $2; delete $3; $4.destroy(); delete $5; delete $7;
886 delete $9; $10.destroy(); delete $11; delete $12; $13.destroy();
891 *O << " " << *$1 << "\n";
896 *O << " " << *$1 << "\n";
901 JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
902 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6;
903 $2.destroy(); delete $3; $5.destroy(); delete $6;
906 | IntType ConstValueRef ',' LABEL ValueRef {
907 $2->insert(0, *$1.newTy + " " );
908 *$2 += ", " + *$4.newTy + " " + *$5;
909 $1.destroy(); $4.destroy(); delete $5;
914 : OptAssign InstVal {
921 : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
922 $3->insert(0, *$1.newTy + "[");
923 *$3 += "," + *$5 + "]";
924 $1.destroy(); delete $5;
927 | PHIList ',' '[' ValueRef ',' ValueRef ']' {
928 *$1 += ", [" + *$4 + "," + *$6 + "]";
929 delete $4; delete $6;
935 : ResolvedVal { $$ = new std::string(*$1.val); $1.destroy(); }
936 | ValueRefList ',' ResolvedVal {
937 *$1 += ", " + *$3.val;
942 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
945 | /*empty*/ { $$ = new std::string(); }
957 InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
958 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
959 $2.destroy(); delete $3; delete $5;
962 | LogicalOps Types ValueRef ',' ValueRef {
963 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
964 $2.destroy(); delete $3; delete $5;
967 | SetCondOps Types ValueRef ',' ValueRef {
968 *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5;
969 $2.destroy(); delete $3; delete $5;
973 *$1 += " " + *$2.val;
977 | ShiftOps ResolvedVal ',' ResolvedVal {
978 const char* shiftop = $1->c_str();
980 shiftop = ($2.type.isUnsigned()) ? "lshr" : "ashr";
981 $$ = new std::string(shiftop);
982 *$$ += " " + *$2.val + ", " + *$4.val;
983 delete $1; $2.destroy(); $4.destroy();
985 | CastOps ResolvedVal TO Types {
986 const char *opcode = $1->c_str();
988 opcode = getCastOpcode($2.type, $4);
989 $$ = new std::string(opcode);
990 *$$ += *$2.val + " " + *$3 + " " + *$4.newTy;
991 delete $1; $2.destroy();
992 delete $3; $4.destroy();
994 | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
995 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
996 $2.destroy(); $4.destroy(); $6.destroy();
999 | VAARG ResolvedVal ',' Types {
1000 *$1 += " " + *$2.val + ", " + *$4.newTy;
1001 $2.destroy(); $4.destroy();
1004 | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
1005 *$1 += " " + *$2.val + ", " + *$4.val;
1006 $2.destroy(); $4.destroy();
1009 | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1010 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1011 $2.destroy(); $4.destroy(); $6.destroy();
1014 | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1015 *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1016 $2.destroy(); $4.destroy(); $6.destroy();
1024 | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
1029 *$1 += *$3.newTy + " " + *$4 + "(" + *$6 + ")";
1030 delete $2; $3.destroy(); delete $4; delete $6;
1036 // IndexList - List of indices for GEP based instructions...
1038 : ',' ValueRefList {
1039 $2->insert(0, ", ");
1042 | /* empty */ { $$ = new std::string(); }
1047 | /* empty */ { $$ = new std::string(); }
1050 MemoryInst : MALLOC Types OptCAlign {
1051 *$1 += " " + *$2.newTy;
1054 $2.destroy(); delete $3;
1057 | MALLOC Types ',' UINT ValueRef OptCAlign {
1058 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1061 $2.destroy(); $4.destroy(); delete $5; delete $6;
1064 | ALLOCA Types OptCAlign {
1065 *$1 += " " + *$2.newTy;
1068 $2.destroy(); delete $3;
1071 | ALLOCA Types ',' UINT ValueRef OptCAlign {
1072 *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5;
1075 $2.destroy(); $4.destroy(); delete $5; delete $6;
1078 | FREE ResolvedVal {
1079 *$1 += " " + *$2.val;
1083 | OptVolatile LOAD Types ValueRef {
1086 *$1 += *$2 + " " + *$3.newTy + " " + *$4;
1087 delete $2; $3.destroy(); delete $4;
1090 | OptVolatile STORE ResolvedVal ',' Types ValueRef {
1093 *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6;
1094 delete $2; $3.destroy(); $5.destroy(); delete $6;
1097 | GETELEMENTPTR Types ValueRef IndexList {
1098 *$1 += *$2.newTy + " " + *$3 + " " + *$4;
1099 $2.destroy(); delete $3; delete $4;
1105 int yyerror(const char *ErrorMsg) {
1107 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
1108 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
1109 std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
1110 if (yychar == YYEMPTY || yychar == 0)
1111 errMsg += "end-of-file.";
1113 errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
1114 std::cerr << errMsg << '\n';