s/Method/Function

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-03-29 03:44:36 +00:00
parent 6056c49ca0
commit 6bfd6a578a
9 changed files with 61 additions and 58 deletions

View File

@ -138,7 +138,7 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast: // Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FunctionType *T) { return true; } static inline bool classof(const FunctionType *T) { return true; }
static inline bool classof(const Type *T) { static inline bool classof(const Type *T) {
return T->getPrimitiveID() == MethodTyID; return T->getPrimitiveID() == FunctionTyID;
} }
static inline bool classof(const Value *V) { static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V)); return isa<Type>(V) && classof(cast<const Type>(V));

View File

@ -47,11 +47,11 @@ HANDLE_PRIM_TYPE(Label , 8)
// Type Name: This is the symbolic name of the type, without the trailing Ty. // Type Name: This is the symbolic name of the type, without the trailing Ty.
// Class Name: This is the subclass that implements the derived type. // Class Name: This is the subclass that implements the derived type.
// //
HANDLE_DERV_TYPE(Method , MethodType) HANDLE_DERV_TYPE(Function, FunctionType)
HANDLE_DERV_TYPE(Array , ArrayType) HANDLE_DERV_TYPE(Array , ArrayType)
HANDLE_DERV_TYPE(Pointer, PointerType) HANDLE_DERV_TYPE(Pointer , PointerType)
HANDLE_DERV_TYPE(Struct , StructType) HANDLE_DERV_TYPE(Struct , StructType)
HANDLE_DERV_TYPE(Opaque , OpaqueType) HANDLE_DERV_TYPE(Opaque , OpaqueType)
// Kill the macros on exit... // Kill the macros on exit...
#undef HANDLE_PRIM_TYPE #undef HANDLE_PRIM_TYPE

View File

@ -30,7 +30,7 @@
#include "Support/GraphTraits.h" #include "Support/GraphTraits.h"
class DerivedType; class DerivedType;
class MethodType; class FunctionType;
class ArrayType; class ArrayType;
class PointerType; class PointerType;
class StructType; class StructType;
@ -58,14 +58,14 @@ public:
// Derived types... see DerivedTypes.h file... // Derived types... see DerivedTypes.h file...
// Make sure FirstDerivedTyID stays up to date!!! // Make sure FirstDerivedTyID stays up to date!!!
MethodTyID , StructTyID, // Methods... Structs... FunctionTyID , StructTyID, // Functions... Structs...
ArrayTyID , PointerTyID, // Array... pointer... ArrayTyID , PointerTyID, // Array... pointer...
OpaqueTyID, // Opaque type instances... OpaqueTyID, // Opaque type instances...
//PackedTyID , // SIMD 'packed' format... TODO //PackedTyID , // SIMD 'packed' format... TODO
//... //...
NumPrimitiveIDs, // Must remain as last defined ID NumPrimitiveIDs, // Must remain as last defined ID
FirstDerivedTyID = MethodTyID, FirstDerivedTyID = FunctionTyID,
}; };
private: private:
@ -151,7 +151,7 @@ public:
// TargetData subsystem to do this. // TargetData subsystem to do this.
// //
bool isSized() const { bool isSized() const {
return ID != TypeTyID && ID != MethodTyID && ID != OpaqueTyID; return ID != TypeTyID && ID != FunctionTyID && ID != OpaqueTyID;
} }
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules... // Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!"); SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external method
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the method signature to the dest module...

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules... // Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!"); SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external method
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the method signature to the dest module...

View File

@ -147,10 +147,10 @@ static string calcTypeName(const Type *Ty, vector<const Type *> &TypeStack,
string Result; string Result;
switch (Ty->getPrimitiveID()) { switch (Ty->getPrimitiveID()) {
case Type::MethodTyID: { case Type::FunctionTyID: {
const MethodType *MTy = cast<const MethodType>(Ty); const FunctionType *MTy = cast<const FunctionType>(Ty);
Result = calcTypeName(MTy->getReturnType(), TypeStack, TypeNames) + " ("; Result = calcTypeName(MTy->getReturnType(), TypeStack, TypeNames) + " (";
for (MethodType::ParamTypes::const_iterator for (FunctionType::ParamTypes::const_iterator
I = MTy->getParamTypes().begin(), I = MTy->getParamTypes().begin(),
E = MTy->getParamTypes().end(); I != E; ++I) { E = MTy->getParamTypes().end(); I != E; ++I) {
if (I != MTy->getParamTypes().begin()) if (I != MTy->getParamTypes().begin())
@ -395,15 +395,15 @@ void AssemblyWriter::printFunction(const Function *M) {
Table.incorporateMethod(M); Table.incorporateMethod(M);
// Loop over the arguments, printing them... // Loop over the arguments, printing them...
const MethodType *MT = cast<const MethodType>(M->getMethodType()); const FunctionType *MT = M->getFunctionType();
if (!M->isExternal()) { if (!M->isExternal()) {
for_each(M->getArgumentList().begin(), M->getArgumentList().end(), for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
bind_obj(this, &AssemblyWriter::printFunctionArgument)); bind_obj(this, &AssemblyWriter::printFunctionArgument));
} else { } else {
// Loop over the arguments, printing them... // Loop over the arguments, printing them...
const MethodType *MT = cast<const MethodType>(M->getMethodType()); const FunctionType *MT = M->getFunctionType();
for (MethodType::ParamTypes::const_iterator I = MT->getParamTypes().begin(), for (FunctionType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
E = MT->getParamTypes().end(); I != E; ++I) { E = MT->getParamTypes().end(); I != E; ++I) {
if (I != MT->getParamTypes().begin()) Out << ", "; if (I != MT->getParamTypes().begin()) Out << ", ";
printType(*I); printType(*I);
@ -538,7 +538,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
Out << " void"; Out << " void";
} else if (isa<CallInst>(I)) { } else if (isa<CallInst>(I)) {
const PointerType *PTy = dyn_cast<PointerType>(Operand->getType()); const PointerType *PTy = dyn_cast<PointerType>(Operand->getType());
const MethodType *MTy = PTy ?dyn_cast<MethodType>(PTy->getElementType()):0; const FunctionType*MTy = PTy ? dyn_cast<FunctionType>(PTy->getElementType()):0;
const Type *RetTy = MTy ? MTy->getReturnType() : 0; const Type *RetTy = MTy ? MTy->getReturnType() : 0;
// If possible, print out the short form of the call instruction, but we can // If possible, print out the short form of the call instruction, but we can
@ -546,7 +546,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
// and if the value returned is not a pointer to a method. // and if the value returned is not a pointer to a method.
// //
if (RetTy && !MTy->isVarArg() && if (RetTy && !MTy->isVarArg() &&
(!isa<PointerType>(RetTy)||!isa<MethodType>(cast<PointerType>(RetTy)))){ (!isa<PointerType>(RetTy)||!isa<FunctionType>(cast<PointerType>(RetTy)))){
Out << " "; printType(RetTy); Out << " "; printType(RetTy);
writeOperand(Operand, false); writeOperand(Operand, false);
} else { } else {

View File

@ -25,11 +25,10 @@
template class ValueHolder<FunctionArgument, Function, Function>; template class ValueHolder<FunctionArgument, Function, Function>;
template class ValueHolder<BasicBlock , Function, Function>; template class ValueHolder<BasicBlock , Function, Function>;
Function::Function(const MethodType *Ty, bool isInternal, Function::Function(const FunctionType *Ty, bool isInternal,
const std::string &name) const std::string &name)
: GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name), : GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name),
SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) { SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
assert(::isa<MethodType>(Ty) && "Function signature must be of method type!");
} }
Function::~Function() { Function::~Function() {
@ -62,12 +61,12 @@ void Function::setParent(Module *parent) {
setParentSymTab(Parent ? Parent->getSymbolTableSure() : 0); setParentSymTab(Parent ? Parent->getSymbolTableSure() : 0);
} }
const MethodType *Function::getMethodType() const { const FunctionType *Function::getFunctionType() const {
return cast<MethodType>(cast<PointerType>(getType())->getElementType()); return cast<FunctionType>(getType()->getElementType());
} }
const Type *Function::getReturnType() const { const Type *Function::getReturnType() const {
return getMethodType()->getReturnType(); return getFunctionType()->getReturnType();
} }
// dropAllReferences() - This function causes all the subinstructions to "let // dropAllReferences() - This function causes all the subinstructions to "let

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules... // Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!"); SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external method
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the method signature to the dest module...

View File

@ -194,8 +194,9 @@ Type *Type::VoidTy = new Type("void" , VoidTyID),
// Derived Type Constructors // Derived Type Constructors
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
MethodType::MethodType(const Type *Result, const vector<const Type*> &Params, FunctionType::FunctionType(const Type *Result,
bool IsVarArgs) : DerivedType(MethodTyID), const vector<const Type*> &Params,
bool IsVarArgs) : DerivedType(FunctionTyID),
ResultType(PATypeHandle<Type>(Result, this)), ResultType(PATypeHandle<Type>(Result, this)),
isVarArgs(IsVarArgs) { isVarArgs(IsVarArgs) {
ParamTys.reserve(Params.size()); ParamTys.reserve(Params.size());
@ -271,11 +272,11 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
TypeStack.push_back(Ty); // Add us to the stack.. TypeStack.push_back(Ty); // Add us to the stack..
switch (Ty->getPrimitiveID()) { switch (Ty->getPrimitiveID()) {
case Type::MethodTyID: { case Type::FunctionTyID: {
const MethodType *MTy = cast<const MethodType>(Ty); const FunctionType *MTy = cast<const FunctionType>(Ty);
Result = getTypeProps(MTy->getReturnType(), TypeStack, Result = getTypeProps(MTy->getReturnType(), TypeStack,
isAbstract, isRecursive)+" ("; isAbstract, isRecursive)+" (";
for (MethodType::ParamTypes::const_iterator for (FunctionType::ParamTypes::const_iterator
I = MTy->getParamTypes().begin(), I = MTy->getParamTypes().begin(),
E = MTy->getParamTypes().end(); I != E; ++I) { E = MTy->getParamTypes().end(); I != E; ++I) {
if (I != MTy->getParamTypes().begin()) if (I != MTy->getParamTypes().begin())
@ -381,8 +382,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
if (ATy->getNumElements() != cast<const ArrayType>(Ty2)->getNumElements()) if (ATy->getNumElements() != cast<const ArrayType>(Ty2)->getNumElements())
return false; return false;
} else if (const MethodType *MTy = dyn_cast<MethodType>(Ty)) { } else if (const FunctionType *MTy = dyn_cast<FunctionType>(Ty)) {
if (MTy->isVarArg() != cast<const MethodType>(Ty2)->isVarArg()) if (MTy->isVarArg() != cast<const FunctionType>(Ty2)->isVarArg())
return false; return false;
} }
@ -522,29 +523,29 @@ protected:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Method Type Factory and Value Class... // Function Type Factory and Value Class...
// //
// MethodValType - Define a class to hold the key that goes into the TypeMap // FunctionValType - Define a class to hold the key that goes into the TypeMap
// //
class MethodValType : public ValTypeBase<MethodValType, MethodType> { class FunctionValType : public ValTypeBase<FunctionValType, FunctionType> {
PATypeHandle<Type> RetTy; PATypeHandle<Type> RetTy;
vector<PATypeHandle<Type> > ArgTypes; vector<PATypeHandle<Type> > ArgTypes;
bool isVarArg; bool isVarArg;
public: public:
MethodValType(const Type *ret, const vector<const Type*> &args, FunctionValType(const Type *ret, const vector<const Type*> &args,
bool IVA, TypeMap<MethodValType, MethodType> &Tab) bool IVA, TypeMap<FunctionValType, FunctionType> &Tab)
: ValTypeBase<MethodValType, MethodType>(Tab), RetTy(ret, this), : ValTypeBase<FunctionValType, FunctionType>(Tab), RetTy(ret, this),
isVarArg(IVA) { isVarArg(IVA) {
for (unsigned i = 0; i < args.size(); ++i) for (unsigned i = 0; i < args.size(); ++i)
ArgTypes.push_back(PATypeHandle<Type>(args[i], this)); ArgTypes.push_back(PATypeHandle<Type>(args[i], this));
} }
// We *MUST* have an explicit copy ctor so that the TypeHandles think that // We *MUST* have an explicit copy ctor so that the TypeHandles think that
// this MethodValType owns them, not the old one! // this FunctionValType owns them, not the old one!
// //
MethodValType(const MethodValType &MVT) FunctionValType(const FunctionValType &MVT)
: ValTypeBase<MethodValType, MethodType>(MVT), RetTy(MVT.RetTy, this), : ValTypeBase<FunctionValType, FunctionType>(MVT), RetTy(MVT.RetTy, this),
isVarArg(MVT.isVarArg) { isVarArg(MVT.isVarArg) {
ArgTypes.reserve(MVT.ArgTypes.size()); ArgTypes.reserve(MVT.ArgTypes.size());
for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i) for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i)
@ -565,7 +566,7 @@ public:
if (ArgTypes[i] == Ty) ArgTypes[i].removeUserFromConcrete(); if (ArgTypes[i] == Ty) ArgTypes[i].removeUserFromConcrete();
} }
inline bool operator<(const MethodValType &MTV) const { inline bool operator<(const FunctionValType &MTV) const {
if (RetTy.get() < MTV.RetTy.get()) return true; if (RetTy.get() < MTV.RetTy.get()) return true;
if (RetTy.get() > MTV.RetTy.get()) return false; if (RetTy.get() > MTV.RetTy.get()) return false;
@ -575,17 +576,17 @@ public:
}; };
// Define the actual map itself now... // Define the actual map itself now...
static TypeMap<MethodValType, MethodType> MethodTypes; static TypeMap<FunctionValType, FunctionType> FunctionTypes;
// MethodType::get - The factory function for the MethodType class... // FunctionType::get - The factory function for the FunctionType class...
MethodType *MethodType::get(const Type *ReturnType, FunctionType *FunctionType::get(const Type *ReturnType,
const vector<const Type*> &Params, const vector<const Type*> &Params,
bool isVarArg) { bool isVarArg) {
MethodValType VT(ReturnType, Params, isVarArg, MethodTypes); FunctionValType VT(ReturnType, Params, isVarArg, FunctionTypes);
MethodType *MT = MethodTypes.get(VT); FunctionType *MT = FunctionTypes.get(VT);
if (MT) return MT; if (MT) return MT;
MethodTypes.add(VT, MT = new MethodType(ReturnType, Params, isVarArg)); FunctionTypes.add(VT, MT = new FunctionType(ReturnType, Params, isVarArg));
#ifdef DEBUG_MERGE_TYPES #ifdef DEBUG_MERGE_TYPES
cerr << "Derived new type: " << MT << endl; cerr << "Derived new type: " << MT << endl;
@ -910,10 +911,10 @@ void DerivedType::typeIsRefined() {
// concrete - this could potentially change us from an abstract type to a // concrete - this could potentially change us from an abstract type to a
// concrete type. // concrete type.
// //
void MethodType::refineAbstractType(const DerivedType *OldType, void FunctionType::refineAbstractType(const DerivedType *OldType,
const Type *NewType) { const Type *NewType) {
#ifdef DEBUG_MERGE_TYPES #ifdef DEBUG_MERGE_TYPES
cerr << "MethodTy::refineAbstractTy(" << (void*)OldType << "[" cerr << "FunctionTy::refineAbstractTy(" << (void*)OldType << "["
<< OldType->getDescription() << "], " << (void*)NewType << " [" << OldType->getDescription() << "], " << (void*)NewType << " ["
<< NewType->getDescription() << "])\n"; << NewType->getDescription() << "])\n";
#endif #endif
@ -931,7 +932,7 @@ void MethodType::refineAbstractType(const DerivedType *OldType,
if (ParamTys[i] == OldType) ParamTys[i] = NewType; if (ParamTys[i] == OldType) ParamTys[i] = NewType;
} }
const MethodType *MT = MethodTypes.containsEquivalent(this); const FunctionType *MT = FunctionTypes.containsEquivalent(this);
if (MT && MT != this) { if (MT && MT != this) {
refineAbstractTypeTo(MT); // Different type altogether... refineAbstractTypeTo(MT); // Different type altogether...
} else { } else {