Project

General

Profile

Download (7.18 KB) Statistics
| Branch: | Tag: | Revision:
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 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 gen_files funs basename prog machines dependencies =
30
  let destname = !Options.dest_dir ^ "/" ^ basename in
31
  
32
  let print_header, print_lib_c, print_main_c, print_makefile(* , print_cmake *) = funs in
33

    
34
  (* Generating H file *)
35
  let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
36
  let header_out = open_out alloc_header_file in
37
  let header_fmt = formatter_of_out_channel header_out in
38
  print_header header_fmt basename prog machines dependencies;
39
  close_out header_out;
40
  
41
  (* Generating Lib C file *)
42
  let source_lib_file = (if !Options.cpp then destname ^ ".cpp" else destname ^ ".c") in (* Could be changed *)
43
  let source_lib_out = open_out source_lib_file in
44
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
45
  print_lib_c source_lib_fmt basename prog machines dependencies;
46
  close_out source_lib_out;
47

    
48
  (match !Options.main_node with
49
  | "" ->  () (* No main node: we do not generate main *)
50
  | main_node -> (
51
    match Machine_code_common.get_machine_opt main_node machines with
52
    | None -> begin
53
      Global.main_node := main_node;
54
      Format.eprintf "Code generation error: %a@." Error.pp_error_msg Error.Main_not_found;
55
      raise (Corelang.Error (Location.dummy_loc, Error.Main_not_found))
56
    end
57
    | Some m -> begin
58
      let source_main_file = (if !Options.cpp then destname ^ "_main.cpp" else destname ^ "_main.c") in (* Could be changed *)
59
      let source_main_out = open_out source_main_file in
60
      let source_main_fmt = formatter_of_out_channel source_main_out in
61

    
62
      (* Generating Main C file *)
63
      print_main_c source_main_fmt m basename prog machines dependencies;
64

    
65
      close_out source_main_out;
66
    end
67
  ));
68

    
69
  (match !Options.mauve with
70
  | "" ->  ()
71
  | mauve -> (
72
    (* looking for the main node *)
73
    match Machine_code_common.get_machine_opt mauve machines with
74
    | None -> begin
75
      Global.main_node := mauve;
76
      Format.eprintf "Code generation error: %a@." Error.pp_error_msg Error.Main_not_found;
77
      raise (Corelang.Error (Location.dummy_loc, Error.Main_not_found))
78
    end
79
    | Some m -> begin
80
      let source_mauve_file = destname ^ "_mauve.hpp" in
81
      let source_mauve_out = open_out source_mauve_file in
82
      let source_mauve_fmt = formatter_of_out_channel source_mauve_out in
83
      (* Header *)
84
      print_mauve_header source_mauve_fmt m basename prog machines dependencies;
85
      (* Shell *)
86
      print_mauve_shell source_mauve_fmt m basename prog machines dependencies;
87
      (* Core *)
88
      print_mauve_core source_mauve_fmt m basename prog machines dependencies;
89
      (* FSM *)
90
      print_mauve_fsm source_mauve_fmt m basename prog machines dependencies;
91

    
92
      close_out source_mauve_out;
93
    end
94
  ));
95

    
96

    
97
  (* Makefiles:
98
     - for the moment two cases
99
     1. Classical Makefile, only when provided with a main node
100
     May contain additional framac eacsl targets
101
     2. Cmake : 2 files
102
         - lustrec-basename.cmake describing all variables
103
         - the main CMakeLists.txt activating the first file
104
     - Later option 1 should be removed
105
  *)
106
  (* Case 1 *)
107
  (match !Options.main_node with
108
  | "" ->  () (* No main node: we do not generate main *)
109
  | main_node -> (
110
    let makefile_file = destname ^ ".makefile" in (* Could be changed *)
111
    let makefile_out = open_out makefile_file in
112
    let makefile_fmt = formatter_of_out_channel makefile_out in
113
    
114
    (* Generating Makefile *)
115
    print_makefile basename main_node dependencies makefile_fmt;
116
    
117
    close_out makefile_out
118
  ))(* ; *)
119
  
120
  (* (\* Case 2 *\) *)
121
  (* let cmake_file = "lustrec-" ^ basename ^ ".cmake" in *)
122
  (* let cmake_file_full_path = !Options.dest_dir ^ "/" ^ cmake_file in *)
123
  (* let cmake_out = open_out cmake_file_full_path in *)
124
  (* let cmake_fmt = formatter_of_out_channel cmake_out in *)
125
  (* (\* Generating Makefile *\) *)
126
  (* print_cmake basename main_node dependencies makefile_fmt; *)
127
    
128
  (*   close_out makefile_out *)
129
  
130

    
131
let translate_to_c basename prog machines dependencies =
132
  match !Options.spec with
133
  | "no" -> begin
134
    let module HeaderMod = C_backend_header.EmptyMod in
135
    let module SourceMod = C_backend_src.EmptyMod in
136
    let module SourceMainMod = C_backend_main.EmptyMod in
137
    let module MakefileMod = C_backend_makefile.EmptyMod in
138

    
139
    let module Header = C_backend_header.Main (HeaderMod) in
140
    let module Source = C_backend_src.Main (SourceMod) in
141
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
142
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
143
    (* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
144
    
145
    let funs = 
146
      Header.print_alloc_header, 
147
      Source.print_lib_c, 
148
      SourceMain.print_main_c, 
149
      Makefile.print_makefile(* , *)
150
      (* CMakefile.print_makefile *)
151
    in
152
    gen_files funs basename prog machines dependencies 
153

    
154
  end
155
  | "acsl" -> begin
156

    
157
    let module HeaderMod = C_backend_header.EmptyMod in
158
    let module SourceMod = C_backend_src.EmptyMod in
159
    let module SourceMainMod = C_backend_main.EmptyMod in
160
    let module MakefileMod = C_backend_spec.MakefileMod in
161

    
162
    let module Header = C_backend_header.Main (HeaderMod) in
163
    let module Source = C_backend_src.Main (SourceMod) in
164
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
165
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
166
    (* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
167
    
168
    let funs = 
169
      Header.print_alloc_header, 
170
      Source.print_lib_c,
171
      SourceMain.print_main_c,
172
      Makefile.print_makefile(* , *)
173
      (* CMakefile.print_makefile  *)
174
    in
175
    gen_files funs basename prog machines dependencies 
176

    
177
  end
178
  | "c" -> begin
179
    assert false (* not implemented yet *)
180
  end
181
  | _ -> assert false
182
(* Local Variables: *)
183
(* compile-command:"make -C ../../.." *)
184
(* End: *)
(1-1/10)