1
|
open Basetypes
|
2
|
open Datatype
|
3
|
open CPS_transformer
|
4
|
open Theta
|
5
|
|
6
|
module Semantics = functor (T: TransformerType) (M: MODEL_T) ->
|
7
|
struct
|
8
|
|
9
|
module Prog =
|
10
|
struct
|
11
|
let init, defs, state_vars, globals =
|
12
|
let Program (init, defs, globals) = M.model in
|
13
|
let state_vars = SF.states M.model in
|
14
|
init, defs, state_vars, globals
|
15
|
|
16
|
(*let _ = Format.printf "Model definitions@.%a@.####" Simulink.pp_src defs; () *)
|
17
|
end
|
18
|
|
19
|
|
20
|
module Interp = CPS_interpreter.Interpreter (T)
|
21
|
module KenvTheta = KenvTheta (T)
|
22
|
module Tables = KenvTheta.MemoThetaTables ()
|
23
|
|
24
|
let eval ((modular_entry:bool), (modular_during:bool), (modular_exit:bool)) =
|
25
|
let module Modularity : KenvTheta.ModularType =
|
26
|
struct
|
27
|
let modular : type b. (path_t, b, bool) tag_t -> path_t -> b =
|
28
|
fun tag ->
|
29
|
match tag with
|
30
|
| E -> (fun p p' f -> modular_entry)
|
31
|
| D -> (fun p -> modular_during)
|
32
|
| X -> (fun p f -> modular_exit)
|
33
|
end
|
34
|
in
|
35
|
let module Thetaify = KenvTheta.ModularThetaify (Tables) (Modularity) in
|
36
|
let module EvalProg = Interp.Evaluation (Thetaify) (Prog) in
|
37
|
(module EvalProg: Interp.EvaluationType)
|
38
|
|
39
|
let compute modular =
|
40
|
let module Eval = (val (eval modular)) in
|
41
|
Eval.eval_prog
|
42
|
|
43
|
let code_gen modular =
|
44
|
let module Eval = (val (eval modular)) in
|
45
|
let principal, components = Eval.eval_prog, Eval.eval_components in
|
46
|
List.flatten (List.map (fun (c, tr) -> T.mkcomponent Ecall c tr) (components Ecall))@
|
47
|
List.flatten (List.map (fun (c, tr) -> T.mkcomponent Dcall c tr) (components Dcall))@
|
48
|
List.flatten (List.map (fun (c, tr) -> T.mkcomponent Xcall c tr) (components Xcall))@
|
49
|
(T.mkprincipal principal)
|
50
|
end
|