Initial revision
[oota-llvm.git] / lib / VMCore / iCall.cpp
1 //===-- iCall.cpp - Implement the Call & Invoke instructions -----*- C++ -*--=//
2 //
3 // This file implements the call and invoke instructions.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/iOther.h"
8 #include "llvm/DerivedTypes.h"
9 #include "llvm/Method.h"
10
11 CallInst::CallInst(Method *m, vector<Value*> &params, 
12                    const string &Name) 
13   : Instruction(m->getReturnType(), Instruction::Call, Name), M(m, this) {
14
15   const MethodType* MT = M->getMethodType();
16   const MethodType::ParamTypes &PL = MT->getParamTypes();
17   assert(params.size() == PL.size());
18 #ifndef NDEBUG
19   MethodType::ParamTypes::const_iterator It = PL.begin();
20 #endif
21   for (unsigned i = 0; i < params.size(); i++) {
22     assert(*It++ == params[i]->getType());
23     Params.push_back(Use(params[i], this));
24   }
25 }
26
27 CallInst::CallInst(const CallInst &CI) 
28   : Instruction(CI.getType(), Instruction::Call), M(CI.M, this) {
29   for (unsigned i = 0; i < CI.Params.size(); i++)
30     Params.push_back(Use(CI.Params[i], this));
31 }
32
33 void CallInst::dropAllReferences() { 
34   M = 0;
35   Params.clear(); 
36 }
37
38 bool CallInst::setOperand(unsigned i, Value *Val) {
39   if (i > Params.size()) return false;
40   if (i == 0) {
41     assert(Val->getValueType() == Value::MethodVal);
42     M = (Method*)Val;
43   } else {
44     // TODO: assert = method arg type
45     Params[i-1] = Val;
46   }
47   return true;
48 }