Skip to content

Commit 2bc52a0

Browse files
committed
Merge branch 'main' into refactor_codepos
2 parents 8519e7a + 1b94156 commit 2bc52a0

8 files changed

Lines changed: 322 additions & 122 deletions

File tree

src/ecCoreModules.ml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ let lv_of_expr e =
5555
LvTuple (List.map (fun e -> EcTypes.destr_var e, e_ty e) pvs)
5656
| _ -> failwith "failed to construct lv from expr"
5757

58+
let explode_assgn (lv : lvalue) (e : expr) : ((prog_var * ty) * expr) list =
59+
match lv, e with
60+
| LvVar lv, e ->
61+
[(lv, e)]
62+
| LvTuple lvs, { e_node = Etuple es } ->
63+
List.combine lvs es
64+
| LvTuple lvs, e ->
65+
List.mapi (fun i (pv, ty) ->
66+
((pv, ty), e_proj_simpl e i ty)) lvs
67+
5868
(* -------------------------------------------------------------------- *)
5969
type instr = EcAst.instr
6070

@@ -161,6 +171,14 @@ let is_while = _is_of_get get_while
161171
let is_match = _is_of_get get_match
162172
let is_raise = _is_of_get get_raise
163173

174+
(* -------------------------------------------------------------------- *)
175+
let i_asgn_of_pve (pve : ((prog_var * ty) * expr) list) : instr option =
176+
let lvs, es = List.split pve in
177+
178+
lvs
179+
|> lv_of_list
180+
|> omap (fun lvs -> i_asgn (lvs, e_tuple es))
181+
164182
(* -------------------------------------------------------------------- *)
165183
let i_iter (f : instr -> unit) =
166184
let rec i_iter (i : instr) =
@@ -181,6 +199,24 @@ let i_iter (f : instr -> unit) =
181199

182200
in fun (i : instr) -> i_iter i
183201

202+
(* -------------------------------------------------------------------- *)
203+
let i_map_expr (tx : expr -> expr) =
204+
let rec doit (i : instr) =
205+
match i.i_node with
206+
| Sasgn (lv, e) -> i_asgn (lv, (tx e))
207+
| Sif (c, t, f) -> i_if (tx c, doit_s t, doit_s f)
208+
| Smatch (e, cs) -> i_match (tx e, List.map (snd_map doit_s) cs)
209+
| Swhile (c, bd) -> i_while (tx c, doit_s bd)
210+
| Srnd (lv, e) -> i_rnd (lv, tx e)
211+
| Sraise e -> i_raise (tx e)
212+
| Sabstract (_ : memory) -> i
213+
| Scall (lv, f, args) -> i_call (lv, f, List.map tx args)
214+
215+
and doit_s (s : stmt) =
216+
stmt (List.map doit s.s_node) in
217+
218+
fun i -> doit i
219+
184220
(* -------------------------------------------------------------------- *)
185221
module Uninit = struct (* FIXME: generalize this for use in ecPV *)
186222
let e_pv e =

src/ecCoreModules.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ val lv_to_list : lvalue -> prog_var list
1515
val lv_to_ty_list : lvalue -> (prog_var * ty) list
1616
val name_of_lv : lvalue -> string
1717
val lv_of_expr : expr -> lvalue
18+
val explode_assgn : lvalue -> expr -> ((prog_var * ty) * expr) list
1819

1920
(* --------------------------------------------------------------------- *)
2021
type instr = EcAst.instr
@@ -76,8 +77,12 @@ val is_while : instr -> bool
7677
val is_match : instr -> bool
7778
val is_raise : instr -> bool
7879

80+
(* -------------------------------------------------------------------- *)
81+
val i_asgn_of_pve : ((prog_var * ty) * expr) list -> instr option
82+
7983
(* -------------------------------------------------------------------- *)
8084
val i_iter : (instr -> unit) -> instr -> unit
85+
val i_map_expr : (expr -> expr) -> instr -> instr
8186

8287
(* -------------------------------------------------------------------- *)
8388
val get_uninit_read : stmt -> Sx.t

src/ecParser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,8 +3003,8 @@ interleave_info:
30033003
| INTERLEAVE info=loc(interleave_info)
30043004
{ Pinterleave info }
30053005

3006-
| CFOLD s=side? c=codepos n=word?
3007-
{ Pcfold (s, c, n) }
3006+
| CFOLD eager=boption(STAR) side=side? start=codepos length=word?
3007+
{ Pcfold { side; start; length; eager; } }
30083008

30093009
| RND s=side? info=rnd_info c=prefix(COLON, semrndpos)?
30103010
{ Prnd (s, c, info) }

src/ecParsetree.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ type phltactic =
774774
| Pcond of pcond_info
775775
| Pmatch of matchmode
776776
| Pswap of ((oside * pswap_kind) located list)
777-
| Pcfold of (oside * pcodepos * int option)
777+
| Pcfold of pcfold
778778
| Pinline of inline_info
779779
| Poutline of outline_info
780780
| Pinterleave of interleave_info located
@@ -829,6 +829,12 @@ and rwprgm = [
829829
| `IdAssign of pcodepos * pqsymbol
830830
]
831831

832+
and pcfold =
833+
{ side : oside
834+
; start : pcodepos
835+
; length : int option
836+
; eager : bool }
837+
832838
(* -------------------------------------------------------------------- *)
833839
type include_exclude = [ `Include | `Exclude ]
834840
type pdbmap1 = {

0 commit comments

Comments
 (0)