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(Value *Func, const std::string &Name,
36 Instruction *InsertBefore)
37 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
38 ->getElementType())->getReturnType(),
39 Instruction::Call, Name, InsertBefore) {
41 Operands.push_back(Use(Func, this));
43 const FunctionType *MTy =
44 cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
46 const FunctionType::ParamTypes &PL = MTy->getParamTypes();
47 assert((0 == PL.size()) ||
48 (MTy->isVarArg() && 0 >= PL.size()) &&
49 "Calling a function with bad signature");
52 CallInst::CallInst(Value *Func, Value* A, const std::string &Name,
53 Instruction *InsertBefore)
54 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
55 ->getElementType())->getReturnType(),
56 Instruction::Call, Name, InsertBefore) {
58 Operands.push_back(Use(Func, this));
60 const FunctionType *MTy =
61 cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
63 const FunctionType::ParamTypes &PL = MTy->getParamTypes();
64 assert((1 == PL.size()) ||
65 (MTy->isVarArg() && 1 >= PL.size()) &&
66 "Calling a function with bad signature");
67 Operands.push_back(Use(A, this));
70 CallInst::CallInst(const CallInst &CI)
71 : Instruction(CI.getType(), Instruction::Call) {
72 Operands.reserve(CI.Operands.size());
73 for (unsigned i = 0; i < CI.Operands.size(); ++i)
74 Operands.push_back(Use(CI.Operands[i], this));
77 //===----------------------------------------------------------------------===//
78 // InvokeInst Implementation
79 //===----------------------------------------------------------------------===//
81 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
82 BasicBlock *IfException,
83 const std::vector<Value*> ¶ms,
84 const std::string &Name, Instruction *InsertBefore)
85 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
86 ->getElementType())->getReturnType(),
87 Instruction::Invoke, Name, InsertBefore) {
88 Operands.reserve(3+params.size());
89 Operands.push_back(Use(Func, this));
90 Operands.push_back(Use((Value*)IfNormal, this));
91 Operands.push_back(Use((Value*)IfException, this));
92 const FunctionType *MTy =
93 cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
95 const FunctionType::ParamTypes &PL = MTy->getParamTypes();
96 assert((params.size() == PL.size()) ||
97 (MTy->isVarArg() && params.size() > PL.size()) &&
98 "Calling a function with bad signature");
100 for (unsigned i = 0; i < params.size(); i++)
101 Operands.push_back(Use(params[i], this));
104 InvokeInst::InvokeInst(const InvokeInst &CI)
105 : TerminatorInst(CI.getType(), Instruction::Invoke) {
106 Operands.reserve(CI.Operands.size());
107 for (unsigned i = 0; i < CI.Operands.size(); ++i)
108 Operands.push_back(Use(CI.Operands[i], this));