Module MemoryWD.
(** Valid memories are the ones that do not contain any dangling pointers*)
Definition valid_mem m :=
forall b,
Mem.valid_block m b ->
forall ofs mv,
Maps.ZMap.get ofs (Mem.mem_contents m) # b = mv ->
match mv with
| Fragment v q n =>
mem_wd.val_valid v m
| _ => True
end.

Lemma valid_val_encode:
forall v m chunk
(Hval_wd: mem_wd.val_valid v m),
forall v',
List.In v' (encode_val chunk v) ->
match v' with
| Undef => True
| Byte _ => True
| Fragment v'' _ _ =>
mem_wd.val_valid v'' m
end.