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

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

New memory model and bug fixes in 8051 branch. Added primitive operations in interpreters from Clight to LIN.

File size: 2.1 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. Labelize.
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 = 
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 ?(suffix="") ast = 
32    Languages.save exact_output output_filename suffix ast
33  in
34  let target_asts =
35    (** If debugging is enabled, the compilation function returns all
36        the intermediate programs. *)
37    Languages.compile (Options.is_debug_enabled ()) 
38      src_language tgt_language input_ast
39  in
40  let final_ast, intermediate_asts = Misc.ListExt.cut_last target_asts in
41  save final_ast;
42  if Options.annotation_requested () then
43    begin
44      let (annotated_input_ast, cost_id, cost_incr) =
45        Languages.annotate input_ast final_ast in (
46          save ~suffix:"-annotated" annotated_input_ast;
47          Languages.save_cost output_filename cost_id cost_incr);
48    end;
49                                             
50  if Options.is_debug_enabled () then 
51    List.iter save intermediate_asts;
52
53  if Options.interpretation_requested () || Options.is_debug_enabled () then
54    begin
55      let asts = input_ast :: target_asts in
56      let label_traces = List.map (Languages.interpret false) asts in
57      Printf.eprintf "Checking execution traces...%!";
58      Checker.same_traces (List.combine asts label_traces);
59      Printf.eprintf "OK.\n%!";
60    end
61
62let _ =
63  if Options.is_dev_test_enabled () then Dev_test.do_dev_test input_files
64  else List.iter process input_files
Note: See TracBrowser for help on using the repository browser.