source: Deliverables/D2.2/8051-indexed-labels-branch/src/acc.ml @ 1433

Last change on this file since 1433 was 1433, checked in by tranquil, 8 years ago
  • added infrastructure to add same-language transformations along the compilation chain from command line options
  • started work on cost expression semplification
File size: 2.7 KB
Line 
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
10    2. Add runtime functions.
11
12    3. Labelize.
13
14    4. Compile to the target language.
15       (And keep track of annotations if required).
16 
17    5. Annotate the input program with collected costs.
18
19    6. Save the annotated input program.
20
21    Optionnally, we can interpret the intermediate programs
22    if {!Options.interpretation_requested}.
23*)
24let process filename = 
25  let _ = Printf.eprintf "Processing %s.\n%!" filename in
26  let src_language    = Options.get_source_language () in
27  let tgt_language    = Options.get_target_language () in
28  let input_ast       = Languages.parse src_language filename in 
29  let input_ast       = Languages.add_runtime input_ast in 
30  let input_ast       = Languages.labelize input_ast in
31  let (exact_output, output_filename) = match Options.get_output_files () with
32    | None -> (false, filename)
33    | Some filename' -> (true, filename') in
34  let save ?(suffix="") ast = 
35    Languages.save exact_output output_filename suffix ast
36  in
37  let target_asts =
38    (** If debugging is enabled, the compilation function returns all
39        the intermediate programs. *)
40    Languages.compile (Options.is_debug_enabled ()) 
41      (Options.get_transformations ()) src_language tgt_language input_ast
42  in
43  let final_ast, intermediate_asts = Misc.ListExt.cut_last target_asts in
44  save final_ast;
45  if Options.annotation_requested () then
46    begin
47      let (annotated_input_ast, cost_id, cost_incr) =
48        Languages.annotate input_ast final_ast in (
49          save ~suffix:"-annotated" annotated_input_ast;
50          Languages.save_cost output_filename cost_id cost_incr);
51    end;
52                                             
53  if Options.is_debug_enabled () then 
54    List.iter save intermediate_asts;
55
56  if Options.interpretation_requested () || Options.is_debug_enabled () ||
57               Options.trace_requested () then
58    begin
59      let asts = target_asts in
60      let debug = Options.is_debug_enabled () in
61      let label_traces = List.map (Languages.interpret debug) asts in
62      Printf.eprintf "Checking execution traces...%!";
63                        if Options.trace_requested () then
64                                let print_l l =
65                                        Printf.printf "%s, " (CostLabel.string_of_cost_label
66                                                               ~pretty:true l) in
67                          let print_ls ls = List.iter print_l ls in
68                                let print_trace (v, ls) =
69                                        Printf.printf "%s | " (Big_int.string_of_big_int v);
70                                        print_ls ls;
71                                        Printf.printf "\n" in
72                                List.iter print_trace label_traces
73                        else ();
74      Checker.same_traces (List.combine asts label_traces);
75      Printf.eprintf "OK.\n%!";
76    end
77
78let _ =
79  if Options.is_dev_test_enabled () then Dev_test.do_dev_test input_files
80  else List.iter process input_files
Note: See TracBrowser for help on using the repository browser.