aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/Type.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 42c3770913..4bddeca73f 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -460,6 +460,30 @@ FunctionType::FunctionType(const Type *Result,
setAbstract(isAbstract);
}
+FunctionType::FunctionType(const Type *Result,
+ const SmallVectorImpl<const Type *> &Params,
+ bool IsVarArgs)
+ : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) {
+ ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
+ NumContainedTys = Params.size() + 1; // + 1 for result type
+ assert((Result->isFirstClassType() || Result == Type::VoidTy ||
+ Result->getTypeID() == Type::StructTyID ||
+ isa<OpaqueType>(Result)) &&
+ "LLVM functions cannot return aggregates");
+ bool isAbstract = Result->isAbstract();
+ new (&ContainedTys[0]) PATypeHandle(Result, this);
+
+ for (unsigned i = 0; i != Params.size(); ++i) {
+ assert((Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])) &&
+ "Function arguments must be value types!");
+ new (&ContainedTys[i+1]) PATypeHandle(Params[i],this);
+ isAbstract |= Params[i]->isAbstract();
+ }
+
+ // Calculate whether or not this type is abstract
+ setAbstract(isAbstract);
+}
+
StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
: CompositeType(StructTyID) {
ContainedTys = reinterpret_cast<PATypeHandle*>(this + 1);
@@ -1055,6 +1079,12 @@ public:
ArgTypes.push_back(args[i]);
}
+ FunctionValType(const Type *ret, const SmallVectorImpl<const Type*> &args,
+ bool isVA) : RetTy(ret), isVarArg(isVA) {
+ for (unsigned i = 0; i < args.size(); ++i)
+ ArgTypes.push_back(args[i]);
+ }
+
static FunctionValType get(const FunctionType *FT);
static unsigned hashTypeStructure(const FunctionType *FT) {
@@ -1108,6 +1138,27 @@ FunctionType *FunctionType::get(const Type *ReturnType,
return FT;
}
+// FunctionType::get - The factory function for the FunctionType class...
+FunctionType *FunctionType::get(const Type *ReturnType,
+ const SmallVectorImpl<const Type*> &Params,
+ bool isVarArg) {
+ FunctionValType VT(ReturnType, Params, isVarArg);
+ FunctionType *FT = FunctionTypes->get(VT);
+ if (FT) {
+ return FT;
+ }
+
+ FT = (FunctionType*) new char[sizeof(FunctionType) +
+ sizeof(PATypeHandle)*(Params.size()+1)];
+ new (FT) FunctionType(ReturnType, Params, isVarArg);
+ FunctionTypes->add(VT, FT);
+
+#ifdef DEBUG_MERGE_TYPES
+ DOUT << "Derived new type: " << FT << "\n";
+#endif
+ return FT;
+}
+
//===----------------------------------------------------------------------===//
// Array Type Factory...
//