Global environments are a component of the dynamic semantics of
all languages involved in the compiler. A global environment
maps symbol names (names of functions and of global variables)
to the corresponding memory addresses. It also maps memory addresses
of functions to the corresponding function descriptions.
Global environments, along with the initial memory state at the beginning
of program execution, are built from the program of interest, as follows:
-
A distinct memory address is assigned to each function of the program.
These function addresses use negative numbers to distinguish them from
addresses of memory blocks. The associations of function name to function
address and function address to function description are recorded in
the global environment.
-
For each global variable, a memory block is allocated and associated to
the name of the variable.
These operations reflect (at a high level of abstraction) what takes
place during program linking and program loading in a real operating
system.
Require Recdef.
Require Import Zwf.
Require Import Axioms.
Require Import Coqlib.
Require Import Errors.
Require Import Maps.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Values.
Require Import Memory.
Notation "
s #1" := (
fst s) (
at level 9,
format "
s '#1'") :
pair_scope.
Notation "
s #2" := (
snd s) (
at level 9,
format "
s '#2'") :
pair_scope.
Local Open Scope pair_scope.
Local Open Scope error_monad_scope.
Set Implicit Arguments.
Module Genv.
Global environments
Section GENV.
Variable F:
Type.
(* The type of function descriptions *)
Variable V:
Type.
(* The type of information attached to variables *)
The type of global environments.
Record t:
Type :=
mkgenv {
genv_symb:
PTree.t block;
(* mapping symbol -> block *)
genv_funs:
ZMap.t (
option F);
(* mapping function pointer -> definition *)
genv_vars:
ZMap.t (
option (
globvar V));
(* mapping variable pointer -> info *)
genv_nextfun:
block;
(* next function pointer *)
genv_nextvar:
block;
(* next variable pointer *)
genv_nextfun_neg:
genv_nextfun < 0;
genv_nextvar_pos:
genv_nextvar > 0;
genv_symb_range:
forall id b,
PTree.get id genv_symb =
Some b ->
b <> 0 /\
genv_nextfun <
b /\
b <
genv_nextvar;
genv_funs_range:
forall b f,
ZMap.get b genv_funs =
Some f ->
genv_nextfun <
b < 0;
genv_vars_range:
forall b v,
ZMap.get b genv_vars =
Some v -> 0 <
b <
genv_nextvar;
genv_vars_inj:
forall id1 id2 b,
PTree.get id1 genv_symb =
Some b ->
PTree.get id2 genv_symb =
Some b ->
id1 =
id2
}.
Lookup functions
find_symbol ge id returns the block associated with the given name, if any
Definition find_symbol (
ge:
t) (
id:
ident) :
option block :=
PTree.get id ge.(
genv_symb).
find_funct_ptr ge b returns the function description associated with
the given address.
Definition find_funct_ptr (
ge:
t) (
b:
block) :
option F :=
ZMap.get b ge.(
genv_funs).
find_funct is similar to find_funct_ptr, but the function address
is given as a value, which must be a pointer with offset 0.
Definition find_funct (
ge:
t) (
v:
val) :
option F :=
match v with
|
Vptr b ofs =>
if Int.eq_dec ofs Int.zero then find_funct_ptr ge b else None
|
_ =>
None
end.
invert_symbol ge b returns the name associated with the given block, if any
Definition invert_symbol (
ge:
t) (
b:
block) :
option ident :=
PTree.fold
(
fun res id b' =>
if eq_block b b'
then Some id else res)
ge.(
genv_symb)
None.
find_var_info ge b returns the information attached to the variable
at address b.
Definition find_var_info (
ge:
t) (
b:
block) :
option (
globvar V) :=
ZMap.get b ge.(
genv_vars).
Constructing the global environment
Program Definition add_function (
ge:
t) (
idf:
ident *
F) :
t :=
@
mkgenv
(
PTree.set idf#1
ge.(
genv_nextfun)
ge.(
genv_symb))
(
ZMap.set ge.(
genv_nextfun) (
Some idf#2)
ge.(
genv_funs))
ge.(
genv_vars)
(
ge.(
genv_nextfun) - 1)
ge.(
genv_nextvar)
_ _ _ _ _ _.
Next Obligation.
destruct ge; simpl; omega.
Qed.
Next Obligation.
destruct ge; auto.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite PTree.gsspec in H.
destruct (
peq id i).
inv H.
unfold block;
omega.
exploit genv_symb_range0;
eauto.
unfold block;
omega.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite ZMap.gsspec in H.
destruct (
ZIndexed.eq b genv_nextfun0).
subst;
omega.
exploit genv_funs_range0;
eauto.
omega.
Qed.
Next Obligation.
destruct ge; eauto.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite PTree.gsspec in H.
rewrite PTree.gsspec in H0.
destruct (
peq id1 i);
destruct (
peq id2 i).
congruence.
exploit genv_symb_range0;
eauto.
intros [
A B].
inv H.
omegaContradiction.
exploit genv_symb_range0;
eauto.
intros [
A B].
inv H0.
omegaContradiction.
eauto.
Qed.
Program Definition add_variable (
ge:
t) (
idv:
ident *
globvar V) :
t :=
@
mkgenv
(
PTree.set idv#1
ge.(
genv_nextvar)
ge.(
genv_symb))
ge.(
genv_funs)
(
ZMap.set ge.(
genv_nextvar) (
Some idv#2)
ge.(
genv_vars))
ge.(
genv_nextfun)
(
ge.(
genv_nextvar) + 1)
_ _ _ _ _ _.
Next Obligation.
destruct ge; auto.
Qed.
Next Obligation.
destruct ge; simpl; omega.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite PTree.gsspec in H.
destruct (
peq id i).
inv H.
unfold block;
omega.
exploit genv_symb_range0;
eauto.
unfold block;
omega.
Qed.
Next Obligation.
destruct ge; eauto.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite ZMap.gsspec in H.
destruct (
ZIndexed.eq b genv_nextvar0).
subst;
omega.
exploit genv_vars_range0;
eauto.
omega.
Qed.
Next Obligation.
destruct ge;
simpl in *.
rewrite PTree.gsspec in H.
rewrite PTree.gsspec in H0.
destruct (
peq id1 i);
destruct (
peq id2 i).
congruence.
exploit genv_symb_range0;
eauto.
intros [
A B].
inv H.
omegaContradiction.
exploit genv_symb_range0;
eauto.
intros [
A B].
inv H0.
omegaContradiction.
eauto.
Qed.
Program Definition empty_genv :
t :=
@
mkgenv (
PTree.empty block) (
ZMap.init None) (
ZMap.init None) (-1) 1
_ _ _ _ _ _.
Next Obligation.
omega.
Qed.
Next Obligation.
omega.
Qed.
Next Obligation.
Next Obligation.
rewrite ZMap.gi in H.
discriminate.
Qed.
Next Obligation.
rewrite ZMap.gi in H.
discriminate.
Qed.
Next Obligation.
Definition add_functions (
ge:
t) (
fl:
list (
ident *
F)) :
t :=
List.fold_left add_function fl ge.
Lemma add_functions_app :
forall ge fl1 fl2,
add_functions ge (
fl1 ++
fl2) =
add_functions (
add_functions ge fl1)
fl2.
Proof.
Definition add_variables (
ge:
t) (
vl:
list (
ident *
globvar V)) :
t :=
List.fold_left add_variable vl ge.
Lemma add_variables_app :
forall ge vl1 vl2 ,
add_variables ge (
vl1 ++
vl2) =
add_variables (
add_variables ge vl1)
vl2.
Proof.
Definition globalenv (
p:
program F V) :=
add_variables (
add_functions empty_genv p.(
prog_funct))
p.(
prog_vars).
Properties of the operations over global environments
Theorem find_funct_inv:
forall ge v f,
find_funct ge v =
Some f ->
exists b,
v =
Vptr b Int.zero.
Proof.
intros until f;
unfold find_funct.
destruct v;
try congruence.
destruct (
Int.eq_dec i Int.zero);
try congruence.
intros.
exists b;
congruence.
Qed.
Theorem find_funct_find_funct_ptr:
forall ge b,
find_funct ge (
Vptr b Int.zero) =
find_funct_ptr ge b.
Proof.
Theorem find_symbol_exists:
forall p id gv,
In (
id,
gv) (
prog_vars p) ->
exists b,
find_symbol (
globalenv p)
id =
Some b.
Proof.
Theorem find_var_exists:
forall p id gv,
list_norepet (
prog_var_names p) ->
In (
id,
gv) (
prog_vars p) ->
exists b,
find_symbol (
globalenv p)
id =
Some b
/\
find_var_info (
globalenv p)
b =
Some gv.
Proof.
Remark add_variables_inversion :
forall vs e x b,
find_symbol (
add_variables e vs)
x =
Some b ->
In x (
var_names vs) \/
find_symbol e x =
Some b.
Proof.
induction vs;
intros.
simpl in H.
intuition.
simpl in H.
destruct (
IHvs _ _ _ H).
left.
simpl.
intuition.
destruct a as [
y ?].
unfold add_variable,
find_symbol in H0.
simpl in H0.
rewrite PTree.gsspec in H0.
destruct (
peq x y);
subst;
simpl;
intuition.
Qed.
Remark add_functions_inversion :
forall fs e x b,
find_symbol (
add_functions e fs)
x =
Some b ->
In x (
funct_names fs) \/
find_symbol e x =
Some b.
Proof.
induction fs;
intros.
simpl in H.
intuition.
simpl in H.
destruct (
IHfs _ _ _ H).
left.
simpl.
intuition.
destruct a as [
y ?].
unfold add_variable,
find_symbol in H0.
simpl in H0.
rewrite PTree.gsspec in H0.
destruct (
peq x y);
subst;
simpl;
intuition.
Qed.
Lemma find_symbol_inversion :
forall p x b,
find_symbol (
globalenv p)
x =
Some b ->
In x (
prog_var_names p ++
prog_funct_names p).
Proof.
Remark add_functions_same_symb:
forall id fl ge,
~
In id (
funct_names fl) ->
find_symbol (
add_functions ge fl)
id =
find_symbol ge id.
Proof.
induction fl;
simpl;
intros.
auto.
rewrite IHfl.
unfold find_symbol;
simpl.
apply PTree.gso.
intuition.
intuition.
Qed.
Remark add_functions_same_address:
forall b fl ge,
b >
ge.(
genv_nextfun) ->
find_funct_ptr (
add_functions ge fl)
b =
find_funct_ptr ge b.
Proof.
induction fl;
simpl;
intros.
auto.
rewrite IHfl.
unfold find_funct_ptr;
simpl.
apply ZMap.gso.
red;
intros;
subst b;
omegaContradiction.
simpl.
omega.
Qed.
Remark add_variables_same_symb:
forall id vl ge,
~
In id (
var_names vl) ->
find_symbol (
add_variables ge vl)
id =
find_symbol ge id.
Proof.
induction vl;
simpl;
intros.
auto.
rewrite IHvl.
unfold find_symbol;
simpl.
apply PTree.gso.
intuition.
intuition.
Qed.
Remark add_variables_same_address:
forall b vl ge,
b <
ge.(
genv_nextvar) ->
find_var_info (
add_variables ge vl)
b =
find_var_info ge b.
Proof.
induction vl;
simpl;
intros.
auto.
rewrite IHvl.
unfold find_var_info;
simpl.
apply ZMap.gso.
red;
intros;
subst b;
omegaContradiction.
simpl.
omega.
Qed.
Remark add_variables_same_funs:
forall b vl ge,
find_funct_ptr (
add_variables ge vl)
b =
find_funct_ptr ge b.
Proof.
induction vl; simpl; intros. auto. rewrite IHvl. auto.
Qed.
Remark add_functions_nextvar:
forall fl ge,
genv_nextvar (
add_functions ge fl) =
genv_nextvar ge.
Proof.
induction fl; simpl; intros. auto. rewrite IHfl. auto.
Qed.
Remark add_variables_nextvar:
forall vl ge,
genv_nextvar (
add_variables ge vl) =
genv_nextvar ge +
Z_of_nat(
List.length vl).
Proof.
induction vl;
intros.
simpl.
unfold block;
omega.
simpl length;
rewrite inj_S;
simpl.
rewrite IHvl.
simpl.
unfold block;
omega.
Qed.
Theorem find_funct_ptr_exists:
forall p id f,
list_norepet (
prog_funct_names p) ->
list_disjoint (
prog_funct_names p) (
prog_var_names p) ->
In (
id,
f) (
prog_funct p) ->
exists b,
find_symbol (
globalenv p)
id =
Some b
/\
find_funct_ptr (
globalenv p)
b =
Some f.
Proof.
Theorem find_funct_ptr_prop:
forall (
P:
F ->
Prop)
p b f,
(
forall id f,
In (
id,
f) (
prog_funct p) ->
P f) ->
find_funct_ptr (
globalenv p)
b =
Some f ->
P f.
Proof.
Theorem find_funct_prop:
forall (
P:
F ->
Prop)
p v f,
(
forall id f,
In (
id,
f) (
prog_funct p) ->
P f) ->
find_funct (
globalenv p)
v =
Some f ->
P f.
Proof.
Theorem find_funct_ptr_inversion:
forall p b f,
find_funct_ptr (
globalenv p)
b =
Some f ->
exists id,
In (
id,
f) (
prog_funct p).
Proof.
Theorem find_funct_inversion:
forall p v f,
find_funct (
globalenv p)
v =
Some f ->
exists id,
In (
id,
f) (
prog_funct p).
Proof.
intros.
pattern f.
apply find_funct_prop with p v;
auto.
intros.
exists id;
auto.
Qed.
Theorem find_funct_ptr_negative:
forall p b f,
find_funct_ptr (
globalenv p)
b =
Some f ->
b < 0.
Proof.
unfold find_funct_ptr.
intros.
destruct (
globalenv p).
simpl in H.
exploit genv_funs_range0;
eauto.
omega.
Qed.
Theorem find_var_info_positive:
forall p b v,
find_var_info (
globalenv p)
b =
Some v ->
b > 0.
Proof.
unfold find_var_info.
intros.
destruct (
globalenv p).
simpl in H.
exploit genv_vars_range0;
eauto.
omega.
Qed.
Remark add_variables_symb_neg:
forall id b vl ge,
find_symbol (
add_variables ge vl)
id =
Some b ->
b < 0 ->
find_symbol ge id =
Some b.
Proof.
induction vl;
simpl;
intros.
auto.
exploit IHvl;
eauto.
unfold find_symbol;
simpl.
rewrite PTree.gsspec.
fold ident.
destruct (
peq id (
a#1));
auto.
intros.
inv H1.
generalize (
genv_nextvar_pos ge).
intros.
omegaContradiction.
Qed.
Theorem find_funct_ptr_symbol_inversion:
forall p id b f,
find_symbol (
globalenv p)
id =
Some b ->
find_funct_ptr (
globalenv p)
b =
Some f ->
In (
id,
f)
p.(
prog_funct).
Proof.
Theorem find_symbol_not_nullptr:
forall p id b,
find_symbol (
globalenv p)
id =
Some b ->
b <>
Mem.nullptr.
Proof.
intros until b.
unfold find_symbol.
destruct (
globalenv p);
simpl.
intros.
exploit genv_symb_range0;
eauto.
intuition.
Qed.
Theorem global_addresses_distinct:
forall ge id1 id2 b1 b2,
id1 <>
id2 ->
find_symbol ge id1 =
Some b1 ->
find_symbol ge id2 =
Some b2 ->
b1 <>
b2.
Proof.
intros. red; intros; subst. elim H. destruct ge. eauto.
Qed.
Theorem invert_find_symbol:
forall ge id b,
invert_symbol ge b =
Some id ->
find_symbol ge id =
Some b.
Proof.
Theorem find_invert_symbol:
forall ge id b,
find_symbol ge id =
Some b ->
invert_symbol ge b =
Some id.
Proof.
Construction of the initial memory state
Section INITMEM.
Variable ge:
t.
Definition init_data_size (
i:
init_data) :
Z :=
match i with
|
Init_int8 _ => 1
|
Init_int16 _ => 2
|
Init_int32 _ => 4
|
Init_float32 _ => 4
|
Init_float64 _ => 8
|
Init_addrof _ _ => 4
|
Init_space n =>
Zmax n 0
end.
Lemma init_data_size_pos:
forall i,
init_data_size i >= 0.
Proof.
destruct i;
simpl;
try omega.
generalize (
Zle_max_r z 0).
omega.
Qed.
Definition store_init_data (
m:
mem) (
b:
block) (
p:
Z) (
id:
init_data) :
option mem :=
match id with
|
Init_int8 n =>
Mem.store Mint8unsigned m b p (
Vint n)
|
Init_int16 n =>
Mem.store Mint16unsigned m b p (
Vint n)
|
Init_int32 n =>
Mem.store Mint32 m b p (
Vint n)
|
Init_float32 n =>
Mem.store Mfloat32 m b p (
Vfloat n)
|
Init_float64 n =>
Mem.store Mfloat64 m b p (
Vfloat n)
|
Init_addrof symb ofs =>
match find_symbol ge symb with
|
None =>
None
|
Some b' =>
Mem.store Mint32 m b p (
Vptr b'
ofs)
end
|
Init_space n =>
Some m
end.
Fixpoint store_init_data_list (
m:
mem) (
b:
block) (
p:
Z) (
idl:
list init_data)
{
struct idl}:
option mem :=
match idl with
|
nil =>
Some m
|
id ::
idl' =>
match store_init_data m b p id with
|
None =>
None
|
Some m' =>
store_init_data_list m'
b (
p +
init_data_size id)
idl'
end
end.
Function store_zeros (
m:
mem) (
b:
block) (
n:
Z) {
wf (
Zwf 0)
n}:
option mem :=
if zle n 0
then Some m else
let n' :=
n - 1
in
match Mem.store Mint8unsigned m b n'
Vzero with
|
Some m' =>
store_zeros m'
b n'
|
None =>
None
end.
Proof.
Fixpoint init_data_list_size (
il:
list init_data) {
struct il} :
Z :=
match il with
|
nil => 0
|
i ::
il' =>
init_data_size i +
init_data_list_size il'
end.
Definition perm_globvar (
gv:
globvar V) :
permission :=
if gv.(
gvar_volatile)
then Nonempty
else if gv.(
gvar_readonly)
then Readable
else Writable.
Definition alloc_variable (
m:
mem) (
idv:
ident *
globvar V) :
option mem :=
let init :=
idv#2.(
gvar_init)
in
let sz :=
init_data_list_size init in
let (
m1,
b) :=
Mem.alloc m 0
sz in
match store_zeros m1 b sz with
|
None =>
None
|
Some m2 =>
match store_init_data_list m2 b 0
init with
|
None =>
None
|
Some m3 =>
Mem.drop_perm m3 b 0
sz (
perm_globvar idv#2)
end
end.
Fixpoint alloc_variables (
m:
mem) (
vl:
list (
ident *
globvar V))
{
struct vl} :
option mem :=
match vl with
|
nil =>
Some m
|
v ::
vl' =>
match alloc_variable m v with
|
None =>
None
|
Some m' =>
alloc_variables m'
vl'
end
end.
Lemma alloc_variables_app :
forall vl1 vl2 m m1,
alloc_variables m vl1 =
Some m1 ->
alloc_variables m1 vl2 =
alloc_variables m (
vl1 ++
vl2).
Proof.
induction vl1.
simpl.
intros.
inversion H;
subst.
auto.
simpl.
intros.
destruct (
alloc_variable m a);
eauto.
inversion H.
Qed.
Remark store_init_data_list_nextblock:
forall idl b m p m',
store_init_data_list m b p idl =
Some m' ->
Mem.nextblock m' =
Mem.nextblock m.
Proof.
Remark store_zeros_nextblock:
forall m b n m',
store_zeros m b n =
Some m' ->
Mem.nextblock m' =
Mem.nextblock m.
Proof.
intros until n.
functional induction (
store_zeros m b n);
intros.
inv H;
auto.
rewrite IHo;
eauto with mem.
congruence.
Qed.
Remark alloc_variable_nextblock:
forall v m m',
alloc_variable m v =
Some m' ->
Mem.nextblock m' =
Zsucc(
Mem.nextblock m).
Proof.
Remark alloc_variables_nextblock:
forall vl m m',
alloc_variables m vl =
Some m' ->
Mem.nextblock m' =
Mem.nextblock m +
Z_of_nat(
List.length vl).
Proof.
Remark store_zeros_perm:
forall k prm b'
q m b n m',
store_zeros m b n =
Some m' ->
(
Mem.perm m b'
q k prm <->
Mem.perm m'
b'
q k prm).
Proof.
intros until n.
functional induction (
store_zeros m b n);
intros.
inv H;
tauto.
destruct (
IHo _ H);
intros.
split;
eauto with mem.
congruence.
Qed.
Remark store_init_data_list_perm:
forall k prm b'
q idl b m p m',
store_init_data_list m b p idl =
Some m' ->
(
Mem.perm m b'
q k prm <->
Mem.perm m'
b'
q k prm).
Proof.
induction idl;
simpl;
intros until m'.
intros.
inv H.
tauto.
caseEq (
store_init_data m b p a);
try congruence.
intros.
rewrite <- (
IHidl _ _ _ _ H0).
destruct a;
simpl in H;
split;
eauto with mem.
inv H;
auto.
inv H;
auto.
destruct (
find_symbol ge i);
try congruence.
eauto with mem.
destruct (
find_symbol ge i);
try congruence.
eauto with mem.
Qed.
Remark alloc_variables_perm:
forall k prm b'
q vl m m',
alloc_variables m vl =
Some m' ->
Mem.valid_block m b' ->
(
Mem.perm m b'
q k prm <->
Mem.perm m'
b'
q k prm).
Proof.
Remark store_zeros_outside:
forall m b n m',
store_zeros m b n =
Some m' ->
forall chunk b'
p,
b' <>
b ->
Mem.load chunk m'
b'
p =
Mem.load chunk m b'
p.
Proof.
Remark store_init_data_list_outside:
forall b il m p m',
store_init_data_list m b p il =
Some m' ->
forall chunk b'
q,
b' <>
b \/
q +
size_chunk chunk <=
p ->
Mem.load chunk m'
b'
q =
Mem.load chunk m b'
q.
Proof.
Fixpoint load_store_init_data (
m:
mem) (
b:
block) (
p:
Z) (
il:
list init_data) {
struct il} :
Prop :=
match il with
|
nil =>
True
|
Init_int8 n ::
il' =>
Mem.load Mint8unsigned m b p =
Some(
Vint(
Int.zero_ext 8
n))
/\
load_store_init_data m b (
p + 1)
il'
|
Init_int16 n ::
il' =>
Mem.load Mint16unsigned m b p =
Some(
Vint(
Int.zero_ext 16
n))
/\
load_store_init_data m b (
p + 2)
il'
|
Init_int32 n ::
il' =>
Mem.load Mint32 m b p =
Some(
Vint n)
/\
load_store_init_data m b (
p + 4)
il'
|
Init_float32 n ::
il' =>
Mem.load Mfloat32 m b p =
Some(
Vfloat(
Float.singleoffloat n))
/\
load_store_init_data m b (
p + 4)
il'
|
Init_float64 n ::
il' =>
Mem.load Mfloat64 m b p =
Some(
Vfloat n)
/\
load_store_init_data m b (
p + 8)
il'
|
Init_addrof symb ofs ::
il' =>
(
exists b',
find_symbol ge symb =
Some b' /\
Mem.load Mint32 m b p =
Some(
Vptr b'
ofs))
/\
load_store_init_data m b (
p + 4)
il'
|
Init_space n ::
il' =>
load_store_init_data m b (
p +
Zmax n 0)
il'
end.
Lemma store_init_data_list_charact:
forall b il m p m',
store_init_data_list m b p il =
Some m' ->
load_store_init_data m'
b p il.
Proof.
Remark load_alloc_variables:
forall chunk b p vl m m',
alloc_variables m vl =
Some m' ->
Mem.valid_block m b ->
Mem.load chunk m'
b p =
Mem.load chunk m b p.
Proof.
Remark load_store_init_data_invariant:
forall m m'
b,
(
forall chunk ofs,
Mem.load chunk m'
b ofs =
Mem.load chunk m b ofs) ->
forall il p,
load_store_init_data m b p il ->
load_store_init_data m'
b p il.
Proof.
induction il; intro p; simpl.
auto.
repeat rewrite H. destruct a; intuition.
Qed.
Definition variables_initialized (
g:
t) (
m:
mem) :=
forall b gv,
find_var_info g b =
Some gv ->
Mem.range_perm m b 0 (
init_data_list_size gv.(
gvar_init))
Cur (
perm_globvar gv)
/\ (
forall ofs k p,
Mem.perm m b ofs k p ->
0 <=
ofs <
init_data_list_size gv.(
gvar_init) /\
perm_order (
perm_globvar gv)
p)
/\ (
gv.(
gvar_volatile) =
false ->
load_store_init_data m b 0
gv.(
gvar_init)).
Lemma alloc_variable_initialized:
forall g m id v m',
genv_nextvar g =
Mem.nextblock m ->
alloc_variable m (
id,
v) =
Some m' ->
variables_initialized g m ->
variables_initialized (
add_variable g (
id,
v))
m'
/\
genv_nextvar (
add_variable g (
id,
v)) =
Mem.nextblock m'.
Proof.
Lemma alloc_variables_initialized:
forall vl g m m',
genv_nextvar g =
Mem.nextblock m ->
alloc_variables m vl =
Some m' ->
variables_initialized g m ->
variables_initialized (
add_variables g vl)
m'.
Proof.
induction vl;
simpl;
intros.
inv H0;
auto.
destruct (
alloc_variable m a)
as [
m1|]
_eqn;
try discriminate.
destruct a as [
id gv].
exploit alloc_variable_initialized;
eauto.
intros [
P Q].
eapply IHvl;
eauto.
Qed.
End INITMEM.
Definition init_mem (
p:
program F V) :=
alloc_variables (
globalenv p)
Mem.empty p.(
prog_vars).
Theorem find_symbol_not_fresh:
forall p id b m,
init_mem p =
Some m ->
find_symbol (
globalenv p)
id =
Some b ->
Mem.valid_block m b.
Proof.
Lemma init_mem_genv_vars :
forall p m,
init_mem p =
Some m ->
genv_nextvar (
globalenv p) =
Mem.nextblock m.
Proof.
Theorem find_var_info_not_fresh:
forall p b gv m,
init_mem p =
Some m ->
find_var_info (
globalenv p)
b =
Some gv ->
Mem.valid_block m b.
Proof.
Theorem init_mem_characterization:
forall p b gv m,
find_var_info (
globalenv p)
b =
Some gv ->
init_mem p =
Some m ->
Mem.range_perm m b 0 (
init_data_list_size gv.(
gvar_init))
Cur (
perm_globvar gv)
/\ (
forall ofs k p,
Mem.perm m b ofs k p ->
0 <=
ofs <
init_data_list_size gv.(
gvar_init) /\
perm_order (
perm_globvar gv)
p)
/\ (
gv.(
gvar_volatile) =
false ->
load_store_init_data (
globalenv p)
m b 0
gv.(
gvar_init)).
Proof.
Compatibility with memory injections
Section INITMEM_INJ.
Variable ge:
t.
Variable thr:
block.
Hypothesis symb_inject:
forall id b,
find_symbol ge id =
Some b ->
b <
thr.
Lemma store_init_data_neutral:
forall m b p id m',
Mem.inject_neutral thr m ->
b <
thr ->
store_init_data ge m b p id =
Some m' ->
Mem.inject_neutral thr m'.
Proof.
Lemma store_init_data_list_neutral:
forall b idl m p m',
Mem.inject_neutral thr m ->
b <
thr ->
store_init_data_list ge m b p idl =
Some m' ->
Mem.inject_neutral thr m'.
Proof.
induction idl;
simpl.
intros;
congruence.
intros until m';
intros INJ FB.
caseEq (
store_init_data ge m b p a);
try congruence.
intros.
eapply IHidl.
eapply store_init_data_neutral;
eauto.
auto.
eauto.
Qed.
Lemma store_zeros_neutral:
forall m b n m',
Mem.inject_neutral thr m ->
b <
thr ->
store_zeros m b n =
Some m' ->
Mem.inject_neutral thr m'.
Proof.
Lemma alloc_variable_neutral:
forall id m m',
alloc_variable ge m id =
Some m' ->
Mem.inject_neutral thr m ->
Mem.nextblock m <
thr ->
Mem.inject_neutral thr m'.
Proof.
Lemma alloc_variables_neutral:
forall idl m m',
alloc_variables ge m idl =
Some m' ->
Mem.inject_neutral thr m ->
Mem.nextblock m' <=
thr ->
Mem.inject_neutral thr m'.
Proof.
End INITMEM_INJ.
Theorem initmem_inject:
forall p m,
init_mem p =
Some m ->
Mem.inject (
Mem.flat_inj (
Mem.nextblock m))
m m.
Proof.
Section INITMEM_AUGMENT_INJ.
Variable ge:
t.
Variable thr:
block.
Lemma store_init_data_augment:
forall m1 m2 b p id m2',
Mem.inject (
Mem.flat_inj thr)
m1 m2 ->
b >=
thr ->
store_init_data ge m2 b p id =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2'.
Proof.
intros until m2'.
intros INJ BND ST.
assert (
P:
forall chunk ofs v m2',
Mem.store chunk m2 b ofs v =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2').
intros.
eapply Mem.store_outside_inject;
eauto.
intros.
unfold Mem.flat_inj in H0.
destruct (
zlt b'
thr);
inversion H0;
subst.
omega.
destruct id;
simpl in ST;
try (
eapply P;
eauto;
fail).
inv ST;
auto.
revert ST.
caseEq (
find_symbol ge i);
try congruence.
intros;
eapply P;
eauto.
Qed.
Lemma store_init_data_list_augment:
forall b idl m1 m2 p m2',
Mem.inject (
Mem.flat_inj thr)
m1 m2 ->
b >=
thr ->
store_init_data_list ge m2 b p idl =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2'.
Proof.
induction idl;
simpl.
intros;
congruence.
intros until m2';
intros INJ FB.
caseEq (
store_init_data ge m2 b p a);
try congruence.
intros.
eapply IHidl.
eapply store_init_data_augment;
eauto.
auto.
eauto.
Qed.
Lemma store_zeros_augment:
forall m1 m2 b n m2',
Mem.inject (
Mem.flat_inj thr)
m1 m2 ->
b >=
thr ->
store_zeros m2 b n =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2'.
Proof.
intros until n.
functional induction (
store_zeros m2 b n);
intros.
inv H1;
auto.
apply IHo;
auto.
exploit Mem.store_outside_inject;
eauto.
simpl.
intros.
exfalso.
unfold Mem.flat_inj in H2.
destruct (
zlt b'
thr).
inversion H2;
subst;
omega.
discriminate.
inv H1.
Qed.
Lemma alloc_variable_augment:
forall id m1 m2 m2',
alloc_variable ge m2 id =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2 ->
Mem.nextblock m2 >=
thr ->
Mem.inject (
Mem.flat_inj thr)
m1 m2'.
Proof.
Lemma alloc_variables_augment:
forall idl m1 m2 m2',
alloc_variables ge m2 idl =
Some m2' ->
Mem.inject (
Mem.flat_inj thr)
m1 m2 ->
Mem.nextblock m2 >=
thr ->
Mem.inject (
Mem.flat_inj thr)
m1 m2'.
Proof.
End INITMEM_AUGMENT_INJ.
End GENV.
Commutation with program transformations
Commutation with matching between programs.
Section MATCH_PROGRAMS.
Variables A B V W:
Type.
Variable match_fun:
A ->
B ->
Prop.
Variable match_varinfo:
V ->
W ->
Prop.
Inductive match_globvar:
globvar V ->
globvar W ->
Prop :=
|
match_globvar_intro:
forall info1 info2 init ro vo,
match_varinfo info1 info2 ->
match_globvar (
mkglobvar info1 init ro vo) (
mkglobvar info2 init ro vo).
Record match_genvs (
new_functs :
list (
ident *
B)) (
new_vars :
list (
ident *
globvar W))
(
ge1:
t A V) (
ge2:
t B W):
Prop := {
mge_nextfun:
genv_nextfun ge2 =
genv_nextfun ge1 -
Z_of_nat(
length new_functs);
mge_nextvar:
genv_nextvar ge2 =
genv_nextvar ge1 +
Z_of_nat(
length new_vars);
mge_symb:
forall id, ~
In id ((
funct_names new_functs) ++ (
var_names new_vars)) ->
PTree.get id (
genv_symb ge2) =
PTree.get id (
genv_symb ge1);
mge_funs:
forall b f,
ZMap.get b (
genv_funs ge1) =
Some f ->
exists tf,
ZMap.get b (
genv_funs ge2) =
Some tf /\
match_fun f tf;
mge_rev_funs:
forall b tf,
ZMap.get b (
genv_funs ge2) =
Some tf ->
if zlt (
genv_nextfun ge1)
b then
exists f,
ZMap.get b (
genv_funs ge1) =
Some f /\
match_fun f tf
else
In tf (
map (@
snd ident B)
new_functs);
mge_vars:
forall b v,
ZMap.get b (
genv_vars ge1) =
Some v ->
exists tv,
ZMap.get b (
genv_vars ge2) =
Some tv /\
match_globvar v tv;
mge_rev_vars:
forall b tv,
ZMap.get b (
genv_vars ge2) =
Some tv ->
if zlt b (
genv_nextvar ge1)
then
exists v,
ZMap.get b (
genv_vars ge1) =
Some v /\
match_globvar v tv
else
In tv (
map (@
snd ident (
globvar W))
new_vars)
}.
Lemma add_function_match:
forall ge1 ge2 id f1 f2,
match_genvs nil nil ge1 ge2 ->
match_fun f1 f2 ->
match_genvs nil nil (
add_function ge1 (
id,
f1)) (
add_function ge2 (
id,
f2)).
Proof.
Lemma add_functions_match:
forall fl1 fl2,
list_forall2 (
match_funct_entry match_fun)
fl1 fl2 ->
forall ge1 ge2,
match_genvs nil nil ge1 ge2 ->
match_genvs nil nil (
add_functions ge1 fl1) (
add_functions ge2 fl2).
Proof.
induction 1;
intros;
simpl.
auto.
destruct a1 as [
id1 f1];
destruct b1 as [
id2 f2].
destruct H.
subst.
apply IHlist_forall2.
apply add_function_match;
auto.
Qed.
Lemma add_function_augment_match:
forall new_functs new_vars ge1 ge2 id f2,
match_genvs new_functs new_vars ge1 ge2 ->
match_genvs (
new_functs++((
id,
f2)::
nil))
new_vars ge1 (
add_function ge2 (
id,
f2)).
Proof.
intros.
destruct H.
constructor;
simpl.
rewrite mge_nextfun0.
rewrite app_length.
simpl.
rewrite inj_plus.
rewrite inj_S.
rewrite inj_0.
unfold block;
omega.
auto.
intros.
unfold funct_names in H.
rewrite map_app in H.
rewrite in_app in H.
rewrite in_app in H.
simpl in H.
destruct (
peq id id0).
subst.
intuition.
rewrite PTree.gso.
apply mge_symb0.
intro.
apply H.
rewrite in_app in H0.
inversion H0;
intuition.
intuition.
intros.
rewrite ZMap.gso.
auto.
rewrite mge_nextfun0.
pose proof (
genv_funs_range ge1 b H).
intro;
subst;
omega.
intros.
rewrite ZMap.gsspec in H.
destruct (
ZIndexed.eq b (
genv_nextfun ge2)).
destruct (
zlt (
genv_nextfun ge1)
b).
exfalso.
rewrite mge_nextfun0 in e.
unfold block;
omega.
rewrite map_app.
rewrite in_app.
simpl.
inversion H;
intuition.
pose proof (
mge_rev_funs0 b tf H).
destruct (
zlt (
genv_nextfun ge1)
b).
auto.
rewrite map_app.
rewrite in_app.
intuition.
auto.
auto.
Qed.
Lemma add_functions_augment_match:
forall fl new_functs new_vars ge1 ge2,
match_genvs new_functs new_vars ge1 ge2 ->
match_genvs (
new_functs++
fl)
new_vars ge1 (
add_functions ge2 fl).
Proof.
induction fl;
simpl.
intros.
rewrite app_nil_r.
auto.
intros.
replace (
new_functs ++
a ::
fl)
with ((
new_functs ++ (
a::
nil)) ++
fl)
by (
rewrite app_ass;
auto).
apply IHfl.
destruct a.
apply add_function_augment_match.
auto.
Qed.
Lemma add_variable_match:
forall new_functs ge1 ge2 id v1 v2,
match_genvs new_functs nil ge1 ge2 ->
match_globvar v1 v2 ->
match_genvs new_functs nil (
add_variable ge1 (
id,
v1)) (
add_variable ge2 (
id,
v2)).
Proof.
Lemma add_variables_match:
forall vl1 vl2,
list_forall2 (
match_var_entry match_varinfo)
vl1 vl2 ->
forall new_functs ge1 ge2,
match_genvs new_functs nil ge1 ge2 ->
match_genvs new_functs nil (
add_variables ge1 vl1) (
add_variables ge2 vl2).
Proof.
induction 1;
intros;
simpl.
auto.
inv H.
apply IHlist_forall2.
apply add_variable_match;
auto.
constructor;
auto.
Qed.
Lemma add_variable_augment_match:
forall ge1 new_functs new_vars ge2 id v2,
match_genvs new_functs new_vars ge1 ge2 ->
match_genvs new_functs (
new_vars++((
id,
v2)::
nil))
ge1 (
add_variable ge2 (
id,
v2)).
Proof.
intros.
destruct H.
constructor;
simpl.
auto.
rewrite mge_nextvar0.
rewrite app_length.
simpl.
rewrite inj_plus.
rewrite inj_S.
rewrite inj_0.
unfold block;
omega.
intros.
unfold funct_names,
var_names in H.
rewrite map_app in H.
rewrite in_app in H.
rewrite in_app in H.
simpl in H.
destruct (
peq id id0).
subst.
intuition.
rewrite PTree.gso.
apply mge_symb0.
intro.
apply H.
rewrite in_app in H0.
inversion H0;
intuition.
intuition.
auto.
auto.
intros.
rewrite ZMap.gso.
auto.
rewrite mge_nextvar0.
pose proof (
genv_vars_range ge1 b H).
intro;
subst;
omega.
intros.
rewrite ZMap.gsspec in H.
destruct (
ZIndexed.eq b (
genv_nextvar ge2)).
destruct (
zlt b (
genv_nextvar ge1)).
exfalso.
rewrite mge_nextvar0 in e.
unfold block;
omega.
rewrite map_app.
rewrite in_app.
simpl.
inversion H;
intuition.
pose proof (
mge_rev_vars0 b tv H).
destruct (
zlt b (
genv_nextvar ge1)).
auto.
rewrite map_app.
rewrite in_app.
intuition.
Qed.
Lemma add_variables_augment_match:
forall vl ge1 new_functs new_vars ge2,
match_genvs new_functs new_vars ge1 ge2 ->
match_genvs new_functs (
new_vars++
vl)
ge1 (
add_variables ge2 vl).
Proof.
Variable new_functs :
list (
ident *
B).
Variable new_vars :
list (
ident *
globvar W).
Variable new_main :
ident.
Variable p:
program A V.
Variable p':
program B W.
Hypothesis progmatch:
match_program match_fun match_varinfo new_functs new_vars new_main p p'.
Lemma globalenvs_match:
match_genvs new_functs new_vars (
globalenv p) (
globalenv p').
Proof.
Theorem find_funct_ptr_match:
forall (
b :
block) (
f :
A),
find_funct_ptr (
globalenv p)
b =
Some f ->
exists tf :
B,
find_funct_ptr (
globalenv p')
b =
Some tf /\
match_fun f tf.
Proof (
mge_funs globalenvs_match).
Theorem find_funct_ptr_rev_match:
forall (
b :
block) (
tf :
B),
find_funct_ptr (
globalenv p')
b =
Some tf ->
if zlt (
genv_nextfun (
globalenv p))
b then
exists f,
find_funct_ptr (
globalenv p)
b =
Some f /\
match_fun f tf
else
In tf (
map (@
snd ident B)
new_functs).
Proof (
mge_rev_funs globalenvs_match).
Theorem find_funct_match:
forall (
v :
val) (
f :
A),
find_funct (
globalenv p)
v =
Some f ->
exists tf :
B,
find_funct (
globalenv p')
v =
Some tf /\
match_fun f tf.
Proof.
Theorem find_funct_rev_match:
forall (
v :
val) (
tf :
B),
find_funct (
globalenv p')
v =
Some tf ->
(
exists f,
find_funct (
globalenv p)
v =
Some f /\
match_fun f tf)
\/ (
In tf (
map (@
snd ident B)
new_functs)).
Proof.
Theorem find_var_info_match:
forall (
b :
block) (
v :
globvar V),
find_var_info (
globalenv p)
b =
Some v ->
exists tv,
find_var_info (
globalenv p')
b =
Some tv /\
match_globvar v tv.
Proof (
mge_vars globalenvs_match).
Theorem find_var_info_rev_match:
forall (
b :
block) (
tv :
globvar W),
find_var_info (
globalenv p')
b =
Some tv ->
if zlt b (
genv_nextvar (
globalenv p))
then
exists v,
find_var_info (
globalenv p)
b =
Some v /\
match_globvar v tv
else
In tv (
map (@
snd ident (
globvar W))
new_vars).
Proof (
mge_rev_vars globalenvs_match).
Theorem find_symbol_match:
forall (
s :
ident),
~
In s (
funct_names new_functs ++
var_names new_vars) ->
find_symbol (
globalenv p')
s =
find_symbol (
globalenv p)
s.
Proof.
Hypothesis new_ids_fresh :
(
forall s',
find_symbol (
globalenv p)
s' <>
None ->
~
In s' (
funct_names new_functs ++
var_names new_vars)).
Lemma store_init_data_list_match:
forall idl m b ofs m',
store_init_data_list (
globalenv p)
m b ofs idl =
Some m' ->
store_init_data_list (
globalenv p')
m b ofs idl =
Some m'.
Proof.
Lemma alloc_variables_match:
forall vl1 vl2,
list_forall2 (
match_var_entry match_varinfo)
vl1 vl2 ->
forall m m',
alloc_variables (
globalenv p)
m vl1 =
Some m' ->
alloc_variables (
globalenv p')
m vl2 =
Some m'.
Proof.
Theorem init_mem_match:
forall m,
init_mem p =
Some m ->
init_mem p' =
alloc_variables (
globalenv p')
m new_vars.
Proof.
End MATCH_PROGRAMS.
Section TRANSF_PROGRAM_AUGMENT.
Variable A B V W:
Type.
Variable transf_fun:
A ->
res B.
Variable transf_var:
V ->
res W.
Variable new_functs :
list (
ident *
B).
Variable new_vars :
list (
ident *
globvar W).
Variable new_main :
ident.
Variable p:
program A V.
Variable p':
program B W.
Hypothesis transf_OK:
transform_partial_augment_program transf_fun transf_var new_functs new_vars new_main p =
OK p'.
Remark prog_match:
match_program
(
fun fd tfd =>
transf_fun fd =
OK tfd)
(
fun info tinfo =>
transf_var info =
OK tinfo)
new_functs new_vars new_main
p p'.
Proof.
Theorem find_funct_ptr_transf_augment:
forall (
b:
block) (
f:
A),
find_funct_ptr (
globalenv p)
b =
Some f ->
exists f',
find_funct_ptr (
globalenv p')
b =
Some f' /\
transf_fun f =
OK f'.
Proof.
Theorem find_new_funct_ptr_exists:
list_norepet (
prog_funct_names p ++
funct_names new_functs) ->
list_disjoint (
prog_funct_names p ++
funct_names new_functs) (
prog_var_names p ++
var_names new_vars) ->
forall id f,
In (
id,
f)
new_functs ->
exists b,
find_symbol (
globalenv p')
id =
Some b
/\
find_funct_ptr (
globalenv p')
b =
Some f.
Proof.
intros.
destruct p.
unfold transform_partial_augment_program in transf_OK.
monadInv transf_OK.
rename x into prog_funct'.
rename x0 into prog_vars'.
simpl in *.
assert (
funct_names prog_funct =
funct_names prog_funct').
clear -
EQ.
generalize dependent prog_funct'.
induction prog_funct;
intros.
simpl in EQ.
inversion EQ;
subst;
auto.
simpl in EQ.
destruct a.
destruct (
transf_fun a);
try discriminate.
monadInv EQ.
simpl;
f_equal;
auto.
assert (
var_names prog_vars =
var_names prog_vars').
clear -
EQ1.
generalize dependent prog_vars'.
induction prog_vars;
intros.
simpl in EQ1.
inversion EQ1;
subst;
auto.
simpl in EQ1.
destruct a.
destruct (
transf_globvar transf_var g);
try discriminate.
monadInv EQ1.
simpl;
f_equal;
auto.
apply find_funct_ptr_exists.
unfold prog_funct_names in *;
simpl in *.
rewrite funct_names_app.
rewrite <-
H2.
auto.
unfold prog_funct_names,
prog_var_names in *;
simpl in *.
rewrite funct_names_app.
rewrite var_names_app.
rewrite <-
H2.
rewrite <-
H3.
auto.
simpl.
intuition.
Qed.
Theorem find_funct_ptr_rev_transf_augment:
forall (
b:
block) (
tf:
B),
find_funct_ptr (
globalenv p')
b =
Some tf ->
if (
zlt (
genv_nextfun (
globalenv p))
b)
then
(
exists f,
find_funct_ptr (
globalenv p)
b =
Some f /\
transf_fun f =
OK tf)
else
In tf (
map (@
snd ident B)
new_functs).
Proof.
Theorem find_funct_transf_augment:
forall (
v:
val) (
f:
A),
find_funct (
globalenv p)
v =
Some f ->
exists f',
find_funct (
globalenv p')
v =
Some f' /\
transf_fun f =
OK f'.
Proof.
Theorem find_funct_rev_transf_augment:
forall (
v:
val) (
tf:
B),
find_funct (
globalenv p')
v =
Some tf ->
(
exists f,
find_funct (
globalenv p)
v =
Some f /\
transf_fun f =
OK tf) \/
In tf (
map (@
snd ident B)
new_functs).
Proof.
Theorem find_var_info_transf_augment:
forall (
b:
block) (
v:
globvar V),
find_var_info (
globalenv p)
b =
Some v ->
exists v',
find_var_info (
globalenv p')
b =
Some v' /\
transf_globvar transf_var v =
OK v'.
Proof.
intros.
exploit find_var_info_match.
eexact prog_match.
eauto.
intros [
tv [
X Y]].
exists tv;
split;
auto.
inv Y.
unfold transf_globvar;
simpl.
rewrite H0;
simpl.
auto.
Qed.
Theorem find_new_var_exists:
forall id gv,
list_norepet (
var_names new_vars) ->
In (
id,
gv)
new_vars ->
exists b,
find_symbol (
globalenv p')
id =
Some b /\
find_var_info (
globalenv p')
b =
Some gv.
Proof.
Theorem find_var_info_rev_transf_augment:
forall (
b:
block) (
v':
globvar W),
find_var_info (
globalenv p')
b =
Some v' ->
if zlt b (
genv_nextvar (
globalenv p))
then
(
exists v,
find_var_info (
globalenv p)
b =
Some v /\
transf_globvar transf_var v =
OK v')
else
(
In v' (
map (@
snd ident (
globvar W))
new_vars)).
Proof.
Theorem find_symbol_transf_augment:
forall (
s:
ident),
~
In s (
funct_names new_functs ++
var_names new_vars) ->
find_symbol (
globalenv p')
s =
find_symbol (
globalenv p)
s.
Proof.
Theorem init_mem_transf_augment:
(
forall s',
find_symbol (
globalenv p)
s' <>
None ->
~
In s' (
funct_names new_functs ++
var_names new_vars)) ->
forall m,
init_mem p =
Some m ->
init_mem p' =
alloc_variables (
globalenv p')
m new_vars.
Proof.
Theorem init_mem_inject_transf_augment:
(
forall s',
find_symbol (
globalenv p)
s' <>
None ->
~
In s' (
funct_names new_functs ++
var_names new_vars)) ->
forall m,
init_mem p =
Some m ->
forall m',
init_mem p' =
Some m' ->
Mem.inject (
Mem.flat_inj (
Mem.nextblock m))
m m'.
Proof.
End TRANSF_PROGRAM_AUGMENT.
Section TRANSF_PROGRAM_PARTIAL2.
Variable A B V W:
Type.
Variable transf_fun:
A ->
res B.
Variable transf_var:
V ->
res W.
Variable p:
program A V.
Variable p':
program B W.
Hypothesis transf_OK:
transform_partial_program2 transf_fun transf_var p =
OK p'.
Remark transf_augment_OK:
transform_partial_augment_program transf_fun transf_var nil nil p.(
prog_main)
p =
OK p'.
Proof.
Theorem find_funct_ptr_transf_partial2:
forall (
b:
block) (
f:
A),
find_funct_ptr (
globalenv p)
b =
Some f ->
exists f',
find_funct_ptr (
globalenv p')
b =
Some f' /\
transf_fun f =
OK f'.
Proof.
Theorem find_funct_ptr_rev_transf_partial2:
forall (
b:
block) (
tf:
B),
find_funct_ptr (
globalenv p')
b =
Some tf ->
exists f,
find_funct_ptr (
globalenv p)
b =
Some f /\
transf_fun f =
OK tf.
Proof.
Theorem find_funct_transf_partial2:
forall (
v:
val) (
f:
A),
find_funct (
globalenv p)
v =
Some f ->
exists f',
find_funct (
globalenv p')
v =
Some f' /\
transf_fun f =
OK f'.
Proof.
Theorem find_funct_rev_transf_partial2:
forall (
v:
val) (
tf:
B),
find_funct (
globalenv p')
v =
Some tf ->
exists f,
find_funct (
globalenv p)
v =
Some f /\
transf_fun f =
OK tf.
Proof.
Theorem find_var_info_transf_partial2:
forall (
b:
block) (
v:
globvar V),
find_var_info (
globalenv p)
b =
Some v ->
exists v',
find_var_info (
globalenv p')
b =
Some v' /\
transf_globvar transf_var v =
OK v'.
Proof.
Theorem find_var_info_rev_transf_partial2:
forall (
b:
block) (
v':
globvar W),
find_var_info (
globalenv p')
b =
Some v' ->
exists v,
find_var_info (
globalenv p)
b =
Some v /\
transf_globvar transf_var v =
OK v'.
Proof.
Theorem find_symbol_transf_partial2:
forall (
s:
ident),
find_symbol (
globalenv p')
s =
find_symbol (
globalenv p)
s.
Proof.
Theorem init_mem_transf_partial2:
forall m,
init_mem p =
Some m ->
init_mem p' =
Some m.
Proof.
End TRANSF_PROGRAM_PARTIAL2.
Section TRANSF_PROGRAM_PARTIAL.
Variable A B V:
Type.
Variable transf:
A ->
res B.
Variable p:
program A V.
Variable p':
program B V.
Hypothesis transf_OK:
transform_partial_program transf p =
OK p'.
Remark transf2_OK:
transform_partial_program2 transf (
fun x =>
OK x)
p =
OK p'.
Proof.
Theorem find_funct_ptr_transf_partial:
forall (
b:
block) (
f:
A),
find_funct_ptr (
globalenv p)
b =
Some f ->
exists f',
find_funct_ptr (
globalenv p')
b =
Some f' /\
transf f =
OK f'.
Proof.
Theorem find_funct_ptr_rev_transf_partial:
forall (
b:
block) (
tf:
B),
find_funct_ptr (
globalenv p')
b =
Some tf ->
exists f,
find_funct_ptr (
globalenv p)
b =
Some f /\
transf f =
OK tf.
Proof.
Theorem find_funct_transf_partial:
forall (
v:
val) (
f:
A),
find_funct (
globalenv p)
v =
Some f ->
exists f',
find_funct (
globalenv p')
v =
Some f' /\
transf f =
OK f'.
Proof.
Theorem find_funct_rev_transf_partial:
forall (
v:
val) (
tf:
B),
find_funct (
globalenv p')
v =
Some tf ->
exists f,
find_funct (
globalenv p)
v =
Some f /\
transf f =
OK tf.
Proof.
Theorem find_symbol_transf_partial:
forall (
s:
ident),
find_symbol (
globalenv p')
s =
find_symbol (
globalenv p)
s.
Proof.
Theorem find_var_info_transf_partial:
forall (
b:
block),
find_var_info (
globalenv p')
b =
find_var_info (
globalenv p)
b.
Proof.
Theorem init_mem_transf_partial:
forall m,
init_mem p =
Some m ->
init_mem p' =
Some m.
Proof.
End TRANSF_PROGRAM_PARTIAL.
Section TRANSF_PROGRAM.
Variable A B V:
Type.
Variable transf:
A ->
B.
Variable p:
program A V.
Let tp :=
transform_program transf p.
Remark transf_OK:
transform_partial_program (
fun x =>
OK (
transf x))
p =
OK tp.
Proof.
unfold tp,
transform_program,
transform_partial_program.
rewrite map_partial_total.
reflexivity.
Qed.
Theorem find_funct_ptr_transf:
forall (
b:
block) (
f:
A),
find_funct_ptr (
globalenv p)
b =
Some f ->
find_funct_ptr (
globalenv tp)
b =
Some (
transf f).
Proof.
Theorem find_funct_ptr_rev_transf:
forall (
b:
block) (
tf:
B),
find_funct_ptr (
globalenv tp)
b =
Some tf ->
exists f,
find_funct_ptr (
globalenv p)
b =
Some f /\
transf f =
tf.
Proof.
Theorem find_funct_transf:
forall (
v:
val) (
f:
A),
find_funct (
globalenv p)
v =
Some f ->
find_funct (
globalenv tp)
v =
Some (
transf f).
Proof.
Theorem find_funct_rev_transf:
forall (
v:
val) (
tf:
B),
find_funct (
globalenv tp)
v =
Some tf ->
exists f,
find_funct (
globalenv p)
v =
Some f /\
transf f =
tf.
Proof.
Theorem find_symbol_transf:
forall (
s:
ident),
find_symbol (
globalenv tp)
s =
find_symbol (
globalenv p)
s.
Proof.
Theorem find_var_info_transf:
forall (
b:
block),
find_var_info (
globalenv tp)
b =
find_var_info (
globalenv p)
b.
Proof.
Theorem init_mem_transf:
forall m,
init_mem p =
Some m ->
init_mem tp =
Some m.
Proof.
End TRANSF_PROGRAM.
End Genv.