Skip to content

Instantly share code, notes, and snippets.

@eldar
Created April 3, 2012 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eldar/2294388 to your computer and use it in GitHub Desktop.
Save eldar/2294388 to your computer and use it in GitHub Desktop.
API for LDC JIT
import ldc.JIT;
void main()
{
Compiler compiler = new Compiler();
compiler.importPaths = [ "/home/eldar/ldc/druntime/import",
"/home/eldar/mylib/" ];
compiler.emitModuleInfo = false;
Module mod = compiler.compile("extern(C) int helloWorld() { return 15; }");
// Now we have options
mod.writeToFile("/home/eldar/test.bc", Compiler.ByteCode);
// Or we can JIT it
ExecutionEngine ee = new ExecutionEngine(mod);
auto func = cast(int function()) ee.findFunctionNamed("helloWorld", Linkage.C);
// Call the function
int result = func();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment