Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / lusic.ml @ 6efbcb73

History | View | Annotate | Download (2.79 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 owner = dirname/basename *)
30
let extract_header dirname basename prog =
31
  let owner = dirname ^ "/" ^ basename in
32
 List.fold_right
33
   (fun decl header ->
34
(*Format.eprintf "Lusic.extract_header: owner = %s decl_owner = %s@." owner decl.top_decl_owner;*)
35
     if decl.top_decl_itf || decl.top_decl_owner <> owner then header else
36
    match decl.top_decl_desc with
37
    | Node nd        -> { decl with top_decl_desc = ImportedNode (Corelang.get_node_interface nd) } :: header 
38
    | ImportedNode _ -> header
39
    | Const _
40
    | TypeDef _
41
    | Open _         -> decl :: header)
42
   prog []
43

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

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

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

    
75