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? DEBUG(pWrapper->dump();); DEBUG(pWrapper->getFunctionType()->dump()); DEBUG(cerr << "number of arguments: " << pWrapper->getArgumentList().size() << endl;); The debug code above prints as below: declare void %foo(int*) void (int *) number of arguments: 0 -- Brian Ensink www-sal.cs.uiuc.edu/~ensink Graduate Student, University of Illinois at Urbana-Champaign
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
> 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.I just checked in a changeset that changes LLVM to operate exactly this way: when a Function is constructed, the argument list is populated. Thus every function will always have an argument list that matches it's function type, even external functions. I think this is a case where you incorrect expectations was due to a problem in LLVM, not your expectations. :) Thanks, -Chris http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/