I am using LLVM to compile script code and then executing using the JIT compiler via the runFunction() method. The script code is contained with a C++ program compiled with G++. I am having a problem when an intrinsic function (i.e. a function implemented in C++ which is called from the LLVM compiled script) throws a C++ exception. I want the exception to be caught by the C++ code that invoked the script. Instead it appears that no exception handler is found.<br>
<br>Does anyone know of a way to throw C++ exceptions through LLVM JITed code?<br><br>To illustrate the problem a bit better, consider this psuedo code. I want the exception thrown in intrinsic_function(), which is called from the LLVM compiled code, to be caught by the exception handler at the bottom of run_program().<br>
<br>void intrinsic_function() {<br>   throw runtime_error("unimplemented function");<br>}<br><br>void run_program() {<br>  char *script_code = "call intrinsic_function();";<br><br>  try {<br>    myFunction = compile(script_code);<br>
    Engine->runFunction(myFunction);<br>  } catch (...) {<br>     // This is never reached.<br>  }<br>}<br><br>I suspect this is not going to be possible unless somehow GCC and LLVM used the same stack structure so that the exception handling code could unwind the stack through the JITed code.<br>
<br>Thanks, Chris.<br>