Require Import Smallstep.
Require Import Machregs.
Require Import Asm.
Require Import Integers.
Require Import List.
Require Import ZArith.
Require Import Memtype.
Require Import Memory.
Require Import Archi.
Require Import Coqlib.
Require Import AST.
Require Import Globalenvs.
Require Import Events.
Require Import Values.
Require Import Conventions1.
Require Import AsmFacts.
Require Import RealAsm PseudoInstructions.
Require Import RealAsmproof2.
Require Import AsmRegs.
Definition match_prog (
p:
Asm.program) (
tp:
Asm.program) :=
Linking.match_program (
fun _ f tf =>
tf =
transf_fundef f)
eq p tp.
Lemma transf_program_match:
forall p tp,
transf_program p =
tp ->
match_prog p tp.
Proof.
Section WITHMEMORYMODEL.
Context `{
memory_model:
Mem.MemoryModel }.
Existing Instance inject_perm_upto_writable.
Context `{
external_calls_ops : !
ExternalCallsOps mem }.
Context `{!
EnableBuiltins mem}.
Existing Instance mem_accessors_default.
Existing Instance symbols_inject_instance.
Context `{
external_calls_props : !
ExternalCallsProps mem
(
memory_model_ops :=
memory_model_ops)
}.
Variable prog tprog:
Asm.program.
Hypothesis TRANSF:
Linking.match_program (
fun _ f1 f2 =>
f2 =
transf_fundef f1)
eq prog tprog.
Let ge :=
Genv.globalenv prog.
Let tge :=
Genv.globalenv tprog.
Lemma symbols_preserved:
forall (
s:
ident),
Genv.find_symbol tge s =
Genv.find_symbol ge s.
Proof (
Genv.find_symbol_match TRANSF).
Lemma senv_preserved:
Senv.equiv ge tge.
Proof (
Genv.senv_match TRANSF).
Lemma genv_next_preserved:
Genv.genv_next tge =
Genv.genv_next ge.
Proof.
Lemma functions_translated:
forall b f,
Genv.find_funct_ptr ge b =
Some f ->
Genv.find_funct_ptr tge b =
Some (
transf_fundef f).
Proof.
Lemma functions_transl:
forall fb f,
Genv.find_funct_ptr ge fb =
Some (
Internal f) ->
Genv.find_funct_ptr tge fb =
Some (
Internal (
transf_function f)).
Proof.
Lemma public_preserved:
forall id :
ident,
Genv.public_symbol (
Genv.globalenv tprog)
id =
Genv.public_symbol (
Genv.globalenv prog)
id.
Proof.
Axiom instr_size_alloc:
forall sz pub ora r i a rr,
instr_size (
Pallocframe sz pub ora) =
instr_size (
Plea r a) + (
instr_size (
Psub rr rr i)).
Axiom instr_size_free:
forall sz ora r s,
instr_size (
Pfreeframe sz ora) =
instr_size (
Padd r r s).
Axiom instr_size_load_parent_pointer:
forall r s rd a,
instr_size (
Pload_parent_pointer r s) =
instr_size (
Plea rd a).
Lemma transf_instr_size:
forall i,
instr_size i =
code_size (
transf_instr i).
Proof.
Inductive code_at:
Z ->
code ->
code ->
Prop :=
|
code_at_nil o c:
code_at o c nil
|
code_at_cons o c i c':
find_instr o c =
Some i ->
code_at (
o +
instr_size i)
c c' ->
code_at o c (
i::
c').
Lemma code_size_app:
forall c1 c2,
code_size (
c1 ++
c2) =
code_size c1 +
code_size c2.
Proof.
induction c1; simpl; intros; eauto. rewrite IHc1. omega.
Qed.
Lemma code_at_app:
forall b a c,
code_at (
code_size a) (
a ++ (
b ++
c))
b.
Proof.
Lemma code_at_next:
forall a i b,
code_at (
instr_size i) (
i ::
a ++
b)
a.
Proof.
Lemma code_at_shift:
forall i a c o,
code_at (
o -
code_size a)
c i ->
code_at o (
a ++
c)
i.
Proof.
Lemma find_instr_transl:
forall c o i,
find_instr o c =
Some i ->
code_at o (
transf_code c) (
transf_instr i).
Proof.
Definition id_instr (
i:
instruction) :
bool :=
match i with
|
Pallocframe _ _ _
|
Pfreeframe _ _
|
Pload_parent_pointer _ _ =>
false
|
_ =>
true
end.
Hypothesis WF:
wf_asm_prog ge.
Hypothesis prog_no_rsp:
asm_prog_no_rsp ge.
Lemma exec_instr_Plea:
forall ge f r a (
rs:
regset)
m,
exec_instr ge f (
Plea r a)
rs m =
Next (
nextinstr (
rs #
r <- (
eval_addrmode ge a rs)) (
Ptrofs.repr (
instr_size (
Plea r a))))
m.
Proof.
Lemma ptrofs_eq_unsigned:
forall a b,
Ptrofs.unsigned a =
Ptrofs.unsigned b ->
a =
b.
Proof.
Lemma eval_addrmode_offset_ptr:
forall (
rs:
regset) (
r:
ireg)
z (
RSPPTR:
exists b o,
rs r =
Vptr b o),
eval_addrmode (
Genv.globalenv tprog) (
linear_addr r z)
rs =
Val.offset_ptr (
rs r) (
Ptrofs.repr z).
Proof.
Lemma id_instr_transf:
forall i,
id_instr i =
true ->
transf_instr i =
i ::
nil.
Proof.
destruct i; simpl; intros; congruence.
Qed.
Lemma eval_addrmode64_senv_equiv:
forall (
ge1 ge2:
genv) (
EQ:
Senv.equiv ge1 ge2)
a rs,
eval_addrmode64 ge1 a rs =
eval_addrmode64 ge2 a rs.
Proof.
Lemma eval_addrmode32_senv_equiv:
forall (
ge1 ge2:
genv) (
EQ:
Senv.equiv ge1 ge2)
a rs,
eval_addrmode32 ge1 a rs =
eval_addrmode32 ge2 a rs.
Proof.
Lemma eval_addrmode_senv_equiv:
forall (
ge1 ge2:
genv) (
EQ:
Senv.equiv ge1 ge2)
a rs,
eval_addrmode ge1 a rs =
eval_addrmode ge2 a rs.
Proof.
Lemma exec_load_senv_equiv:
forall (
ge1 ge2:
genv) (
EQ:
Senv.equiv ge1 ge2)
chunk m a rs r o,
exec_load ge1 chunk m a rs r o =
exec_load ge2 chunk m a rs r o.
Proof.
Lemma exec_store_senv_equiv:
forall (
ge1 ge2:
genv) (
EQ:
Senv.equiv ge1 ge2)
chunk m a rs r lr o,
exec_store ge1 chunk m a rs r lr o =
exec_store ge2 chunk m a rs r lr o.
Proof.
Lemma label_pos_app:
forall a b l o,
~
In (
Plabel l)
a ->
label_pos l o (
a ++
b) =
label_pos l (
o +
code_size a)
b.
Proof.
induction a;
simpl;
intros;
eauto.
rewrite Z.add_0_r;
auto.
destr.
destruct a;
simpl in Heqb0;
try congruence.
destr_in Heqb0.
rewrite IHa;
auto.
f_equal.
omega.
Qed.
Lemma label_pos_transf:
forall c l o,
label_pos l o c =
label_pos l o (
transf_code c).
Proof.
induction c;
simpl;
intros;
eauto.
unfold transf_code.
simpl.
fold (
transf_code c).
destr.
-
destruct a;
simpl in Heqb;
try congruence.
destr_in Heqb.
subst.
simpl.
rewrite peq_true.
reflexivity.
-
rewrite label_pos_app.
rewrite <-
transf_instr_size.
auto.
intro IN.
destruct a;
try now (
simpl in *;
unfold Padd,
Psub,
Plea in *;
simpl in *;
repeat destr_in IN;
try intuition congruence).
simpl in *.
destr_in Heqb.
simpl in *.
unfold Padd,
Psub,
Plea in *.
simpl in *.
repeat destr_in IN.
intuition congruence.
unfold Padd,
Psub,
Plea in *.
repeat destr_in H.
intuition congruence.
unfold Padd,
Psub,
Plea in *.
repeat destr_in H.
Qed.
Lemma goto_label_senv_equiv:
forall f l rs m rs'
m',
goto_label ge f l rs m =
Next rs'
m' ->
goto_label tge (
transf_function f)
l rs m =
Next rs'
m'.
Proof.
Lemma functions_only_translated:
forall b,
Genv.find_funct_ptr ge b =
None ->
Genv.find_funct_ptr tge b =
None.
Proof.
Lemma goto_label_senv_equiv':
forall f l rs m,
goto_label ge f l rs m =
Stuck ->
goto_label tge (
transf_function f)
l rs m =
Stuck.
Proof.
Lemma goto_label_eq:
forall f l rs m,
goto_label ge f l rs m =
goto_label tge (
transf_function f)
l rs m.
Proof.
Lemma eval_ros_eq:
forall ros rs,
eval_ros ge ros rs =
eval_ros tge ros rs.
Proof.
Lemma exec_instr_senv_equiv:
forall f i rs m (
ID :
id_instr i =
true),
exec_instr ge f i rs m =
exec_instr tge (
transf_function f)
i rs m.
Proof.
Lemma pseudo_instructions_step:
forall s1 t s2
(
STEP :
step (
Genv.globalenv prog)
s1 t s2)
(
INV:
real_asm_inv prog s1),
plus step (
Genv.globalenv tprog)
s1 t s2.
Proof.
Theorem pseudo_instructions_correct rs:
forward_simulation (
RealAsm.semantics prog rs) (
RealAsm.semantics tprog rs).
Proof.
End WITHMEMORYMODEL.