[LLVMdev] OCaml Install Error

Jan Rehders cmdkeen at gmx.de
Fri Oct 19 08:51:31 PDT 2007


Hi,

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?

greetings, Jan

On 2. Okt 2007, at 19:51, Gordon Henriksen wrote:

> On 2007-10-02, at 10:46, Jan Rehders wrote:
>
>> 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?
>
> Jan,
>
> Here's a trivial example.
>
> $ cat metahelloworld.ml
> (* metahelloworld.ml *)
>
> open Llvm
> open Llvm_bitwriter
>
> let _ =
>   let filename = Sys.argv.(1) in
>   let m = create_module filename in
>
>   (* @greeting = global [14 x i8] c"Hello, world!\00" *)
>   let greeting = define_global "greeting" (make_string_constant
>                                              "Hello, world!" true)  
> m in
>
>   (* declare i32 @puts(i8*) *)
>   let puts = declare_function "puts" (make_function_type i32_type [|
>                                         make_pointer_type i8_type  
> |] false) m in
>
>   (* define i32 @main() {
>      entry:               *)
>   let main = define_function "main" (make_function_type
>                                        i32_type [| |] false) m in
>   let at_entry = builder_at_end (entry_block main) in
>
>   (* %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32 0 *)
>   let zero = make_int_constant i32_type 0 false in
>   let str = build_gep greeting [| zero; zero |] "tmp" at_entry in
>
>   (* call i32 @puts( i8* %tmp ) *)
>   ignore (build_call puts [| str |] "" at_entry);
>
>   (* ret void *)
>   ignore (build_ret (make_null i32_type) at_entry);
>
>   (* write the module to a file *)
>   if not (write_bitcode_file m filename) then exit 1;
>   dispose_module m
>
> $ ocamlopt -cc g++ llvm.cmxa llvm_bitwriter.cmxa -o metahelloworld  
> metahelloworld.ml
> $ ./metahelloworld helloworld.bc
> $ llvm-dis < helloworld.bc
> ; ModuleID = '<stdin>'
> @greeting = global [14 x i8] c"Hello, world!\00"                ; < 
> [14 x i8]*> [#uses=1]
>
> declare i32 @puts(i8*)
>
> define i32 @main() {
> entry:
>         %tmp = getelementptr [14 x i8]* @greeting, i32 0, i32  
> 0    ; <i8*> [#uses=1]
>         call i32 @puts( i8* %tmp )              ; <i32>:0 [#uses=0]
>         ret i32 0
> }
> $ llc -o helloworld.s helloworld.bc
> $ gcc -o helloworld helloworld.s
> $ ./helloworld
> Hello, world!
>
> — Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20071019/6d0089be/attachment.html>


More information about the llvm-dev mailing list