Skip to content

Commit cdd0c5e

Browse files
committed
Use UID to find unfolded vector formals instead of flag when dealing with output variables
1 parent 7340fa9 commit cdd0c5e

File tree

3 files changed

+24
-51
lines changed

3 files changed

+24
-51
lines changed

compiler/src/CL_vsimpl.ml

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ module GhostVector = struct
128128
type vector =
129129
| U16x16
130130

131-
let get_vghost ghosts gname b =
132-
let vghost = List.find (fun (v, _) -> v.v_name = gname) (if b then List.rev ghosts else ghosts) in (* FIXME: DIRTY HACK *)
131+
let get_vghost ghosts gname =
132+
let vghost = List.find (fun (v, _) -> v.v_name = gname) ghosts in
133133
vghost
134134

135135
let get_unfolded_vector_namei v i =
136-
String.concat "_" [v.v_name; "v" ; string_of_int i]
136+
String.concat "_" [v.v_name; (string_of_uid v.v_id); "v" ; string_of_int i]
137137

138138
let rec replace_vghosts_rexp ghosts r =
139-
let aux (v, ty) i b =
139+
let aux (v, ty) i =
140140
let name = get_unfolded_vector_namei v i in
141-
let v' = get_vghost ghosts name b in
141+
let v' = get_vghost ghosts name in
142142
Rvar v'
143143
in
144144
match r with
@@ -158,8 +158,11 @@ module GhostVector = struct
158158
let e2' = replace_vghosts_rexp ghosts e2 in
159159
Rbinop(e1', s, e2')
160160
| RVget(e,c) -> r
161-
| UnPack (e,us,i,b) ->
162-
aux e i b
161+
| UnPack (e,us,i) ->
162+
aux e i
163+
| Rlimbs (c, e) ->
164+
let e' = List.map (replace_vghosts_rexp ghosts) e in
165+
Rlimbs (c, e')
163166

164167
let rec unfold_ghosts_rpred ghosts pre =
165168
match pre with
@@ -186,9 +189,9 @@ module GhostVector = struct
186189
List.map (unfold_ghosts_rpred ghosts) pre
187190

188191
let rec replace_vghosts_eexp ghosts e =
189-
let aux (v, ty) i b =
192+
let aux (v, ty) i =
190193
let name = get_unfolded_vector_namei v i in
191-
let v' = get_vghost ghosts name b in
194+
let v' = get_vghost ghosts name in
192195
Ivar v'
193196
in
194197
match e with
@@ -204,8 +207,8 @@ module GhostVector = struct
204207
| Ilimbs (c, l) ->
205208
let l' = List.map (replace_vghosts_eexp ghosts) l in
206209
Ilimbs (c, l')
207-
| IUnPack (e, us, i, b) ->
208-
aux e i b
210+
| IUnPack (e, us, i) ->
211+
aux e i
209212

210213
let rec unfold_ghosts_epred ghosts pre =
211214
match pre with
@@ -280,29 +283,6 @@ module GhostVector = struct
280283
| h::t ->
281284
[unfold_clauses h formals] @ (unfold_cfg_clauses t formals)
282285
| [] -> []
283-
284-
(* CHECK ME: CL doesn't support vector/arrays as arguments it seems; see preliminary.cl *)
285-
(*
286-
let unfold_vectors_list formals ret_vars =
287-
let aux ((v,ty) as tv) =
288-
let mk_vector = Annot.filter_string_list None ["u16x16", U16x16] in
289-
match Annot.ensure_uniq1 "vect" mk_vector (v.v_annot) with
290-
| None -> [tv],[],[]
291-
| Some U16x16 ->
292-
let (l_16x16, lty_16x16) as l16x16 = I.var_to_tyvar ~vector:(16,16) v in
293-
let ll16x16 = Llvar l16x16 in
294-
if List.exists (is_eq_tyvar tv) ret_vars then
295-
let a_1x256 = Avatome [Avar tv] in
296-
[l16x16], [], [cast lty_16x16 ll16x16 a_1x256]
297-
else
298-
let vl16x16 = Avar l16x16 in
299-
[l16x16], [cast ty (Llvar tv) vl16x16],[]
300-
in
301-
List.fold_left (fun (acc1,acc2,acc3) tv ->
302-
let fs,ispre,ispost = aux tv in
303-
fs @ acc1, ispre @ acc2, ispost @ acc3)
304-
([],[],[]) formals
305-
*)
306286
end
307287

308288
module SimplVector = struct

compiler/src/toCL.ml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module CL = struct
8484
| Iunop of string * eexp
8585
| Ibinop of eexp * string * eexp
8686
| Ilimbs of const * eexp list
87-
| IUnPack of tyvar * int * int * bool
87+
| IUnPack of tyvar * int * int
8888

8989
let (!-) e1 = Iunop ("-", e1)
9090
let (-) e1 e2 = Ibinop (e1, "-", e2)
@@ -134,7 +134,7 @@ module CL = struct
134134
| Runop of string * rexp
135135
| Rbinop of rexp * string * rexp
136136
| RVget of tyvar * const
137-
| UnPack of tyvar * int * int * bool
137+
| UnPack of tyvar * int * int
138138
| Rlimbs of const * rexp list
139139

140140
let const (i1,z1) = Rconst (i1,z1)
@@ -557,9 +557,7 @@ module I (S:S): I = struct
557557
| PappN(Oabstract {pa_name="ze_16_32"}, [v]) -> Ruext (!> v, 16)
558558
| PappN(Oabstract {pa_name="limbs_4u64"}, [q]) -> Rlimbs ((Z.of_int 64), (List.map (!>) (extract_list q [])))
559559
| PappN(Oabstract {pa_name="u256_as_16u16"}, [Pvar x ; Pconst z]) ->
560-
UnPack (to_var ~sign x, 16, Z.to_int z, false)
561-
| PappN(Oabstract {pa_name="u256_as_16u16"}, [Presult (_, x) ; Pconst z]) ->
562-
UnPack (to_var ~sign x, 16, Z.to_int z, true)
560+
UnPack (to_var ~sign x, 16, Z.to_int z)
563561
| _ -> error e
564562

565563
let rec gexp_to_rpred ?(sign=S.s) e : CL.R.rpred =
@@ -579,8 +577,8 @@ module I (S:S): I = struct
579577
| Papp2(Olt int, e1, e2) -> ult !> e1 !> e2
580578
| Papp2(Ogt int, e1, e2) -> ugt !> e1 !> e2
581579
| Pif(_, e1, e2, e3) -> RPand [RPor [RPnot !>> e1; !>> e2];RPor[ !>> e1; !>> e3]]
582-
| Pabstract ({name="eq"}, [e1;e2]) -> eq !> e1 !> e2
583-
| Pabstract ({name="eqsmod"} as _opa, [e1;e2;e3]) -> RPeqsmod (!> e1, !> e2, !> e3)
580+
| PappN (Oabstract {pa_name="eq"}, [e1;e2]) -> eq !> e1 !> e2
581+
| PappN (Oabstract {pa_name="eqsmod"} as _opa, [e1;e2;e3]) -> RPeqsmod (!> e1, !> e2, !> e3)
584582
| _ -> error e
585583

586584
let rec get_const x =
@@ -696,11 +694,8 @@ module I (S:S): I = struct
696694
mull !> b (power (Ivar v) !> a)
697695
| PappN (Oabstract {pa_name="mon0"}, [b]) ->
698696
!> b
699-
| PappN (Oabstract {name="u256_as_16u16"}, [Pvar x; Pconst z]) ->
700-
IUnPack (to_var ~sign x, 16, Z.to_int z, false)
701-
| Pabstract ({name="u256_as_16u16"}, [Presult (_, x) ; Pconst z]) ->
702-
IUnPack (to_var ~sign x, 16, Z.to_int z, true)
703-
| Presult (_,x) -> Ivar (to_var ~sign x)
697+
| PappN (Oabstract {pa_name="u256_as_16u16"}, [Pvar x; Pconst z]) ->
698+
IUnPack (to_var ~sign x, 16, Z.to_int z)
704699
| _ -> error e
705700

706701
let rec gexp_to_epred env ?(sign=S.s) e :CL.I.epred list =
@@ -1886,11 +1881,10 @@ module Mk(O:BaseOp) = struct
18861881
[CL.Instr.assert_ pre_cl], [CL.Instr.assume post_cl]
18871882
in
18881883
(* FIXME: How are we sure that the variables in r are fresh ? *)
1889-
r , pre_cl @ post_cl
18901884
let formals = List.map O.I.var_to_tyvar fd.f_args in
18911885
let cond (a,_) (x,_) = (x.v_name = a.v_name) && (x.v_id = a.v_id) in
18921886
let formals = filter_add cond formals (List.map O.I.gexp_to_var params) in
1893-
r , formals , [CL.Instr.assert_ pre_cl] @ [CL.Instr.assume post_cl]
1887+
r , formals, pre_cl @ post_cl
18941888

18951889
| Cassgn (a, _, _, e) ->
18961890
begin
@@ -1934,7 +1928,6 @@ module Mk(O:BaseOp) = struct
19341928
let post = sub_fun_returns ci.f_ires r post in
19351929
let post = to_clause env post in
19361930
pre, post in
1937-
let lval,prog = pp_c env fds fd.f_body in
19381931
let lval,formals_args,prog = pp_c env fds fd.f_body in
19391932
let formals_lval = List.map (fun x -> O.I.get_lval (O.I.glval_to_lval x)) lval in
19401933
let cond (a,_) (x,_) = (x.v_name = a.v_name) && (x.v_id = a.v_id) in

compiler/src/toCL.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module CL : sig
2323
| Iunop of string * eexp
2424
| Ibinop of eexp * string * eexp
2525
| Ilimbs of const * eexp list
26-
| IUnPack of tyvar * int * int * bool
26+
| IUnPack of tyvar * int * int
2727

2828
type epred =
2929
| Eeq of eexp * eexp
@@ -41,7 +41,7 @@ module CL : sig
4141
| Runop of string * rexp
4242
| Rbinop of rexp * string * rexp
4343
| RVget of tyvar * const
44-
| UnPack of tyvar * int * int * bool
44+
| UnPack of tyvar * int * int
4545
| Rlimbs of const * rexp list
4646

4747
type rpred =

0 commit comments

Comments
 (0)