[cfe-dev] Calling Extern Function

Paul Griffiths gafferuk at gmail.com
Sun Aug 15 16:14:14 PDT 2010


 Im using example code from interpreter example. Im trying to call an
extern fuction from JIT code, but I can't get it to work.
Ive looked at examples on the net, but some are old and there all different.

How do I register an extern function?

heres some code im using at the moment.
Any help would be great!

// function I want to call
int yipee(int val)
{
	fprintf(stderr, "yipee!");

	return 1;
}

int Execute(llvm::Module *Mod, char * const *envp)
{
...
	llvm::Function *F =
cast<llvm::Function>(Mod->getOrInsertFunction("yipee",
	llvm::Type::getInt32Ty(llvm::getGlobalContext()),
llvm::Type::getInt32Ty	(llvm::getGlobalContext()), NULL));
	EE->addGlobalMapping(F, yipee);
	llvm::Function *YipeeFn = Mod->getFunction("yipee");
	if (!YipeeFn) {
		llvm::errs() << "'yipee' function not found in module.\n";
		return 255;
	}
...
}



More information about the cfe-dev mailing list