1 (*===----------------------------------------------------------------------===
3 *===----------------------------------------------------------------------===*)
6 open Llvm_executionengine
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
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. *)
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