Fix the ocaml kaleidoscope tutorial to fix linking external libraries.
[oota-llvm.git] / docs / tutorial / OCamlLangImpl7.html
index abda44011cab14a629855bd4f463d8b3a515c1ba..c140888626cf10126db866ab60fec4441f356e39 100644 (file)
@@ -543,7 +543,7 @@ good codegen once again:</p>
 <pre>
 let main () =
   ...
-  let the_fpm = PassManager.create_function the_module_provider in
+  let the_fpm = PassManager.create_function Codegen.the_module in
 
   (* Set up the optimizer pipeline.  Start with registering info about how the
    * target lays out data structures. *)
@@ -581,12 +581,12 @@ then:    ; preds = %entry
 
 else:    ; preds = %entry
   <b>%x3 = load double* %x1</b>
-  %subtmp = sub double %x3, 1.000000e+00
+  %subtmp = fsub double %x3, 1.000000e+00
   %calltmp = call double @fib( double %subtmp )
   <b>%x4 = load double* %x1</b>
-  %subtmp5 = sub double %x4, 2.000000e+00
+  %subtmp5 = fsub double %x4, 2.000000e+00
   %calltmp6 = call double @fib( double %subtmp5 )
-  %addtmp = add double %calltmp, %calltmp6
+  %addtmp = fadd double %calltmp, %calltmp6
   br label %ifcont
 
 ifcont:    ; preds = %else, %then
@@ -619,11 +619,11 @@ then:
   br label %ifcont
 
 else:
-  %subtmp = sub double <b>%x</b>, 1.000000e+00
+  %subtmp = fsub double <b>%x</b>, 1.000000e+00
   %calltmp = call double @fib( double %subtmp )
-  %subtmp5 = sub double <b>%x</b>, 2.000000e+00
+  %subtmp5 = fsub double <b>%x</b>, 2.000000e+00
   %calltmp6 = call double @fib( double %subtmp5 )
-  %addtmp = add double %calltmp, %calltmp6
+  %addtmp = fadd double %calltmp, %calltmp6
   br label %ifcont
 
 ifcont:    ; preds = %else, %then
@@ -649,11 +649,11 @@ entry:
   br i1 %ifcond, label %else, label %ifcont
 
 else:
-  %subtmp = sub double %x, 1.000000e+00
+  %subtmp = fsub double %x, 1.000000e+00
   %calltmp = call double @fib( double %subtmp )
-  %subtmp5 = sub double %x, 2.000000e+00
+  %subtmp5 = fsub double %x, 2.000000e+00
   %calltmp6 = call double @fib( double %subtmp5 )
-  %addtmp = add double %calltmp, %calltmp6
+  %addtmp = fadd double %calltmp, %calltmp6
   ret double %addtmp
 
 ifcont:
@@ -999,7 +999,7 @@ ocaml_lib ~extern:true "llvm_executionengine";;
 ocaml_lib ~extern:true "llvm_target";;
 ocaml_lib ~extern:true "llvm_scalar_opts";;
 
-flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;
+flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"; A"-cclib"; A"-rdynamic"]);;
 dep ["link"; "ocaml"; "use_bindings"] ["bindings.o"];;
 </pre>
 </dd>
@@ -1384,14 +1384,16 @@ open Llvm
 
 exception Error of string
 
-let the_module = create_module "my cool jit"
-let builder = builder ()
+let context = global_context ()
+let the_module = create_module context "my cool jit"
+let builder = builder context
 let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
+let double_type = double_type context
 
 (* Create an alloca instruction in the entry block of the function. This
  * is used for mutable variables etc. *)
 let create_entry_block_alloca the_function var_name =
-  let builder = builder_at (instr_begin (entry_block the_function)) in
+  let builder = builder_at context (instr_begin (entry_block the_function)) in
   build_alloca double_type var_name builder
 
 let rec codegen_expr = function
@@ -1481,7 +1483,7 @@ let rec codegen_expr = function
       let start_bb = insertion_block builder in
       let the_function = block_parent start_bb in
 
-      let then_bb = append_block "then" the_function in
+      let then_bb = append_block context "then" the_function in
 
       (* Emit 'then' value. *)
       position_at_end then_bb builder;
@@ -1493,7 +1495,7 @@ let rec codegen_expr = function
       let new_then_bb = insertion_block builder in
 
       (* Emit 'else' value. *)
-      let else_bb = append_block "else" the_function in
+      let else_bb = append_block context "else" the_function in
       position_at_end else_bb builder;
       let else_val = codegen_expr else_ in
 
@@ -1502,7 +1504,7 @@ let rec codegen_expr = function
       let new_else_bb = insertion_block builder in
 
       (* Emit merge block. *)
-      let merge_bb = append_block "ifcont" the_function in
+      let merge_bb = append_block context "ifcont" the_function in
       position_at_end merge_bb builder;
       let incoming = [(then_val, new_then_bb); (else_val, new_else_bb)] in
       let phi = build_phi incoming "iftmp" builder in
@@ -1554,7 +1556,7 @@ let rec codegen_expr = function
 
       (* Make the new basic block for the loop header, inserting after current
        * block. *)
-      let loop_bb = append_block "loop" the_function in
+      let loop_bb = append_block context "loop" the_function in
 
       (* Insert an explicit fall through from the current block to the
        * loop_bb. *)
@@ -1598,7 +1600,7 @@ let rec codegen_expr = function
       let end_cond = build_fcmp Fcmp.One end_cond zero "loopcond" builder in
 
       (* Create the "after loop" block and insert it. *)
-      let after_bb = append_block "afterloop" the_function in
+      let after_bb = append_block context "afterloop" the_function in
 
       (* Insert the conditional branch into the end of loop_end_bb. *)
       ignore (build_cond_br end_cond loop_bb after_bb builder);
@@ -1722,7 +1724,7 @@ let codegen_func the_fpm = function
       end;
 
       (* Create a new basic block to start insertion into. *)
-      let bb = append_block "entry" the_function in
+      let bb = append_block context "entry" the_function in
       position_at_end bb builder;
 
       try
@@ -1790,7 +1792,7 @@ let rec main_loop the_fpm the_execution_engine stream =
               the_execution_engine in
 
             print_string "Evaluated to ";
-            print_float (GenericValue.as_float double_type result);
+            print_float (GenericValue.as_float Codegen.double_type result);
             print_newline ();
         with Stream.Error s | Codegen.Error s -&gt;
           (* Skip token for error recovery. *)
@@ -1815,6 +1817,8 @@ open Llvm_target
 open Llvm_scalar_opts
 
 let main () =
+  ignore (initialize_native_target ());
+
   (* Install standard binary operators.
    * 1 is the lowest precedence. *)
   Hashtbl.add Parser.binop_precedence '=' 2;
@@ -1828,9 +1832,8 @@ let main () =
   let stream = Lexer.lex (Stream.of_channel stdin) in
 
   (* Create the JIT. *)
-  let the_module_provider = ModuleProvider.create Codegen.the_module in
-  let the_execution_engine = ExecutionEngine.create the_module_provider in
-  let the_fpm = PassManager.create_function the_module_provider in
+  let the_execution_engine = ExecutionEngine.create Codegen.the_module in
+  let the_fpm = PassManager.create_function Codegen.the_module in
 
   (* Set up the optimizer pipeline.  Start with registering info about how the
    * target lays out data structures. *)
@@ -1840,7 +1843,7 @@ let main () =
   add_memory_to_register_promotion the_fpm;
 
   (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
-  add_instruction_combining the_fpm;
+  add_instruction_combination the_fpm;
 
   (* reassociate expressions. *)
   add_reassociation the_fpm;
@@ -1851,6 +1854,8 @@ let main () =
   (* Simplify the control flow graph (deleting unreachable blocks, etc). *)
   add_cfg_simplification the_fpm;
 
+  ignore (PassManager.initialize the_fpm);
+
   (* Run the main "interpreter loop" now. *)
   Toplevel.main_loop the_fpm the_execution_engine stream;
 
@@ -1896,7 +1901,7 @@ extern double printd(double X) {
   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
   <a href="mailto:idadesub@users.sourceforge.net">Erick Tryzelaar</a><br>
-  Last modified: $Date: 2007-10-17 11:05:13 -0700 (Wed, 17 Oct 2007) $
+  Last modified: $Date$
 </address>
 </body>
 </html>