Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / lusic.ml @ 9603460e

History | View | Annotate | Download (2.62 KB)

1

    
2
(********************************************************************)
3
(*                                                                  *)
4
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
5
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
6
(*                                                                  *)
7
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
8
(*  under the terms of the GNU Lesser General Public License        *)
9
(*  version 2.1.                                                    *)
10
(*                                                                  *)
11
(********************************************************************)
12

    
13
open Format 
14
open LustreSpec
15
open Corelang
16

    
17
(********************************************************************************************)
18
(*                      Lusic to/from Header Printing functions                             *)
19
(********************************************************************************************)
20

    
21
type lusic =
22
{ from_lusi : bool;
23
  contents  : top_decl list;
24
}
25

    
26
module HeaderMod = C_backend_header.EmptyMod
27
module Header = C_backend_header.Main (HeaderMod)
28

    
29
(* extracts a header from a program representing module own *)
30
let extract_header own prog =
31
 List.fold_right
32
   (fun decl header ->
33
     if decl.top_decl_itf || decl.top_decl_owner <> own then header else
34
    match decl.top_decl_desc with
35
    | Node nd        -> { decl with top_decl_desc = ImportedNode (Corelang.get_node_interface nd) } :: header 
36
    | ImportedNode _ -> header
37
    | Const _
38
    | TypeDef _
39
    | Open _         -> decl :: header)
40
   prog []
41

    
42
(* encode and write a header in a file *)
43
let write_lusic lusi (header : top_decl list) basename extension =
44
  let target_name = basename ^ extension in
45
  let outchan = open_out_bin target_name in
46
  begin
47
    Marshal.to_channel outchan {from_lusi = lusi; contents = header} [];
48
    close_out outchan
49
  end
50

    
51
(* read and decode a header from a file *)
52
let read_lusic basename extension =
53
  let source_name = basename ^ extension in
54
  let inchan = open_in_bin source_name in
55
  let lusic = (Marshal.from_channel inchan : lusic) in
56
  begin
57
    close_in inchan;
58
    lusic
59
  end
60

    
61
let print_lusic_to_h basename extension =
62
  let lusic = read_lusic basename extension in
63
  let header_name = basename ^ ".h" in
64
  let h_out = open_out header_name in
65
  let h_fmt = formatter_of_out_channel h_out in
66
  begin
67
    Typing.uneval_prog_generics lusic.contents;
68
    Clock_calculus.uneval_prog_generics lusic.contents;
69
    Header.print_header_from_header h_fmt (Filename.basename basename) lusic.contents;
70
    close_out h_out
71
  end
72

    
73