aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp7
-rw-r--r--lib/VMCore/Type.cpp26
-rw-r--r--lib/VMCore/iCall.cpp10
3 files changed, 27 insertions, 16 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 1719bc532f..cc62e6007d 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -107,7 +107,12 @@ bool AssemblyWriter::visitMethod(const Method *M) {
bool AssemblyWriter::processConstPool(const ConstantPool &CP, bool isMethod) {
// Done printing arguments...
- if (isMethod) Out << ")\n";
+ if (isMethod) {
+ if (CP.getParentV()->castMethodAsserting()->getType()->
+ isMethodType()->isVarArg())
+ Out << ", ..."; // Output varargs portion of signature!
+ Out << ")\n";
+ }
ModuleAnalyzer::processConstPool(CP, isMethod);
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 2adba049bc..9d09e29507 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -143,8 +143,10 @@ const Type *Type::VoidTy = new Type("void" , VoidTyID),
//===----------------------------------------------------------------------===//
MethodType::MethodType(const Type *Result, const vector<const Type*> &Params,
- const string &Name)
- : Type(Name, MethodTyID), ResultType(Result), ParamTys(Params) {
+ bool IsVarArgs, const string &Name)
+ : Type(Name, MethodTyID), ResultType(Result),
+ ParamTys(Params.begin(), Params.end()-IsVarArgs),
+ isVarArgs(IsVarArgs) {
}
ArrayType::ArrayType(const Type *ElType, int NumEl, const string &Name)
@@ -171,20 +173,23 @@ PointerType::PointerType(const Type *E)
const MethodType *MethodType::getMethodType(const Type *ReturnType,
const vector<const Type*> &Params) {
static vector<const MethodType*> ExistingMethodTypesCache;
+
+ bool IsVarArg = Params.size() && (Params[Params.size()-1] == Type::VoidTy);
+
for (unsigned i = 0; i < ExistingMethodTypesCache.size(); ++i) {
const MethodType *T = ExistingMethodTypesCache[i];
- if (T->getReturnType() == ReturnType) {
+ if (T->getReturnType() == ReturnType && T->isVarArg() == IsVarArg) {
const ParamTypes &EParams = T->getParamTypes();
- ParamTypes::const_iterator I = Params.begin();
+ ParamTypes::const_iterator I = Params.begin(), EI = Params.end()-IsVarArg;
ParamTypes::const_iterator J = EParams.begin();
- for (; I != Params.end() && J != EParams.end(); ++I, ++J)
+ for (; I != EI && J != EParams.end(); ++I, ++J)
if (*I != *J) break; // These types aren't equal!
- if (I == Params.end() && J == EParams.end()) {
+ if (I == EI && J == EParams.end()) {
#if TEST_MERGE_TYPES == 2
ostream_iterator<const Type*> out(cerr, ", ");
cerr << "Type: \"";
- copy(Params.begin(), Params.end(), out);
+ copy(Params.begin(), EI, out);
cerr << "\"\nEquals: \"";
copy(EParams.begin(), EParams.end(), out);
cerr << "\"" << endl;
@@ -196,25 +201,26 @@ const MethodType *MethodType::getMethodType(const Type *ReturnType,
#if TEST_MERGE_TYPES == 2
ostream_iterator<const Type*> out(cerr, ", ");
cerr << "Input Types: ";
- copy(Params.begin(), Params.end(), out);
+ copy(Params.begin(), Params.end()-IsVarArg, out);
cerr << endl;
#endif
// Calculate the string name for the new type...
string Name = ReturnType->getName() + " (";
for (ParamTypes::const_iterator I = Params.begin();
- I != Params.end(); ++I) {
+ I != (Params.end()-IsVarArg); ++I) {
if (I != Params.begin())
Name += ", ";
Name += (*I)->getName();
}
+ if (IsVarArg) Name += ", ...";
Name += ")";
#if TEST_MERGE_TYPES
cerr << "Derived new type: " << Name << endl;
#endif
- MethodType *Result = new MethodType(ReturnType, Params, Name);
+ MethodType *Result = new MethodType(ReturnType, Params, IsVarArg, Name);
ExistingMethodTypesCache.push_back(Result);
return Result;
}
diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp
index 67826ff4bc..22e238a2cf 100644
--- a/lib/VMCore/iCall.cpp
+++ b/lib/VMCore/iCall.cpp
@@ -8,7 +8,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Method.h"
-CallInst::CallInst(Method *M, vector<Value*> &params,
+CallInst::CallInst(Method *M, const vector<Value*> &params,
const string &Name)
: Instruction(M->getReturnType(), Instruction::Call, Name) {
@@ -17,14 +17,14 @@ CallInst::CallInst(Method *M, vector<Value*> &params,
const MethodType* MT = M->getMethodType();
const MethodType::ParamTypes &PL = MT->getParamTypes();
- assert(params.size() == PL.size() && "Calling a function with bad signature");
+ assert((params.size() == PL.size()) ||
+ (MT->isVarArg() && params.size() > PL.size()) &&
+ "Calling a function with bad signature");
#ifndef NDEBUG
MethodType::ParamTypes::const_iterator It = PL.begin();
#endif
- for (unsigned i = 0; i < params.size(); i++) {
- assert(*It++ == params[i]->getType() && "Call Operands not correct type!");
+ for (unsigned i = 0; i < params.size(); i++)
Operands.push_back(Use(params[i], this));
- }
}
CallInst::CallInst(const CallInst &CI)