2001-10-13 07:01:45 +00:00
|
|
|
//===-- iCall.cpp - Implement the call & invoke instructions -----*- C++ -*--=//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-10-13 07:01:45 +00:00
|
|
|
// This file implements the call and invoke instructions.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/iOther.h"
|
2001-10-13 07:01:45 +00:00
|
|
|
#include "llvm/iTerminators.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-13 07:01:45 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CallInst Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-07 08:36:50 +00:00
|
|
|
|
2002-04-07 20:49:59 +00:00
|
|
|
CallInst::CallInst(Value *Func, const std::vector<Value*> ¶ms,
|
2002-09-10 15:45:53 +00:00
|
|
|
const std::string &Name, Instruction *InsertBefore)
|
2002-04-07 20:49:59 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
2001-12-04 00:03:30 +00:00
|
|
|
->getElementType())->getReturnType(),
|
2002-09-10 15:45:53 +00:00
|
|
|
Instruction::Call, Name, InsertBefore) {
|
2001-07-07 08:36:50 +00:00
|
|
|
Operands.reserve(1+params.size());
|
2002-04-07 20:49:59 +00:00
|
|
|
Operands.push_back(Use(Func, this));
|
2001-10-13 07:01:45 +00:00
|
|
|
|
2002-04-04 22:19:18 +00:00
|
|
|
const FunctionType *MTy =
|
2002-04-07 20:49:59 +00:00
|
|
|
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-04 22:19:18 +00:00
|
|
|
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
|
2003-02-01 03:33:22 +00:00
|
|
|
assert(params.size() == PL.size() ||
|
|
|
|
(MTy->isVarArg() && params.size() > PL.size()) &&
|
2001-07-25 22:47:55 +00:00
|
|
|
"Calling a function with bad signature");
|
|
|
|
for (unsigned i = 0; i < params.size(); i++)
|
2001-07-07 08:36:50 +00:00
|
|
|
Operands.push_back(Use(params[i], this));
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-01 00:39:58 +00:00
|
|
|
CallInst::CallInst(Value *Func, const std::string &Name,
|
2003-02-01 03:33:22 +00:00
|
|
|
Instruction *InsertBefore)
|
2003-02-01 00:39:58 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call, Name, InsertBefore) {
|
|
|
|
Operands.reserve(1);
|
|
|
|
Operands.push_back(Use(Func, this));
|
|
|
|
|
|
|
|
const FunctionType *MTy =
|
|
|
|
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
|
|
|
|
|
|
|
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
|
2003-02-01 03:33:22 +00:00
|
|
|
assert(PL.empty() && "Calling a function with bad signature");
|
2003-02-01 00:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CallInst::CallInst(Value *Func, Value* A, const std::string &Name,
|
|
|
|
Instruction *InsertBefore)
|
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call, Name, InsertBefore) {
|
|
|
|
Operands.reserve(2);
|
|
|
|
Operands.push_back(Use(Func, this));
|
|
|
|
|
|
|
|
const FunctionType *MTy =
|
|
|
|
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
|
|
|
|
|
|
|
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
|
2003-02-01 03:33:22 +00:00
|
|
|
assert(PL.size() == 1 || (MTy->isVarArg() && PL.empty()) &&
|
2003-02-01 00:39:58 +00:00
|
|
|
"Calling a function with bad signature");
|
|
|
|
Operands.push_back(Use(A, this));
|
|
|
|
}
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
CallInst::CallInst(const CallInst &CI)
|
2001-07-07 08:36:50 +00: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-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2001-10-13 07:01:45 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InvokeInst Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-04-09 18:36:52 +00:00
|
|
|
InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
|
2002-01-20 22:54:45 +00:00
|
|
|
BasicBlock *IfException,
|
|
|
|
const std::vector<Value*> ¶ms,
|
2002-09-10 15:45:53 +00:00
|
|
|
const std::string &Name, Instruction *InsertBefore)
|
2002-04-07 20:49:59 +00:00
|
|
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
2001-12-04 00:03:30 +00:00
|
|
|
->getElementType())->getReturnType(),
|
2002-09-10 15:45:53 +00:00
|
|
|
Instruction::Invoke, Name, InsertBefore) {
|
2001-10-13 07:01:45 +00:00
|
|
|
Operands.reserve(3+params.size());
|
2002-04-07 20:49:59 +00:00
|
|
|
Operands.push_back(Use(Func, this));
|
2002-04-09 18:36:52 +00:00
|
|
|
Operands.push_back(Use((Value*)IfNormal, this));
|
|
|
|
Operands.push_back(Use((Value*)IfException, this));
|
2002-04-04 22:19:18 +00:00
|
|
|
const FunctionType *MTy =
|
2002-04-07 20:49:59 +00:00
|
|
|
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
2001-10-13 07:01:45 +00:00
|
|
|
|
2002-04-04 22:19:18 +00:00
|
|
|
const FunctionType::ParamTypes &PL = MTy->getParamTypes();
|
2001-10-13 07:01:45 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|