[LLVMdev] clang: call extern function using JIT

gafferuk gafferuk at gmail.com
Tue Aug 17 19:55:42 PDT 2010


Can someone pease tell me what I am doing wrong?

Im trying to register an external function with the JIT, so can call
functions in my music 

application.

Here my function

int Execute(llvm::Module *Mod, char * const *envp) {
	llvm::InitializeNativeTarget();

	std::string Error;
	llvm::OwningPtr<llvm::ExecutionEngine> EE(
		llvm::ExecutionEngine::createJIT(Mod, &Error));
	if (!EE) {
		llvm::errs() << "unable to make execution engine: " << Error << "\n";
		return 255;
	}

	// code I have added 

-------------------------------------------------------------------------------------------

--
	llvm::FunctionType* ft = llvm::FunctionType::get(llvm::Type::getInt32Ty

(llvm::getGlobalContext()),
		std::vector<const llvm::Type*>(0, llvm::Type::getInt32Ty

(llvm::getGlobalContext())), false);

	llvm::Function* f = llvm::Function::Create(ft,
llvm::Function::ExternalLinkage, 

"yipee", Mod);
	EE->addGlobalMapping(f, yipee);
	llvm::Function *YipeeFn = Mod->getFunction("yipee");
	if (!YipeeFn) {
		llvm::errs() << "'yipee' function not found in module.\n";
		return 255;
	}
	// end code I have added 

-------------------------------------------------------------------------------------------

--

	llvm::Function *EntryFn = Mod->getFunction("main");
	if (!EntryFn) {
		llvm::errs() << "'main' function not found in module.\n";
		return 255;
	}

	// FIXME: Support passing arguments.
	std::vector<std::string> Args;
	Args.push_back(Mod->getModuleIdentifier());

	return EE->runFunctionAsMain(EntryFn, Args, envp);
}



// here the C code to be ran with JIT 

-------------------------------------------------------------------

int main() {
	int dd = yipee(1);
  return 1;
}

-----------------------------------------------------------------------------------------------

gafferuk wrote:
> 
> hi, im creating a music application(image below).
> 
> At the moment im using tcc compiler but im moving across to clang because
> of the improved compiler warnings.
> Can anyone please explain and show code so I can use clang's JIT to call
> functions in my application?
> 
> Thanks.
> 
>  http://old.nabble.com/file/p29449300/51709341.jpeg 
> 

-- 
View this message in context: http://old.nabble.com/clang%3A-call-extern-function-using-JIT-tp29449300p29449502.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list