How to create arguments CallInst

Hello,

I need create a CallInst to this function

define i32 @function(i32 %n, i8 %m){ … }

I now how get argument’s type but I do not know how to create arguments that meet these types.
For example, if the argument is long, accurate pass CallInst an integer argument, however, if a Char, Char must pass an argument.
How to get the type of the argument of the function definition and create the same type to pass the Callinst???

If you want to pass a value to a function that doesn’t match the type, you will need to insert a cast instruction to cast the value to the correct type. Which cast instruction you insert will depend on the value’s type and the type you want it to be.

SAFECode has a utility function castTo() that takes a Value * and a desired Type * and inserts a cast instruction if Value * is not of the desired type. It’s designed to minimize the number of cast instructions it inserts so that the resulting LLVM IR is more readable for debugging:

– John T.

virtual std::vector<Value *> getESetArgumentosFunc(Function *F){
std::vector<Value *> varg_list;
varg_list.clear();
for(Function::arg_iterator arg_iti = F->getArgumentList().begin(), arg_ite = F->getArgumentList().end(); arg_iti != arg_ite; ++arg_iti){
Value *para = ConstantInt::get(IntegerType::get(getGlobalContext(),32), 0);
Value *val2 = cast< arg_iti->getType()>(para); <--------------------------
para->setName(“test”);
varg_list.push_back(para);
}
return varg_list;
}

How can I make this cast??

2011/10/6 John Criswell <criswell@illinois.edu>

virtual std::vector<Value *> getESetArgumentosFunc(Function *F){
std::vector<Value *> varg_list;
varg_list.clear();
for(Function::arg_iterator arg_iti = F->getArgumentList().begin(), arg_ite = F->getArgumentList().end(); arg_iti != arg_ite; ++arg_iti){
Value *para = ConstantInt::get(IntegerType::get(getGlobalContext(),32), 0);
Value *val2 = cast< arg_iti->getType()>(para); <--------------------------
para->setName(“test”);
varg_list.push_back(para);
}
return varg_list;
}

How can I make this cast??

I think you misunderstood me. You need to insert an LLVM cast instruction. For example, you might insert the following code:

Value *para = ConstantInt::get(IntegerType::get(getGlobalContext(),32), 0);
Value * Val2 = CastInst::CreateZExtOrBitCast (para, arg_iti->getType(), “test”, InsertPt)

… where InsertPt is an Instruction * specifying where to insert the cast instruction.

Having said that, if all you’re doing is inserting zero values of the appropriate type, it might be easier to use:

Value * Val2 = Constant::getNullValue (arg_iti->getType());

– John T.

John,
I needed just this: Value * Val2 = Constant::getNullValue (arg_iti->getType());

Thanks.

2011/10/6 John Criswell <criswell@illinois.edu>