0

I want to use Function::Create method to create a function whose input parameter type is llvm::Instruction* but I didn't find any direct method in class Type to do that. Can anyone give me some hints?

Also For a concrete compare Instruction *pi, I tried pi->getType()->print(errs()) and it returned me i1 as type. But when I wrote a function int externalCall(Instruction *p) in another cpp file and compiled into IR. This IR says the type is class.llvm::Instruction. Why this two are different and how can I get the latter one from the API?

Min Gao
  • 383
  • 4
  • 16
  • Could you provide an example of how you would expect the IR to look like at the end, and how you would expect a call to that function to look like in the IR? – Oak Jun 26 '14 at 19:46
  • something like `call void @foo('class.llvm::Instruction' p)` – Min Gao Jun 26 '14 at 19:51
  • As far as the LLVM bitcode is concerned there's nothing special about `llvm::Instruction`, it's just a C++ type. So this question might be just as well about any other type. In particular, you would definitely not find any special treatment of that type. So I suggest searching for general ways to create a type in LLVM. – Oak Jun 26 '14 at 19:55

1 Answers1

0

As long as you use c-style linking, the pointer type is largely irrelevant:

  • cast to pointer to i8 on the llvm side
  • receive whatever type you want on the c/c++ callee side. Instruction * is ok

(Just use a BitcastInst to case, on the llvm side, like:

BitCastInst *bitcast = new BitCastInst(value, PointerType::get(IntegerType::get(context, 8), 0));

(... where value is your Instruction * object)

Hugh Perkins
  • 7,975
  • 7
  • 63
  • 71