1
|
(********************************************************************)
|
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 Utils.Format
|
13
|
open C_backend_mauve
|
14
|
(******************************************************************************)
|
15
|
(* Translation function *)
|
16
|
(******************************************************************************)
|
17
|
(* USELESS
|
18
|
let makefile_opt print basename dependencies makefile_fmt machines =
|
19
|
(* If a main node is identified, generate a main target for it *)
|
20
|
match !Options.main_node with
|
21
|
| "" -> ()
|
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
|
| Some _ -> print basename !Options.main_node dependencies makefile_fmt
|
26
|
)
|
27
|
*)
|
28
|
|
29
|
let c_or_cpp f =
|
30
|
if !Options.cpp then f ^ ".cpp" else f ^ ".c" (* Could be changed *)
|
31
|
|
32
|
let with_main_node machines node f =
|
33
|
if node <> "" then
|
34
|
(* looking for the main node *)
|
35
|
match Machine_code_common.get_machine_opt machines node with
|
36
|
| None ->
|
37
|
let open Error in
|
38
|
Global.main_node := node;
|
39
|
Format.eprintf "Code generation error: %a@." pp_error_msg Main_not_found;
|
40
|
raise (Error (Location.dummy_loc, Main_not_found))
|
41
|
| Some m ->
|
42
|
f m
|
43
|
|
44
|
let gen_files
|
45
|
(print_header, print_lib_c, print_main_c, print_makefile, preprocess (* , print_cmake *))
|
46
|
basename prog machines dependencies =
|
47
|
let destname = !Options.dest_dir ^ "/" ^ basename in
|
48
|
|
49
|
let machines, spec = preprocess machines in
|
50
|
|
51
|
(* Generating H file *)
|
52
|
let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
|
53
|
with_out_file alloc_header_file (fun header_fmt ->
|
54
|
print_header header_fmt basename prog machines dependencies spec);
|
55
|
|
56
|
(* Generating Lib C file *)
|
57
|
let source_lib_file = c_or_cpp destname in
|
58
|
with_out_file source_lib_file (fun source_lib_fmt ->
|
59
|
print_lib_c source_lib_fmt basename prog machines dependencies);
|
60
|
|
61
|
(* Generating Main C file *)
|
62
|
let main_node = !Options.main_node in
|
63
|
with_main_node machines main_node (fun m ->
|
64
|
let source_main_file = c_or_cpp (destname ^ "_main") in
|
65
|
with_out_file source_main_file (fun source_main_fmt ->
|
66
|
print_main_c source_main_fmt m basename prog machines dependencies));
|
67
|
|
68
|
(* Generating Mauve files *)
|
69
|
with_main_node machines !Options.mauve (fun m ->
|
70
|
let source_mauve_file = destname ^ "_mauve.hpp" in
|
71
|
with_out_file source_mauve_file (fun source_mauve_fmt ->
|
72
|
(* Header *)
|
73
|
print_mauve_header source_mauve_fmt basename;
|
74
|
(* Shell *)
|
75
|
print_mauve_shell source_mauve_fmt m;
|
76
|
(* Core *)
|
77
|
print_mauve_core source_mauve_fmt m;
|
78
|
(* FSM *)
|
79
|
print_mauve_fsm source_mauve_fmt m));
|
80
|
|
81
|
(* Generating Makefile *)
|
82
|
(* Makefiles:
|
83
|
- for the moment two cases
|
84
|
1. Classical Makefile, only when provided with a main node
|
85
|
May contain additional framac eacsl targets
|
86
|
2. Cmake : 2 files
|
87
|
- lustrec-basename.cmake describing all variables
|
88
|
- the main CMakeLists.txt activating the first file
|
89
|
- Later option 1 should be removed
|
90
|
*)
|
91
|
(* Case 1 *)
|
92
|
if main_node <> "" then
|
93
|
let makefile_file = destname ^ ".makefile" in (* Could be changed *)
|
94
|
with_out_file makefile_file (fun makefile_fmt ->
|
95
|
print_makefile basename main_node dependencies makefile_fmt)
|
96
|
|
97
|
(* (\* Case 2 *\) *)
|
98
|
(* let cmake_file = "lustrec-" ^ basename ^ ".cmake" in *)
|
99
|
(* let cmake_file_full_path = !Options.dest_dir ^ "/" ^ cmake_file in *)
|
100
|
(* let cmake_out = open_out cmake_file_full_path in *)
|
101
|
(* let cmake_fmt = formatter_of_out_channel cmake_out in *)
|
102
|
(* (\* Generating Makefile *\) *)
|
103
|
(* print_cmake basename main_node dependencies makefile_fmt; *)
|
104
|
|
105
|
(* close_out makefile_out *)
|
106
|
|
107
|
|
108
|
let translate_to_c basename prog machines dependencies =
|
109
|
let header_m, source_m, source_main_m, makefile_m, preprocess =
|
110
|
match !Options.spec with
|
111
|
| "no" ->
|
112
|
C_backend_header.(module EmptyMod : MODIFIERS_HDR),
|
113
|
C_backend_src.(module EmptyMod : MODIFIERS_SRC),
|
114
|
C_backend_main.(module EmptyMod : MODIFIERS_MAINSRC),
|
115
|
C_backend_makefile.(module EmptyMod : MODIFIERS_MKF),
|
116
|
fun m -> m, []
|
117
|
|
118
|
| "acsl" ->
|
119
|
C_backend_header.(module EmptyMod : MODIFIERS_HDR),
|
120
|
(module C_backend_spec.SrcMod : C_backend_src.MODIFIERS_SRC),
|
121
|
C_backend_main.(module EmptyMod : MODIFIERS_MAINSRC),
|
122
|
(module C_backend_spec.MakefileMod : C_backend_makefile.MODIFIERS_MKF),
|
123
|
C_backend_spec.preprocess_acsl
|
124
|
|
125
|
| "c" -> assert false (* not implemented yet *)
|
126
|
|
127
|
| _ -> assert false
|
128
|
in
|
129
|
let module Header = C_backend_header.Main (val header_m) in
|
130
|
let module Source = C_backend_src.Main (val source_m) in
|
131
|
let module SourceMain = C_backend_main.Main (val source_main_m) in
|
132
|
let module Makefile = C_backend_makefile.Main (val makefile_m) in
|
133
|
(* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
|
134
|
let funs =
|
135
|
Header.print_alloc_header,
|
136
|
Source.print_lib_c,
|
137
|
SourceMain.print_main_c,
|
138
|
Makefile.print_makefile,
|
139
|
preprocess
|
140
|
(* CMakefile.print_makefile *)
|
141
|
in
|
142
|
gen_files funs basename prog machines dependencies
|
143
|
|
144
|
|
145
|
(* Local Variables: *)
|
146
|
(* compile-command:"make -C ../../.." *)
|
147
|
(* End: *)
|