File size: 2,320 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Require Import Coq.ZArith.ZArith.
Require Import Coq.Lists.List.
Require Import Coq.micromega.Lia.
From AUXLib Require Import ListLib.
From SimpleC.SL Require Import Mem SeparationLogic ArrayLib.
Require Import Logic.LogicGenerator.demo932.Interface.

Import ListNotations.
Local Open Scope Z_scope.
Local Open Scope list_scope.
Import naive_C_Rules.
Local Open Scope sac.

(**
  [sll] is the abstract, singly-linked-list-shaped sequence used to describe
  stack contents.  It is deliberately independent of the concrete memory
  representation: this case stores the sequence in a contiguous C array.
  The head of an [sll] is the logical top of the stack.
 *)
Definition sll : Type := list Z.

Definition sll_empty : sll := [].

Definition sll_cons (x : Z) (contents : sll) : sll :=
  x :: contents.

Definition sll_from_array (concrete : list Z) : sll :=
  rev concrete.

Definition stack_capacity : Z := 100000.

(**
  Physical array index 0 is the bottom of the stack, so the concrete array is
  the reverse of the abstract [sll].  Keeping the size in the relation makes
  every public stack state carry the capacity and exact-length invariants.
 *)
Definition stack_representation
    (contents : sll) (concrete : list Z) (size : Z) : Prop :=
  0 <= size /\
  size <= stack_capacity /\
  Zlength contents = size /\
  Zlength concrete = size /\
  concrete = rev contents.

Definition store_stack
    (p : Z) (contents : sll) (size : Z) : Assertion :=
  EX concrete : list Z,
    “ stack_representation contents concrete size ” &&
    IntArray.full p size concrete.

(**
  Mathematical state shared by the incremental [build] annotations.  The C
  invariant owns the loop bounds and the array resources; this predicate owns
  only the abstract meaning of the already processed input prefix.
 *)
Definition BuildStackPrefix
    (contents : sll) (input : list Z) (processed : Z) : Prop :=
  contents = sll_from_array (sublist 0 processed input).

(**
  Body-facing view of the frozen public representation relation.  Keeping a
  separate internal root preserves the frozen [store_stack] dependency
  surface while allowing QCP assertions to open its concrete array facts.
 *)
Definition StackConcreteView
    (contents : sll) (concrete : list Z) (size : Z) : Prop :=
  stack_representation contents concrete size.