diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index 553ba8100e4..5e60654c84c 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -41,20 +41,16 @@ void set_scan_string (const char * str) { // Construct a token value for a non-obsolete token #define RET_TOK(type, Enum, sym) \ - llvmAsmlval.type.opcode = Instruction::Enum; \ - llvmAsmlval.type.obsolete = false; \ + llvmAsmlval.type = Instruction::Enum; \ + return sym + +#define RET_ENUM(type, Enum, sym) \ + llvmAsmlval.type = Enum; \ return sym // Construct a token value for an obsolete token -#define RET_TOK_OBSOLETE(type, Enum, sym) \ - llvmAsmlval.type.opcode = Instruction::Enum; \ - llvmAsmlval.type.obsolete = true; \ - return sym - -// Construct a token value for an obsolete token -#define RET_TY(CTYPE, SIGN, SYM) \ - llvmAsmlval.TypeVal.type = new PATypeHolder(CTYPE); \ - llvmAsmlval.TypeVal.signedness = SIGN; \ +#define RET_TY(CTYPE, SYM) \ + llvmAsmlval.PrimType = CTYPE;\ return SYM namespace llvm { @@ -209,7 +205,6 @@ appending { return APPENDING; } dllimport { return DLLIMPORT; } dllexport { return DLLEXPORT; } extern_weak { return EXTERN_WEAK; } -uninitialized { return EXTERNAL; } /* Deprecated, turn into external */ external { return EXTERNAL; } implementation { return IMPLEMENTATION; } zeroinitializer { return ZEROINITIALIZER; } @@ -217,8 +212,6 @@ zeroinitializer { return ZEROINITIALIZER; } undef { return UNDEF; } null { return NULL_TOK; } to { return TO; } -except { RET_TOK(TermOpVal, Unwind, UNWIND); } -not { return NOT; } /* Deprecated, turned into XOR */ tail { return TAIL; } target { return TARGET; } triple { return TRIPLE; } @@ -243,30 +236,28 @@ coldcc { return COLDCC_TOK; } x86_stdcallcc { return X86_STDCALLCC_TOK; } x86_fastcallcc { return X86_FASTCALLCC_TOK; } -void { RET_TY(Type::VoidTy, isSignless, VOID); } -bool { RET_TY(Type::BoolTy, isSignless, BOOL); } -sbyte { RET_TY(Type::SByteTy, isSigned, SBYTE); } -ubyte { RET_TY(Type::UByteTy, isUnsigned, UBYTE); } -short { RET_TY(Type::ShortTy, isSigned, SHORT); } -ushort { RET_TY(Type::UShortTy,isUnsigned, USHORT);} -int { RET_TY(Type::IntTy, isSigned, INT); } -uint { RET_TY(Type::UIntTy, isUnsigned, UINT); } -long { RET_TY(Type::LongTy, isSigned, LONG); } -ulong { RET_TY(Type::ULongTy, isUnsigned, ULONG); } -float { RET_TY(Type::FloatTy, isSignless, FLOAT); } -double { RET_TY(Type::DoubleTy,isSignless, DOUBLE);} -label { RET_TY(Type::LabelTy, isSignless, LABEL); } +void { RET_TY(Type::VoidTy, VOID); } +bool { RET_TY(Type::BoolTy, BOOL); } +sbyte { RET_TY(Type::SByteTy, SBYTE); } +ubyte { RET_TY(Type::UByteTy, UBYTE); } +short { RET_TY(Type::ShortTy, SHORT); } +ushort { RET_TY(Type::UShortTy,USHORT);} +int { RET_TY(Type::IntTy, INT); } +uint { RET_TY(Type::UIntTy, UINT); } +long { RET_TY(Type::LongTy, LONG); } +ulong { RET_TY(Type::ULongTy, ULONG); } +float { RET_TY(Type::FloatTy, FLOAT); } +double { RET_TY(Type::DoubleTy,DOUBLE);} +label { RET_TY(Type::LabelTy, LABEL); } type { return TYPE; } opaque { return OPAQUE; } add { RET_TOK(BinaryOpVal, Add, ADD); } sub { RET_TOK(BinaryOpVal, Sub, SUB); } mul { RET_TOK(BinaryOpVal, Mul, MUL); } -div { RET_TOK_OBSOLETE(BinaryOpVal, UDiv, UDIV); } udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); } sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); } fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); } -rem { RET_TOK_OBSOLETE(BinaryOpVal, URem, UREM); } urem { RET_TOK(BinaryOpVal, URem, UREM); } srem { RET_TOK(BinaryOpVal, SRem, SREM); } frem { RET_TOK(BinaryOpVal, FRem, FREM); } @@ -279,10 +270,35 @@ setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); } setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); } setle { RET_TOK(BinaryOpVal, SetLE, SETLE); } setge { RET_TOK(BinaryOpVal, SetGE, SETGE); } +icmp { RET_TOK(OtherOpVal, ICmp, ICMP); } +fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); } +eq { RET_ENUM(IPredicate, ICmpInst::ICMP_EQ, EQ); } +ne { RET_ENUM(IPredicate, ICmpInst::ICMP_NE, NE); } +slt { RET_ENUM(IPredicate, ICmpInst::ICMP_SLT, SLT); } +sgt { RET_ENUM(IPredicate, ICmpInst::ICMP_SGT, SGT); } +sle { RET_ENUM(IPredicate, ICmpInst::ICMP_SLE, SLE); } +sge { RET_ENUM(IPredicate, ICmpInst::ICMP_SGE, SGE); } +ult { RET_ENUM(IPredicate, ICmpInst::ICMP_ULT, ULT); } +ugt { RET_ENUM(IPredicate, ICmpInst::ICMP_UGT, UGT); } +ule { RET_ENUM(IPredicate, ICmpInst::ICMP_ULE, ULE); } +uge { RET_ENUM(IPredicate, ICmpInst::ICMP_UGE, UGE); } +ordeq { RET_ENUM(FPredicate, FCmpInst::FCMP_OEQ, ORDEQ); } +ordne { RET_ENUM(FPredicate, FCmpInst::FCMP_ONE, ORDNE); } +ordlt { RET_ENUM(FPredicate, FCmpInst::FCMP_OLT, ORDLT); } +ordgt { RET_ENUM(FPredicate, FCmpInst::FCMP_OGT, ORDGT); } +ordle { RET_ENUM(FPredicate, FCmpInst::FCMP_OLE, ORDLE); } +ordge { RET_ENUM(FPredicate, FCmpInst::FCMP_OGE, ORDGE); } +ord { RET_ENUM(FPredicate, FCmpInst::FCMP_ORD, ORD); } +uno { RET_ENUM(FPredicate, FCmpInst::FCMP_UNO, UNO); } +unoeq { RET_ENUM(FPredicate, FCmpInst::FCMP_UEQ, UNOEQ); } +unone { RET_ENUM(FPredicate, FCmpInst::FCMP_UNE, UNONE); } +unolt { RET_ENUM(FPredicate, FCmpInst::FCMP_ULT, UNOLT); } +unogt { RET_ENUM(FPredicate, FCmpInst::FCMP_UGT, UNOGT); } +unole { RET_ENUM(FPredicate, FCmpInst::FCMP_ULE, UNOLE); } +unoge { RET_ENUM(FPredicate, FCmpInst::FCMP_UGE, UNOGE); } phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); } call { RET_TOK(OtherOpVal, Call, CALL); } -cast { RET_TOK_OBSOLETE(CastOpVal, Trunc, TRUNC); } trunc { RET_TOK(CastOpVal, Trunc, TRUNC); } zext { RET_TOK(CastOpVal, ZExt, ZEXT); } sext { RET_TOK(CastOpVal, SExt, SEXT); } @@ -297,11 +313,8 @@ ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); } bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); } select { RET_TOK(OtherOpVal, Select, SELECT); } shl { RET_TOK(OtherOpVal, Shl, SHL); } -shr { RET_TOK_OBSOLETE(OtherOpVal, LShr, LSHR); } lshr { RET_TOK(OtherOpVal, LShr, LSHR); } ashr { RET_TOK(OtherOpVal, AShr, ASHR); } -vanext { return VANEXT_old; } -vaarg { return VAARG_old; } va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); } ret { RET_TOK(TermOpVal, Ret, RET); } br { RET_TOK(TermOpVal, Br, BR); } diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index 604057c9ba0..79e367fe1fe 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/lib/AsmParser/ParserInternals.h @@ -201,56 +201,4 @@ struct ValID { } // End llvm namespace -// This structure is used to keep track of obsolete opcodes. The lexer will -// retain the ability to parse obsolete opcode mnemonics. In this case it will -// set "obsolete" to true and the opcode will be the replacement opcode. For -// example if "rem" is encountered then opcode will be set to "urem" and the -// "obsolete" flag will be true. If the opcode is not obsolete then "obsolete" -// will be false. -template -struct OpcodeInfo { - Enum opcode; - bool obsolete; -}; -typedef OpcodeInfo BinaryOpInfo; -typedef OpcodeInfo TermOpInfo; -typedef OpcodeInfo MemOpInfo; -typedef OpcodeInfo CastOpInfo; -typedef OpcodeInfo OtherOpInfo; - -/// This enumeration is used to indicate if a type is signed, signless or -/// unsigned. It is used for backwards compatibility with assembly code that -/// pre-dates the signless types conversion. -enum Signedness { - isSigned, - isUnsigned, - isSignless -}; - -/// This type is used to keep track of the signedness of the obsolete -/// integer types. Instead of creating an llvm::Type directly, the Lexer will -/// create instances of TypeInfo which retains the signedness indication so -/// it can be used by the parser for upgrade decisions. -/// For example if "uint" is encountered then the "first" field will be set -/// to "int32" and the "second" field will be set to "isUnsigned". If the -/// type is not obsolete then "second" will be set to "isSignless". -struct TypeInfo { - llvm::PATypeHolder* type; - Signedness signedness; -}; - -/// This type is used to keep track of the signedness of values. Instead -/// of creating llvm::Value directly, the parser will create ValueInfo which -/// associates a Value* with a Signedness indication. -struct ValueInfo { - llvm::Value* val; - Signedness signedness; -}; - -/// This type is used to keep track of the signedness of constants. -struct ConstInfo { - llvm::Constant *cnst; - Signedness signedness; -}; - #endif diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 1d1558eb6be..8d0b7a27143 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -124,11 +124,6 @@ static struct PerModuleInfo { return; } - // Look for intrinsic functions and CallInst that need to be upgraded - for (Module::iterator FI = CurrentModule->begin(), - FE = CurrentModule->end(); FI != FE; ) - UpgradeCallsToIntrinsic(FI++); - Values.clear(); // Clear out function local definitions Types.clear(); CurrentModule = 0; @@ -254,7 +249,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { Type *Typ = OpaqueType::get(); CurModule.LateResolveTypes.insert(std::make_pair(D, Typ)); return Typ; -} + } static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) { SymbolTable &SymTab = @@ -813,71 +808,6 @@ static PATypeHolder HandleUpRefs(const Type *ty) { return Ty; } -/// This function is used to obtain the correct opcode for an instruction when -/// an obsolete opcode is encountered. The OI parameter (OpcodeInfo) has both -/// an opcode and an "obsolete" flag. These are generated by the lexer and -/// the "obsolete" member will be true when the lexer encounters the token for -/// an obsolete opcode. For example, "div" was replaced by [usf]div but we need -/// to maintain backwards compatibility for asm files that still have the "div" -/// instruction. This function handles converting div -> [usf]div appropriately. -/// @brief Convert obsolete BinaryOps opcodes to new values -static void -sanitizeOpcode(OpcodeInfo &OI, const Type *Ty) -{ - // If its not obsolete, don't do anything - if (!OI.obsolete) - return; - - // If its a packed type we want to use the element type - if (const PackedType *PTy = dyn_cast(Ty)) - Ty = PTy->getElementType(); - - // Depending on the opcode .. - switch (OI.opcode) { - default: - GenerateError("Invalid obsolete opCode (check Lexer.l)"); - break; - case Instruction::UDiv: - // Handle cases where the opcode needs to change - if (Ty->isFloatingPoint()) - OI.opcode = Instruction::FDiv; - else if (Ty->isSigned()) - OI.opcode = Instruction::SDiv; - break; - case Instruction::URem: - if (Ty->isFloatingPoint()) - OI.opcode = Instruction::FRem; - else if (Ty->isSigned()) - OI.opcode = Instruction::SRem; - break; - } - // Its not obsolete any more, we fixed it. - OI.obsolete = false; -} - -/// This function is similar to the previous overload of sanitizeOpcode but -/// operates on Instruction::OtherOps instead of Instruction::BinaryOps. -/// @brief Convert obsolete OtherOps opcodes to new values -static void -sanitizeOpcode(OpcodeInfo &OI, const Type *Ty) -{ - // If its not obsolete, don't do anything - if (!OI.obsolete) - return; - - switch (OI.opcode) { - default: - GenerateError("Invalid obsolete opcode (check Lexer.l)"); - break; - case Instruction::LShr: - if (Ty->isSigned()) - OI.opcode = Instruction::AShr; - break; - } - // Its not obsolete any more, we fixed it. - OI.obsolete = false; -} - // common code from the two 'RunVMAsmParser' functions static Module* RunParser(Module * M) { @@ -1038,21 +968,24 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %union { llvm::Module *ModuleVal; llvm::Function *FunctionVal; - std::pair *ArgVal; + std::pair *ArgVal; llvm::BasicBlock *BasicBlockVal; llvm::TerminatorInst *TermInstVal; llvm::Instruction *InstVal; - ConstInfo ConstVal; - TypeInfo TypeVal; - ValueInfo ValueVal; + llvm::Constant *ConstVal; - std::vector >*ArgList; - std::vector *ValueList; - std::list *TypeList; + const llvm::Type *PrimType; + llvm::PATypeHolder *TypeVal; + llvm::Value *ValueVal; + + std::vector > *ArgList; + std::vector *ValueList; + std::list *TypeList; // Represent the RHS of PHI node - std::list > *PHIList; + std::list > *PHIList; std::vector > *JumpTable; - std::vector *ConstVector; + std::vector *ConstVector; llvm::GlobalValue::LinkageTypes Linkage; int64_t SInt64Val; @@ -1065,12 +998,14 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { char *StrVal; // This memory is strdup'd! llvm::ValID ValIDVal; // strdup'd memory maybe! - BinaryOpInfo BinaryOpVal; - TermOpInfo TermOpVal; - MemOpInfo MemOpVal; - CastOpInfo CastOpVal; - OtherOpInfo OtherOpVal; + llvm::Instruction::BinaryOps BinaryOpVal; + llvm::Instruction::TermOps TermOpVal; + llvm::Instruction::MemoryOps MemOpVal; + llvm::Instruction::CastOps CastOpVal; + llvm::Instruction::OtherOps OtherOpVal; llvm::Module::Endianness Endianness; + llvm::ICmpInst::Predicate IPredicate; + llvm::FCmpInst::Predicate FPredicate; } %type Module FunctionList @@ -1113,9 +1048,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { // Built in types... %type Types TypesV UpRTypes UpRTypesV -%type SIntType UIntType IntType FPType PrimType // Classifications -%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG -%token FLOAT DOUBLE TYPE LABEL +%type SIntType UIntType IntType FPType PrimType // Classifications +%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG +%token FLOAT DOUBLE TYPE LABEL %token VAR_ID LABELSTR STRINGCONSTANT %type Name OptName OptAssign @@ -1140,6 +1075,12 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %type ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories %token ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR %token SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators +%token ICMP FCMP +%token EQ NE SLT SGT SLE SGE ULT UGT ULE UGE +%type IPredicates +%token ORDEQ ORDNE ORDLT ORDGT ORDLE ORDGE ORD UNO UNOEQ UNONE +%token UNOLT UNOGT UNOLE UNOGE +%type FPredicates // Memory Instructions %token MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR @@ -1187,6 +1128,9 @@ SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE; CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST | UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT; ShiftOps : SHL | LSHR | ASHR; +IPredicates : EQ | NE | SLT | SGT | SLE | SGE | ULT | UGT | ULE | UGE ; +FPredicates : ORDEQ | ORDNE | ORDLT | ORDGT | ORDLE | ORDGE | ORD | UNO + | UNOEQ | UNONE | UNOLT | UNOGT | UNOLE | UNOGE ; // These are some types that allow classification if we only want a particular // thing... for example, only a signed, unsigned, or integral type. @@ -1281,22 +1225,15 @@ GlobalVarAttribute : SectionString { // // TypesV includes all of 'Types', but it also includes the void type. -TypesV : Types | VOID { - $$.type = new PATypeHolder($1.type->get()); - $$.signedness = $1.signedness; -}; -UpRTypesV : UpRTypes | VOID { - $$.type = new PATypeHolder($1.type->get()); - $$.signedness = $1.signedness; -}; +TypesV : Types | VOID { $$ = new PATypeHolder($1); }; +UpRTypesV : UpRTypes | VOID { $$ = new PATypeHolder($1); }; Types : UpRTypes { if (!UpRefs.empty()) - GEN_ERROR("Invalid upreference in type: " + - ($1.type->get())->getDescription()); + GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); $$ = $1; CHECK_FOR_ERROR -}; + }; // Derived types are added later... @@ -1304,19 +1241,17 @@ Types : UpRTypes { PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ; PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL; UpRTypes : OPAQUE { - $$.type = new PATypeHolder(OpaqueType::get()); - $$.signedness = isSignless; + $$ = new PATypeHolder(OpaqueType::get()); CHECK_FOR_ERROR } | PrimType { - $$ = $1; + $$ = new PATypeHolder($1); CHECK_FOR_ERROR }; UpRTypes : SymbolicValueRef { // Named types are also simple types... const Type* tmp = getTypeVal($1); CHECK_FOR_ERROR - $$.type = new PATypeHolder(tmp); - $$.signedness = isSignless; + $$ = new PATypeHolder(tmp); }; // Include derived types in the Types production. @@ -1325,69 +1260,59 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!"); OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector... - $$.type = new PATypeHolder(OT); - $$.signedness = isSignless; + $$ = new PATypeHolder(OT); UR_OUT("New Upreference!\n"); CHECK_FOR_ERROR } | UpRTypesV '(' ArgTypeListI ')' { // Function derived type? std::vector Params; - for (std::list::iterator I = $3->begin(), + for (std::list::iterator I = $3->begin(), E = $3->end(); I != E; ++I) - Params.push_back(I->type->get()); + Params.push_back(*I); bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); - $$.type = new PATypeHolder(HandleUpRefs( - FunctionType::get($1.type->get(),Params,isVarArg))); - $$.signedness = isSignless; + $$ = new PATypeHolder(HandleUpRefs(FunctionType::get(*$1,Params,isVarArg))); delete $3; // Delete the argument list - delete $1.type; + delete $1; // Delete the return type handle CHECK_FOR_ERROR } | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? - $$.type = new PATypeHolder(HandleUpRefs( - ArrayType::get($4.type->get(), (unsigned)$2))); - $$.signedness = isSignless; - delete $4.type; + $$ = new PATypeHolder(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2))); + delete $4; CHECK_FOR_ERROR } | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type? - const llvm::Type* ElemTy = $4.type->get(); - if ((unsigned)$2 != $2) - GEN_ERROR("Unsigned result not equal to signed result"); - if (!ElemTy->isPrimitiveType()) - GEN_ERROR("Elemental type of a PackedType must be primitive"); - if (!isPowerOf2_32($2)) - GEN_ERROR("Vector length should be a power of 2!"); - $$.type = new PATypeHolder(HandleUpRefs( - PackedType::get($4.type->get(), (unsigned)$2))); - $$.signedness = isSignless; - delete $4.type; - CHECK_FOR_ERROR + const llvm::Type* ElemTy = $4->get(); + if ((unsigned)$2 != $2) + GEN_ERROR("Unsigned result not equal to signed result"); + if (!ElemTy->isPrimitiveType()) + GEN_ERROR("Elemental type of a PackedType must be primitive"); + if (!isPowerOf2_32($2)) + GEN_ERROR("Vector length should be a power of 2!"); + $$ = new PATypeHolder(HandleUpRefs(PackedType::get(*$4, (unsigned)$2))); + delete $4; + CHECK_FOR_ERROR } | '{' TypeListI '}' { // Structure type? std::vector Elements; - for (std::list::iterator I = $2->begin(), + for (std::list::iterator I = $2->begin(), E = $2->end(); I != E; ++I) - Elements.push_back((*I).type->get()); + Elements.push_back(*I); - $$.type = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); - $$.signedness = isSignless; + $$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); delete $2; CHECK_FOR_ERROR } | '{' '}' { // Empty structure type? - $$.type = new PATypeHolder(StructType::get(std::vector())); - $$.signedness = isSignless; + $$ = new PATypeHolder(StructType::get(std::vector())); CHECK_FOR_ERROR } | UpRTypes '*' { // Pointer type? - if ($1.type->get() == Type::LabelTy) + if (*$1 == Type::LabelTy) GEN_ERROR("Cannot form a pointer to a basic block"); - $$.type = new PATypeHolder(HandleUpRefs(PointerType::get($1.type->get()))); - $$.signedness = isSignless; - delete $1.type; + $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1))); + delete $1; CHECK_FOR_ERROR }; @@ -1395,31 +1320,27 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference // declaration type lists // TypeListI : UpRTypes { - $$ = new std::list(); - $$->push_back($1); + $$ = new std::list(); + $$->push_back(*$1); delete $1; CHECK_FOR_ERROR } | TypeListI ',' UpRTypes { - ($$=$1)->push_back($3); + ($$=$1)->push_back(*$3); delete $3; CHECK_FOR_ERROR }; // ArgTypeList - List of types for a function type declaration... ArgTypeListI : TypeListI | TypeListI ',' DOTDOTDOT { - TypeInfo TI; - TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless; - ($$=$1)->push_back(TI); + ($$=$1)->push_back(Type::VoidTy); CHECK_FOR_ERROR } | DOTDOTDOT { - TypeInfo TI; - TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless; - ($$ = new std::list())->push_back(TI); + ($$ = new std::list())->push_back(Type::VoidTy); CHECK_FOR_ERROR } | /*empty*/ { - $$ = new std::list(); + $$ = new std::list(); CHECK_FOR_ERROR }; @@ -1430,10 +1351,10 @@ ArgTypeListI : TypeListI // ResolvedVal, ValueRef and ConstValueRef productions. // ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr - const ArrayType *ATy = dyn_cast($1.type->get()); + const ArrayType *ATy = dyn_cast($1->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - ($1.type->get())->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); const Type *ETy = ATy->getElementType(); int NumElements = ATy->getNumElements(); @@ -1444,42 +1365,36 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr itostr(NumElements) + "!"); // Verify all elements are correct type! - std::vector elems; for (unsigned i = 0; i < $3->size(); i++) { - if (ETy != (*$3)[i].cnst->getType()) { + if (ETy != (*$3)[i]->getType()) GEN_ERROR("Element #" + utostr(i) + " is not of type '" + ETy->getDescription() +"' as required!\nIt is of type '"+ - (*$3)[i].cnst->getType()->getDescription() + "'."); - } else { - elems.push_back((*$3)[i].cnst); - } + (*$3)[i]->getType()->getDescription() + "'."); } - $$.cnst = ConstantArray::get(ATy, elems); - $$.signedness = isSignless; - delete $1.type; delete $3; + $$ = ConstantArray::get(ATy, *$3); + delete $1; delete $3; CHECK_FOR_ERROR } | Types '[' ']' { - const ArrayType *ATy = dyn_cast($1.type->get()); + const ArrayType *ATy = dyn_cast($1->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - ($1.type->get())->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); int NumElements = ATy->getNumElements(); if (NumElements != -1 && NumElements != 0) GEN_ERROR("Type mismatch: constant sized array initialized with 0" " arguments, but has size of " + itostr(NumElements) +"!"); - $$.cnst = ConstantArray::get(ATy, std::vector()); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantArray::get(ATy, std::vector()); + delete $1; CHECK_FOR_ERROR } | Types 'c' STRINGCONSTANT { - const ArrayType *ATy = dyn_cast($1.type->get()); + const ArrayType *ATy = dyn_cast($1->get()); if (ATy == 0) GEN_ERROR("Cannot make array constant with type: '" + - ($1.type->get())->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); int NumElements = ATy->getNumElements(); const Type *ETy = ATy->getElementType(); @@ -1501,16 +1416,15 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr GEN_ERROR("Cannot build string arrays of non byte sized elements!"); } free($3); - $$.cnst = ConstantArray::get(ATy, Vals); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantArray::get(ATy, Vals); + delete $1; CHECK_FOR_ERROR } | Types '<' ConstVector '>' { // Nonempty unsized arr - const PackedType *PTy = dyn_cast($1.type->get()); + const PackedType *PTy = dyn_cast($1->get()); if (PTy == 0) GEN_ERROR("Cannot make packed constant with type: '" + - $1.type->get()->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); const Type *ETy = PTy->getElementType(); int NumElements = PTy->getNumElements(); @@ -1521,79 +1435,68 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr itostr(NumElements) + "!"); // Verify all elements are correct type! - std::vector elems; for (unsigned i = 0; i < $3->size(); i++) { - if (ETy != (*$3)[i].cnst->getType()) { + if (ETy != (*$3)[i]->getType()) GEN_ERROR("Element #" + utostr(i) + " is not of type '" + ETy->getDescription() +"' as required!\nIt is of type '"+ - (*$3)[i].cnst->getType()->getDescription() + "'."); - } else - elems.push_back((*$3)[i].cnst); + (*$3)[i]->getType()->getDescription() + "'."); } - $$.cnst = ConstantPacked::get(PTy, elems); - $$.signedness = isSignless; - delete $1.type; delete $3; + $$ = ConstantPacked::get(PTy, *$3); + delete $1; delete $3; CHECK_FOR_ERROR } | Types '{' ConstVector '}' { - const StructType *STy = dyn_cast($1.type->get()); + const StructType *STy = dyn_cast($1->get()); if (STy == 0) GEN_ERROR("Cannot make struct constant with type: '" + - $1.type->get()->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); if ($3->size() != STy->getNumContainedTypes()) GEN_ERROR("Illegal number of initializers for structure type!"); // Check to ensure that constants are compatible with the type initializer! - std::vector elems; for (unsigned i = 0, e = $3->size(); i != e; ++i) - if ((*$3)[i].cnst->getType() != STy->getElementType(i)) { + if ((*$3)[i]->getType() != STy->getElementType(i)) GEN_ERROR("Expected type '" + STy->getElementType(i)->getDescription() + "' for element #" + utostr(i) + " of structure initializer!"); - } else - elems.push_back((*$3)[i].cnst); - $$.cnst = ConstantStruct::get(STy, elems); - $$.signedness = isSignless; - delete $1.type; delete $3; + $$ = ConstantStruct::get(STy, *$3); + delete $1; delete $3; CHECK_FOR_ERROR } | Types '{' '}' { - const StructType *STy = dyn_cast($1.type->get()); + const StructType *STy = dyn_cast($1->get()); if (STy == 0) GEN_ERROR("Cannot make struct constant with type: '" + - $1.type->get()->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); if (STy->getNumContainedTypes() != 0) GEN_ERROR("Illegal number of initializers for structure type!"); - $$.cnst = ConstantStruct::get(STy, std::vector()); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantStruct::get(STy, std::vector()); + delete $1; CHECK_FOR_ERROR } | Types NULL_TOK { - const PointerType *PTy = dyn_cast($1.type->get()); + const PointerType *PTy = dyn_cast($1->get()); if (PTy == 0) GEN_ERROR("Cannot make null pointer constant with type: '" + - $1.type->get()->getDescription() + "'!"); + (*$1)->getDescription() + "'!"); - $$.cnst = ConstantPointerNull::get(PTy); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantPointerNull::get(PTy); + delete $1; CHECK_FOR_ERROR } | Types UNDEF { - $$.cnst = UndefValue::get($1.type->get()); - $$.signedness = isSignless; - delete $1.type; + $$ = UndefValue::get($1->get()); + delete $1; CHECK_FOR_ERROR } | Types SymbolicValueRef { - const PointerType *Ty = dyn_cast($1.type->get()); + const PointerType *Ty = dyn_cast($1->get()); if (Ty == 0) GEN_ERROR("Global const reference must be a pointer type!"); @@ -1649,132 +1552,116 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr } } - $$.cnst = cast(V); - $$.signedness = $1.signedness; - delete $1.type; // Free the type handle + $$ = cast(V); + delete $1; // Free the type handle CHECK_FOR_ERROR } | Types ConstExpr { - if ($1.type->get() != $2.cnst->getType()) + if ($1->get() != $2->getType()) GEN_ERROR("Mismatched types for constant expression!"); $$ = $2; - delete $1.type; + delete $1; CHECK_FOR_ERROR } | Types ZEROINITIALIZER { - const Type *Ty = $1.type->get(); + const Type *Ty = $1->get(); if (isa(Ty) || Ty == Type::LabelTy || isa(Ty)) GEN_ERROR("Cannot create a null initialized value of this type!"); - $$.cnst = Constant::getNullValue(Ty); - $$.signedness = isSignless; - delete $1.type; + $$ = Constant::getNullValue(Ty); + delete $1; CHECK_FOR_ERROR - }; - -ConstVal : SIntType EINT64VAL { // integral constants - if (!ConstantInt::isValueValidForType($1.type->get(), $2)) + } + | SIntType EINT64VAL { // integral constants + if (!ConstantInt::isValueValidForType($1, $2)) GEN_ERROR("Constant value doesn't fit in type!"); - $$.cnst = ConstantInt::get($1.type->get(), $2); - $$.signedness = $1.signedness; + $$ = ConstantInt::get($1, $2); CHECK_FOR_ERROR } | UIntType EUINT64VAL { // integral constants - if (!ConstantInt::isValueValidForType($1.type->get(), $2)) + if (!ConstantInt::isValueValidForType($1, $2)) GEN_ERROR("Constant value doesn't fit in type!"); - $$.cnst = ConstantInt::get($1.type->get(), $2); - $$.signedness = $1.signedness; + $$ = ConstantInt::get($1, $2); CHECK_FOR_ERROR } | BOOL TRUETOK { // Boolean constants - $$.cnst = ConstantBool::getTrue(); - $$.signedness = isSignless; + $$ = ConstantBool::getTrue(); CHECK_FOR_ERROR } | BOOL FALSETOK { // Boolean constants - $$.cnst = ConstantBool::getFalse(); - $$.signedness = isSignless; + $$ = ConstantBool::getFalse(); CHECK_FOR_ERROR } | FPType FPVAL { // Float & Double constants - if (!ConstantFP::isValueValidForType($1.type->get(), $2)) + if (!ConstantFP::isValueValidForType($1, $2)) GEN_ERROR("Floating point constant invalid for type!!"); - $$.cnst = ConstantFP::get($1.type->get(), $2); - $$.signedness = isSignless; + $$ = ConstantFP::get($1, $2); CHECK_FOR_ERROR }; ConstExpr: CastOps '(' ConstVal TO Types ')' { - Constant *Val = $3.cnst; - const Type *Ty = $5.type->get(); + Constant *Val = $3; + const Type *Ty = $5->get(); if (!Val->getType()->isFirstClassType()) GEN_ERROR("cast constant expression from a non-primitive type: '" + Val->getType()->getDescription() + "'!"); if (!Ty->isFirstClassType()) GEN_ERROR("cast constant expression to a non-primitive type: '" + Ty->getDescription() + "'!"); - if ($1.obsolete) { - if (Ty == Type::BoolTy) { - // The previous definition of cast to bool was a compare against zero. - // We have to retain that semantic so we do it here. - $$.cnst = ConstantExpr::get(Instruction::SetNE, Val, - Constant::getNullValue(Val->getType())); - } else if (Val->getType()->isFloatingPoint() && isa(Ty)) { - Constant *CE = ConstantExpr::getFPToUI(Val, Type::ULongTy); - $$.cnst = ConstantExpr::getIntToPtr(CE, Ty); - } else { - $$.cnst = ConstantExpr::getCast(Val, Ty); - } - } else { - $$.cnst = ConstantExpr::getCast($1.opcode, $3.cnst, $5.type->get()); - } - delete $5.type; + $$ = ConstantExpr::getCast($1, $3, $5->get()); + delete $5; } | GETELEMENTPTR '(' ConstVal IndexList ')' { - if (!isa($3.cnst->getType())) + if (!isa($3->getType())) GEN_ERROR("GetElementPtr requires a pointer operand!"); - std::vector IdxVec; - for (unsigned i = 0, e = $4->size(); i < e; ++i) - if (Constant *C = dyn_cast((*$4)[i].val)) + // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct + // indices to uint struct indices for compatibility. + generic_gep_type_iterator::iterator> + GTI = gep_type_begin($3->getType(), $4->begin(), $4->end()), + GTE = gep_type_end($3->getType(), $4->begin(), $4->end()); + for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI) + if (isa(*GTI)) // Only change struct indices + if (ConstantInt *CUI = dyn_cast((*$4)[i])) + if (CUI->getType() == Type::UByteTy) + (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); + + const Type *IdxTy = + GetElementPtrInst::getIndexedType($3->getType(), *$4, true); + if (!IdxTy) + GEN_ERROR("Index list invalid for constant getelementptr!"); + + std::vector IdxVec; + for (unsigned i = 0, e = $4->size(); i != e; ++i) + if (Constant *C = dyn_cast((*$4)[i])) IdxVec.push_back(C); else GEN_ERROR("Indices to constant getelementptr must be constants!"); - const Type *IdxTy = - GetElementPtrInst::getIndexedType($3.cnst->getType(), IdxVec, true); - if (!IdxTy) - GEN_ERROR("Index list invalid for constant getelementptr!"); - delete $4; - $$.cnst = ConstantExpr::getGetElementPtr($3.cnst, IdxVec); - $$.signedness = isSignless; + $$ = ConstantExpr::getGetElementPtr($3, IdxVec); CHECK_FOR_ERROR } | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' { - if ($3.cnst->getType() != Type::BoolTy) + if ($3->getType() != Type::BoolTy) GEN_ERROR("Select condition must be of boolean type!"); - if ($5.cnst->getType() != $7.cnst->getType()) + if ($5->getType() != $7->getType()) GEN_ERROR("Select operand types must match!"); - $$.cnst = ConstantExpr::getSelect($3.cnst, $5.cnst, $7.cnst); - $$.signedness = isSignless; + $$ = ConstantExpr::getSelect($3, $5, $7); CHECK_FOR_ERROR } | ArithmeticOps '(' ConstVal ',' ConstVal ')' { - if ($3.cnst->getType() != $5.cnst->getType()) + if ($3->getType() != $5->getType()) GEN_ERROR("Binary operator types must match!"); - // First, make sure we're dealing with the right opcode by upgrading from - // obsolete versions. - sanitizeOpcode($1, $3.cnst->getType()); CHECK_FOR_ERROR; // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs. // To retain backward compatibility with these early compilers, we emit a // cast to the appropriate integer type automatically if we are in the // broken case. See PR424 for more information. - if (!isa($3.cnst->getType())) { - $$.cnst = ConstantExpr::get($1.opcode, $3.cnst, $5.cnst); + if (!isa($3->getType())) { + $$ = ConstantExpr::get($1, $3, $5); } else { const Type *IntPtrTy = 0; switch (CurModule.CurrentModule->getPointerSize()) { @@ -1782,64 +1669,64 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' { case Module::Pointer64: IntPtrTy = Type::LongTy; break; default: GEN_ERROR("invalid pointer binary constant expr!"); } - $$.cnst = ConstantExpr::get($1.opcode, - ConstantExpr::getCast($3.cnst, IntPtrTy), - ConstantExpr::getCast($5.cnst, IntPtrTy)); - $$.cnst = ConstantExpr::getCast($$.cnst, $3.cnst->getType()); + $$ = ConstantExpr::get($1, ConstantExpr::getCast($3, IntPtrTy), + ConstantExpr::getCast($5, IntPtrTy)); + $$ = ConstantExpr::getCast($$, $3->getType()); } - $$.signedness = $3.signedness; CHECK_FOR_ERROR } | LogicalOps '(' ConstVal ',' ConstVal ')' { - if ($3.cnst->getType() != $5.cnst->getType()) + if ($3->getType() != $5->getType()) GEN_ERROR("Logical operator types must match!"); - if (!$3.cnst->getType()->isIntegral()) { - if (!isa($3.cnst->getType()) || - !cast($3.cnst->getType())->getElementType()->isIntegral()) + if (!$3->getType()->isIntegral()) { + if (!isa($3->getType()) || + !cast($3->getType())->getElementType()->isIntegral()) GEN_ERROR("Logical operator requires integral operands!"); } - $$.cnst = ConstantExpr::get($1.opcode, $3.cnst, $5.cnst); - $$.signedness = $3.signedness; + $$ = ConstantExpr::get($1, $3, $5); CHECK_FOR_ERROR } | SetCondOps '(' ConstVal ',' ConstVal ')' { - if ($3.cnst->getType() != $5.cnst->getType()) + if ($3->getType() != $5->getType()) GEN_ERROR("setcc operand types must match!"); - $$.cnst = ConstantExpr::get($1.opcode, $3.cnst, $5.cnst); - $$.signedness = isSignless; + $$ = ConstantExpr::get($1, $3, $5); CHECK_FOR_ERROR } + | ICMP '(' IPredicates ',' ConstVal ',' ConstVal ')' { + if ($5->getType() != $7->getType()) + GEN_ERROR("icmp operand types must match!"); + $$ = ConstantExpr::getICmp($3, $5, $7); + } + | FCMP '(' FPredicates ',' ConstVal ',' ConstVal ')' { + if ($5->getType() != $7->getType()) + GEN_ERROR("fcmp operand types must match!"); + $$ = ConstantExpr::getFCmp($3, $5, $7); + } | ShiftOps '(' ConstVal ',' ConstVal ')' { - if ($5.cnst->getType() != Type::UByteTy) + if ($5->getType() != Type::UByteTy) GEN_ERROR("Shift count for shift constant must be unsigned byte!"); - if (!$3.cnst->getType()->isInteger()) + if (!$3->getType()->isInteger()) GEN_ERROR("Shift constant expression requires integer operand!"); - // Handle opcode upgrade situations - sanitizeOpcode($1, $3.cnst->getType()); CHECK_FOR_ERROR; - $$.cnst = ConstantExpr::get($1.opcode, $3.cnst, $5.cnst); - $$.signedness = $3.signedness; + $$ = ConstantExpr::get($1, $3, $5); CHECK_FOR_ERROR } | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' { - if (!ExtractElementInst::isValidOperands($3.cnst, $5.cnst)) + if (!ExtractElementInst::isValidOperands($3, $5)) GEN_ERROR("Invalid extractelement operands!"); - $$.cnst = ConstantExpr::getExtractElement($3.cnst, $5.cnst); - $$.signedness = $3.signedness; + $$ = ConstantExpr::getExtractElement($3, $5); CHECK_FOR_ERROR } | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' { - if (!InsertElementInst::isValidOperands($3.cnst, $5.cnst, $7.cnst)) + if (!InsertElementInst::isValidOperands($3, $5, $7)) GEN_ERROR("Invalid insertelement operands!"); - $$.cnst = ConstantExpr::getInsertElement($3.cnst, $5.cnst, $7.cnst); - $$.signedness = isSignless; + $$ = ConstantExpr::getInsertElement($3, $5, $7); CHECK_FOR_ERROR } | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' { - if (!ShuffleVectorInst::isValidOperands($3.cnst, $5.cnst, $7.cnst)) + if (!ShuffleVectorInst::isValidOperands($3, $5, $7)) GEN_ERROR("Invalid shufflevector operands!"); - $$.cnst = ConstantExpr::getShuffleVector($3.cnst, $5.cnst, $7.cnst); - $$.signedness = isSignless; + $$ = ConstantExpr::getShuffleVector($3, $5, $7); CHECK_FOR_ERROR }; @@ -1850,7 +1737,7 @@ ConstVector : ConstVector ',' ConstVal { CHECK_FOR_ERROR } | ConstVal { - $$ = new std::vector(); + $$ = new std::vector(); $$->push_back($1); CHECK_FOR_ERROR }; @@ -1917,16 +1804,16 @@ ConstPool : ConstPool OptAssign TYPE TypesV { // If types are not resolved eagerly, then the two types will not be // determined to be the same type! // - ResolveTypeTo($2, $4.type->get()); + ResolveTypeTo($2, *$4); - if (!setTypeName($4.type->get(), $2) && !$2) { + if (!setTypeName(*$4, $2) && !$2) { CHECK_FOR_ERROR // If this is a named type that is not a redefinition, add it to the slot // table. - CurModule.Types.push_back(*($4.type)); - } else { - delete $4.type; + CurModule.Types.push_back(*$4); } + + delete $4; CHECK_FOR_ERROR } | ConstPool FunctionProto { // Function prototypes can be in const pool @@ -1936,37 +1823,34 @@ ConstPool : ConstPool OptAssign TYPE TypesV { CHECK_FOR_ERROR } | ConstPool OptAssign OptLinkage GlobalType ConstVal { - if ($5.cnst == 0) + if ($5 == 0) GEN_ERROR("Global value initializer is not a constant!"); - CurGV = ParseGlobalVariable($2, $3, $4, $5.cnst->getType(), $5.cnst); + CurGV = ParseGlobalVariable($2, $3, $4, $5->getType(), $5); CHECK_FOR_ERROR } GlobalVarAttributes { CurGV = 0; } | ConstPool OptAssign EXTERNAL GlobalType Types { - CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, - $5.type->get(), 0); + CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0); CHECK_FOR_ERROR - delete $5.type; + delete $5; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR } | ConstPool OptAssign DLLIMPORT GlobalType Types { - CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, - $5.type->get(), 0); + CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, *$5, 0); CHECK_FOR_ERROR - delete $5.type; + delete $5; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR } | ConstPool OptAssign EXTERN_WEAK GlobalType Types { CurGV = - ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, - $5.type->get(), 0); + ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, *$5, 0); CHECK_FOR_ERROR - delete $5.type; + delete $5; } GlobalVarAttributes { CurGV = 0; CHECK_FOR_ERROR @@ -2044,9 +1928,9 @@ Name : VAR_ID | STRINGCONSTANT; OptName : Name | /*empty*/ { $$ = 0; }; ArgVal : Types OptName { - if ($1.type->get() == Type::VoidTy) + if (*$1 == Type::VoidTy) GEN_ERROR("void typed arguments are invalid!"); - $$ = new std::pair($1, $2); + $$ = new std::pair($1, $2); CHECK_FOR_ERROR }; @@ -2057,7 +1941,7 @@ ArgListH : ArgListH ',' ArgVal { CHECK_FOR_ERROR } | ArgVal { - $$ = new std::vector >(); + $$ = new std::vector >(); $$->push_back(*$1); delete $1; CHECK_FOR_ERROR @@ -2069,18 +1953,13 @@ ArgList : ArgListH { } | ArgListH ',' DOTDOTDOT { $$ = $1; - TypeInfo TI; - TI.type = new PATypeHolder(Type::VoidTy); - TI.signedness = isSignless; - $$->push_back(std::pair(TI,(char*)0)); + $$->push_back(std::pair(new PATypeHolder(Type::VoidTy), 0)); CHECK_FOR_ERROR } | DOTDOTDOT { - $$ = new std::vector >(); - TypeInfo TI; - TI.type = new PATypeHolder(Type::VoidTy); - TI.signedness = isSignless; - $$->push_back(std::make_pair(TI, (char*)0)); + $$ = new std::vector >(); + $$->push_back(std::make_pair(new PATypeHolder(Type::VoidTy), (char*)0)); CHECK_FOR_ERROR } | /* empty */ { @@ -2094,23 +1973,22 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' std::string FunctionName($3); free($3); // Free strdup'd memory! - if (!($2.type->get())->isFirstClassType() && $2.type->get() != Type::VoidTy) + if (!(*$2)->isFirstClassType() && *$2 != Type::VoidTy) GEN_ERROR("LLVM functions cannot return aggregate types!"); std::vector ParamTypeList; if ($5) { // If there are arguments... - for (std::vector >::iterator I = $5->begin(); + for (std::vector >::iterator I = $5->begin(); I != $5->end(); ++I) - ParamTypeList.push_back(I->first.type->get()); + ParamTypeList.push_back(I->first->get()); } bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy; if (isVarArg) ParamTypeList.pop_back(); - const FunctionType *FT = FunctionType::get($2.type->get(), ParamTypeList, - isVarArg); + const FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg); const PointerType *PFT = PointerType::get(FT); - delete $2.type; + delete $2; ValID ID; if (!FunctionName.empty()) { @@ -2164,19 +2042,21 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' // Add all of the arguments we parsed to the function... if ($5) { // Is null if empty... if (isVarArg) { // Nuke the last entry - assert($5->back().first.type->get() == Type::VoidTy && - $5->back().second == 0 && "Not a varargs marker!"); - delete $5->back().first.type; + assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&& + "Not a varargs marker!"); + delete $5->back().first; $5->pop_back(); // Delete the last entry } Function::arg_iterator ArgIt = Fn->arg_begin(); - for (std::vector >::iterator I = $5->begin(); + for (std::vector >::iterator I = $5->begin(); I != $5->end(); ++I, ++ArgIt) { - delete I->first.type; // Delete the typeholder... + delete I->first; // Delete the typeholder... + setValueName(ArgIt, I->second); // Insert arg into symtab... CHECK_FOR_ERROR InsertValue(ArgIt); } + delete $5; // We're now done with the argument list } CHECK_FOR_ERROR @@ -2255,30 +2135,32 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant CHECK_FOR_ERROR } | '<' ConstVector '>' { // Nonempty unsized packed vector - const Type *ETy = (*$2)[0].cnst->getType(); + const Type *ETy = (*$2)[0]->getType(); int NumElements = $2->size(); PackedType* pt = PackedType::get(ETy, NumElements); PATypeHolder* PTy = new PATypeHolder( - HandleUpRefs(PackedType::get( ETy, NumElements))); + HandleUpRefs( + PackedType::get( + ETy, + NumElements) + ) + ); // Verify all elements are correct type! - std::vector elems; for (unsigned i = 0; i < $2->size(); i++) { - if (ETy != (*$2)[i].cnst->getType()) { + if (ETy != (*$2)[i]->getType()) GEN_ERROR("Element #" + utostr(i) + " is not of type '" + ETy->getDescription() +"' as required!\nIt is of type '" + - (*$2)[i].cnst->getType()->getDescription() + "'."); - } else - elems.push_back((*$2)[i].cnst); + (*$2)[i]->getType()->getDescription() + "'."); } - $$ = ValID::create(ConstantPacked::get(pt, elems)); + $$ = ValID::create(ConstantPacked::get(pt, *$2)); delete PTy; delete $2; CHECK_FOR_ERROR } | ConstExpr { - $$ = ValID::create($1.cnst); + $$ = ValID::create($1); CHECK_FOR_ERROR } | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT { @@ -2312,10 +2194,8 @@ ValueRef : SymbolicValueRef | ConstValueRef; // type immediately preceeds the value reference, and allows complex constant // pool references (for things like: 'ret [2 x int] [ int 12, int 42]') ResolvedVal : Types ValueRef { - $$.val = getVal($1.type->get(), $2); - delete $1.type; + $$ = getVal(*$1, $2); delete $1; CHECK_FOR_ERROR - $$.signedness = $1.signedness; }; BasicBlockList : BasicBlockList BasicBlock { @@ -2377,7 +2257,7 @@ InstructionList : InstructionList Inst { }; BBTerminatorInst : RET ResolvedVal { // Return with a result... - $$ = new ReturnInst($2.val); + $$ = new ReturnInst($2); CHECK_FOR_ERROR } | RET VOID { // Return with no result... @@ -2399,7 +2279,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal); } | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { - Value* tmpVal = getVal($2.type->get(), $3); + Value* tmpVal = getVal($2, $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($6); CHECK_FOR_ERROR @@ -2418,7 +2298,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... CHECK_FOR_ERROR } | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' { - Value* tmpVal = getVal($2.type->get(), $3); + Value* tmpVal = getVal($2, $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($6); CHECK_FOR_ERROR @@ -2431,20 +2311,20 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... const PointerType *PFTy; const FunctionType *Ty; - if (!(PFTy = dyn_cast($3.type->get())) || + if (!(PFTy = dyn_cast($3->get())) || !(Ty = dyn_cast(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector ParamTypes; if ($6) { - for (std::vector::iterator I = $6->begin(), E = $6->end(); + for (std::vector::iterator I = $6->begin(), E = $6->end(); I != E; ++I) - ParamTypes.push_back((*I).val->getType()); + ParamTypes.push_back((*I)->getType()); } bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; if (isVarArg) ParamTypes.pop_back(); - Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg); + Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); PFTy = PointerType::get(Ty); } @@ -2464,30 +2344,21 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... // FunctionType::param_iterator I = Ty->param_begin(); FunctionType::param_iterator E = Ty->param_end(); - std::vector::iterator ArgI = $6->begin(), ArgE = $6->end(); + std::vector::iterator ArgI = $6->begin(), ArgE = $6->end(); - std::vector args; - for (; ArgI != ArgE; ++ArgI) - if (I == E) { - if (Ty->isVarArg()) { - args.push_back((*ArgI).val); - } else { - GEN_ERROR("Too many parameters for function of type " + - Ty->getDescription()); - } - } else { - if ((*ArgI).val->getType() != *I) { - GEN_ERROR("Parameter " + (*ArgI).val->getName() + - " is not of type '" + (*I)->getDescription() + "'!"); - } else - args.push_back((*ArgI).val); - ++I; - } - $$ = new InvokeInst(V, Normal, Except, args); + for (; ArgI != ArgE && I != E; ++ArgI, ++I) + if ((*ArgI)->getType() != *I) + GEN_ERROR("Parameter " +(*ArgI)->getName()+ " is not of type '" + + (*I)->getDescription() + "'!"); + + if (I != E || (ArgI != ArgE && !Ty->isVarArg())) + GEN_ERROR("Invalid number of parameters detected!"); + + $$ = new InvokeInst(V, Normal, Except, *$6); } cast($$)->setCallingConv($2); - delete $3.type; + delete $3; delete $6; CHECK_FOR_ERROR } @@ -2504,7 +2375,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { $$ = $1; - Constant *V = cast(getValNonImprovising($2.type->get(), $3)); + Constant *V = cast(getValNonImprovising($2, $3)); CHECK_FOR_ERROR if (V == 0) GEN_ERROR("May only switch on a constant pool value!"); @@ -2515,7 +2386,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { } | IntType ConstValueRef ',' LABEL ValueRef { $$ = new std::vector >(); - Constant *V = cast(getValNonImprovising($1.type->get(), $2)); + Constant *V = cast(getValNonImprovising($1, $2)); CHECK_FOR_ERROR if (V == 0) @@ -2537,12 +2408,12 @@ Inst : OptAssign InstVal { PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes $$ = new std::list >(); - Value* tmpVal = getVal($1.type->get(), $3); + Value* tmpVal = getVal(*$1, $3); CHECK_FOR_ERROR BasicBlock* tmpBB = getBBVal($5); CHECK_FOR_ERROR $$->push_back(std::make_pair(tmpVal, tmpBB)); - delete $1.type; + delete $1; } | PHIList ',' '[' ValueRef ',' ValueRef ']' { $$ = $1; @@ -2555,7 +2426,7 @@ PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes ValueRefList : ResolvedVal { // Used for call statements, and memory insts... - $$ = new std::vector(); + $$ = new std::vector(); $$->push_back($1); } | ValueRefList ',' ResolvedVal { @@ -2565,12 +2436,7 @@ ValueRefList : ResolvedVal { // Used for call statements, and memory insts... }; // ValueRefListE - Just like ValueRefList, except that it may also be empty! -ValueRefListE : ValueRefList { - $$ = $1; - } - | /*empty*/ { - $$ = 0; - }; +ValueRefListE : ValueRefList | /*empty*/ { $$ = 0; }; OptTailCall : TAIL CALL { $$ = true; @@ -2582,123 +2448,125 @@ OptTailCall : TAIL CALL { }; InstVal : ArithmeticOps Types ValueRef ',' ValueRef { - if (!$2.type->get()->isInteger() && !$2.type->get()->isFloatingPoint() && - !isa($2.type->get())) + if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint() && + !isa((*$2).get())) GEN_ERROR( "Arithmetic operator requires integer, FP, or packed operands!"); - if (isa($2.type->get()) && - ($1.opcode == Instruction::URem || - $1.opcode == Instruction::SRem || - $1.opcode == Instruction::FRem)) + if (isa((*$2).get()) && + ($1 == Instruction::URem || + $1 == Instruction::SRem || + $1 == Instruction::FRem)) GEN_ERROR("U/S/FRem not supported on packed types!"); - // Upgrade the opcode from obsolete versions before we do anything with it. - sanitizeOpcode($1,$2.type->get()); - CHECK_FOR_ERROR; - Value* val1 = getVal($2.type->get(), $3); + Value* val1 = getVal(*$2, $3); CHECK_FOR_ERROR - Value* val2 = getVal($2.type->get(), $5); + Value* val2 = getVal(*$2, $5); CHECK_FOR_ERROR - $$ = BinaryOperator::create($1.opcode, val1, val2); + $$ = BinaryOperator::create($1, val1, val2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2.type; + delete $2; } | LogicalOps Types ValueRef ',' ValueRef { - if (!$2.type->get()->isIntegral()) { - if (!isa($2.type->get()) || - !cast($2.type->get())->getElementType()->isIntegral()) + if (!(*$2)->isIntegral()) { + if (!isa($2->get()) || + !cast($2->get())->getElementType()->isIntegral()) GEN_ERROR("Logical operator requires integral operands!"); } - Value* tmpVal1 = getVal($2.type->get(), $3); + Value* tmpVal1 = getVal(*$2, $3); CHECK_FOR_ERROR - Value* tmpVal2 = getVal($2.type->get(), $5); + Value* tmpVal2 = getVal(*$2, $5); CHECK_FOR_ERROR - $$ = BinaryOperator::create($1.opcode, tmpVal1, tmpVal2); + $$ = BinaryOperator::create($1, tmpVal1, tmpVal2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2.type; + delete $2; } | SetCondOps Types ValueRef ',' ValueRef { - if(isa($2.type->get())) { + if(isa((*$2).get())) { GEN_ERROR( "PackedTypes currently not supported in setcc instructions!"); } - Value* tmpVal1 = getVal($2.type->get(), $3); + Value* tmpVal1 = getVal(*$2, $3); CHECK_FOR_ERROR - Value* tmpVal2 = getVal($2.type->get(), $5); + Value* tmpVal2 = getVal(*$2, $5); CHECK_FOR_ERROR - $$ = new SetCondInst($1.opcode, tmpVal1, tmpVal2); + $$ = new SetCondInst($1, tmpVal1, tmpVal2); if ($$ == 0) GEN_ERROR("binary operator returned null!"); - delete $2.type; + delete $2; + } + | ICMP IPredicates Types ValueRef ',' ValueRef { + if (isa((*$3).get())) + GEN_ERROR("Packed types not supported by icmp instruction"); + Value* tmpVal1 = getVal(*$3, $4); + CHECK_FOR_ERROR + Value* tmpVal2 = getVal(*$3, $6); + CHECK_FOR_ERROR + $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2); + if ($$ == 0) + GEN_ERROR("icmp operator returned null!"); + } + | FCMP FPredicates Types ValueRef ',' ValueRef { + if (isa((*$3).get())) + GEN_ERROR("Packed types not supported by fcmp instruction"); + Value* tmpVal1 = getVal(*$3, $4); + CHECK_FOR_ERROR + Value* tmpVal2 = getVal(*$3, $6); + CHECK_FOR_ERROR + $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2); + if ($$ == 0) + GEN_ERROR("fcmp operator returned null!"); } | NOT ResolvedVal { llvm_cerr << "WARNING: Use of eliminated 'not' instruction:" << " Replacing with 'xor'.\n"; - Value *Ones = ConstantIntegral::getAllOnesValue($2.val->getType()); + Value *Ones = ConstantIntegral::getAllOnesValue($2->getType()); if (Ones == 0) GEN_ERROR("Expected integral type for not instruction!"); - $$ = BinaryOperator::create(Instruction::Xor, $2.val, Ones); + $$ = BinaryOperator::create(Instruction::Xor, $2, Ones); if ($$ == 0) GEN_ERROR("Could not create a xor instruction!"); CHECK_FOR_ERROR } | ShiftOps ResolvedVal ',' ResolvedVal { - if ($4.val->getType() != Type::UByteTy) + if ($4->getType() != Type::UByteTy) GEN_ERROR("Shift amount must be ubyte!"); - if (!$2.val->getType()->isInteger()) + if (!$2->getType()->isInteger()) GEN_ERROR("Shift constant expression requires integer operand!"); - // Handle opcode upgrade situations - sanitizeOpcode($1, $2.val->getType()); CHECK_FOR_ERROR; - $$ = new ShiftInst($1.opcode, $2.val, $4.val); + $$ = new ShiftInst($1, $2, $4); CHECK_FOR_ERROR } | CastOps ResolvedVal TO Types { - Value* Val = $2.val; - const Type* Ty = $4.type->get(); + Value* Val = $2; + const Type* Ty = $4->get(); if (!Val->getType()->isFirstClassType()) GEN_ERROR("cast from a non-primitive type: '" + Val->getType()->getDescription() + "'!"); if (!Ty->isFirstClassType()) GEN_ERROR("cast to a non-primitive type: '" + Ty->getDescription() +"'!"); - - if ($1.obsolete) { - if (Ty == Type::BoolTy) { - // The previous definition of cast to bool was a compare against zero. - // We have to retain that semantic so we do it here. - $$ = new SetCondInst(Instruction::SetNE, $2.val, - Constant::getNullValue($2.val->getType())); - } else if (Val->getType()->isFloatingPoint() && isa(Ty)) { - CastInst *CI = new FPToUIInst(Val, Type::ULongTy); - $$ = new IntToPtrInst(CI, Ty); - } else { - $$ = CastInst::createInferredCast(Val, Ty); - } - } else { - $$ = CastInst::create($1.opcode, $2.val, $4.type->get()); - } - delete $4.type; + $$ = CastInst::create($1, $2, $4->get()); + delete $4; } | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { - if ($2.val->getType() != Type::BoolTy) + if ($2->getType() != Type::BoolTy) GEN_ERROR("select condition must be boolean!"); - if ($4.val->getType() != $6.val->getType()) + if ($4->getType() != $6->getType()) GEN_ERROR("select value types should match!"); - $$ = new SelectInst($2.val, $4.val, $6.val); + $$ = new SelectInst($2, $4, $6); CHECK_FOR_ERROR } | VAARG ResolvedVal ',' Types { NewVarArgs = true; - $$ = new VAArgInst($2.val, $4.type->get()); - delete $4.type; + $$ = new VAArgInst($2, *$4); + delete $4; CHECK_FOR_ERROR } | VAARG_old ResolvedVal ',' Types { ObsoleteVarArgs = true; - const Type* ArgTy = $2.val->getType(); + const Type* ArgTy = $2->getType(); Function* NF = CurModule.CurrentModule-> getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0); @@ -2709,16 +2577,16 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { //b = vaarg foo, t AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix"); CurBB->getInstList().push_back(foo); - CallInst* bar = new CallInst(NF, $2.val); + CallInst* bar = new CallInst(NF, $2); CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(new StoreInst(bar, foo)); - $$ = new VAArgInst(foo, $4.type->get()); - delete $4.type; + $$ = new VAArgInst(foo, *$4); + delete $4; CHECK_FOR_ERROR } | VANEXT_old ResolvedVal ',' Types { ObsoleteVarArgs = true; - const Type* ArgTy = $2.val->getType(); + const Type* ArgTy = $2->getType(); Function* NF = CurModule.CurrentModule-> getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0); @@ -2730,31 +2598,31 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { //b = load foo AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix"); CurBB->getInstList().push_back(foo); - CallInst* bar = new CallInst(NF, $2.val); + CallInst* bar = new CallInst(NF, $2); CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(new StoreInst(bar, foo)); - Instruction* tmp = new VAArgInst(foo, $4.type->get()); + Instruction* tmp = new VAArgInst(foo, *$4); CurBB->getInstList().push_back(tmp); $$ = new LoadInst(foo); - delete $4.type; + delete $4; CHECK_FOR_ERROR } | EXTRACTELEMENT ResolvedVal ',' ResolvedVal { - if (!ExtractElementInst::isValidOperands($2.val, $4.val)) + if (!ExtractElementInst::isValidOperands($2, $4)) GEN_ERROR("Invalid extractelement operands!"); - $$ = new ExtractElementInst($2.val, $4.val); + $$ = new ExtractElementInst($2, $4); CHECK_FOR_ERROR } | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal { - if (!InsertElementInst::isValidOperands($2.val, $4.val, $6.val)) + if (!InsertElementInst::isValidOperands($2, $4, $6)) GEN_ERROR("Invalid insertelement operands!"); - $$ = new InsertElementInst($2.val, $4.val, $6.val); + $$ = new InsertElementInst($2, $4, $6); CHECK_FOR_ERROR } | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal { - if (!ShuffleVectorInst::isValidOperands($2.val, $4.val, $6.val)) + if (!ShuffleVectorInst::isValidOperands($2, $4, $6)) GEN_ERROR("Invalid shufflevector operands!"); - $$ = new ShuffleVectorInst($2.val, $4.val, $6.val); + $$ = new ShuffleVectorInst($2, $4, $6); CHECK_FOR_ERROR } | PHI_TOK PHIList { @@ -2776,24 +2644,23 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { const PointerType *PFTy = 0; const FunctionType *Ty = 0; - if (!(PFTy = dyn_cast($3.type->get())) || + if (!(PFTy = dyn_cast($3->get())) || !(Ty = dyn_cast(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector ParamTypes; if ($6) { - for (std::vector::iterator I = $6->begin(), E = $6->end(); + for (std::vector::iterator I = $6->begin(), E = $6->end(); I != E; ++I) - ParamTypes.push_back((*I).val->getType()); + ParamTypes.push_back((*I)->getType()); } bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; if (isVarArg) ParamTypes.pop_back(); - if (!$3.type->get()->isFirstClassType() && - $3.type->get() != Type::VoidTy) + if (!(*$3)->isFirstClassType() && *$3 != Type::VoidTy) GEN_ERROR("LLVM functions cannot return aggregate types!"); - Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg); + Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); PFTy = PointerType::get(Ty); } @@ -2814,34 +2681,21 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { // FunctionType::param_iterator I = Ty->param_begin(); FunctionType::param_iterator E = Ty->param_end(); - std::vector::iterator ArgI = $6->begin(), ArgE = $6->end(); + std::vector::iterator ArgI = $6->begin(), ArgE = $6->end(); - std::vector args; - for (; ArgI != ArgE ; ++ArgI) - if (I == E) { - if (Ty->isVarArg()) { - args.push_back((*ArgI).val); - } else { - GEN_ERROR("Too many parameters for function of type " + - Ty->getDescription()); - } - } else { - if ((*ArgI).val->getType() != *I) { - GEN_ERROR("Parameter " + (*ArgI).val->getName() + - " is not of type '" + (*I)->getDescription() + "'!"); - } else - args.push_back((*ArgI).val); - ++I; - } + for (; ArgI != ArgE && I != E; ++ArgI, ++I) + if ((*ArgI)->getType() != *I) + GEN_ERROR("Parameter " +(*ArgI)->getName()+ " is not of type '" + + (*I)->getDescription() + "'!"); if (I != E || (ArgI != ArgE && !Ty->isVarArg())) GEN_ERROR("Invalid number of parameters detected!"); - $$ = new CallInst(V, args); + $$ = new CallInst(V, *$6); } cast($$)->setTailCall($1); cast($$)->setCallingConv($2); - delete $3.type; + delete $3; delete $6; CHECK_FOR_ERROR } @@ -2856,7 +2710,7 @@ IndexList : ',' ValueRefList { $$ = $2; CHECK_FOR_ERROR } | /* empty */ { - $$ = new std::vector(); + $$ = new std::vector(); CHECK_FOR_ERROR }; @@ -2872,77 +2726,84 @@ OptVolatile : VOLATILE { MemoryInst : MALLOC Types OptCAlign { - $$ = new MallocInst($2.type->get(), 0, $3); - delete $2.type; + $$ = new MallocInst(*$2, 0, $3); + delete $2; CHECK_FOR_ERROR } | MALLOC Types ',' UINT ValueRef OptCAlign { - Value* tmpVal = getVal($4.type->get(), $5); + Value* tmpVal = getVal($4, $5); CHECK_FOR_ERROR - $$ = new MallocInst($2.type->get(), tmpVal, $6); - delete $2.type; + $$ = new MallocInst(*$2, tmpVal, $6); + delete $2; } | ALLOCA Types OptCAlign { - $$ = new AllocaInst($2.type->get(), 0, $3); - delete $2.type; + $$ = new AllocaInst(*$2, 0, $3); + delete $2; CHECK_FOR_ERROR } | ALLOCA Types ',' UINT ValueRef OptCAlign { - Value* tmpVal = getVal($4.type->get(), $5); + Value* tmpVal = getVal($4, $5); CHECK_FOR_ERROR - $$ = new AllocaInst($2.type->get(), tmpVal, $6); - delete $2.type; + $$ = new AllocaInst(*$2, tmpVal, $6); + delete $2; } | FREE ResolvedVal { - if (!isa($2.val->getType())) + if (!isa($2->getType())) GEN_ERROR("Trying to free nonpointer type " + - $2.val->getType()->getDescription() + "!"); - $$ = new FreeInst($2.val); + $2->getType()->getDescription() + "!"); + $$ = new FreeInst($2); CHECK_FOR_ERROR } | OptVolatile LOAD Types ValueRef { - if (!isa($3.type->get())) + if (!isa($3->get())) GEN_ERROR("Can't load from nonpointer type: " + - $3.type->get()->getDescription()); - if (!cast($3.type->get())->getElementType()->isFirstClassType()) + (*$3)->getDescription()); + if (!cast($3->get())->getElementType()->isFirstClassType()) GEN_ERROR("Can't load from pointer of non-first-class type: " + - $3.type->get()->getDescription()); - Value* tmpVal = getVal($3.type->get(), $4); + (*$3)->getDescription()); + Value* tmpVal = getVal(*$3, $4); CHECK_FOR_ERROR $$ = new LoadInst(tmpVal, "", $1); - delete $3.type; + delete $3; } | OptVolatile STORE ResolvedVal ',' Types ValueRef { - const PointerType *PT = dyn_cast($5.type->get()); + const PointerType *PT = dyn_cast($5->get()); if (!PT) GEN_ERROR("Can't store to a nonpointer type: " + - ($5.type->get())->getDescription()); + (*$5)->getDescription()); const Type *ElTy = PT->getElementType(); - if (ElTy != $3.val->getType()) - GEN_ERROR("Can't store '" + $3.val->getType()->getDescription() + + if (ElTy != $3->getType()) + GEN_ERROR("Can't store '" + $3->getType()->getDescription() + "' into space of type '" + ElTy->getDescription() + "'!"); - Value* tmpVal = getVal($5.type->get(), $6); + Value* tmpVal = getVal(*$5, $6); CHECK_FOR_ERROR - $$ = new StoreInst($3.val, tmpVal, $1); - delete $5.type; + $$ = new StoreInst($3, tmpVal, $1); + delete $5; } | GETELEMENTPTR Types ValueRef IndexList { - if (!isa($2.type->get())) + if (!isa($2->get())) GEN_ERROR("getelementptr insn requires pointer operand!"); - std::vector indices; - for (unsigned i = 0, e = $4->size(); i != e; ++i) - indices.push_back((*$4)[i].val); + // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct + // indices to uint struct indices for compatibility. + generic_gep_type_iterator::iterator> + GTI = gep_type_begin($2->get(), $4->begin(), $4->end()), + GTE = gep_type_end($2->get(), $4->begin(), $4->end()); + for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI) + if (isa(*GTI)) // Only change struct indices + if (ConstantInt *CUI = dyn_cast((*$4)[i])) + if (CUI->getType() == Type::UByteTy) + (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); - if (!GetElementPtrInst::getIndexedType($2.type->get(), indices, true)) + if (!GetElementPtrInst::getIndexedType(*$2, *$4, true)) GEN_ERROR("Invalid getelementptr indices for type '" + - $2.type->get()->getDescription()+ "'!"); - Value* tmpVal = getVal($2.type->get(), $3); + (*$2)->getDescription()+ "'!"); + Value* tmpVal = getVal(*$2, $3); CHECK_FOR_ERROR - $$ = new GetElementPtrInst(tmpVal, indices); - delete $2.type; + $$ = new GetElementPtrInst(tmpVal, *$4); + delete $2; delete $4; };