Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
forall n b ofs vl,
In Undef vl -> check_pointer n b ofs vl = false.
Proof.
induction n; intros; simpl.
destruct vl. elim H. auto.
destruct vl. auto.
destruct m; auto. simpl in H; destruct H. congruence.
rewrite IHn; auto. apply andb_false_r.
Qed.
Lemma proj_pointer_undef:
forall vl, In Undef vl -> proj_pointer vl = Vundef.
Proof.
intros; unfold proj_pointer.
destruct vl; auto. destruct m; auto.
rewrite check_pointer_undef. auto. auto.
Qed.
Theorem decode_val_inject:
forall f vl1 vl2 chunk,
list_forall2 (memval_inject f) vl1 vl2 ->
val_inject f (decode_val chunk vl1) (decode_val chunk vl2).
Proof.
intros. unfold decode_val.
case_eq (proj_bytes vl1); intros.
exploit proj_bytes_inject; eauto. intros. rewrite H1.
destruct chunk; constructor.
destruct chunk; auto.
case_eq (proj_bytes vl2); intros.
rewrite proj_pointer_undef. auto. eapply proj_bytes_not_inject; eauto. congruence.
apply proj_pointer_inject; auto.
Qed.
(** Symmetrically, [encode_val], applied to values related by [val_inject],
returns lists of memory values that are pairwise
related by [memval_inject]. *)
Lemma inj_bytes_inject:
forall f bl, list_forall2 (memval_inject f) (inj_bytes bl) (inj_bytes bl).
Proof.
induction bl; constructor; auto. constructor.
Qed.
Lemma repeat_Undef_inject_any:
forall f vl,
list_forall2 (memval_inject f) (list_repeat (length vl) Undef) vl.
Proof.
induction vl; simpl; constructor; auto. constructor.
Qed.
Lemma repeat_Undef_inject_self:
forall f n,
list_forall2 (memval_inject f) (list_repeat n Undef) (list_repeat n Undef).
Proof.
induction n; simpl; constructor; auto. constructor.
Qed.
Theorem encode_val_inject:
forall f v1 v2 chunk,
val_inject f v1 v2 ->
list_forall2 (memval_inject f) (encode_val chunk v1) (encode_val chunk v2).
Proof.
intros. inv H; simpl.
apply inj_bytes_inject.
apply inj_bytes_inject.
destruct chunk; try apply repeat_Undef_inject_self.
unfold inj_pointer; simpl; repeat econstructor; auto.
replace (size_chunk_nat chunk) with (length (encode_val chunk v2)).
apply repeat_Undef_inject_any. apply encode_val_length.
Qed.
(** The identity injection has interesting properties. *)
Definition inject_id : meminj := fun b => Some(b, 0).
Lemma val_inject_id:
forall v1 v2,
val_inject inject_id v1 v2 <-> Val.lessdef v1 v2.
Proof.
intros; split; intros.
inv H. constructor. constructor.
unfold inject_id in H0. inv H0. rewrite Int.add_zero. constructor.
constructor.
inv H. destruct v2; econstructor. unfold inject_id; reflexivity. rewrite Int.add_zero; auto.
constructor.
Qed.
Lemma memval_inject_id:
forall mv, memval_inject inject_id mv mv.
Proof.
destruct mv; econstructor. unfold inject_id; reflexivity. rewrite Int.add_zero; auto.
Qed.