Project

General

Profile

Download (5.7 KB) Statistics
| Branch: | Tag: | Revision:
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
open LustreSpec
28
open Machine_code
29
(********************************************************************************************)
30
(*                         Translation function                                             *)
31
(********************************************************************************************)
32

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

    
43
module type MODIFIER = sig
44
    module HdrMod : C_backend_header.MODIFIERS_HDR
45
    module SrcMod : C_backend_src.MODIFIERS_SRC
46
    module MainMod : C_backend_main.MODIFIERS_MAINSRC
47
    module MakefileMod : C_backend_makefile.MODIFIERS_MKF
48
    module CoqMod : C_backend_coq.MODIFIERS_COQ
49
    
50
    val init : machine_t list -> unit
51
end
52

    
53
module EmptyMod = struct
54
    module HdrMod = C_backend_header.EmptyMod
55
    module SrcMod = C_backend_src.EmptyMod
56
    module MainMod = C_backend_main.EmptyMod
57
    module MakefileMod = C_backend_makefile.EmptyMod
58
    module CoqMod = C_backend_coq.EmptyMod
59

    
60
    let init machines = ()
61
end
62

    
63
module Backend = functor (Mod:MODIFIER) ->
64
struct
65
    module Header = C_backend_header.Main (Mod.HdrMod)
66
    module Source = C_backend_src.Main (Mod.SrcMod)
67
    module SourceMain = C_backend_main.Main (Mod.MainMod)
68
    module Makefile = C_backend_makefile.Main (Mod.MakefileMod)
69
    module Coq = C_backend_coq.Main (Mod.CoqMod)
70

    
71
    let gen_files basename prog machines dependencies header_file source_lib_file source_main_file makefile_file coq_file machines =
72
      Mod.init machines;
73
      
74
      let header_out = open_out header_file in
75
      let header_fmt = formatter_of_out_channel header_out in
76
      let source_lib_out = open_out source_lib_file in
77
      let source_lib_fmt = formatter_of_out_channel source_lib_out in
78
      
79
      (* Generating H file *)
80
      Header.print_header header_fmt basename prog machines;
81
      
82
      (* Generating Lib C file *)
83
      Source.print_lib_c source_lib_fmt basename prog machines dependencies;
84
      
85
      (match coq_file with
86
        | None -> ()
87
        | Some path ->
88
          let coq_lib_out = open_out path in
89
          let coq_lib_fmt = formatter_of_out_channel coq_lib_out in
90
          Coq.print_lib_coq coq_lib_fmt basename prog machines
91
      );
92
      match !Options.main_node with
93
      | "" ->  () (* No main node: we do not genenrate main nor makefile *)
94
      | main_node -> (
95
        match Machine_code.get_machine_opt main_node machines with
96
        | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; assert false
97
        | Some m -> begin
98
          let source_main_out = open_out source_main_file in
99
          let source_main_fmt = formatter_of_out_channel source_main_out in
100
          let makefile_out = open_out makefile_file in
101
          let makefile_fmt = formatter_of_out_channel makefile_out in
102

    
103
          (* Generating Main C file *)
104
          SourceMain.print_main_c source_main_fmt m basename prog machines dependencies;
105
          
106
          (* Generating Makefile *)
107
         Makefile.print_makefile basename main_node dependencies makefile_fmt
108
        end
109
      )
110
end
111

    
112
let translate_to_c header source_lib source_main makefile coq_file basename prog machines dependencies =
113
  Format.printf "%a" (Utils.fprintf_list ~sep:"\n@ " pp_machine) machines;
114
  let module SpecArg = struct 
115
    let prog = prog 
116
    let machines = arrow_machine::machines
117
  end in
118
  let module ProofArg = struct 
119
    let prog = prog 
120
    let machines = arrow_machine::machines
121
  end in
122
  let module SpecMod = C_backend_spec.Make (SpecArg) in
123
  let module ProofMod = C_backend_proof.Make (ProofArg) in
124
  
125
  match !Options.spec with
126
  | "no" -> begin
127
    let module B = Backend(EmptyMod) in
128
    B.gen_files basename prog machines dependencies header source_lib source_main makefile None machines
129
  end
130
  | "acsl" -> begin
131
    let module B = Backend(SpecMod) in
132
    B.gen_files basename prog machines dependencies header source_lib source_main makefile None machines
133
  end
134
  | "proof" -> begin
135
    let module B = Backend(ProofMod) in
136
    B.gen_files basename prog machines dependencies header source_lib source_main makefile (Some coq_file) machines
137
  end
138
  | "c" -> begin
139
    assert false (* not implemented yet *)
140
  end
141
  | _ -> assert false
142
(* Local Variables: *)
143
(* compile-command:"make -C ../../.." *)
144
(* End: *)
(1-1/9)