[LLVMdev] How to create arguments CallInst

John Criswell criswell at illinois.edu
Thu Oct 6 11:26:52 PDT 2011


On 10/6/11 12:40 PM, Rafael Baldiati Parizi wrote:
> 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.

>
>
> 2011/10/6 John Criswell <criswell at illinois.edu 
> <mailto:criswell at illinois.edu>>
>
>     On 10/6/11 11:48 AM, Rafael Baldiati Parizi wrote:
>>     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:
>
>     http://llvm.org/viewvc/llvm-project/safecode/trunk/include/safecode/Utility.h?view=markup
>
>     -- John T.
>
>>
>>
>>     -- 
>>     */Rafael Parizi/*
>>
>>
>>
>>
>>
>>     _______________________________________________
>>     LLVM Developers mailing list
>>     LLVMdev at cs.uiuc.edu  <mailto:LLVMdev at cs.uiuc.edu>          http://llvm.cs.uiuc.edu
>>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
>
> -- 
> */Rafael Parizi/*
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111006/52f78112/attachment.html>


More information about the llvm-dev mailing list