lustrec / src / tools / stateflow / sf_sem.ml @ 93119c3f
History  View  Annotate  Download (2.42 KB)
1  

2 

3 
type backend = GenLus  GenImp 
4  
5 
(* Model choice *) 
6 
let model_name = ref "stopwatch" (*"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 
"model", Arg.String set_model, "model in {simple, stopwatch} (default: simple)"; 
33 
(* "eval", Arg.Int set_trace_run_mode, "execute the model on trace <int>"; *) 
34 
(* "evalmode", Arg.String set_eval_mode, "select evaluator: cps"; *) 
35 
"gen_c", Arg.Unit (fun _ > set_mode GenImp), "generate imperative code"; 
36 
"gen_lustre", Arg.Unit (fun _ > set_mode GenLus), "generate lustre model"; 
37 
"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)" 
38 
] 
39  
40 
let usage = 
41 
"lustresf [JSON file] takes as input a stateflow model in the JSON format and a backend.\n"^ 
42 
"Backends are eother the C code generator or the lustre code generator." 
43  
44 

45 
let _ = 
46 
Arg.parse options (fun _ > ()) usage; 
47 
let model = List.find (fun m > get_model_name m = !model_name) models in 
48 
let modularmode = 
49 
match !modular with 
50 
 2 > true, true, true 
51 
 1 > false, true, false 
52 
 _ (* 0 *) > false, false ,false 
53 
in 
54 
match !mode with 
55 
 GenImp > ( 
56 
let module Model = (val model) in 
57 
let module T = CPS_ccode_generator.CodeGenerator in 
58 
let module Sem = CPS.Semantics (T) (Model) in 
59 
Sem.code_gen Format.std_formatter modularmode 
60 
) 
61 
 GenLus > 
62 
let module Model = (val model) in 
63 
let state_vars = Datatype.SF.states Model.model in 
64 
let global_vars = Datatype.SF.global_vars Model.model in 
65 

66 
let module T = CPS_lustre_generator.LustrePrinter (struct 
67 
let state_vars = state_vars 
68 
let global_vars = global_vars 
69 
end) in 
70 
let module Sem = CPS.Semantics (T) (Model) in 
71 
Sem.code_gen Format.std_formatter modularmode 
72  
73  
74 
