Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / stateflow / semantics / cPS_ccode_generator.ml @ 93119c3f

History | View | Annotate | Download (1.97 KB)

1 93119c3f ploc
open Basetypes
2
open ActiveStates
3
open CPS_transformer
4
5
module CodeGenerator : ComparableTransformerType =
6
struct
7
  include TransformerStub
8
9
  type t =
10
  | Bot
11
  | Act of act_t
12
  | Seq of t list
13
  | Ite of cond_t * t * t
14
15
  let null = Seq []
16
17
  let bot = Bot
18
 
19
  let ( >> ) tr1 tr2 =
20
    match tr1, tr2 with
21
    | Seq trl1, Seq trl2 -> Seq (trl1@trl2)
22
    | Seq trl1, _        -> Seq (trl1@[tr2])
23
    | _       , Seq trl2 -> Seq (tr1::trl2)
24
    | _                  -> Seq ([tr1;tr2])
25
26
  let rec ( == ) tr1 tr2 = tr1 = tr2
27
28
  let eval_act kenv (action : act_t) =
29
    (*Format.printf "----- action = %a@." Action.pp_act action;*)
30
    Act action
31
32
  (*if (match trans.event with None -> true | _ -> e = trans.event) && trans.condition rho*)
33
  let rec eval_cond condition ok ko =
34
    (*Format.printf "----- cond = %a@." Condition.pp_cond condition;*)
35
    Ite (condition, ok, ko)
36
    
37
  let rec pp_transformer fmt tr =
38
    match tr with
39
    | Bot           -> Format.fprintf fmt "bot"
40
    | Act a         ->
41
       Format.fprintf fmt "<%a>" pp_act a
42
    | Seq trl       ->
43
       Format.fprintf fmt "@[<v 0>%a@]"
44
	 (Utils.fprintf_list ~sep:";@ " pp_transformer)
45
	 trl
46
    | Ite (c, t, e) ->
47
       Format.fprintf fmt "@[<v 0>if %a@ @[<v 2>then@ %a@]@ @[<v 2>else@ %a@]@ endif@]" pp_cond c pp_transformer t pp_transformer e
48
49
  let pp_principal fmt tr =
50
    Format.fprintf fmt "principal =@.%a" pp_transformer tr
51
      
52
  let pp_component : type c. Format.formatter -> c call_t -> c -> t -> unit =
53
    fun fmt call -> match call with
54
    | Ecall -> (fun (p, p', f) tr ->
55
      Format.fprintf fmt "component %a(%a, %a, %a) =@.@[<v 2>begin@ %a@]@.end" pp_call call pp_path p pp_path p' pp_frontier f pp_transformer tr)
56
    | Dcall -> (fun p tr ->
57
      Format.fprintf fmt "component %a(%a) =@.@[<v 2>begin@ %a@]@.end" pp_call call pp_path p pp_transformer tr)
58
    | Xcall -> (fun (p, f) tr ->
59
      Format.fprintf fmt "component %a(%a, %a) =@.@[<v 2>begin@ %a@]@.end" pp_call call pp_path p pp_frontier f pp_transformer tr)
60
end