1 |
a2d97a3e
|
ploc
|
(********************************************************************)
|
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 |
22fe1c93
|
ploc
|
|
12 |
d4107cf2
|
ploc
|
open Format
|
13 |
d1b9423d
|
David Doose
|
open C_backend_mauve
|
14 |
22fe1c93
|
ploc
|
(********************************************************************************************)
|
15 |
|
|
(* Translation function *)
|
16 |
|
|
(********************************************************************************************)
|
17 |
ef34b4ae
|
xthirioux
|
(* USELESS
|
18 |
d4107cf2
|
ploc
|
let makefile_opt print basename dependencies makefile_fmt machines =
|
19 |
|
|
(* If a main node is identified, generate a main target for it *)
|
20 |
9c4cc944
|
Corentin Lauverjat
|
match !Lustrec.Options.main_node with
|
21 |
d4107cf2
|
ploc
|
| "" -> ()
|
22 |
|
|
| main_node -> (
|
23 |
|
|
match Machine_code.get_machine_opt main_node machines with
|
24 |
|
|
| None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; ()
|
25 |
9c4cc944
|
Corentin Lauverjat
|
| Some _ -> print basename !Lustrec.Options.main_node dependencies makefile_fmt
|
26 |
d4107cf2
|
ploc
|
)
|
27 |
ef34b4ae
|
xthirioux
|
*)
|
28 |
d4107cf2
|
ploc
|
|
29 |
dc893173
|
ploc
|
let gen_files funs basename prog machines dependencies =
|
30 |
9c4cc944
|
Corentin Lauverjat
|
let destname = !Lustrec.Options.dest_dir ^ "/" ^ basename in
|
31 |
dc893173
|
ploc
|
|
32 |
71999483
|
ploc
|
let print_header, print_lib_c, print_main_c, print_makefile, preprocess (* , print_cmake *) = funs in
|
33 |
dc893173
|
ploc
|
|
34 |
71999483
|
ploc
|
let machines, spec = preprocess machines in
|
35 |
|
|
|
36 |
d4107cf2
|
ploc
|
(* Generating H file *)
|
37 |
dc893173
|
ploc
|
let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
|
38 |
|
|
let header_out = open_out alloc_header_file in
|
39 |
|
|
let header_fmt = formatter_of_out_channel header_out in
|
40 |
71999483
|
ploc
|
print_header header_fmt basename prog machines dependencies spec;
|
41 |
dc893173
|
ploc
|
close_out header_out;
|
42 |
|
|
|
43 |
d4107cf2
|
ploc
|
(* Generating Lib C file *)
|
44 |
9c4cc944
|
Corentin Lauverjat
|
let source_lib_file = (if !Lustrec.Options.cpp then destname ^ ".cpp" else destname ^ ".c") in (* Could be changed *)
|
45 |
dc893173
|
ploc
|
let source_lib_out = open_out source_lib_file in
|
46 |
|
|
let source_lib_fmt = formatter_of_out_channel source_lib_out in
|
47 |
d4107cf2
|
ploc
|
print_lib_c source_lib_fmt basename prog machines dependencies;
|
48 |
ef34b4ae
|
xthirioux
|
close_out source_lib_out;
|
49 |
|
|
|
50 |
9c4cc944
|
Corentin Lauverjat
|
(match !Lustrec.Options.main_node with
|
51 |
bb1b5e04
|
Ploc
|
| "" -> () (* No main node: we do not generate main *)
|
52 |
d4107cf2
|
ploc
|
| main_node -> (
|
53 |
9c4cc944
|
Corentin Lauverjat
|
match Lustrec.Machine_code_common.get_machine_opt machines main_node with
|
54 |
04a63d25
|
xthirioux
|
| None -> begin
|
55 |
9c4cc944
|
Corentin Lauverjat
|
Lustrec.Global.main_node := main_node;
|
56 |
|
|
Format.eprintf "Code generation error: %a@." Lustrec.Error.pp_error_msg Lustrec.Error.Main_not_found;
|
57 |
|
|
raise (Lustrec.Error.Error (Lustrec.Location.dummy_loc,Lustrec.Error.Main_not_found))
|
58 |
04a63d25
|
xthirioux
|
end
|
59 |
d4107cf2
|
ploc
|
| Some m -> begin
|
60 |
9c4cc944
|
Corentin Lauverjat
|
let source_main_file = (if !Lustrec.Options.cpp then destname ^ "_main.cpp" else destname ^ "_main.c") in (* Could be changed *)
|
61 |
d4107cf2
|
ploc
|
let source_main_out = open_out source_main_file in
|
62 |
|
|
let source_main_fmt = formatter_of_out_channel source_main_out in
|
63 |
13eb21df
|
ploc
|
|
64 |
d4107cf2
|
ploc
|
(* Generating Main C file *)
|
65 |
|
|
print_main_c source_main_fmt m basename prog machines dependencies;
|
66 |
ef34b4ae
|
xthirioux
|
|
67 |
bb1b5e04
|
Ploc
|
close_out source_main_out;
|
68 |
d4107cf2
|
ploc
|
end
|
69 |
bb1b5e04
|
Ploc
|
));
|
70 |
|
|
|
71 |
9c4cc944
|
Corentin Lauverjat
|
(match !Lustrec.Options.mauve with
|
72 |
d1b9423d
|
David Doose
|
| "" -> ()
|
73 |
|
|
| mauve -> (
|
74 |
|
|
(* looking for the main node *)
|
75 |
9c4cc944
|
Corentin Lauverjat
|
match Lustrec.Machine_code_common.get_machine_opt machines mauve with
|
76 |
d1b9423d
|
David Doose
|
| None -> begin
|
77 |
9c4cc944
|
Corentin Lauverjat
|
Lustrec.Global.main_node := mauve;
|
78 |
|
|
Format.eprintf "Code generation error: %a@." Lustrec.Error.pp_error_msg Lustrec.Error.Main_not_found;
|
79 |
|
|
raise (Lustrec.Error.Error (Lustrec.Location.dummy_loc,Lustrec.Error.Main_not_found))
|
80 |
d1b9423d
|
David Doose
|
end
|
81 |
|
|
| Some m -> begin
|
82 |
|
|
let source_mauve_file = destname ^ "_mauve.hpp" in
|
83 |
|
|
let source_mauve_out = open_out source_mauve_file in
|
84 |
|
|
let source_mauve_fmt = formatter_of_out_channel source_mauve_out in
|
85 |
|
|
(* Header *)
|
86 |
|
|
print_mauve_header source_mauve_fmt m basename prog machines dependencies;
|
87 |
|
|
(* Shell *)
|
88 |
|
|
print_mauve_shell source_mauve_fmt m basename prog machines dependencies;
|
89 |
|
|
(* Core *)
|
90 |
|
|
print_mauve_core source_mauve_fmt m basename prog machines dependencies;
|
91 |
|
|
(* FSM *)
|
92 |
|
|
print_mauve_fsm source_mauve_fmt m basename prog machines dependencies;
|
93 |
|
|
|
94 |
|
|
close_out source_mauve_out;
|
95 |
|
|
end
|
96 |
|
|
));
|
97 |
|
|
|
98 |
bb1b5e04
|
Ploc
|
|
99 |
|
|
(* Makefiles:
|
100 |
|
|
- for the moment two cases
|
101 |
|
|
1. Classical Makefile, only when provided with a main node
|
102 |
|
|
May contain additional framac eacsl targets
|
103 |
|
|
2. Cmake : 2 files
|
104 |
|
|
- lustrec-basename.cmake describing all variables
|
105 |
|
|
- the main CMakeLists.txt activating the first file
|
106 |
|
|
- Later option 1 should be removed
|
107 |
|
|
*)
|
108 |
|
|
(* Case 1 *)
|
109 |
9c4cc944
|
Corentin Lauverjat
|
(match !Lustrec.Options.main_node with
|
110 |
bb1b5e04
|
Ploc
|
| "" -> () (* No main node: we do not generate main *)
|
111 |
|
|
| main_node -> (
|
112 |
|
|
let makefile_file = destname ^ ".makefile" in (* Could be changed *)
|
113 |
|
|
let makefile_out = open_out makefile_file in
|
114 |
|
|
let makefile_fmt = formatter_of_out_channel makefile_out in
|
115 |
|
|
|
116 |
|
|
(* Generating Makefile *)
|
117 |
|
|
print_makefile basename main_node dependencies makefile_fmt;
|
118 |
|
|
|
119 |
|
|
close_out makefile_out
|
120 |
dcafc99b
|
Ploc
|
))(* ; *)
|
121 |
bb1b5e04
|
Ploc
|
|
122 |
dcafc99b
|
Ploc
|
(* (\* Case 2 *\) *)
|
123 |
|
|
(* let cmake_file = "lustrec-" ^ basename ^ ".cmake" in *)
|
124 |
9c4cc944
|
Corentin Lauverjat
|
(* let cmake_file_full_path = !Lustrec.Options.dest_dir ^ "/" ^ cmake_file in *)
|
125 |
dcafc99b
|
Ploc
|
(* let cmake_out = open_out cmake_file_full_path in *)
|
126 |
|
|
(* let cmake_fmt = formatter_of_out_channel cmake_out in *)
|
127 |
|
|
(* (\* Generating Makefile *\) *)
|
128 |
|
|
(* print_cmake basename main_node dependencies makefile_fmt; *)
|
129 |
bb1b5e04
|
Ploc
|
|
130 |
dcafc99b
|
Ploc
|
(* close_out makefile_out *)
|
131 |
bb1b5e04
|
Ploc
|
|
132 |
cefc3744
|
ploc
|
|
133 |
dc893173
|
ploc
|
let translate_to_c basename prog machines dependencies =
|
134 |
9c4cc944
|
Corentin Lauverjat
|
match !Lustrec.Options.spec with
|
135 |
d4107cf2
|
ploc
|
| "no" -> begin
|
136 |
|
|
let module HeaderMod = C_backend_header.EmptyMod in
|
137 |
|
|
let module SourceMod = C_backend_src.EmptyMod in
|
138 |
|
|
let module SourceMainMod = C_backend_main.EmptyMod in
|
139 |
|
|
let module MakefileMod = C_backend_makefile.EmptyMod in
|
140 |
cefc3744
|
ploc
|
|
141 |
d4107cf2
|
ploc
|
let module Header = C_backend_header.Main (HeaderMod) in
|
142 |
|
|
let module Source = C_backend_src.Main (SourceMod) in
|
143 |
|
|
let module SourceMain = C_backend_main.Main (SourceMainMod) in
|
144 |
|
|
let module Makefile = C_backend_makefile.Main (MakefileMod) in
|
145 |
dcafc99b
|
Ploc
|
(* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
|
146 |
bb1b5e04
|
Ploc
|
|
147 |
58a463e7
|
ploc
|
let funs =
|
148 |
|
|
Header.print_alloc_header,
|
149 |
|
|
Source.print_lib_c,
|
150 |
|
|
SourceMain.print_main_c,
|
151 |
71999483
|
ploc
|
Makefile.print_makefile,
|
152 |
|
|
(fun m -> m, [])
|
153 |
dcafc99b
|
Ploc
|
(* CMakefile.print_makefile *)
|
154 |
58a463e7
|
ploc
|
in
|
155 |
dc893173
|
ploc
|
gen_files funs basename prog machines dependencies
|
156 |
cefc3744
|
ploc
|
|
157 |
d4107cf2
|
ploc
|
end
|
158 |
|
|
| "acsl" -> begin
|
159 |
13eb21df
|
ploc
|
|
160 |
d4107cf2
|
ploc
|
let module HeaderMod = C_backend_header.EmptyMod in
|
161 |
|
|
let module SourceMod = C_backend_src.EmptyMod in
|
162 |
|
|
let module SourceMainMod = C_backend_main.EmptyMod in
|
163 |
|
|
let module MakefileMod = C_backend_spec.MakefileMod in
|
164 |
22fe1c93
|
ploc
|
|
165 |
d4107cf2
|
ploc
|
let module Header = C_backend_header.Main (HeaderMod) in
|
166 |
|
|
let module Source = C_backend_src.Main (SourceMod) in
|
167 |
|
|
let module SourceMain = C_backend_main.Main (SourceMainMod) in
|
168 |
|
|
let module Makefile = C_backend_makefile.Main (MakefileMod) in
|
169 |
dcafc99b
|
Ploc
|
(* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
|
170 |
bb1b5e04
|
Ploc
|
|
171 |
58a463e7
|
ploc
|
let funs =
|
172 |
|
|
Header.print_alloc_header,
|
173 |
|
|
Source.print_lib_c,
|
174 |
|
|
SourceMain.print_main_c,
|
175 |
71999483
|
ploc
|
Makefile.print_makefile,
|
176 |
|
|
C_backend_spec.preprocess_acsl
|
177 |
dcafc99b
|
Ploc
|
(* CMakefile.print_makefile *)
|
178 |
58a463e7
|
ploc
|
in
|
179 |
dc893173
|
ploc
|
gen_files funs basename prog machines dependencies
|
180 |
22fe1c93
|
ploc
|
|
181 |
d4107cf2
|
ploc
|
end
|
182 |
|
|
| "c" -> begin
|
183 |
|
|
assert false (* not implemented yet *)
|
184 |
|
|
end
|
185 |
|
|
| _ -> assert false
|
186 |
22fe1c93
|
ploc
|
(* Local Variables: *)
|
187 |
cd670fe1
|
ploc
|
(* compile-command:"make -C ../../.." *)
|
188 |
22fe1c93
|
ploc
|
(* End: *)
|