[LLVMdev] Accessing a function's arguments

Brian Ensink ensink at cs.uiuc.edu
Fri Oct 11 17:30:01 PDT 2002


Just a followup for the archives ... 

> I am trying to generate a simple wrapper function: 
> 
>     Function* pWrapper = m_module.getOrInsertFunction(name, 
>        FunctionType::get(Type::VoidTy, 
> 	 vector<const Type*>(1, PointerType::get(Type::IntTy)), false));
> 
> How do I actually get the Value* for the one argument to this function?
> The pWrapper->getArgumentList().size() is 0. Shouldn't the argument list  
> contain the Value* for the parameter?

My incorrect assumption was that the ArgumentList would get built when the
Function is instantiated -- by simply walking over the parameter type vector
of the FunctionType.

Instead you have to manually fill in the ArgumentList but this also gives you
the opportunity to specify a name for each argument. In my case all I needed
to add was one line of code to create the only argument:

  new Argument(PointerType::get(Type::IntTy), "arg", pWrapper);

-- 
Brian Ensink                     www-sal.cs.uiuc.edu/~ensink
Graduate Student, University of Illinois at Urbana-Champaign



More information about the llvm-dev mailing list