[obj2yaml] - Stop triggering UB when dumping corrupted strings.
[llvm-complete.git] / examples / OCaml-Kaleidoscope / Chapter4 / toy.ml
blob5a6bde9458cb090c2a9f0edb35ecc0c83eacc24c
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 '<' 10;
16 Hashtbl.add Parser.binop_precedence '+' 20;
17 Hashtbl.add Parser.binop_precedence '-' 20;
18 Hashtbl.add Parser.binop_precedence '*' 40; (* highest. *)
20 (* Prime the first token. *)
21 print_string "ready> "; flush stdout;
22 let stream = Lexer.lex (Stream.of_channel stdin) in
24 (* Create the JIT. *)
25 let the_execution_engine = ExecutionEngine.create Codegen.the_module in
26 let the_fpm = PassManager.create_function Codegen.the_module in
28 (* Set up the optimizer pipeline. Start with registering info about how the
29 * target lays out data structures. *)
30 DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
32 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
33 add_instruction_combination the_fpm;
35 (* reassociate expressions. *)
36 add_reassociation the_fpm;
38 (* Eliminate Common SubExpressions. *)
39 add_gvn the_fpm;
41 (* Simplify the control flow graph (deleting unreachable blocks, etc). *)
42 add_cfg_simplification the_fpm;
44 ignore (PassManager.initialize the_fpm);
46 (* Run the main "interpreter loop" now. *)
47 Toplevel.main_loop the_fpm the_execution_engine stream;
49 (* Print out all the generated code. *)
50 dump_module Codegen.the_module
53 main ()