<font face="arial,helvetica,sans-serif">Hi everyone !</font><div><font face="arial,helvetica,sans-serif">I am very new to LLVM and intent to use it in a research project.</font></div><div><font face="arial,helvetica,sans-serif">I have a problem with the interpreter: I have a simple compiler that generates LLVM bitcode, JIT it and execute it, and it works very well.</font></div>

<div><font face="arial,helvetica,sans-serif">Now I would like to execute it using the interpreter. And I get a segfault.</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div>

<div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Here is the code :</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-tab-span" style="white-space: pre; ">   </span>// This code JIT the function and executes it</font></div>

<div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::InitializeNativeTarget();</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::ExecutionEngine * EJ  = llvm::ExecutionEngine::create(&nM);</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>typedef int (*REFunc)(const char *);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>union { void * obj; REFunc func; } u;</div><div>

<span class="Apple-tab-span" style="white-space:pre"> </span>u.obj = EJ->getPointerToFunction(func);</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>REFunc jit = u.func;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int ret = jit("aaa");</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>std::cout << std::endl << ret << std::endl;</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-tab-span" style="white-space: pre; ">       </span>// This code interprets the function</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::initializeCore();</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::ExecutionEngine * EI  = llvm::EngineBuilder(&M).setEngineKind(llvm::EngineKind::Interpreter).create();</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>EI->runStaticConstructorsDestructors(false);</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>std::vector<llvm::GenericValue> args;</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::GenericValue arg1((void*)"aaabc");</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>args.push_back(arg1);</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>llvm::APInt res = EI->runFunction(func, args).IntVal;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>llvm::outs() << res << "\n";</div><div><br></div><div>The first block of code works very well and write the expected result.</div><div>

The second block segfaults on the EI->runFunction(func, args) call.</div><div>I can't find my mistake. Would somebody help me on this ???</div><div><br></div><div>Thank you very much !</div><div><br></div><div>Salomon BRYS.</div>

</font><meta http-equiv="content-type" content="text/html; charset=utf-8"></div><div><br>-- <br>###########################################<br># Salomon BRYS<br># +33 (0) 6 83 54 55 96<br>#------------------------------------------<br>

# > EPITECH "Koala" : C++ assistant : Sbire du C++<br># > Zend Certified Engineer for PHP5<br>#------------------------------------------<br># All data in this e-mail is confidential.<br># If you are not, or if you don't believe you are, the recipient of this e-mail, please delete it.<br>

#------------------------------------------<br># GPG : <a href="http://gpgkey-salomon.antesocial.fr/">http://gpgkey-salomon.antesocial.fr/</a><br>###########################################<br>
</div>