lustrec / src / tools / stateflow / sf_sem.ml @ 74ca6b61
History  View  Annotate  Download (3.06 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 
"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 
let _ = Sem.code_gen modularmode in 
60 
() 
61 
) 
62 
 GenLus > 
63 
let module Model = (val model) in 
64 
let state_vars = Datatype.SF.states Model.model in 
65 
let global_vars = Datatype.SF.global_vars Model.model in 
66 

67 
let module T = CPS_lustre_generator.LustrePrinter (struct 
68 
let state_vars = state_vars 
69 
let global_vars = global_vars 
70 
end) in 
71 
let module Sem = CPS.Semantics (T) (Model) in 
72 
let prog = Sem.code_gen modularmode in 
73 
Options.print_dec_types := true; 
74 
Format.printf "%a@." Printers.pp_prog prog; 
75  
76 
let prog, deps = Main_lustre_compiler.stage1 prog "" "" in 
77  
78 

79 
(* (\* Importing source *\) *) 
80 
(* let _ = Modules.load_program Utils.ISet.empty prog in *) 
81  
82 
(* (\* Extracting dependencies *\) *) 
83 
(* let dependencies, type_env, clock_env = Compiler_common.import_dependencies prog in *) 
84  
85  
86 
(* (\* Typing *\) *) 
87 
(* let computed_types_env = Compiler_common.type_decls type_env prog in *) 
88 

89 
(* (\* Clock calculus *\) *) 
90 
(* let computed_clocks_env = Compiler_common.clock_decls clock_env prog in *) 
91  
92 
Format.printf "%a@." Printers.pp_prog prog 
93  
94  
95 
