Project

General

Profile

Revision 9c654082

View differences:

src/tools/stateflow/common/basetypes.ml
122 122

  
123 123
  val pp_cond : Format.formatter -> t -> unit
124 124
end
125

  
126
  module Condition =
125
  
126
module Condition =
127 127
struct
128 128
  type t =
129 129
    | Quote of base_condition_t
......
155 155
end
156 156

  
157 157
let _ = (module Condition : ConditionType)
158

  
159
module GlobalVarDef =
160
struct
161
  type t = {variable: LustreSpec.var_decl; init_val: LustreSpec.expr}
162
end
src/tools/stateflow/common/datatype.ml
39 39
  | Junction of junction_name_t * transitions_t
40 40
  | SFFunction of 'prog_t
41 41

  
42
type prog_t = Program of state_name_t * prog_t src_components_t list * LustreSpec.var_decl list
42
type prog_t = Program of state_name_t * prog_t src_components_t list * (LustreSpec.var_decl * LustreSpec.expr) list
43 43

  
44 44
type scope_t = Constant | Input | Local | Output | Parameter
45 45

  
......
159 159
    Format.fprintf fmt "Main node name: %s@ %a@ %a@"
160 160
      name
161 161
      (pp_src pp_sffunction) component_list
162
      pp_vars vars
162
      pp_vars (List.map fst vars)
163 163

  
164 164
  let pp_scope fmt src =
165 165
    Format.fprintf fmt (match src with
src/tools/stateflow/json-parser/main_parse_json_file.ml
129 129
    end) in
130 130
    let module Sem = CPS.Semantics (T) (Model) in
131 131
    let prog = Sem.code_gen modularmode in
132
    let header = List.map Corelang.mktop [
133
      (LustreSpec.Open (false,"lustrec_math"));
134
      (LustreSpec.Open (false,"conv"));
135
      (LustreSpec.Open (true,"locallib"));
136
    ]
137
    in
138
    let prog =header@prog in
132 139
    Options.print_dec_types := true;
133
    Format.printf "%a@." Printers.pp_prog prog;
140
    (* Format.printf "%a@." Printers.pp_prog prog; *)
134 141

  
135 142
    let auto_file = "sf_gen_test_auto.lus" in (* Could be changed *)
136 143
    let auto_out = open_out auto_file in
137 144
    let auto_fmt = Format.formatter_of_out_channel auto_out in
138 145
    Format.fprintf auto_fmt "%a@." Printers.pp_prog prog;
139

  
140
    let prog = (LustreSpec.Open ("math",false))::prog
146
    Format.eprintf "Print initial lustre model with automaton in sf_gen_test_auto.lus@.";
147
    
141 148
    let prog, deps = Compiler_stages.stage1 prog "" "" in
142 149

  
143
    Format.printf "%a@." Printers.pp_prog prog;
150
    (* Format.printf "%a@." Printers.pp_prog prog; *)
144 151
    let noauto_file = "sf_gen_test_noauto.lus" in (* Could be changed *)
145 152
    let noauto_out = open_out noauto_file in
146 153
    let noauto_fmt = Format.formatter_of_out_channel noauto_out in
147
    Format.fprintf noauto_fmt "%a@." Printers.pp_prog prog
148

  
149

  
150
      
154
    Format.fprintf noauto_fmt "%a@." Printers.pp_prog prog;
155
    Format.eprintf "Print expanded lustre model in sf_gen_test_noauto.lus@.";
156
    ()
151 157

  
152 158
  with Parse.Error (l, err) -> Format.eprintf "Parse error at loc %a : %a@.@?" Location.pp_loc l Parse.pp_error err
153 159

  
src/tools/stateflow/models/model_simple.ml
3 3

  
4 4
let name = "simple"
5 5

  
6
  let condition x = condition (Corelang.mkexpr Location.dummy_loc (LustreSpec.Expr_const (Corelang.const_of_bool true)))
6
let condition x = condition {
7
  expr = Corelang.mkexpr Location.dummy_loc (LustreSpec.Expr_const (Corelang.const_of_bool true));
8
  cinputs = [];
9
  coutputs = [];
10
  cvariables = [];
11
}
12
  
7 13
  let action _ = no_action
8 14

  
9 15
let model : prog_t =
src/tools/stateflow/models/model_stopwatch.ml
5 5
let verbose = false
6 6
let actionv x = no_action (*TODO if verbose then action x else no_action*)
7 7
let action x = no_action (* TODO *)
8
let condition x = condition (Corelang.mkexpr Location.dummy_loc (LustreSpec.Expr_const (Corelang.const_of_bool true)))
9

  
8
let condition x = condition {
9
  expr = Corelang.mkexpr Location.dummy_loc (LustreSpec.Expr_const (Corelang.const_of_bool true));
10
  cinputs = [];
11
  coutputs = [];
12
  cvariables = [];
13
}
10 14
let name = "stopwatch"
11 15

  
12 16
let model =
......
250 254
	 int_typ, (* type *)
251 255
	 Corelang.dummy_clock_dec, (* clock *)
252 256
	 false, (* not a constant *)
253
	 None (* no default value *)
254
	)
257
	 None, (* no default value *)
258
	 None (* no parent known *)
259
	),
260
      (* Default value is zero *)
261
      Corelang.mkexpr Location.dummy_loc (LustreSpec.Expr_const (LustreSpec.Const_int 0))
262
      
255 263
    )
256 264
      ["cent";
257 265
       "sec";
src/tools/stateflow/semantics/cPS.ml
8 8

  
9 9
module Prog =
10 10
struct
11
  let init, defs, state_vars =
11
  let init, defs, state_vars, globals =
12 12
    let Program (init, defs, globals) = M.model in
13 13
    let state_vars = SF.states M.model in
14
    init, defs, state_vars
14
    init, defs, state_vars, globals
15 15

  
16 16
(*let _ = Format.printf "Model definitions@.%a@.####" Simulink.pp_src defs; () *)
17 17
end
src/tools/stateflow/semantics/cPS_lustre_generator.ml
7 7
module LustrePrinter (
8 8
  Vars : sig
9 9
    val state_vars : ActiveStates.Vars.t
10
    val global_vars : LustreSpec.var_decl list
10
    val global_vars : GlobalVarDef.t list
11

  
11 12
  end) : TransformerType =
12 13
struct
13 14
  include TransformerStub
......
53 54
    let loc = Location.dummy_loc in
54 55
    Corelang.mkvar_decl
55 56
      loc
56
      (name, typ, Corelang.mkclock loc LustreSpec.Ckdec_any, false, None)
57
      (name, typ, Corelang.mkclock loc LustreSpec.Ckdec_any, false, None, None (*"__no_parent__" *))
57 58

  
58 59
  let var_to_vdecl ?(prefix="") var typ = mkvar (var_to_ident prefix var) typ 
59 60
  let state_vars_to_vdecl_list ?(prefix="") vars =
......
115 116
    LustreSpec.ty_dec_loc = Location.dummy_loc;
116 117
  }
117 118
    
118
  let event_var = mkvar "event" event_type
119
  let event_var = mkvar "event" event_type 
119 120

  
120 121

  
121 122
  let const_map : (event_base_t, int) Hashtbl.t = Hashtbl.create 13
......
327 328
	let (vars', tr') = tr "sin_" "sout_" in
328 329
	pp_name call args;
329 330
	let funname = Format.flush_str_formatter () in
331
	let inputs = event_var :: state_vars_to_vdecl_list ~prefix:"sin_" Vars.state_vars in
332
	let outputs = state_vars_to_vdecl_list ~prefix:"sout_" Vars.state_vars in
330 333
	let node =
331 334
	  Corelang.mktop (	
332 335
	    LustreSpec.Node {LustreSpec.node_id = funname;
333 336
			   node_type = Types.new_var ();
334 337
			   node_clock = Clocks.new_var true;
335
			   node_inputs = event_var :: state_vars_to_vdecl_list ~prefix:"sin_" Vars.state_vars;
336
			   node_outputs = state_vars_to_vdecl_list ~prefix:"sout_" Vars.state_vars;
338
			   node_inputs = inputs;
339
			   node_outputs = outputs;
337 340
			   node_locals = mk_locals vars'; (* TODO: add global vars *)
338 341
			   node_gencalls = [];
339 342
			   node_checks = [];
......
346 349
      )  
347 350
	in
348 351
	[node]
352

  
353

  
354

  
355
	  (* TODO
356
	     C'est pas evident. 
357
Il faut faire les choses suivantes:
358
- rajouter dans un ensemble les variables manipulées localement
359
- on doit comprendre comment les variables globales sont injectées dans le modele final:
360
   - le node principal doit uniquement les afficher. Il peut les initialiser avec les valeurs init définies. Puis appeller la fcn thetacallD_from_principal.
361
   - elles peuvent/doivent etre dans input et output de ce node thetacallD
362
	  *)
363

  
349 364
	  
350 365
  let mk_main_loop () =
351 366
    (* let loc = Location.dummy_loc in *)
352 367
    
353 368
    let call_stmt =
354 369
      (* (%t) -> pre (thetaCallD_from_principal (event, %a)) *)
355
      let init = mkexpr
356
	(LustreSpec.Expr_tuple (List.map (fun _ -> expr_of_bool false) (ActiveStates.Vars.elements Vars.state_vars)))
370
      let init =
371
	let init_state_false =
372
	  List.map (fun _ -> expr_of_bool false) (ActiveStates.Vars.elements Vars.state_vars) in
373
	let init_globals =
374
	  List.map (fun v -> v.GlobalVarDef.init_val) Vars.global_vars in
375
	mkexpr (LustreSpec.Expr_tuple (init_state_false @ init_globals))
357 376
      in
358 377
      let args = (Corelang.expr_of_vdecl event_var)::
359 378
	(vars_to_exprl ~prefix:"sout_" Vars.state_vars)
......
363 382
      let rhs = mkexpr (LustreSpec.Expr_arrow (init, pre_call_expr)) in
364 383
      mkstmt_eq Vars.state_vars ~prefix_lhs:"sout_" rhs
365 384
    in
385
    let inputs = List.map Corelang.copy_var_decl [event_var] in
386
    let outputs = state_vars_to_vdecl_list ~prefix:"sout_" Vars.state_vars in
387
    (* TODO add the globals as sout_data_x entry values *)
366 388
    let node_principal =
367 389
      Corelang.mktop (	
368 390
	LustreSpec.Node {LustreSpec.node_id = "principal_loop";
369 391
			 node_type = Types.new_var ();
370 392
			 node_clock = Clocks.new_var true;
371
			 node_inputs = List.map Corelang.copy_var_decl [event_var];
372
			 node_outputs = state_vars_to_vdecl_list ~prefix:"sout_" Vars.state_vars;
393
			 node_inputs = inputs;
394
			 node_outputs = outputs;
373 395
			 node_locals = []; (* TODO: add global vars *)
374 396
			 node_gencalls = [];
375 397
			 node_checks = [];
......
381 403
			 node_annot = []}
382 404
      )  
383 405
    in
384
      node_principal
406
    node_principal
385 407
    
386 408

  
387 409
  let mkprincipal tr =
src/tools/stateflow/sf_sem.ml
63 63
  | GenLus ->
64 64
     let module Model = (val model) in
65 65
     let state_vars = Datatype.SF.states Model.model in
66
     let global_vars = Datatype.SF.global_vars Model.model in
66
     let global_vars =
67
       List.map (fun (v,e) -> {Basetypes.GlobalVarDef.variable = v; init_val = e;})
68
	 (Datatype.SF.global_vars Model.model) in
67 69
     
68 70
     let module T = CPS_lustre_generator.LustrePrinter (struct
69 71
       let state_vars = state_vars

Also available in: Unified diff