diff options
Diffstat (limited to 'lib/AsmParser/llvmAsmParser.y')
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 899 |
1 files changed, 380 insertions, 519 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 1d1558eb6b..8d0b7a2714 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<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*> >(); |