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

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

Update of D2.2 from Paris.

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