@@ -25,22 +25,44 @@ let gen_output_filename ?(ext = ".c") file_in =
2525 | None -> failwith " You didn't provide a file suffixed with '.ua'"
2626 | Some base -> base ^ ext
2727
28- let compile (file_in : string ) (prog : Usuba_AST.prog ) (conf : config ) : unit =
29- (* Type-checking *)
28+ let compile file conf =
29+ (* Parsing *)
30+ let prog =
31+ Errors. exec_with_print_and_fail
32+ (Parser_api. parse_file conf.path)
33+ (fun prog -> if conf.parse_only then exit 0 else prog)
34+ file
35+ in
36+
37+ (* Variables binding *)
3038 let prog =
3139 Errors. exec_with_print_and_fail
32- (Type_checker. type_prog ~conf )
40+ (Variable_binding. bind_prog ~conf )
3341 (fun prog -> prog)
3442 prog
3543 in
3644
45+ (* Format.eprintf "--------BINDING--------@.@.%a@."
46+ * (Usuba_print.pp_prog ~detailed:(conf.verbose > 10) ())
47+ * prog; *)
48+
49+ (* Type-checking *)
50+ let prog =
51+ if conf.type_check then
52+ Errors. exec_with_print_and_fail
53+ (Type_checker. type_prog ~conf )
54+ (fun prog -> if conf.type_only then exit 0 else prog)
55+ prog
56+ else prog
57+ in
58+
3759 (* Normalizing AND optimizing *)
3860 let normed_prog = Normalize. compile prog conf in
3961 match conf.dump_sexp with
4062 | true ->
4163 let out =
4264 match conf.output with
43- | "" -> open_out (gen_output_filename ~ext: " .ua0" file_in )
65+ | "" -> open_out (gen_output_filename ~ext: " .ua0" file )
4466 | str -> open_out str
4567 in
4668 let ppf = Format. formatter_of_out_channel out in
@@ -49,26 +71,27 @@ let compile (file_in : string) (prog : Usuba_AST.prog) (conf : config) : unit =
4971 close_out out
5072 | false ->
5173 (* Generating a string of C code *)
52- let c_prog_str = Usuba_to_c. prog_to_c prog normed_prog conf file_in in
74+ let c_prog_str = Usuba_to_c. prog_to_c prog normed_prog conf file in
5375
5476 (* Opening out file *)
5577 let out =
5678 match conf.output with
57- | "" -> open_out (gen_output_filename file_in )
79+ | "" -> open_out (gen_output_filename file )
5880 | str -> open_out str
5981 in
6082 (* Printing the C code *)
6183 Printf. fprintf out " %s" c_prog_str;
6284 close_out out
6385
64- let run_tests () : unit =
65- Test_constant_folding. test () ;
66- Test_CSE. test () ;
67- Test_copy_propagation. test () ;
68- Test_remove_dead_code. test () ;
69- Test_pass_runner. test () ;
70- Test_monomorphize. test () ;
71- Printf. printf " All tests ran.\n "
86+ let run_tests () : unit = ()
87+ (* Do nothing for now *)
88+ (* Test_constant_folding.test (); *)
89+ (* Test_CSE.test (); *)
90+ (* Test_copy_propagation.test (); *)
91+ (* Test_remove_dead_code.test (); *)
92+ (* Test_pass_runner.test (); *)
93+ (* Test_monomorphize.test (); *)
94+ (* Printf.printf "All tests ran.\n" *)
7295
7396let main () =
7497 Printexc. record_backtrace true ;
@@ -77,6 +100,8 @@ let main () =
77100 let nocolor = ref false in
78101 let verbose = ref 1 in
79102 let path = ref [ " ." ] in
103+ let parse_only = ref false in
104+ let type_only = ref false in
80105 let type_check = ref true in
81106 let check_tbl = ref false in
82107 let no_inline = ref false in
@@ -273,12 +298,16 @@ let main () =
273298 ( " -compact" ,
274299 Arg. Set compact,
275300 " Generates more compact code (for bitslicing only)" );
301+ (" -parse-only" , Arg. Set parse_only, " Only parse files" );
302+ (" -type-only" , Arg. Set type_only, " Only parse and type files" );
276303 (" -tests" , Arg. Unit (fun () -> run_tests () ), " Run tests" );
277304 ]
278305 in
279306 let usage_msg = " Usage: usuba [switches] [files]" in
280307
281- let compile s =
308+ let generate_conf_and_compile file =
309+ let path = Filename. dirname file :: List. rev ! path in
310+
282311 let bits_per_reg =
283312 if ! bits_per_reg <> 64 then ! bits_per_reg
284313 else if ! shares <> 1 then 32
@@ -287,8 +316,6 @@ let main () =
287316
288317 let pre_sched = ! pre_schedule (* && !scheduling *) in
289318
290- let path = Filename. dirname s :: List. rev ! path in
291-
292319 if ! maskVerif then (
293320 unroll := true ;
294321 no_arr := true ;
@@ -298,7 +325,7 @@ let main () =
298325 (* When -no-arr is combined with -ua-masked, the linearization
299326 could take forever, and is obviously not necessary. *)
300327 linearize_arr := false ;
301- let base_file = Filename. (basename @@ chop_suffix s " .ua" ) in
328+ let base_file = Filename. (basename @@ chop_suffix file " .ua" ) in
302329 let dump_steps_dir = Filename. (concat ! dump_steps_dir base_file) in
303330 (if ! dump_steps <> None then
304331 try Sys. mkdir dump_steps_dir 0o777 with Sys_error _ -> () );
@@ -311,6 +338,8 @@ let main () =
311338 verbose = ! verbose;
312339 path;
313340 (* local var *)
341+ parse_only = ! parse_only;
342+ type_only = ! type_only;
314343 type_check = ! type_check;
315344 check_tbl = ! check_tbl;
316345 auto_inline = ! auto_inline;
@@ -353,28 +382,24 @@ let main () =
353382 gen_bench = ! gen_bench;
354383 keep_tables = ! keep_tables;
355384 compact = ! compact;
385+ step_counter = ref 0 ;
386+ dump_sexp = ! dump_sexp;
387+ dump_steps = ! dump_steps;
388+ dump_steps_base_file;
356389 bench_inline = ! bench_inline || ! bench_all;
357390 bench_inter = ! bench_inter || ! bench_all;
358391 bench_bitsched = ! bench_bitsched || ! bench_all;
359392 bench_msched = ! bench_msched || ! bench_all;
360393 bench_sharevar = ! bench_sharevar || ! bench_all;
361- step_counter = ref 0 ;
362- dump_sexp = ! dump_sexp;
363- dump_steps = ! dump_steps;
364- dump_steps_base_file;
365394 }
366395 in
367-
368- let prog = Parser_api. parse_file conf.path s in
369-
370- compile s prog conf
396+ compile file conf
371397 in
372398
373399 let input_files = ref [] in
374400 let anon_fun filename = input_files := filename :: ! input_files in
375-
376401 Arg. parse speclist anon_fun usage_msg;
377402
378- List. iter (fun file -> compile file) ! input_files
403+ List. iter (fun file -> generate_conf_and_compile file) ! input_files
379404
380405let () = main ()
0 commit comments