Require Import Coqlib Errors.
Require Import Integers Floats AST Linking.
Require Import Values Memory Events Globalenvs Smallstep.
Require Import Op Locations Machblock Conventions Asmblock.
Require Import Asmblockprops.
Require Import PostpassScheduling.
Require Import Asmblockgenproof.
Require Import Axioms.
Require Import Lia.
Local Open Scope error_monad_scope.
Definition match_prog (
p tp:
program) :=
match_program (
fun _
f tf =>
transf_fundef f =
OK tf)
eq p tp.
Lemma transf_program_match:
forall p tp,
transf_program p =
OK tp ->
match_prog p tp.
Proof.
Section PRESERVATION_ASMBLOCK.
Variables prog tprog:
program.
Hypothesis TRANSL:
match_prog prog tprog.
Let ge :=
Genv.globalenv prog.
Let tge :=
Genv.globalenv tprog.
Lemma symbols_preserved:
forall id,
Genv.find_symbol tge id =
Genv.find_symbol ge id.
Proof (
Genv.find_symbol_match TRANSL).
Lemma senv_preserved:
Senv.equiv ge tge.
Proof (
Genv.senv_match TRANSL).
Lemma function_ptr_translated:
forall v f,
Genv.find_funct_ptr ge v =
Some f ->
exists tf,
Genv.find_funct_ptr tge v =
Some tf /\
transf_fundef f =
OK tf.
Proof (
Genv.find_funct_ptr_transf_partial TRANSL).
Inductive match_states:
state ->
state ->
Prop :=
|
match_states_intro:
forall s1 s2,
s1 =
s2 ->
match_states s1 s2.
Lemma prog_main_preserved:
prog_main tprog =
prog_main prog.
Proof (
match_program_main TRANSL).
Lemma prog_main_address_preserved:
(
Genv.symbol_address (
Genv.globalenv prog) (
prog_main prog)
Ptrofs.zero) =
(
Genv.symbol_address (
Genv.globalenv tprog) (
prog_main tprog)
Ptrofs.zero).
Proof.
Lemma transf_initial_states:
forall st1,
initial_state prog st1 ->
exists st2,
initial_state tprog st2 /\
match_states st1 st2.
Proof.
Lemma transf_final_states:
forall st1 st2 r,
match_states st1 st2 ->
final_state st1 r ->
final_state st2 r.
Proof.
intros. inv H0. inv H. econstructor; eauto.
Qed.
Lemma transf_find_bblock:
forall ofs f bb tf,
find_bblock (
Ptrofs.unsigned ofs) (
fn_blocks f) =
Some bb ->
transf_function f =
OK tf ->
exists tbb,
verified_schedule bb =
OK tbb
/\
find_bblock (
Ptrofs.unsigned ofs) (
fn_blocks tf) =
Some tbb.
Proof.
intros.
monadInv H0.
destruct (
zlt Ptrofs.max_unsigned (
size_blocks (
fn_blocks x)));
try (
inv EQ0;
fail).
inv EQ0.
monadInv EQ.
simpl in *.
generalize (
Ptrofs.unsigned ofs)
H x EQ0;
clear ofs H x g EQ0.
induction (
fn_blocks f).
-
intros.
simpl in *.
discriminate.
-
intros.
simpl in *.
monadInv EQ0.
simpl.
destruct (
zlt z 0);
try discriminate.
destruct (
zeq z 0).
+
inv H.
eauto.
+
monadInv EQ0.
exploit IHb;
eauto.
intros (
tbb &
SCH &
FIND).
eexists;
split;
eauto.
inv FIND.
unfold verify_size in EQ0.
destruct (
size a =?
size (
stick_header (
header a)
x))
eqn:
EQSIZE;
try discriminate.
rewrite Z.eqb_eq in EQSIZE;
rewrite EQSIZE.
reflexivity.
Qed.
Lemma stick_header_neutral:
forall a,
a = (
stick_header (
header a) (
no_header a)).
Proof.
Lemma symbol_address_preserved:
forall l ofs,
Genv.symbol_address ge l ofs =
Genv.symbol_address tge l ofs.
Proof.
Lemma verified_schedule_label:
forall bb tbb l,
verified_schedule bb =
OK (
tbb) ->
is_label l bb =
is_label l tbb.
Proof.
intros.
unfold is_label.
monadInv H.
simpl.
auto.
Qed.
Remark label_pos_pvar_none_add:
forall tc l p p' k,
label_pos l (
p+
k)
tc =
None ->
label_pos l (
p'+
k)
tc =
None.
Proof.
induction tc.
-
intros.
simpl.
auto.
-
intros.
simpl in *.
destruct (
is_label _ _)
eqn:
ISLBL.
+
discriminate.
+
pose (
IHtc l p p' (
k +
size a)).
repeat (
rewrite Z.add_assoc in e).
auto.
Qed.
Lemma label_pos_pvar_none:
forall tc l p p',
label_pos l p tc =
None ->
label_pos l p' tc =
None.
Proof.
Remark label_pos_pvar_some_add_add:
forall tc l p p' k k',
label_pos l (
p+
k')
tc =
Some (
p+
k) ->
label_pos l (
p'+
k')
tc =
Some (
p'+
k).
Proof.
induction tc.
-
intros.
simpl in H.
discriminate.
-
intros.
simpl in *.
destruct (
is_label _ _)
eqn:
ISLBL.
+
inv H.
assert (
k =
k')
by lia.
subst.
reflexivity.
+
pose (
IHtc l p p' k (
k' +
size a)).
repeat (
rewrite Z.add_assoc in e).
auto.
Qed.
Lemma label_pos_pvar_some_add:
forall tc l p p' k,
label_pos l p tc =
Some (
p+
k) ->
label_pos l p' tc =
Some (
p'+
k).
Proof.
Remark label_pos_pvar_add:
forall c tc l p p' k,
label_pos l (
p+
k)
c =
label_pos l p tc ->
label_pos l (
p'+
k)
c =
label_pos l p' tc.
Proof.
Lemma label_pos_pvar:
forall c tc l p p',
label_pos l p c =
label_pos l p tc ->
label_pos l p' c =
label_pos l p' tc.
Proof.
Lemma label_pos_head_cons:
forall c bb tbb l tc p,
verified_schedule bb =
OK tbb ->
label_pos l p c =
label_pos l p tc ->
label_pos l p (
bb ::
c) =
label_pos l p (
tbb ::
tc).
Proof.
Lemma label_pos_preserved:
forall c tc l,
transf_blocks c =
OK tc ->
label_pos l 0
c =
label_pos l 0
tc.
Proof.
Lemma label_pos_preserved_blocks:
forall l f tf,
transf_function f =
OK tf ->
label_pos l 0 (
fn_blocks f) =
label_pos l 0 (
fn_blocks tf).
Proof.
Lemma transf_exec_basic:
forall i rs m,
exec_basic ge i rs m =
exec_basic tge i rs m.
Proof.
Lemma transf_exec_body:
forall bdy rs m,
exec_body ge bdy rs m =
exec_body tge bdy rs m.
Proof.
Lemma transf_exec_cfi:
forall f tf cfi rs m,
transf_function f =
OK tf ->
exec_cfi ge f cfi rs m =
exec_cfi tge tf cfi rs m.
Proof.
Lemma transf_exec_exit:
forall f tf sz ex t rs m rs' m',
transf_function f =
OK tf ->
exec_exit ge f sz rs m ex t rs' m' ->
exec_exit tge tf sz rs m ex t rs' m'.
Proof.
Lemma transf_exec_bblock:
forall f tf bb t rs m rs' m',
transf_function f =
OK tf ->
exec_bblock ge f bb rs m t rs' m' ->
exec_bblock tge tf bb rs m t rs' m'.
Proof.
Theorem transf_step_correct:
forall s1 t s2,
step ge s1 t s2 ->
forall s1' (
MS:
match_states s1 s1'),
(
exists s2',
step tge s1' t s2' /\
match_states s2 s2').
Proof.
Theorem transf_program_correct_Asmblock:
forward_simulation (
Asmblock.semantics prog) (
Asmblock.semantics tprog).
Proof.
End PRESERVATION_ASMBLOCK.
Section PRESERVATION.
Variables prog tprog:
program.
Hypothesis TRANSL:
match_prog prog tprog.
Let ge :=
Genv.globalenv prog.
Let tge :=
Genv.globalenv tprog.
Theorem transf_program_correct:
forward_simulation (
Asmblock.semantics prog) (
Asmblock.semantics tprog).
Proof.
End PRESERVATION.