diff options
Diffstat (limited to 'lib/AsmParser/llvmAsmParser.y.cvs')
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y.cvs | 899 |
1 files changed, 380 insertions, 519 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y.cvs b/lib/AsmParser/llvmAsmParser.y.cvs index 1d1558e..8d0b7a2 100644 --- a/lib/AsmParser/llvmAsmParser.y.cvs +++ b/lib/AsmParser/llvmAsmParser.y.cvs @@ -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<Instruction::BinaryOps> &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<PackedType>(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<Instruction::OtherOps> &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<TypeInfo, char*> *ArgVal; + std::pair<llvm::PATypeHolder*, char*> *ArgVal; llvm::BasicBlock *BasicBlockVal; llvm::TerminatorInst *TermInstVal; llvm::Instruction *InstVal; - ConstInfo ConstVal; - TypeInfo TypeVal; - ValueInfo ValueVal; + llvm::Constant *ConstVal; - std::vector<std::pair<TypeInfo,char*> >*ArgList; - std::vector<ValueInfo> *ValueList; - std::list<TypeInfo> *TypeList; + const llvm::Type *PrimType; + llvm::PATypeHolder *TypeVal; + llvm::Value *ValueVal; + + std::vector<std::pair<llvm::PATypeHolder*,char*> > *ArgList; + std::vector<llvm::Value*> *ValueList; + std::list<llvm::PATypeHolder> *TypeList; // Represent the RHS of PHI node - std::list<std::pair<llvm::Value*, llvm::BasicBlock*> > *PHIList; + std::list<std::pair<llvm::Value*, + llvm::BasicBlock*> > *PHIList; std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable; - std::vector<ConstInfo> *ConstVector; + std::vector<llvm::Constant*> *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 <ModuleVal> Module FunctionList @@ -1113,9 +1048,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { // Built in types... %type <TypeVal> Types TypesV UpRTypes UpRTypesV -%type <TypeVal> SIntType UIntType IntType FPType PrimType // Classifications -%token <TypeVal> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG -%token <TypeVal> FLOAT DOUBLE TYPE LABEL +%type <PrimType> SIntType UIntType IntType FPType PrimType // Classifications +%token <PrimType> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG +%token <PrimType> FLOAT DOUBLE TYPE LABEL %token <StrVal> VAR_ID LABELSTR STRINGCONSTANT %type <StrVal> Name OptName OptAssign @@ -1140,6 +1075,12 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) { %type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories %token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR %token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators +%token <OtherOpVal> ICMP FCMP +%token <IPredicate> EQ NE SLT SGT SLE SGE ULT UGT ULE UGE +%type <IPredicate> IPredicates +%token <FPredicate> ORDEQ ORDNE ORDLT ORDGT ORDLE ORDGE ORD UNO UNOEQ UNONE +%token <FPredicate> UNOLT UNOGT UNOLE UNOGE +%type <FPredicate> FPredicates // Memory Instructions %token <MemOpVal> 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<const Type*> Params; - for (std::list<TypeInfo>::iterator I = $3->begin(), + for (std::list<llvm::PATypeHolder>::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<const Type*> Elements; - for (std::list<TypeInfo>::iterator I = $2->begin(), + for (std::list<llvm::PATypeHolder>::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<const Type*>())); - $$.signedness = isSignless; + $$ = new PATypeHolder(StructType::get(std::vector<const Type*>())); 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<TypeInfo>(); - $$->push_back($1); + $$ = new std::list<PATypeHolder>(); + $$->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<TypeInfo>())->push_back(TI); + ($$ = new std::list<PATypeHolder>())->push_back(Type::VoidTy); CHECK_FOR_ERROR } | /*empty*/ { - $$ = new std::list<TypeInfo>(); + $$ = new std::list<PATypeHolder>(); 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<ArrayType>($1.type->get()); + const ArrayType *ATy = dyn_cast<ArrayType>($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<Constant*> 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<ArrayType>($1.type->get()); + const ArrayType *ATy = dyn_cast<ArrayType>($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<llvm::Constant*>()); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantArray::get(ATy, std::vector<Constant*>()); + delete $1; CHECK_FOR_ERROR } | Types 'c' STRINGCONSTANT { - const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get()); + const ArrayType *ATy = dyn_cast<ArrayType>($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<PackedType>($1.type->get()); + const PackedType *PTy = dyn_cast<PackedType>($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<Constant*> 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<StructType>($1.type->get()); + const StructType *STy = dyn_cast<StructType>($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<Constant*> 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<StructType>($1.type->get()); + const StructType *STy = dyn_cast<StructType>($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<Constant*>()); - $$.signedness = isSignless; - delete $1.type; + $$ = ConstantStruct::get(STy, std::vector<Constant*>()); + delete $1; CHECK_FOR_ERROR } | Types NULL_TOK { - const PointerType *PTy = dyn_cast<PointerType>($1.type->get()); + const PointerType *PTy = dyn_cast<PointerType>($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<PointerType>($1.type->get()); + const PointerType *Ty = dyn_cast<PointerType>($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<GlobalValue>(V); - $$.signedness = $1.signedness; - delete $1.type; // Free the type handle + $$ = cast<GlobalValue>(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<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(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<PointerType>(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<PointerType>($3.cnst->getType())) + if (!isa<PointerType>($3->getType())) GEN_ERROR("GetElementPtr requires a pointer operand!"); - std::vector<llvm::Value*> IdxVec; - for (unsigned i = 0, e = $4->size(); i < e; ++i) - if (Constant *C = dyn_cast<Constant>((*$4)[i].val)) - IdxVec.push_back(C); - else - GEN_ERROR("Indices to constant getelementptr must be constants!"); + // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct + // indices to uint struct indices for compatibility. + generic_gep_type_iterator<std::vector<Value*>::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<StructType>(*GTI)) // Only change struct indices + if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i])) + if (CUI->getType() == Type::UByteTy) + (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); const Type *IdxTy = - GetElementPtrInst::getIndexedType($3.cnst->getType(), IdxVec, true); + GetElementPtrInst::getIndexedType($3->getType(), *$4, true); if (!IdxTy) GEN_ERROR("Index list invalid for constant getelementptr!"); + std::vector<Constant*> IdxVec; + for (unsigned i = 0, e = $4->size(); i != e; ++i) + if (Constant *C = dyn_cast<Constant>((*$4)[i])) + IdxVec.push_back(C); + else + GEN_ERROR("Indices to constant getelementptr must be constants!"); + 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<PointerType>($3.cnst->getType())) { - $$.cnst = ConstantExpr::get($1.opcode, $3.cnst, $5.cnst); + if (!isa<PointerType>($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<PackedType>($3.cnst->getType()) || - !cast<PackedType>($3.cnst->getType())->getElementType()->isIntegral()) + if (!$3->getType()->isIntegral()) { + if (!isa<PackedType>($3->getType()) || + !cast<PackedType>($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<ConstInfo>(); + $$ = new std::vector<Constant*>(); $$->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<TypeInfo, char*>($1, $2); + $$ = new std::pair<PATypeHolder*, char*>($1, $2); CHECK_FOR_ERROR }; @@ -2057,7 +1941,7 @@ ArgListH : ArgListH ',' ArgVal { CHECK_FOR_ERROR } | ArgVal { - $$ = new std::vector<std::pair<TypeInfo,char*> >(); + $$ = new std::vector<std::pair<PATypeHolder*,char*> >(); $$->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<TypeInfo,char*>(TI,(char*)0)); + $$->push_back(std::pair<PATypeHolder*, + char*>(new PATypeHolder(Type::VoidTy), 0)); CHECK_FOR_ERROR } | DOTDOTDOT { - $$ = new std::vector<std::pair<TypeInfo,char*> >(); - TypeInfo TI; - TI.type = new PATypeHolder(Type::VoidTy); - TI.signedness = isSignless; - $$->push_back(std::make_pair(TI, (char*)0)); + $$ = new std::vector<std::pair<PATypeHolder*,char*> >(); + $$->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<const Type*> ParamTypeList; if ($5) { // If there are arguments... - for (std::vector<std::pair<TypeInfo,char*> >::iterator I = $5->begin(); + for (std::vector<std::pair<PATypeHolder*,char*> >::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<std::pair<TypeInfo,char*> >::iterator I = $5->begin(); + for (std::vector<std::pair<PATypeHolder*,char*> >::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<Constant*> 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<PointerType>($3.type->get())) || + if (!(PFTy = dyn_cast<PointerType>($3->get())) || !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector<const Type*> ParamTypes; if ($6) { - for (std::vector<ValueInfo>::iterator I = $6->begin(), E = $6->end(); + for (std::vector<Value*>::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<ValueInfo>::iterator ArgI = $6->begin(), ArgE = $6->end(); - - std::vector<Value*> 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); + std::vector<Value*>::iterator ArgI = $6->begin(), ArgE = $6->end(); + + 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<InvokeInst>($$)->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<Constant>(getValNonImprovising($2.type->get(), $3)); + Constant *V = cast<Constant>(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<std::pair<Constant*, BasicBlock*> >(); - Constant *V = cast<Constant>(getValNonImprovising($1.type->get(), $2)); + Constant *V = cast<Constant>(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<std::pair<Value*, BasicBlock*> >(); - 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<ValueInfo>(); + $$ = new std::vector<Value*>(); $$->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<PackedType>($2.type->get())) + if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint() && + !isa<PackedType>((*$2).get())) GEN_ERROR( "Arithmetic operator requires integer, FP, or packed operands!"); - if (isa<PackedType>($2.type->get()) && - ($1.opcode == Instruction::URem || - $1.opcode == Instruction::SRem || - $1.opcode == Instruction::FRem)) + if (isa<PackedType>((*$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<PackedType>($2.type->get()) || - !cast<PackedType>($2.type->get())->getElementType()->isIntegral()) + if (!(*$2)->isIntegral()) { + if (!isa<PackedType>($2->get()) || + !cast<PackedType>($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<PackedType>($2.type->get())) { + if(isa<PackedType>((*$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<PackedType>((*$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<PackedType>((*$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<PointerType>(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<PointerType>($3.type->get())) || + if (!(PFTy = dyn_cast<PointerType>($3->get())) || !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector<const Type*> ParamTypes; if ($6) { - for (std::vector<ValueInfo>::iterator I = $6->begin(), E = $6->end(); + for (std::vector<Value*>::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<ValueInfo>::iterator ArgI = $6->begin(), ArgE = $6->end(); - - std::vector<Value*> 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; - } + std::vector<Value*>::iterator ArgI = $6->begin(), ArgE = $6->end(); + + 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<CallInst>($$)->setTailCall($1); cast<CallInst>($$)->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<ValueInfo>(); + $$ = new std::vector<Value*>(); 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<PointerType>($2.val->getType())) + if (!isa<PointerType>($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<PointerType>($3.type->get())) + if (!isa<PointerType>($3->get())) GEN_ERROR("Can't load from nonpointer type: " + - $3.type->get()->getDescription()); - if (!cast<PointerType>($3.type->get())->getElementType()->isFirstClassType()) + (*$3)->getDescription()); + if (!cast<PointerType>($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<PointerType>($5.type->get()); + const PointerType *PT = dyn_cast<PointerType>($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<PointerType>($2.type->get())) + if (!isa<PointerType>($2->get())) GEN_ERROR("getelementptr insn requires pointer operand!"); - std::vector<Value*> indices; - for (unsigned i = 0, e = $4->size(); i != e; ++i) - indices.push_back((*$4)[i].val); - - if (!GetElementPtrInst::getIndexedType($2.type->get(), indices, true)) + // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct + // indices to uint struct indices for compatibility. + generic_gep_type_iterator<std::vector<Value*>::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<StructType>(*GTI)) // Only change struct indices + if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i])) + if (CUI->getType() == Type::UByteTy) + (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); + + 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; }; |