summaryrefslogtreecommitdiff
path: root/lib/VMCore/iCall.cpp
blob: 9ff6bb6fc8cd3e9a574631af409593af3e958dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===-- iCall.cpp - Implement the Call & Invoke instructions -----*- C++ -*--=//
//
// This file implements the call and invoke instructions.
//
//===----------------------------------------------------------------------===//

#include "llvm/iOther.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Method.h"

CallInst::CallInst(Method *m, vector<Value*> &params, 
                   const string &Name) 
  : Instruction(m->getReturnType(), Instruction::Call, Name), M(m, this) {

  const MethodType* MT = M->getMethodType();
  const MethodType::ParamTypes &PL = MT->getParamTypes();
  assert(params.size() == PL.size());
#ifndef NDEBUG
  MethodType::ParamTypes::const_iterator It = PL.begin();
#endif
  for (unsigned i = 0; i < params.size(); i++) {
    assert(*It++ == params[i]->getType());
    Params.push_back(Use(params[i], this));
  }
}

CallInst::CallInst(const CallInst &CI) 
  : Instruction(CI.getType(), Instruction::Call), M(CI.M, this) {
  for (unsigned i = 0; i < CI.Params.size(); i++)
    Params.push_back(Use(CI.Params[i], this));
}

void CallInst::dropAllReferences() { 
  M = 0;
  Params.clear(); 
}

bool CallInst::setOperand(unsigned i, Value *Val) {
  if (i > Params.size()) return false;
  if (i == 0) {
    assert(Val->getValueType() == Value::MethodVal);
    M = (Method*)Val;
  } else {
    // TODO: assert = method arg type
    Params[i-1] = Val;
  }
  return true;
}