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

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

32 and 16 bits operations support in D2.2/8051

File size: 2.3 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      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 () then
57    begin
58      let asts = target_asts in
59      let debug = Options.is_debug_enabled () in
60      let label_traces = List.map (Languages.interpret debug) asts in
61      Printf.eprintf "Checking execution traces...%!";
62      Checker.same_traces (List.combine asts label_traces);
63      Printf.eprintf "OK.\n%!";
64    end
65
66let _ =
67  if Options.is_dev_test_enabled () then Dev_test.do_dev_test input_files
68  else List.iter process input_files
Note: See TracBrowser for help on using the repository browser.