Section AMap2PMap.
(*Need to build a permission map from a finite map*)
(*The pmap is used in the compcert memory. *)
Context {lock_info: Type}.
Variable am: AMap.t lock_info.
Definition A2PMap (*: Map.PMap*) :=
fold_left
(fun (pmap:access_map) (a:address * lock_info)=>
match a with
| ((b, ofs), _) => setPermBlock (Some Memtype.Writable) b ofs pmap LKSIZE_nat
end)
(AMap.elements am)
(PMap.init (fun _ => None)).
End AMap2PMap.
Instance EqDec_AMap_key : EqDec AMap.key.
Definition PMap_eq {A} (m m' : PMap.t (Z -> A)) := forall b' ofs', m !! b' ofs' = m' !! b' ofs'.
Definition A2P {A} :=
(fun (pmap : access_map) (a : address * A) =>
let (a0, _) := a in let (b0, ofs0) := a0 in setPermBlock (Some Writable) b0 ofs0 pmap LKSIZE_nat).

Lemma A2PMap_add_outside T b b' ofs ofs' set o :
(@A2PMap T (AMap.add (b, ofs) o set)) !! b' ofs' =
if adr_range_dec (b, ofs) LKSIZE (b', ofs') then
Some Writable
else
(@A2PMap T set) !! b' ofs'.