1 |
6efbcb73
|
xthirioux
|
(********************************************************************)
|
2 |
|
|
(* *)
|
3 |
|
|
(* The LustreC compiler toolset / The LustreC Development Team *)
|
4 |
|
|
(* Copyright 2012 - -- ONERA - CNRS - INPT *)
|
5 |
|
|
(* *)
|
6 |
|
|
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *)
|
7 |
|
|
(* under the terms of the GNU Lesser General Public License *)
|
8 |
|
|
(* version 2.1. *)
|
9 |
|
|
(* *)
|
10 |
|
|
(********************************************************************)
|
11 |
|
|
|
12 |
|
|
open Format
|
13 |
04257b1e
|
ploc
|
open Compiler_common
|
14 |
6efbcb73
|
xthirioux
|
open Utils
|
15 |
ca7e8027
|
Lélio Brun
|
|
16 |
04a63d25
|
xthirioux
|
let usage = "Usage: lustrec [options] \x1b[4msource file\x1b[0m"
|
17 |
6efbcb73
|
xthirioux
|
|
18 |
ca7ff3f7
|
Lélio Brun
|
let extensions = [ ".ec"; ".lus"; ".lusi" ]
|
19 |
6efbcb73
|
xthirioux
|
|
20 |
|
|
(* print a .lusi header file from a source prog *)
|
21 |
|
|
let print_lusi prog dirname basename extension =
|
22 |
|
|
let header = Lusic.extract_header dirname basename prog in
|
23 |
|
|
let header_name = dirname ^ "/" ^ basename ^ extension in
|
24 |
|
|
let h_out = open_out header_name in
|
25 |
|
|
let h_fmt = formatter_of_out_channel h_out in
|
26 |
ca7ff3f7
|
Lélio Brun
|
Typing.uneval_prog_generics header;
|
27 |
|
|
Clock_calculus.uneval_prog_generics header;
|
28 |
|
|
Printers.pp_lusi_header h_fmt basename header;
|
29 |
|
|
close_out h_out
|
30 |
04a63d25
|
xthirioux
|
|
31 |
|
|
(* compile a .lus source file *)
|
32 |
ca7e8027
|
Lélio Brun
|
let compile dirname basename extension =
|
33 |
04a63d25
|
xthirioux
|
let source_name = dirname ^ "/" ^ basename ^ extension in
|
34 |
|
|
|
35 |
521e2a6b
|
ploc
|
Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>");
|
36 |
04a63d25
|
xthirioux
|
|
37 |
|
|
(* Parsing source *)
|
38 |
217837e2
|
ploc
|
let prog = parse source_name extension in
|
39 |
ca7ff3f7
|
Lélio Brun
|
|
40 |
04a63d25
|
xthirioux
|
let prog =
|
41 |
ca7ff3f7
|
Lélio Brun
|
if
|
42 |
|
|
!Options.mpfr && extension = ".lus"
|
43 |
|
|
(* trying to avoid the injection of the module for lusi files *)
|
44 |
|
|
then Lustrec_mpfr.mpfr_module :: prog
|
45 |
|
|
else prog
|
46 |
04a63d25
|
xthirioux
|
in
|
47 |
ad4774b0
|
ploc
|
let params = Backends.get_normalization_params () in
|
48 |
|
|
|
49 |
ca7ff3f7
|
Lélio Brun
|
let prog, dependencies =
|
50 |
|
|
Log.report ~level:1 (fun fmt ->
|
51 |
|
|
fprintf fmt "@[<v 2>.. Phase 1: Normalisation@,");
|
52 |
|
|
try Compiler_stages.stage1 params prog dirname basename extension
|
53 |
|
|
with Compiler_stages.StopPhase1 prog ->
|
54 |
|
|
if !Options.lusi then (
|
55 |
|
|
let lusi_ext = extension ^ "i" in
|
56 |
|
|
Log.report ~level:1 (fun fmt ->
|
57 |
|
|
fprintf fmt ".. generating interface file %s@ " (basename ^ lusi_ext));
|
58 |
|
|
print_lusi prog dirname basename lusi_ext;
|
59 |
|
|
Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
|
60 |
|
|
exit 0)
|
61 |
a0c92fa8
|
ploc
|
else if !Options.print_nodes then (
|
62 |
|
|
Format.printf "%a@.@?" Printers.pp_node_list prog;
|
63 |
ca7ff3f7
|
Lélio Brun
|
exit 0)
|
64 |
|
|
else assert false
|
65 |
6efbcb73
|
xthirioux
|
in
|
66 |
ca7ff3f7
|
Lélio Brun
|
Log.report ~level:3 (fun fmt ->
|
67 |
|
|
fprintf fmt "@ @[<v 2>.. Normalized program:@ %a@]" Printers.pp_prog prog);
|
68 |
521e2a6b
|
ploc
|
|
69 |
ca7ff3f7
|
Lélio Brun
|
Log.report ~level:1 (fun fmt ->
|
70 |
|
|
fprintf fmt "@]@ @ @[<v 2>.. Phase 2 : Machines generation@,");
|
71 |
04a63d25
|
xthirioux
|
|
72 |
ca7ff3f7
|
Lélio Brun
|
let prog, machine_code = Compiler_stages.stage2 params prog in
|
73 |
521e2a6b
|
ploc
|
|
74 |
ca7ff3f7
|
Lélio Brun
|
Log.report ~level:3 (fun fmt ->
|
75 |
|
|
fprintf fmt "@ @[<v 2>.. Generated machines:@ %a@]"
|
76 |
|
|
Machine_code_common.pp_machines machine_code);
|
77 |
|
|
|
78 |
|
|
if Scopes.Plugin.show_scopes () then (
|
79 |
|
|
let all_scopes = Scopes.compute_scopes prog !Options.main_node in
|
80 |
|
|
(* Printing scopes *)
|
81 |
|
|
if !Options.verbose_level >= 1 then Format.printf "Possible scopes are:@ ";
|
82 |
|
|
Format.printf "@[<v>%a@ @]@ @?" Scopes.print_scopes all_scopes;
|
83 |
|
|
exit 0);
|
84 |
ca88e660
|
Ploc
|
let machine_code = Plugins.refine_machine_code prog machine_code in
|
85 |
bc9fd714
|
ploc
|
Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ @ ");
|
86 |
ca7ff3f7
|
Lélio Brun
|
|
87 |
217837e2
|
ploc
|
Compiler_stages.stage3 prog machine_code dependencies basename extension;
|
88 |
ca7ff3f7
|
Lélio Brun
|
Log.report ~level:1 (fun fmt -> fprintf fmt "@ .. done !@]@.");
|
89 |
|
|
(* We stop the process here *)
|
90 |
|
|
exit 0
|
91 |
6efbcb73
|
xthirioux
|
|
92 |
|
|
let compile dirname basename extension =
|
93 |
61df3cb9
|
ploc
|
Plugins.init ();
|
94 |
6efbcb73
|
xthirioux
|
match extension with
|
95 |
ca7ff3f7
|
Lélio Brun
|
| ".lusi" | ".lus" ->
|
96 |
|
|
compile dirname basename extension
|
97 |
|
|
| _ ->
|
98 |
|
|
assert false
|
99 |
6efbcb73
|
xthirioux
|
|
100 |
|
|
let anonymous filename =
|
101 |
ca7ff3f7
|
Lélio Brun
|
let ok_ext, ext =
|
102 |
|
|
List.fold_left
|
103 |
|
|
(fun (ok, ext) ext' ->
|
104 |
|
|
if (not ok) && Filename.check_suffix filename ext' then true, ext'
|
105 |
|
|
else ok, ext)
|
106 |
|
|
(false, "") extensions
|
107 |
|
|
in
|
108 |
|
|
if ok_ext then (
|
109 |
|
|
Options_management.setup ();
|
110 |
6efbcb73
|
xthirioux
|
let dirname = Filename.dirname filename in
|
111 |
|
|
let basename = Filename.chop_suffix (Filename.basename filename) ext in
|
112 |
ca7ff3f7
|
Lélio Brun
|
compile dirname basename ext)
|
113 |
|
|
else raise (Arg.Bad "Can only compile *.lusi, *.lus or *.ec files")
|
114 |
6efbcb73
|
xthirioux
|
|
115 |
|
|
let _ =
|
116 |
04a63d25
|
xthirioux
|
Global.initialize ();
|
117 |
6efbcb73
|
xthirioux
|
Corelang.add_internal_funs ();
|
118 |
|
|
try
|
119 |
|
|
Printexc.record_backtrace true;
|
120 |
04a63d25
|
xthirioux
|
|
121 |
ca7ff3f7
|
Lélio Brun
|
let options = Options_management.lustrec_options @ Plugins.options () in
|
122 |
|
|
|
123 |
04a63d25
|
xthirioux
|
Arg.parse options anonymous usage
|
124 |
6efbcb73
|
xthirioux
|
with
|
125 |
ca7ff3f7
|
Lélio Brun
|
| Parse.Error | Types.Error (_, _) | Clocks.Error (_, _) ->
|
126 |
90e83deb
|
Lélio Brun
|
exit 1
|
127 |
ca7ff3f7
|
Lélio Brun
|
| Error.Error (loc, kind) (*| Task_set.Error _*) ->
|
128 |
90e83deb
|
Lélio Brun
|
Error.pp_error loc (fun fmt -> Error.pp_error_msg fmt kind);
|
129 |
|
|
exit (Error.return_code kind)
|
130 |
ca7ff3f7
|
Lélio Brun
|
(* | Causality.Error _ -> exit (Error.return_code Error.AlgebraicLoop) *)
|
131 |
90e83deb
|
Lélio Brun
|
| Sys_error msg ->
|
132 |
ca7ff3f7
|
Lélio Brun
|
eprintf "Failure: %s@." msg;
|
133 |
|
|
exit 1
|
134 |
90e83deb
|
Lélio Brun
|
| exc ->
|
135 |
ca7ff3f7
|
Lélio Brun
|
track_exception ();
|
136 |
|
|
raise exc
|
137 |
6efbcb73
|
xthirioux
|
|
138 |
|
|
(* Local Variables: *)
|
139 |
|
|
(* compile-command:"make -C .." *)
|
140 |
|
|
(* End: *)
|