PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/3rd_party/llvm/examples/OCaml-Kaleidoscope/Chapter7/toy.ml

https://code.google.com/p/softart/
OCaml | 57 lines | 26 code | 15 blank | 16 comment | 0 complexity | 9f32059e86c5bc8ae0130ab2e947601d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, JSON, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0, LGPL-3.0, BSD-2-Clause
 1(*===----------------------------------------------------------------------===
 2 * Main driver code.
 3 *===----------------------------------------------------------------------===*)
 4
 5open Llvm
 6open Llvm_executionengine
 7open Llvm_target
 8open Llvm_scalar_opts
 9
10let main () =
11  ignore (initialize_native_target ());
12
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. *)
20
21  (* Prime the first token. *)
22  print_string "ready> "; flush stdout;
23  let stream = Lexer.lex (Stream.of_channel stdin) in
24
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
28
29  (* Set up the optimizer pipeline.  Start with registering info about how the
30   * target lays out data structures. *)
31  DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
32
33  (* Promote allocas to registers. *)
34  add_memory_to_register_promotion the_fpm;
35
36  (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
37  add_instruction_combination the_fpm;
38
39  (* reassociate expressions. *)
40  add_reassociation the_fpm;
41
42  (* Eliminate Common SubExpressions. *)
43  add_gvn the_fpm;
44
45  (* Simplify the control flow graph (deleting unreachable blocks, etc). *)
46  add_cfg_simplification the_fpm;
47
48  ignore (PassManager.initialize the_fpm);
49
50  (* Run the main "interpreter loop" now. *)
51  Toplevel.main_loop the_fpm the_execution_engine stream;
52
53  (* Print out all the generated code. *)
54  dump_module Codegen.the_module
55;;
56
57main ()