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/Method.h"
12 //===----------------------------------------------------------------------===//
13 // CallInst Implementation
14 //===----------------------------------------------------------------------===//
16 CallInst::CallInst(Value *Meth, const vector<Value*> ¶ms,
18 : Instruction(cast<MethodType>(cast<PointerType>(Meth->getType())
19 ->getValueType())->getReturnType(),
20 Instruction::Call, Name) {
21 Operands.reserve(1+params.size());
22 Operands.push_back(Use(Meth, this));
24 const MethodType *MTy =
25 cast<MethodType>(cast<PointerType>(Meth->getType())->getValueType());
27 const MethodType::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 *Meth, BasicBlock *IfNormal, \
47 BasicBlock *IfException, const vector<Value*>¶ms,
49 : TerminatorInst(cast<MethodType>(cast<PointerType>(Meth->getType())
50 ->getValueType())->getReturnType(),
51 Instruction::Invoke, Name) {
52 Operands.reserve(3+params.size());
53 Operands.push_back(Use(Meth, this));
54 Operands.push_back(Use(IfNormal, this));
55 Operands.push_back(Use(IfException, this));
56 const MethodType *MTy =
57 cast<MethodType>(cast<PointerType>(Meth->getType())->getValueType());
59 const MethodType::ParamTypes &PL = MTy->getParamTypes();
60 assert((params.size() == PL.size()) ||
61 (MTy->isVarArg() && params.size() > PL.size()) &&
62 "Calling a function with bad signature");
64 for (unsigned i = 0; i < params.size(); i++)
65 Operands.push_back(Use(params[i], this));
68 InvokeInst::InvokeInst(const InvokeInst &CI)
69 : TerminatorInst(CI.getType(), Instruction::Invoke) {
70 Operands.reserve(CI.Operands.size());
71 for (unsigned i = 0; i < CI.Operands.size(); ++i)
72 Operands.push_back(Use(CI.Operands[i], this));