2001-10-13 15:01:45 +08:00
|
|
|
//===-- iCall.cpp - Implement the call & invoke instructions -----*- C++ -*--=//
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
2001-10-13 15:01:45 +08:00
|
|
|
// This file implements the call and invoke instructions.
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/iOther.h"
|
2001-10-13 15:01:45 +08:00
|
|
|
#include "llvm/iTerminators.h"
|
2001-06-07 04:29:01 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Method.h"
|
|
|
|
|
2001-10-13 15:01:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CallInst Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-07 16:36:50 +08:00
|
|
|
|
2002-01-21 06:54:45 +08:00
|
|
|
CallInst::CallInst(Value *Meth, const std::vector<Value*> ¶ms,
|
|
|
|
const std::string &Name)
|
2001-10-13 15:01:45 +08:00
|
|
|
: Instruction(cast<MethodType>(cast<PointerType>(Meth->getType())
|
2001-12-04 08:03:30 +08:00
|
|
|
->getElementType())->getReturnType(),
|
2001-10-13 15:01:45 +08:00
|
|
|
Instruction::Call, Name) {
|
2001-07-07 16:36:50 +08:00
|
|
|
Operands.reserve(1+params.size());
|
2001-10-13 15:01:45 +08:00
|
|
|
Operands.push_back(Use(Meth, this));
|
|
|
|
|
|
|
|
const MethodType *MTy =
|
2001-12-04 08:03:30 +08:00
|
|
|
cast<MethodType>(cast<PointerType>(Meth->getType())->getElementType());
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-10-13 15:01:45 +08:00
|
|
|
const MethodType::ParamTypes &PL = MTy->getParamTypes();
|
2001-07-26 06:47:55 +08:00
|
|
|
assert((params.size() == PL.size()) ||
|
2001-10-22 05:54:51 +08:00
|
|
|
(MTy->isVarArg() && params.size() >= PL.size()) &&
|
2001-07-26 06:47:55 +08:00
|
|
|
"Calling a function with bad signature");
|
|
|
|
for (unsigned i = 0; i < params.size(); i++)
|
2001-07-07 16:36:50 +08:00
|
|
|
Operands.push_back(Use(params[i], this));
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CallInst::CallInst(const CallInst &CI)
|
2001-07-07 16:36:50 +08:00
|
|
|
: Instruction(CI.getType(), Instruction::Call) {
|
|
|
|
Operands.reserve(CI.Operands.size());
|
|
|
|
for (unsigned i = 0; i < CI.Operands.size(); ++i)
|
|
|
|
Operands.push_back(Use(CI.Operands[i], this));
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2001-10-13 15:01:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InvokeInst Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
InvokeInst::InvokeInst(Value *Meth, BasicBlock *IfNormal, \
|
2002-01-21 06:54:45 +08:00
|
|
|
BasicBlock *IfException,
|
|
|
|
const std::vector<Value*> ¶ms,
|
|
|
|
const std::string &Name)
|
2001-10-13 15:01:45 +08:00
|
|
|
: TerminatorInst(cast<MethodType>(cast<PointerType>(Meth->getType())
|
2001-12-04 08:03:30 +08:00
|
|
|
->getElementType())->getReturnType(),
|
2001-10-13 15:01:45 +08:00
|
|
|
Instruction::Invoke, Name) {
|
|
|
|
Operands.reserve(3+params.size());
|
|
|
|
Operands.push_back(Use(Meth, this));
|
|
|
|
Operands.push_back(Use(IfNormal, this));
|
|
|
|
Operands.push_back(Use(IfException, this));
|
|
|
|
const MethodType *MTy =
|
2001-12-04 08:03:30 +08:00
|
|
|
cast<MethodType>(cast<PointerType>(Meth->getType())->getElementType());
|
2001-10-13 15:01:45 +08:00
|
|
|
|
|
|
|
const MethodType::ParamTypes &PL = MTy->getParamTypes();
|
|
|
|
assert((params.size() == PL.size()) ||
|
|
|
|
(MTy->isVarArg() && params.size() > PL.size()) &&
|
|
|
|
"Calling a function with bad signature");
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < params.size(); i++)
|
|
|
|
Operands.push_back(Use(params[i], this));
|
|
|
|
}
|
|
|
|
|
|
|
|
InvokeInst::InvokeInst(const InvokeInst &CI)
|
|
|
|
: TerminatorInst(CI.getType(), Instruction::Invoke) {
|
|
|
|
Operands.reserve(CI.Operands.size());
|
|
|
|
for (unsigned i = 0; i < CI.Operands.size(); ++i)
|
|
|
|
Operands.push_back(Use(CI.Operands[i], this));
|
|
|
|
}
|
|
|
|
|