Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / C / c_backend.ml @ 01d48bb0

History | View | Annotate | Download (4.67 KB)

1 b38ffff3 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 0cbf0839 ploc
12 e95470b3 ploc
open Format
13 0cbf0839 ploc
(********************************************************************************************)
14
(*                         Translation function                                             *)
15
(********************************************************************************************)
16 70e1006b xthirioux
(* USELESS
17 e95470b3 ploc
let makefile_opt print basename dependencies makefile_fmt machines =
18
  (* If a main node is identified, generate a main target for it *)
19
  match !Options.main_node with
20
  | "" ->  ()
21
  | main_node -> (
22
    match Machine_code.get_machine_opt main_node machines with
23
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; ()
24
    | Some _ -> print basename !Options.main_node dependencies makefile_fmt
25
  )
26 70e1006b xthirioux
*)
27 e95470b3 ploc
28
let gen_files funs basename prog machines dependencies header_file source_lib_file source_main_file makefile_file machines =
29 01d48bb0 xthirioux
30 e95470b3 ploc
  let header_out = open_out header_file in
31
  let header_fmt = formatter_of_out_channel header_out in
32
  let source_lib_out = open_out source_lib_file in
33
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
34 01d48bb0 xthirioux
35 e95470b3 ploc
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
36
  (* Generating H file *)
37 70e1006b xthirioux
  print_header header_fmt basename prog machines dependencies;
38 01d48bb0 xthirioux
 
39 e95470b3 ploc
  (* Generating Lib C file *)
40
  print_lib_c source_lib_fmt basename prog machines dependencies;
41 01d48bb0 xthirioux
 
42 70e1006b xthirioux
  close_out header_out;
43
  close_out source_lib_out;
44
45 e95470b3 ploc
  match !Options.main_node with
46
  | "" ->  () (* No main node: we do not genenrate main nor makefile *)
47
  | main_node -> (
48
    match Machine_code.get_machine_opt main_node machines with
49
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; assert false
50
    | Some m -> begin
51
      let source_main_out = open_out source_main_file in
52
      let source_main_fmt = formatter_of_out_channel source_main_out in
53
      let makefile_out = open_out makefile_file in
54
      let makefile_fmt = formatter_of_out_channel makefile_out in
55 d2be420e ploc
56 e95470b3 ploc
      (* Generating Main C file *)
57
      print_main_c source_main_fmt m basename prog machines dependencies;
58
      
59
      (* Generating Makefile *)
60 70e1006b xthirioux
     print_makefile basename main_node dependencies makefile_fmt;
61
62
     close_out source_main_out;
63
     close_out makefile_out
64
65 e95470b3 ploc
    end
66
  )
67 713176a4 ploc
68 01d48bb0 xthirioux
let translate_to_c header source_lib source_main makefile basename prog machines dependencies =
69 e95470b3 ploc
  match !Options.spec with
70
  | "no" -> begin
71
    let module HeaderMod = C_backend_header.EmptyMod in
72
    let module SourceMod = C_backend_src.EmptyMod in
73
    let module SourceMainMod = C_backend_main.EmptyMod in
74
    let module MakefileMod = C_backend_makefile.EmptyMod in
75 713176a4 ploc
76 e95470b3 ploc
    let module Header = C_backend_header.Main (HeaderMod) in
77
    let module Source = C_backend_src.Main (SourceMod) in
78
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
79
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
80 01d48bb0 xthirioux
81 830de634 ploc
    let funs = 
82
      Header.print_alloc_header, 
83
      Source.print_lib_c, 
84
      SourceMain.print_main_c, 
85
      Makefile.print_makefile 
86
    in
87
    gen_files 
88
      funs basename prog machines dependencies 
89
      header source_lib source_main makefile machines
90 713176a4 ploc
91 e95470b3 ploc
  end
92
  | "acsl" -> begin
93 d2be420e ploc
94 e95470b3 ploc
    let module HeaderMod = C_backend_header.EmptyMod in
95
    let module SourceMod = C_backend_src.EmptyMod in
96
    let module SourceMainMod = C_backend_main.EmptyMod in
97
    let module MakefileMod = C_backend_spec.MakefileMod in
98 0cbf0839 ploc
99 e95470b3 ploc
    let module Header = C_backend_header.Main (HeaderMod) in
100
    let module Source = C_backend_src.Main (SourceMod) in
101
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
102
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
103 01d48bb0 xthirioux
104 830de634 ploc
    let funs = 
105
      Header.print_alloc_header, 
106
      Source.print_lib_c,
107
      SourceMain.print_main_c,
108
      Makefile.print_makefile 
109
    in
110
    gen_files
111
      funs basename prog machines dependencies
112
      header source_lib source_main makefile machines
113 0cbf0839 ploc
114 e95470b3 ploc
  end
115
  | "c" -> begin
116
    assert false (* not implemented yet *)
117
  end
118
  | _ -> assert false
119 0cbf0839 ploc
(* Local Variables: *)
120 522938b5 ploc
(* compile-command:"make -C ../../.." *)
121 0cbf0839 ploc
(* End: *)