<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Hi,<div><br class="webkit-block-placeholder"></div><div>this looks very promising. Do you have any plans to add bindings for the use of an ExecutionEngine, especially recompileAndRelinkFunction? I've build an interactive toplevel implemented in OCaml and I have to pull of some stunts to be able to change the definition of a function. (emit a .ll file containing the code, looking up the function and calling removeBody, then reading the .ll file back in using ParseAssemblyString). I noticed that functions are represented as an llvalue which makes turning it into a Function* unsafe if I'm correct?</div><div><br class="webkit-block-placeholder"></div><div>greetings, Jan</div><div><br><div><div>On 2. Okt 2007, at 19:51, Gordon Henriksen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div>On 2007-10-02, at 10:46, Jan Rehders wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">where can I read more about this? I assume (hope) the lib provides some kind of OCaml bindings? I could not find any trace of it in the 2.1 release source so I guess it's currently SVN only?</span></div></blockquote><br></div><div>Jan,</div><div><br class="webkit-block-placeholder"></div><div>Here's a trivial example.</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div><font class="Apple-style-span" face="Courier">$ <b>cat metahelloworld.ml</b></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#FF0000">(* metahelloworld.ml *)</font></font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF">open</font> <i>Llvm</i></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF">open</font> <i>Llvm_bitwriter</i></font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF">let</font> _ =</font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> filename = <i>Sys</i>.argv.(1) <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> m = create_module filename <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><span class="Apple-style-span" style="font-family: Courier; ">  <font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">(* @greeting = global [14 x i8] c"Hello, world!\00" *)</span></font></span></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> greeting = define_global <font class="Apple-style-span" color="#999999">"greeting"</font> (make_string_constant</font></div><div><font class="Apple-style-span" face="Courier">                                             "Hello, world!" <font class="Apple-style-span" color="#0000FF">true</font>) m <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">(* declare i32 @puts(i8*) *)</span></font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> puts = declare_function <font class="Apple-style-span" color="#999999">"puts"</font> (make_function_type i32_type [|</font></div><div><font class="Apple-style-span" face="Courier">                                        make_pointer_type i8_type |] <font class="Apple-style-span" color="#0000FF">false</font>) m <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">(* define i32 @main() {</span></font></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">     entry:               *)</span></font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> main = define_function <font class="Apple-style-span" color="#999999">"main"</font> (make_function_type</font></div><div><font class="Apple-style-span" face="Courier">                                       i32_type [| |] <font class="Apple-style-span" color="#0000FF">false</font>) m <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">let</font> at_entry = builder_at_end (entry_block main) <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">(* %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32 0 *)</span></font></font></div><div><span class="Apple-style-span" style="font-family: Courier; ">  <font class="Apple-style-span" color="#0000FF">let</font> zero = make_int_constant i32_type 0 <font class="Apple-style-span" color="#0000FF">false in</font></span></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">  </span>let</font> str = build_gep greeting [| zero; zero |] "tmp" at_entry <font class="Apple-style-span" color="#0000FF">in</font></font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#FF0000">  (* call i32 @puts( i8* %tmp ) *)</font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">ignore</font> (build_call puts [| str |] <font class="Apple-style-span" color="#999999">""</font> at_entry);</font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF"><span class="Apple-style-span" style="color: rgb(255, 0, 0); ">(* ret void *)</span></font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">ignore</font> (build_ret (make_null i32_type) at_entry);</font></div><div><font class="Apple-style-span" face="Courier">  </font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#FF0000">(* write the module to a file *)</font></font></div><div><font class="Apple-style-span" face="Courier">  <font class="Apple-style-span" color="#0000FF">if</font> <font class="Apple-style-span" color="#0000FF">not</font> (write_bitcode_file m filename) <font class="Apple-style-span" color="#0000FF">then</font> exit 1;</font></div><div><font class="Apple-style-span" face="Courier">  dispose_module m</font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier">$ <b>ocamlopt -cc g++ llvm.cmxa llvm_bitwriter.cmxa -o metahelloworld metahelloworld.ml</b></font></div><div><font class="Apple-style-span" face="Courier">$ <b>./metahelloworld helloworld.bc</b></font></div><div><font class="Apple-style-span" face="Courier">$ <b>llvm-dis < helloworld.bc</b></font></div><div><font class="Apple-style-span" face="Courier">; ModuleID = '<stdin>'</font></div><div><font class="Apple-style-span" face="Courier">@greeting = global [14 x i8] c"Hello, world!\00"                ; <[14 x i8]*> [#uses=1]</font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier">declare i32 @puts(i8*)</font></div><div><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Courier">define i32 @main() {</font></div><div><font class="Apple-style-span" face="Courier">entry:</font></div><div><font class="Apple-style-span" face="Courier">        %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32 0    ; <i8*> [#uses=1]</font></div><div><font class="Apple-style-span" face="Courier">        call i32 @puts( i8* %tmp )              ; <i32>:0 [#uses=0]</font></div><div><font class="Apple-style-span" face="Courier">        ret i32 0</font></div><div><font class="Apple-style-span" face="Courier">}</font></div><div><span class="Apple-style-span" style="font-family: Courier; ">$ <b>llc -o helloworld.s helloworld.bc</b></span></div><div><font class="Apple-style-span" face="Courier">$ <b>gcc -o helloworld helloworld.s</b></font></div><div><font class="Apple-style-span" face="Courier">$ <b>./helloworld </b></font></div><div><font class="Apple-style-span" face="Courier">Hello, world!</font></div><font class="Apple-style-span" face="Courier New"><br></font></div></div><div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">— Gordon<br class="Apple-interchange-newline"></span></span></span></span></span></span> </div></blockquote></div><br></div></body></html>