Project

General

Profile

« Previous | Next » 

Revision d1b9423d

Added by David Doose almost 5 years ago

mauve generator: first shot

View differences:

include/arrow.hpp
2 2
#ifndef _ARROW_CPP
3 3
#define _ARROW_CPP
4 4

  
5
#include <stdint.h>
5 6
#include <stdlib.h>
6 7

  
7 8
struct _arrow_mem {
src/_tags
9 9
<*.ml{,i}>: package(ocamlgraph)
10 10
<*.ml{,i}>: use_str
11 11
<*.ml{,i}>: use_unix
12

  
src/backends/C/c_backend.ml
10 10
(********************************************************************)
11 11

  
12 12
open Format
13
open C_backend_mauve
13 14
(********************************************************************************************)
14 15
(*                         Translation function                                             *)
15 16
(********************************************************************************************)
......
65 66
    end
66 67
  ));
67 68

  
69
  (match !Options.mauve with
70
  | "" ->  ()
71
  | mauve -> (
72
    (* looking for the main node *)
73
    match Machine_code.get_machine_opt mauve machines with
74
    | None -> begin
75
      Global.main_node := mauve;
76
      Format.eprintf "Code generation error: %a@." Corelang.pp_error LustreSpec.Main_not_found;
77
      raise (Corelang.Error (Location.dummy_loc, LustreSpec.Main_not_found))
78
    end
79
    | Some m -> begin
80
      let source_mauve_file = destname ^ "_mauve.hpp" in
81
      let source_mauve_out = open_out source_mauve_file in
82
      let source_mauve_fmt = formatter_of_out_channel source_mauve_out in
83
      (* Header *)
84
      print_mauve_header source_mauve_fmt m basename prog machines dependencies;
85
      (* Shell *)
86
      print_mauve_shell source_mauve_fmt m basename prog machines dependencies;
87
      (* Core *)
88
      print_mauve_core source_mauve_fmt m basename prog machines dependencies;
89
      (* FSM *)
90
      print_mauve_fsm source_mauve_fmt m basename prog machines dependencies;
91

  
92
      close_out source_mauve_out;
93
    end
94
  ));
95

  
68 96

  
69 97
  (* Makefiles:
70 98
     - for the moment two cases
src/backends/C/c_backend_common.ml
125 125
  | _                                       -> false
126 126

  
127 127
let pp_c_basic_type_desc t_dsec =
128
  match (t_dsec) with
128
  match t_dsec with
129 129
  | Types.Tbool when !Options.cpp  -> "bool"
130 130
  | Types.Tbool                    -> "_Bool"
131 131
  | Types.Tint                     -> !Options.int_type
src/backends/C/c_backend_mauve.ml
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: *)
src/options.ml
55 55
let int_type  = ref "int"
56 56
let real_type = ref "double"
57 57

  
58
let mauve = ref ""
59

  
58 60
let sfunction = ref ""
59 61

  
60 62
let set_mpfr prec =
......
98 100
    "-c++" , Arg.Set        cpp      , "c++ backend";
99 101
    "-int" , Arg.Set_string int_type , "specifies the integer type (default=\"int\")";
100 102
    "-real", Arg.Set_string real_type, "specifies the real type (default=\"double\" without mpfr option)";
103

  
104
    "-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code";
101 105
]
102 106

  
103 107

  

Also available in: Unified diff