Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.89 KB)

1
(* ----------------------------------------------------------------------------
2
 * SchedMCore - A MultiCore Scheduling Framework
3
 * Copyright (C) 2009-2013, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE
4
 * Copyright (C) 2012-2013, INPT, Toulouse, FRANCE
5
 *
6
 * This file is part of Prelude
7
 *
8
 * Prelude is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public License
10
 * as published by the Free Software Foundation ; either version 2 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * Prelude is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY ; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this program ; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
 * USA
22
 *---------------------------------------------------------------------------- *)
23

    
24
(* This module is used for the lustre to C compiler *)
25

    
26
open Format
27
(********************************************************************************************)
28
(*                         Translation function                                             *)
29
(********************************************************************************************)
30

    
31
let makefile_opt print basename dependencies makefile_fmt machines =
32
  (* If a main node is identified, generate a main target for it *)
33
  match !Options.main_node with
34
  | "" ->  ()
35
  | main_node -> (
36
    match Machine_code.get_machine_opt main_node machines with
37
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; ()
38
    | Some _ -> print basename !Options.main_node dependencies makefile_fmt
39
  )
40

    
41

    
42
let gen_files funs basename prog machines dependencies header_file source_lib_file source_main_file makefile_file machines =
43
  let header_out = open_out header_file in
44
  let header_fmt = formatter_of_out_channel header_out in
45
  let source_lib_out = open_out source_lib_file in
46
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
47
  
48
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
49
  (* Generating H file *)
50
  print_header header_fmt basename prog machines;
51
  
52
  (* Generating Lib C file *)
53
  print_lib_c source_lib_fmt basename prog machines dependencies;
54

    
55
  match !Options.main_node with
56
  | "" ->  () (* No main node: we do not genenrate main nor makefile *)
57
  | main_node -> (
58
    match Machine_code.get_machine_opt main_node machines with
59
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; assert false
60
    | Some m -> begin
61
      let source_main_out = open_out source_main_file in
62
      let source_main_fmt = formatter_of_out_channel source_main_out in
63
      let makefile_out = open_out makefile_file in
64
      let makefile_fmt = formatter_of_out_channel makefile_out in
65

    
66
      (* Generating Main C file *)
67
      print_main_c source_main_fmt m basename prog machines dependencies;
68
      
69
      (* Generating Makefile *)
70
     print_makefile basename main_node dependencies makefile_fmt
71
    end
72
  )
73
    
74

    
75

    
76
let translate_to_c header source_lib source_main makefile basename prog machines dependencies =
77

    
78
  match !Options.spec with
79
  | "no" -> begin
80
    let module HeaderMod = C_backend_header.EmptyMod in
81
    let module SourceMod = C_backend_src.EmptyMod in
82
    let module SourceMainMod = C_backend_main.EmptyMod in
83
    let module MakefileMod = C_backend_makefile.EmptyMod in
84

    
85
    let module Header = C_backend_header.Main (HeaderMod) in
86
    let module Source = C_backend_src.Main (SourceMod) in
87
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
88
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
89
        
90
    let funs = Header.print_header, Source.print_lib_c, SourceMain.print_main_c, Makefile.print_makefile in
91
    gen_files funs basename prog machines dependencies header source_lib source_main makefile machines
92

    
93
  end
94
  | "acsl" -> begin
95

    
96
    let module HeaderMod = C_backend_header.EmptyMod in
97
    let module SourceMod = C_backend_src.EmptyMod in
98
    let module SourceMainMod = C_backend_main.EmptyMod in
99
    let module MakefileMod = C_backend_spec.MakefileMod in
100

    
101
    let module Header = C_backend_header.Main (HeaderMod) in
102
    let module Source = C_backend_src.Main (SourceMod) in
103
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
104
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
105
        
106
    let funs = Header.print_header, Source.print_lib_c, SourceMain.print_main_c, Makefile.print_makefile in
107
    gen_files funs basename prog machines dependencies header source_lib source_main makefile machines
108

    
109
  end
110
  | "c" -> begin
111
    assert false (* not implemented yet *)
112
  end
113
  | _ -> assert false
114
(* Local Variables: *)
115
(* compile-command:"make -C ../../.." *)
116
(* End: *)