Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / stateflow / sf_sem.ml @ 9c654082

History | View | Annotate | Download (3.33 KB)

1

    
2
  
3
type backend = GenLus | GenImp
4

    
5
(* Model choice *)
6
let model_name = ref "simple"
7

    
8
let models = [(module Model_simple : Datatype.MODEL_T);
9
	      (module Model_stopwatch : Datatype.MODEL_T);
10
	     (*  (module Model_medium : Datatype.MODEL_T)*)
11
	     ]
12
let get_model_name m = let module M = (val m : Datatype.MODEL_T) in M.name
13
let set_model name = 
14
  if List.exists (fun n -> get_model_name n = name) models then
15
    model_name := name
16
  else failwith ("incorrect model name. Use " ^
17
		    (List.fold_left (fun r n -> r ^ " or " ^ get_model_name n) "" models))
18

    
19
(* Backend selection *)
20
let modular = ref 0
21
let set_modular i = modular := i
22

    
23
let mode = ref GenLus
24
  
25
     
26
let set_mode m =
27
  mode := m
28

    
29
(* Main *)
30
    
31
let options = [
32
  "-verbose", Arg.Set_int Options.verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>";
33
  "-model", Arg.String set_model, "model in {simple, stopwatch} (default: simple)";
34
  (* "-eval", Arg.Int set_trace_run_mode, "execute the model on trace <int>"; *)
35
  (* "-eval-mode", Arg.String set_eval_mode, "select evaluator: cps"; *)
36
  "-gen_c", Arg.Unit (fun _ -> set_mode GenImp), "generate imperative code";
37
  "-gen_lustre", Arg.Unit (fun _ -> set_mode GenLus), "generate lustre model";
38
  "-modular", Arg.Int set_modular, "generate modular code (either for imperative or lustre backend) 0 is not modular, 1 modularize nodes, 2 modularize entry, during and exit actions (default 0)"
39
]
40

    
41
let usage =
42
  "lustresf [JSON file] takes as input a stateflow model in the JSON format and a backend.\n"^
43
    "Backends are eother the C code generator or the lustre code generator."
44

    
45
    
46
let _ =
47
  Arg.parse options (fun _ -> ()) usage;
48
  let model = List.find (fun m -> get_model_name m = !model_name) models in
49
  let modularmode =
50
    match !modular with
51
    | 2 -> true, true, true
52
    | 1 -> false, true, false
53
    | _ (* 0 *) -> false, false ,false
54
  in
55
  match !mode with
56
  | GenImp -> (
57
    let module Model = (val model) in
58
    let module T = CPS_ccode_generator.CodeGenerator in
59
    let module Sem = CPS.Semantics (T) (Model) in
60
    let _ = Sem.code_gen modularmode in
61
    ()
62
  )				     
63
  | GenLus ->
64
     let module Model = (val model) in
65
     let state_vars = Datatype.SF.states 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
69
     
70
     let module T = CPS_lustre_generator.LustrePrinter (struct
71
       let state_vars = state_vars
72
       let global_vars = global_vars 
73
     end) in
74
     let module Sem = CPS.Semantics (T) (Model) in
75
     let prog = Sem.code_gen modularmode in
76
     Options.print_dec_types := true;
77
     Format.printf "%a@." Printers.pp_prog prog;
78

    
79
     let auto_file = "sf_gen_test_auto.lus" in (* Could be changed *)
80
     let auto_out = open_out auto_file in
81
     let auto_fmt = Format.formatter_of_out_channel auto_out in
82
     Format.fprintf auto_fmt "%a@." Printers.pp_prog prog;
83
     
84
     let prog, deps = Compiler_stages.stage1 prog "" "" in
85

    
86
     Format.printf "%a@." Printers.pp_prog prog;
87
     let noauto_file = "sf_gen_test_noauto.lus" in (* Could be changed *)
88
     let noauto_out = open_out noauto_file in
89
     let noauto_fmt = Format.formatter_of_out_channel noauto_out in
90
     Format.fprintf noauto_fmt "%a@." Printers.pp_prog prog
91

    
92

    
93
  
94
(* Local Variables: *)
95
(* compile-command: "make -C ../.. lustresf" *)
96
(* End: *)