Project

General

Profile

Download (5.31 KB) Statistics
| Branch: | Tag: | Revision:
1
open LustreSpec
2
open Corelang
3
open Machine_code
4
open Format
5
open C_backend_common
6
open Utils
7

    
8
(* module type MODIFIERS_MAINSRC =
9
sig
10
end
11

    
12
module EmptyMod =
13
struct
14
end
15

    
16
module Mauve = functor (Mod: MODIFIERS_MAINSRC) -> 
17
struct
18
end
19
 *)
20
(********************************************************************************************)
21
(*                         Main related functions                                           *)
22
(********************************************************************************************)
23

    
24
let mauve_default_value v =
25
  let v_name = v.var_id in
26
  let v_type = (Types.repr v.var_type).Types.tdesc in
27
  match v_type with
28
  | Types.Tbool -> "false"
29
  | Types.Tint  -> "0"
30
  | Types.Treal -> "0.0"
31
  | _ -> assert false
32

    
33
let shell_name node = node ^ "Shell"
34
let core_name  node = node ^ "Core"
35
let fsm_name   node = node ^ "FSM"
36

    
37
let print_mauve_header fmt mauve_machine basename prog machines _ (*dependencies*) =
38
  fprintf fmt "#include \"mauve/runtime.hpp\"@.";
39
  print_import_alloc_prototype fmt (Dep (true, basename, [], true (* assuming it is stateful*) ));
40
  pp_print_newline fmt ();
41
  pp_print_newline fmt ()
42

    
43

    
44
let print_mauve_shell fmt mauve_machine basename prog machines _ (*dependencies*) =
45
  let node_name = mauve_machine.mname.node_id in
46
  
47
  fprintf fmt "/*@.";
48
  fprintf fmt " *          SHELL@.";
49
  fprintf fmt " */@.";
50

    
51
  fprintf fmt "struct %s: public Shell {@." (shell_name node_name);
52

    
53
  (* in ports *)
54
  fprintf fmt "\t// InputPorts@.";
55
  List.iter
56
    (fun v ->
57
      let v_name = v.var_id in
58
      let v_type = pp_c_basic_type_desc (Types.repr v.var_type).Types.tdesc in
59
      let default = mauve_default_value v in
60
      fprintf fmt "\tReadPort<%s> port_%s = mk_readPort<%s>(\"%s\", %s);@." v_type v_name v_type v_name default;
61
    ) mauve_machine.mstep.step_inputs;
62
  (* out ports *)
63
  fprintf fmt "\t// OutputPorts@.";
64
  List.iter
65
    (fun v ->
66
      let v_name = v.var_id in
67
      let v_type = pp_c_basic_type_desc (Types.repr v.var_type).Types.tdesc in
68
      fprintf fmt "\tWritePort<%s> port_%s = mk_writePort<%s>(\"%s\");@." v_type v_name v_type v_name;
69
    ) mauve_machine.mstep.step_outputs;
70

    
71
  fprintf fmt "};@.";
72

    
73
  pp_print_newline fmt ()
74

    
75
let print_mauve_step fmt node_name mauve_machine =
76
  fprintf fmt "\t\t%s_step(" node_name;
77
  List.iter
78
    (fun v ->
79
      let v_name = v.var_id in
80
      fprintf fmt "%s, " v_name;
81
    ) mauve_machine.mstep.step_inputs;
82
  List.iter
83
    (fun v ->
84
      let v_name = v.var_id in
85
      fprintf fmt "&%s, " v_name;
86
    ) mauve_machine.mstep.step_outputs;
87
  fprintf fmt "node";
88
  fprintf fmt ");@."
89

    
90
let print_mauve_core fmt mauve_machine basename prog machines _ (*dependencies*) =
91
  let node_name = mauve_machine.mname.node_id in
92

    
93
  fprintf fmt "/*@.";
94
  fprintf fmt " *          CORE@.";
95
  fprintf fmt " */@.";
96

    
97
  fprintf fmt "struct %s: public Core<%s> {@." (core_name node_name) (shell_name node_name);
98

    
99
  (* Attribute *)
100
  fprintf fmt "\tstruct %s_mem * node;@." node_name;
101
  pp_print_newline fmt ();
102
  (* Update *)
103
  fprintf fmt "\tvoid update() {@.";
104
  List.iter
105
    (fun v ->
106
      let v_name = v.var_id in
107
      let v_type = pp_c_basic_type_desc (Types.repr v.var_type).Types.tdesc in
108
      fprintf fmt "\t\t%s %s = port_%s.read();@." v_type v_name v_name;
109
    ) mauve_machine.mstep.step_inputs;
110
  List.iter
111
    (fun v ->
112
      let v_name = v.var_id in
113
      let v_type = pp_c_basic_type_desc (Types.repr v.var_type).Types.tdesc in
114
      fprintf fmt "\t\t%s %s;@." v_type v_name;
115
    ) mauve_machine.mstep.step_outputs;
116
  print_mauve_step fmt node_name mauve_machine;
117
  List.iter
118
    (fun v ->
119
      let v_name = v.var_id in
120
      fprintf fmt "\t\tport_%s.write(%s);@." v_name v_name;
121
    ) mauve_machine.mstep.step_outputs;
122
  fprintf fmt "\t}@.";
123
  pp_print_newline fmt ();
124
  (* Configure *)
125
  fprintf fmt "\tbool configure_hook() override {@.";
126
  fprintf fmt "\t\tnode = %s_alloc();@." node_name;
127
  fprintf fmt "\t\t%s_reset(node);@." node_name;
128
  fprintf fmt "\t\treturn true;@.";
129
  fprintf fmt "\t}@.";
130
  pp_print_newline fmt ();
131
  (* Cleanup *)
132
  fprintf fmt "\tvoid cleanup_hook() override {@.";
133
  fprintf fmt "\t\t%s_reset(node);@." node_name;
134
  fprintf fmt "\t\tfree(node);@.";
135
  fprintf fmt "\t}@.";
136
  fprintf fmt "};@.";
137
  pp_print_newline fmt ()
138

    
139

    
140
let print_mauve_fsm fmt mauve_machine basename prog machines _ (*dependencies*) =
141
  let node_name = mauve_machine.mname.node_id in
142

    
143
  fprintf fmt "/*@.";
144
  fprintf fmt " *          FSM@.";
145
  fprintf fmt " */@.";
146

    
147
  fprintf fmt "struct %s: public FiniteStateMachine<%s, %s> {@." (fsm_name node_name) (shell_name node_name) (core_name node_name);
148

    
149
  (* Attribute *)
150
  fprintf fmt "\tExecState<%s>    & update  = mk_execution      (\"Update\" , &%s::update);@." (core_name node_name) (core_name node_name);
151
  fprintf fmt "\tSynchroState<%s> & synchro = mk_synchronization(\"Synchro\", ms_to_ns(100));@." (core_name node_name);
152
  pp_print_newline fmt ();
153
  (* Configure *)
154
  fprintf fmt "\tbool configure_hook() override {@.";
155
  fprintf fmt "\t\tset_initial(update);@.";
156
  fprintf fmt "\t\tset_next(update, synchro);@.";
157
  fprintf fmt "\t\tset_next(synchro, update);@.";
158
  fprintf fmt "\t\treturn true;@.";
159
  fprintf fmt "\t}@.";
160
  pp_print_newline fmt ();
161
  (* Cleanup *)
162
  fprintf fmt "\tvoid cleanup_hook() override {@.";
163
  fprintf fmt "\t}@.";
164
  fprintf fmt "};@.";
165
  pp_print_newline fmt ()
166

    
167
(* Local Variables: *)
168
(* compile-command:"make -C ../../.." *)
169
(* End: *)
(6-6/8)