Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / C / c_backend.ml @ ef34b4ae

History | View | Annotate | Download (4.59 KB)

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 22fe1c93 ploc
(********************************************************************************************)
14
(*                         Translation function                                             *)
15
(********************************************************************************************)
16 ef34b4ae xthirioux
(* USELESS
17 d4107cf2 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 ef34b4ae xthirioux
*)
27 d4107cf2 ploc
28
let gen_files funs basename prog machines dependencies header_file source_lib_file source_main_file makefile_file machines =
29
  let header_out = open_out header_file in
30
  let header_fmt = formatter_of_out_channel header_out in
31
  let source_lib_out = open_out source_lib_file in
32
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
33
  
34
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
35
  (* Generating H file *)
36 ef34b4ae xthirioux
  print_header header_fmt basename prog machines dependencies;
37 d4107cf2 ploc
  
38
  (* Generating Lib C file *)
39
  print_lib_c source_lib_fmt basename prog machines dependencies;
40 cefc3744 ploc
41 ef34b4ae xthirioux
  close_out header_out;
42
  close_out source_lib_out;
43
44 d4107cf2 ploc
  match !Options.main_node with
45
  | "" ->  () (* No main node: we do not genenrate main nor makefile *)
46
  | main_node -> (
47
    match Machine_code.get_machine_opt main_node machines with
48
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; assert false
49
    | Some m -> begin
50
      let source_main_out = open_out source_main_file in
51
      let source_main_fmt = formatter_of_out_channel source_main_out in
52
      let makefile_out = open_out makefile_file in
53
      let makefile_fmt = formatter_of_out_channel makefile_out in
54 13eb21df ploc
55 d4107cf2 ploc
      (* Generating Main C file *)
56
      print_main_c source_main_fmt m basename prog machines dependencies;
57
      
58
      (* Generating Makefile *)
59 ef34b4ae xthirioux
     print_makefile basename main_node dependencies makefile_fmt;
60
61
     close_out source_main_out;
62
     close_out makefile_out
63
64 d4107cf2 ploc
    end
65
  )
66 cefc3744 ploc
67 d4107cf2 ploc
let translate_to_c header source_lib source_main makefile basename prog machines dependencies =
68 cefc3744 ploc
69 d4107cf2 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 cefc3744 ploc
76 d4107cf2 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
        
81 ef34b4ae xthirioux
    let funs = Header.print_alloc_header, Source.print_lib_c, SourceMain.print_main_c, Makefile.print_makefile in
82 d4107cf2 ploc
    gen_files funs basename prog machines dependencies header source_lib source_main makefile machines
83 cefc3744 ploc
84 d4107cf2 ploc
  end
85
  | "acsl" -> begin
86 13eb21df ploc
87 d4107cf2 ploc
    let module HeaderMod = C_backend_header.EmptyMod in
88
    let module SourceMod = C_backend_src.EmptyMod in
89
    let module SourceMainMod = C_backend_main.EmptyMod in
90
    let module MakefileMod = C_backend_spec.MakefileMod in
91 22fe1c93 ploc
92 d4107cf2 ploc
    let module Header = C_backend_header.Main (HeaderMod) in
93
    let module Source = C_backend_src.Main (SourceMod) in
94
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
95
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
96
        
97 ef34b4ae xthirioux
    let funs = Header.print_alloc_header, Source.print_lib_c, SourceMain.print_main_c, Makefile.print_makefile in
98 d4107cf2 ploc
    gen_files funs basename prog machines dependencies header source_lib source_main makefile machines
99 22fe1c93 ploc
100 d4107cf2 ploc
  end
101
  | "c" -> begin
102
    assert false (* not implemented yet *)
103
  end
104
  | _ -> assert false
105 22fe1c93 ploc
(* Local Variables: *)
106 cd670fe1 ploc
(* compile-command:"make -C ../../.." *)
107 22fe1c93 ploc
(* End: *)