From: Chris Lattner Date: Wed, 3 Oct 2001 14:53:21 +0000 (+0000) Subject: * Both Method & GlobalVariable now subclass GlobalValue X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=ef9c23f2812322ae5c5f3140bfbcf92629d7ff47 * Both Method & GlobalVariable now subclass GlobalValue * ConstPoolPointerReference now represents a pointer to a GlobalValue * Methods name references are now explicit pointers to methods * Rename Value::GlobalVal to Value::GlobalVariableVal to avoid confusion git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@703 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h index 020989e5d92..bcda38b90d6 100644 --- a/include/llvm/Assembly/Writer.h +++ b/include/llvm/Assembly/Writer.h @@ -97,7 +97,8 @@ inline ostream &operator<<(ostream &o, const Value *I) { case Value::InstructionVal:WriteToAssembly(cast(I) , o); break; case Value::BasicBlockVal: WriteToAssembly(cast(I) , o); break; case Value::MethodVal: WriteToAssembly(cast(I) , o); break; - case Value::GlobalVal: WriteToAssembly(cast(I), o); break; + case Value::GlobalVariableVal: + WriteToAssembly(cast(I), o); break; case Value::ModuleVal: WriteToAssembly(cast(I) , o); break; default: return o << "getValueType() << ">"; } diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h index a2cd1431b21..68dd0a3acfa 100644 --- a/include/llvm/ConstPoolVals.h +++ b/include/llvm/ConstPoolVals.h @@ -227,26 +227,26 @@ public: // ConstPoolPointerReference - a constant pointer value that is initialized to -// point to a global value, which is a constant. +// point to a global value, which lies at a constant, fixed address. // class ConstPoolPointerReference : public ConstPoolPointer { ConstPoolPointerReference(const ConstPoolPointerReference &); // DNI! protected: - ConstPoolPointerReference(GlobalVariable *GV); + ConstPoolPointerReference(GlobalValue *GV); ~ConstPoolPointerReference() {} public: - static ConstPoolPointerReference *get(GlobalVariable *GV) { + static ConstPoolPointerReference *get(GlobalValue *GV) { // FIXME: These should all be shared! return new ConstPoolPointerReference(GV); } virtual string getStrValue() const; - const GlobalVariable *getValue() const { - return cast(Operands[0].get()); + const GlobalValue *getValue() const { + return cast(Operands[0].get()); } - GlobalVariable *getValue() { - return cast(Operands[0].get()); + GlobalValue *getValue() { + return cast(Operands[0].get()); } }; diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 227ab53cd0d..d7c35b3c040 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -13,6 +13,7 @@ #include "llvm/SymTabValue.h" #include "llvm/BasicBlock.h" +#include "llvm/GlobalValue.h" class Instruction; class BasicBlock; @@ -20,7 +21,7 @@ class MethodArgument; class MethodType; class Module; -class Method : public Value, public SymTabValue { +class Method : public GlobalValue, public SymTabValue { public: typedef ValueHolder ArgumentListType; typedef ValueHolder BasicBlocksType; @@ -49,10 +50,8 @@ public: // Specialize setName to handle symbol table majik... virtual void setName(const string &name, SymbolTable *ST = 0); - const Type *getReturnType() const; - const MethodType *getType() const { - return (const MethodType*)Value::getType(); - } + const Type *getReturnType() const; // Return the return type of method + const MethodType *getMethodType() const; // Return the MethodType for me // Is the body of this method unknown? (the basic block list is empty if so) // this is true for external methods, defined as forward "declare"ations diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h new file mode 100644 index 00000000000..394e2a262a1 --- /dev/null +++ b/include/llvm/GlobalValue.h @@ -0,0 +1,36 @@ +//===-- llvm/GlobalValue.h - Class to represent a global value ---*- C++ -*--=// +// +// This file is a common base class of all globally definable objects. As such, +// it is subclassed by GlobalVariable and by Method. This is used because you +// can do certain things with these global objects that you can't do to anything +// else. For example, use the address of one as a constant. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_GLOBALVALUE_H +#define LLVM_GLOBALVALUE_H + +#include "llvm/User.h" +class PointerType; + +class GlobalValue : public User { + GlobalValue(const GlobalValue &); // do not implement +protected: + GlobalValue(const Type *Ty, ValueTy vty, const string &name = "") + : User(Ty, vty, name) {} +public: + + // getType - Global values are always pointers (FIXME, methods should be ptrs too!) + inline const PointerType *getType() const { + return (const PointerType*)User::getType(); + } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const GlobalValue *T) { return true; } + static inline bool classof(const Value *V) { + return V->getValueType() == Value::MethodVal || + V->getValueType() == Value::GlobalVariableVal; + } +}; + +#endif diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index 3ee7f6d45a2..4256ffee940 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -13,12 +13,12 @@ #ifndef LLVM_GLOBAL_VARIABLE_H #define LLVM_GLOBAL_VARIABLE_H -#include "llvm/User.h" +#include "llvm/GlobalValue.h" class Module; class ConstPoolVal; class PointerType; -class GlobalVariable : public User { +class GlobalVariable : public GlobalValue { Module *Parent; // The module that contains this method friend class ValueHolder; @@ -30,11 +30,6 @@ public: const string &Name = ""); ~GlobalVariable() {} - // getType - Global variables are always pointers - inline const PointerType *getType() const { - return (const PointerType*)User::getType(); - } - // Specialize setName to handle symbol table majik... virtual void setName(const string &name, SymbolTable *ST = 0); @@ -63,7 +58,7 @@ public: // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const GlobalVariable *) { return true; } static inline bool classof(const Value *V) { - return V->getValueType() == Value::GlobalVal; + return V->getValueType() == Value::GlobalVariableVal; } }; diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 5716d29c665..255105f2880 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -22,6 +22,7 @@ class ConstPoolVal; class MethodArgument; class Instruction; class BasicBlock; +class GlobalValue; class Method; class GlobalVariable; class Module; @@ -43,7 +44,7 @@ public: InstructionVal, // This is an instance of Instruction BasicBlockVal, // This is an instance of BasicBlock MethodVal, // This is an instance of Method - GlobalVal, // This is an instance of GlobalVariable + GlobalVariableVal, // This is an instance of GlobalVariable ModuleVal, // This is an instance of Module }; @@ -256,10 +257,16 @@ template <> inline bool isa(Value *Val) { return Val->getValueType() == Value::MethodVal; } template <> inline bool isa(const Value *Val) { - return Val->getValueType() == Value::GlobalVal; + return Val->getValueType() == Value::GlobalVariableVal; } template <> inline bool isa(Value *Val) { - return Val->getValueType() == Value::GlobalVal; + return Val->getValueType() == Value::GlobalVariableVal; +} +template <> inline bool isa(const Value *Val) { + return isa(Val) || isa(Val); +} +template <> inline bool isa(Value *Val) { + return isa(Val) || isa(Val); } template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::ModuleVal; diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index d0e0e2e1952..1351e71cea0 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -150,7 +150,7 @@ public: return cast(Operands[0]); } Method *getCalledMethod() { - return cast(Operands[0]); + return cast(Operands[0]); } // Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index abe2a18b941..e6f4cfa9478 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -224,7 +224,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { case Value::TypeVal: case Value::BasicBlockVal: case Value::MethodVal: case Value::ModuleVal: default: assert(0 && "Unexpected expression type to classify!"); - case Value::GlobalVal: // Global Variable & Method argument: + case Value::GlobalVariableVal: // Global Variable & Method argument: case Value::MethodArgumentVal: // nothing known, return variable itself return Expr; case Value::ConstantVal: // Constant value, just return constant diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index bedb65f4a86..b00a35281fb 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/lib/AsmParser/ParserInternals.h @@ -176,7 +176,12 @@ typedef PlaceholderValue BBPlaceHolder; typedef PlaceholderValue MethPlaceHolder; static inline ValID &getValIDFromPlaceHolder(const Value *Val) { - switch (Val->getType()->getPrimitiveID()) { + const Type *Ty = Val->getType(); + if (isa(Ty) && + isa(cast(Ty)->getValueType())) + Ty = cast(Ty)->getValueType(); + + switch (Ty->getPrimitiveID()) { case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getDef(); case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getDef(); case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getDef(); @@ -185,7 +190,12 @@ static inline ValID &getValIDFromPlaceHolder(const Value *Val) { } static inline int getLineNumFromPlaceHolder(const Value *Val) { - switch (Val->getType()->getPrimitiveID()) { + const Type *Ty = Val->getType(); + if (isa(Ty) && + isa(cast(Ty)->getValueType())) + Ty = cast(Ty)->getValueType(); + + switch (Ty->getPrimitiveID()) { case Type::TypeTyID: return ((TypePlaceHolder*)Val)->getLineNum(); case Type::LabelTyID: return ((BBPlaceHolder*)Val)->getLineNum(); case Type::MethodTyID: return ((MethPlaceHolder*)Val)->getLineNum(); diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 6852df7dc6b..43c69f3a08a 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -295,6 +295,10 @@ static Value *getVal(const Type *Ty, const ValID &D, vector *LateResolver = (CurMeth.CurrentMethod) ? &CurMeth.LateResolveValues : &CurModule.LateResolveValues; + if (const PointerType *PTy = dyn_cast(Ty)) + if (const MethodType *MTy = dyn_cast(PTy->getValueType())) + Ty = MTy; // Convert pointer to method to method type + switch (Ty->getPrimitiveID()) { case Type::LabelTyID: d = new BBPlaceHolder(Ty, D); break; case Type::MethodTyID: d = new MethPlaceHolder(Ty, D); @@ -938,8 +942,7 @@ ConstPool : ConstPool OptAssign CONST ConstVal { if (Initializer == 0) ThrowException("Global value initializer is not a constant!"); - GlobalVariable *GV = new GlobalVariable(PointerType::get(Ty), $3, - Initializer); + GlobalVariable *GV = new GlobalVariable(Ty, $3, Initializer); setValueName(GV, $2); CurModule.CurrentModule->getGlobalList().push_back(GV); @@ -953,7 +956,7 @@ ConstPool : ConstPool OptAssign CONST ConstVal { "' is not a sized type!"); } - GlobalVariable *GV = new GlobalVariable(PointerType::get(Ty), $4); + GlobalVariable *GV = new GlobalVariable(Ty, $4); setValueName(GV, $2); CurModule.CurrentModule->getGlobalList().push_back(GV); @@ -1031,13 +1034,14 @@ MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' { for (list::iterator I = $4->begin(); I != $4->end(); ++I) ParamTypeList.push_back((*I)->getType()); - const MethodType *MT = MethodType::get(*$1, ParamTypeList); + const MethodType *MT = MethodType::get(*$1, ParamTypeList); + const PointerType *PMT = PointerType::get(MT); delete $1; Method *M = 0; if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) { - if (Value *V = ST->lookup(MT, $2)) { // Method already in symtab? - M = cast(V); + if (Value *V = ST->lookup(PMT, $2)) { // Method already in symtab? + M = cast(V); // Yes it is. If this is the case, either we need to be a forward decl, // or it needs to be. @@ -1274,18 +1278,23 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { delete $2; // Free the list... } | CALL TypesV ValueRef '(' ValueRefListE ')' { + const PointerType *PMTy; const MethodType *Ty; - if (!(Ty = dyn_cast($2->get()))) { + if (!(PMTy = dyn_cast($2->get())) || + !(Ty = dyn_cast(PMTy->getValueType()))) { // Pull out the types of all of the arguments... vector ParamTypes; - for (list::iterator I = $5->begin(), E = $5->end(); I != E; ++I) - ParamTypes.push_back((*I)->getType()); - Ty = MethodType::get(*$2, ParamTypes); + if ($5) { + for (list::iterator I = $5->begin(), E = $5->end(); I != E; ++I) + ParamTypes.push_back((*I)->getType()); + } + Ty = MethodType::get($2->get(), ParamTypes); + PMTy = PointerType::get(Ty); } delete $2; - Value *V = getVal(Ty, $3); // Get the method we're calling... + Value *V = getVal(PMTy, $3); // Get the method we're calling... // Create the call node... if (!$5) { // Has no arguments? diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 4c7f7c9ac27..8ccaf309de1 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -158,7 +158,7 @@ bool BytecodeParser::parseTypeConstants(const uchar *&Buf, const uchar *EndBuf, BCR_TRACE(5, "Resulting types:\n"); for (unsigned i = 0; i < NumEntries; i++) { - BCR_TRACE(5, cast(Tab[i+BaseLevel]) << "\n"); + BCR_TRACE(5, cast(Tab[i+BaseLevel]) << "\n"); } return false; } diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index b6eec664913..5697b2620f9 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -197,9 +197,9 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, if (M == 0) return failure(true); vector Params; - const MethodType::ParamTypes &PL = M->getType()->getParamTypes(); + const MethodType::ParamTypes &PL = M->getMethodType()->getParamTypes(); - if (!M->getType()->isVarArg()) { + if (!M->getMethodType()->isVarArg()) { MethodType::ParamTypes::const_iterator It = PL.begin(); switch (Raw.NumOperands) { diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 14e89e2d20d..97428ea4ee9 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -223,7 +223,10 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, Values.clear(); if (MethodSignatureList.empty()) return failure(true); // Unexpected method! - const MethodType *MTy = MethodSignatureList.front().first; + const PointerType *PMTy = MethodSignatureList.front().first; // PtrMeth + const MethodType *MTy = dyn_cast(PMTy->getValueType()); + if (MTy == 0) return failure(true); // Not ptr to method! + unsigned MethSlot = MethodSignatureList.front().second; MethodSignatureList.pop_front(); Method *M = new Method(MTy); @@ -289,13 +292,13 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, delete M; return failure(true); // Unresolvable references! } - Value *MethPHolder = getValue(MTy, MethSlot, false); + Value *MethPHolder = getValue(PMTy, MethSlot, false); assert(MethPHolder && "Something is broken no placeholder found!"); assert(isa(MethPHolder) && "Not a method?"); unsigned type; // Type slot assert(!getTypeSlot(MTy, type) && "How can meth type not exist?"); - getTypeSlot(MTy, type); + getTypeSlot(PMTy, type); C->getMethodList().push_back(M); @@ -330,6 +333,9 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, return failure(true); } + const PointerType *PTy = cast(Ty); + Ty = PTy->getValueType(); + ConstPoolVal *Initializer = 0; if (VarType & 2) { // Does it have an initalizer? // Do not improvise... values must have been stored in the constant pool, @@ -338,8 +344,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, unsigned InitSlot; if (read_vbr(Buf, End, InitSlot)) return failure(true); - Value *V = getValue(cast(Ty)->getValueType(), - InitSlot, false); + Value *V = getValue(Ty, InitSlot, false); if (V == 0) return failure(true); Initializer = cast(V); } @@ -350,7 +355,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, C->getGlobalList().push_back(GV); if (read_vbr(Buf, End, VarType)) return failure(true); - BCR_TRACE(2, "Global Variable of type: " << Ty->getDescription() << endl); + BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription() << endl); } // Read the method signatures for all of the methods that are coming, and @@ -359,10 +364,14 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, if (read_vbr(Buf, End, MethSignature)) return failure(true); while (MethSignature != Type::VoidTyID) { // List is terminated by Void const Type *Ty = getType(MethSignature); - if (!Ty || !isa(Ty)) { - cerr << "Method not meth type! Ty = " << Ty << endl; + if (!Ty || !isa(Ty) || + !isa(cast(Ty)->getValueType())) { + cerr << "Method not ptr to meth type! Ty = " << Ty << endl; return failure(true); } + + // We create methods by passing the underlying MethodType to create... + Ty = cast(Ty)->getValueType(); // When the ModuleGlobalInfo section is read, we load the type of each // method and the 'ModuleValues' slot that it lands in. We then load a @@ -370,19 +379,20 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, // placeholder is replaced. // Insert the placeholder... - Value *Def = new MethPHolder(Ty, 0); - insertValue(Def, ModuleValues); + Value *Val = new MethPHolder(Ty, 0); + insertValue(Val, ModuleValues); // Figure out which entry of its typeslot it went into... unsigned TypeSlot; - if (getTypeSlot(Def->getType(), TypeSlot)) return failure(true); + if (getTypeSlot(Val->getType(), TypeSlot)) return failure(true); unsigned SlotNo = ModuleValues[TypeSlot].size()-1; // Keep track of this information in a linked list that is emptied as // methods are loaded... // - MethodSignatureList.push_back(make_pair(cast(Ty),SlotNo)); + MethodSignatureList.push_back( + make_pair(cast(Val->getType()), SlotNo)); if (read_vbr(Buf, End, MethSignature)) return failure(true); BCR_TRACE(2, "Method of type: " << Ty << endl); } diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h index cf5a43ef3bb..ec486d851e4 100644 --- a/lib/Bytecode/Reader/ReaderInternals.h +++ b/lib/Bytecode/Reader/ReaderInternals.h @@ -72,7 +72,7 @@ private: // All of this data is transient across calls to ParseBytecode // into its slot to reserve it. When the method is loaded, this placeholder // is replaced. // - list > MethodSignatureList; + list > MethodSignatureList; private: bool ParseModule (const uchar * Buf, const uchar *End, Module *&); diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp index 256f7c82889..d8e17e25187 100644 --- a/lib/Bytecode/Writer/InstructionWriter.cpp +++ b/lib/Bytecode/Writer/InstructionWriter.cpp @@ -15,6 +15,7 @@ #include "llvm/BasicBlock.h" #include "llvm/Instruction.h" #include "llvm/DerivedTypes.h" +#include "llvm/iOther.h" #include typedef unsigned char uchar; @@ -214,10 +215,11 @@ void BytecodeWriter::processInstruction(const Instruction *I) { assert(Slots[1] != -1 && "Cast return type unknown?"); if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1]; NumOperands++; - } else if (I->getOpcode() == Instruction::Call && // Handle VarArg calls - cast(I->getOperand(0)->getType())->isVarArg()) { - outputInstrVarArgsCall(I, Table, Type, Out); - return; + } else if (const CallInst *CI = dyn_cast(I)) {// Handle VarArg calls + if (CI->getCalledMethod()->getMethodType()->isVarArg()) { + outputInstrVarArgsCall(I, Table, Type, Out); + return; + } } // Decide which instruction encoding to use. This is determined primarily by diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 8b2db6f73c0..4c2039ded4c 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -45,7 +45,7 @@ static ExFunc lookupMethod(const Method *M) { // Function not found, look it up... start by figuring out what the // composite function name should be. string ExtName = "lle_"; - const MethodType *MT = M->getType(); + const MethodType *MT = M->getMethodType(); for (unsigned i = 0; const Type *Ty = MT->getContainedType(i); ++i) ExtName += getTypeID(Ty); ExtName += "_" + M->getName(); @@ -72,7 +72,7 @@ void Interpreter::callExternalMethod(Method *M, } // TODO: FIXME when types are not const! - GenericValue Result = Fn(const_cast(M->getType()), ArgVals); + GenericValue Result = Fn(const_cast(M->getMethodType()),ArgVals); // Copy the result back into the result variable if we are not returning void. if (M->getReturnType() != Type::VoidTy) { diff --git a/lib/Target/SparcV9/SparcV9RegInfo.cpp b/lib/Target/SparcV9/SparcV9RegInfo.cpp index 0a2570e5a42..fd9c75cb9b6 100644 --- a/lib/Target/SparcV9/SparcV9RegInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegInfo.cpp @@ -696,7 +696,7 @@ MachineInstr * UltraSparcRegInfo::cpValue2RegMI(Value * Val, switch( Val->getValueType() ) { case Value::ConstantVal: - case Value::GlobalVal: + case Value::GlobalVariableVal: MOType = MachineOperand:: MO_UnextendedImmed; // TODO**** correct??? break; diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index d317bd72918..241bfba29b2 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -192,7 +192,7 @@ void AssemblyWriter::processMethod(const Method *M) { // Finish printing arguments... - const MethodType *MT = cast(M->getType()); + const MethodType *MT = cast(M->getMethodType()); if (MT->isVarArg()) { if (MT->getParamTypes().size()) Out << ", "; Out << "..."; // Output varargs portion of signature! @@ -300,6 +300,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) { } else if (I->getOpcode() == Instruction::Ret && !Operand) { Out << " void"; } else if (I->getOpcode() == Instruction::Call) { + // TODO: Should try to print out short form of the Call instruction writeOperand(Operand, true); Out << "("; if (I->getNumOperands() > 1) writeOperand(I->getOperand(1), true); diff --git a/lib/VMCore/ConstPoolVals.cpp b/lib/VMCore/ConstPoolVals.cpp index 0e0da5e16e8..6c054e1ee07 100644 --- a/lib/VMCore/ConstPoolVals.cpp +++ b/lib/VMCore/ConstPoolVals.cpp @@ -106,7 +106,7 @@ ConstPoolStruct::ConstPoolStruct(const StructType *T, ConstPoolPointer::ConstPoolPointer(const PointerType *T) : ConstPoolVal(T) {} -ConstPoolPointerReference::ConstPoolPointerReference(GlobalVariable *GV) +ConstPoolPointerReference::ConstPoolPointerReference(GlobalValue *GV) : ConstPoolPointer(GV->getType()) { Operands.push_back(Use(GV, this)); } diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 9eb8277a272..372d0d28b91 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -26,8 +26,8 @@ template class ValueHolder; template class ValueHolder; Method::Method(const MethodType *Ty, const string &name) - : Value(Ty, Value::MethodVal, name), SymTabValue(this), BasicBlocks(this), - ArgumentList(this, this) { + : GlobalValue(PointerType::get(Ty), Value::MethodVal, name), + SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) { assert(::isa(Ty) && "Method signature must be of method type!"); Parent = 0; } @@ -62,8 +62,12 @@ void Method::setParent(Module *parent) { setParentSymTab(Parent ? Parent->getSymbolTableSure() : 0); } +const MethodType *Method::getMethodType() const { + return cast(cast(getType())->getValueType()); +} + const Type *Method::getReturnType() const { - return ((const MethodType *)getType())->getReturnType(); + return getMethodType()->getReturnType(); } // dropAllReferences() - This function causes all the subinstructions to "let @@ -85,8 +89,8 @@ void Method::dropAllReferences() { GlobalVariable::GlobalVariable(const Type *Ty, bool isConstant, ConstPoolVal *Initializer = 0, const string &Name = "") - : User(Ty, Value::GlobalVal, Name), Parent(0), Constant(isConstant) { - assert(Ty->isPointerType() && "Global Variables must be pointers!"); + : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, Name), + Parent(0), Constant(isConstant) { if (Initializer) Operands.push_back(Use((Value*)Initializer, this)); assert(!isConstant || hasInitializer() && diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp index 13f07d7f578..f739730b67d 100644 --- a/lib/VMCore/iCall.cpp +++ b/lib/VMCore/iCall.cpp @@ -15,9 +15,9 @@ CallInst::CallInst(Method *M, const vector ¶ms, Operands.reserve(1+params.size()); Operands.push_back(Use(M, this)); - const MethodType::ParamTypes &PL = M->getType()->getParamTypes(); + const MethodType::ParamTypes &PL = M->getMethodType()->getParamTypes(); assert((params.size() == PL.size()) || - (M->getType()->isVarArg() && params.size() > PL.size()) && + (M->getMethodType()->isVarArg() && params.size() > PL.size()) && "Calling a function with bad signature"); #ifndef NDEBUG MethodType::ParamTypes::const_iterator It = PL.begin();