1
|
open Datatype
|
2
|
open Basetypes
|
3
|
|
4
|
(* open Transformer2 *)
|
5
|
open SF
|
6
|
|
7
|
let verbose = false
|
8
|
|
9
|
let actionv _ = no_action
|
10
|
(*TODO if verbose then action x else no_action*)
|
11
|
|
12
|
let action _ = no_action
|
13
|
(* TODO *)
|
14
|
|
15
|
let condition _ =
|
16
|
condition
|
17
|
{
|
18
|
expr =
|
19
|
Corelang.mkexpr Location.dummy_loc
|
20
|
(Lustre_types.Expr_const (Corelang.const_of_bool true));
|
21
|
cinputs = [];
|
22
|
coutputs = [];
|
23
|
cvariables = [];
|
24
|
}
|
25
|
|
26
|
let name = "stopwatch"
|
27
|
|
28
|
let model =
|
29
|
let smain = "main" in
|
30
|
let sstop = "stop" in
|
31
|
let sreset = "reset" in
|
32
|
let slapstop = "lap_stop" in
|
33
|
let srun = "run" in
|
34
|
let srunning = "running" in
|
35
|
let slap = "lap" in
|
36
|
|
37
|
let tinitstop =
|
38
|
{
|
39
|
event = no_event;
|
40
|
condition = no_condition;
|
41
|
condition_act = actionv "ac_cond_init_stop";
|
42
|
transition_act = actionv "ac_trans_init_stop";
|
43
|
dest = DPath [ smain; sstop ];
|
44
|
}
|
45
|
in
|
46
|
let tinitreset =
|
47
|
{
|
48
|
event = no_event;
|
49
|
condition = no_condition;
|
50
|
condition_act = actionv "ac_cond_init_reset";
|
51
|
transition_act = actionv "ac_cond_init_stop";
|
52
|
dest = DPath [ smain; sstop; sreset ];
|
53
|
}
|
54
|
in
|
55
|
let treset =
|
56
|
{
|
57
|
event = event "LAP";
|
58
|
condition = no_condition;
|
59
|
condition_act = action "reset counter";
|
60
|
transition_act = actionv "ac_trans_reset_junction";
|
61
|
dest =
|
62
|
DJunction "jreset"
|
63
|
(* [smain;sstop;sreset]; ou bien mettre une junction. Verifier si il y a
|
64
|
des effets de bords non desirés de fermeture/ouverture de noeud *);
|
65
|
}
|
66
|
in
|
67
|
let treset_start =
|
68
|
{
|
69
|
event = event "START";
|
70
|
condition = no_condition;
|
71
|
condition_act = actionv "ac_cond_reset->running";
|
72
|
transition_act = actionv "ac_trans_reset->running";
|
73
|
dest = DPath [ smain; srun; srunning ];
|
74
|
}
|
75
|
in
|
76
|
|
77
|
let tlapstop_lap =
|
78
|
{
|
79
|
event = event "LAP";
|
80
|
condition = no_condition;
|
81
|
condition_act = actionv "ac_cond_lap_stop->reset";
|
82
|
transition_act = actionv "ac_trans_lap_stop->reset";
|
83
|
dest = DPath [ smain; sstop; sreset ];
|
84
|
}
|
85
|
in
|
86
|
|
87
|
let tlapstop_start =
|
88
|
{
|
89
|
event = event "START";
|
90
|
condition = no_condition;
|
91
|
condition_act = actionv "ac_cond_lap_stop->lap";
|
92
|
transition_act = actionv "ac_trans_lap_stop->lap";
|
93
|
dest = DPath [ smain; srun; slap ];
|
94
|
}
|
95
|
in
|
96
|
let ttic =
|
97
|
{
|
98
|
event = event "TIC";
|
99
|
condition = no_condition;
|
100
|
condition_act = action "cent+=1";
|
101
|
transition_act = actionv "ac_trans_->J1";
|
102
|
dest = DJunction "j1";
|
103
|
}
|
104
|
in
|
105
|
let trunning_start =
|
106
|
{
|
107
|
event = event "START";
|
108
|
condition = no_condition;
|
109
|
condition_act = actionv "ac_cond_running->reset";
|
110
|
transition_act = actionv "ac_trans_running->reset";
|
111
|
dest = DPath [ smain; sstop; sreset ];
|
112
|
}
|
113
|
in
|
114
|
let tlap_start =
|
115
|
{
|
116
|
event = event "START";
|
117
|
condition = no_condition;
|
118
|
condition_act = actionv "ac_cond_lap->lap_stop";
|
119
|
transition_act = actionv "ac_trans_lap->lap_stop";
|
120
|
dest = DPath [ smain; sstop; slapstop ];
|
121
|
}
|
122
|
in
|
123
|
let tlap_lap =
|
124
|
{
|
125
|
event = event "LAP";
|
126
|
condition = no_condition;
|
127
|
condition_act = actionv "ac_cond_lap->running";
|
128
|
transition_act = actionv "ac_trans_lap->running";
|
129
|
dest = DPath [ smain; srun; srunning ];
|
130
|
}
|
131
|
in
|
132
|
let trunning_lap =
|
133
|
{
|
134
|
event = event "LAP";
|
135
|
condition = no_condition;
|
136
|
condition_act = actionv "ac_cond_running->lap";
|
137
|
transition_act = actionv "ac_trans_running->lap";
|
138
|
dest = DPath [ smain; srun; slap ];
|
139
|
}
|
140
|
in
|
141
|
let tj1j2 =
|
142
|
{
|
143
|
event = no_event;
|
144
|
condition = condition "cent==100";
|
145
|
condition_act = action "cont=0;sec+=1";
|
146
|
transition_act = actionv "ac_trans_J1->J2";
|
147
|
dest = DJunction "j2";
|
148
|
}
|
149
|
in
|
150
|
let tj1j3 =
|
151
|
{
|
152
|
event = no_event;
|
153
|
condition = condition "cent!=100";
|
154
|
condition_act = actionv "ac_cond_J1->J3";
|
155
|
transition_act = actionv "ac_trans_J1->J3";
|
156
|
dest = DJunction "j3";
|
157
|
}
|
158
|
in
|
159
|
let tj2j3gauche =
|
160
|
{
|
161
|
event = no_event;
|
162
|
condition = condition "sec!=60";
|
163
|
condition_act = actionv "ac_cond_J2->J3_left";
|
164
|
transition_act = actionv "ac_trans_J2->J3_left";
|
165
|
dest = DJunction "j3";
|
166
|
}
|
167
|
in
|
168
|
let tj2j3droite =
|
169
|
{
|
170
|
event = no_event;
|
171
|
condition = condition "sec==60";
|
172
|
condition_act = action "sec=0; min+=1";
|
173
|
transition_act = actionv "ac_trans_J2->J3_right";
|
174
|
dest = (*DPath [smain;srun];*)
|
175
|
DJunction "j3";
|
176
|
}
|
177
|
in
|
178
|
let def_main =
|
179
|
{
|
180
|
state_actions =
|
181
|
{
|
182
|
entry_act = actionv "ac_main_entry";
|
183
|
during_act = actionv "ac_main_during";
|
184
|
exit_act = actionv "ac_main_exit";
|
185
|
};
|
186
|
outer_trans = [];
|
187
|
inner_trans = [];
|
188
|
internal_composition = Or ([ tinitstop ], [ sstop; srun ]);
|
189
|
}
|
190
|
in
|
191
|
|
192
|
let def_stop =
|
193
|
{
|
194
|
state_actions =
|
195
|
{
|
196
|
entry_act = actionv "ac_stop_entry";
|
197
|
during_act = actionv "ac_stop_during";
|
198
|
exit_act = actionv "ac_stop_exit";
|
199
|
};
|
200
|
outer_trans = [];
|
201
|
inner_trans = [];
|
202
|
internal_composition = Or ([ tinitreset ], [ sreset; slapstop ]);
|
203
|
}
|
204
|
in
|
205
|
|
206
|
let def_reset =
|
207
|
{
|
208
|
state_actions =
|
209
|
{
|
210
|
entry_act = actionv "ac_reset_entry";
|
211
|
during_act = actionv "ac_reset_during";
|
212
|
exit_act = actionv "ac_reset_exit";
|
213
|
};
|
214
|
outer_trans = [ treset_start ];
|
215
|
inner_trans = [ treset ];
|
216
|
internal_composition = Or ([ treset_start ], []);
|
217
|
}
|
218
|
in
|
219
|
|
220
|
let def_lapstop =
|
221
|
{
|
222
|
state_actions =
|
223
|
{
|
224
|
entry_act = actionv "ac_lapstop_entry";
|
225
|
during_act = actionv "ac_lapstop_during";
|
226
|
exit_act = actionv "ac_lapstop_exit";
|
227
|
};
|
228
|
outer_trans = [ tlapstop_lap; tlapstop_start ];
|
229
|
inner_trans = [];
|
230
|
internal_composition = Or ([], []);
|
231
|
}
|
232
|
in
|
233
|
|
234
|
let def_run =
|
235
|
{
|
236
|
state_actions =
|
237
|
{
|
238
|
entry_act = actionv "ac_run_entry";
|
239
|
during_act = actionv "ac_run_during";
|
240
|
exit_act = actionv "ac_run_exit";
|
241
|
};
|
242
|
outer_trans = [];
|
243
|
inner_trans = [ ttic ];
|
244
|
internal_composition = Or ([], [ srunning; slap ]);
|
245
|
}
|
246
|
in
|
247
|
|
248
|
let def_running =
|
249
|
{
|
250
|
state_actions =
|
251
|
{
|
252
|
entry_act = actionv "ac_running_entry";
|
253
|
during_act = action "disp=(cent,sec,min)";
|
254
|
exit_act = actionv "ac_running_exit";
|
255
|
};
|
256
|
outer_trans = [ trunning_start; trunning_lap ];
|
257
|
inner_trans = [];
|
258
|
internal_composition = Or ([], []);
|
259
|
}
|
260
|
in
|
261
|
|
262
|
let def_lap =
|
263
|
{
|
264
|
state_actions =
|
265
|
{
|
266
|
entry_act = actionv "ac_lap_entry";
|
267
|
during_act = actionv "ac_lap_during";
|
268
|
exit_act = actionv "ac_lap_exit";
|
269
|
};
|
270
|
outer_trans = [ tlap_start; tlap_lap ];
|
271
|
inner_trans = [];
|
272
|
internal_composition = Or ([], []);
|
273
|
}
|
274
|
in
|
275
|
|
276
|
let src =
|
277
|
[
|
278
|
State ([ smain; srun; srunning ], def_running);
|
279
|
State ([ smain; srun; slap ], def_lap);
|
280
|
State ([ smain; srun ], def_run);
|
281
|
State ([ smain; sstop; sreset ], def_reset);
|
282
|
State ([ smain; sstop; slapstop ], def_lapstop);
|
283
|
State ([ smain; sstop ], def_stop);
|
284
|
State ([ smain ], def_main);
|
285
|
Junction ("jreset", []);
|
286
|
Junction ("j1", [ tj1j2; tj1j3 ]);
|
287
|
Junction ("j2", [ tj2j3droite; tj2j3gauche ]);
|
288
|
Junction ("j3", []);
|
289
|
]
|
290
|
in
|
291
|
let globals =
|
292
|
let int_typ = Corelang.mktyp Location.dummy_loc Lustre_types.Tydec_int in
|
293
|
List.map
|
294
|
(fun k ->
|
295
|
( Corelang.mkvar_decl Location.dummy_loc
|
296
|
( k,
|
297
|
(* name *)
|
298
|
int_typ,
|
299
|
(* type *)
|
300
|
Corelang.dummy_clock_dec,
|
301
|
(* clock *)
|
302
|
false,
|
303
|
(* not a constant *)
|
304
|
None,
|
305
|
(* no default value *)
|
306
|
None (* no parent known *) ),
|
307
|
(* Default value is zero *)
|
308
|
Corelang.mkexpr Location.dummy_loc
|
309
|
(Lustre_types.Expr_const (Lustre_types.Const_int 0)) ))
|
310
|
[ "cent"; "sec"; "min"; "cont" ]
|
311
|
in
|
312
|
Program (smain, src, globals)
|
313
|
|
314
|
let traces : trace_t list =
|
315
|
[
|
316
|
[ None; Some "TIC"; Some "START"; Some "TIC"; Some "TIC" ];
|
317
|
[ None; Some "START"; Some "START"; Some "START" ];
|
318
|
[ None; Some "START"; Some "TIC"; Some "START"; Some "TIC" ];
|
319
|
]
|