Project

General

Profile

Download (4.78 KB) Statistics
| Branch: | Tag: | Revision:
1
open Basetypes
2
(* open ActiveEnv *)
3

    
4
(* Type definitions of a model *)
5

    
6
type destination_t =
7
  | DPath of path_t
8
  | DJunction of junction_name_t
9

    
10
type trans_t = {
11
  event: event_t;
12
  condition: Condition.t;
13
  condition_act: Action.t;
14
  transition_act: Action.t;
15
  dest: destination_t;
16
}
17

    
18
type transitions_t = trans_t list
19

    
20
type composition_t =
21
  | Or of transitions_t * state_name_t list
22
  | And of state_name_t list
23

    
24
type state_actions_t = {
25
  entry_act: Action.t;
26
  during_act: Action.t;
27
  exit_act: Action.t;
28
}
29

    
30
type state_def_t = {
31
  state_actions : state_actions_t;
32
  outer_trans : transitions_t;
33
  inner_trans : transitions_t;
34
  internal_composition : composition_t;
35
}
36

    
37
type 'prog_t src_components_t =
38
  | State of path_t * state_def_t
39
  | Junction of junction_name_t * transitions_t
40
  | SFFunction of 'prog_t
41

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

    
44
type prog_t = Program of state_name_t * prog_t src_components_t list * GlobalVarDef.t list
45

    
46
type scope_t = Constant | Input | Local | Output | Parameter
47

    
48
type datatype_var_init_t = Bool of bool | Real of float | Int of int
49

    
50
type user_variable_t = user_variable_name_t * scope_t * datatype_var_init_t
51

    
52
type trace_t = event_t list
53

    
54
module type MODEL_T = sig
55
  val name : string
56
  val model : prog_t
57
  val traces: trace_t list
58
end
59

    
60
(* Module (S)tate(F)low provides basic constructors for action, condition,
61
   events, as well as printer functions *)
62
module SF =
63
struct
64

    
65
  (* Basic constructors *)
66

    
67
  let no_action    = Action.nil
68
  let no_condition = Condition.tru
69
  let no_event     = None
70
  let event s      = Some s
71
  let action s     = Action.aquote s
72
  let condition s  = Condition.cquote s
73
  let no_state_action    = {entry_act = no_action; during_act = no_action; exit_act = no_action; }
74
  let state_action a b c = {entry_act = a; during_act = b; exit_act = c; }
75

    
76
  let states (Program (_, defs, _)) =
77
    List.fold_left
78
      (fun res c ->
79
	match c with
80
	| State (p, _) -> ActiveStates.Vars.add p res
81
	| Junction _  -> res
82
        | SFFunction _ -> res
83
      )
84
      ActiveStates.Vars.empty defs
85

    
86
  let init_env model = ActiveStates.Env.from_set (states model) false
87

    
88
  let global_vars (Program (_, _, env)) = env
89

    
90
  (* Printers *)
91

    
92
  let pp_event fmt e =
93
    match e with
94
    | Some e -> Format.fprintf fmt "%s" e
95
    | None -> Format.fprintf fmt "noevent"
96

    
97
  let pp_dest fmt d = match d with
98
    | DPath p -> Format.fprintf fmt "Path %a" pp_path p
99
    | DJunction j -> Format.fprintf fmt "Junction %a" pp_junction_name j
100

    
101
  let pp_trans fmt t =
102
    Format.fprintf fmt
103
      "@[<hov 0>(@[<hov 0>%a,@ %a,@ %a,@ %a,@ %a@]@ )@]"
104
      pp_event t.event
105
      Condition.pp_cond t.condition
106
      Action.pp_act t.condition_act
107
      Action.pp_act t.transition_act
108
      pp_dest t.dest
109

    
110
  let pp_transitions fmt l =
111
    Format.fprintf fmt
112
      "@[<hov 0>[@[<hov 0>%a@]@ ]@]"
113
      (Utils.fprintf_list ~sep:";@ " pp_trans) l
114

    
115
  let pp_comp fmt c = match c with
116
    | Or (_T, _S) ->
117
       Format.fprintf fmt "Or(%a, {%a})"
118
	 pp_transitions _T
119
	 (Utils.fprintf_list ~sep:"; " pp_state_name) _S
120
    | And (_S) ->
121
       Format.fprintf fmt "And({%a})"
122
	 (Utils.fprintf_list ~sep:"; " pp_state_name) _S
123

    
124
  let pp_state_actions fmt sa =
125
    Format.fprintf fmt "@[<hov 0>(%a,@ %a,@ %a)@]"
126
      Action.pp_act sa.entry_act
127
      Action.pp_act sa.during_act
128
      Action.pp_act sa.exit_act
129

    
130
  let pp_state fmt s =
131
    Format.fprintf fmt "@[<v 0>(@[<v 0>%a,@ %a,@ %a,@ %a@]@ @])"
132
      pp_state_actions s.state_actions
133
      pp_transitions s.outer_trans
134
      pp_transitions s.inner_trans
135
      pp_comp s.internal_composition
136

    
137
  let pp_src pp_sffunction fmt src =
138
    Format.fprintf fmt "@[<v>%a@ @]"
139
      (Utils.fprintf_list ~sep:"@ @ "
140
         (fun fmt src -> match src with
141
	    | State (p, def)   -> Format.fprintf fmt "%a: %a"
142
                                  pp_path p pp_state def
143
            | Junction (s, tl) -> Format.fprintf fmt "%a: %a"
144
	                            pp_state_name s
145
	                            pp_transitions tl
146
            | SFFunction p     -> pp_sffunction fmt p
147
         ))
148
      src
149

    
150
  let rec pp_sffunction fmt (Program (name, component_list, _)) =
151
    Format.fprintf fmt "SFFunction name: %s@ %a@ "
152
      name
153
      (pp_src pp_sffunction) component_list
154

    
155
  let pp_vars fmt src =
156
    Format.fprintf fmt "@[<v>%a@ @]"
157
      (Utils.fprintf_list ~sep:"@ " Printers.pp_var)
158
    src
159

    
160
  let pp_prog fmt (Program (name, component_list, vars)) =
161
    Format.fprintf fmt "Main node name: %s@ %a@ %a@"
162
      name
163
      (pp_src pp_sffunction) component_list
164
      pp_vars (List.map .variable vars)
165

    
166
  let pp_scope fmt src =
167
    Format.fprintf fmt (match src with
168
        | Constant  -> "Constant"
169
        | Input     -> "Input"
170
        | Local     -> "Local"
171
        | Output    -> "Output"
172
        | Parameter -> "Parameter")
173
end
(3-3/3)