1 (*===----------------------------------------------------------------------=== 2 * Main driver code. 3 *===----------------------------------------------------------------------===*) 4 5 open Llvm 6 open Llvm_executionengine 7 open Llvm_target 8 open Llvm_scalar_opts 9 10 let main () = 11 ignore (initialize_native_target ()); 12 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. *) 19 20 (* Prime the first token. *) 21 print_string "ready> "; flush stdout; 22 let stream = Lexer.lex (Stream.of_channel stdin) in 23 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 27 28 (* Set up the optimizer pipeline. Start with registering info about how the 29 * target lays out data structures. *) 30 TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; 31 32 (* Do simple "peephole" optimizations and bit-twiddling optzn. *) 33 add_instruction_combination the_fpm; 34 35 (* reassociate expressions. *) 36 add_reassociation the_fpm; 37 38 (* Eliminate Common SubExpressions. *) 39 add_gvn the_fpm; 40 41 (* Simplify the control flow graph (deleting unreachable blocks, etc). *) 42 add_cfg_simplification the_fpm; 43 44 ignore (PassManager.initialize the_fpm); 45 46 (* Run the main "interpreter loop" now. *) 47 Toplevel.main_loop the_fpm the_execution_engine stream; 48 49 (* Print out all the generated code. *) 50 dump_module Codegen.the_module 51 ;; 52 53 main () 54