Project

General

Profile

Revision 3769b712 src/main_lustre_compiler.ml

View differences:

src/main_lustre_compiler.ml
8 8
(*  version 2.1.                                                    *)
9 9
(*                                                                  *)
10 10
(********************************************************************)
11

  
11
open Lustrec
12 12
open Format
13
open Log
13
open Lustrec.Log
14 14
open Compiler_common
15 15

  
16
open Utils
17
open Lustre_types
16
open Lustrec.Utils
17
open Lustrec.Lustre_types
18 18
 
19 19

  
20
let usage = "Usage: lustrec [options] \x1b[4msource file\x1b[0m"
20
let usage = "Usage: lustrec [options] \x1b[4msource file\x1b[0m"^ (Filename.dirname Sys.argv.(0))
21 21

  
22 22
let extensions = [".ec"; ".lus"; ".lusi"]
23 23

  
......
30 30
  begin
31 31
    Typing.uneval_prog_generics header;
32 32
    Clock_calculus.uneval_prog_generics header;
33
    Printers.pp_lusi_header h_fmt basename header;
33
    Lustrec.Printers.pp_lusi_header h_fmt basename header;
34 34
    close_out h_out
35 35
  end
36 36

  
......
43 43
let rec compile dirname basename extension =
44 44
  let source_name = dirname ^ "/" ^ basename ^ extension in
45 45

  
46
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>");
46
  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>");
47 47

  
48 48
  (* Parsing source *)
49 49
  let prog = parse source_name extension in
50 50
  
51 51
  let prog =
52
    if !Options.mpfr &&
52
    if !Lustrec.Options.mpfr &&
53 53
         extension = ".lus" (* trying to avoid the injection of the module for lusi files *) 
54 54
    then
55 55
      Lustrec_mpfr.mpfr_module::prog
......
59 59
  let params = Backends.get_normalization_params () in
60 60

  
61 61
  let prog, dependencies = 
62
    Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 1 : Normalisation@,");
62
    Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 1 : Normalisation@,");
63 63
    try 
64 64
      Compiler_stages.stage1 params prog dirname basename extension
65 65
    with Compiler_stages.StopPhase1 prog -> (
66
      if !Options.lusi then
66
      if !Lustrec.Options.lusi then
67 67
	begin
68 68
	  let lusi_ext = extension ^ "i" in
69
	  Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating interface file %s@ " (basename ^ lusi_ext));
69
	  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating interface file %s@ " (basename ^ lusi_ext));
70 70
	  print_lusi prog dirname basename lusi_ext;
71
	  Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
71
	  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
72 72
	  exit 0
73 73
	end
74
      else if !Options.print_nodes then (
75
        Format.printf "%a@.@?" Printers.pp_node_list prog;
74
      else if !Lustrec.Options.print_nodes then (
75
        Format.printf "%a@.@?" Lustrec.Printers.pp_node_list prog;
76 76
        exit 0
77 77
      )
78 78
      else
79 79
        assert false
80 80
    )
81 81
  in
82
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. Normalized program:@ %a@ "Printers.pp_prog prog);
83
  Log.report ~level:1 (fun fmt -> fprintf fmt "@]@,");
82
  Lustrec.Log.report ~level:3 (fun fmt -> fprintf fmt ".. Normalized program:@ %a@ "Lustrec.Printers.pp_prog prog);
83
  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt "@]@,");
84 84

  
85
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 2 : Machines generation@,");
85
  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 2 : Machines generation@,");
86 86

  
87 87
  let prog, machine_code = 
88 88
    Compiler_stages.stage2 params prog 
89 89
  in
90 90

  
91
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. Generated machines:@ %a@ " Machine_code_common.pp_machines machine_code);
91
  Lustrec.Log.report ~level:3 (fun fmt -> fprintf fmt ".. Generated machines:@ %a@ " Lustrec.Machine_code_common.pp_machines machine_code);
92 92

  
93 93
  if Scopes.Plugin.show_scopes () then
94 94
    begin
95
      let all_scopes = Scopes.compute_scopes prog !Options.main_node in
95
      let all_scopes = Scopes.compute_scopes prog !Lustrec.Options.main_node in
96 96
      (* Printing scopes *)
97
      if !Options.verbose_level >= 1 then
97
      if !Lustrec.Options.verbose_level >= 1 then
98 98
	Format.printf "Possible scopes are:@   ";
99 99
      Format.printf "@[<v>%a@ @]@ @?" Scopes.print_scopes all_scopes;
100 100
      exit 0
101 101
	
102 102
    end;
103 103
  let machine_code = Plugins.refine_machine_code prog machine_code in
104
  Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ @ ");
104
  Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ @ ");
105 105
  
106 106
  Compiler_stages.stage3 prog machine_code dependencies basename extension;
107 107
  begin
108
    Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
108
    Lustrec.Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
109 109
    (* We stop the process here *)
110 110
    exit 0
111 111
  end
......
133 133
    raise (Arg.Bad ("Can only compile *.lusi, *.lus or *.ec files"))
134 134

  
135 135
let _ =
136
  Global.initialize ();
137
  Corelang.add_internal_funs ();
136
  Lustrec.Global.initialize ();
137
  Lustrec.Corelang.add_internal_funs ();
138 138
  try
139 139
    Printexc.record_backtrace true;
140 140

  
141
    let options = Options_management.lustrec_options @ (Plugins.options ()) in
141
    let options = Lustrec.Options_management.lustrec_options @ (Plugins.options ()) in
142 142
    
143 143
    Arg.parse options anonymous usage
144 144
  with
145 145
  | Parse.Error _
146
  | Types.Error (_,_) | Clocks.Error (_,_) -> exit 1
147
  | Error.Error (loc , kind) (*| Task_set.Error _*) ->
148
     Error.pp_error loc (fun fmt -> Error.pp_error_msg fmt kind);
146
  | Lustrec.Types.Error (_,_) | Lustrec.Clocks.Error (_,_) -> exit 1
147
  |Lustrec.Error.Error (loc , kind) (*| Task_set.Error _*) ->
148
    Lustrec.Error.pp_error loc (fun fmt ->Lustrec.Error.pp_error_msg fmt kind);
149 149
     exit (Error.return_code kind)
150
  (* | Causality.Error _  -> exit (Error.return_code Error.AlgebraicLoop) *)
150
  (* | Lustrec.Causality.Error _  -> exit (Error.return_codeLustrec.Error.AlgebraicLoop) *)
151 151
  | Sys_error msg -> (eprintf "Failure: %s@." msg); exit 1
152 152
  | exc -> (track_exception (); raise exc) 
153 153

  

Also available in: Unified diff