zpu: simple fn with stack slots compile
[llvm/zpu.git] / examples / OCaml-Kaleidoscope / Chapter7 / toy.ml
blobbabab28601ddc1e84073214b3b21e5cad27e70b5
1 (*===----------------------------------------------------------------------===
2 * Main driver code.
3 *===----------------------------------------------------------------------===*)
5 open Llvm
6 open Llvm_executionengine
7 open Llvm_target
8 open Llvm_scalar_opts
10 let main () =
11 ignore (initialize_native_target ());
13 (* Install standard binary operators.
14 * 1 is the lowest precedence. *)
15 Hashtbl.add Parser.binop_precedence '=' 2;
16 Hashtbl.add Parser.binop_precedence '<' 10;
17 Hashtbl.add Parser.binop_precedence '+' 20;
18 Hashtbl.add Parser.binop_precedence '-' 20;
19 Hashtbl.add Parser.binop_precedence '*' 40; (* highest. *)
21 (* Prime the first token. *)
22 print_string "ready> "; flush stdout;
23 let stream = Lexer.lex (Stream.of_channel stdin) in
25 (* Create the JIT. *)
26 let the_execution_engine = ExecutionEngine.create Codegen.the_module in
27 let the_fpm = PassManager.create_function Codegen.the_module in
29 (* Set up the optimizer pipeline. Start with registering info about how the
30 * target lays out data structures. *)
31 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
33 (* Promote allocas to registers. *)
34 add_memory_to_register_promotion the_fpm;
36 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
37 add_instruction_combination the_fpm;
39 (* reassociate expressions. *)
40 add_reassociation the_fpm;
42 (* Eliminate Common SubExpressions. *)
43 add_gvn the_fpm;
45 (* Simplify the control flow graph (deleting unreachable blocks, etc). *)
46 add_cfg_simplification the_fpm;
48 ignore (PassManager.initialize the_fpm);
50 (* Run the main "interpreter loop" now. *)
51 Toplevel.main_loop the_fpm the_execution_engine stream;
53 (* Print out all the generated code. *)
54 dump_module Codegen.the_module
57 main ()