Project

General

Profile

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

    
5
(* Type definitions of a model *)
6

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

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

    
17
type transitions_t = trans_t list
18

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

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

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

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

    
41
type prog_t =
42
  | Program of
43
      state_name_t
44
      * prog_t src_components_t list
45
      * (Lustre_types.var_decl * Lustre_types.expr) list
46

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

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

    
51
type user_variable_t = user_variable_name_t * scope_t * datatype_var_init_t
52

    
53
type trace_t = event_t list
54

    
55
module type MODEL_T = sig
56
  val name : string
57

    
58
  val model : prog_t
59

    
60
  val traces : trace_t list
61
end
62

    
63
(* Module (S)tate(F)low provides basic constructors for action, condition,
64
   events, as well as printer functions *)
65
module SF = struct
66
  (* Basic constructors *)
67

    
68
  let no_action = Action.nil
69

    
70
  let no_condition = Condition.tru
71

    
72
  let no_event = None
73

    
74
  let event s = Some s
75

    
76
  let action s = Action.aquote s
77

    
78
  let condition s = Condition.cquote s
79

    
80
  let no_state_action =
81
    { entry_act = no_action; during_act = no_action; exit_act = no_action }
82

    
83
  let state_action a b c = { entry_act = a; during_act = b; exit_act = c }
84

    
85
  let states (Program (_, defs, _)) =
86
    List.fold_left
87
      (fun res c ->
88
        match c with
89
        | State (p, _) ->
90
          ActiveStates.Vars.add p res
91
        | Junction _ ->
92
          res
93
        | SFFunction _ ->
94
          res)
95
      ActiveStates.Vars.empty defs
96

    
97
  let init_env model = ActiveStates.Env.from_set (states model) false
98

    
99
  let global_vars (Program (_, _, env)) = env
100

    
101
  (* Printers *)
102

    
103
  let pp_event fmt e =
104
    match e with
105
    | Some e ->
106
      Format.fprintf fmt "%s" e
107
    | None ->
108
      Format.fprintf fmt "noevent"
109

    
110
  let pp_dest fmt d =
111
    match d with
112
    | DPath p ->
113
      Format.fprintf fmt "Path %a" pp_path p
114
    | DJunction j ->
115
      Format.fprintf fmt "Junction %a" pp_junction_name j
116

    
117
  let pp_trans fmt t =
118
    Format.fprintf fmt "@[<hov 0>(@[<hov 0>%a,@ %a,@ %a,@ %a,@ %a@]@ )@]"
119
      pp_event t.event Condition.pp_cond t.condition Action.pp_act
120
      t.condition_act Action.pp_act t.transition_act pp_dest t.dest
121

    
122
  let pp_transitions fmt l =
123
    Format.(fprintf fmt "@[<hov 0>[@[<hov 0>%a@]@ ]@]"
124
              (pp_print_list ~pp_sep:pp_print_semicolon pp_trans)
125
              l)
126

    
127
  let pp_comp fmt c =
128
    match c with
129
    | Or (_T, _S) ->
130
      Format.(fprintf fmt "Or(%a, {%a})" pp_transitions _T
131
                (pp_print_list ~pp_sep:pp_print_semicolon pp_state_name)
132
                _S)
133
    | And _S ->
134
      Format.(fprintf fmt "And({%a})"
135
                (pp_print_list ~pp_sep:pp_print_semicolon pp_state_name)
136
                _S)
137

    
138
  let pp_state_actions fmt sa =
139
    Format.fprintf fmt "@[<hov 0>(%a,@ %a,@ %a)@]" Action.pp_act sa.entry_act
140
      Action.pp_act sa.during_act Action.pp_act sa.exit_act
141

    
142
  let pp_state fmt s =
143
    Format.fprintf fmt "@[<v 0>(@[<v 0>%a,@ %a,@ %a,@ %a@]@ @])"
144
      pp_state_actions s.state_actions pp_transitions s.outer_trans
145
      pp_transitions s.inner_trans pp_comp s.internal_composition
146

    
147
  let pp_src pp_sffunction fmt src =
148
    Format.(fprintf fmt "@[<v>%a@ @]"
149
              (pp_print_list ~pp_sep:pp_print_cutcut (fun fmt src ->
150
                   match src with
151
                   | State (p, def) ->
152
                     Format.fprintf fmt "%a: %a" pp_path p pp_state def
153
                   | Junction (s, tl) ->
154
                     Format.fprintf fmt "%a: %a" pp_state_name s pp_transitions tl
155
                   | SFFunction p ->
156
                     pp_sffunction fmt p))
157
              src)
158

    
159
  let rec pp_sffunction fmt (Program (name, component_list, _)) =
160
    Format.fprintf fmt "SFFunction name: %s@ %a@ " name (pp_src pp_sffunction)
161
      component_list
162

    
163
  let pp_vars fmt src =
164
    Format.(fprintf fmt "@[<v>%a@ @]" (pp_print_list Printers.pp_var) src)
165

    
166
  let pp_prog fmt (Program (name, component_list, vars)) =
167
    Format.fprintf fmt "Main node name: %s@ %a@ %a@" name (pp_src pp_sffunction)
168
      component_list pp_vars (List.map fst vars)
169

    
170
  let pp_scope fmt src =
171
    Format.fprintf fmt
172
      (match src with
173
      | Constant ->
174
        "Constant"
175
      | Input ->
176
        "Input"
177
      | Local ->
178
        "Local"
179
      | Output ->
180
        "Output"
181
      | Parameter ->
182
        "Parameter")
183
end
(5-5/6)