[LLVMdev] CallInst constructor interface

Robert L. Bocchino Jr. bocchino at uiuc.edu
Wed Aug 24 14:58:10 PDT 2005


Hi,

Inserting a call instruction is a bit of a pain.  The only way I know 
how to do it is to write a bunch of code like the following:

    	std::vector<const Type*> formalArgs;
    	formalArgs.push_back(arg1->getType());
    	formalArgs.push_back(arg2->getType());
	...
	formalArgs.push_back(argn->getType());
	std::vector<Value*> args;
	args.push_back(arg1);
	args.push_back(arg2);
	...
	args.push_back(argn);
	FunctionType *FType = FunctionType::get(RetTy, formalArgs, false);
	Module *M = before->getParent()->getParent()->getParent();
	Function *F = M->getOrInsertFunction(FName, FType);
	CallInst *call = new CallInst(F, args, "func", before);

It seems that for the common case you should just be able to write this:

	std::vector<Value*> args;
	args.push_back(arg1);
	args.push_back(arg2);
	...
	args.push_back(argn);
	CallInst *call = new CallInst(RetTy, FName, args, "func", before);

or even (for a small number of arguments)

	CallInst *call = new CallInst(RetTy, FName, arg1, arg2, ..., argn, 
"func", before);

All the other stuff can be inferred from these parameters, so the extra 
rigamarole is redundant.

Does any interface like this exist?  If not, would it be acceptable to 
add one?  This would make my life easier.

Rob

Robert L. Bocchino Jr.
Ph.D. Student, Computer Science
University of Illinois, Urbana-Champaign
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20050824/88ff972d/attachment.bin>


More information about the llvm-dev mailing list