1 //===-- iCall.cpp - Implement the call & invoke instructions -----*- C++ -*--=//
3 // This file implements the call and invoke instructions.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iOther.h"
8 #include "llvm/iTerminators.h"
9 #include "llvm/DerivedTypes.h"
10 #include "llvm/Function.h"
12 //===----------------------------------------------------------------------===//
13 // CallInst Implementation
14 //===----------------------------------------------------------------------===//
16 CallInst::CallInst(Value *Func, const std::vector<Value*> ¶ms,
17 const std::string &Name, Instruction *InsertBefore)
18 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
19 ->getElementType())->getReturnType(),
20 Instruction::Call, Name, InsertBefore) {
21 Operands.reserve(1+params.size());
22 Operands.push_back(Use(Func, this));
24 const FunctionType *MTy =
25 cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
27 const FunctionType::ParamTypes &PL = MTy->getParamTypes();
28 assert((params.size() == PL.size()) ||
29 (MTy->isVarArg() && params.size() >= PL.size()) &&
30 "Calling a function with bad signature");
31 for (unsigned i = 0; i < params.size(); i++)
32 Operands.push_back(Use(params[i], this));
35 CallInst::CallInst(const CallInst &CI)
36 : Instruction(CI.getType(), Instruction::Call) {
37 Operands.reserve(CI.Operands.size());
38 for (unsigned i = 0; i < CI.Operands.size(); ++i)
39 Operands.push_back(Use(CI.Operands[i], this));
42 //===----------------------------------------------------------------------===//
43 // InvokeInst Implementation
44 //===----------------------------------------------------------------------===//
46 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
47 BasicBlock *IfException,
48 const std::vector<Value*> ¶ms,
49 const std::string &Name, Instruction *InsertBefore)
50 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
51 ->getElementType())->getReturnType(),
52 Instruction::Invoke, Name, InsertBefore) {
53 Operands.reserve(3+params.size());
54 Operands.push_back(Use(Func, this));
55 Operands.push_back(Use((Value*)IfNormal, this));
56 Operands.push_back(Use((Value*)IfException, this));
57 const FunctionType *MTy =
58 cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
60 const FunctionType::ParamTypes &PL = MTy->getParamTypes();
61 assert((params.size() == PL.size()) ||
62 (MTy->isVarArg() && params.size() > PL.size()) &&
63 "Calling a function with bad signature");
65 for (unsigned i = 0; i < params.size(); i++)
66 Operands.push_back(Use(params[i], this));
69 InvokeInst::InvokeInst(const InvokeInst &CI)
70 : TerminatorInst(CI.getType(), Instruction::Invoke) {
71 Operands.reserve(CI.Operands.size());
72 for (unsigned i = 0; i < CI.Operands.size(); ++i)
73 Operands.push_back(Use(CI.Operands[i], this));