Skip to content

Commit 857a1cb

Browse files
committed
Linearization: correct info on RET instructions
1 parent ef6d357 commit 857a1cb

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

proofs/compiler/linearization.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ Fixpoint linear_i (i:instr) (lbl:label) (lc:lcmd) :=
729729
| Cfor _ _ _ => (lbl, lc)
730730
end.
731731

732-
Definition linear_body (e: stk_fun_extra) (body: cmd) : label * lcmd :=
732+
Definition linear_body (fi: fun_info) (e: stk_fun_extra) (body: cmd) : label * lcmd :=
733733
let: (tail, head, lbl) :=
734734
match sf_return_address e with
735735
| RAreg r _ =>
@@ -741,7 +741,7 @@ Definition linear_body (e: stk_fun_extra) (body: cmd) : label * lcmd :=
741741
( if ra_return is Some ra_return
742742
then [:: lload (mk_var_i ra_return) rspi z;
743743
MkLI dummy_instr_info (Ligoto (Rexpr (Fvar (mk_var_i ra_return)))) ]
744-
else [:: MkLI dummy_instr_info Lret ]
744+
else [:: MkLI (ret_info_of_fun_info fi) Lret ]
745745
, MkLI dummy_instr_info (Llabel 1) ::
746746
(if ra_call is Some ra_call
747747
then [:: lstore rspi z (mk_var_i ra_call) ]
@@ -786,7 +786,7 @@ Definition linear_fd (fd: sfundef) :=
786786
let e := fd.(f_extra) in
787787
let is_export := is_RAnone (sf_return_address e) in
788788
let res := if is_export then f_res fd else [::] in
789-
let body := linear_body e fd.(f_body) in
789+
let body := linear_body fd.(f_info) e fd.(f_body) in
790790
(body.1,
791791
{| lfd_info := f_info fd
792792
; lfd_align := sf_align e

proofs/compiler/linearization_proof.v

+6-6
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,8 @@ Section NUMBER_OF_LABELS.
10801080
Definition linear_i_nb_labels : ∀ i, Pi i :=
10811081
instr_Rect nb_labels_MkI nb_labels_nil nb_labels_cons nb_labels_assign nb_labels_opn nb_labels_syscall nb_labels_if nb_labels_for nb_labels_while nb_labels_call.
10821082

1083-
Lemma linear_body_nb_labels fn e body :
1084-
let: (lbl, lc) := linear_body liparams p fn e body in
1083+
Lemma linear_body_nb_labels fn fi e body :
1084+
let: (lbl, lc) := linear_body liparams p fn fi e body in
10851085
(Z.of_nat (size (label_in_lcmd lc)) <= lbl)%Z.
10861086
Proof.
10871087
rewrite /linear_body.
@@ -1313,8 +1313,8 @@ Section PROOF.
13131313
Proof.
13141314
elim: funcs lbl => [|[f fd] funcs ih] lbl //=.
13151315
set linear_f := (fun _ => _).
1316-
have := ih ((linear_body liparams p f (f_extra fd) (f_body fd)).1)%positive.
1317-
have := ih (lbl + (linear_body liparams p f (f_extra fd) (f_body fd)).1)%positive.
1316+
have := ih ((linear_body liparams p f (f_info fd) (f_extra fd) (f_body fd)).1)%positive.
1317+
have := ih (lbl + (linear_body liparams p f (f_info fd) (f_extra fd) (f_body fd)).1)%positive.
13181318
case: fmap => [nb_lbl' funcs'].
13191319
rewrite Pos.add_assoc => -> ->.
13201320
by rewrite (Pos.add_comm lbl) Pos.add_assoc.
@@ -1331,7 +1331,7 @@ Section PROOF.
13311331
have := fmap_linear_fd_acc ((linear_fd fn f').1)%positive funcs.
13321332
case: fmap ih => [nb_lbl funcs'] /= ih -> /=.
13331333
rewrite size_cat size_map Nat2Z.inj_add.
1334-
have := linear_body_nb_labels p liparams fn (f_extra f') (f_body f').
1334+
have := linear_body_nb_labels p liparams fn (f_info f') (f_extra f') (f_body f').
13351335
case: linear_body => [nb_lbl' lc] /=.
13361336
lia.
13371337
Qed.
@@ -4786,7 +4786,7 @@ Section PROOF.
47864786
have := [elaborate (wunsigned_range (top_stack m))].
47874787
by lia.
47884788
set ls0 := ls_export_initial scs lm vm fn.
4789-
case/(_ m0 sp0 max0 _ _ ls0 lm vm (linear_body liparams p fn fd.(f_extra)
4789+
case/(_ m0 sp0 max0 _ _ ls0 lm vm (linear_body liparams p fn fd.(f_info) fd.(f_extra)
47904790
fd.(f_body)).2 RAnone None (top_stack m)
47914791
(map fst fd.(f_extra).(sf_to_save)) M _ _ erefl).
47924792
- exact: enough_space.

proofs/lang/expr.v

+10-3
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,27 @@ Section CMD_RECT.
433433

434434
End CMD_RECT.
435435

436-
Module FunInfo : TAG.
436+
Module Type FunInfoT <: TAG.
437+
Include TAG.
438+
Parameter ret_info : t -> instr_info.
439+
End FunInfoT.
440+
441+
Module FunInfo : FunInfoT.
437442
Definition t := positive.
438443
Definition witness : t := 1%positive.
444+
Definition ret_info of t := dummy_instr_info.
439445
End FunInfo.
440446

447+
Definition fun_info := FunInfo.t.
448+
Definition ret_info_of_fun_info (fi: fun_info) : instr_info := FunInfo.ret_info fi.
449+
441450
Section ASM_OP.
442451

443452
Context `{asmop:asmOp}.
444453

445454
(* ** Functions
446455
* -------------------------------------------------------------------- *)
447456

448-
Definition fun_info := FunInfo.t.
449-
450457
Class progT := {
451458
extra_fun_t : Type;
452459
extra_prog_t : Type;

proofs/lang/extraction.v

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Extract Constant expr.InstrInfo.is_inline => "IInfo.is_inline".
3232
Extract Constant expr.InstrInfo.var_info_of_ii => "IInfo.var_info_of_ii".
3333
Extract Constant expr.instr_info => "IInfo.t".
3434
Extract Constant expr.fun_info => "FInfo.t".
35+
Extract Constant expr.ret_info_of_fun_info => "FInfo.ret_info".
3536
Extract Constant waes.MixColumns => "(fun _ -> failwith ""MixColumns is not implemented"")".
3637
Extract Constant waes.InvMixColumns => "(fun _ -> failwith ""InvMixColumns not implemented"")".
3738

0 commit comments

Comments
 (0)