2011-03-16 23:25:04 +01:00
|
|
|
|
(****************************************************)
|
|
|
|
|
(* *)
|
|
|
|
|
(* Heptagon/BZR *)
|
|
|
|
|
(* *)
|
2011-07-27 11:21:34 +02:00
|
|
|
|
(* Author : Gwena<6E>l Delaval *)
|
|
|
|
|
(* Organization : UJF, LIG *)
|
2011-03-16 23:25:04 +01:00
|
|
|
|
(* *)
|
|
|
|
|
(****************************************************)
|
|
|
|
|
|
|
|
|
|
(* Translation from the source language to Sigali polynomial systems *)
|
|
|
|
|
|
|
|
|
|
(* $Id: dynamic_system.ml 2652 2011-03-11 16:26:17Z delaval $ *)
|
|
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
|
open Compiler_utils
|
|
|
|
|
open Names
|
|
|
|
|
open Idents
|
|
|
|
|
open Types
|
|
|
|
|
open Clocks
|
|
|
|
|
open Sigali
|
|
|
|
|
|
|
|
|
|
type mtype = Tint | Tbool | Tother
|
|
|
|
|
|
|
|
|
|
let actual_ty = function
|
2011-04-20 11:42:03 +02:00
|
|
|
|
| Tid({ qual = Pervasives; name = "bool"}) -> Tbool
|
|
|
|
|
| Tid({ qual = Pervasives; name = "int"}) -> Tint
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| _ -> Tother
|
|
|
|
|
|
|
|
|
|
let var_list prefix n =
|
|
|
|
|
let rec varl acc = function
|
|
|
|
|
| 0 -> acc
|
|
|
|
|
| n ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
let acc = (prefix ^ (string_of_int n)) :: acc in
|
|
|
|
|
varl acc (n-1) in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
varl [] n
|
|
|
|
|
|
|
|
|
|
let dummy_prefix = "d"
|
|
|
|
|
|
|
|
|
|
let translate_static_exp se =
|
|
|
|
|
match se.se_desc with
|
|
|
|
|
| Sint(v) -> Cint(v)
|
|
|
|
|
| Sfloat(_) -> failwith("Sigali: floats not implemented")
|
2012-06-06 15:59:08 +02:00
|
|
|
|
| Sbool(true)
|
|
|
|
|
| Sconstructor { qual = Pervasives; name = "true" }
|
|
|
|
|
-> Ctrue
|
|
|
|
|
| Sbool(false)
|
|
|
|
|
| Sconstructor { qual = Pervasives; name = "false" }
|
|
|
|
|
-> Cfalse
|
2011-08-04 13:37:33 +02:00
|
|
|
|
| Sop({ qual = Pervasives; name = "~-" },[{se_desc = Sint(v)}]) ->
|
|
|
|
|
Cint(-v)
|
2011-10-17 15:28:04 +02:00
|
|
|
|
| _ ->
|
2011-08-04 13:37:33 +02:00
|
|
|
|
Format.printf "Constant %a@\n"
|
2011-11-21 02:03:45 +01:00
|
|
|
|
Global_printer.print_static_exp se;
|
2011-08-04 13:37:33 +02:00
|
|
|
|
failwith("Sigali: untranslatable constant")
|
2011-03-16 23:25:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let rec translate_pat = function
|
2012-06-06 15:59:08 +02:00
|
|
|
|
| Minils.Evarpat(x) -> [x]
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Etuplepat(pat_list) ->
|
|
|
|
|
List.fold_right (fun pat acc -> (translate_pat pat) @ acc) pat_list []
|
|
|
|
|
|
|
|
|
|
let rec translate_ck pref e = function
|
|
|
|
|
| Cbase | Cvar { contents = Cindex _ } ->
|
|
|
|
|
e
|
|
|
|
|
| Cvar { contents = Clink ck } -> translate_ck pref e ck
|
|
|
|
|
| Con(ck,c,var) ->
|
|
|
|
|
let e = translate_ck pref e ck in
|
|
|
|
|
Swhen(e,
|
2011-11-21 02:03:45 +01:00
|
|
|
|
match (shortname c) with
|
|
|
|
|
"true" -> Svar(pref ^ (name var))
|
|
|
|
|
| "false" -> Snot(Svar(pref ^ (name var)))
|
|
|
|
|
| _ -> assert false)
|
2011-03-16 23:25:04 +01:00
|
|
|
|
|
2011-07-27 11:21:34 +02:00
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let rec translate_ext prefix ({ Minils.w_desc = desc; Minils.w_ty = ty }) =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
match desc with
|
2011-07-27 11:21:34 +02:00
|
|
|
|
| Minils.Wconst(v) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
begin match (actual_ty ty) with
|
|
|
|
|
| Tbool -> Sconst(translate_static_exp v)
|
|
|
|
|
| Tint -> a_const (Sconst(translate_static_exp v))
|
|
|
|
|
| Tother -> failwith("Sigali: untranslatable type")
|
|
|
|
|
end
|
2011-07-27 11:21:34 +02:00
|
|
|
|
| Minils.Wvar(n) -> Svar(prefix ^ (name n))
|
2012-06-06 15:59:08 +02:00
|
|
|
|
|
|
|
|
|
(* TODO remove if this works without *)
|
|
|
|
|
(* | Minils.Wwhen(e, c, var) when ((actual_ty e.Minils.w_ty) = Tbool) -> *)
|
|
|
|
|
(* let e = translate_ext prefix e in *)
|
|
|
|
|
(* Swhen(e, *)
|
|
|
|
|
(* match (shortname c) with *)
|
|
|
|
|
(* "true" -> Svar(prefix ^ (name var)) *)
|
|
|
|
|
(* | "false" -> Snot(Svar(prefix ^ (name var))) *)
|
|
|
|
|
(* | _ -> assert false) *)
|
2011-07-27 11:21:34 +02:00
|
|
|
|
| Minils.Wwhen(e, _c, _var) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
translate_ext prefix e
|
2011-07-27 11:21:34 +02:00
|
|
|
|
| Minils.Wfield(_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
failwith("Sigali: structures not implemented")
|
2011-10-17 15:28:04 +02:00
|
|
|
|
| Minils.Wreinit _ -> failwith("Sigali: reinit not implemented")
|
2011-07-27 11:21:34 +02:00
|
|
|
|
|
|
|
|
|
(* [translate e = c] *)
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let rec translate prefix ({ Minils.e_desc = desc } as e) =
|
2011-07-27 11:21:34 +02:00
|
|
|
|
match desc with
|
|
|
|
|
| Minils.Eextvalue(ext) -> translate_ext prefix ext
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Eapp (* pervasives binary or unary stateless operations *)
|
2011-11-21 02:03:45 +01:00
|
|
|
|
({ Minils.a_op = Minils.Efun({qual=Pervasives;name=n})},
|
|
|
|
|
e_list, _) ->
|
|
|
|
|
begin
|
|
|
|
|
match n, e_list with
|
|
|
|
|
| "not", [e] -> Snot(translate_ext prefix e)
|
|
|
|
|
| "or", [e1;e2] -> Sor((translate_ext prefix e1),
|
|
|
|
|
(translate_ext prefix e2))
|
|
|
|
|
| "&", [e1;e2] -> Sand((translate_ext prefix e1),
|
|
|
|
|
(translate_ext prefix e2))
|
|
|
|
|
| ("<="|"<"|">="|">"), [e1;e2] ->
|
|
|
|
|
let op,modv =
|
|
|
|
|
begin match n with
|
|
|
|
|
| "<=" -> a_inf,0
|
|
|
|
|
| "<" -> a_inf,-1
|
|
|
|
|
| ">=" -> a_sup,0
|
|
|
|
|
| _ -> a_sup,1
|
|
|
|
|
end in
|
|
|
|
|
let e1 = translate_ext prefix e1 in
|
|
|
|
|
let sig_e =
|
|
|
|
|
begin match e2.Minils.w_desc with
|
|
|
|
|
| Minils.Wconst({se_desc = Sint(v)}) ->
|
|
|
|
|
op e1 (Sconst(Cint(v+modv)))
|
|
|
|
|
| _ ->
|
|
|
|
|
let e2 = translate_ext prefix e2 in
|
|
|
|
|
op (Sminus(e1,e2)) (Sconst(Cint(modv)))
|
|
|
|
|
end in
|
|
|
|
|
(* a_inf and a_sup : +1 to translate ideals to boolean
|
|
|
|
|
polynomials *)
|
|
|
|
|
Splus(sig_e,Sconst(Ctrue))
|
|
|
|
|
| "+", [e1;e2] -> Splus((translate_ext prefix e1),
|
|
|
|
|
(translate_ext prefix e2))
|
|
|
|
|
| "-", [e1;e2] -> Sminus((translate_ext prefix e1),
|
|
|
|
|
(translate_ext prefix e2))
|
|
|
|
|
| "*", [e1;e2] -> Sprod((translate_ext prefix e1),
|
|
|
|
|
(translate_ext prefix e2))
|
|
|
|
|
| ("="
|
|
|
|
|
| "<>"),_ -> failwith("Sigali: '=' or '<>' not yet implemented")
|
|
|
|
|
| _ -> assert false
|
|
|
|
|
end
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(* | Minils.Ewhen(e, c, var) when ((actual_ty e.Minils.e_ty) = Tbool) -> *)
|
|
|
|
|
(* let e = translate prefix e in *)
|
|
|
|
|
(* Swhen(e, *)
|
|
|
|
|
(* match (shortname c) with *)
|
|
|
|
|
(* "true" -> Svar(prefix ^ (name var)) *)
|
|
|
|
|
(* | "false" -> Snot(Svar(prefix ^ (name var))) *)
|
|
|
|
|
(* | _ -> assert false) *)
|
2011-08-04 13:37:33 +02:00
|
|
|
|
| Minils.Ewhen(e, _c, _var) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
translate prefix e
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Emerge(ck,[(c1,e1);(_c2,e2)]) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
let e1 = translate_ext prefix e1 in
|
|
|
|
|
let e2 = translate_ext prefix e2 in
|
|
|
|
|
let e1,e2 =
|
|
|
|
|
begin
|
|
|
|
|
match (shortname c1) with
|
|
|
|
|
"true" -> e1,e2
|
|
|
|
|
| "false" -> e2,e1
|
|
|
|
|
| _ -> assert false
|
|
|
|
|
end in
|
|
|
|
|
let var_ck = Svar(prefix ^ (name ck)) in
|
|
|
|
|
begin match (actual_ty e.Minils.e_ty) with
|
|
|
|
|
| Tbool -> Sdefault(Swhen(e1,var_ck),e2)
|
|
|
|
|
| Tint -> a_part var_ck (a_const (Sconst(Cint(0)))) e1 e2
|
|
|
|
|
| Tother -> assert false
|
|
|
|
|
end
|
2011-08-04 13:37:33 +02:00
|
|
|
|
| Minils.Eapp({Minils.a_op = Minils.Eifthenelse},[e1;e2;e3],_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
let e1 = translate_ext prefix e1 in
|
|
|
|
|
let e2 = translate_ext prefix e2 in
|
|
|
|
|
let e3 = translate_ext prefix e3 in
|
|
|
|
|
begin match (actual_ty e.Minils.e_ty) with
|
|
|
|
|
| Tbool -> Sdefault(Swhen(e2,e1),e3)
|
|
|
|
|
| Tint -> a_part e1 (a_const (Sconst(Cint(0)))) e2 e3
|
|
|
|
|
| Tother -> assert false
|
|
|
|
|
end
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Estruct(_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
failwith("Sigali: structures not implemented")
|
2011-04-20 11:42:03 +02:00
|
|
|
|
| Minils.Eiterator(_,_,_,_,_,_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
failwith("Sigali: iterators not implemented")
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Eapp({Minils.a_op = Minils.Enode(_)},_,_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
failwith("Sigali: node in expressions; programs should be normalized")
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Efby(_,_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
failwith("Sigali: fby in expressions; programs should be normalized")
|
2011-10-17 15:28:04 +02:00
|
|
|
|
| Minils.Eapp(_,_,_) ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
Format.printf "Application : %a@\n"
|
|
|
|
|
Mls_printer.print_exp e;
|
|
|
|
|
failwith("Sigali: not supported application")
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Emerge(_, _) -> assert false
|
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let rec translate_eq f
|
|
|
|
|
(acc_states,acc_init,acc_inputs,acc_eqs)
|
2012-01-25 09:34:58 +01:00
|
|
|
|
{ Minils.eq_lhs = pat; Minils.eq_rhs = e; eq_base_ck = ck } =
|
2011-10-17 15:28:04 +02:00
|
|
|
|
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let prefix = f ^ "_" in
|
|
|
|
|
|
|
|
|
|
let prefixed n = prefix ^ n in
|
2011-10-17 15:28:04 +02:00
|
|
|
|
|
2012-01-25 09:34:58 +01:00
|
|
|
|
let { Minils.e_desc = desc } = e in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
match pat, desc with
|
|
|
|
|
| Minils.Evarpat(n), Minils.Efby(opt_c, e) ->
|
|
|
|
|
let sn = prefixed (name n) in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let acc_eqs =
|
|
|
|
|
(extend
|
|
|
|
|
constraints
|
|
|
|
|
(Slist[Sequal(Ssquare(Svar(sn)),Sconst(Ctrue))]))::acc_eqs in
|
2011-10-17 15:28:04 +02:00
|
|
|
|
let acc_eqs,acc_init =
|
2011-11-21 02:03:45 +01:00
|
|
|
|
match opt_c with
|
|
|
|
|
| None -> acc_eqs,Cfalse::acc_init
|
|
|
|
|
| Some(c) ->
|
|
|
|
|
let c = translate_static_exp c in
|
|
|
|
|
(extend
|
|
|
|
|
initialisations
|
|
|
|
|
(Slist[Sequal(Svar(sn),Sconst(c))]))::acc_eqs,
|
|
|
|
|
c::acc_init
|
2011-03-16 23:25:04 +01:00
|
|
|
|
in
|
2011-07-27 11:21:34 +02:00
|
|
|
|
let e_next = translate_ext prefix e in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let e_next = translate_ck prefix e_next ck in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(n,sn)::acc_states,
|
|
|
|
|
acc_init,acc_inputs,
|
2011-10-17 15:28:04 +02:00
|
|
|
|
(extend
|
2011-11-21 02:03:45 +01:00
|
|
|
|
evolutions
|
|
|
|
|
(Slist[Sdefault(e_next,Svar(sn))]))
|
2011-03-16 23:25:04 +01:00
|
|
|
|
::acc_eqs
|
2012-06-06 15:59:08 +02:00
|
|
|
|
| pat, Minils.Eapp({ Minils.a_op = Minils.Enode _f; }, _e_list, None) ->
|
2011-03-16 23:25:04 +01:00
|
|
|
|
(*
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(y1,...,yp) = f(x1,...,xn)
|
2011-11-21 02:03:45 +01:00
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
add inputs y1,...,yp. Link between yi and f's contract has
|
|
|
|
|
been done in the pass "Contracts".
|
2011-03-16 23:25:04 +01:00
|
|
|
|
*)
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let ident_list = translate_pat pat in
|
|
|
|
|
let acc_inputs =
|
|
|
|
|
acc_inputs @
|
|
|
|
|
(List.map (fun id -> (id,(prefixed (name id)))) ident_list) in
|
|
|
|
|
acc_states,acc_init,
|
|
|
|
|
acc_inputs,acc_eqs
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| Minils.Evarpat(n), _ ->
|
|
|
|
|
(* assert : no fby, no node application in e *)
|
|
|
|
|
let e' = translate prefix e in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(* let e' = *)
|
|
|
|
|
(* begin match (actual_ty e.Minils.e_ty) with *)
|
|
|
|
|
(* | Tbool -> translate_ck prefix e' ck *)
|
|
|
|
|
(* | _ -> e' *)
|
|
|
|
|
(* end in *)
|
|
|
|
|
acc_states,acc_init,
|
|
|
|
|
acc_inputs,
|
2011-03-16 23:25:04 +01:00
|
|
|
|
{ stmt_name = prefixed (name n);
|
2011-11-21 02:03:45 +01:00
|
|
|
|
stmt_def = e' }::acc_eqs
|
2011-03-16 23:25:04 +01:00
|
|
|
|
| _ -> assert false
|
2011-10-17 15:28:04 +02:00
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let translate_eq_list f eq_list =
|
2011-10-17 15:28:04 +02:00
|
|
|
|
List.fold_left
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(fun (acc_states,acc_init, acc_inputs,acc_eqs) eq ->
|
|
|
|
|
translate_eq f (acc_states,acc_init,acc_inputs,acc_eqs) eq)
|
|
|
|
|
([],[],[],[])
|
2011-03-16 23:25:04 +01:00
|
|
|
|
eq_list
|
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let translate_contract f contract =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let prefix = f ^ "_" in
|
|
|
|
|
let var_a = prefix ^ "assume" in
|
|
|
|
|
let var_g = prefix ^ "guarantee" in
|
|
|
|
|
match contract with
|
2011-10-17 15:28:04 +02:00
|
|
|
|
| None ->
|
|
|
|
|
let body =
|
2011-11-21 02:03:45 +01:00
|
|
|
|
[{ stmt_name = var_g; stmt_def = Sconst(Ctrue) };
|
|
|
|
|
{ stmt_name = var_a; stmt_def = Sconst(Ctrue) }] in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
[],[],body,(Svar(var_a),Svar(var_g)),[],[],[]
|
|
|
|
|
| Some {Minils.c_local = locals;
|
2011-11-21 02:03:45 +01:00
|
|
|
|
Minils.c_eq = l_eqs;
|
|
|
|
|
Minils.c_assume = e_a;
|
|
|
|
|
Minils.c_enforce = e_g;
|
2012-06-06 15:59:08 +02:00
|
|
|
|
Minils.c_assume_loc = e_a_loc;
|
|
|
|
|
Minils.c_enforce_loc = e_g_loc;
|
2011-11-21 02:03:45 +01:00
|
|
|
|
Minils.c_controllables = cl} ->
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let states,init,inputs,body = translate_eq_list f l_eqs in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
assert (inputs = []);
|
2011-08-04 13:37:33 +02:00
|
|
|
|
let e_a = translate_ext prefix e_a in
|
|
|
|
|
let e_g = translate_ext prefix e_g in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let e_a_loc = translate_ext prefix e_a_loc in
|
|
|
|
|
let e_g_loc = translate_ext prefix e_g_loc in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let body =
|
2012-06-06 15:59:08 +02:00
|
|
|
|
{stmt_name = var_g; stmt_def = e_g &~ e_g_loc } ::
|
|
|
|
|
{stmt_name = var_a; stmt_def = e_a &~ e_a_loc } ::
|
2011-11-21 02:03:45 +01:00
|
|
|
|
body in
|
2011-10-17 15:28:04 +02:00
|
|
|
|
let controllables =
|
2012-06-06 15:59:08 +02:00
|
|
|
|
List.map
|
|
|
|
|
(fun ({ Minils.v_ident = id } as v) -> v,(prefix ^ (name id))) cl in
|
|
|
|
|
states,init,body,(Svar(var_a),Svar(var_g)),controllables,(locals@cl),l_eqs
|
2011-03-16 23:25:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let translate_node
|
2011-03-16 23:25:04 +01:00
|
|
|
|
({ Minils.n_name = {name = f};
|
|
|
|
|
Minils.n_input = i_list; Minils.n_output = o_list;
|
|
|
|
|
Minils.n_local = _d_list; Minils.n_equs = eq_list;
|
|
|
|
|
Minils.n_contract = contract } as node) =
|
|
|
|
|
(* every variable is prefixed by its node name *)
|
|
|
|
|
let inputs =
|
|
|
|
|
List.map
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(fun { Minils.v_ident = v } -> v,(f ^ "_" ^ (name v))) i_list in
|
|
|
|
|
let sig_outputs =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
List.map
|
|
|
|
|
(fun { Minils.v_ident = v } -> f ^ "_" ^ (name v)) o_list in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let states,init,add_inputs,body =
|
|
|
|
|
translate_eq_list f eq_list in
|
|
|
|
|
let states_c,init_c,body_c,(a_c,g_c),controllables,locals_c,eqs_c =
|
|
|
|
|
translate_contract f contract in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let inputs = inputs @ add_inputs in
|
|
|
|
|
let body = List.rev body in
|
|
|
|
|
let states = List.rev states in
|
|
|
|
|
let body_c = List.rev body_c in
|
|
|
|
|
let states_c = List.rev states_c in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let mls_inputs,sig_inputs = List.split inputs in
|
|
|
|
|
let mls_states,sig_states = List.split (states@states_c) in
|
|
|
|
|
let mls_ctrl,sig_ctrl = List.split controllables in
|
2011-10-17 15:28:04 +02:00
|
|
|
|
let constraints =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
List.map
|
|
|
|
|
(fun v -> Sequal(Ssquare(Svar(v)),Sconst(Ctrue)))
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(sig_inputs@sig_ctrl) in
|
|
|
|
|
let constraints = constraints @ [Sequal (a_c,Sconst(Ctrue))] in
|
|
|
|
|
let obj = Security(g_c) in
|
|
|
|
|
let p = { proc_dep = [];
|
2011-11-21 02:03:45 +01:00
|
|
|
|
proc_name = f;
|
2012-06-06 15:59:08 +02:00
|
|
|
|
proc_inputs = sig_inputs@sig_ctrl;
|
|
|
|
|
proc_uncont_inputs = sig_inputs;
|
|
|
|
|
proc_outputs = sig_outputs;
|
|
|
|
|
proc_controllables = sig_ctrl;
|
|
|
|
|
proc_states = sig_states;
|
2011-11-21 02:03:45 +01:00
|
|
|
|
proc_init = init@init_c;
|
|
|
|
|
proc_constraints = constraints;
|
|
|
|
|
proc_body = body@body_c;
|
|
|
|
|
proc_objectives = [obj] } in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let ctrlr_pat = Minils.Etuplepat(List.map (fun { Minils.v_ident = v } ->
|
|
|
|
|
Minils.Evarpat(v))
|
|
|
|
|
mls_ctrl) in
|
|
|
|
|
let ctrlr_name = f ^ "_controller" in
|
|
|
|
|
let ctrlr_fun_name = { qual = Module (String.capitalize ctrlr_name);
|
|
|
|
|
name = ctrlr_name } in
|
|
|
|
|
let ctrlr_exp =
|
|
|
|
|
Minils.mk_exp
|
|
|
|
|
Cbase
|
|
|
|
|
(Tprod (List.map (fun _ -> Initial.tbool) mls_ctrl))
|
|
|
|
|
~linearity:Linearity.Ltop
|
|
|
|
|
(Minils.Eapp(Minils.mk_app (Minils.Efun ctrlr_fun_name),
|
|
|
|
|
(List.map
|
|
|
|
|
(fun v ->
|
|
|
|
|
Minils.mk_extvalue
|
|
|
|
|
~ty:Initial.tbool
|
|
|
|
|
~linearity:Linearity.Ltop
|
|
|
|
|
~clock:Cbase
|
|
|
|
|
(Minils.Wvar v))
|
|
|
|
|
(mls_inputs@mls_states))
|
|
|
|
|
@ (List.map
|
|
|
|
|
(fun _ ->
|
|
|
|
|
Minils.mk_extvalue
|
|
|
|
|
~ty:Initial.tbool
|
|
|
|
|
~linearity:Linearity.Ltop
|
|
|
|
|
~clock:Cbase
|
|
|
|
|
(Minils.Wconst(Initial.mk_static_bool true)))
|
|
|
|
|
mls_ctrl),
|
|
|
|
|
None))
|
|
|
|
|
in
|
|
|
|
|
let ctrlr_call =
|
|
|
|
|
Minils.mk_equation ~base_ck:Cbase false ctrlr_pat ctrlr_exp in
|
|
|
|
|
|
|
|
|
|
let ctrlr_inputs =
|
|
|
|
|
(List.map
|
|
|
|
|
(fun v ->
|
|
|
|
|
Signature.mk_arg (Some v) Initial.tbool Linearity.Ltop Signature.Cbase)
|
|
|
|
|
(sig_inputs@sig_states))
|
|
|
|
|
@ (List.map
|
|
|
|
|
(fun v ->
|
|
|
|
|
Signature.mk_arg
|
|
|
|
|
(Some ("p_" ^ v)) Initial.tbool Linearity.Ltop Signature.Cbase)
|
|
|
|
|
sig_ctrl) in
|
|
|
|
|
let ctrlr_outputs =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
List.map
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(fun v ->
|
|
|
|
|
Signature.mk_arg (Some v) Initial.tbool Linearity.Ltop Signature.Cbase)
|
|
|
|
|
sig_ctrl in
|
|
|
|
|
let ctrlr_signature =
|
|
|
|
|
Signature.mk_node Location.no_location ~extern:false
|
|
|
|
|
ctrlr_inputs ctrlr_outputs false false [] in
|
|
|
|
|
(* Add controller into modules *)
|
|
|
|
|
Modules.add_value ctrlr_fun_name ctrlr_signature;
|
|
|
|
|
|
|
|
|
|
let node =
|
|
|
|
|
{ node with
|
|
|
|
|
Minils.n_contract = None;
|
|
|
|
|
Minils.n_local = node.Minils.n_local @ locals_c;
|
|
|
|
|
Minils.n_equs = ctrlr_call :: (node.Minils.n_equs @ eqs_c);
|
|
|
|
|
} in
|
|
|
|
|
node, p
|
2011-03-16 23:25:04 +01:00
|
|
|
|
|
|
|
|
|
let program p =
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let acc_proc, acc_p_desc =
|
2011-03-16 23:25:04 +01:00
|
|
|
|
List.fold_left
|
2012-06-06 15:59:08 +02:00
|
|
|
|
(fun (acc_proc,acc_p_desc) p_desc ->
|
2011-11-21 02:03:45 +01:00
|
|
|
|
match p_desc with
|
|
|
|
|
| Minils.Pnode(node) ->
|
2012-06-06 15:59:08 +02:00
|
|
|
|
let (node,proc) = translate_node node in
|
|
|
|
|
(proc::acc_proc),((Minils.Pnode(node))::acc_p_desc)
|
|
|
|
|
| p -> (acc_proc,p::acc_p_desc))
|
|
|
|
|
([],[])
|
2011-07-27 11:21:34 +02:00
|
|
|
|
p.Minils.p_desc in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let procs = List.rev acc_proc in
|
2011-04-20 11:42:03 +02:00
|
|
|
|
let filename = filename_of_name (modul_to_string p.Minils.p_modname) in
|
2011-03-16 23:25:04 +01:00
|
|
|
|
let dirname = build_path (filename ^ "_z3z") in
|
|
|
|
|
let dir = clean_dir dirname in
|
2012-06-06 15:59:08 +02:00
|
|
|
|
Sigali.Printer.print dir procs;
|
|
|
|
|
{ p with Minils.p_desc = List.rev acc_p_desc }
|
|
|
|
|
|
2011-10-17 15:28:04 +02:00
|
|
|
|
|