1 | |
---|
2 | (**************************************************************************) |
---|
3 | (* ___ *) |
---|
4 | (* ||M|| *) |
---|
5 | (* ||A|| A project by Andrea Asperti *) |
---|
6 | (* ||T|| *) |
---|
7 | (* ||I|| Developers: *) |
---|
8 | (* ||T|| The HELM team. *) |
---|
9 | (* ||A|| http://helm.cs.unibo.it *) |
---|
10 | (* \ / *) |
---|
11 | (* \ / This file is distributed under the terms of the *) |
---|
12 | (* v GNU General Public License Version 2 *) |
---|
13 | (* *) |
---|
14 | (**************************************************************************) |
---|
15 | |
---|
16 | include "ERTLptr/ERTLtoERTLptr.ma". |
---|
17 | include "common/StatusSimulation.ma". |
---|
18 | include "joint/Traces.ma". |
---|
19 | include "ERTLptr/ERTLptr_semantics.ma". |
---|
20 | include "common/ExtraMonads.ma". |
---|
21 | |
---|
22 | definition ERTL_status ≝ |
---|
23 | λprog : ertl_program.λstack_sizes. |
---|
24 | joint_abstract_status (mk_prog_params ERTL_semantics prog stack_sizes). |
---|
25 | |
---|
26 | definition ERTLptr_status ≝ |
---|
27 | λprog : ertlptr_program.λstack_sizes. |
---|
28 | joint_abstract_status (mk_prog_params ERTLptr_semantics prog stack_sizes). |
---|
29 | |
---|
30 | definition sigma_map ≝ λ prog : ertl_program. |
---|
31 | joint_closed_internal_function ERTL (prog_var_names … prog) → label → option label. |
---|
32 | |
---|
33 | |
---|
34 | definition sigma_pc_opt : |
---|
35 | ∀ prog : ertl_program. |
---|
36 | sigma_map prog → program_counter → option program_counter ≝ |
---|
37 | λprog,sigma,pc. |
---|
38 | let ge ≝ globalenv_noinit … prog in |
---|
39 | if eqZb (block_id (pc_block pc)) (-1) then (* check for dummy exit pc *) |
---|
40 | return pc |
---|
41 | else |
---|
42 | ! 〈i, fd〉 ← res_to_opt … (fetch_internal_function … ge (pc_block pc)) ; |
---|
43 | ! ertl_ptr_point ← sigma fd (point_of_pc ERTL_semantics pc) ; |
---|
44 | return pc_of_point |
---|
45 | ERTLptr_semantics (pc_block pc) ertl_ptr_point. |
---|
46 | |
---|
47 | definition sigma_stored_pc ≝ |
---|
48 | λprog,sigma,pc. match sigma_pc_opt prog sigma pc with |
---|
49 | [None ⇒ null_pc (pc_offset … pc) | Some x ⇒ x]. |
---|
50 | |
---|
51 | |
---|
52 | definition sigma_beval : |
---|
53 | ∀prog : ertl_program. |
---|
54 | sigma_map prog → |
---|
55 | beval → beval ≝ |
---|
56 | λprog,sigma,bv. |
---|
57 | match bv with |
---|
58 | [ BVpc pc prt ⇒ match sigma_pc_opt prog sigma pc with |
---|
59 | [None ⇒ BVundef | Some x ⇒ BVpc x prt] |
---|
60 | | _ ⇒ bv |
---|
61 | ]. |
---|
62 | |
---|
63 | (* |
---|
64 | definition sigma_beval : |
---|
65 | ∀prog,sigma,bv. |
---|
66 | sigma_beval_opt prog sigma bv ≠ None ? → beval ≝ |
---|
67 | λprog,sigma,bv.opt_safe …. |
---|
68 | *) |
---|
69 | definition sigma_is : |
---|
70 | ∀prog : ertl_program. |
---|
71 | sigma_map prog → |
---|
72 | internal_stack → internal_stack ≝ |
---|
73 | λprog,sigma,is. |
---|
74 | match is with |
---|
75 | [ empty_is ⇒ empty_is |
---|
76 | | one_is bv ⇒ one_is (sigma_beval prog sigma bv) |
---|
77 | | both_is bv1 bv2 ⇒ |
---|
78 | both_is (sigma_beval prog sigma bv1) (sigma_beval prog sigma bv2) |
---|
79 | ]. |
---|
80 | |
---|
81 | lemma sigma_is_empty : ∀prog,sigma. |
---|
82 | sigma_is prog sigma empty_is = empty_is. |
---|
83 | #prog #sigma % |
---|
84 | qed. |
---|
85 | |
---|
86 | definition sigma_mem : |
---|
87 | ∀prog : ertl_program . sigma_map prog → bemem → bemem ≝ |
---|
88 | λprog,sigma,m. |
---|
89 | mk_mem |
---|
90 | (λb. |
---|
91 | If Zltb (block_id b) (nextblock m) then with prf' do |
---|
92 | let l ≝ low_bound m b in |
---|
93 | let h ≝ high_bound m b in |
---|
94 | mk_block_contents l h |
---|
95 | (λz.If Zleb l z ∧ Zltb z h then with prf'' do |
---|
96 | sigma_beval prog sigma (contents (blocks m b) z) |
---|
97 | else BVundef) |
---|
98 | else empty_block OZ OZ) |
---|
99 | (nextblock m) |
---|
100 | (nextblock_pos m). |
---|
101 | |
---|
102 | (*DOPPIONE ASSIOMA IN LINEARISE_PROOF.MA *) |
---|
103 | axiom mem_ext_eq : |
---|
104 | ∀m1,m2 : mem. |
---|
105 | (∀b.let bc1 ≝ blocks m1 b in |
---|
106 | let bc2 ≝ blocks m2 b in |
---|
107 | low bc1 = low bc2 ∧ high bc1 = high bc2 ∧ |
---|
108 | ∀z.contents bc1 z = contents bc2 z) → |
---|
109 | nextblock m1 = nextblock m2 → m1 = m2. |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | inductive id_is_in (A : Type[0]) : Pos → positive_map A → Prop ≝ |
---|
114 | | is_in_root : ∀l,r,opt_a. id_is_in A (one) (pm_node … opt_a l r) |
---|
115 | | is_in_left : ∀l,r,opt_a,x. id_is_in A x l → |
---|
116 | id_is_in A (p0 x) (pm_node … opt_a l r) |
---|
117 | | is_in_right : ∀l,r,opt_a,x. id_is_in A x r → |
---|
118 | id_is_in A (p1 x) (pm_node … opt_a l r). |
---|
119 | |
---|
120 | definition id_is_in : ∀A : Type[0]. ∀tag : identifierTag. |
---|
121 | identifier_map tag A → identifier tag → Prop ≝ |
---|
122 | λA,tag,m,id.match id with |
---|
123 | [an_identifier x ⇒ match m with |
---|
124 | [an_id_map p ⇒ id_is_in A x p] |
---|
125 | ]. |
---|
126 | |
---|
127 | lemma lookup_eq : ∀ A : Type[0]. |
---|
128 | ∀m,m' : positive_map A. |
---|
129 | (∀id. lookup_opt A id m = lookup_opt A id m' |
---|
130 | ∧ (id_is_in A id m ↔ id_is_in A id m')) → m=m'. |
---|
131 | #A #m elim m |
---|
132 | [ * [#_ %] #opt_a #l #r #H lapply(H one) normalize * #EQ >EQ * #_ #H1 lapply(H1 ?) [%] |
---|
133 | -H1 -H <EQ -EQ #H inversion H #l1 #r1 #opt_a1 |
---|
134 | [ #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) |
---|
135 | |*: #pos #H1 #_ #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) |
---|
136 | ] |
---|
137 | | #opt_a #l #r #Hl #Hr * |
---|
138 | [ #H lapply(H one) normalize * #EQ >EQ * #H1 #_ lapply(H1 ?) [%] |
---|
139 | -H1 -H -EQ #H inversion H #l1 #r1 #opt_a1 |
---|
140 | [ #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) |
---|
141 | |*: #pos #H1 #_ #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) |
---|
142 | ] |
---|
143 | | #opt_a1 #l1 #r1 #H lapply(H one) normalize * #EQ >EQ -EQ #_ @eq_f2 [@Hl|@Hr] |
---|
144 | #id [ lapply(H (p0 id)) | lapply(H (p1 id))] normalize * #H1 * #H2 #H3 % |
---|
145 | [1,3: assumption] % #H4 [1,3: lapply(H2 ?) |*: lapply(H3 ?)] |
---|
146 | try %2 try %3 try assumption #H5 inversion H5 #l2 #r2 #opt_a2 |
---|
147 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ @⊥ |
---|
148 | [1,3: cut(p0 id ≠ one) [1,3: @(pos_elim … id) /3/] |
---|
149 | |*: cut(p1 id ≠ one) [1,3: @(pos_elim … id) /3/] |
---|
150 | ] * #H @H assumption |
---|
151 | |*: #pos #H6 #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) |
---|
152 | #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct(EQ) #_ assumption |
---|
153 | ] |
---|
154 | ] |
---|
155 | ] |
---|
156 | qed. |
---|
157 | |
---|
158 | include alias "common/Identifiers.ma". |
---|
159 | include alias "common/PositiveMap.ma". |
---|
160 | |
---|
161 | |
---|
162 | lemma p0_neq_one : ∀x: Pos. p0 x ≠ one. |
---|
163 | #x /3/ |
---|
164 | qed. |
---|
165 | |
---|
166 | lemma p1_neq_one : ∀x: Pos. p1 x ≠ one. |
---|
167 | #x /3/ |
---|
168 | qed. |
---|
169 | |
---|
170 | lemma lookup_ok_to_update : ∀ A : Type[0]. |
---|
171 | ∀ tag : identifierTag. |
---|
172 | ∀m,m' : identifier_map tag A. ∀id,a. |
---|
173 | (lookup tag A m' id = Some ? a) → lookup tag A m id ≠ None ? → |
---|
174 | (∀ id'. id ≠ id' → (lookup tag A m id' = lookup tag A m' id') ∧ |
---|
175 | (id_is_in A tag m id' ↔ id_is_in A tag m' id')) → |
---|
176 | update tag A m id a = return m'. |
---|
177 | #A #tag * #m * #m' * #id #a |
---|
178 | normalize in ⊢ (%→%→?); lapply id -id lapply m' -m' elim m |
---|
179 | [ #m' #id #m_spec' normalize in ⊢ (% → ?); * #EQ @⊥ @EQ %] #opt_a #l #r #Hl #Hr |
---|
180 | #m' * [|*: #x] normalize in ⊢ (%→%→?); #m_spec' |
---|
181 | [ cases opt_a -opt_a [* #H @⊥ @H %] #a1 #_ #H normalize @eq_f @eq_f |
---|
182 | lapply H -H lapply m_spec'; -m_spec' lapply a -a cases m' |
---|
183 | [#a normalize #EQ destruct] #opt_a1 #l1 #r1 #a |
---|
184 | normalize in ⊢ (%→?); #EQ >EQ #H @eq_f2 @lookup_eq #id' |
---|
185 | [ lapply (H (an_identifier tag (p0 id')) ?) |
---|
186 | | lapply (H (an_identifier tag (p1 id')) ?) |
---|
187 | ] |
---|
188 | [1,3:% @(pos_elim … id') [1,3:#H destruct|*: #n #IP #H destruct]] |
---|
189 | * normalize #H1 * #H2 #H3 % [1,3: >H1 %] % #H4 |
---|
190 | [1,3: lapply(H2 ?) |*: lapply(H3 ?)] try %2 try %3 try assumption |
---|
191 | #H5 inversion H5 #l2 #r2 #opt_a2 |
---|
192 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ @⊥ |
---|
193 | [1,3: cut(p0 id' ≠ one) [1,3: /3/] |
---|
194 | |*: cut(p1 id' ≠ one) [1,3: /3/] |
---|
195 | ] >EQ * #H @H % |
---|
196 | |*: #pos #H6 #_ #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 destruct(EQ1) |
---|
197 | #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 destruct(EQ1) #_ assumption |
---|
198 | ] |
---|
199 | |*: #H lapply m_spec' -m_spec' cases m' -m' [1,3: normalize #EQ destruct] |
---|
200 | #opt_a1 #l1 #r1 normalize in ⊢ (% → ?); #H1 #H2 |
---|
201 | [ lapply(Hr ?? H1 H ?) | lapply(Hl ?? H1 H ?)] |
---|
202 | [1,3: * #y * #y_spec |
---|
203 | [lapply(H2 (an_identifier tag (p1 y)) ?) | lapply(H2 (an_identifier tag (p0 y)) ?)] |
---|
204 | [1,3: % #EQ destruct @y_spec %] * normalize #H3 * #H4 #H5 % // % #H6 |
---|
205 | [1,3: lapply(H4 ?) |*: lapply (H5 ?)] try %2 try %3 try assumption |
---|
206 | #H7 inversion H7 #l2 #r2 #opt_a2 |
---|
207 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ @⊥ |
---|
208 | [1,3: cut(p1 y ≠ one) [1,3: /3/] |
---|
209 | |*: cut(p0 y ≠ one) [1,3: /3/] |
---|
210 | ] >EQ * #H @H % |
---|
211 | |*: #pos #H6 #_ #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 |
---|
212 | destruct(EQ1) #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 |
---|
213 | destruct(EQ1) #_ assumption |
---|
214 | ] |
---|
215 | |2,4: normalize cases(update A x a ?) normalize [2,4: #pos_map] |
---|
216 | #EQ destruct @eq_f @eq_f lapply(H2 (an_identifier tag one) ?) |
---|
217 | [1,3: % #EQ destruct] * normalize #EQ >EQ #_ @eq_f2 [2,3: %] |
---|
218 | @lookup_eq #id' |
---|
219 | [lapply (H2 (an_identifier tag (p0 id')) ?) | |
---|
220 | lapply (H2 (an_identifier tag (p1 id')) ?) ] |
---|
221 | [1,3: % #EQ1 destruct] * normalize #H3 * #H4 #H5 % // % #H6 |
---|
222 | [1,3: lapply(H4 ?) |*: lapply(H5 ?)] try %2 try %3 try assumption |
---|
223 | #H7 inversion H7 #l2 #r2 #opt_a2 |
---|
224 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ @⊥ |
---|
225 | [1,3: cut(p0 id' ≠ one) [1,3: /3/] |
---|
226 | |*: cut(p1 id' ≠ one) [1,3: /3/] |
---|
227 | ] >EQ * #H @H % |
---|
228 | |*: #pos #H6 #_ #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 |
---|
229 | destruct(EQ1) #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 |
---|
230 | destruct(EQ1) #_ assumption |
---|
231 | ] |
---|
232 | ] |
---|
233 | ] |
---|
234 | qed. |
---|
235 | |
---|
236 | lemma update_ok_to_lookup : ∀ A : Type[0]. |
---|
237 | ∀ tag : identifierTag. |
---|
238 | ∀m,m' : identifier_map tag A. ∀id,a. |
---|
239 | update tag A m id a = return m' → |
---|
240 | (lookup tag A m' id = Some ? a) ∧ lookup tag A m id ≠ None ? ∧ |
---|
241 | (∀ id'. id ≠ id' → (lookup tag A m id' = lookup tag A m' id') ∧ |
---|
242 | (id_is_in A tag m id' ↔ id_is_in A tag m' id')). |
---|
243 | #A #tag * #m * #m' * #id #a |
---|
244 | whd in ⊢ (??%% → ?); inversion(update A ???) normalize nodelta [#_ #ABS destruct] |
---|
245 | #m1 #m1_spec #EQ destruct % [%] |
---|
246 | [ normalize @(update_lookup_opt_same … m1_spec) |
---|
247 | |3: * #id' * #id_spec' normalize % |
---|
248 | [@(update_lookup_opt_other … m1_spec ??) % #EQ @id_spec' >EQ %] |
---|
249 | lapply id_spec' lapply m1_spec -id_spec' -m1_spec |
---|
250 | (*cases id [|*:#x] -id normalize*) lapply m' -m' lapply id lapply id' -id -id' |
---|
251 | elim m [#id' #id #m' cases id [|*: #x] normalize #EQ destruct] |
---|
252 | #opt_a #l #r #Hl #Hr #id' #id #m' cases id [|*:#x] -id normalize |
---|
253 | [ cases opt_a [2:#a] normalize #EQ destruct cases id' [#H @⊥ @H %] |
---|
254 | #x #_ normalize % #H [1,2: %3 |*: %2] |
---|
255 | inversion H #l1 #r1 #opt_a1 |
---|
256 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) #EQ1 @⊥ |
---|
257 | [1,2: cut(p1 x ≠ one) [1,3: @(pos_elim … x) /3/] |
---|
258 | |*: cut(p0 x ≠ one) [1,3: @(pos_elim … x) /3/] |
---|
259 | ] |
---|
260 | * #H @H >EQ1 // |
---|
261 | |*: #pos #H1 #_ #EQ lapply(jmeq_to_eq ??? EQ) #EQ1 destruct(EQ1) |
---|
262 | #EQ lapply(jmeq_to_eq ??? EQ) #EQ1 destruct(EQ1) #_ assumption |
---|
263 | ] |
---|
264 | |*: inversion(update A x a ?) normalize [1,3: #_ #EQ destruct] #pos_map |
---|
265 | #pos_map_spec #EQ destruct #id_spec' % #H |
---|
266 | inversion H #l1 #l2 #opt_a1 |
---|
267 | [1,4,7,10: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ |
---|
268 | #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 destruct(EQ1) |
---|
269 | #H1 % |
---|
270 | |*: #pos #H1 #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ |
---|
271 | #EQ1 lapply(jmeq_to_eq ??? EQ1) -EQ1 #EQ1 destruct(EQ1) |
---|
272 | #H2 try %2 try %3 try assumption |
---|
273 | [ @(proj1 … (Hr ? ? pos_map pos_map_spec ?)) [#EQ1 destruct @id_spec' %] |
---|
274 | | @(proj2 … (Hr ? ? l2 pos_map_spec ?)) [#EQ1 destruct @id_spec' %] |
---|
275 | | @(proj1 … (Hl ? ? pos_map pos_map_spec ?)) [#EQ1 destruct @id_spec' %] |
---|
276 | | @(proj2 … (Hl ? ? l1 pos_map_spec ?)) [#EQ1 destruct @id_spec' %] |
---|
277 | ] |
---|
278 | assumption |
---|
279 | ] |
---|
280 | ] |
---|
281 | | % normalize lapply m1_spec lapply id lapply m' -id -m' elim m |
---|
282 | [#m' * [|*: #x] normalize #EQ destruct] #opt_a #l #r #Hl #Hr #m' * [|*: #x] |
---|
283 | normalize [ cases opt_a [2:#a] normalize #EQ1 #EQ2 destruct] |
---|
284 | inversion (update A x a ?) [1,3: #_ normalize #EQ destruct] |
---|
285 | #pos_map #EQpos_map normalize #EQ destruct [@Hr|@Hl] assumption |
---|
286 | ] |
---|
287 | qed. |
---|
288 | |
---|
289 | |
---|
290 | (* |
---|
291 | |
---|
292 | lemma update_lookup_after : ∀ A : Type[0]. |
---|
293 | ∀ tag : identifierTag. |
---|
294 | ∀m,m' : identifier_map tag A. ∀id,a. |
---|
295 | update tag A m id a = return m' → |
---|
296 | lookup tag A m' id = Some ? a. |
---|
297 | #A #B #tag * #m1 * #id #a whd in ⊢ (??%% → ?); inversion(update A ???) |
---|
298 | normalize nodelta [#_ #EQ destruct] #pos_map #pos_map_spec #EQ destruct |
---|
299 | @(update_lookup_opt_same … pos_map_spec) |
---|
300 | qed. |
---|
301 | |
---|
302 | lemma p0_neq_one : ∀x: Pos. p0 x ≠ one. |
---|
303 | #x /3/ |
---|
304 | qed. |
---|
305 | |
---|
306 | lemma p1_neq_one : ∀x: Pos. p1 x ≠ one. |
---|
307 | #x /3/ |
---|
308 | qed. |
---|
309 | |
---|
310 | lemma id_is_in_map : ∀ A,B : Type[0]. ∀tag : identifierTag. |
---|
311 | ∀m : identifier_map tag A. |
---|
312 | ∀ F : (∀a:A.(Σid. lookup tag A m id = Some A a) → B). |
---|
313 | ∀id. id_is_in A tag m id ↔ id_is_in B tag (map_inf1 A B tag m F) id. |
---|
314 | #A #B #tag * #m elim m |
---|
315 | [ #F * #id % normalize #H inversion H #l #r #opt_a |
---|
316 | [1,4: #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct |
---|
317 | |*: #pos #H1 #_ #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct |
---|
318 | ] |
---|
319 | | * [2:#a] #l #r #Hl #Hr #F ** [1,4: |*:#x] normalize % #H try % try %2 try %3 |
---|
320 | [1,2,5,6: cases(Hr ? (an_identifier tag x)) |*: cases (Hl ? (an_identifier tag x))] |
---|
321 | [2,4,6,8,10,12,14,16: #a1 ** #id1 #prf1 @F try(@a1) |
---|
322 | try(%{(an_identifier tag (p1 id1))} assumption) |
---|
323 | try(%{(an_identifier tag (p0 id1))} assumption) ] |
---|
324 | try(#H1 #_ @H1) try(#_ #H1 @H1) -H1 -Hl -Hr inversion H #l1 #r1 #opt_a1 |
---|
325 | [1,4,7,10,13,16,19,22: #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ @⊥ |
---|
326 | [1,2,3,4: lapply(p1_neq_one x) |
---|
327 | |*: lapply(p0_neq_one x) |
---|
328 | ] * #H @H >EQ % |
---|
329 | |*: #pos #H1 #_ #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct |
---|
330 | #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQ destruct #_ assumption |
---|
331 | ] |
---|
332 | ] |
---|
333 | qed. |
---|
334 | |
---|
335 | lemma map_update_commute : ∀ A, B : Type[0]. |
---|
336 | ∀tag : identifierTag. |
---|
337 | ∀m1,m2 : identifier_map tag A. |
---|
338 | ∀id,a. |
---|
339 | update tag A m1 id a = return m2 → |
---|
340 | ∀ F : (∀a:A.(Σid. lookup tag A m1 id = Some A a) → B). |
---|
341 | ∀ F': (∀a:A.(Σid. lookup tag A m2 id = Some A a) → B). |
---|
342 | (∀a',id',prf,prf'. F a' «id',prf» = F' a' «id',prf'») → ∃prf. |
---|
343 | update tag B (map_inf1 A B tag m1 F) id (F' a «id,prf») = |
---|
344 | return map_inf1 A B tag m2 F'. |
---|
345 | #A #B #tag #m1 #m2 #id #a #m2_spec #F #F' #eqFF' % |
---|
346 | [ @hide_prf cases(update_lookup_previous A tag m1 m2 id a) #H1 #_ cases (H1 m2_spec) |
---|
347 | * #H1 #H2 #H3 assumption |
---|
348 | | cases(update_lookup_previous B tag (map_inf1 A B tag m1 F) |
---|
349 | (map_inf1 A B tag m2 F') id (F' a «id,?»)) |
---|
350 | [ #_ #H @H |] cases(update_lookup_previous A tag m1 m2 id a) #H2 #INUTILE |
---|
351 | cases(H2 m2_spec) * #H3 #H4 #H5 % [%] |
---|
352 | [ >(lookup_map … H3) % |
---|
353 | | elim H4 -H4 #H4 % #H5 @H4 lapply H5 cases m1 in F; -m1 #m1 cases id -id |
---|
354 | elim m1 [ #id #F normalize * %] #a1 #l #r #Hl #Hr * [|*:#x] #F normalize |
---|
355 | [ cases a1 in F; [2: #a2] #F normalize [2: * %] #EQ destruct |
---|
356 | |*: #H |
---|
357 | [@(Hr x ??) | @(Hl x ??)] |
---|
358 | [1,3:#a ** #id1 #prf1 @F [1,3: @a] |
---|
359 | [%{(an_identifier tag (p1 id1))}|%{(an_identifier tag (p0 id1))}] |
---|
360 | normalize assumption |
---|
361 | |*: normalize @H |
---|
362 | ] |
---|
363 | ] |
---|
364 | | #id' #id_spec' lapply(H5 id' id_spec') * #H6 * #H7 #H8 % |
---|
365 | [ lapply H6 inversion (lookup tag A m2 id') |
---|
366 | [2: #w] #w_spec #EQ >(lookup_map … EQ) normalize nodelta |
---|
367 | >(lookup_map … w_spec) normalize nodelta [2: %] @eq_f @eqFF' |
---|
368 | | cases(id_is_in_map A B tag m1 F id') cases(id_is_in_map A B tag m2 F' id') |
---|
369 | #H9 #H10 #H11 #H12 % #H13 [ @H9 @H7 @H12 assumption | @H11 @H8 @H10 assumption] |
---|
370 | ] |
---|
371 | ] |
---|
372 | qed. |
---|
373 | |
---|
374 | (* |
---|
375 | definition well_formed_register_env : |
---|
376 | ∀prog : ertl_program .∀sigma : (sigma_map prog). |
---|
377 | register_env beval → Prop ≝ |
---|
378 | λprog,sigma,psd_reg.∀id,bv. lookup ?? psd_reg id = Some ? bv → |
---|
379 | sigma_beval_opt prog sigma bv ≠ None ?. |
---|
380 | *) |
---|
381 | *) |
---|
382 | |
---|
383 | definition map : ∀tag,A,B. identifier_map tag A → (A → B) → identifier_map tag B ≝ |
---|
384 | λtag,A,B,m,f.match m with |
---|
385 | [an_id_map p ⇒ an_id_map … (map ?? f p)]. |
---|
386 | |
---|
387 | lemma lookup_map : ∀A,B : Type[0]. |
---|
388 | ∀tag : identifierTag. |
---|
389 | ∀m : identifier_map tag A. |
---|
390 | ∀ f:A → B. |
---|
391 | ∀ id. |
---|
392 | lookup tag B (map tag A B m f) id = |
---|
393 | ! a ← lookup tag A m id; return f a. |
---|
394 | #A #B #tag * #m #f * #id normalize >lookup_opt_map % |
---|
395 | qed. |
---|
396 | |
---|
397 | lemma update_leaf_fail: ∀tag,A,i,v. |
---|
398 | update tag A (empty_map ??) i v = Error ? [MSG MissingId; CTX … i]. |
---|
399 | #ta #A ** [|*: #x] #v normalize % |
---|
400 | qed. |
---|
401 | |
---|
402 | lemma update_def : ∀tag,A,m,i,v. |
---|
403 | update tag A m i v = |
---|
404 | match lookup tag A m i with |
---|
405 | [ Some _ ⇒ OK ? (add tag A m i v) |
---|
406 | | None ⇒ Error ? [MSG MissingId; CTX … i] |
---|
407 | ]. |
---|
408 | #tag #A #m #i #v inversion(update tag A m i v) |
---|
409 | [ #m' #EQm' cases(update_ok_to_lookup ?????? EQm') * #_ |
---|
410 | #H #_ elim H cases(lookup tag A m i) [#H @⊥ @H %] |
---|
411 | #x #_ normalize <EQm' lapply EQm' cases i cases m cases m' -m -m' -i |
---|
412 | normalize #m' #m #i inversion(update A i v m) normalize [#_ #ABS destruct] |
---|
413 | #m'' #EQm'' #EQ destruct(EQ) @eq_f @eq_f lapply EQm'' -EQm'' lapply i -i |
---|
414 | lapply m' -m' elim m [#m' * [2,3: #z] normalize #EQ destruct] |
---|
415 | #opt_a #l #r #Hl #Hr #m' * [2,3: #z] normalize |
---|
416 | [3: cases opt_a normalize [2: #y] #EQ destruct % |
---|
417 | |*: inversion(update A z v ?) [2,4: #m''] #EQm'' normalize #EQ destruct |
---|
418 | [<(Hr … EQm'') | <(Hl … EQm'')] % |
---|
419 | ] |
---|
420 | | #err cases m -m cases i -i #i #m normalize inversion(update A i v m) [2:#m'] |
---|
421 | #EQerr normalize #EQ destruct lapply EQerr lapply i elim m |
---|
422 | [ normalize #x #_ %] #opt_a #l #r #Hl #Hr * [2,3:#z] normalize |
---|
423 | [3: cases opt_a [2:#w] normalize #EQ destruct % |
---|
424 | |*: inversion(update A z v ?) [2,4: #m'] #EQm' normalize #EQ destruct |
---|
425 | [lapply(Hr … EQm') | lapply(Hl … EQm')] cases(lookup_opt A z ?) [2,4: #a] |
---|
426 | normalize #EQ destruct % |
---|
427 | ] |
---|
428 | ] |
---|
429 | qed. |
---|
430 | |
---|
431 | lemma map_add : ∀tag : identifierTag.∀A,B : Type[0].∀ f: A → B.∀m,id,v. |
---|
432 | map tag A B (add tag A m id v) f = add tag B (map tag A B m f) id (f v). |
---|
433 | #tag #A #B #f * #m * #id #v normalize @eq_f lapply v -v lapply id -id elim m |
---|
434 | [ #id elim id [#v %] #x #IH #id normalize >IH normalize inversion(pm_set ? ? ? ?) |
---|
435 | normalize // cases x normalize [2,3,5,6: #y] #EQ destruct |
---|
436 | | #opt_a #l #r #Hl #Hr * [2,3: #x| #v normalize cases opt_a normalize [2: #a %] |
---|
437 | cases (map_opt ? ? ? l) normalize [2: //] cases (map_opt ? ? ? r) normalize |
---|
438 | //] #v normalize cases opt_a [2,4: #a] normalize // |
---|
439 | [ cases(map_opt ? ? ? l) normalize // >Hr cases(map_opt ? ? ? r) normalize |
---|
440 | [2: #opt_b #lb #rb] inversion(pm_set B x ? ?) normalize // cases x [2,3,5,6: #y] |
---|
441 | normalize #EQ destruct |
---|
442 | | >Hl cases(map_opt ? ? ? l) normalize [2: #opt_b #lb #rb] |
---|
443 | inversion (pm_set B x ? ?) normalize // |
---|
444 | [1,2: cases x [2,3,5,6: #y] normalize #EQ destruct] |
---|
445 | #opt_b' #lb' #rb' #_ normalize #_ #EQ cases(map_opt ? ? ? r) |
---|
446 | normalize nodelta [%] #opt_b'' #lb'' #rb'' >EQ % |
---|
447 | ] |
---|
448 | qed. |
---|
449 | |
---|
450 | |
---|
451 | definition restrict : ∀tag.∀A,B. |
---|
452 | identifier_map tag A → identifier_map tag B → identifier_map tag A ≝ |
---|
453 | λtag,A,B,m1,m2.an_id_map … |
---|
454 | (merge A B A (λo,o'.match o' with [None ⇒ None ? | Some _ ⇒ o]) |
---|
455 | (match m1 with [an_id_map p1 ⇒ p1]) |
---|
456 | (match m2 with [an_id_map p2 ⇒ p2])). |
---|
457 | |
---|
458 | interpretation "identifier map restriction" 'intersects a b = (restrict ??? a b). |
---|
459 | |
---|
460 | unification hint 0 ≔ tag ; R ≟ identifier tag ⊢ list R ≡ list (identifier tag). |
---|
461 | |
---|
462 | lemma map_update_commute : ∀tag : identifierTag.∀A,B : Type[0].∀f : A → B. ∀m,id,v. |
---|
463 | update tag B (map tag A B m f) id (f v) = |
---|
464 | !m' ← update tag A m id v; return map tag A B m' f. |
---|
465 | #tag #A #B #f #m #id #v >update_def >update_def >lookup_map |
---|
466 | cases (lookup tag A m id) [%] #a >m_return_bind >m_return_bind normalize nodelta |
---|
467 | whd in ⊢ (???%); @eq_f @sym_eq @map_add |
---|
468 | qed. |
---|
469 | |
---|
470 | definition is_leaf ≝ λA.λpm : positive_map A. |
---|
471 | match pm with [ pm_leaf ⇒ true | _ ⇒ false ]. |
---|
472 | (* |
---|
473 | let rec pm_clean A (pm : positive_map A) on pm : positive_map A ≝ |
---|
474 | match pm with |
---|
475 | [ pm_leaf ⇒ pm_leaf ? |
---|
476 | | pm_node o l r ⇒ |
---|
477 | let l' ≝ pm_clean … l in |
---|
478 | let r' ≝ pm_clean … r in |
---|
479 | match o with |
---|
480 | [ Some _ ⇒ pm_node … o l' r' |
---|
481 | | None ⇒ |
---|
482 | if is_leaf … l' ∧ is_leaf … r' then pm_leaf ? else |
---|
483 | pm_node … o l' r' |
---|
484 | ] |
---|
485 | ]. |
---|
486 | |
---|
487 | definition clean ≝ λtag,A.λm : identifier_map tag A. |
---|
488 | match m with [ an_id_map pm ⇒ an_id_map tag A (pm_clean … pm) ]. |
---|
489 | *) |
---|
490 | |
---|
491 | definition sigma_register_env : |
---|
492 | ∀prog : ertl_program.∀sigma : (sigma_map prog). |
---|
493 | register_env beval → list register → register_env beval ≝ |
---|
494 | λprog,sigma,psd_env,ids. |
---|
495 | let m' ≝ map ??? psd_env (λbv.sigma_beval prog sigma bv) in |
---|
496 | m' ∖ ids. |
---|
497 | |
---|
498 | (* |
---|
499 | definition well_formed_ertl_psd_env : |
---|
500 | ∀prog : ertl_program. ∀sigma : (sigma_map prog). |
---|
501 | ertl_psd_env → Prop≝ |
---|
502 | λprog,sigma,psd_env.well_formed_register_env prog sigma (psd_regs psd_env). |
---|
503 | *) |
---|
504 | (* |
---|
505 | let rec well_formed_frames |
---|
506 | (prog : ertl_program) (sigma : (sigma_map prog)) |
---|
507 | (l : list ertl_psd_env) on l : Prop ≝ |
---|
508 | match l with |
---|
509 | [nil ⇒ True |
---|
510 | | cons a tl ⇒ well_formed_ertl_psd_env prog sigma a ∧ |
---|
511 | well_formed_frames prog sigma tl |
---|
512 | ]. |
---|
513 | *) |
---|
514 | |
---|
515 | |
---|
516 | lemma lookup_restrict : ∀tag,A,B.∀a : identifier_map tag A.∀b : identifier_map tag B. |
---|
517 | ∀i.lookup ?? (a ∩ b) i = if i ∈ b then lookup … a i else None ?. |
---|
518 | #tag #A #B * #a * #b * #i normalize >lookup_opt_merge [2: %] cases (lookup_opt B i b) |
---|
519 | [2: #b] normalize % qed. |
---|
520 | |
---|
521 | |
---|
522 | lemma lookup_set_minus : ∀tag,A,B. ∀a : identifier_map tag A. ∀b : identifier_map tag B. |
---|
523 | ∀i. lookup ?? (a ∖ b) i = if i ∈ b then None ? else lookup … a i. |
---|
524 | #tag #A #B * #a * #b * #i normalize >lookup_opt_merge [2: %] cases(lookup_opt B i b) |
---|
525 | [2: #b] % qed. |
---|
526 | |
---|
527 | (* |
---|
528 | lemma clean_add : ∀tag,A,m,i,v.clean … (add tag A m i v) = add tag A (clean … m) i v. |
---|
529 | #tag #A * #m * #i #v normalize @eq_f |
---|
530 | lapply m -m |
---|
531 | elim i -i |
---|
532 | [ * [%] |
---|
533 | * [2: #x] #l #r [%] normalize |
---|
534 | cases (pm_clean A l) normalize // cases (pm_clean A r) // |
---|
535 | |*: #i #IH * normalize |
---|
536 | [1,3: >IH cases i // ] |
---|
537 | * [2,4: #x] #l #r normalize |
---|
538 | [1,2: >IH % ] |
---|
539 | >IH cases i cases (pm_clean A l) cases (pm_clean A r) normalize // |
---|
540 | ] |
---|
541 | qed. |
---|
542 | |
---|
543 | lemma clean_lookup : ∀tag,A,m,i.lookup … (clean tag A m) i = lookup … m i. |
---|
544 | #tag #A * #m * #i normalize lapply i -i elim m |
---|
545 | [#i %] * [2: #a] #l #r #Hl #Hr * [2,3,5,6: #x] normalize in ⊢ (???%); |
---|
546 | [1,3:<Hr|2,4:<Hl] normalize try % [3: @if_elim #_ %] |
---|
547 | cases(pm_clean A l) in Hl; normalize |
---|
548 | [2: #opt_a1 #l1 #r1 #_ % |
---|
549 | |3: #H cases(pm_clean A r) normalize // |
---|
550 | | #H cases(pm_clean A r) in Hr; normalize // |
---|
551 | | #opt_a1 #l1 #r1 #H cases x normalize // |
---|
552 | ] |
---|
553 | qed. |
---|
554 | |
---|
555 | |
---|
556 | lemma clean_update : ∀tag,A,m,i,v. |
---|
557 | ! m' ← update tag A m i v; return clean … m' = |
---|
558 | update tag A (clean … m) i v. |
---|
559 | #tag #A #m #i #v |
---|
560 | >update_def >update_def >clean_lookup cases (lookup tag A m i) |
---|
561 | [ % ] |
---|
562 | #m' >m_return_bind normalize nodelta >clean_add % |
---|
563 | qed. |
---|
564 | *) |
---|
565 | lemma lookup_eq_id_map : ∀tag : identifierTag. ∀ A : Type[0]. |
---|
566 | ∀m,m' : identifier_map tag A. |
---|
567 | (∀id. lookup … m id = lookup … m' id |
---|
568 | ∧ (id_is_in A tag m id ↔ id_is_in A tag m' id)) → m=m'. |
---|
569 | #tag #A * #m * #m' #H @eq_f @lookup_eq #id lapply(H (an_identifier tag id)) |
---|
570 | * #H1 #H2 % // assumption |
---|
571 | qed. |
---|
572 | |
---|
573 | (* |
---|
574 | lemma clean_leaf : ∀tag : identifierTag . ∀ A : Type[0]. |
---|
575 | ∀m : identifier_map tag A. (∀ id. lookup … m id = None ?) → |
---|
576 | clean ?? m = empty_map ??. |
---|
577 | #tag #A * #m elim m [#_ %] #opt_a #l #r #Hl #Hr #H normalize @eq_f |
---|
578 | lapply(H (an_identifier tag one)) normalize #EQ >EQ -EQ normalize |
---|
579 | lapply(Hl ?) [2: lapply(Hr ?)] |
---|
580 | [1,3: * #id [lapply(H (an_identifier tag (p1 id))) | lapply(H (an_identifier tag (p0 id)))] |
---|
581 | #H assumption |
---|
582 | | normalize #EQ #EQ1 destruct >e0 >e1 normalize % |
---|
583 | ] |
---|
584 | qed. |
---|
585 | *) |
---|
586 | lemma id_is_in_lookup : ∀tag,A,m,id,v. |
---|
587 | lookup tag A m id = Some ? v → id_is_in A tag m id. |
---|
588 | #tag #A * #m * #id #a normalize lapply m -m elim id |
---|
589 | [|*: #x #IH] * normalize [1,3,5: #EQ destruct] #opt_a #l #r [ #_ %] #H [%3 |%2] |
---|
590 | @IH assumption |
---|
591 | qed. |
---|
592 | (* |
---|
593 | lemma pm_clean_leaf : ∀ A : Type[0]. |
---|
594 | ∀m : positive_map A. (∀ id. lookup_opt … id m = None ?) → |
---|
595 | pm_clean ? m = pm_leaf …. |
---|
596 | #A #m elim m [ #id %] #opt_a #l #r #Hl #Hr #H normalize lapply(H one) normalize |
---|
597 | #EQ >EQ normalize >Hl [normalize >Hr [ %]] #id [@(H (p1 id))|@(H (p0 id))] |
---|
598 | qed. |
---|
599 | |
---|
600 | |
---|
601 | lemma pm_clean_canonic : ∀A,m,n.(∀i.lookup_opt A i m = lookup_opt A i n) → |
---|
602 | pm_clean ? m = pm_clean ? n. |
---|
603 | #A #m #n lapply m -m elim n |
---|
604 | [ @pm_clean_leaf ] |
---|
605 | * [2: #x] #l #r #IHl #IHr * |
---|
606 | [1,3: #H @sym_eq @pm_clean_leaf #id @sym_eq @H ] #opt #l' #r' #H |
---|
607 | lapply (H one) normalize in ⊢ (%→?); #EQ destruct |
---|
608 | whd in ⊢ (??%%); |
---|
609 | >(IHl l') [1,3: >(IHr r') [1,3 : % ]] #i |
---|
610 | [1,2: @(H (p1 i)) |*: @(H (p0 i)) ] qed. |
---|
611 | |
---|
612 | |
---|
613 | lemma clean_canonic : ∀tag,A,m,n.(∀i.lookup tag A m i = lookup tag A n i) → |
---|
614 | clean ?? m = clean ?? n. |
---|
615 | #tag #A * #m * #n #H normalize @eq_f @pm_clean_canonic #i |
---|
616 | lapply(H (an_identifier tag i)) |
---|
617 | normalize // |
---|
618 | qed. |
---|
619 | *) |
---|
620 | lemma update_fail_lookup : ∀tag,A,m,i,v,e.update tag A m i v = Error … e → |
---|
621 | e = [MSG MissingId; CTX … i] ∧ lookup … m i = None ?. |
---|
622 | #tag #A #m #i #v #errmsg >update_def cases(lookup tag A m i) [2: #a] normalize |
---|
623 | #EQ destruct % // |
---|
624 | qed. |
---|
625 | |
---|
626 | lemma lookup_hit_update : ∀tag,A,m,i,v.i ∈ m → |
---|
627 | ∃m'.update tag A m i v = OK ? m'. |
---|
628 | #tag #A #m #i #v #H % [2: >update_def lapply(in_map_domain … m i) >H * #v #EQ >EQ |
---|
629 | normalize %|] |
---|
630 | qed. |
---|
631 | |
---|
632 | lemma lookup_miss_update : ∀tag,A,m,i,v.lookup tag A m i = None ? → |
---|
633 | update … m i v = Error … [MSG MissingId; CTX … i]. |
---|
634 | #tag #A #m #i #v #EQ >update_def >EQ normalize % |
---|
635 | qed. |
---|
636 | |
---|
637 | lemma update_ok_old_lookup : ∀tag,A,m,i,v,m'.update tag A m i v = OK ? m' → |
---|
638 | i ∈ m. |
---|
639 | #tag #A #m #i #v #m' >update_def inversion(lookup tag A m i) [2: #a] #EQ normalize |
---|
640 | #EQ destruct >EQ normalize @I |
---|
641 | qed. |
---|
642 | |
---|
643 | lemma lookup_update_ok : ∀tag,A,m,i,v,m',i'.update tag A m i v = OK ? m' → |
---|
644 | lookup … m' i' = if eq_identifier ? i' i then Some ? v else lookup … m i'. |
---|
645 | #tag #A #m #i #v #m' #i' >update_def inversion(lookup tag A m i) [2: #a] #EQ |
---|
646 | normalize nodelta #EQ1 destruct @eq_identifier_elim |
---|
647 | [ #H normalize nodelta >H @lookup_add_hit |
---|
648 | | #H normalize nodelta @lookup_add_miss assumption |
---|
649 | ] |
---|
650 | qed. |
---|
651 | |
---|
652 | lemma mem_set_restrict : ∀tag,A,B.∀a : identifier_map tag A.∀b : identifier_map tag B. |
---|
653 | ∀i.i ∈ a ∩ b = (i ∈ a ∧ i ∈ b). |
---|
654 | #tag #A #B * #a * #b * #i normalize >lookup_opt_merge [2: %] cases(lookup_opt B i b) |
---|
655 | [2: #a1] normalize [2: @if_elim #_ %] cases(lookup_opt A i a) [2: #a2] normalize % |
---|
656 | qed. |
---|
657 | (* |
---|
658 | lemma merge_eq : ∀A.∀p : positive_map A.∀choice. merge |
---|
659 | *) |
---|
660 | (* |
---|
661 | lemma add_restrict : ∀tag,A,B.∀a : identifier_map tag A. ∀b : identifier_map tag B. |
---|
662 | ∀i,v.i∈b → add tag A (a ∩ b) i v = (add tag A a i v) ∩ b. |
---|
663 | #tag #A #B * #a * #b * #i #v normalize inversion(lookup_opt B i b) normalize [#_ *] |
---|
664 | #v1 #EQv1 * @eq_f lapply EQv1 lapply v1 lapply a lapply b -a -b -v1 elim i normalize |
---|
665 | [ * normalize [#b #v #EQ destruct] #opt_a #l #r * |
---|
666 | [#v #EQ destruct normalize %] #opt_b #l1 #r1 #v #EQ destruct normalize cases opt_b |
---|
667 | normalize [2: #x %] cases(merge A B A ? l1 l) normalize [2: #opt_a2 #l2 #r2 %] |
---|
668 | cases(merge A B A ? r1 r) // |
---|
669 | |*: #x #IH * [2,4: #opt_b #l1 #r1] #p1 normalize [3,4: #i #EQ destruct] cases p1 -p1 |
---|
670 | [2,4: #opt_a #l2 #r2] normalize #v #H cases opt_b [2,4,6,8: #b] normalize |
---|
671 | [1,2,5,6: <IH try assumption [1,2: cases opt_a [2,4: #a] normalize try %] |
---|
672 | cases(merge A B A ? l2 l1) normalize // lapply H [1,4: cases r1 |*: cases l1] |
---|
673 | normalize [1,3,5,7,9,11: #EQ destruct] #opt_b4 #l4 #r4 cases x normalize |
---|
674 | [1,4,7,10,13,16: #EQ destruct normalize // cases(merge A B A ? ? ?) normalize //] |
---|
675 | #x #H normalize cases(merge A B A ? ? ?) normalize // |
---|
676 | |*: <IH try assumption |
---|
677 | [1,3: cases(map_opt ? ? ? l1) normalize // lapply H cases r1 normalize |
---|
678 | [1,3: #EQ destruct] #opt_b2 #l2 #r2 cases x [1,4: //] #x normalize // |
---|
679 | |*: lapply H cases x normalize [2,3,5,6: #y] cases l1 normalize |
---|
680 | [1,3,5,7,9,11: #EQ destruct] #opt_b2 #l2 #r2 #H // |
---|
681 | ] |
---|
682 | ] |
---|
683 | ] |
---|
684 | qed. |
---|
685 | |
---|
686 | lemma update_restrict : ∀tag,A,B.∀a : identifier_map tag A.∀b : identifier_map tag B. |
---|
687 | ∀i,v.i ∈ b → update ?? (a ∩ b) i v = |
---|
688 | ! a' ← update ?? a i v ; return a' ∩ b. |
---|
689 | #tag #A #B #a #b #id #v #H |
---|
690 | lapply (in_map_domain … b id) >H * #ignore #EQ_lookup_b |
---|
691 | (*<clean_update*) |
---|
692 | inversion (update tag A a id v) |
---|
693 | [2: #e #EQ cases (update_fail_lookup ?????? EQ) #EQ1 #EQ2 destruct |
---|
694 | >lookup_miss_update [%] |
---|
695 | >lookup_restrict >H assumption ] |
---|
696 | #m' #EQ >m_return_bind |
---|
697 | cases (lookup_hit_update ?? (a∩b) id v ?) |
---|
698 | [2: >mem_set_restrict >H >(update_ok_old_lookup ?????? EQ) % ] |
---|
699 | #m'' >update_def >update_def in EQ; >lookup_restrict >H normalize nodelta |
---|
700 | cases(lookup tag A a id) normalize nodelta [#ABS destruct] #v1 #EQ #EQ'' destruct |
---|
701 | whd in ⊢ (??%%); @eq_f @add_restrict assumption |
---|
702 | qed. |
---|
703 | *) |
---|
704 | lemma add_set_minus : ∀tag,A,B.∀a : identifier_map tag A.∀b : identifier_map tag B. |
---|
705 | ∀i,v.¬(i ∈ b) → add tag A (a ∖ b) i v = (add tag A a i v) ∖ b. |
---|
706 | #tag #A #B * #a * #b * #i #v @notb_elim @if_elim normalize [#_ *] |
---|
707 | @if_elim [2: #_ *] @if_elim [#_ *] inversion(lookup_opt B i b) normalize [2: #x #_ *] |
---|
708 | #H * * * * @eq_f lapply H -H lapply v -v lapply b -b lapply a -a elim i |
---|
709 | [ * |
---|
710 | [ * [2: #opt_b #l #r] #v normalize in ⊢ (% → ?); #EQ destruct [2: %] |
---|
711 | normalize in ⊢ (??%%); cases (map_opt ??? l) // normalize cases(map_opt ??? r) |
---|
712 | normalize // |
---|
713 | | * [2: #a] #l #r * [2,4: #opt_b #l1 #r1] #v normalize in ⊢ (% → ?); #EQ destruct |
---|
714 | normalize [3: % |1,2: cases(merge ???? l l1) // cases(merge ???? r r1) //] |
---|
715 | cases(map_opt ??? l) normalize // cases(map_opt ??? r) // |
---|
716 | ] |
---|
717 | |2,3: #x #IH * [2,4: #opt_a #l #r] * [2,4,6,8: #opt_b #l1 #r1] #v |
---|
718 | normalize in ⊢ (% → ?); #H whd in match (pm_set ????) in ⊢ (???%); |
---|
719 | whd in match (merge ??????) in ⊢ (???%); |
---|
720 | [1,2,3,4: <IH try assumption whd in match (pm_set ????) in ⊢ (??%?); |
---|
721 | whd in match (merge ??????) in ⊢ (??%?); cases opt_b normalize |
---|
722 | [2,4,6,8: #b] [5,6: cases opt_a normalize //] |
---|
723 | [1,2,3,4: cases (merge ???? l l1) normalize [2,4,6,8: #opt_a2 #l2 #r2] |
---|
724 | // cases (merge ???? r r1) normalize |
---|
725 | [2,4,6,8,10,12: #opt_a3 #l3 #r3] inversion(pm_set ????) |
---|
726 | normalize // cases x |
---|
727 | [2,3,5,6,8,9,11,12,14,15,17,18,20,21,23,24 : #y] |
---|
728 | normalize #EQ destruct |
---|
729 | |*: cases(map_opt ??? l1) normalize [2,4,6,8: #opt_a2 #l2 #r2] // |
---|
730 | cases(map_opt ??? r1) normalize [2,4,6,8,10,12: #opt_a3 #l3 #r3] |
---|
731 | inversion(pm_set ????) normalize // cases x |
---|
732 | [2,3,5,6,8,9,11,12,14,15,17,18,20,21,23,24 : #y] |
---|
733 | normalize #EQ destruct |
---|
734 | ] |
---|
735 | |*: whd in match (pm_set ????) in ⊢ (??%?); |
---|
736 | whd in match (merge ??????) in ⊢ (??%?); [1,2: cases opt_a [2,4: #a]] |
---|
737 | normalize |
---|
738 | [1,2: @eq_f2 [1,4:%] | cases(map_opt ??? l) [2: #opt_a1 #l1 #r1] normalize |
---|
739 | | cases(map_opt ??? r) [2: #opt_a1 #l1 #r1] normalize] |
---|
740 | [1,3,4: lapply(map_add tag A A (λx.x) (an_id_map … r) (an_identifier ? x) v) |
---|
741 | |2,5,6: lapply(map_add tag A A (λx.x) (an_id_map … l) (an_identifier ? x) v) |
---|
742 | |*: lapply(map_add tag A A (λx.x) (an_id_map … (pm_leaf ?)) (an_identifier ? x) v) |
---|
743 | ] normalize #EQ destruct >e0 try % [4,5: cases x [2,3,5,6: #y] normalize %] |
---|
744 | cases(map_opt ????) [2,4,6: #opt_a1 #l1 #r1] normalize |
---|
745 | inversion(pm_set ????) normalize // cases x [2,3,5,6,8,9,11,12: #y] |
---|
746 | normalize #EQ1 destruct |
---|
747 | ] |
---|
748 | ] |
---|
749 | qed. |
---|
750 | |
---|
751 | lemma update_set_minus : ∀tag,A,B.∀a : identifier_map tag A.∀b : identifier_map tag B. |
---|
752 | ∀i,v.¬(i ∈ b) → update ?? (a ∖ b) i v = |
---|
753 | ! a' ← update ?? a i v ; return a' ∖ b. |
---|
754 | #tag #A #B #a #b #id #v #H >update_def >lookup_set_minus @if_elim |
---|
755 | [ #H1 @⊥ lapply H1 lapply H @notb_elim >H1 normalize *] #_ >update_def |
---|
756 | cases (lookup tag A a id) normalize [ %] #a @eq_f @add_set_minus assumption |
---|
757 | qed. |
---|
758 | |
---|
759 | |
---|
760 | record good_state_transformation |
---|
761 | (prog : ertl_program) |
---|
762 | (def_in : joint_closed_internal_function ERTL (prog_var_names ?? prog)) : |
---|
763 | Type[0] ≝ |
---|
764 | { f_lbls : label → option (list label) |
---|
765 | ; f_regs : label → option (list register) |
---|
766 | ; part_partition_f_lbls : partial_partition … f_lbls |
---|
767 | ; part_partion_f_regs : partial_partition … f_regs |
---|
768 | ; freshness_lab : let def_out ≝ translate_internal … def_in in |
---|
769 | (∀l.opt_All … (All … |
---|
770 | (λlbl.¬fresh_for_univ … lbl (joint_if_luniverse … def_in) ∧ |
---|
771 | fresh_for_univ … lbl (joint_if_luniverse … def_out))) (f_lbls l)) |
---|
772 | ; freshness_regs : let def_out ≝ translate_internal … def_in in |
---|
773 | (∀l.opt_All … (All … |
---|
774 | (λreg.¬fresh_for_univ … reg (joint_if_runiverse … def_in) ∧ |
---|
775 | fresh_for_univ … reg (joint_if_runiverse … def_out))) (f_regs l)) |
---|
776 | ; multi_fetch_ok : let def_out ≝ translate_internal … def_in in |
---|
777 | let f_step ≝ translate_step ? in |
---|
778 | let f_fin ≝ translate_fin_step ? in |
---|
779 | ∀l,s.stmt_at … (joint_if_code … def_in) l = Some ? s → |
---|
780 | ∃lbls,regs.f_lbls l = Some ? lbls ∧ f_regs l = Some ? regs ∧ |
---|
781 | match s with |
---|
782 | [ sequential s' nxt ⇒ |
---|
783 | l ~❨f_step l s', lbls, regs❩~> nxt in joint_if_code … def_out |
---|
784 | | final s' ⇒ |
---|
785 | l ~❨f_fin l s', lbls, regs❩~> it in joint_if_code … def_out |
---|
786 | | FCOND abs _ _ _ ⇒ Ⓧabs |
---|
787 | ] |
---|
788 | }. |
---|
789 | |
---|
790 | definition get_internal_function_from_ident : |
---|
791 | ∀ p: sem_params. ∀ globals : list ident . ∀ge : genv_t (joint_function p globals). |
---|
792 | ident → option (joint_closed_internal_function p globals) ≝ |
---|
793 | λp,globals,ge,id. |
---|
794 | ! bl ← (find_symbol (joint_function p globals) ge id); |
---|
795 | ! bl' ← (code_block_of_block bl); |
---|
796 | ! 〈f,fn〉 ← res_to_opt … (fetch_internal_function ? ge bl'); |
---|
797 | return fn. |
---|
798 | |
---|
799 | definition get_sigma_from_good_state : |
---|
800 | ∀prog : ertl_program. |
---|
801 | (∀ fn : joint_closed_internal_function ERTL (prog_var_names ?? prog). |
---|
802 | good_state_transformation prog fn) → sigma_map prog ≝ |
---|
803 | λprog,good,fn,searched. |
---|
804 | !〈res,s〉 ← find ?? (joint_if_code … fn) |
---|
805 | (λlbl.λ_. match (f_lbls … (good fn)) lbl with |
---|
806 | [None ⇒ false |
---|
807 | |Some lbls ⇒ |
---|
808 | match lbls with |
---|
809 | [nil ⇒ eq_identifier … searched lbl |
---|
810 | |cons hd tl ⇒ let last ≝ last_ne … «hd::tl,I» in |
---|
811 | eq_identifier … searched last |
---|
812 | ] |
---|
813 | ]); |
---|
814 | return res. |
---|
815 | |
---|
816 | |
---|
817 | definition sigma_frames : ∀prog : ertl_program. |
---|
818 | (∀fn.good_state_transformation prog fn) → |
---|
819 | list (register_env beval × ident) → (list (register_env beval × ident)) ≝ |
---|
820 | λprog,good,frms. |
---|
821 | let sigma ≝ get_sigma_from_good_state … good in |
---|
822 | foldr ?? |
---|
823 | (λx,tl.let 〈reg_env,id〉 ≝ x in |
---|
824 | match get_internal_function_from_ident |
---|
825 | ERTL_semantics (prog_var_names … prog) |
---|
826 | (globalenv_noinit … prog) id with |
---|
827 | [Some fn ⇒ |
---|
828 | 〈(sigma_register_env prog sigma reg_env |
---|
829 | (added_registers … fn (f_regs … (good fn)))),id〉 :: tl |
---|
830 | |None ⇒ [ ] |
---|
831 | ]) ([ ]) frms. |
---|
832 | |
---|
833 | |
---|
834 | (* |
---|
835 | lemma sigma_empty_frames_commute : |
---|
836 | ∀prog : ertl_program. ∀ sigma : (sigma_map prog). |
---|
837 | ∃prf. |
---|
838 | sigma_frames prog sigma [] prf = []. |
---|
839 | #p #s % normalize % |
---|
840 | qed. |
---|
841 | |
---|
842 | |
---|
843 | let rec sigma_bit_vector_trie_opt (prog : ertl_program) |
---|
844 | (sigma : (sigma_map prog)) (n : nat) (t : BitVectorTrie beval n) |
---|
845 | on t : option … (BitVectorTrie beval n) ≝ |
---|
846 | match t with |
---|
847 | [Leaf bv ⇒ ! bv' ← (sigma_beval_opt prog sigma bv); |
---|
848 | return Leaf … bv' |
---|
849 | |Node n1 b1 b2 ⇒ ! b1' ← (sigma_bit_vector_trie_opt prog sigma n1 b1); |
---|
850 | ! b2' ← (sigma_bit_vector_trie_opt prog sigma n1 b2); |
---|
851 | return Node … n1 b1' b2' |
---|
852 | |Stub n1 ⇒ return Stub … n1 |
---|
853 | ]. |
---|
854 | |
---|
855 | |
---|
856 | definition well_formed_hw_register_env : |
---|
857 | ∀ prog : ertl_program. ∀ sigma : (sigma_map prog). |
---|
858 | hw_register_env → Prop ≝ |
---|
859 | λprog,sigma,regs.sigma_bit_vector_trie_opt prog sigma 6 (reg_env … regs) ≠ None ?. |
---|
860 | *) |
---|
861 | |
---|
862 | |
---|
863 | include "common/BitVectorTrieMap.ma". |
---|
864 | |
---|
865 | definition sigma_hw_register_env : |
---|
866 | ∀prog: ertl_program. ∀sigma : (sigma_map prog). |
---|
867 | hw_register_env → hw_register_env ≝ |
---|
868 | λprog,sigma,h_reg.mk_hw_register_env |
---|
869 | (map ? ? (sigma_beval prog sigma) 6 (reg_env … h_reg)) (other_bit … h_reg). |
---|
870 | |
---|
871 | |
---|
872 | definition sigma_regs : |
---|
873 | ∀prog : ertl_program. ∀sigma : (sigma_map prog). |
---|
874 | (register_env beval)×hw_register_env→ list register → |
---|
875 | (register_env beval)×hw_register_env ≝ |
---|
876 | λprog,sigma,regs,ids.let 〈x,y〉≝ regs in |
---|
877 | 〈sigma_register_env prog sigma x ids, |
---|
878 | sigma_hw_register_env prog sigma y〉. |
---|
879 | (* |
---|
880 | lemma sigma_empty_regsT_commute : |
---|
881 | ∀prog : ertl_program. ∀sigma : (sigma_map prog). |
---|
882 | ∀ptr.∃ prf. |
---|
883 | empty_regsT ERTLptr_semantics ptr = |
---|
884 | sigma_regs prog sigma (empty_regsT ERTL_semantics ptr) prf. |
---|
885 | #prog #sigma #ptr % |
---|
886 | [ @hide_prf whd in match well_formed_regs; normalize nodelta % |
---|
887 | [whd in match well_formed_ertl_psd_env; normalize nodelta #id #bv |
---|
888 | normalize in ⊢ (%→?); #EQ destruct |
---|
889 | | normalize % #EQ destruct |
---|
890 | ] |
---|
891 | | % ] |
---|
892 | qed. |
---|
893 | |
---|
894 | axiom sigma_load_sp_commute : |
---|
895 | ∀prog : ertl_program.∀sigma : (sigma_map prog). |
---|
896 | ∀regs,ptr. |
---|
897 | load_sp ERTL_semantics regs = return ptr |
---|
898 | → ∃prf. |
---|
899 | load_sp ERTLptr_semantics (sigma_regs prog sigma regs prf) = return ptr. |
---|
900 | |
---|
901 | axiom sigma_save_sp_commute : |
---|
902 | ∀prog : ertl_program. ∀sigma : (sigma_map prog). |
---|
903 | ∀reg,ptr,prf1. ∃prf2. |
---|
904 | save_sp ERTLptr_semantics (sigma_regs prog sigma reg prf1) ptr = |
---|
905 | sigma_regs prog sigma (save_sp ERTL_semantics reg ptr) prf2. |
---|
906 | |
---|
907 | definition well_formed_state : |
---|
908 | ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
909 | state ERTL_semantics → Prop ≝ |
---|
910 | λprog,sigma,st. |
---|
911 | well_formed_frames prog sigma (st_frms … st) ∧ |
---|
912 | sigma_is_opt prog sigma (istack … st) ≠ None ? ∧ |
---|
913 | well_formed_regs prog sigma (regs … st) ∧ |
---|
914 | well_formed_mem prog sigma (m … st). |
---|
915 | *) |
---|
916 | |
---|
917 | definition sigma_state : ∀prog : ertl_program. |
---|
918 | (∀fn.good_state_transformation prog fn) → |
---|
919 | state ERTLptr_semantics → list register → |
---|
920 | state ERTL_semantics ≝ |
---|
921 | λprog,good,st,ids. |
---|
922 | let sigma ≝ get_sigma_from_good_state … good in |
---|
923 | mk_state ? |
---|
924 | (sigma_frames prog good (st_frms ERTLptr_semantics st)) |
---|
925 | (sigma_is ? sigma (istack … st)) |
---|
926 | (carry … st) |
---|
927 | (sigma_regs ? sigma (regs … st) ids) |
---|
928 | (sigma_mem ? sigma (m … st)). |
---|
929 | |
---|
930 | |
---|
931 | definition dummy_state : state ERTL_semantics ≝ |
---|
932 | mk_state ERTL_semantics |
---|
933 | [ ] empty_is BBundef 〈empty_map ? ?,mk_hw_register_env … (Stub …) BBundef〉 empty. |
---|
934 | |
---|
935 | definition dummy_state_pc : state_pc ERTL_semantics ≝ |
---|
936 | mk_state_pc ? dummy_state (null_pc one) (null_pc one). |
---|
937 | |
---|
938 | definition sigma_state_pc : |
---|
939 | ∀prog : ertl_program. |
---|
940 | (∀fn.good_state_transformation prog fn) → |
---|
941 | state_pc ERTLptr_semantics → |
---|
942 | state_pc ERTL_semantics ≝ |
---|
943 | λprog,good,st. |
---|
944 | let sigma ≝ get_sigma_from_good_state … good in |
---|
945 | let ge ≝ globalenv_noinit … prog in |
---|
946 | if eqZb (block_id (pc_block (pc … st))) (-1) then (* check for dummy pc *) |
---|
947 | dummy_state_pc |
---|
948 | else |
---|
949 | match (fetch_internal_function (joint_closed_internal_function ERTL |
---|
950 | (prog_var_names (joint_function ERTL) ℕ prog)) ge (pc_block (pc … st))) with |
---|
951 | [OK x ⇒ let 〈i,fd〉 ≝ x in |
---|
952 | mk_state_pc ? |
---|
953 | (sigma_state prog good st (added_registers … fd (f_regs … (good fd)))) |
---|
954 | (pc … st) (sigma_stored_pc prog sigma (last_pop … st)) |
---|
955 | |Error msg ⇒ dummy_state_pc]. |
---|
956 | |
---|
957 | |
---|
958 | definition ERTLptrStatusSimulation : |
---|
959 | ∀ prog : ertl_program. |
---|
960 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
961 | ∀stack_sizes.(∀fn.good_state_transformation prog fn) → |
---|
962 | status_rel (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) ≝ |
---|
963 | λprog,stack_sizes,good. |
---|
964 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
965 | mk_status_rel ?? |
---|
966 | (* sem_rel ≝ *) (λs1:ERTL_status prog stack_sizes |
---|
967 | .λs2:ERTLptr_status trans_prog stack_sizes |
---|
968 | .s1=sigma_state_pc prog good s2) |
---|
969 | (* call_rel ≝ *) |
---|
970 | (λs1:Σs:ERTL_status prog stack_sizes |
---|
971 | .as_classifier (ERTL_status prog stack_sizes) s cl_call |
---|
972 | .λs2:Σs:ERTLptr_status trans_prog stack_sizes |
---|
973 | .as_classifier (ERTLptr_status trans_prog stack_sizes) s cl_call |
---|
974 | .let sigma ≝ get_sigma_from_good_state … good in |
---|
975 | pc (mk_prog_params ERTL_semantics prog stack_sizes) s1 |
---|
976 | =sigma_stored_pc prog sigma |
---|
977 | (pc |
---|
978 | (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_sizes) |
---|
979 | s2)) |
---|
980 | (* sim_final ≝ *) ?. |
---|
981 | cases daemon |
---|
982 | qed. |
---|
983 | |
---|
984 | lemma fetch_function_no_minus_one : |
---|
985 | ∀F,V,i,p,bl. |
---|
986 | block_id (pi1 … bl) = -1 → |
---|
987 | fetch_function … (globalenv (λvars.fundef (F vars)) V i p) |
---|
988 | bl = Error … [MSG BadFunction]. |
---|
989 | #F#V#i#p ** #r #id #EQ1 destruct |
---|
990 | whd in match fetch_function; normalize nodelta |
---|
991 | >globalenv_no_minus_one |
---|
992 | cases (symbol_for_block ???) normalize // |
---|
993 | qed. |
---|
994 | |
---|
995 | lemma fetch_function_no_zero : |
---|
996 | ∀F,V,i,p,bl. |
---|
997 | block_id (pi1 … bl) = 0 → |
---|
998 | fetch_function … (globalenv (λvars.fundef (F vars)) V i p) |
---|
999 | bl = Error … [MSG BadFunction]. |
---|
1000 | #F#V#i#p ** #r #id #EQ1 destruct |
---|
1001 | whd in match fetch_function; normalize nodelta |
---|
1002 | >globalenv_no_zero |
---|
1003 | cases (symbol_for_block ???) normalize // |
---|
1004 | qed. |
---|
1005 | |
---|
1006 | (*DOPPIONI dei LEMMI in LINEARISE_PROOF*) |
---|
1007 | lemma symbol_for_block_match: |
---|
1008 | ∀M:matching.∀initV,initW. |
---|
1009 | (∀v,w. match_var_entry M v w → |
---|
1010 | size_init_data_list (initV (\snd v)) = size_init_data_list (initW (\snd w))) → |
---|
1011 | ∀p: program (m_A M) (m_V M). ∀p': program (m_B M) (m_W M). |
---|
1012 | ∀MATCH:match_program … M p p'. |
---|
1013 | ∀b: block. |
---|
1014 | symbol_for_block … (globalenv … initW p') b = |
---|
1015 | symbol_for_block … (globalenv … initV p) b. |
---|
1016 | * #A #B #V #W #match_fn #match_var #initV #initW #H |
---|
1017 | #p #p' * #Mvars #Mfn #Mmain |
---|
1018 | #b |
---|
1019 | whd in match symbol_for_block; normalize nodelta |
---|
1020 | whd in match globalenv in ⊢ (???%); normalize nodelta |
---|
1021 | whd in match (globalenv_allocmem ????); |
---|
1022 | change with (add_globals ?????) in match (foldl ?????); |
---|
1023 | >(proj1 … (add_globals_match … initW … Mvars)) |
---|
1024 | [ % |*:] |
---|
1025 | [ * #idr #v * #idr' #w #MVE % |
---|
1026 | [ inversion MVE |
---|
1027 | #H1 #H2 #H3 #H4 #H5 #H6 #H7 #H8 destruct % |
---|
1028 | | @(H … MVE) |
---|
1029 | ] |
---|
1030 | | @(matching_fns_get_same_blocks … Mfn) |
---|
1031 | #f #g @match_funct_entry_id |
---|
1032 | ] |
---|
1033 | qed. |
---|
1034 | |
---|
1035 | lemma symbol_for_block_transf : |
---|
1036 | ∀A,B,V,init.∀prog_in : program A V. |
---|
1037 | ∀trans : ∀vars.A vars → B vars. |
---|
1038 | let prog_out ≝ transform_program … prog_in trans in |
---|
1039 | ∀bl. |
---|
1040 | symbol_for_block … (globalenv … init prog_out) bl = |
---|
1041 | symbol_for_block … (globalenv … init prog_in) bl. |
---|
1042 | #A #B #V #iV #p #tf @(symbol_for_block_match … (transform_program_match … tf ?)) |
---|
1043 | #v0 #w0 * // |
---|
1044 | qed. |
---|
1045 | |
---|
1046 | lemma fetch_function_transf : |
---|
1047 | ∀A,B,V,init.∀prog_in : program A V. |
---|
1048 | ∀trans : ∀vars.A vars → B vars. |
---|
1049 | let prog_out ≝ transform_program … prog_in trans in |
---|
1050 | ∀bl,i,f. |
---|
1051 | fetch_function … (globalenv … init prog_in) bl = |
---|
1052 | return 〈i, f〉 |
---|
1053 | → fetch_function … (globalenv … init prog_out) bl = |
---|
1054 | return 〈i, trans … f〉. |
---|
1055 | #A #B #V #init #prog_in #trans #bl #i #f |
---|
1056 | whd in match fetch_function; normalize nodelta |
---|
1057 | #H lapply (opt_eq_from_res ???? H) -H |
---|
1058 | #H @('bind_inversion H) -H #id #eq_symbol_for_block |
---|
1059 | #H @('bind_inversion H) -H #fd #eq_find_funct |
---|
1060 | whd in ⊢ (??%?→?); #EQ destruct(EQ) |
---|
1061 | >(symbol_for_block_transf … trans) >eq_symbol_for_block >m_return_bind |
---|
1062 | >(find_funct_ptr_transf A B … eq_find_funct) % |
---|
1063 | qed. |
---|
1064 | |
---|
1065 | |
---|
1066 | lemma fetch_internal_function_transf : |
---|
1067 | ∀A,B.∀prog_in : program (λvars.fundef (A vars)) ℕ. |
---|
1068 | ∀trans : ∀vars.A vars → B vars. |
---|
1069 | let prog_out ≝ transform_program … prog_in (λvars.transf_fundef … (trans vars)) in |
---|
1070 | ∀bl,i,f. |
---|
1071 | fetch_internal_function … (globalenv_noinit … prog_in) bl = |
---|
1072 | return 〈i, f〉 |
---|
1073 | → fetch_internal_function … (globalenv_noinit … prog_out) bl = |
---|
1074 | return 〈i, trans … f〉. |
---|
1075 | #A #B #prog #trans #bl #i #f |
---|
1076 | whd in match fetch_internal_function; normalize nodelta |
---|
1077 | #H @('bind_inversion H) * #id * #fd normalize nodelta #EQfetch |
---|
1078 | whd in ⊢ (??%%→?); #EQ destruct(EQ) |
---|
1079 | >(fetch_function_transf … EQfetch) % |
---|
1080 | qed. |
---|
1081 | |
---|
1082 | (* |
---|
1083 | definition good_local_sigma : |
---|
1084 | ∀globals. |
---|
1085 | ∀g:codeT ERTLptr globals. |
---|
1086 | (Σl.bool_to_Prop (code_has_label … g l)) → |
---|
1087 | codeT ERTL globals → |
---|
1088 | (label → option label) → Prop ≝ |
---|
1089 | λglobals,g,c,sigma. |
---|
1090 | ∀l,l'.sigma l = Some ? l' → |
---|
1091 | ∃s. stmt_at … g l = Some ? s ∧ |
---|
1092 | All ? (λl.sigma l ≠ None ?) (stmt_labels … s) ∧ |
---|
1093 | (match s with |
---|
1094 | [ sequential s' nxt ⇒ |
---|
1095 | match s' with |
---|
1096 | [ step_seq _ ⇒ |
---|
1097 | (stmt_at … c n = Some ? (sequential … s' it)) ∧ |
---|
1098 | ((sigma nxt = Some ? (S n)) ∨ |
---|
1099 | (stmt_at … c (S n) = Some ? (GOTO … nxt))) |
---|
1100 | | COND a ltrue ⇒ |
---|
1101 | (stmt_at … c n = Some ? (sequential … s' it) ∧ sigma nxt = Some ? (S n)) ∨ |
---|
1102 | (stmt_at … c n = Some ? (FCOND … I a ltrue nxt)) |
---|
1103 | ] |
---|
1104 | | final s' ⇒ |
---|
1105 | stmt_at … c n = Some ? (final … s') |
---|
1106 | | FCOND abs _ _ _ ⇒ Ⓧabs |
---|
1107 | ]). |
---|
1108 | |
---|
1109 | *) |
---|
1110 | |
---|
1111 | lemma ps_reg_retrieve_ok : ∀prog : ertl_program. |
---|
1112 | ∀sigma : sigma_map prog. ∀r,restr. |
---|
1113 | preserving1 ?? res_preserve1 … |
---|
1114 | (λregs.sigma_regs prog sigma regs restr) |
---|
1115 | (sigma_beval prog sigma) |
---|
1116 | (λregs.ps_reg_retrieve regs r) |
---|
1117 | (λregs.ps_reg_retrieve regs r). |
---|
1118 | #prog #sigma #r #restr * #psd_r #hw_r whd in match ps_reg_retrieve; |
---|
1119 | whd in match reg_retrieve; normalize nodelta @opt_to_res_preserve1 |
---|
1120 | whd in match sigma_regs; whd in match sigma_register_env; normalize nodelta |
---|
1121 | >lookup_set_minus @if_elim [ #_ @opt_preserve_none1] #id_r_not_in |
---|
1122 | >(lookup_map ?? RegisterTag ???) #bv #H @('bind_inversion H) -H #bv1 |
---|
1123 | #bv1_spec whd in ⊢ (??%? → ?); #EQ destruct %{bv1} % // >bv1_spec % |
---|
1124 | qed. |
---|
1125 | |
---|
1126 | lemma hw_reg_retrieve_ok : ∀prog : ertl_program. |
---|
1127 | ∀sigma : sigma_map prog. ∀r,restr. |
---|
1128 | preserving1 ?? res_preserve1 … |
---|
1129 | (λregs.sigma_regs prog sigma regs restr) |
---|
1130 | (sigma_beval prog sigma) |
---|
1131 | (λregs.hw_reg_retrieve regs r) |
---|
1132 | (λregs.hw_reg_retrieve regs r). |
---|
1133 | #prog #sigma #r #restr * #psd_r * #hw_r #b whd in match hw_reg_retrieve; |
---|
1134 | whd in match hwreg_retrieve; normalize nodelta whd in match sigma_regs; |
---|
1135 | whd in match sigma_hw_register_env; normalize nodelta |
---|
1136 | change with (sigma_beval prog sigma BVundef) in ⊢ (???????(??(?????%))?); |
---|
1137 | #bv >lookup_map whd in ⊢ (???% → ?); #EQ destruct |
---|
1138 | %{(lookup beval 6 (bitvector_of_register r) hw_r BVundef)} |
---|
1139 | % // |
---|
1140 | qed. |
---|
1141 | |
---|
1142 | |
---|
1143 | lemma ps_reg_store_ok : ∀prog : ertl_program. |
---|
1144 | ∀sigma : sigma_map prog. ∀r,restr. |
---|
1145 | preserving21 ?? res_preserve1 … |
---|
1146 | (sigma_beval prog sigma) |
---|
1147 | (λregs.sigma_regs prog sigma regs restr) |
---|
1148 | (λregs.sigma_regs prog sigma regs restr) |
---|
1149 | (ps_reg_store r) |
---|
1150 | (ps_reg_store r). |
---|
1151 | #prog #sigma #r #restr whd in match ps_reg_store; normalize nodelta |
---|
1152 | #bv * #psd_r #hw_r @mfr_bind1 |
---|
1153 | [ @(λr.sigma_register_env prog sigma r restr) |
---|
1154 | | whd in match reg_store; whd in match sigma_regs; normalize nodelta |
---|
1155 | #x #x_spec lapply(update_ok_to_lookup ?????? x_spec) * * #_ #EQpsd #_ |
---|
1156 | lapply x_spec -x_spec lapply EQpsd -EQpsd whd in match sigma_register_env; |
---|
1157 | normalize nodelta >lookup_set_minus @if_elim [ #_ * #H @⊥ @H %] |
---|
1158 | #id_not_in #_ >update_set_minus [2: assumption] #H @('bind_inversion H) -H |
---|
1159 | #x0 >map_update_commute #H @('bind_inversion H) -H #x1 #x1_spec |
---|
1160 | whd in ⊢ (??%% → ??%% → ?); #EQ1 #EQ2 destruct %{x1} % // |
---|
1161 | | #x * #psd_r' #hw_r' whd in match sigma_regs; normalize nodelta |
---|
1162 | whd in ⊢ (???% → ?); #EQ destruct %{〈x,hw_r〉} % // |
---|
1163 | ] |
---|
1164 | qed. |
---|
1165 | |
---|
1166 | |
---|
1167 | lemma hw_reg_store_ok : ∀prog : ertl_program. |
---|
1168 | ∀sigma : sigma_map prog. ∀r,restr. |
---|
1169 | preserving21 ?? res_preserve1 … |
---|
1170 | (sigma_beval prog sigma) |
---|
1171 | (λregs.sigma_regs prog sigma regs restr) |
---|
1172 | (λregs.sigma_regs prog sigma regs restr) |
---|
1173 | (hw_reg_store r) |
---|
1174 | (hw_reg_store r). |
---|
1175 | #prog #sigma #r #restr whd in match hw_reg_store; normalize nodelta |
---|
1176 | #bv * #psd_r * #hw_r #b whd in match hwreg_store; whd in match sigma_regs; normalize nodelta |
---|
1177 | whd in match sigma_hw_register_env; normalize nodelta <insert_map * #psd_r' |
---|
1178 | * #hw_r' #b' whd in ⊢ (???% → ?); #EQ destruct % [2: % [%] % |] |
---|
1179 | qed. |
---|
1180 | |
---|
1181 | |
---|
1182 | lemma ertl_eval_move_ok : ∀prog : ertl_program. |
---|
1183 | ∀sigma : sigma_map prog. ∀ restr,pm. |
---|
1184 | preserving1 ?? res_preserve1 … |
---|
1185 | (λregs.sigma_regs prog sigma regs restr) |
---|
1186 | (λregs.sigma_regs prog sigma regs restr) |
---|
1187 | (λregs.ertl_eval_move regs pm) |
---|
1188 | (λregs.ertl_eval_move regs pm). |
---|
1189 | #prog #sigma #restr * #mv_dst #arg_dst #pm whd in match ertl_eval_move; |
---|
1190 | normalize nodelta @mfr_bind1 [@(sigma_beval prog sigma) |
---|
1191 | | cases arg_dst normalize nodelta |
---|
1192 | [2: #b change with (return sigma_beval prog sigma (BVByte b)) in ⊢ (???????%?); |
---|
1193 | @mfr_return1] |
---|
1194 | * #r normalize nodelta [@ps_reg_retrieve_ok| @hw_reg_retrieve_ok] |
---|
1195 | | #bv cases mv_dst #r normalize nodelta [@ps_reg_store_ok | @hw_reg_store_ok] |
---|
1196 | ] |
---|
1197 | qed. |
---|
1198 | |
---|
1199 | lemma ps_arg_retrieve_ok : ∀prog : ertl_program. |
---|
1200 | ∀sigma : sigma_map prog. ∀a,restr. |
---|
1201 | preserving1 ?? res_preserve1 … |
---|
1202 | (λregs.sigma_regs prog sigma regs restr) |
---|
1203 | (sigma_beval prog sigma) |
---|
1204 | (λregs.ps_arg_retrieve regs a) |
---|
1205 | (λregs.ps_arg_retrieve regs a). |
---|
1206 | #prog #sigma #a #restr whd in match ps_arg_retrieve; normalize nodelta cases a -a |
---|
1207 | normalize nodelta [#r | #b ] #regs |
---|
1208 | [ @ps_reg_retrieve_ok |
---|
1209 | | change with (return sigma_beval prog sigma (BVByte b)) in ⊢ (???????%?); |
---|
1210 | @mfr_return1 |
---|
1211 | ] |
---|
1212 | qed. |
---|
1213 | |
---|
1214 | lemma pop_ok : |
---|
1215 | ∀prog : ertl_program. |
---|
1216 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1217 | ∀restr. |
---|
1218 | preserving1 ?? res_preserve1 ???? |
---|
1219 | (λst.sigma_state prog good st restr) |
---|
1220 | (λx.let 〈bv,st〉 ≝ x in |
---|
1221 | 〈let sigma ≝ get_sigma_from_good_state … good in |
---|
1222 | sigma_beval prog sigma bv, |
---|
1223 | sigma_state prog good st restr〉) |
---|
1224 | (pop ERTL_semantics) |
---|
1225 | (pop ERTLptr_semantics). |
---|
1226 | #prog #good #restr whd in match pop; normalize nodelta #st @mfr_bind1 |
---|
1227 | [@(λx.let 〈bv,is〉 ≝ x in |
---|
1228 | let sigma ≝ get_sigma_from_good_state … good in |
---|
1229 | 〈sigma_beval prog sigma bv, |
---|
1230 | sigma_is prog sigma is 〉) |
---|
1231 | | whd in match is_pop; normalize nodelta whd in match sigma_state; normalize nodelta |
---|
1232 | cases(istack ? st) normalize nodelta |
---|
1233 | [@res_preserve_error1 |
---|
1234 | |2,3: #bv1 [2: #bv2] * #bv3 #is1 whd in ⊢ (??%% → ?); #EQ destruct |
---|
1235 | % [2,4: % [1,3: %|*: %] |*:] |
---|
1236 | ] |
---|
1237 | | * #bv #is * #bv1 #st whd in ⊢ (??%% → ?); #EQ destruct % [2: % [%] %|] |
---|
1238 | ] |
---|
1239 | qed. |
---|
1240 | |
---|
1241 | lemma push_ok : |
---|
1242 | ∀prog : ertl_program. |
---|
1243 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1244 | ∀restr. |
---|
1245 | preserving21 ?? res_preserve1 … |
---|
1246 | (λst.sigma_state prog good st restr) |
---|
1247 | (let sigma ≝ get_sigma_from_good_state … good in sigma_beval prog sigma) |
---|
1248 | (λst.sigma_state prog good st restr) |
---|
1249 | (push ERTL_semantics) |
---|
1250 | (push ERTLptr_semantics). |
---|
1251 | #prog #good #restr whd in match push; normalize nodelta #st #bv @mfr_bind1 |
---|
1252 | [ @(let sigma ≝ get_sigma_from_good_state … good in sigma_is ? sigma) |
---|
1253 | | whd in match is_push; normalize nodelta whd in match sigma_state; normalize nodelta |
---|
1254 | cases (istack ? st) [2,3: #bv [2: #bv']] whd in match sigma_is in ⊢ (???????%?); |
---|
1255 | normalize nodelta [@res_preserve_error1] @mfr_return_eq1 % |
---|
1256 | | #is @mfr_return_eq1 % |
---|
1257 | ] |
---|
1258 | qed. |
---|
1259 | |
---|
1260 | lemma be_opaccs_ok : |
---|
1261 | ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
1262 | ∀ op. |
---|
1263 | preserving21 ?? res_preserve1 ?????? |
---|
1264 | (sigma_beval prog sigma) |
---|
1265 | (sigma_beval prog sigma) |
---|
1266 | (λx.let 〈bv1,bv2〉 ≝ x in |
---|
1267 | 〈sigma_beval prog sigma bv1, |
---|
1268 | sigma_beval prog sigma bv2〉) |
---|
1269 | (be_opaccs op) |
---|
1270 | (be_opaccs op). |
---|
1271 | #prog #sigma #op #bv #bv1 |
---|
1272 | whd in match be_opaccs; normalize nodelta @mfr_bind1 |
---|
1273 | [ @(λx.x) |
---|
1274 | | cases bv |
---|
1275 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1276 | whd in match Byte_of_val; normalize nodelta |
---|
1277 | try @res_preserve_error1 [ #x whd in ⊢ (???% → ?); #EQ destruct %{x} % //] |
---|
1278 | whd in match sigma_beval; normalize nodelta cases (sigma_pc_opt ? ? ?) |
---|
1279 | normalize nodelta [2: #pc] @res_preserve_error1 |
---|
1280 | | #by @mfr_bind1 |
---|
1281 | [ @(λx.x) |
---|
1282 | | cases bv1 |
---|
1283 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1284 | whd in match Byte_of_val; normalize nodelta |
---|
1285 | try @res_preserve_error1 [ #x whd in ⊢ (???% → ?); #EQ destruct %{x} % //] |
---|
1286 | whd in match sigma_beval; normalize nodelta cases (sigma_pc_opt ? ? ?) |
---|
1287 | normalize nodelta [2: #pc] @res_preserve_error1 |
---|
1288 | | #by1 * #bv2 #bv3 cases(opaccs eval op by by1) #by' #by1' normalize nodelta |
---|
1289 | whd in ⊢ (??%% → ?); #EQ destruct % [2: % [%] % |] |
---|
1290 | qed. |
---|
1291 | |
---|
1292 | lemma be_op1_ok : ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
1293 | ∀ op. |
---|
1294 | preserving1 ?? res_preserve1 … |
---|
1295 | (sigma_beval prog sigma) |
---|
1296 | (sigma_beval prog sigma) |
---|
1297 | (be_op1 op) |
---|
1298 | (be_op1 op). |
---|
1299 | #prog #sigma #o #bv whd in match be_op1; normalize nodelta @mfr_bind1 |
---|
1300 | [ @(λx.x) |
---|
1301 | | cases bv |
---|
1302 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1303 | whd in match Byte_of_val; whd in match sigma_beval; normalize nodelta |
---|
1304 | try @res_preserve_error1 [ @mfr_return_eq1 %] |
---|
1305 | cases(sigma_pc_opt prog sigma pc1) [2: #pc2] normalize nodelta |
---|
1306 | @res_preserve_error1 |
---|
1307 | | #by @mfr_return_eq1 % |
---|
1308 | ] |
---|
1309 | qed. |
---|
1310 | |
---|
1311 | lemma res_preserve_error11 : ∀X,Y,F,e,n. (∃e'.n = Error … e') → |
---|
1312 | res_preserve1 X Y F n (Error … e). |
---|
1313 | #X #Y #F #e #n * #e' #n_spec >n_spec @res_preserve_error1 |
---|
1314 | qed. |
---|
1315 | |
---|
1316 | |
---|
1317 | lemma be_op2_ok : ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
1318 | ∀ b,op. |
---|
1319 | preserving21 ?? res_preserve1 … |
---|
1320 | (sigma_beval prog sigma) |
---|
1321 | (sigma_beval prog sigma) |
---|
1322 | (λx.let 〈bv,b〉≝ x in 〈sigma_beval prog sigma bv,b〉) |
---|
1323 | (be_op2 b op) |
---|
1324 | (be_op2 b op). |
---|
1325 | #prog #sigma #b #op #bv #bv1 whd in match be_op2; normalize nodelta |
---|
1326 | cases bv |
---|
1327 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1328 | normalize nodelta [@res_preserve_error1] whd in match sigma_beval; |
---|
1329 | normalize nodelta |
---|
1330 | cases bv1 |
---|
1331 | [1,2,8,9,15,16,22,23,29,30,36,37: |
---|
1332 | |3,10,17,24,31,38: #ptr1' #ptr2' #p' |
---|
1333 | |4,11,18,25,32,39: #by' |
---|
1334 | |5,12,19,26,33,40: #p' |
---|
1335 | |6,13,20,27,34,41: #ptr' #p' |
---|
1336 | |7,14,21,28,35,42: #pc1' #p1' |
---|
1337 | ] |
---|
1338 | normalize nodelta try @res_preserve_error1 |
---|
1339 | [4,5,8,13,16,20,21,22,23,24,25,26 : @res_preserve_error11 % |
---|
1340 | [2,4,6,8,10,12,14,16,18,20,22,24: cases(sigma_pc_opt ???) try % #pc2 % |
---|
1341 | |*:] |
---|
1342 | |*: cases op normalize nodelta |
---|
1343 | try @res_preserve_error1 try( @mfr_return_eq1 %) |
---|
1344 | [1,2,12,13,16,17,18: @if_elim #_ try @res_preserve_error1 |
---|
1345 | try( @mfr_return_eq1 %) |
---|
1346 | [ @if_elim #_ @mfr_return_eq1 % |
---|
1347 | | cases(ptype ptr) normalize nodelta |
---|
1348 | [2: @res_preserve_error1] @mfr_bind1 |
---|
1349 | [ @(λx.x) |
---|
1350 | | whd in match Bit_of_val; normalize nodelta |
---|
1351 | cases b [#bo|| #bo #ptr'' #p'' #bit_v] |
---|
1352 | normalize nodelta [2,3: @res_preserve_error1] |
---|
1353 | @mfr_return_eq1 % |
---|
1354 | | #bi cases(op2 ?????) #by #bi1 normalize nodelta |
---|
1355 | @mfr_return_eq1 % |
---|
1356 | ] |
---|
1357 | | cases(ptype ptr) normalize nodelta @res_preserve_error1 |
---|
1358 | ] |
---|
1359 | |3,4,5,6,7,8: @mfr_bind1 |
---|
1360 | [1,4,7,10,13,16: @(λx.x) |
---|
1361 | |2,5,8,11,14,17: whd in match Bit_of_val; normalize nodelta |
---|
1362 | cases b [1,4,7,10,13,16: #bo| |
---|
1363 | |2,5,8,11,14,17: |
---|
1364 | |3,6,9,12,15,18: #bo #ptr'' #p'' #bit_v |
---|
1365 | ] normalize nodelta try @res_preserve_error1 |
---|
1366 | @mfr_return_eq1 % |
---|
1367 | |3,6,9,12,15,18: #bi cases(op2 ?????) #by #bi1 normalize nodelta |
---|
1368 | @mfr_return_eq1 % |
---|
1369 | ] |
---|
1370 | |*: whd in match be_add_sub_byte; normalize nodelta |
---|
1371 | [1,2,3: cases(ptype ptr) normalize nodelta [2,4,6: @res_preserve_error1] |
---|
1372 | cases p * [2,4,6: #p_no] #prf normalize nodelta |
---|
1373 | [@res_preserve_error1 |
---|
1374 | |2,3: cases b [1,4: #bo|2,5: |3,6: #bo #ptr'' #p'' #bit_v] |
---|
1375 | normalize nodelta [1,2,3,4: @res_preserve_error1] |
---|
1376 | @if_elim #_ [2,4: @res_preserve_error1] |
---|
1377 | @If_elim #INUTILE [2,4: @res_preserve_error1] |
---|
1378 | @pair_elim #a1 #a2 #_ normalize nodelta |
---|
1379 | @mfr_return_eq1 % |
---|
1380 | |*: @mfr_bind1 |
---|
1381 | [1,4,7: @(λx.x) |
---|
1382 | |2,5,8: whd in match Bit_of_val; normalize nodelta |
---|
1383 | [@mfr_return_eq1 %] cases b |
---|
1384 | [1,4: #bo|2,5: |3,6: #bo #ptr'' #p'' #bit_v] |
---|
1385 | normalize nodelta [3,4,5,6: @res_preserve_error1] |
---|
1386 | @mfr_return_eq1 % |
---|
1387 | |3,6,9: * normalize nodelta [1,3,5: @res_preserve_error1] |
---|
1388 | cases(op2 ?????) #a1 #a2 normalize nodelta |
---|
1389 | @mfr_return_eq1 % |
---|
1390 | ] |
---|
1391 | ] |
---|
1392 | |*: cases(ptype ptr') normalize nodelta [2,4: @res_preserve_error1] |
---|
1393 | cases p' * [2,4: #part_no] #prf normalize nodelta |
---|
1394 | [ @res_preserve_error1 |
---|
1395 | | cases b [#bo|| #bo #ptr'' #p'' #bit_v] |
---|
1396 | normalize nodelta [1,2: @res_preserve_error1] @if_elim #_ |
---|
1397 | [2: @res_preserve_error1] @If_elim #INUTILE [2: @res_preserve_error1] |
---|
1398 | @pair_elim #a1 #a2 #_ normalize nodelta @mfr_return_eq1 % |
---|
1399 | |*: @mfr_bind1 |
---|
1400 | [1,4: @(λx.x) |
---|
1401 | |2,5: whd in match Bit_of_val; normalize nodelta [ @mfr_return_eq1 %] |
---|
1402 | cases b [#bo|| #bo #ptr'' #p'' #bit_v] normalize nodelta |
---|
1403 | [2,3: @res_preserve_error1] @mfr_return_eq1 % |
---|
1404 | |3,6: * normalize nodelta [1,3: @res_preserve_error1] |
---|
1405 | cases(op2 ?????) #a1 #a2 normalize nodelta |
---|
1406 | @mfr_return_eq1 % |
---|
1407 | ] |
---|
1408 | ] |
---|
1409 | ] |
---|
1410 | ] |
---|
1411 | ] |
---|
1412 | qed. |
---|
1413 | |
---|
1414 | lemma pointer_of_address_ok : ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
1415 | preserving1 … res_preserve1 … |
---|
1416 | (λx.let 〈bv1,bv2〉 ≝ x in〈sigma_beval prog sigma bv1, |
---|
1417 | sigma_beval prog sigma bv2〉) |
---|
1418 | (λx.x) |
---|
1419 | pointer_of_address pointer_of_address. |
---|
1420 | #prog #sigma * #bv1 #bv2 whd in match pointer_of_address; |
---|
1421 | whd in match pointer_of_bevals; normalize nodelta |
---|
1422 | cases bv1 normalize nodelta |
---|
1423 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1424 | try @res_preserve_error1 |
---|
1425 | [ cases bv2 [ | | #ptr1' #ptr2' #p' | #by' | #p' | #ptr' #p' | #pc1' #p1'] |
---|
1426 | normalize nodelta |
---|
1427 | [1,2,3,4,5: @res_preserve_error1 |
---|
1428 | | @if_elim #_ [ @mfr_return_eq1 % | @res_preserve_error1] |
---|
1429 | ] |
---|
1430 | ] whd in match sigma_beval; normalize nodelta cases(sigma_pc_opt ???) |
---|
1431 | [2,4: #pc4] normalize nodelta @res_preserve_error1 |
---|
1432 | qed. |
---|
1433 | |
---|
1434 | lemma beloadv_ok : ∀prog : ertl_program. ∀sigma : sigma_map prog. |
---|
1435 | ∀ptr. |
---|
1436 | preserving1 … opt_preserve1 … |
---|
1437 | (sigma_mem prog sigma) |
---|
1438 | (sigma_beval prog sigma) |
---|
1439 | (λm.beloadv m ptr) |
---|
1440 | (λm.beloadv m ptr). |
---|
1441 | #prog #sigma #ptr #mem whd in match beloadv; whd in match do_if_in_bounds; |
---|
1442 | normalize nodelta @if_elim [2: #_ @opt_preserve_none1] |
---|
1443 | whd in match sigma_mem in ⊢ (% → ?); normalize nodelta #Hzlb |
---|
1444 | @if_elim [2: #_ @opt_preserve_none1] whd in match sigma_mem in ⊢ (% → ?); |
---|
1445 | normalize nodelta @If_elim [2: >Hzlb * #H @⊥ @H %] #_ @andb_elim @if_elim |
---|
1446 | [2: #_ *] #Hzleb #Hzlb' >Hzlb normalize nodelta >Hzlb' normalize nodelta |
---|
1447 | @mfr_return_eq1 whd in match sigma_mem; normalize nodelta >Hzlb |
---|
1448 | @If_elim [2: * #H @⊥ @H %] * >Hzleb >Hzlb' @If_elim [2: * #H @⊥ @H %] |
---|
1449 | * % |
---|
1450 | qed. |
---|
1451 | |
---|
1452 | lemma bestorev_ok : ∀prog : ertl_program.∀sigma : sigma_map prog. |
---|
1453 | ∀ptr. |
---|
1454 | preserving21 … opt_preserve1 … |
---|
1455 | (sigma_mem prog sigma) |
---|
1456 | (sigma_beval prog sigma) |
---|
1457 | (sigma_mem prog sigma) |
---|
1458 | (λm.bestorev m ptr) |
---|
1459 | (λm.bestorev m ptr). |
---|
1460 | #prog #sigma #ptr #mem #bv whd in match bestorev; whd in match do_if_in_bounds; |
---|
1461 | normalize nodelta @if_elim [2: #_ @opt_preserve_none1] |
---|
1462 | whd in match sigma_mem in ⊢ (% → ?); normalize nodelta #Hzlb |
---|
1463 | @if_elim [2: #_ @opt_preserve_none1] @andb_elim @if_elim [2: #_ *] |
---|
1464 | whd in match sigma_mem in ⊢ (% → % → ?); normalize nodelta >Hzlb |
---|
1465 | @If_elim [2: * #H @⊥ @H %] * #Hzleb #Hzlb' normalize nodelta >Hzleb |
---|
1466 | >Hzlb' normalize nodelta @mfr_return_eq1 whd in ⊢ (???%); @eq_f @mem_ext_eq |
---|
1467 | [ #bl normalize nodelta % [%] |
---|
1468 | [ whd in match sigma_mem; normalize nodelta >Hzlb @If_elim [2: * #H @⊥ @H %] * |
---|
1469 | whd in match update_block; normalize nodelta @if_elim |
---|
1470 | [ @eq_block_elim [2: #_ *] #EQbl * >EQbl >Hzlb @If_elim [2: * #H @⊥ @H %] |
---|
1471 | * whd in match low_bound; normalize nodelta @if_elim [ #_ %] |
---|
1472 | @eq_block_elim #_ * % |
---|
1473 | | @eq_block_elim [#_ *] * #Hbl * @If_elim |
---|
1474 | [ #Hzlb'' >Hzlb'' @If_elim [2: * #H @⊥ @H %] * whd in match low_bound; |
---|
1475 | normalize nodelta @if_elim [2: #_ %] @eq_block_elim [2: #_ *] #H @⊥ @Hbl |
---|
1476 | assumption |
---|
1477 | | #Hzlb'' >Hzlb'' @If_elim [*] #_ % |
---|
1478 | ] |
---|
1479 | ] |
---|
1480 | | whd in match update_block; whd in match sigma_mem; normalize nodelta |
---|
1481 | @if_elim @eq_block_elim [2,3: #_ * |4: *] #Hbl #_ @If_elim |
---|
1482 | [3,4: >Hbl >Hzlb * [2: #H @⊥ @H %] @If_elim [2: * #H @⊥ @H %] * |
---|
1483 | whd in match high_bound; normalize nodelta @if_elim [#_ %] |
---|
1484 | @eq_block_elim [ #_ *] * #H @⊥ @H % |
---|
1485 | | #Hzlb'' >Hzlb'' @If_elim [2: * #H @⊥ @H %] * whd in match high_bound; |
---|
1486 | normalize nodelta @if_elim [2: #_ %] @eq_block_elim [2: #_ *] |
---|
1487 | #H @⊥ @Hbl assumption |
---|
1488 | | #Hzlb'' >Hzlb'' @If_elim [*] #_ % |
---|
1489 | ] |
---|
1490 | | #z whd in match update_block; whd in match sigma_mem; normalize nodelta |
---|
1491 | @if_elim @eq_block_elim [2,3: #_ * |4: *] #Hbl #_ |
---|
1492 | [ @If_elim #Hzlb'' >Hzlb'' [2: @If_elim * #_ %] @If_elim @andb_elim |
---|
1493 | @if_elim [2: #_ *] #Hzleb' #Hzlb''' |
---|
1494 | [ @If_elim [2: * #H @⊥ @H %] * whd in match low_bound; normalize nodelta |
---|
1495 | @If_elim @andb_elim @if_elim [2: #_ *] @if_elim |
---|
1496 | [1,3,5: @eq_block_elim [2,4,6: #_ *] #H @⊥ @Hbl assumption] #_ >Hzleb' * |
---|
1497 | whd in match high_bound; normalize nodelta @if_elim |
---|
1498 | [1,3: @eq_block_elim [2,4: #_ *] #H @⊥ @Hbl assumption] #_ >Hzlb''' |
---|
1499 | [ * %] * #H @⊥ @H % |
---|
1500 | | @If_elim * [2: #H @⊥ @H %] whd in match low_bound; normalize nodelta |
---|
1501 | @if_elim [@eq_block_elim [2: #_ *] #H @⊥ @Hbl assumption] #_ |
---|
1502 | >Hzleb' whd in match high_bound; normalize nodelta @if_elim |
---|
1503 | [@eq_block_elim [2: #_ *] #H @⊥ @Hbl assumption] #_ >Hzlb''' |
---|
1504 | @If_elim [2: #_ %] * |
---|
1505 | | @If_elim [2: * #H @⊥ @H %] whd in match low_bound; normalize nodelta @if_elim |
---|
1506 | [@eq_block_elim [2: #_ *] #H @⊥ @Hbl assumption] #_ #_ |
---|
1507 | whd in match low_bound in Hzleb'; normalize nodelta in Hzleb'; |
---|
1508 | whd in match high_bound; normalize nodelta @if_elim |
---|
1509 | [@eq_block_elim [2: #_ *] #H @⊥ @Hbl assumption] #_ @If_elim [2: #_ %] |
---|
1510 | @andb_elim @if_elim [2: #_ *] #H >H in Hzleb'; * |
---|
1511 | ] |
---|
1512 | | whd in ⊢ (??%?); @if_elim @eqZb_elim [2,3: #_ * |4: *] #Hz * |
---|
1513 | [ >Hzlb @If_elim [2: * #H @⊥ @H %] * @If_elim @andb_elim @if_elim |
---|
1514 | [2: #_ *] #Hzleb' #Hzlb'' >Hbl >Hzlb @If_elim [2,4,6: * #H @⊥ @H %] #_ |
---|
1515 | whd in match low_bound; normalize nodelta @eq_block_elim |
---|
1516 | [2,4,6: * #H @⊥ @H %] #_ normalize nodelta whd in match high_bound; |
---|
1517 | normalize nodelta @eq_block_elim [2,4,6: * #H @⊥ @H %] |
---|
1518 | #_ normalize nodelta |
---|
1519 | [1,2: >Hzleb' >Hzlb'' @If_elim [2,3: * #H @⊥ @H %] |
---|
1520 | #_ [2: %] whd in ⊢ (???(???%)); @if_elim [2: #_ %] |
---|
1521 | @eqZb_elim [2: #_ *] #H @⊥ @Hz assumption |
---|
1522 | | @If_elim [2: #_ %] @andb_elim @if_elim [2: #_ *] #H >H in Hzleb'; * |
---|
1523 | ] |
---|
1524 | | >Hbl >Hzlb @If_elim [2: * #H @⊥ @H %] * whd in match low_bound; |
---|
1525 | normalize nodelta @eq_block_elim [2: * #H @⊥ @H %] #_ normalize nodelta |
---|
1526 | whd in match high_bound; normalize nodelta @eq_block_elim [2: * #H @⊥ @H %] |
---|
1527 | normalize nodelta >Hz >Hzleb >Hzlb' @If_elim [2: * #H @⊥ @H %] #_ #_ |
---|
1528 | whd in ⊢ (???(???%)); @eqZb_elim [2: * #H @⊥ @H %] #_ % |
---|
1529 | ] |
---|
1530 | ] |
---|
1531 | ] |
---|
1532 | | % |
---|
1533 | ] |
---|
1534 | qed. |
---|
1535 | |
---|
1536 | lemma match_reg_elim : ∀ A : Type[0]. ∀ P : A → Prop. ∀ r : region. |
---|
1537 | ∀f : (r = XData) → A. ∀g : (r = Code) → A. (∀ prf : r = XData.P (f prf)) → |
---|
1538 | (∀ prf : r = Code.P (g prf)) → |
---|
1539 | P ((match r return λx.(r = x → ?) with |
---|
1540 | [XData ⇒ f | Code ⇒ g])(refl ? r)). |
---|
1541 | #A #P * #f #g #H1 #H2 normalize nodelta [ @H1 | @H2] |
---|
1542 | qed. |
---|
1543 | |
---|
1544 | |
---|
1545 | lemma sp_ok : ∀prog : ertl_program. |
---|
1546 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1547 | ∀restr. |
---|
1548 | preserving1 … res_preserve1 … |
---|
1549 | (λst.sigma_state prog good st restr) |
---|
1550 | (λx.x) |
---|
1551 | (sp ERTL_semantics) |
---|
1552 | (sp ERTLptr_semantics). |
---|
1553 | #prog #good #restr #st whd in match sp; normalize nodelta |
---|
1554 | whd in match (load_sp ??); whd in match (load_sp ??); whd in match sigma_state; |
---|
1555 | normalize nodelta whd in match sigma_regs; normalize nodelta |
---|
1556 | cases(regs ? st) #psd_r #hw_r normalize nodelta |
---|
1557 | inversion(pointer_of_address ?) normalize nodelta [2: #e #_ @res_preserve_error1] |
---|
1558 | #pt #EQ lapply(jmeq_to_eq ??? EQ) -EQ whd in match hwreg_retrieve; normalize nodelta |
---|
1559 | whd in match sigma_hw_register_env; normalize nodelta |
---|
1560 | change with (sigma_beval ? (get_sigma_from_good_state … good) BVundef) in ⊢ (??(?(???(?????%)(?????%)))? → ?); |
---|
1561 | >lookup_map >lookup_map |
---|
1562 | cases(lookup beval 6 (bitvector_of_register RegisterSPL) (reg_env hw_r) BVundef) |
---|
1563 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1564 | whd in match pointer_of_address; whd in match pointer_of_bevals; normalize nodelta |
---|
1565 | [1,2,3,4,5: #ABS destruct |
---|
1566 | | cases(lookup beval 6 (bitvector_of_register RegisterSPH) (reg_env hw_r) BVundef) |
---|
1567 | [ | | #ptr1' #ptr2' #p' | #by' | #p' | #ptr' #p' | #pc1' #p1'] |
---|
1568 | whd in match sigma_beval; normalize nodelta |
---|
1569 | [1,2,3,4,5: #ABS destruct |
---|
1570 | | @if_elim [2: #_ #ABS destruct] #H whd in ⊢ (??%? → ?); #EQ destruct |
---|
1571 | normalize nodelta @match_reg_elim #INUTILE |
---|
1572 | [ @mfr_return_eq1 % | @res_preserve_error1 ] |
---|
1573 | | cases (sigma_pc_opt ? ? ?) normalize nodelta [2: #x] #EQ destruct |
---|
1574 | ] |
---|
1575 | | whd in match sigma_beval; normalize nodelta cases(sigma_pc_opt ? ? ?) |
---|
1576 | normalize nodelta [2: #x] #EQ destruct |
---|
1577 | ] |
---|
1578 | qed. |
---|
1579 | |
---|
1580 | lemma set_sp_ok : ∀prog : ertl_program. |
---|
1581 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1582 | ∀restr.∀ptr,st. |
---|
1583 | set_sp ? ptr (sigma_state prog good st restr) = |
---|
1584 | sigma_state prog good (set_sp ? ptr st) restr. |
---|
1585 | #prog #good #restr #ptr #st whd in match set_sp; whd in match sigma_state; |
---|
1586 | normalize nodelta @eq_f2 [2: %] whd in match (save_sp ???); |
---|
1587 | whd in match (save_sp ???); whd in match sigma_regs; normalize nodelta |
---|
1588 | cases(regs ? st) #psd_env #hw_regs normalize nodelta @eq_f |
---|
1589 | whd in match hwreg_store_sp; normalize nodelta whd in match sigma_hw_register_env; |
---|
1590 | normalize nodelta whd in match hwreg_store; normalize nodelta @eq_f2 [2: %] |
---|
1591 | >insert_map @eq_f >insert_map % |
---|
1592 | qed. |
---|
1593 | |
---|
1594 | lemma eval_seq_no_pc_no_call_ok : |
---|
1595 | ∀prog : ertl_program. |
---|
1596 | let trans_prog ≝ (ertl_to_ertlptr prog) in |
---|
1597 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1598 | ∀stack_size. ∀id. ∀fn : (joint_closed_internal_function ??) .∀seq. |
---|
1599 | preserving1 ?? res_preserve1 ???? |
---|
1600 | (λst.sigma_state prog good st (added_registers … fn (f_regs … (good fn)))) |
---|
1601 | (λst.sigma_state prog good st (added_registers … fn (f_regs … (good fn)))) |
---|
1602 | (eval_seq_no_pc ERTL_semantics |
---|
1603 | (globals (mk_prog_params ERTL_semantics prog stack_size)) |
---|
1604 | (ev_genv (mk_prog_params ERTL_semantics prog stack_size)) id fn seq) |
---|
1605 | (eval_seq_no_pc ERTLptr_semantics |
---|
1606 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_size)) |
---|
1607 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_size)) id (translate_internal … fn) (seq_embed … seq)). |
---|
1608 | #prog #good #stack_size #f #fn * |
---|
1609 | whd in match eval_seq_no_pc; normalize nodelta |
---|
1610 | [ #c #st @mfr_return1 |
---|
1611 | | #c #st @mfr_return1 |
---|
1612 | | #pm #st whd in match pair_reg_move; normalize nodelta |
---|
1613 | @mfr_bind1 |
---|
1614 | [ 2: change with (ertl_eval_move ??) in ⊢ (???????%%); @ertl_eval_move_ok |
---|
1615 | | | #regs @mfr_return_eq1 % |
---|
1616 | ] |
---|
1617 | | #r #st @mfr_bind1 |
---|
1618 | [2: @pop_ok | |
---|
1619 | | * #bv #st whd in match acca_store; normalize nodelta @mfr_bind1 |
---|
1620 | [2: @ps_reg_store_ok | |
---|
1621 | | #regs @mfr_return_eq1 % |
---|
1622 | ] |
---|
1623 | ] |
---|
1624 | | #r #st @mfr_bind1 |
---|
1625 | [2: whd in match acca_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1626 | | #bv @push_ok |
---|
1627 | ] |
---|
1628 | | #i |
---|
1629 | #i_spec |
---|
1630 | change with ((dpl_reg ERTL) → ?) |
---|
1631 | #dpl |
---|
1632 | change with ((dph_reg ERTL) → ?) |
---|
1633 | #dph #st @mfr_bind1 |
---|
1634 | [ @(λst.sigma_state prog good st (added_registers … fn (f_regs … (good fn)))) |
---|
1635 | | whd in match dpl_store; normalize nodelta @mfr_bind1 |
---|
1636 | [2: @opt_safe_elim #bl #EQbl |
---|
1637 | @opt_safe_elim #bl' |
---|
1638 | >(find_symbol_transf … |
---|
1639 | (λvars.transf_fundef … (λfn.(translate_internal … fn))) prog i) in ⊢ (%→?); |
---|
1640 | >EQbl #EQ destruct whd in match sigma_state; normalize nodelta |
---|
1641 | change with (sigma_beval prog (get_sigma_from_good_state … good) (BVptr …)) |
---|
1642 | in ⊢ (???????(?????%?)?); |
---|
1643 | @ps_reg_store_ok | |
---|
1644 | | #regs @mfr_return_eq1 % |
---|
1645 | ] |
---|
1646 | | #st1 @opt_safe_elim #bl #EQbl @opt_safe_elim #bl' |
---|
1647 | >(find_symbol_transf … |
---|
1648 | (λvars.transf_fundef … (λfn.(translate_internal … fn))) prog i) in ⊢ (%→?); |
---|
1649 | >EQbl #EQ destruct whd in match dph_store; normalize nodelta @mfr_bind1 |
---|
1650 | [2: whd in match sigma_state; normalize nodelta |
---|
1651 | change with (sigma_beval prog (get_sigma_from_good_state … good) (BVptr …)) |
---|
1652 | in ⊢ (???????(?????%?)?); |
---|
1653 | @ps_reg_store_ok | |
---|
1654 | | #regs @mfr_return_eq1 % |
---|
1655 | ] |
---|
1656 | ] |
---|
1657 | | #op #a #b #arg1 #arg2 #st @mfr_bind1 |
---|
1658 | [2: whd in match acca_arg_retrieve; whd in match sigma_state; normalize nodelta |
---|
1659 | @ps_arg_retrieve_ok | |
---|
1660 | | #bv1 @mfr_bind1 |
---|
1661 | [2: whd in match accb_arg_retrieve; whd in match sigma_state; normalize nodelta |
---|
1662 | @ps_arg_retrieve_ok | |
---|
1663 | | #bv2 @mfr_bind1 |
---|
1664 | [2: @be_opaccs_ok | |
---|
1665 | | * #bv3 #bv4 normalize nodelta @mfr_bind1 |
---|
1666 | [ @(λst.sigma_state prog good st (added_registers … fn (f_regs … (good fn)))) |
---|
1667 | | whd in match acca_store; normalize nodelta @mfr_bind1 |
---|
1668 | [2: @ps_reg_store_ok | |
---|
1669 | | #regs @mfr_return_eq1 % |
---|
1670 | ] |
---|
1671 | | #st1 whd in match accb_store; normalize nodelta @mfr_bind1 |
---|
1672 | [2: whd in match sigma_state; normalize nodelta |
---|
1673 | @ps_reg_store_ok | |
---|
1674 | | #regs @mfr_return_eq1 % |
---|
1675 | ] |
---|
1676 | ] |
---|
1677 | ] |
---|
1678 | ] |
---|
1679 | ] |
---|
1680 | | #op #r1 #r2 #st @mfr_bind1 |
---|
1681 | [ @(sigma_beval prog (get_sigma_from_good_state … good)) |
---|
1682 | | whd in match acca_retrieve; normalize nodelta @ps_reg_retrieve_ok |
---|
1683 | | #bv1 @mfr_bind1 |
---|
1684 | [ @(sigma_beval prog (get_sigma_from_good_state … good)) |
---|
1685 | | @be_op1_ok |
---|
1686 | | #bv2 whd in match acca_store; normalize nodelta @mfr_bind1 |
---|
1687 | [2: whd in match sigma_state; normalize nodelta @ps_reg_store_ok | |
---|
1688 | | #regs @mfr_return_eq1 % |
---|
1689 | ] |
---|
1690 | ] |
---|
1691 | ] |
---|
1692 | | #op2 #r1 #r2 #arg #st @mfr_bind1 |
---|
1693 | [2: whd in match acca_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1694 | | #bv @mfr_bind1 |
---|
1695 | [2: whd in match snd_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1696 | | #bv1 @mfr_bind1 |
---|
1697 | [2: @be_op2_ok | |
---|
1698 | | * #bv2 #b @mfr_bind1 |
---|
1699 | [ @(λst.sigma_state prog good st (added_registers … fn (f_regs … (good fn)))) |
---|
1700 | | whd in match acca_store; normalize nodelta @mfr_bind1 |
---|
1701 | [2: whd in match sigma_state; normalize nodelta @ps_reg_store_ok | |
---|
1702 | | #regs @mfr_return_eq1 % |
---|
1703 | ] |
---|
1704 | | #st1 @mfr_return_eq1 % |
---|
1705 | ] |
---|
1706 | ] |
---|
1707 | ] |
---|
1708 | ] |
---|
1709 | | #st @mfr_return_eq1 % |
---|
1710 | | #st @mfr_return_eq1 % |
---|
1711 | | #r1 #dpl #dph #st @mfr_bind1 |
---|
1712 | [2: whd in match dph_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1713 | | #bv @mfr_bind1 |
---|
1714 | [2: whd in match dpl_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1715 | | #bv1 @mfr_bind1 |
---|
1716 | [ @(λx.x) |
---|
1717 | | @(pointer_of_address_ok ? ? 〈bv1,bv〉) |
---|
1718 | | #ptr @mfr_bind1 |
---|
1719 | [2: @opt_to_res_preserve1 @beloadv_ok | |
---|
1720 | | #bv2 whd in match acca_store; normalize nodelta @mfr_bind1 |
---|
1721 | [2: whd in match sigma_state; normalize nodelta @ps_reg_store_ok | |
---|
1722 | | #regs @mfr_return_eq1 % |
---|
1723 | ] |
---|
1724 | ] |
---|
1725 | ] |
---|
1726 | ] |
---|
1727 | ] |
---|
1728 | | #dpl #dph #r #st @mfr_bind1 |
---|
1729 | [2: whd in match dph_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1730 | | #bv @mfr_bind1 |
---|
1731 | [2: whd in match dpl_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1732 | | #bv1 @mfr_bind1 |
---|
1733 | [ @(λx.x) |
---|
1734 | | @(pointer_of_address_ok ? ? 〈bv1,bv〉) |
---|
1735 | | #ptr @mfr_bind1 |
---|
1736 | [2: whd in match acca_arg_retrieve; normalize nodelta @ps_arg_retrieve_ok | |
---|
1737 | | #bv2 @mfr_bind1 |
---|
1738 | [2: @opt_to_res_preserve1 @bestorev_ok | |
---|
1739 | | #m @mfr_return_eq1 % |
---|
1740 | ] |
---|
1741 | ] |
---|
1742 | ] |
---|
1743 | ] |
---|
1744 | ] |
---|
1745 | | #ext #st whd in ⊢ (???????%%); whd in match (stack_sizes ????); cases (stack_size f) |
---|
1746 | normalize nodelta |
---|
1747 | [ @res_preserve_error1 |
---|
1748 | | #n cases ext normalize nodelta |
---|
1749 | [1,2: @mfr_bind1 |
---|
1750 | [1,4: @(λx.x) |
---|
1751 | |2,5: @sp_ok |
---|
1752 | |3,6: #ptr @mfr_return_eq1 >set_sp_ok % |
---|
1753 | ] |
---|
1754 | | #r whd in match ps_reg_store_status; normalize nodelta @mfr_bind1 |
---|
1755 | [2: whd in match sigma_state; normalize nodelta |
---|
1756 | change with (sigma_beval ? (get_sigma_from_good_state … good) (BVByte ?)) |
---|
1757 | in ⊢ (???????(??%?)?); |
---|
1758 | @ps_reg_store_ok |
---|
1759 | | |
---|
1760 | | #regs @mfr_return_eq1 % |
---|
1761 | ] |
---|
1762 | ] |
---|
1763 | ] |
---|
1764 | ] |
---|
1765 | qed. |
---|
1766 | |
---|
1767 | lemma partial_inj_sigma : ∀ prog : ertl_program. |
---|
1768 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1769 | let sigma ≝ (get_sigma_from_good_state … good) in |
---|
1770 | ∀fn,lbl1,lbl2. sigma fn lbl1 ≠ None ? → sigma fn lbl1 = sigma fn lbl2 → lbl1 = lbl2. |
---|
1771 | #prog #good #fn #lbl1 #lbl2 inversion(get_sigma_from_good_state … lbl1) |
---|
1772 | [#_ * #H @⊥ @H %] #lbl1' whd in match get_sigma_from_good_state; normalize nodelta |
---|
1773 | #H @('bind_inversion H) -H * #lbl1'' #stmt1 #H1 whd in ⊢ (??%? → ?); #EQ destruct |
---|
1774 | #_ #H lapply(sym_eq ??? H) -H #H @('bind_inversion H) -H * #lbl2' #stmt2 #H2 |
---|
1775 | whd in ⊢ (??%? → ?); #EQ destruct lapply(find_predicate ?????? H1) |
---|
1776 | lapply(find_predicate ?????? H2) cases(f_lbls ????) normalize nodelta [*] |
---|
1777 | * normalize nodelta |
---|
1778 | [@eq_identifier_elim #EQ1 * @eq_identifier_elim #EQ2 * >EQ1 >EQ2 % ] |
---|
1779 | #lb #tl @eq_identifier_elim #EQ1 * @eq_identifier_elim #EQ2 * >EQ1 >EQ2 % |
---|
1780 | qed. |
---|
1781 | |
---|
1782 | lemma pc_of_label_eq : |
---|
1783 | ∀p,p'.let pars ≝ make_sem_graph_params p p' in |
---|
1784 | ∀globals,ge,bl,i_fn,lbl. |
---|
1785 | fetch_internal_function ? ge bl = return i_fn → |
---|
1786 | pc_of_label pars globals ge bl lbl = |
---|
1787 | OK ? (pc_of_point ERTL_semantics bl lbl). |
---|
1788 | #p #p' #globals #ge #bl #i_fn #lbl #EQf |
---|
1789 | whd in match pc_of_label; |
---|
1790 | normalize nodelta >EQf >m_return_bind % |
---|
1791 | qed. |
---|
1792 | |
---|
1793 | lemma pop_ra_ok : |
---|
1794 | ∀prog : ertl_program. |
---|
1795 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
1796 | ∀restr. |
---|
1797 | preserving1 … res_preserve1 … |
---|
1798 | (λst.sigma_state prog good st restr) |
---|
1799 | (λx.let 〈st,pc〉 ≝ x in |
---|
1800 | let sigma ≝ (get_sigma_from_good_state … good) in |
---|
1801 | 〈sigma_state prog good st restr, |
---|
1802 | sigma_stored_pc ? sigma pc〉) |
---|
1803 | (pop_ra ERTL_semantics) |
---|
1804 | (pop_ra ERTLptr_semantics). |
---|
1805 | #prog #good #restr #st whd in match pop_ra; normalize nodelta @mfr_bind1 |
---|
1806 | [ | @pop_ok ] * #bv #st1 @mfr_bind1 [ | @pop_ok] * #bv1 #st2 @mfr_bind1 |
---|
1807 | [ @(sigma_stored_pc ? (get_sigma_from_good_state … good)) |
---|
1808 | | whd in match pc_of_bevals; normalize nodelta |
---|
1809 | cases bv [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc #p] |
---|
1810 | whd in match sigma_beval; normalize nodelta try @res_preserve_error1 |
---|
1811 | inversion(sigma_pc_opt ? ? ?) normalize nodelta [ #_ @res_preserve_error1] |
---|
1812 | #sigma_pc #sigma_pc_spec normalize nodelta cases bv1 |
---|
1813 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc1 #p1] |
---|
1814 | normalize nodelta try @res_preserve_error1 |
---|
1815 | inversion(sigma_pc_opt ? ? ?) normalize nodelta [#_ @res_preserve_error1] |
---|
1816 | #sigma_pc1 #sigma_pc1_spec @if_elim [2: #_ @res_preserve_error1] |
---|
1817 | @andb_elim @if_elim [2: #_ *] @andb_elim @if_elim [2: #_ *] |
---|
1818 | #_ #H >H @eq_program_counter_elim [2: #_ *] |
---|
1819 | #EQspc * @eq_program_counter_elim |
---|
1820 | [#_ normalize nodelta @mfr_return_eq1 whd in match sigma_stored_pc; normalize nodelta |
---|
1821 | >sigma_pc1_spec %] * #H1 @⊥ @H1 >EQspc in sigma_pc_spec; <sigma_pc1_spec |
---|
1822 | whd in match sigma_pc_opt; normalize nodelta @if_elim |
---|
1823 | [ #H2 #EQ lapply(sym_eq ??? EQ) -EQ @if_elim [#_ whd in ⊢ (??%% → ?); #EQ destruct %] |
---|
1824 | #H3 #H @('bind_inversion H) -H #x #_ #H @('bind_inversion H) -H #y #_ |
---|
1825 | cases sigma_pc1 in H2; #bl_pc1 #z #H2 whd in ⊢ (??%? → ?); #EQ destruct >H2 in H3; * |
---|
1826 | | #H2 @if_elim |
---|
1827 | [ #H3 #H @('bind_inversion H) -H #x1 #_ #H @('bind_inversion H) -H #lbl1 #_ |
---|
1828 | cases pc in H2; #bl #z #H2 whd in match pc_of_point; normalize nodelta whd in ⊢ (??%? → ?); |
---|
1829 | #EQ destruct >H3 in H2; * |
---|
1830 | | #H3 lapply sigma_pc1_spec; whd in match sigma_pc_opt; normalize nodelta @if_elim |
---|
1831 | [#H >H in H3; *] #_ #EQ >EQ @('bind_inversion EQ) -EQ #x #x_spec |
---|
1832 | lapply(res_eq_from_opt ??? x_spec) -x_spec #x_spec #H @('bind_inversion H) * #lbl |
---|
1833 | #lbl_spec whd in match pc_of_point; normalize nodelta cases sigma_pc1 #bl1 #lbl1 |
---|
1834 | whd in match (offset_of_point ??); whd in ⊢ (??%? → ?); #EQ destruct cases pc #bl2 #p2 |
---|
1835 | #H @('bind_inversion H) -H #x1 #x1_spec lapply(res_eq_from_opt ??? x1_spec) -x1_spec #x1_spec |
---|
1836 | #H @('bind_inversion H) -H * #lbl2 #lbl2_spec |
---|
1837 | whd in match (offset_of_point ??); whd in ⊢ (??%? → ?); #EQ destruct |
---|
1838 | <lbl_spec in lbl2_spec; #EQsig >x_spec in x1_spec; whd in ⊢ (??%% → ?); #EQ destruct |
---|
1839 | lapply(partial_inj_sigma … EQsig) |
---|
1840 | [>EQsig >lbl_spec % #ABS destruct] whd in match point_of_pc; normalize nodelta |
---|
1841 | whd in match (point_of_offset ??); whd in match (point_of_offset ??); |
---|
1842 | #EQ destruct cases pc1 #bl #p % |
---|
1843 | ] |
---|
1844 | ] |
---|
1845 | | #pc @mfr_return_eq1 % |
---|
1846 | ] |
---|
1847 | qed. |
---|
1848 | |
---|
1849 | lemma pc_block_eq : ∀prog : ertl_program. |
---|
1850 | ∀sigma : sigma_map prog. |
---|
1851 | ∀pc,id,fn. |
---|
1852 | fetch_internal_function (joint_closed_internal_function ERTL |
---|
1853 | (prog_var_names (joint_function ERTL) ℕ prog)) |
---|
1854 | (globalenv_noinit (joint_function ERTL) prog) (pc_block … pc) |
---|
1855 | = return 〈id,fn〉→ |
---|
1856 | sigma fn (point_of_pc ERTL_semantics pc) ≠ None ? → |
---|
1857 | pc_block … pc = pc_block … (sigma_stored_pc prog sigma pc). |
---|
1858 | #prog #sigma * #bl #pos #id #fn #EQfn #EQlbl whd in match sigma_stored_pc; |
---|
1859 | normalize nodelta whd in match sigma_pc_opt; normalize nodelta @if_elim [ #_ %] |
---|
1860 | #_ >EQfn >m_return_bind >(opt_to_opt_safe … EQlbl) >m_return_bind % |
---|
1861 | qed. |
---|
1862 | |
---|
1863 | inductive ex_Type1 (A:Type[1]) (P:A → Prop) : Prop ≝ |
---|
1864 | ex1_intro: ∀ x:A. P x → ex_Type1 A P. |
---|
1865 | (*interpretation "exists in Type[1]" 'exists x = (ex_Type1 ? x).*) |
---|
1866 | |
---|
1867 | include "joint/semantics_blocks.ma". |
---|
1868 | |
---|
1869 | lemma fetch_internal_function_no_zero : |
---|
1870 | ∀F,V,i,p,bl. |
---|
1871 | block_id (pi1 … bl) = 0 → |
---|
1872 | fetch_internal_function ? |
---|
1873 | |
---|
1874 | (globalenv (λvars.fundef (F vars)) V i p) bl = |
---|
1875 | Error ? [MSG BadFunction]. |
---|
1876 | #F #V #i #p #bl #EQbl whd in match fetch_internal_function; |
---|
1877 | normalize nodelta >fetch_function_no_zero [2: assumption] % |
---|
1878 | qed. |
---|
1879 | |
---|
1880 | lemma fetch_statement_no_zero : |
---|
1881 | ∀pars,prog,stack_size,pc. |
---|
1882 | block_id(pi1 … (pc_block pc)) = 0 → |
---|
1883 | fetch_statement pars (prog_var_names … prog) |
---|
1884 | (ev_genv (mk_prog_params pars prog stack_size)) pc = |
---|
1885 | Error ? [MSG BadFunction]. |
---|
1886 | #pars #vars #ge #pc #EQpc whd in match fetch_statement; normalize nodelta |
---|
1887 | >fetch_internal_function_no_zero [2: assumption] % |
---|
1888 | qed. |
---|
1889 | |
---|
1890 | lemma foo : |
---|
1891 | ∀P1_unser,P2_unser: unserialized_params. |
---|
1892 | ∀P1_sem_unser,P2_sem_unser. |
---|
1893 | let P1_sem ≝ make_sem_graph_params P1_unser P1_sem_unser in |
---|
1894 | let P2_sem ≝ make_sem_graph_params P2_unser P2_sem_unser in |
---|
1895 | ∀init,translate_step. |
---|
1896 | ∀translate_fin_step. |
---|
1897 | ∀closed_graph_translate. |
---|
1898 | let translate_internal : |
---|
1899 | ∀globals. |
---|
1900 | joint_closed_internal_function P1_sem globals → |
---|
1901 | joint_closed_internal_function P2_sem globals |
---|
1902 | ≝ |
---|
1903 | λglobals,fun. |
---|
1904 | «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals |
---|
1905 | (init globals) |
---|
1906 | (translate_step globals) |
---|
1907 | (translate_fin_step globals) |
---|
1908 | (pi1 … fun), closed_graph_translate globals fun» in |
---|
1909 | ∀prog. |
---|
1910 | let trans_prog ≝ transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames)) in |
---|
1911 | ∀stack_size. |
---|
1912 | ∀sigma_state_pc. |
---|
1913 | (∀s. pc_block (pc … (sigma_state_pc s)) = pc_block … (pc … s)) → |
---|
1914 | ∀st : state_pc P2_sem. |
---|
1915 | ∀st' : state_pc P1_sem. |
---|
1916 | ∀f. |
---|
1917 | ∀fn: joint_closed_internal_function P1_sem (globals (mk_prog_params P1_sem prog stack_size)). |
---|
1918 | luniverse_ok … fn → |
---|
1919 | ∀stmt,nxt. |
---|
1920 | (∀pre_Instrs',last_Instrs',dst. |
---|
1921 | ∃st''.∃st'''.∃st''''. |
---|
1922 | repeat_eval_seq_no_pc (mk_prog_params P2_sem trans_prog stack_size) |
---|
1923 | f (translate_internal ? fn) (map_eval ?? pre_Instrs' dst) st = return st''' ∧ |
---|
1924 | eval_seq_no_pc ? (prog_var_names … trans_prog) (ev_genv … (mk_prog_params P2_sem trans_prog stack_size)) |
---|
1925 | f (translate_internal … fn) (last_Instrs' dst) st''' = return st'''' ∧ |
---|
1926 | st'' = (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size) |
---|
1927 | st'''' (pc_of_point P2_sem (pc_block (pc … (sigma_state_pc st))) dst) (last_pop … st)) ∧ |
---|
1928 | st' = sigma_state_pc st'' ∧ |
---|
1929 | let P2_prog_params ≝ mk_prog_params P2_sem trans_prog stack_size in |
---|
1930 | let P2_globals ≝ globals P2_prog_params in |
---|
1931 | All |
---|
1932 | (joint_seq … P2_globals) |
---|
1933 | (no_cost_label … P2_globals) |
---|
1934 | (map_eval (code_point P2_sem) (joint_seq … P2_globals) pre_Instrs' dst)) → |
---|
1935 | fetch_statement … |
---|
1936 | (prog_var_names (joint_function P1_sem) ℕ prog) |
---|
1937 | (ev_genv (mk_prog_params P1_sem prog stack_size)) |
---|
1938 | (pc … (sigma_state_pc st)) = |
---|
1939 | return 〈f, fn, sequential … (step_seq P1_sem … stmt) nxt〉 → |
---|
1940 | eval_state … |
---|
1941 | (prog_var_names (joint_function P1_sem) ℕ prog) |
---|
1942 | (ev_genv … (mk_prog_params P1_sem prog stack_size)) |
---|
1943 | (sigma_state_pc st) = return st' → |
---|
1944 | ∃st''. (*CSC: this needs to be linked back again st' = sigma_state_pc ? good st'' ∧*) |
---|
1945 | ∃taf : trace_any_any_free (joint_abstract_status (mk_prog_params P2_sem trans_prog stack_size)) st st''. |
---|
1946 | True (* the length of taf is the same of the length of ??? *). |
---|
1947 | #P1_unser #P2_unser #P1_sem_unser #P2_sem_unser |
---|
1948 | letin P1_sem ≝ (make_sem_graph_params P1_unser P1_sem_unser) |
---|
1949 | letin P2_sem ≝ (make_sem_graph_params P2_unser P2_sem_unser) |
---|
1950 | #init #translate_step #translate_fin_step #closed_graph_translate. |
---|
1951 | letin translate_internal ≝ |
---|
1952 | (λglobals,fun. |
---|
1953 | «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals |
---|
1954 | (init globals) |
---|
1955 | (translate_step globals) |
---|
1956 | (translate_fin_step globals) |
---|
1957 | (pi1 … fun), closed_graph_translate globals fun») |
---|
1958 | #prog |
---|
1959 | letin trans_prog ≝ (transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames))) |
---|
1960 | #stack_size #sigma_state_pc #sigma_state_pc_ok #st #st' #f #fn #fn_universe_ok #stmt #nxt #Hpass |
---|
1961 | #EQfetch lapply(fetch_statement_inv … EQfetch) * #EQfn #EQstmt |
---|
1962 | cases |
---|
1963 | (b_graph_translate_ok … (init …) (translate_step …) (translate_fin_step …) … fn_universe_ok) |
---|
1964 | #_ * #MK_fresh_labels * #MK_fresh_registers **** #_ #_ #_ #_ (*CSC: useful things thrown out here *) |
---|
1965 | #MULTI_FETCH_OK cases (MULTI_FETCH_OK … EQstmt) |
---|
1966 | #list_b_last * #fresh_registers ** #EQlist_b_last #EQfresh_registers |
---|
1967 | normalize nodelta * #Instrs * #fresh_registers_spec whd in ⊢ (% → ?); |
---|
1968 | @pair_elim #pre_Instrs #last_Instrs #EQInstrs * #dst * #Multi_fetch #STEP_in_code |
---|
1969 | #EQeval |
---|
1970 | cut((list |
---|
1971 | (code_point P2_sem |
---|
1972 | →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog)))) [ cases daemon (*Paolo should fix the lemma*)] |
---|
1973 | #pre_Instrs' |
---|
1974 | cut((code_point P2_sem |
---|
1975 | →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog))) [ cases daemon (*Paolo should fix the lemma*)] |
---|
1976 | #last_Instrs' |
---|
1977 | cases (Hpass pre_Instrs' last_Instrs' dst (* MANY MORE HERE *)) |
---|
1978 | #st'' * #st''' * #st'''' **** #REPEAT #EVAL_NO_PC_Last #EQst'' #EQst' #NO_COSTED |
---|
1979 | lapply(produce_trace_any_any_free … NO_COSTED … REPEAT) |
---|
1980 | [ cases daemon (* should be @Multi_fetch *) |
---|
1981 | | <sigma_state_pc_ok @(fetch_internal_function_transf … (λvars.translate_internal vars)) |
---|
1982 | assumption |
---|
1983 | | @dst |
---|
1984 | | @list_b_last (*wrong, should dst be destination or the last of list_b_last *) |
---|
1985 | ] #TAAF |
---|
1986 | lapply |
---|
1987 | (produce_step_trace (mk_prog_params P2_sem trans_prog stack_size) |
---|
1988 | (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size) |
---|
1989 | st''' (pc_of_point P2_sem (pc_block (pc … st)) dst) (last_pop … st)) |
---|
1990 | f (translate_internal ? fn) (last_Instrs' dst) nxt st'''' … EVAL_NO_PC_Last) |
---|
1991 | [ cases daemon (* should be @STEP_In_code *) |
---|
1992 | | <sigma_state_pc_ok |
---|
1993 | @(fetch_internal_function_transf … (λvars. translate_internal vars) … EQfn) ] |
---|
1994 | #LAST_STEP |
---|
1995 | cases daemon |
---|
1996 | qed. |
---|
1997 | |
---|
1998 | lemma eval_seq_no_call_ok : |
---|
1999 | ∀prog. |
---|
2000 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2001 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
2002 | ∀stack_sizes. |
---|
2003 | (*? →*) |
---|
2004 | ∀st : state_pc ERTLptr_semantics. |
---|
2005 | ∀st' : state_pc ERTL_semantics. |
---|
2006 | ∀f,fn,stmt,nxt. |
---|
2007 | fetch_statement ERTL_semantics |
---|
2008 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2009 | (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2010 | (pc … (sigma_state_pc ? good st)) = |
---|
2011 | return 〈f, fn, sequential … (step_seq ERTL … stmt) nxt〉 → |
---|
2012 | eval_state ERTL_semantics |
---|
2013 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2014 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2015 | (sigma_state_pc ? good st) = |
---|
2016 | return st' → |
---|
2017 | ∃st''. st' = sigma_state_pc ? good st'' ∧ |
---|
2018 | ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) |
---|
2019 | st |
---|
2020 | st''. |
---|
2021 | bool_to_Prop (taaf_non_empty … taf). |
---|
2022 | #prog #good #stack_size #st #st' #f #fn #stmt #nxt #EQfetch #EQeval |
---|
2023 | cases (foo … translate_step translate_fin_step … EQfetch EQeval) |
---|
2024 | [2,3: cases daemon (* first one, take out init definition from ERTLtoERTLptr; |
---|
2025 | second one to be taken from somewhere *) |
---|
2026 | |4: #x cases daemon (* TO BE DONE, EASY *) |
---|
2027 | |5: cases daemon (* to be taken in input *) ] |
---|
2028 | [2: cases daemon |
---|
2029 | | #st'' * #taaf #_ %{st''} |
---|
2030 | change with ERTL_uns in match (mk_unserialized_params ???????????????); |
---|
2031 | change with ERTLptr_uns in match (mk_unserialized_params ???????????????); |
---|
2032 | change with ERTL_semantics in match (make_sem_graph_params ??); |
---|
2033 | change with ERTLptr_semantics in match (make_sem_graph_params ??); |
---|
2034 | |
---|
2035 | |
---|
2036 | #H1 #H2 #H3 * |
---|
2037 | |
---|
2038 | ∀P1_unser,P2_unser: unserialized_params. |
---|
2039 | ∀P1_sem_unser,P2_sem_unser. |
---|
2040 | ∀init,translate_step. |
---|
2041 | ∀translate_fin_step. |
---|
2042 | ∀closed_graph_translate. |
---|
2043 | ∀prog. |
---|
2044 | ∀stack_size. |
---|
2045 | ∀sigma_state_pc. |
---|
2046 | (∀s. pc_block (pc … (sigma_state_pc s)) = pc_block … (pc … s)) → |
---|
2047 | ∀st : state_pc P2_sem. |
---|
2048 | ∀st' : state_pc P1_sem. |
---|
2049 | ∀f. |
---|
2050 | ∀fn: joint_closed_internal_function P1_sem (globals (mk_prog_params P1_sem prog stack_size)). |
---|
2051 | luniverse_ok … fn → |
---|
2052 | ∀stmt,nxt. |
---|
2053 | (∀pre_Instrs',last_Instrs',dst. |
---|
2054 | ∃st''.∃st'''.∃st''''. |
---|
2055 | repeat_eval_seq_no_pc (mk_prog_params P2_sem trans_prog stack_size) |
---|
2056 | f (translate_internal ? fn) (map_eval ?? pre_Instrs' dst) st = return st''' ∧ |
---|
2057 | eval_seq_no_pc ? (prog_var_names … trans_prog) (ev_genv … (mk_prog_params P2_sem trans_prog stack_size)) |
---|
2058 | f (translate_internal … fn) (last_Instrs' dst) st''' = return st'''' ∧ |
---|
2059 | st'' = (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size) |
---|
2060 | st'''' (pc_of_point P2_sem (pc_block (pc … (sigma_state_pc st))) dst) (last_pop … st)) ∧ |
---|
2061 | st' = sigma_state_pc st'' ∧ |
---|
2062 | let P2_prog_params ≝ mk_prog_params P2_sem trans_prog stack_size in |
---|
2063 | let P2_globals ≝ globals P2_prog_params in |
---|
2064 | All |
---|
2065 | (joint_seq … P2_globals) |
---|
2066 | (no_cost_label … P2_globals) |
---|
2067 | (map_eval (code_point P2_sem) (joint_seq … P2_globals) pre_Instrs' dst)) → |
---|
2068 | |
---|
2069 | |
---|
2070 | |
---|
2071 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta @if_elim |
---|
2072 | [ #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2073 | #EQbl inversion(fetch_internal_function ?? (pc_block (pc ? st))) normalize nodelta |
---|
2074 | [2: #err #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2075 | * #id1 #fn1 #EQfn normalize nodelta #EQfetch lapply(fetch_statement_inv … EQfetch) |
---|
2076 | * >EQfn #EQ destruct normalize nodelta #EQstmt |
---|
2077 | cases(multi_fetch_ok … (good fn) ?? EQstmt) |
---|
2078 | #list_b_last * #fresh_registers ** #EQlist_b_last #EQfresh_registers |
---|
2079 | normalize nodelta * #Instrs * #fresh_registers_spec whd in ⊢ (% → ?); |
---|
2080 | @pair_elim #pre_Instrs #last_Instrs #EQInstrs * #dst * #Multi_fetch #STEP_in_code |
---|
2081 | #EQeval |
---|
2082 | cut((list |
---|
2083 | (code_point ERTLptr |
---|
2084 | →joint_seq ERTLptr (prog_var_names (joint_function ERTL) ℕ prog)))) [ cases daemon (*Paolo should fix the lemma*)] |
---|
2085 | #pre_Instrs' |
---|
2086 | cut((code_point ERTLptr |
---|
2087 | →joint_seq ERTLptr (prog_var_names (joint_function ERTL) ℕ prog))) [ cases daemon (*Paolo should fix the lemma*)] |
---|
2088 | #last_Instrs' |
---|
2089 | letin list_map ≝ cic:/matita/basics/lists/list/map.fix(0,3,1) |
---|
2090 | cut(∃st''.∃st'''.∃st''''. |
---|
2091 | repeat_eval_seq_no_pc (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2092 | f (translate_internal ? fn) (map_eval ?? pre_Instrs' dst) st = return st''' ∧ |
---|
2093 | eval_seq_no_pc ? (prog_var_names … (ertl_to_ertlptr prog)) (ev_genv … (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)) |
---|
2094 | f (translate_internal … fn) (last_Instrs' dst) st''' = return st'''' ∧ |
---|
2095 | st'' = (mk_state_pc (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2096 | st'''' (pc_of_point ERTLptr_semantics (pc_block (pc … st)) dst) |
---|
2097 | (last_pop … st)) ∧ |
---|
2098 | st' = sigma_state_pc ? good st'') |
---|
2099 | [ cases daemon (*to be generalized and TO be moved into an other lemma *)] |
---|
2100 | * #st'' * #st''' * #st'''' *** #REPEAT #EVAL_NO_PC_Last #EQst'' #EQst' %{st''} % [assumption] |
---|
2101 | lapply(produce_trace_any_any_free … REPEAT) |
---|
2102 | [ cases daemon (* Pass dependent *) |
---|
2103 | | cases daemon (* should be @Multi_fetch *) |
---|
2104 | | @(fetch_internal_function_transf … (λvars. translate_internal …) … EQfn) |
---|
2105 | | @dst |
---|
2106 | | @list_b_last (*wrong, should dst be destination or the last of list_b_last *) |
---|
2107 | ] #TAAF |
---|
2108 | lapply(produce_step_trace (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2109 | (mk_state_pc (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2110 | st''' (pc_of_point ERTLptr_semantics (pc_block (pc … st)) dst) |
---|
2111 | (last_pop … st)) f (translate_internal ? fn) (last_Instrs' dst) nxt st'''' (fetch_internal_function_transf … (λvars. translate_internal …) … EQfn) |
---|
2112 | ? EVAL_NO_PC_Last) [cases daemon (* should be @STEP_in_code *)] |
---|
2113 | #LAST_STEP |
---|
2114 | letin taaf_last ≝ (taaf_step ???? TAAF LAST_STEP) |
---|
2115 | |
---|
2116 | cut(dst = (point_of_pc |
---|
2117 | (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2118 | (pc … st))) [cases daemon (*TODO it is true since pre_Instr is empty *)] |
---|
2119 | #EQ <EQ whd in match step_in_code; normalize nodelta |
---|
2120 | cases STEP_in_code #x * #x_spec #x_spec' %{x} % |
---|
2121 | [ >x_spec in ⊢ (??%?); @eq_f @eq_f2 [2: %] cases daemon (*should be % *) | |
---|
2122 | [<EVAL_NO_PC_Last in ⊢ (???%); @eq_f % |
---|
2123 | |
---|
2124 | |
---|
2125 | |
---|
2126 | whd in match eval_state; normalize nodelta >EQfetch >m_return_bind |
---|
2127 | lapply EQfetch -EQfetch whd in match sigma_state_pc in ⊢ (% → ?); |
---|
2128 | normalize nodelta @if_elim |
---|
2129 | [ #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2130 | #EQbl inversion(fetch_internal_function ?? (pc_block (pc ? st))) normalize nodelta |
---|
2131 | [2: #err #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2132 | * #id1 #fn1 #EQfn normalize nodelta #EQfetch lapply(fetch_statement_inv … EQfetch) |
---|
2133 | * >EQfn #EQ destruct normalize nodelta #EQstmt |
---|
2134 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta @if_elim |
---|
2135 | [#H >H in EQbl; *] #_ >EQfn normalize nodelta whd in match eval_statement_no_pc; |
---|
2136 | normalize nodelta #H @('bind_inversion H) -H #ex_st_nopc |
---|
2137 | #H lapply (err_eq_from_io ????? H) -H #EQnopc whd in match eval_statement_advance; |
---|
2138 | normalize nodelta whd in match set_no_pc; normalize nodelta |
---|
2139 | whd in ⊢ (??%% → ?); #EQ destruct cases(eval_seq_no_pc_no_call_ok … EQnopc) |
---|
2140 | #sigma_st_nopc * #EQsigma_st_nopc #sem_rel % |
---|
2141 | [ % [@sigma_st_nopc |
---|
2142 | | @(succ_pc ERTL_semantics (pc ERTLptr_semantics st) nxt) |
---|
2143 | | @(last_pop … st) |
---|
2144 | ] |
---|
2145 | ] % whd in match sigma_state_pc; |
---|
2146 | |
---|
2147 | |
---|
2148 | |
---|
2149 | qed. |
---|
2150 | |
---|
2151 | lemma ertl_to_ertlptr_ok: |
---|
2152 | ∀prog. |
---|
2153 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2154 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
2155 | ∀stack_sizes. |
---|
2156 | ex_Type1 … (λR. |
---|
2157 | status_simulation |
---|
2158 | (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) R). |
---|
2159 | #prog #good #stack_size % [@ERTLptrStatusSimulation assumption] |
---|
2160 | whd in match status_simulation; normalize nodelta |
---|
2161 | whd in match ERTL_status; whd in match ERTLptr_status; normalize nodelta |
---|
2162 | whd in ⊢ (% → % → % → % → ?); #st1 #st1' #st2 |
---|
2163 | change with |
---|
2164 | (eval_state ERTL_semantics (prog_var_names ???) ?? = ? → ?) |
---|
2165 | #EQeval @('bind_inversion EQeval) |
---|
2166 | ** #id #fn #stmt #H lapply (err_eq_from_io ????? H) -H #EQfetch |
---|
2167 | #_ whd in match ERTLptrStatusSimulation; normalize nodelta #EQst2 destruct |
---|
2168 | cases stmt in EQfetch; -stmt |
---|
2169 | [ * [ #called_id #args #dest| #reg #lbl | #seq] #nxt | #fin_step | *] #EQfetch |
---|
2170 | change with (joint_classify ??) in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); |
---|
2171 | [ (*CALL*) cases daemon |
---|
2172 | | (*COND*) cases daemon |
---|
2173 | | (*seq*) whd in match joint_classify; normalize nodelta >EQfetch >m_return_bind |
---|
2174 | normalize nodelta cases (eval_seq_no_call_ok ????????? EQfetch EQeval) |
---|
2175 | #st3 * #EQ destruct * #taf #tafne %{st3} %{taf} >tafne normalize nodelta |
---|
2176 | % [% //] whd >as_label_ok [2:assumption] % |
---|
2177 | |
---|
2178 | |
---|
2179 | lapply(produce_trace_any_any_free |
---|
2180 | (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2181 | st2 id (translate_internal ? fn)) #PRODUCE_TAAF |
---|
2182 | cases stmt in EQfetch; -stmt |
---|
2183 | [ * [ #called_id #args #dest| #reg #lbl | #seq] #nxt | #fin_step | *] #EQfetch |
---|
2184 | normalize nodelta |
---|
2185 | |
---|
2186 | |
---|
2187 | lapply EQfetch -EQfetch whd in match sigma_state_pc in ⊢ (% → ?); |
---|
2188 | normalize nodelta @if_elim |
---|
2189 | [ #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2190 | #EQbl inversion(fetch_internal_function ?? (pc_block (pc ? st2))) normalize nodelta |
---|
2191 | [2: #err #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2192 | * #id1 #fn1 #EQfn normalize nodelta #EQfetch lapply(fetch_statement_inv … EQfetch) |
---|
2193 | * >EQfn #EQ destruct normalize nodelta #EQstmt |
---|
2194 | |
---|
2195 | ? ? ?? ? ???) |
---|
2196 | |
---|
2197 | |
---|
2198 | |
---|
2199 | cases stmt in EQfetch; -stmt |
---|
2200 | [ * [ #called_id #args #dest| #reg #lbl | #seq] #nxt | #fin_step | *] #EQstmt |
---|
2201 | change with (joint_classify ??) in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); |
---|
2202 | whd in match joint_classify; normalize nodelta >EQstmt >m_return_bind |
---|
2203 | normalize nodelta lapply(fetch_statement_inv … EQstmt) * #fn_spec |
---|
2204 | #stmt_spec |
---|
2205 | cases(multi_fetch_ok … (good fn) ?? stmt_spec) #f_labs * #f_regs ** #f_labs_spec |
---|
2206 | #f_regs_spec normalize nodelta * #list_instr * #b_new_f_regs |
---|
2207 | whd in ⊢ (% → ?); normalize nodelta |
---|
2208 | [1,2,3: @pair_elim #list_instr1 #rgt #last_ne_spec * #last_lab * |
---|
2209 | #list_instr1_spec #last_step |
---|
2210 | lapply(fetch_internal_function_transf … |
---|
2211 | (λvars. translate_internal …) … fn_spec) |
---|
2212 | change with ((fetch_internal_function |
---|
2213 | (joint_closed_internal_function ? (prog_var_names … (ertl_to_ertlptr prog))) |
---|
2214 | (globalenv_noinit … (ertl_to_ertlptr prog)) ?) = ? → ?) |
---|
2215 | #EQtrans_fn |
---|
2216 | check prog_params |
---|
2217 | lapply(produce_trace_any_any_free |
---|
2218 | (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size) |
---|
2219 | ? id (translate_internal ? fn) ? ? ?? EQtrans_fn ???) [2: @EQtrans_fn |
---|
2220 | |
---|
2221 | |
---|
2222 | |
---|
2223 | |
---|
2224 | |
---|
2225 | lapply EQstmt whd in match sigma_state_pc in ⊢ (% → ?); |
---|
2226 | normalize nodelta @if_elim |
---|
2227 | [1,3: #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2228 | #EQbl inversion(fetch_internal_function ?? (pc_block (pc ? st2))) normalize nodelta |
---|
2229 | [2,4: #err #_ >fetch_statement_no_zero [2,4: %] whd in ⊢ (???% → ?); #ABS destruct] |
---|
2230 | * #id1 #fn1 #EQfn1 normalize nodelta #EQstmt1 lapply(fetch_statement_inv … EQstmt1) |
---|
2231 | * >EQfn1 #EQ destruct normalize nodelta #EQstmtat |
---|
2232 | |
---|
2233 | |
---|
2234 | |
---|
2235 | |
---|
2236 | [ (*CALL*) |
---|
2237 | cases daemon (*TODO*) |
---|
2238 | | whd in match joint_classify; normalize nodelta |
---|
2239 | >EQfetch in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); |
---|
2240 | normalize nodelta |
---|
2241 | #n_cost |
---|
2242 | cases (eval_cond_ok … EQfetch EQeval n_cost) |
---|
2243 | #st3 * #EQ destruct * #taf #tafne %{st3} %{taf} |
---|
2244 | % [ % [2: %] >tafne normalize nodelta @I] whd >as_label_ok % |
---|
2245 | | whd in match joint_classify; normalize nodelta |
---|
2246 | >EQfetch in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); |
---|
2247 | normalize nodelta |
---|
2248 | cases (eval_seq_no_call_ok ????????? EQfetch EQeval) |
---|
2249 | #st3 * #EQ destruct * #taf #tafne %{st3} %{taf} >tafne normalize nodelta |
---|
2250 | % [% //] whd >as_label_ok [2:assumption] % |
---|
2251 | | (*FIN*) |
---|
2252 | cases fin_step in EQfetch; |
---|
2253 | [ (*GOTO*) #lbl #EQfetch whd in match joint_classify; normalize nodelta |
---|
2254 | >EQfetch in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); normalize nodelta |
---|
2255 | cases (eval_goto_ok … EQfetch EQeval) |
---|
2256 | #st3 * #EQ destruct * #taf #tarne %{st3} %{taf} >tarne normalize nodelta |
---|
2257 | % [% //] whd >as_label_ok [2:assumption] % |
---|
2258 | | (*RETURN*) #EQfetch |
---|
2259 | whd in match joint_classify; normalize nodelta |
---|
2260 | >EQfetch in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]); normalize nodelta |
---|
2261 | cases (eval_return_ok … EQfetch EQeval) #is_ret |
---|
2262 | * #st3 * #EQ destruct * #after_ret * #taf ** #taf_prf #EQeval' #ret_prf |
---|
2263 | % [2: % [2: % [2: %{(taa_base …)} %{taf}] |*: ] |*:] |
---|
2264 | % [2: whd >as_label_ok %] % [2: assumption] % [2: %] % [2: assumption] |
---|
2265 | % assumption |
---|
2266 | | (*TAILCALL*) #fl #called #args #EQfetch |
---|
2267 | cases (eval_tailcall_ok … EQfetch EQeval) #st3 * #EQ destruct * #is_tailcall |
---|
2268 | * #is_tailcall' * #eq_call #EQeval' >is_tailcall normalize nodelta |
---|
2269 | #prf %{«?, is_tailcall'»} %{eq_call} |
---|
2270 | % [2: % [2: %{(taa_base …)} %{(taa_base …)} % [ %{EQeval'} % |] | ] | ] |
---|
2271 | whd >as_label_ok % |
---|
2272 | ] |
---|
2273 | ] |
---|
2274 | qed. |
---|
2275 | |
---|
2276 | @('bind_inversion EQfetch) * #id1 #fn1 #EQfn #H @('bind_inversion H) -H |
---|
2277 | #stmt1 #H lapply(opt_eq_from_res ???? H) -H #EQstmt whd in ⊢ (??%% → ?); |
---|
2278 | #EQ destruct |
---|
2279 | |
---|
2280 | (* |
---|
2281 | lemma push_ra_ok : ∀prog : ertl_program. |
---|
2282 | ∀good : (∀fn.good_state_transformation prog fn).∀restr. |
---|
2283 | preserving21 … res_preserve1 … |
---|
2284 | (sigma_state_pc prog good) |
---|
2285 | (\l |
---|
2286 | (λst.sigma_state prog good st restr) |
---|
2287 | (push_ra ERTL_semantics) |
---|
2288 | (push_ra ERTLptr_semantics). |
---|
2289 | #prog #good #restr #st #pc whd in match push_ra; normalize nodelta @mfr_bind1 |
---|
2290 | [2: whd in match sigma_stored_pc; normalize nodelta |
---|
2291 | |
---|
2292 | [2: #x |
---|
2293 | |
---|
2294 | |
---|
2295 | lemma ertlptr_save_frame_ok : ∀prog : ertl_program. |
---|
2296 | ∀good : (∀fn.good_state_transformation prog fn). |
---|
2297 | ∀id. |
---|
2298 | preserving1 … res_preserve1 … |
---|
2299 | (sigma_state_pc prog good) |
---|
2300 | (λst. match get_internal_function_from_ident |
---|
2301 | ERTL_semantics (prog_var_names … prog) |
---|
2302 | (globalenv_noinit … prog) id with |
---|
2303 | [None ⇒ dummy_state |
---|
2304 | |Some fd ⇒ |
---|
2305 | sigma_state prog good st (added_registers … fd (f_regs … (good fd))) |
---|
2306 | ]) |
---|
2307 | (ertl_save_frame ID it id) |
---|
2308 | (ertlptr_save_frame ID it id). |
---|
2309 | #prog #good #id #st whd in match ertl_save_frame; whd in match ertlptr_save_frame; |
---|
2310 | normalize nodelta @mfr_bind1 |
---|
2311 | [2: whd in match push_ra; normalize nodelta @mfr_bind1 |
---|
2312 | xxxxxxxxxxxx |
---|
2313 | |
---|
2314 | |
---|
2315 | |
---|
2316 | lemma fetch_statement_commute : |
---|
2317 | ∀prog : ertl_program. |
---|
2318 | let trans_prog ≝ (ertl_to_ertlptr prog) in |
---|
2319 | ∀sigma : sigma_map trans_prog. |
---|
2320 | ∀stack_sizes,id,fn,stmt,pc. |
---|
2321 | fetch_statement ERTL_semantics |
---|
2322 | (globals (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2323 | (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2324 | pc = return 〈id,fn,stmt〉 → |
---|
2325 | match stmt with |
---|
2326 | [ sequential seq nxt ⇒ |
---|
2327 | match seq with |
---|
2328 | [ CALL ids args dest ⇒ |
---|
2329 | match ids with |
---|
2330 | [ inl i ⇒ |
---|
2331 | fetch_statement ERTLptr_semantics |
---|
2332 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2333 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2334 | pc = |
---|
2335 | return 〈id, |
---|
2336 | translate_internal … fn, |
---|
2337 | sequential ?? (CALL ERTLptr ? (inl ?? i) args dest) nxt〉 |
---|
2338 | | inr p ⇒ ?(* |
---|
2339 | ∃reg,lbl. |
---|
2340 | fetch_statement ERTLptr_semantics |
---|
2341 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2342 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2343 | pc = return 〈id,translate_internal … fn,sequential ?? (extension_seq ERTLptr ? (LOW_ADDRESS reg lbl)) nxt〉 |
---|
2344 | ∧ ∃ nxt'. |
---|
2345 | ! pc' ← get_pc_from_label ? ? (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2346 | id nxt; |
---|
2347 | fetch_statement ERTLptr_semantics |
---|
2348 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2349 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2350 | pc' = return 〈id,translate_internal … fn,sequential ?? (step_seq ERTLptr ? (PUSH … (Reg … reg))) nxt'〉 |
---|
2351 | ∧ ∃ nxt''. |
---|
2352 | ! pc' ← get_pc_from_label ? ? (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2353 | id nxt'; |
---|
2354 | fetch_statement ERTLptr_semantics |
---|
2355 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2356 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2357 | pc' = return 〈id,translate_internal … fn,sequential ?? (extension_seq ERTLptr ? (HIGH_ADDRESS reg lbl)) nxt''〉 |
---|
2358 | ∧ ∃ nxt'''. |
---|
2359 | ! pc' ← get_pc_from_label ? ? (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2360 | id nxt''; |
---|
2361 | fetch_statement ERTLptr_semantics |
---|
2362 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2363 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2364 | pc' = return 〈id,translate_internal … fn,sequential ?? (step_seq ERTLptr ? (PUSH … (Reg … reg))) nxt'''〉 |
---|
2365 | ∧ ∃ nxt''''. |
---|
2366 | ! pc' ← get_pc_from_label ? ? (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2367 | id nxt'''; |
---|
2368 | fetch_statement ERTLptr_semantics |
---|
2369 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2370 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2371 | pc' = return 〈id,translate_internal … fn,sequential ?? (CALL ERTLptr ? (inr ?? p) args dest) nxt''''〉 |
---|
2372 | ∧ sigma (translate_internal … fn) nxt''' = return point_of_pc ERTL_semantics pc *) |
---|
2373 | ] |
---|
2374 | | COND r lbl ⇒ |
---|
2375 | fetch_statement ERTLptr_semantics |
---|
2376 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2377 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2378 | pc = |
---|
2379 | return 〈id, |
---|
2380 | translate_internal … fn, |
---|
2381 | sequential ?? (COND ERTLptr ? r lbl) nxt〉 |
---|
2382 | | step_seq s ⇒ |
---|
2383 | fetch_statement ERTLptr_semantics |
---|
2384 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2385 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2386 | pc = |
---|
2387 | return 〈id, |
---|
2388 | translate_internal … fn, |
---|
2389 | sequential ?? (step_seq ERTLptr … (translate_step_seq ? s)) nxt〉 |
---|
2390 | ] |
---|
2391 | | final fin ⇒ |
---|
2392 | fetch_statement ERTLptr_semantics |
---|
2393 | (globals (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2394 | (ev_genv (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2395 | pc = return 〈id,(translate_internal … fn),final … (joint_fin_step_id fin)〉 |
---|
2396 | | FCOND abs _ _ _ ⇒ Ⓧabs |
---|
2397 | ]. |
---|
2398 | cases daemon |
---|
2399 | qed. |
---|
2400 | |
---|
2401 | lemma eval_seq_no_call_ok : |
---|
2402 | ∀prog. |
---|
2403 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2404 | ∀sigma : sigma_map trans_prog.∀stack_sizes. |
---|
2405 | (*? →*) |
---|
2406 | ∀st,st',f,fn,stmt,nxt. |
---|
2407 | fetch_statement ERTL_semantics |
---|
2408 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2409 | (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2410 | (pc … (sigma_state_pc ? sigma st)) = |
---|
2411 | return 〈f, fn, sequential … (step_seq ERTL … stmt) nxt〉 → |
---|
2412 | eval_state ERTL_semantics |
---|
2413 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2414 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2415 | (sigma_state_pc ? sigma st) = |
---|
2416 | return st' → |
---|
2417 | ∃st''. st' = sigma_state_pc ? sigma st'' ∧ |
---|
2418 | ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) |
---|
2419 | st |
---|
2420 | st''. |
---|
2421 | bool_to_Prop (taaf_non_empty … taf). |
---|
2422 | #prog #sigma #stack_size #st1 #st2 #f #fn #stmt #nxt #EQf whd in match eval_state; |
---|
2423 | normalize nodelta >EQf >m_return_bind whd in match eval_statement_advance; |
---|
2424 | whd in match eval_statement_no_pc; normalize nodelta |
---|
2425 | #H @('bind_inversion H) -H #st_no_pc #EQ lapply(err_eq_from_io ????? EQ) -EQ |
---|
2426 | #EQeval whd in ⊢ (??%% → ?); #EQ destruct lapply EQf |
---|
2427 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta @if_elim |
---|
2428 | [ #EQbl |
---|
2429 | | #pc_st1_spec inversion(fetch_internal_function ???) [2: #e #_] |
---|
2430 | ] |
---|
2431 | [1,2: whd in match dummy_state_pc; whd in match null_pc; |
---|
2432 | whd in match fetch_statement; normalize nodelta whd in match fetch_internal_function; |
---|
2433 | normalize nodelta lapply(fetch_function_no_zero ??????) |
---|
2434 | [2,9: @( «mk_block Code OZ,refl region Code») |
---|
2435 | |1,8: % |3,10: @prog |7,14: #EQ >EQ |*:] whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2436 | * #f1 #fn1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fn1_spec normalize nodelta |
---|
2437 | whd in match fetch_statement; normalize nodelta >fn1_spec |
---|
2438 | >m_return_bind #H @('bind_inversion H) -H #stmt1 #EQ |
---|
2439 | lapply(opt_eq_from_res ???? EQ) -EQ #stmt1_spec whd in ⊢ (??%% → ?); #EQ destruct |
---|
2440 | lapply EQeval -EQeval whd in match sigma_state_pc in ⊢ (% → ?); |
---|
2441 | normalize nodelta @if_elim [#H >H in pc_st1_spec; *] #_ >fn1_spec |
---|
2442 | normalize nodelta #EQeval cases(eval_seq_no_pc_no_call_ok ???????? EQeval) |
---|
2443 | #st_no_pc' * #EQeval' #EQst_no_pc' |
---|
2444 | whd in match set_no_pc; normalize nodelta |
---|
2445 | % [ % [@st_no_pc'|@(succ_pc ERTL_semantics (pc ERTL_semantics (sigma_state_pc prog sigma st1)) |
---|
2446 | nxt)| @(last_pop ? st1)]] |
---|
2447 | % [ whd in match sigma_state_pc; normalize nodelta |
---|
2448 | @if_elim [#H >H in pc_st1_spec; *] #_ >fn1_spec normalize nodelta |
---|
2449 | @if_elim [#H >H in pc_st1_spec; *] #_ >fn1_spec normalize nodelta |
---|
2450 | >EQst_no_pc' %] |
---|
2451 | %{(taaf_step … (taa_base …) …)} |
---|
2452 | [3: //] lapply(fetch_statement_commute ? sigma ????? EQf) normalize nodelta |
---|
2453 | whd in match sigma_state_pc; normalize nodelta |
---|
2454 | @if_elim [1,3:#H >H in pc_st1_spec; *] #_ >fn1_spec normalize nodelta |
---|
2455 | #EQf1 |
---|
2456 | [ whd in match as_classifier; normalize nodelta whd in match (as_classify ??); |
---|
2457 | >EQf1 normalize nodelta % |
---|
2458 | | whd in match (as_execute ???); whd in match eval_state; normalize nodelta |
---|
2459 | >EQf1 >m_return_bind whd in match eval_statement_no_pc; normalize nodelta |
---|
2460 | >EQeval' >m_return_bind % |
---|
2461 | ] |
---|
2462 | qed. |
---|
2463 | |
---|
2464 | |
---|
2465 | lemma eval_goto_ok : |
---|
2466 | ∀prog : ertl_program. |
---|
2467 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2468 | ∀stack_sizes. |
---|
2469 | ∀sigma : sigma_map trans_prog. |
---|
2470 | ∀st,st',f,fn,nxt. |
---|
2471 | fetch_statement ERTL_semantics … |
---|
2472 | (globalenv_noinit ? prog) (pc … (sigma_state_pc ? sigma st)) = |
---|
2473 | return 〈f, fn, final … (GOTO ERTL … nxt)〉 → |
---|
2474 | eval_state ERTL_semantics |
---|
2475 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2476 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2477 | (sigma_state_pc ? sigma st) = |
---|
2478 | return st' → |
---|
2479 | ∃ st''. st' = sigma_state_pc ? sigma st'' ∧ |
---|
2480 | ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) |
---|
2481 | st |
---|
2482 | st''. |
---|
2483 | bool_to_Prop (taaf_non_empty … taf). |
---|
2484 | #prog #stack_sizes #sigma #st #st' #f #fn #nxt |
---|
2485 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2486 | @if_elim |
---|
2487 | [ #EQbl whd in match dummy_state_pc; whd in match null_pc; |
---|
2488 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2489 | normalize nodelta lapply(fetch_function_no_zero ??????) |
---|
2490 | [2: @( «mk_block Code OZ,refl region Code») |
---|
2491 | | % | @prog |7: #EQ >EQ |*:] whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2492 | #Hbl inversion(fetch_internal_function ???) |
---|
2493 | [2: #e #_ normalize nodelta whd in match dummy_state_pc; whd in match null_pc; |
---|
2494 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2495 | normalize nodelta lapply(fetch_function_no_zero ??????) |
---|
2496 | [2: @( «mk_block Code OZ,refl region Code») |
---|
2497 | | % | @prog |7: #EQ >EQ |*:] whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2498 | * #f1 #fn1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fn1_spec normalize nodelta |
---|
2499 | #EQf lapply EQf whd in match fetch_statement; normalize nodelta >fn1_spec |
---|
2500 | >m_return_bind #H @('bind_inversion H) -H #stmt' #_ whd in ⊢ (??%% → ?); |
---|
2501 | #EQ destruct whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2502 | @if_elim [#H >H in Hbl; *] #_ >fn1_spec normalize nodelta whd in match eval_state; |
---|
2503 | normalize nodelta >EQf >m_return_bind whd in match eval_statement_advance; |
---|
2504 | whd in match eval_statement_no_pc; normalize nodelta >m_return_bind |
---|
2505 | whd in match goto; normalize nodelta #H lapply (err_eq_from_io ????? H) -H |
---|
2506 | #H @('bind_inversion H) -H #pc' whd in match set_no_pc; normalize nodelta |
---|
2507 | >(pc_of_label_eq … fn1_spec) whd in ⊢ (???% → ?); #EQ whd in ⊢ (??%% → ?); #EQ1 |
---|
2508 | destruct lapply (fetch_statement_commute … sigma … stack_sizes … EQf) |
---|
2509 | normalize nodelta #EQf' % |
---|
2510 | [ % [ @st |
---|
2511 | | @(mk_program_counter |
---|
2512 | (pc_block (pc ERTLptr_semantics st)) |
---|
2513 | (offset_of_point ERTL_semantics nxt)) |
---|
2514 | | @(last_pop … st) |
---|
2515 | ] |
---|
2516 | ] % |
---|
2517 | [ whd in match sigma_state_pc; normalize nodelta @if_elim [#H >H in Hbl; *] |
---|
2518 | >fn1_spec normalize nodelta #_ % ] |
---|
2519 | %{(taaf_step … (taa_base …) …)} |
---|
2520 | [ whd in match as_classifier; normalize nodelta whd in match (as_classify ??); |
---|
2521 | >EQf' normalize nodelta % |
---|
2522 | | whd in match (as_execute ???); whd in match eval_state; normalize nodelta |
---|
2523 | >EQf' >m_return_bind whd in match eval_statement_no_pc; |
---|
2524 | whd in match eval_statement_advance; normalize nodelta >m_return_bind |
---|
2525 | whd in match goto; normalize nodelta whd in match pc_of_label; normalize nodelta |
---|
2526 | lapply(fetch_internal_function_transf ??????? fn1_spec) |
---|
2527 | [ #vars @translate_internal |] #EQ >EQ >m_return_bind % |
---|
2528 | | % |
---|
2529 | ] |
---|
2530 | qed. |
---|
2531 | *) |
---|
2532 | |
---|
2533 | |
---|
2534 | |
---|
2535 | |
---|
2536 | |
---|
2537 | lemma eval_return_ok : |
---|
2538 | ∀prog : ertl_program. |
---|
2539 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2540 | ∀stack_sizes. |
---|
2541 | ∀sigma : sigma_map trans_prog. |
---|
2542 | ∀st,st',f,fn. |
---|
2543 | fetch_statement ERTL_semantics … |
---|
2544 | (globalenv_noinit ? prog) (pc … (sigma_state_pc ? sigma st)) = |
---|
2545 | return 〈f, fn, final … (RETURN ERTL … )〉 → |
---|
2546 | eval_state ERTL_semantics |
---|
2547 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2548 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2549 | (sigma_state_pc ? sigma st) = |
---|
2550 | return st' → |
---|
2551 | joint_classify (mk_prog_params ERTLptr_semantics trans_prog stack_sizes) |
---|
2552 | st = Some ? cl_return ∧ |
---|
2553 | ∃ st''. st' = sigma_state_pc ? sigma st'' ∧ |
---|
2554 | ∃st2_after_ret. |
---|
2555 | ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) |
---|
2556 | st2_after_ret |
---|
2557 | st''. |
---|
2558 | (if taaf_non_empty … taf then |
---|
2559 | ¬as_costed (ERTLptr_status trans_prog stack_sizes) |
---|
2560 | st2_after_ret |
---|
2561 | else True) ∧ |
---|
2562 | eval_state … (ev_genv … (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) st = |
---|
2563 | return st2_after_ret ∧ |
---|
2564 | ret_rel ?? (ERTLptrStatusSimulation prog stack_sizes sigma) st' st2_after_ret. |
---|
2565 | #prog #stack_size #sigma #st #st' #f #fn |
---|
2566 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2567 | @if_elim |
---|
2568 | [ #EQbl whd in match dummy_state_pc; whd in match null_pc; |
---|
2569 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2570 | normalize nodelta >(fetch_function_no_zero ??????) [2: %] |
---|
2571 | whd in ⊢ (??%% → ?); #EQ destruct ] |
---|
2572 | #Hbl inversion(fetch_internal_function ???) |
---|
2573 | [2: #e #_ normalize nodelta whd in match dummy_state_pc; whd in match null_pc; |
---|
2574 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2575 | normalize nodelta lapply(fetch_function_no_zero ??????) |
---|
2576 | [2: @( «mk_block Code OZ,refl region Code») |
---|
2577 | | % | @prog |7: #EQ >EQ |*:] whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2578 | * #f1 #fn1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fn1_spec normalize nodelta |
---|
2579 | #EQf lapply EQf whd in match fetch_statement; normalize nodelta >fn1_spec |
---|
2580 | >m_return_bind #H @('bind_inversion H) -H #stmt' #_ whd in ⊢ (??%% → ?); |
---|
2581 | #EQ destruct whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2582 | @if_elim [#H >H in Hbl; *] #_ >fn1_spec normalize nodelta |
---|
2583 | whd in match eval_state; normalize nodelta >EQf >m_return_bind |
---|
2584 | whd in match eval_statement_no_pc; whd in match eval_statement_advance; |
---|
2585 | normalize nodelta >m_return_bind |
---|
2586 | #H lapply (err_eq_from_io ????? H) -H #H @('bind_inversion H) -H |
---|
2587 | * #st1 #pc1 #EQpop whd in match next_of_call_pc; normalize nodelta |
---|
2588 | >m_bind_bind #H @('bind_inversion H) -H ** #f1 #fn1 * normalize nodelta |
---|
2589 | [ * [ #c_id #args #dest | #r #lbl | #seq ] #nxt | #fin | * ] |
---|
2590 | #EQf1 normalize nodelta [2,3,4: whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2591 | >m_return_bind whd in ⊢ (??%% → ?); #EQ destruct |
---|
2592 | lapply (fetch_statement_commute prog sigma stack_size … EQf) |
---|
2593 | normalize nodelta #EQf' |
---|
2594 | % [ whd in match joint_classify; normalize nodelta >EQf' >m_return_bind %] |
---|
2595 | change with (pop_ra ?? = ?) in EQpop; whd in match set_no_pc in EQpop; |
---|
2596 | normalize nodelta in EQpop; |
---|
2597 | cases(pop_ra_ok ? sigma stack_size fn ?? EQpop) * #st3 #pc3 * #st3_spec |
---|
2598 | normalize nodelta #EQ destruct whd in match set_last_pop; whd in match succ_pc; |
---|
2599 | normalize nodelta whd in match (point_of_succ ???); |
---|
2600 | % [ % [ @st3 | @(pc_of_point ERTL_semantics (pc_block … pc3) nxt) | @pc3] ] |
---|
2601 | % [ @('bind_inversion EQf1) * #f3 #fn3 whd in match sigma_stored_pc; |
---|
2602 | normalize nodelta inversion(sigma_pc_opt ???) normalize nodelta |
---|
2603 | [ #_ #H @('bind_inversion H) -H #x whd in match null_pc; normalize nodelta |
---|
2604 | >fetch_function_no_zero [2: %] whd in ⊢ (???% → ?); #EQ destruct |
---|
2605 | | #pc4 whd in match sigma_pc_opt; normalize nodelta @if_elim |
---|
2606 | [ #bl3_spec @('bind_inversion EQf1) #x #H @('bind_inversion H) -H |
---|
2607 | #x1 >fetch_function_no_minus_one [ whd in ⊢ (???% → ?); #EQ destruct] |
---|
2608 | lapply bl3_spec @eqZb_elim #EQ * whd in match sigma_stored_pc; |
---|
2609 | normalize nodelta whd in match sigma_pc_opt; normalize nodelta |
---|
2610 | >bl3_spec normalize nodelta assumption |
---|
2611 | | #bl3_spec #H @('bind_inversion H) -H * #id4 #fn4 |
---|
2612 | #H lapply(res_eq_from_opt ??? H) -H #fn4_spec |
---|
2613 | #H @('bind_inversion H) -H #lbl4 #lbl4_spec whd in ⊢ (??%? → ?); #EQ |
---|
2614 | destruct #fn3_spec #H @('bind_inversion H) -H #stmt1 #_ |
---|
2615 | whd in ⊢ (??%% → ?); #EQ destruct |
---|
2616 | >(fetch_internal_function_transf … fn3_spec) in fn4_spec; |
---|
2617 | whd in ⊢ (??%% → ?); #EQ destruct |
---|
2618 | ] |
---|
2619 | ] |
---|
2620 | whd in match sigma_state_pc; normalize nodelta @if_elim |
---|
2621 | [ >(pc_block_eq prog sigma ????) in bl3_spec; |
---|
2622 | [2: >lbl4_spec % #ABS destruct |
---|
2623 | |3: >(fetch_internal_function_transf … fn3_spec) % |*:] |
---|
2624 | #bl3_spec whd in match pc_of_point; normalize nodelta #EQ >EQ in bl3_spec; * |
---|
2625 | | #_ cases daemon |
---|
2626 | ] |
---|
2627 | ] cases daemon |
---|
2628 | qed. |
---|
2629 | |
---|
2630 | (* |
---|
2631 | lemma ertl_allocate_local_ok : ∀ prog : ertl_program. |
---|
2632 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2633 | ∀sigma : sigma_map. |
---|
2634 | ∀stack_size. |
---|
2635 | ∀id,regs. |
---|
2636 | ertl_allocate_local id (sigma_regs ? sigma getLocalsFromId( |
---|
2637 | *) |
---|
2638 | |
---|
2639 | lemma eval_tailcall_ok : |
---|
2640 | ∀prog. |
---|
2641 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2642 | ∀stack_sizes. |
---|
2643 | ∀sigma : sigma_map trans_prog. |
---|
2644 | ∀st,st',f,fn,fl,called,args. |
---|
2645 | fetch_statement ERTL_semantics … |
---|
2646 | (globalenv_noinit ? prog) (pc … (sigma_state_pc ? sigma st)) = |
---|
2647 | return 〈f, fn, final … (TAILCALL ERTL … fl called args)〉 → |
---|
2648 | eval_state ERTL_semantics |
---|
2649 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2650 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2651 | (sigma_state_pc ? sigma st) = |
---|
2652 | return st' → |
---|
2653 | ∃ st''. st' = sigma_state_pc ? sigma st'' ∧ |
---|
2654 | ∃is_tailcall, is_tailcall'. |
---|
2655 | joint_tailcall_ident (mk_prog_params ERTLptr_semantics trans_prog stack_sizes) «st, is_tailcall'» = |
---|
2656 | joint_tailcall_ident (mk_prog_params ERTL_semantics prog stack_sizes) «(sigma_state_pc ? sigma st), is_tailcall» ∧ |
---|
2657 | eval_state … (ev_genv … (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) |
---|
2658 | st = return st''. |
---|
2659 | #prog #stack_size #sigma #st #st' #f #fn #fl #called #args |
---|
2660 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2661 | @if_elim |
---|
2662 | [ #EQbl whd in match dummy_state_pc; whd in match null_pc; |
---|
2663 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2664 | normalize nodelta >(fetch_function_no_zero ??????) [2: %] |
---|
2665 | whd in ⊢ (??%% → ?); #EQ destruct ] |
---|
2666 | #Hbl inversion(fetch_internal_function ???) |
---|
2667 | [2: #e #_ normalize nodelta whd in match dummy_state_pc; whd in match null_pc; |
---|
2668 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2669 | normalize nodelta lapply(fetch_function_no_zero ??????) |
---|
2670 | [2: @( «mk_block Code OZ,refl region Code») |
---|
2671 | | % | @prog |7: #EQ >EQ |*:] whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2672 | * #f1 #fn1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fn1_spec normalize nodelta |
---|
2673 | #EQf lapply EQf whd in match fetch_statement; normalize nodelta >fn1_spec |
---|
2674 | >m_return_bind #H @('bind_inversion H) -H #stmt' #_ whd in ⊢ (??%% → ?); |
---|
2675 | #EQ destruct whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2676 | @if_elim [#H >H in Hbl; *] #_ >fn1_spec normalize nodelta |
---|
2677 | whd in match eval_state; normalize nodelta >EQf >m_return_bind |
---|
2678 | whd in match eval_statement_no_pc; whd in match eval_statement_advance; |
---|
2679 | normalize nodelta >m_return_bind whd in match eval_tailcall; |
---|
2680 | normalize nodelta #H @('bind_inversion H) -H #bl whd in match set_no_pc; |
---|
2681 | normalize nodelta #bl_spec #H @('bind_inversion H) -H * #id1 * [#int_f | #ext_f] |
---|
2682 | #H lapply(err_eq_from_io ????? H) -H #id1_spec normalize nodelta |
---|
2683 | [2: #H @('bind_inversion H) -H #st1 whd in match eval_external_call; normalize nodelta |
---|
2684 | #H @('bind_inversion H) -H #l_val #_ #H @('bind_inversion H) -H #le #_ |
---|
2685 | #H @('bind_inversion H) -H #x whd in match do_io; normalize nodelta |
---|
2686 | whd in ⊢ (???% → ?); #EQ destruct ] |
---|
2687 | #H lapply(err_eq_from_io ????? H) -H #H @('bind_inversion H) -H #st1 |
---|
2688 | whd in match eval_internal_call; normalize nodelta whd in match (stack_sizes ????); |
---|
2689 | #H @('bind_inversion H) -H #n #H lapply(opt_eq_from_res ???? H) -H #n_spec |
---|
2690 | whd in match(setup_call ???????); >m_return_bind |
---|
2691 | whd in ⊢ (??%% → ?); #EQ destruct whd in match sigma_state in ⊢ (% → ?); |
---|
2692 | normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct |
---|
2693 | % [ % |
---|
2694 | [ % |
---|
2695 | [ @(st_frms ERTLptr_semantics st) |
---|
2696 | | @(istack ERTLptr_semantics st) |
---|
2697 | | @(carry ERTLptr_semantics st) |
---|
2698 | | cases daemon |
---|
2699 | | @(m ERTLptr_semantics st) |
---|
2700 | ] |
---|
2701 | | @(mk_program_counter bl |
---|
2702 | (offset_of_point ERTL_semantics |
---|
2703 | (joint_if_entry ERTL_semantics |
---|
2704 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) int_f))) |
---|
2705 | | @(last_pop ERTLptr_semantics st) |
---|
2706 | ] |
---|
2707 | ] |
---|
2708 | % [ whd in match sigma_state_pc; normalize nodelta @if_elim whd in match pc_of_point; |
---|
2709 | normalize nodelta |
---|
2710 | [ #Hbl >fetch_function_no_minus_one in id1_spec; |
---|
2711 | [2: lapply Hbl @eqZb_elim -Hbl #Hbl * @Hbl] whd in ⊢ (???% → ?); |
---|
2712 | #EQ destruct(EQ) |
---|
2713 | ] #_ whd in match fetch_internal_function; normalize nodelta >id1_spec |
---|
2714 | >m_return_bind normalize nodelta cases daemon (*TO BE COmpleted *) |
---|
2715 | ] cases daemon (*TO BE COMPLETED*) |
---|
2716 | qed. |
---|
2717 | |
---|
2718 | |
---|
2719 | |
---|
2720 | |
---|
2721 | lemma as_label_ok : ∀ prog : ertl_program. |
---|
2722 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2723 | ∀ sigma : sigma_map trans_prog. |
---|
2724 | ∀stack_sizes. |
---|
2725 | ∀ st. |
---|
2726 | as_label (ERTLptr_status trans_prog stack_sizes) st = as_label |
---|
2727 | (ERTL_status prog stack_sizes) (sigma_state_pc prog sigma st). |
---|
2728 | #prog #sigma #stack_size * #st #pc #lp |
---|
2729 | whd in match as_label; normalize nodelta whd in match (as_pc_of ??) in ⊢ (??%%); |
---|
2730 | whd in match (as_label_of_pc ??) in ⊢ (??%%); |
---|
2731 | |
---|
2732 | |
---|
2733 | (* |
---|
2734 | |
---|
2735 | whd in match fetch_statement; normalize nodelta |
---|
2736 | whd in match sigma_state_pc; normalize nodelta @if_elim |
---|
2737 | [ #EQbl whd in match fetch_internal_function; normalize nodelta >m_bind_bind |
---|
2738 | lapply(fetch_function_no_minus_one ??????) [2: @(pc_block pc) | lapply EQbl |
---|
2739 | @eqZb_elim #H * @H| @(ertl_to_ertlptr prog) |7: #EQ >EQ |*:] normalize nodelta |
---|
2740 | whd in match dummy_state_pc; whd in match (as_label_of_pc ??); whd in match null_pc; |
---|
2741 | whd in match fetch_statement; normalize nodelta whd in match fetch_internal_function; |
---|
2742 | normalize nodelta >m_bind_bind |
---|
2743 | lapply(fetch_function_no_zero ??????) [2: @( «mk_block Code OZ,refl region Code») |
---|
2744 | | % | @prog |7: #EQ >EQ |*:] % |
---|
2745 | | inversion ( fetch_internal_function |
---|
2746 | (joint_closed_internal_function ERTL |
---|
2747 | (prog_var_names (joint_function ERTL) ℕ prog)) |
---|
2748 | (globalenv_noinit (joint_function ERTL) prog) (pc_block pc)) |
---|
2749 | [ * #id #fn #fn_spec #_ lapply(fetch_internal_function_transf ??????? fn_spec) |
---|
2750 | [ @(λvars,fn.translate_internal … fn) |] #EQ >EQ >m_return_bind normalize nodelta |
---|
2751 | whd in match (as_label_of_pc ??); |
---|
2752 | whd in match fetch_statement; normalize nodelta >fn_spec >m_return_bind |
---|
2753 | cases daemon (*serve specifica su sigma TODO*) |
---|
2754 | | #err #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fetch_err #_ normalize nodelta |
---|
2755 | whd in match dummy_state_pc; |
---|
2756 | whd in match (as_label_of_pc ??); whd in match null_pc; |
---|
2757 | whd in match fetch_statement; normalize nodelta |
---|
2758 | whd in match fetch_internal_function in ⊢ (???%); |
---|
2759 | normalize nodelta |
---|
2760 | lapply(fetch_function_no_zero ??????) [2: @( «mk_block Code OZ,refl region Code») |
---|
2761 | | % | @prog |7: #EQ >EQ in ⊢ (???%); |*:] normalize nodelta -EQ |
---|
2762 | lapply fetch_err -fetch_err whd in match fetch_internal_function; normalize nodelta |
---|
2763 | inversion(fetch_function ???) |
---|
2764 | [* #id * #fn #fn_spec >m_return_bind normalize nodelta [whd in ⊢ (??%? → ?); #EQ destruct] |
---|
2765 | #EQ destruct lapply(jmeq_to_eq ??? fn_spec) -fn_spec #fn_spec |
---|
2766 | lapply(fetch_function_transf ????????? fn_spec) [ #v @transf_fundef [2:@translate_internal |]|] |
---|
2767 | #EQ >EQ >m_return_bind % |
---|
2768 | | #err1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #EQfetch whd in ⊢ (??%? → ?); #EQ destruct |
---|
2769 | normalize nodelta lapply EQfetch -EQfetch whd in match fetch_function; |
---|
2770 | normalize nodelta check joint_function |
---|
2771 | lapply(symbol_for_block_transf ? ? ? ? prog (λvars.?) (pc_block pc)) |
---|
2772 | [@transf_fundef [2: @translate_internal|] |4: #EQ >EQ in ⊢ (? → %); |*:] |
---|
2773 | cases(symbol_for_block ???) [ whd in ⊢ (??%% → ?); #EQ destruct %] |
---|
2774 | #id >m_return_bind inversion(find_funct_ptr ???) |
---|
2775 | [2: #fn1 #_ >m_return_bind whd in ⊢ (??%? → ?); #EQ destruct] |
---|
2776 | #EQf whd in ⊢ (??%? → ?); #EQ destruct |
---|
2777 | lapply(find_funct_ptr_none ??????? EQf) (*forse e' falso*) |
---|
2778 | [#vars @transf_fundef [2: @translate_internal|]|] |
---|
2779 | #EQ >EQ % |
---|
2780 | ] |
---|
2781 | ] |
---|
2782 | ]*) |
---|
2783 | cases daemon |
---|
2784 | qed. |
---|
2785 | |
---|
2786 | lemma bool_of_beval_ok : ∀prog : ertlptr_program. |
---|
2787 | ∀sigma : sigma_map prog. |
---|
2788 | preserving1 … res_preserve1 … |
---|
2789 | (sigma_beval prog sigma) |
---|
2790 | (λx.x) |
---|
2791 | (bool_of_beval) |
---|
2792 | (bool_of_beval). |
---|
2793 | #prog #sigma whd in match bool_of_beval; normalize nodelta |
---|
2794 | * normalize nodelta |
---|
2795 | [ | | #ptr1 #ptr2 #p | #by | #p | #ptr #p | #pc #p] |
---|
2796 | try @res_preserve_error1 #x |
---|
2797 | [1,2,3,4: whd in ⊢ (???% → ?); #EQ destruct |
---|
2798 | [1,4: %{true} % // |
---|
2799 | |3: %{false} % // |
---|
2800 | | %{(eq_bv 8 (zero 8) by)} % // |
---|
2801 | ] |
---|
2802 | | whd in match sigma_beval; normalize nodelta cases(sigma_pc_opt ? ? ?) |
---|
2803 | normalize nodelta [2: #pc1] whd in ⊢ (???% → ?); #EQ destruct |
---|
2804 | ] |
---|
2805 | qed. |
---|
2806 | |
---|
2807 | lemma eval_cond_ok : |
---|
2808 | ∀prog. |
---|
2809 | let trans_prog ≝ ertl_to_ertlptr prog in |
---|
2810 | ∀stack_sizes. |
---|
2811 | ∀sigma : sigma_map trans_prog. |
---|
2812 | ∀st,st',f,fn,a,ltrue,lfalse. |
---|
2813 | fetch_statement ERTL_semantics … |
---|
2814 | (globalenv_noinit ? prog) (pc … (sigma_state_pc ? sigma st)) = |
---|
2815 | return 〈f, fn, sequential … (COND ERTL … a ltrue) lfalse〉 → |
---|
2816 | eval_state ERTL_semantics |
---|
2817 | (prog_var_names (joint_function ERTL_semantics) ℕ prog) |
---|
2818 | (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) |
---|
2819 | (sigma_state_pc ? sigma st) = |
---|
2820 | return st' → |
---|
2821 | as_costed (ERTL_status prog stack_sizes) |
---|
2822 | st' → |
---|
2823 | ∃ st''. st' = sigma_state_pc ? sigma st'' ∧ |
---|
2824 | ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) |
---|
2825 | st st''. |
---|
2826 | bool_to_Prop (taaf_non_empty … taf). |
---|
2827 | #prog #stack_size #sigma #st #st' #f #fn #a #lb_t #lb_f |
---|
2828 | whd in match sigma_state_pc in ⊢ (% → ?); normalize nodelta |
---|
2829 | @if_elim |
---|
2830 | [ #EQbl whd in match dummy_state_pc; whd in match null_pc; |
---|
2831 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2832 | normalize nodelta >(fetch_function_no_zero ??????) [2: %] |
---|
2833 | whd in ⊢ (??%% → ?); #EQ destruct ] |
---|
2834 | #Hbl inversion(fetch_internal_function ???) |
---|
2835 | [2: #e #_ normalize nodelta whd in match dummy_state_pc; whd in match null_pc; |
---|
2836 | whd in match fetch_statement; whd in match fetch_internal_function; |
---|
2837 | normalize nodelta >(fetch_function_no_zero ??????) [2: %] |
---|
2838 | whd in ⊢ (??%% → ?); #EQ destruct] |
---|
2839 | * #f1 #fn1 #EQ lapply(jmeq_to_eq ??? EQ) -EQ #fn1_spec normalize nodelta |
---|
2840 | #EQf lapply EQf whd in match fetch_statement; normalize nodelta >fn1_spec |
---|
2841 | >m_return_bind #H @('bind_inversion H) -H #stmt' #_ whd in ⊢ (??%% → ?); |
---|
2842 | #EQ destruct whd in match eval_state; whd in match eval_statement_no_pc; |
---|
2843 | whd in match eval_statement_advance; whd in match sigma_state_pc in ⊢ (% → ?); |
---|
2844 | normalize nodelta @if_elim [#H >H in Hbl; *] #_ >fn1_spec normalize nodelta |
---|
2845 | >EQf >m_return_bind normalize nodelta >m_return_bind |
---|
2846 | #H lapply(err_eq_from_io ????? H) -H #H @('bind_inversion H) -H #bv |
---|
2847 | change with (ps_reg_retrieve ?? = ? → ?) whd in match set_no_pc; |
---|
2848 | whd in match sigma_state in ⊢ (??(?%?)? → ?); normalize nodelta #bv_spec |
---|
2849 | #H @('bind_inversion H) -H * #EQbv normalize nodelta |
---|
2850 | [ whd in match goto; normalize nodelta >pc_of_label_eq [2: assumption |3:] |
---|
2851 | >m_return_bind whd in match pc_of_point; normalize nodelta whd in ⊢ (??%% → ?); |
---|
2852 | whd in match set_pc; normalize nodelta #EQ destruct |
---|
2853 | | whd in match next; whd in match set_pc; normalize nodelta whd in match (succ_pc ???); |
---|
2854 | whd in match (point_of_succ ???); whd in ⊢ (??%% → ?); #EQ destruct |
---|
2855 | ] |
---|
2856 | whd in match as_costed; normalize nodelta * #n_cost % |
---|
2857 | [1,3: % [1,4: @st |
---|
2858 | |2,5: @(mk_program_counter |
---|
2859 | (pc_block (pc ERTLptr_semantics st)) |
---|
2860 | (offset_of_point ERTL_semantics ?)) [ @lb_t | @lb_f] |
---|
2861 | |3,6: @(last_pop ? st) |
---|
2862 | ] |
---|
2863 | ] |
---|
2864 | % [1,3: whd in match sigma_state_pc; normalize nodelta @if_elim |
---|
2865 | [1,3: #EQ >EQ in Hbl; *] #_ >fn1_spec %] |
---|
2866 | %{(taaf_step_jump … (taa_base …) …) I} |
---|
2867 | lapply (fetch_statement_commute prog sigma … stack_size … EQf) |
---|
2868 | normalize nodelta #EQf' |
---|
2869 | [1,4: whd in match as_costed; normalize nodelta >as_label_ok [2,4: @sigma] |
---|
2870 | % #H @n_cost <H whd in match sigma_state_pc; normalize nodelta |
---|
2871 | @if_elim [1,3: #EQ >EQ in Hbl; *] #_ >fn1_spec % |
---|
2872 | |2,5: whd in match as_classifier; normalize nodelta whd in match (as_classify ??); |
---|
2873 | normalize nodelta >EQf' % |
---|
2874 | |*: whd in match (as_execute ???); whd in match eval_state; normalize nodelta |
---|
2875 | >EQf' >m_return_bind whd in match eval_statement_no_pc; normalize nodelta |
---|
2876 | >m_return_bind whd in match eval_statement_advance; normalize nodelta |
---|
2877 | change with (ps_reg_retrieve ??) in ⊢ (??(????(????%?))?); |
---|
2878 | cases(ps_reg_retrieve_ok ????? ? bv_spec) #bv' * #bv_spec' #bv_bv' |
---|
2879 | >bv_spec' >m_return_bind >bv_bv' in EQbv; #EQbv |
---|
2880 | cases(bool_of_beval_ok ? sigma ? ? EQbv) #b1 * #b1_spec #EQ destruct |
---|
2881 | >b1_spec >m_return_bind normalize nodelta [2: %] whd in match goto; |
---|
2882 | normalize nodelta whd in match set_no_pc; normalize nodelta |
---|
2883 | >pc_of_label_eq |
---|
2884 | [ % |
---|
2885 | | lapply(fetch_internal_function_transf ????????) |
---|
2886 | [3: @f |2: @fn | whd in ⊢ (???%); <fn1_spec in ⊢ (???%); % |
---|
2887 | | | #vars @translate_internal |9: #EQ >EQ in ⊢ (??%?); % |*:] |
---|
2888 | | |
---|
2889 | ] |
---|
2890 | ] |
---|
2891 | qed. |
---|
2892 | |
---|
2893 | |
---|
2894 | lemma |
---|
2895 | find_funct_ptr_none: |
---|
2896 | ∀A,B,V,iV. ∀p: program A V. ∀transf: (∀vs. A vs → B vs). |
---|
2897 | ∀b: block. |
---|
2898 | find_funct_ptr ? (globalenv … iV p) b = None ? → |
---|
2899 | find_funct_ptr ? (globalenv … iV (transform_program … p transf)) b = None ?. |
---|
2900 | #A #B #V #i #p #transf #b |
---|
2901 | whd in match find_funct_ptr; normalize nodelta |
---|
2902 | cases b -b * normalize nodelta [#x #_ %] * normalize nodelta |
---|
2903 | [1,2: [2: #x] #_ %] #x whd in match globalenv; normalize nodelta |
---|
2904 | whd in match globalenv_allocmem; normalize nodelta |
---|
2905 | cases daemon (*forse e' falso *) |
---|
2906 | qed. |
---|
2907 | |
---|
2908 | |
---|
2909 | |
---|
2910 | |
---|
2911 | |
---|
2912 | |
---|
2913 | |
---|