source: Deliverables/D2.2/8051/src/acc.ml @ 640

Last change on this file since 640 was 640, checked in by ayache, 9 years ago

Hex output not too long for mcu anymore. Readable output added.

File size: 2.2 KB
RevLine 
[486]1open Options
2
3(** Parse the command line. *)
4let input_files = OptionsParsing.results ()
5
6(** For each input file of the source language:
7
8    1. Parse.
9
[630]10    2. Labelize.
[486]11
12    3. Compile to the target language.
13       (And keep track of annotations if required).
14 
15    4. Annotate the input program with collected costs.
16
17    5. Save the annotated input program.
18
19    Optionnally, we can interpret the intermediate programs
20    if {!Options.interpretation_requested}.
21*)
22let process filename = 
[619]23  let _ = Printf.eprintf "Processing %s.\n%!" filename in
24  let src_language    = Options.get_source_language () in
25  let tgt_language    = Options.get_target_language () in
26  let input_ast       = Languages.parse src_language filename in 
27  let input_ast       = Languages.labelize input_ast in
28  let (exact_output, output_filename) = match Options.get_output_files () with
29    | None -> (false, filename)
30    | Some filename' -> (true, filename') in
31  let save = Languages.save exact_output output_filename in
[486]32  let target_asts =
33    (** If debugging is enabled, the compilation function returns all
34        the intermediate programs. *)
35    Languages.compile (Options.is_debug_enabled ()) 
36      src_language tgt_language input_ast
37  in
38  let final_ast, intermediate_asts = Misc.ListExt.cut_last target_asts in
[619]39    save final_ast;
[486]40    (if Options.annotation_requested () then
[640]41       let (annotated_input_ast, cost_id, cost_incr) =
[619]42         Languages.annotate input_ast final_ast in
43       save annotated_input_ast;
[640]44       Languages.save_cost output_filename cost_id cost_incr);
[486]45    (if Options.is_debug_enabled () then 
[619]46      List.iter save intermediate_asts);
[486]47    if Options.interpretation_requested () || Options.is_debug_enabled () then
48      begin
49        let asts = input_ast :: target_asts in
[619]50        let print_result = Options.is_print_result_enabled () in
51        let label_traces = List.map (Languages.interpret print_result) asts in
52        Printf.eprintf "Checking execution traces...%!";
53        Checker.same_traces (List.combine asts label_traces);
54        Printf.eprintf "OK.\n%!";
[486]55      end
56
57let _ =
58  if Options.is_dev_test_enabled () then Dev_test.do_dev_test input_files
[619]59  else List.iter process input_files
Note: See TracBrowser for help on using the repository browser.