1 | include "ASM/Assembly.ma". |
---|
2 | include "ASM/Interpret.ma". |
---|
3 | |
---|
4 | (* RUSSEL **) |
---|
5 | |
---|
6 | include "basics/jmeq.ma". |
---|
7 | |
---|
8 | notation > "hvbox(a break ≃ b)" |
---|
9 | non associative with precedence 45 |
---|
10 | for @{ 'jmeq ? $a ? $b }. |
---|
11 | |
---|
12 | notation < "hvbox(term 46 a break maction (≃) (≃\sub(t,u)) term 46 b)" |
---|
13 | non associative with precedence 45 |
---|
14 | for @{ 'jmeq $t $a $u $b }. |
---|
15 | |
---|
16 | interpretation "john major's equality" 'jmeq t x u y = (jmeq t x u y). |
---|
17 | |
---|
18 | lemma eq_to_jmeq: |
---|
19 | ∀A: Type[0]. |
---|
20 | ∀x, y: A. |
---|
21 | x = y → x ≃ y. |
---|
22 | // |
---|
23 | qed. |
---|
24 | |
---|
25 | definition inject : ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ λA,P,a,p. dp … a p. |
---|
26 | definition eject : ∀A.∀P: A → Prop.(Σx:A.P x) → A ≝ λA,P,c.match c with [ dp w p ⇒ w]. |
---|
27 | |
---|
28 | coercion inject nocomposites: ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ inject on a:? to Σx:?.?. |
---|
29 | coercion eject nocomposites: ∀A.∀P:A → Prop.∀c:Σx:A.P x.A ≝ eject on _c:Σx:?.? to ?. |
---|
30 | |
---|
31 | axiom VOID: Type[0]. |
---|
32 | axiom assert_false: VOID. |
---|
33 | definition bigbang: ∀A:Type[0].False → VOID → A. |
---|
34 | #A #abs cases abs |
---|
35 | qed. |
---|
36 | |
---|
37 | coercion bigbang nocomposites: ∀A:Type[0].False → ∀v:VOID.A ≝ bigbang on _v:VOID to ?. |
---|
38 | |
---|
39 | lemma sig2: ∀A.∀P:A → Prop. ∀p:Σx:A.P x. P (eject … p). |
---|
40 | #A #P #p cases p #w #q @q |
---|
41 | qed. |
---|
42 | |
---|
43 | lemma jmeq_to_eq: ∀A:Type[0]. ∀x,y:A. x≃y → x=y. |
---|
44 | #A #x #y #JMEQ @(jmeq_elim ? x … JMEQ) % |
---|
45 | qed. |
---|
46 | |
---|
47 | coercion jmeq_to_eq: ∀A:Type[0]. ∀x,y:A. ∀p:x≃y.x=y ≝ jmeq_to_eq on _p:?≃? to ?=?. |
---|
48 | |
---|
49 | (* END RUSSELL **) |
---|
50 | |
---|
51 | let rec foldl_strong_internal |
---|
52 | (A: Type[0]) (P: list A → Type[0]) (l: list A) |
---|
53 | (H: ∀prefix. ∀hd. ∀tl. l = prefix @ [hd] @ tl → P prefix → P (prefix @ [hd])) |
---|
54 | (prefix: list A) (suffix: list A) (acc: P prefix) on suffix: |
---|
55 | l = prefix @ suffix → P(prefix @ suffix) ≝ |
---|
56 | match suffix return λl'. l = prefix @ l' → P (prefix @ l') with |
---|
57 | [ nil ⇒ λprf. ? |
---|
58 | | cons hd tl ⇒ λprf. ? |
---|
59 | ]. |
---|
60 | [ > (append_nil ?) |
---|
61 | @ acc |
---|
62 | | applyS (foldl_strong_internal A P l H (prefix @ [hd]) tl ? ?) |
---|
63 | [ @ (H prefix hd tl prf acc) |
---|
64 | | applyS prf |
---|
65 | ] |
---|
66 | ] |
---|
67 | qed. |
---|
68 | |
---|
69 | definition foldl_strong ≝ |
---|
70 | λA: Type[0]. |
---|
71 | λP: list A → Type[0]. |
---|
72 | λl: list A. |
---|
73 | λH: ∀prefix. ∀hd. ∀tl. l = prefix @ [hd] @ tl → P prefix → P (prefix @ [hd]). |
---|
74 | λacc: P [ ]. |
---|
75 | foldl_strong_internal A P l H [ ] l acc (refl …). |
---|
76 | |
---|
77 | definition bit_elim: ∀P: bool → bool. bool ≝ |
---|
78 | λP. |
---|
79 | P true ∧ P false. |
---|
80 | |
---|
81 | let rec bitvector_elim_internal |
---|
82 | (n: nat) (P: BitVector n → bool) (m: nat) on m: m ≤ n → BitVector (n - m) → bool ≝ |
---|
83 | match m return λm. m ≤ n → BitVector (n - m) → bool with |
---|
84 | [ O ⇒ λprf1. λprefix. P ? |
---|
85 | | S n' ⇒ λprf2. λprefix. bit_elim (λbit. bitvector_elim_internal n P n' ? ?) |
---|
86 | ]. |
---|
87 | [ applyS prefix |
---|
88 | | letin res ≝ (bit ::: prefix) |
---|
89 | < (minus_S_S ? ?) |
---|
90 | > (minus_Sn_m ? ?) |
---|
91 | [ @ res |
---|
92 | | @ prf2 |
---|
93 | ] |
---|
94 | | /2/ |
---|
95 | ]. |
---|
96 | qed. |
---|
97 | |
---|
98 | definition bitvector_elim ≝ |
---|
99 | λn: nat. |
---|
100 | λP: BitVector n → bool. |
---|
101 | bitvector_elim_internal n P n ? ?. |
---|
102 | [ @ (le_n ?) |
---|
103 | | < (minus_n_n ?) |
---|
104 | @ [[ ]] |
---|
105 | ] |
---|
106 | qed. |
---|
107 | |
---|
108 | axiom vector_associative_append: |
---|
109 | ∀A: Type[0]. |
---|
110 | ∀n, m, o: nat. |
---|
111 | ∀v: Vector A n. |
---|
112 | ∀q: Vector A m. |
---|
113 | ∀r: Vector A o. |
---|
114 | ((v @@ q) @@ r) |
---|
115 | ≃ |
---|
116 | (v @@ (q @@ r)). |
---|
117 | |
---|
118 | lemma vector_cons_append: |
---|
119 | ∀A: Type[0]. |
---|
120 | ∀n: nat. |
---|
121 | ∀e: A. |
---|
122 | ∀v: Vector A n. |
---|
123 | e ::: v = [[ e ]] @@ v. |
---|
124 | # A # N # E # V |
---|
125 | elim V |
---|
126 | [ normalize % |
---|
127 | | # NN # AA # VV # IH |
---|
128 | normalize |
---|
129 | % |
---|
130 | ] |
---|
131 | qed. |
---|
132 | |
---|
133 | lemma super_rewrite2: |
---|
134 | ∀A:Type[0].∀n,m.∀v1: Vector A n.∀v2: Vector A m. |
---|
135 | ∀P: ∀m. Vector A m → Prop. |
---|
136 | n=m → v1 ≃ v2 → P n v1 → P m v2. |
---|
137 | #A #n #m #v1 #v2 #P #EQ <EQ in v2; #V #JMEQ >JMEQ // |
---|
138 | qed. |
---|
139 | |
---|
140 | lemma mem_middle_vector: |
---|
141 | ∀A: Type[0]. |
---|
142 | ∀m, o: nat. |
---|
143 | ∀eq: A → A → bool. |
---|
144 | ∀reflex: ∀a. eq a a = true. |
---|
145 | ∀p: Vector A m. |
---|
146 | ∀a: A. |
---|
147 | ∀r: Vector A o. |
---|
148 | mem A eq ? (p@@(a:::r)) a = true. |
---|
149 | # A # M # O # EQ # REFLEX # P # A |
---|
150 | elim P |
---|
151 | [ normalize |
---|
152 | > (REFLEX A) |
---|
153 | normalize |
---|
154 | # H |
---|
155 | % |
---|
156 | | # NN # AA # PP # IH |
---|
157 | normalize |
---|
158 | cases (EQ A AA) // |
---|
159 | @ IH |
---|
160 | ] |
---|
161 | qed. |
---|
162 | |
---|
163 | lemma mem_monotonic_wrt_append: |
---|
164 | ∀A: Type[0]. |
---|
165 | ∀m, o: nat. |
---|
166 | ∀eq: A → A → bool. |
---|
167 | ∀reflex: ∀a. eq a a = true. |
---|
168 | ∀p: Vector A m. |
---|
169 | ∀a: A. |
---|
170 | ∀r: Vector A o. |
---|
171 | mem A eq ? r a = true → mem A eq ? (p @@ r) a = true. |
---|
172 | # A # M # O # EQ # REFLEX # P # A |
---|
173 | elim P |
---|
174 | [ #R #H @H |
---|
175 | | #NN #AA # PP # IH #R #H |
---|
176 | normalize |
---|
177 | cases (EQ A AA) |
---|
178 | [ normalize % |
---|
179 | | @ IH @ H |
---|
180 | ] |
---|
181 | ] |
---|
182 | qed. |
---|
183 | |
---|
184 | lemma subvector_multiple_append: |
---|
185 | ∀A: Type[0]. |
---|
186 | ∀o, n: nat. |
---|
187 | ∀eq: A → A → bool. |
---|
188 | ∀refl: ∀a. eq a a = true. |
---|
189 | ∀h: Vector A o. |
---|
190 | ∀v: Vector A n. |
---|
191 | ∀m: nat. |
---|
192 | ∀q: Vector A m. |
---|
193 | bool_to_Prop (subvector_with A ? ? eq v (h @@ q @@ v)). |
---|
194 | # A # O # N # EQ # REFLEX # H # V |
---|
195 | elim V |
---|
196 | [ normalize |
---|
197 | # M # V % |
---|
198 | | # NN # AA # VV # IH # MM # QQ |
---|
199 | change with (bool_to_Prop (andb ??)) |
---|
200 | cut ((mem A EQ (O + (MM + S NN)) (H@@QQ@@AA:::VV) AA) = true) |
---|
201 | [ |
---|
202 | | # HH > HH |
---|
203 | > (vector_cons_append ? ? AA VV) |
---|
204 | change with (bool_to_Prop (subvector_with ??????)) |
---|
205 | @(super_rewrite2 A ((MM + 1)+ NN) (MM+S NN) ?? |
---|
206 | (λSS.λVS.bool_to_Prop (subvector_with ?? (O+SS) ?? (H@@VS))) |
---|
207 | ? |
---|
208 | (vector_associative_append A ? ? ? QQ [[AA]] VV)) |
---|
209 | [ >associative_plus // |
---|
210 | | @IH ] |
---|
211 | ] |
---|
212 | @(mem_monotonic_wrt_append) |
---|
213 | [ @ REFLEX |
---|
214 | | @(mem_monotonic_wrt_append) |
---|
215 | [ @ REFLEX |
---|
216 | | normalize |
---|
217 | > REFLEX |
---|
218 | normalize |
---|
219 | % |
---|
220 | ] |
---|
221 | ] |
---|
222 | qed. |
---|
223 | |
---|
224 | lemma vector_cons_empty: |
---|
225 | ∀A: Type[0]. |
---|
226 | ∀n: nat. |
---|
227 | ∀v: Vector A n. |
---|
228 | [[ ]] @@ v = v. |
---|
229 | # A # N # V |
---|
230 | elim V |
---|
231 | [ normalize % |
---|
232 | | # NN # HH # VV #H % |
---|
233 | ] |
---|
234 | qed. |
---|
235 | |
---|
236 | corollary subvector_hd_tl: |
---|
237 | ∀A: Type[0]. |
---|
238 | ∀o: nat. |
---|
239 | ∀eq: A → A → bool. |
---|
240 | ∀refl: ∀a. eq a a = true. |
---|
241 | ∀h: A. |
---|
242 | ∀v: Vector A o. |
---|
243 | bool_to_Prop (subvector_with A ? ? eq v (h ::: v)). |
---|
244 | # A # O # EQ # REFLEX # H # V |
---|
245 | > (vector_cons_append A ? H V) |
---|
246 | < (vector_cons_empty A ? ([[H]] @@ V)) |
---|
247 | @ (subvector_multiple_append A ? ? EQ REFLEX [[]] V ? [[ H ]]) |
---|
248 | qed. |
---|
249 | |
---|
250 | lemma eq_a_reflexive: |
---|
251 | ∀a. eq_a a a = true. |
---|
252 | # A |
---|
253 | cases A |
---|
254 | % |
---|
255 | qed. |
---|
256 | |
---|
257 | lemma is_in_monotonic_wrt_append: |
---|
258 | ∀m, n: nat. |
---|
259 | ∀p: Vector addressing_mode_tag m. |
---|
260 | ∀q: Vector addressing_mode_tag n. |
---|
261 | ∀to_search: addressing_mode. |
---|
262 | bool_to_Prop (is_in ? p to_search) → bool_to_Prop (is_in ? (q @@ p) to_search). |
---|
263 | # M # N # P # Q # TO_SEARCH |
---|
264 | # H |
---|
265 | elim Q |
---|
266 | [ normalize |
---|
267 | @ H |
---|
268 | | # NN # PP # QQ # IH |
---|
269 | normalize |
---|
270 | cases (is_a PP TO_SEARCH) |
---|
271 | [ normalize |
---|
272 | % |
---|
273 | | normalize |
---|
274 | normalize in IH |
---|
275 | @ IH |
---|
276 | ] |
---|
277 | ] |
---|
278 | qed. |
---|
279 | |
---|
280 | corollary is_in_hd_tl: |
---|
281 | ∀to_search: addressing_mode. |
---|
282 | ∀hd: addressing_mode_tag. |
---|
283 | ∀n: nat. |
---|
284 | ∀v: Vector addressing_mode_tag n. |
---|
285 | bool_to_Prop (is_in ? v to_search) → bool_to_Prop (is_in ? (hd:::v) to_search). |
---|
286 | # TO_SEARCH # HD # N # V |
---|
287 | elim V |
---|
288 | [ # H |
---|
289 | normalize in H; |
---|
290 | cases H |
---|
291 | | # NN # HHD # VV # IH # HH |
---|
292 | > vector_cons_append |
---|
293 | > (vector_cons_append ? ? HHD VV) |
---|
294 | @ (is_in_monotonic_wrt_append ? 1 ([[HHD]]@@VV) [[HD]] TO_SEARCH) |
---|
295 | @ HH |
---|
296 | ] |
---|
297 | qed. |
---|
298 | |
---|
299 | let rec list_addressing_mode_tags_elim |
---|
300 | (n: nat) (l: Vector addressing_mode_tag (S n)) on l: (l → bool) → bool ≝ |
---|
301 | match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x'). |
---|
302 | (l → bool) → bool ] with |
---|
303 | [ VEmpty ⇒ true |
---|
304 | | VCons len hd tl ⇒ λP. |
---|
305 | let process_hd ≝ |
---|
306 | match hd return λhd. ∀P: hd:::tl → bool. bool with |
---|
307 | [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x)) |
---|
308 | | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x)) |
---|
309 | | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x)) |
---|
310 | | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x)) |
---|
311 | | acc_a ⇒ λP.P ACC_A |
---|
312 | | acc_b ⇒ λP.P ACC_B |
---|
313 | | dptr ⇒ λP.P DPTR |
---|
314 | | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x)) |
---|
315 | | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x)) |
---|
316 | | acc_dptr ⇒ λP.P ACC_DPTR |
---|
317 | | acc_pc ⇒ λP.P ACC_PC |
---|
318 | | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR |
---|
319 | | indirect_dptr ⇒ λP.P INDIRECT_DPTR |
---|
320 | | carry ⇒ λP.P CARRY |
---|
321 | | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x)) |
---|
322 | | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x)) |
---|
323 | | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x)) |
---|
324 | | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x)) |
---|
325 | | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x)) |
---|
326 | ] |
---|
327 | in |
---|
328 | andb (process_hd P) |
---|
329 | (match len return λx. x = len → bool with |
---|
330 | [ O ⇒ λprf. true |
---|
331 | | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len)) |
---|
332 | ]. |
---|
333 | try % |
---|
334 | [ 2: cases (sym_eq ??? prf); @tl |
---|
335 | | generalize in match H; generalize in match tl; cases prf; |
---|
336 | (* cases prf in tl H; : ??? WAS WORKING BEFORE *) |
---|
337 | #tl |
---|
338 | normalize in ⊢ (∀_: %. ?) |
---|
339 | # H |
---|
340 | whd |
---|
341 | normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
342 | cases (is_a hd (subaddressing_modeel y tl H)) whd // ] |
---|
343 | qed. |
---|
344 | |
---|
345 | definition product_elim ≝ |
---|
346 | λm, n: nat. |
---|
347 | λv: Vector addressing_mode_tag (S m). |
---|
348 | λq: Vector addressing_mode_tag (S n). |
---|
349 | λP: (v × q) → bool. |
---|
350 | list_addressing_mode_tags_elim ? v (λx. list_addressing_mode_tags_elim ? q (λy. P 〈x, y〉)). |
---|
351 | |
---|
352 | definition union_elim ≝ |
---|
353 | λA, B: Type[0]. |
---|
354 | λelimA: (A → bool) → bool. |
---|
355 | λelimB: (B → bool) → bool. |
---|
356 | λelimU: A ⊎ B → bool. |
---|
357 | elimA (λa. elimB (λb. elimU (inl ? ? a) ∧ elimU (inr ? ? b))). |
---|
358 | |
---|
359 | (* |
---|
360 | definition preinstruction_elim: ∀P: preinstruction [[ relative ]] → bool. bool ≝ |
---|
361 | λP. |
---|
362 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADD ? ACC_A addr)) ∧ |
---|
363 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (ADDC ? ACC_A addr)) ∧ |
---|
364 | list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (SUBB ? ACC_A addr)) ∧ |
---|
365 | list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ; dptr ]] (λaddr. P (INC ? addr)) ∧ |
---|
366 | list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (DEC ? addr)) ∧ |
---|
367 | list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (MUL ? ACC_A addr)) ∧ |
---|
368 | list_addressing_mode_tags_elim ? [[acc_b]] (λaddr. P (DIV ? ACC_A addr)) ∧ |
---|
369 | list_addressing_mode_tags_elim ? [[ registr ; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧ |
---|
370 | list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CLR ? addr)) ∧ |
---|
371 | list_addressing_mode_tags_elim ? [[ acc_a ; carry ; bit_addr ]] (λaddr. P (CPL ? addr)) ∧ |
---|
372 | P (DA ? ACC_A) ∧ |
---|
373 | bitvector_elim 8 (λr. P (JC ? (RELATIVE r))) ∧ |
---|
374 | bitvector_elim 8 (λr. P (JNC ? (RELATIVE r))) ∧ |
---|
375 | bitvector_elim 8 (λr. P (JZ ? (RELATIVE r))) ∧ |
---|
376 | bitvector_elim 8 (λr. P (JNZ ? (RELATIVE r))) ∧ |
---|
377 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JB ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
378 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JNB ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
379 | bitvector_elim 8 (λr. (bitvector_elim 8 (λb: BitVector 8. P (JBC ? (BIT_ADDR b) (RELATIVE r))))) ∧ |
---|
380 | list_addressing_mode_tags_elim ? [[ registr; direct ]] (λaddr. bitvector_elim 8 (λr. P (DJNZ ? addr (RELATIVE r)))) ∧ |
---|
381 | P (RL ? ACC_A) ∧ |
---|
382 | P (RLC ? ACC_A) ∧ |
---|
383 | P (RR ? ACC_A) ∧ |
---|
384 | P (RRC ? ACC_A) ∧ |
---|
385 | P (SWAP ? ACC_A) ∧ |
---|
386 | P (RET ?) ∧ |
---|
387 | P (RETI ?) ∧ |
---|
388 | P (NOP ?) ∧ |
---|
389 | bit_elim (λb. P (XCHD ? ACC_A (INDIRECT b))) ∧ |
---|
390 | list_addressing_mode_tags_elim ? [[ carry; bit_addr ]] (λaddr. P (SETB ? addr)) ∧ |
---|
391 | bitvector_elim 8 (λaddr. P (PUSH ? (DIRECT addr))) ∧ |
---|
392 | bitvector_elim 8 (λaddr. P (POP ? (DIRECT addr))) ∧ |
---|
393 | union_elim ? ? (product_elim ? ? [[ acc_a ]] [[ direct; data ]]) |
---|
394 | (product_elim ? ? [[ registr; indirect ]] [[ data ]]) |
---|
395 | (λd. bitvector_elim 8 (λb. P (CJNE ? d (RELATIVE b)))) ∧ |
---|
396 | list_addressing_mode_tags_elim ? [[ registr; direct; indirect ]] (λaddr. P (XCH ? ACC_A addr)) ∧ |
---|
397 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ data ; registr ; direct ; indirect ]]) |
---|
398 | (product_elim ? ? [[direct]] [[ acc_a ; data ]]) |
---|
399 | (λd. P (XRL ? d)) ∧ |
---|
400 | union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]]) |
---|
401 | (product_elim ? ? [[direct]] [[ acc_a ; data ]])) |
---|
402 | (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]]) |
---|
403 | (λd. P (ANL ? d)) ∧ |
---|
404 | union_elim ? ? (union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; data ; direct ; indirect ]]) |
---|
405 | (product_elim ? ? [[direct]] [[ acc_a ; data ]])) |
---|
406 | (product_elim ? ? [[carry]] [[ bit_addr ; n_bit_addr]]) |
---|
407 | (λd. P (ORL ? d)) ∧ |
---|
408 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ ext_indirect ; ext_indirect_dptr ]]) |
---|
409 | (product_elim ? ? [[ ext_indirect ; ext_indirect_dptr ]] [[acc_a]]) |
---|
410 | (λd. P (MOVX ? d)) ∧ |
---|
411 | union_elim ? ? ( |
---|
412 | union_elim ? ? ( |
---|
413 | union_elim ? ? ( |
---|
414 | union_elim ? ? ( |
---|
415 | union_elim ? ? (product_elim ? ? [[acc_a]] [[ registr ; direct ; indirect ; data ]]) |
---|
416 | (product_elim ? ? [[ registr ; indirect ]] [[ acc_a ; direct ; data ]])) |
---|
417 | (product_elim ? ? [[direct]] [[ acc_a ; registr ; direct ; indirect ; data ]])) |
---|
418 | (product_elim ? ? [[dptr]] [[data16]])) |
---|
419 | (product_elim ? ? [[carry]] [[bit_addr]])) |
---|
420 | (product_elim ? ? [[bit_addr]] [[carry]]) |
---|
421 | (λd. P (MOV ? d)). |
---|
422 | % |
---|
423 | qed. |
---|
424 | |
---|
425 | definition instruction_elim: ∀P: instruction → bool. bool ≝ |
---|
426 | λP. (* |
---|
427 | bitvector_elim 11 (λx. P (ACALL (ADDR11 x))) ∧ |
---|
428 | bitvector_elim 16 (λx. P (LCALL (ADDR16 x))) ∧ |
---|
429 | bitvector_elim 11 (λx. P (AJMP (ADDR11 x))) ∧ |
---|
430 | bitvector_elim 16 (λx. P (LJMP (ADDR16 x))) ∧ *) |
---|
431 | bitvector_elim 8 (λx. P (SJMP (RELATIVE x))). (* ∧ |
---|
432 | P (JMP INDIRECT_DPTR) ∧ |
---|
433 | list_addressing_mode_tags_elim ? [[ acc_dptr; acc_pc ]] (λa. P (MOVC ACC_A a)) ∧ |
---|
434 | preinstruction_elim (λp. P (RealInstruction p)). *) |
---|
435 | % |
---|
436 | qed. |
---|
437 | |
---|
438 | |
---|
439 | axiom instruction_elim_complete: |
---|
440 | ∀P. instruction_elim P = true → ∀i. P i = true. |
---|
441 | *) |
---|
442 | (*definition eq_instruction ≝ |
---|
443 | λi, j: instruction. |
---|
444 | true.*) |
---|
445 | axiom eq_instruction: instruction → instruction → bool. |
---|
446 | axiom eq_instruction_refl: ∀i. eq_instruction i i = true. |
---|
447 | |
---|
448 | let rec vect_member |
---|
449 | (A: Type[0]) (n: nat) (eq: A → A → bool) |
---|
450 | (v: Vector A n) (a: A) on v: bool ≝ |
---|
451 | match v with |
---|
452 | [ VEmpty ⇒ false |
---|
453 | | VCons len hd tl ⇒ |
---|
454 | eq hd a ∨ (vect_member A ? eq tl a) |
---|
455 | ]. |
---|
456 | |
---|
457 | let rec list_addressing_mode_tags_elim_prop |
---|
458 | (n: nat) |
---|
459 | (l: Vector addressing_mode_tag (S n)) |
---|
460 | on l: |
---|
461 | ∀P: l → Prop. |
---|
462 | ∀direct_a. ∀indirect_a. ∀ext_indirect_a. ∀register_a. ∀acc_a_a. |
---|
463 | ∀acc_b_a. ∀dptr_a. ∀data_a. ∀data16_a. ∀acc_dptr_a. ∀acc_pc_a. |
---|
464 | ∀ext_indirect_dptr_a. ∀indirect_dptr_a. ∀carry_a. ∀bit_addr_a. |
---|
465 | ∀n_bit_addr_a. ∀relative_a. ∀addr11_a. ∀addr16_a. |
---|
466 | ∀x: l. P x ≝ |
---|
467 | match l return |
---|
468 | λy. |
---|
469 | match y with |
---|
470 | [ O ⇒ λm: Vector addressing_mode_tag O. ∀prf: 0 = S n. True |
---|
471 | | S y' ⇒ λl: Vector addressing_mode_tag (S y'). ∀prf: S y' = S n.∀P:l → Prop. |
---|
472 | ∀direct_a: if vect_member … eq_a l direct then ∀x. P (DIRECT x) else True. |
---|
473 | ∀indirect_a: if vect_member … eq_a l indirect then ∀x. P (INDIRECT x) else True. |
---|
474 | ∀ext_indirect_a: if vect_member … eq_a l ext_indirect then ∀x. P (EXT_INDIRECT x) else True. |
---|
475 | ∀register_a: if vect_member … eq_a l registr then ∀x. P (REGISTER x) else True. |
---|
476 | ∀acc_a_a: if vect_member … eq_a l acc_a then P (ACC_A) else True. |
---|
477 | ∀acc_b_a: if vect_member … eq_a l acc_b then P (ACC_B) else True. |
---|
478 | ∀dptr_a: if vect_member … eq_a l dptr then P DPTR else True. |
---|
479 | ∀data_a: if vect_member … eq_a l data then ∀x. P (DATA x) else True. |
---|
480 | ∀data16_a: if vect_member … eq_a l data16 then ∀x. P (DATA16 x) else True. |
---|
481 | ∀acc_dptr_a: if vect_member … eq_a l acc_dptr then P ACC_DPTR else True. |
---|
482 | ∀acc_pc_a: if vect_member … eq_a l acc_pc then P ACC_PC else True. |
---|
483 | ∀ext_indirect_dptr_a: if vect_member … eq_a l ext_indirect_dptr then P EXT_INDIRECT_DPTR else True. |
---|
484 | ∀indirect_dptr_a: if vect_member … eq_a l indirect_dptr then P INDIRECT_DPTR else True. |
---|
485 | ∀carry_a: if vect_member … eq_a l carry then P CARRY else True. |
---|
486 | ∀bit_addr_a: if vect_member … eq_a l bit_addr then ∀x. P (BIT_ADDR x) else True. |
---|
487 | ∀n_bit_addr_a: if vect_member … eq_a l n_bit_addr then ∀x. P (N_BIT_ADDR x) else True. |
---|
488 | ∀relative_a: if vect_member … eq_a l relative then ∀x. P (RELATIVE x) else True. |
---|
489 | ∀addr11_a: if vect_member … eq_a l addr11 then ∀x. P (ADDR11 x) else True. |
---|
490 | ∀addr_16_a: if vect_member … eq_a l addr16 then ∀x. P (ADDR16 x) else True. |
---|
491 | ∀x:l. P x |
---|
492 | ] with |
---|
493 | [ VEmpty ⇒ λAbsurd. ⊥ |
---|
494 | | VCons len hd tl ⇒ λProof. ? |
---|
495 | ] (refl ? (S n)). cases daemon. qed. (* |
---|
496 | [ destruct(Absurd) |
---|
497 | | # A1 # A2 # A3 # A4 # A5 # A6 # A7 |
---|
498 | # A8 # A9 # A10 # A11 # A12 # A13 # A14 |
---|
499 | # A15 # A16 # A17 # A18 # A19 # X |
---|
500 | cases X |
---|
501 | # SUB cases daemon ] qed. |
---|
502 | cases SUB |
---|
503 | [ # BYTE |
---|
504 | normalize |
---|
505 | ]. |
---|
506 | |
---|
507 | |
---|
508 | (* let prepare_hd ≝ |
---|
509 | match hd with |
---|
510 | [ direct ⇒ λdirect_prf. ? |
---|
511 | | indirect ⇒ λindirect_prf. ? |
---|
512 | | ext_indirect ⇒ λext_indirect_prf. ? |
---|
513 | | registr ⇒ λregistr_prf. ? |
---|
514 | | acc_a ⇒ λacc_a_prf. ? |
---|
515 | | acc_b ⇒ λacc_b_prf. ? |
---|
516 | | dptr ⇒ λdptr_prf. ? |
---|
517 | | data ⇒ λdata_prf. ? |
---|
518 | | data16 ⇒ λdata16_prf. ? |
---|
519 | | acc_dptr ⇒ λacc_dptr_prf. ? |
---|
520 | | acc_pc ⇒ λacc_pc_prf. ? |
---|
521 | | ext_indirect_dptr ⇒ λext_indirect_prf. ? |
---|
522 | | indirect_dptr ⇒ λindirect_prf. ? |
---|
523 | | carry ⇒ λcarry_prf. ? |
---|
524 | | bit_addr ⇒ λbit_addr_prf. ? |
---|
525 | | n_bit_addr ⇒ λn_bit_addr_prf. ? |
---|
526 | | relative ⇒ λrelative_prf. ? |
---|
527 | | addr11 ⇒ λaddr11_prf. ? |
---|
528 | | addr16 ⇒ λaddr16_prf. ? |
---|
529 | ] |
---|
530 | in ? *) |
---|
531 | ]. |
---|
532 | [ 1: destruct(absd) |
---|
533 | | 2: # A1 # A2 # A3 # A4 # A5 # A6 |
---|
534 | # A7 # A8 # A9 # A10 # A11 # A12 |
---|
535 | # A13 # A14 # A15 # A16 # A17 # A18 |
---|
536 | # A19 * |
---|
537 | ]. |
---|
538 | |
---|
539 | |
---|
540 | match l return λx.match x with [O ⇒ λl: Vector … O. bool | S x' ⇒ λl: Vector addressing_mode_tag (S x'). |
---|
541 | (l → bool) → bool ] with |
---|
542 | [ VEmpty ⇒ true |
---|
543 | | VCons len hd tl ⇒ λP. |
---|
544 | let process_hd ≝ |
---|
545 | match hd return λhd. ∀P: hd:::tl → bool. bool with |
---|
546 | [ direct ⇒ λP.bitvector_elim 8 (λx. P (DIRECT x)) |
---|
547 | | indirect ⇒ λP.bit_elim (λx. P (INDIRECT x)) |
---|
548 | | ext_indirect ⇒ λP.bit_elim (λx. P (EXT_INDIRECT x)) |
---|
549 | | registr ⇒ λP.bitvector_elim 3 (λx. P (REGISTER x)) |
---|
550 | | acc_a ⇒ λP.P ACC_A |
---|
551 | | acc_b ⇒ λP.P ACC_B |
---|
552 | | dptr ⇒ λP.P DPTR |
---|
553 | | data ⇒ λP.bitvector_elim 8 (λx. P (DATA x)) |
---|
554 | | data16 ⇒ λP.bitvector_elim 16 (λx. P (DATA16 x)) |
---|
555 | | acc_dptr ⇒ λP.P ACC_DPTR |
---|
556 | | acc_pc ⇒ λP.P ACC_PC |
---|
557 | | ext_indirect_dptr ⇒ λP.P EXT_INDIRECT_DPTR |
---|
558 | | indirect_dptr ⇒ λP.P INDIRECT_DPTR |
---|
559 | | carry ⇒ λP.P CARRY |
---|
560 | | bit_addr ⇒ λP.bitvector_elim 8 (λx. P (BIT_ADDR x)) |
---|
561 | | n_bit_addr ⇒ λP.bitvector_elim 8 (λx. P (N_BIT_ADDR x)) |
---|
562 | | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE x)) |
---|
563 | | addr11 ⇒ λP.bitvector_elim 11 (λx. P (ADDR11 x)) |
---|
564 | | addr16 ⇒ λP.bitvector_elim 16 (λx. P (ADDR16 x)) |
---|
565 | ] |
---|
566 | in |
---|
567 | andb (process_hd P) |
---|
568 | (match len return λx. x = len → bool with |
---|
569 | [ O ⇒ λprf. true |
---|
570 | | S y ⇒ λprf. list_addressing_mode_tags_elim y ? P ] (refl ? len)) |
---|
571 | ]. |
---|
572 | try % |
---|
573 | [ 2: cases (sym_eq ??? prf); @tl |
---|
574 | | generalize in match H; generalize in match tl; cases prf; |
---|
575 | (* cases prf in tl H; : ??? WAS WORKING BEFORE *) |
---|
576 | #tl |
---|
577 | normalize in ⊢ (∀_: %. ?) |
---|
578 | # H |
---|
579 | whd |
---|
580 | normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
581 | cases (is_a hd (subaddressing_modeel y tl H)) whd // ] |
---|
582 | qed. |
---|
583 | *) |
---|
584 | (* |
---|
585 | lemma test: |
---|
586 | let i ≝ SJMP (RELATIVE (bitvector_of_nat 8 255)) in |
---|
587 | (let assembled ≝ assembly1 i in |
---|
588 | let code_memory ≝ load_code_memory assembled in |
---|
589 | let fetched ≝ fetch code_memory ? in |
---|
590 | let 〈instr_pc, ticks〉 ≝ fetched in |
---|
591 | eq_instruction (\fst instr_pc)) i = true. |
---|
592 | [2: @ zero |
---|
593 | | normalize |
---|
594 | ]*) |
---|
595 | |
---|
596 | lemma BitVectorTrie_O: |
---|
597 | ∀A:Type[0].∀v:BitVectorTrie A 0.(∃w. v ≃ Leaf A w) ∨ v ≃ Stub A 0. |
---|
598 | #A #v generalize in match (refl … O) cases v in ⊢ (??%? → (?(??(λ_.?%%??)))(?%%??)) |
---|
599 | [ #w #_ %1 %[@w] % |
---|
600 | | #n #l #r #abs @⊥ // |
---|
601 | | #n #EQ %2 >EQ %] |
---|
602 | qed. |
---|
603 | |
---|
604 | lemma BitVectorTrie_Sn: |
---|
605 | ∀A:Type[0].∀n.∀v:BitVectorTrie A (S n).(∃l,r. v ≃ Node A n l r) ∨ v ≃ Stub A (S n). |
---|
606 | #A #n #v generalize in match (refl … (S n)) cases v in ⊢ (??%? → (?(??(λ_.??(λ_.?%%??))))%) |
---|
607 | [ #m #abs @⊥ // |
---|
608 | | #m #l #r #EQ %1 <(injective_S … EQ) %[@l] %[@r] // |
---|
609 | | #m #EQ %2 // ] |
---|
610 | qed. |
---|
611 | |
---|
612 | lemma lookup_prepare_trie_for_insertion_hit: |
---|
613 | ∀A:Type[0].∀a,v:A.∀n.∀b:BitVector n. |
---|
614 | lookup … b (prepare_trie_for_insertion … b v) a = v. |
---|
615 | #A #a #v #n #b elim b // #m #hd #tl #IH cases hd normalize // |
---|
616 | qed. |
---|
617 | |
---|
618 | lemma lookup_insert_hit: |
---|
619 | ∀A:Type[0].∀a,v:A.∀n.∀b:BitVector n.∀t:BitVectorTrie A n. |
---|
620 | lookup … b (insert … b v t) a = v. |
---|
621 | #A #a #v #n #b elim b -b -n // |
---|
622 | #n #hd #tl #IH #t cases(BitVectorTrie_Sn … t) |
---|
623 | [ * #l * #r #JMEQ >JMEQ cases hd normalize // |
---|
624 | | #JMEQ >JMEQ cases hd normalize @lookup_prepare_trie_for_insertion_hit ] |
---|
625 | qed. |
---|
626 | |
---|
627 | lemma BitVector_O: ∀v:BitVector 0. v ≃ VEmpty bool. |
---|
628 | #v generalize in match (refl … 0) cases v in ⊢ (??%? → ?%%??) // |
---|
629 | #n #hd #tl #abs @⊥ // |
---|
630 | qed. |
---|
631 | |
---|
632 | lemma BitVector_Sn: ∀n.∀v:BitVector (S n). |
---|
633 | ∃hd.∃tl.v ≃ VCons bool n hd tl. |
---|
634 | #n #v generalize in match (refl … (S n)) cases v in ⊢ (??%? → ??(λ_.??(λ_.?%%??))) |
---|
635 | [ #abs @⊥ // |
---|
636 | | #m #hd #tl #EQ <(injective_S … EQ) %[@hd] %[@tl] // ] |
---|
637 | qed. |
---|
638 | |
---|
639 | coercion bool_to_Prop: ∀b:bool. Prop ≝ bool_to_Prop on _b:bool to Type[0]. |
---|
640 | |
---|
641 | lemma lookup_prepare_trie_for_insertion_miss: |
---|
642 | ∀A:Type[0].∀a,v:A.∀n.∀c,b:BitVector n. |
---|
643 | (notb (eq_bv ? b c)) → lookup … b (prepare_trie_for_insertion … c v) a = a. |
---|
644 | #A #a #v #n #c elim c |
---|
645 | [ #b >(BitVector_O … b) normalize #abs @⊥ // |
---|
646 | | #m #hd #tl #IH #b cases(BitVector_Sn … b) #hd' * #tl' #JMEQ >JMEQ |
---|
647 | cases hd cases hd' normalize |
---|
648 | [2,3: #_ cases tl' // |
---|
649 | |*: change with (bool_to_Prop (notb (eq_bv ???)) → ?) /2/ ]] |
---|
650 | qed. |
---|
651 | |
---|
652 | lemma lookup_insert_miss: |
---|
653 | ∀A:Type[0].∀a,v:A.∀n.∀c,b:BitVector n.∀t:BitVectorTrie A n. |
---|
654 | (notb (eq_bv ? b c)) → lookup … b (insert … c v t) a = lookup … b t a. |
---|
655 | #A #a #v #n #c elim c -c -n |
---|
656 | [ #b #t #DIFF @⊥ whd in DIFF; >(BitVector_O … b) in DIFF // |
---|
657 | | #n #hd #tl #IH #b cases(BitVector_Sn … b) #hd' * #tl' #JMEQ >JMEQ |
---|
658 | #t cases(BitVectorTrie_Sn … t) |
---|
659 | [ * #l * #r #JMEQ >JMEQ cases hd cases hd' #H normalize in H; |
---|
660 | [1,4: change in H with (bool_to_Prop (notb (eq_bv ???))) ] normalize // @IH // |
---|
661 | | #JMEQ >JMEQ cases hd cases hd' #H normalize in H; |
---|
662 | [1,4: change in H with (bool_to_Prop (notb (eq_bv ???))) ] normalize |
---|
663 | [3,4: cases tl' // | *: @lookup_prepare_trie_for_insertion_miss //]]] |
---|
664 | qed. |
---|
665 | |
---|
666 | definition load_code_memory_aux ≝ |
---|
667 | fold_left_i_aux … ( |
---|
668 | λi, mem, v. |
---|
669 | insert … (bitvector_of_nat … i) v mem) (Stub Byte 16). |
---|
670 | |
---|
671 | axiom split_elim: |
---|
672 | ∀A,l,m,v.∀P: (Vector A l) × (Vector A m) → Prop. |
---|
673 | (∀vl,vm. v = vl@@vm → P 〈vl,vm〉) → P (split A l m v). |
---|
674 | (* |
---|
675 | axiom half_add_SO: |
---|
676 | ∀pc. |
---|
677 | \snd (half_add 16 (bitvector_of_nat … pc) (bitvector_of_nat … 1)) = bitvector_of_nat … (S pc). |
---|
678 | |
---|
679 | axiom not_eqvb_S: |
---|
680 | ∀pc. |
---|
681 | (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S pc))). |
---|
682 | |
---|
683 | axiom not_eqvb_SS: |
---|
684 | ∀pc. |
---|
685 | (¬eq_bv 16 (bitvector_of_nat 16 pc) (bitvector_of_nat 16 (S (S pc)))). |
---|
686 | |
---|
687 | axiom bitvector_elim_complete: |
---|
688 | ∀n,P. bitvector_elim n P = true → ∀bv. P bv. |
---|
689 | |
---|
690 | lemma bitvector_elim_complete': |
---|
691 | ∀n,P. bitvector_elim n P = true → ∀bv. P bv = true. |
---|
692 | #n #P #H generalize in match (bitvector_elim_complete … H) #K #bv |
---|
693 | generalize in match (K bv) normalize cases (P bv) normalize // #abs @⊥ // |
---|
694 | qed. |
---|
695 | *) |
---|
696 | |
---|
697 | |
---|
698 | |
---|
699 | |
---|
700 | (* |
---|
701 | lemma andb_elim': |
---|
702 | ∀b1,b2. (b1 = true) → (b2 = true) → (b1 ∧ b2) = true. |
---|
703 | #b1 #b2 #H1 #H2 @andb_elim cases b1 in H1; normalize // |
---|
704 | qed. |
---|
705 | *) |
---|
706 | |
---|
707 | let rec encoding_check (code_memory: BitVectorTrie Byte 16) (pc: Word) (final_pc: Word) |
---|
708 | (encoding: list Byte) on encoding: Prop ≝ |
---|
709 | match encoding with |
---|
710 | [ nil ⇒ final_pc = pc |
---|
711 | | cons hd tl ⇒ |
---|
712 | let 〈new_pc, byte〉 ≝ next code_memory pc in |
---|
713 | hd = byte ∧ encoding_check code_memory new_pc final_pc tl |
---|
714 | ]. |
---|
715 | |
---|
716 | axiom eq_bv_refl: ∀n,v. eq_bv n v v = true. |
---|
717 | |
---|
718 | axiom bitvector_3_elim_prop: |
---|
719 | ∀P: BitVector 3 → Prop. |
---|
720 | P [[false;false;false]] → P [[false;false;true]] → P [[false;true;false]] → |
---|
721 | P [[false;true;true]] → P [[true;false;false]] → P [[true;false;true]] → |
---|
722 | P [[true;true;false]] → P [[true;true;true]] → ∀v. P v. |
---|
723 | |
---|
724 | lemma test: |
---|
725 | ∀pc,i,code_memory,assembled. |
---|
726 | assembled = assembly1 i → |
---|
727 | let len ≝ length … assembled in |
---|
728 | encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled → |
---|
729 | let fetched ≝ fetch code_memory (bitvector_of_nat … pc) in |
---|
730 | let 〈instr_pc, ticks〉 ≝ fetched in |
---|
731 | let 〈instr,pc'〉 ≝ instr_pc in |
---|
732 | (eq_instruction instr i ∧ eq_bv … pc' (bitvector_of_nat … (pc + len))) = true. |
---|
733 | #pc #i #code_memory #assembled cases i [8: *] |
---|
734 | [16,20,29: * * |18,19: * * [1,2,4,5: *] |28: * * [1,2: * [1,2: * [1,2: * [1,2: *]]]]] |
---|
735 | [47,48,49: |
---|
736 | |*: #arg @(list_addressing_mode_tags_elim_prop … arg) whd try % -arg |
---|
737 | [2,3,5,7,10,12,16,17,18,21,25,26,27,30,31,32,37,38,39,40,41,42,43,44,45,48,51,58, |
---|
738 | 59,60,63,64,65,66,67: #ARG]] |
---|
739 | [4,5,6,7,8,9,10,11,12,13,22,23,24,27,28,39,40,41,42,43,44,45,46,47,48,49,50,51,52, |
---|
740 | 56,57,69,70,72,73,75: #arg2 @(list_addressing_mode_tags_elim_prop … arg2) whd try % -arg2 |
---|
741 | [1,2,4,7,9,10,12,13,15,16,17,18,20,22,23,24,25,26,27,28,29,30,31,32,33,36,37,38, |
---|
742 | 39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65, |
---|
743 | 68,69,70,71: #ARG2]] |
---|
744 | [1,2,19,20: #arg3 @(list_addressing_mode_tags_elim_prop … arg3) whd try % -arg3 #ARG3] |
---|
745 | normalize in ⊢ (???% → ?) |
---|
746 | [92,94,42,93,95: @split_elim #vl #vm #E >E -E; [2,4: @(bitvector_3_elim_prop … vl)] |
---|
747 | normalize in ⊢ (???% → ?)] |
---|
748 | #H >H * #H1 try (change in ⊢ (% → ?) with (? ∧ ?) * #H2) |
---|
749 | try (change in ⊢ (% → ?) with (? ∧ ?) * #H3) whd in ⊢ (% → ?) #H4 |
---|
750 | change in ⊢ (let fetched ≝ % in ?) with (fetch0 ??) |
---|
751 | whd in ⊢ (let fetched ≝ ??% in ?) <H1 whd in ⊢ (let fetched ≝ % in ?) |
---|
752 | [17,18,19,20,21,22,23,24,25,26,31,34,35,36,37,38: <H3] |
---|
753 | [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29, |
---|
754 | 30,31,32,33,34,35,36,37,38,39,40,43,45,48,49,52,53,54,55,56,57,60,61,62,65,66, |
---|
755 | 69,70,73,74,78,80,81,84,85,95,98,101,102,103,104,105,106,107,108,109,110: <H2] |
---|
756 | whd >eq_instruction_refl >H4 @eq_bv_refl |
---|
757 | qed. |
---|
758 | |
---|
759 | (* This establishes the correspondence between pseudo program counters and |
---|
760 | program counters. It is at the heart of the proof. *) |
---|
761 | (*CSC: code taken from build_maps *) |
---|
762 | definition sigma0: pseudo_assembly_program → option (nat × (nat × (BitVectorTrie Word 16))) ≝ |
---|
763 | λinstr_list. |
---|
764 | foldl ?? |
---|
765 | (λt. λi. |
---|
766 | match t with |
---|
767 | [ None ⇒ None ? |
---|
768 | | Some ppc_pc_map ⇒ |
---|
769 | let 〈ppc,pc_map〉 ≝ ppc_pc_map in |
---|
770 | let 〈program_counter, sigma_map〉 ≝ pc_map in |
---|
771 | let 〈label, i〉 ≝ i in |
---|
772 | match construct_costs instr_list program_counter (λx. zero ?) (λx. zero ?) (Stub …) i with |
---|
773 | [ None ⇒ None ? |
---|
774 | | Some pc_ignore ⇒ |
---|
775 | let 〈pc,ignore〉 ≝ pc_ignore in |
---|
776 | Some … 〈S ppc,〈pc, insert ? ? (bitvector_of_nat ? ppc) (bitvector_of_nat ? pc) sigma_map〉〉 ] |
---|
777 | ]) (Some ? 〈0, 〈0, (Stub ? ?)〉〉) (\snd instr_list). |
---|
778 | |
---|
779 | definition tech_pc_sigma0: pseudo_assembly_program → option (nat × (BitVectorTrie Word 16)) ≝ |
---|
780 | λinstr_list. |
---|
781 | match sigma0 instr_list with |
---|
782 | [ None ⇒ None … |
---|
783 | | Some result ⇒ |
---|
784 | let 〈ppc,pc_sigma_map〉 ≝ result in |
---|
785 | Some … pc_sigma_map ]. |
---|
786 | |
---|
787 | definition sigma_safe: pseudo_assembly_program → option (Word → Word) ≝ |
---|
788 | λinstr_list. |
---|
789 | match sigma0 instr_list with |
---|
790 | [ None ⇒ None ? |
---|
791 | | Some result ⇒ |
---|
792 | let 〈ppc,pc_sigma_map〉 ≝ result in |
---|
793 | let 〈pc, sigma_map〉 ≝ pc_sigma_map in |
---|
794 | if gtb pc (2^16) then |
---|
795 | None ? |
---|
796 | else |
---|
797 | Some ? (λx.lookup ?? x sigma_map (zero …)) ]. |
---|
798 | |
---|
799 | axiom policy_ok: ∀p. sigma_safe p ≠ None …. |
---|
800 | |
---|
801 | definition sigma: pseudo_assembly_program → Word → Word ≝ |
---|
802 | λp. |
---|
803 | match sigma_safe p return λr:option (Word → Word). r ≠ None … → Word → Word with |
---|
804 | [ None ⇒ λabs. ⊥ |
---|
805 | | Some r ⇒ λ_.r] (policy_ok p). |
---|
806 | cases abs // |
---|
807 | qed. |
---|
808 | |
---|
809 | lemma length_append: |
---|
810 | ∀A.∀l1,l2:list A. |
---|
811 | |l1 @ l2| = |l1| + |l2|. |
---|
812 | #A #l1 elim l1 |
---|
813 | [ // |
---|
814 | | #hd #tl #IH #l2 normalize <IH //] |
---|
815 | qed. |
---|
816 | |
---|
817 | let rec does_not_occur (id:Identifier) (l:list labelled_instruction) on l: bool ≝ |
---|
818 | match l with |
---|
819 | [ nil ⇒ true |
---|
820 | | cons hd tl ⇒ notb (instruction_matches_identifier id hd) ∧ does_not_occur id tl]. |
---|
821 | |
---|
822 | lemma does_not_occur_None: |
---|
823 | ∀id,i,list_instr. |
---|
824 | does_not_occur id (list_instr@[〈None …,i〉]) = |
---|
825 | does_not_occur id list_instr. |
---|
826 | #id #i #list_instr elim list_instr |
---|
827 | [ % | #hd #tl #IH whd in ⊢ (??%%) >IH %] |
---|
828 | qed. |
---|
829 | |
---|
830 | let rec occurs_exactly_once (id:Identifier) (l:list labelled_instruction) on l : bool ≝ |
---|
831 | match l with |
---|
832 | [ nil ⇒ false |
---|
833 | | cons hd tl ⇒ |
---|
834 | if instruction_matches_identifier id hd then |
---|
835 | does_not_occur id tl |
---|
836 | else |
---|
837 | occurs_exactly_once id tl ]. |
---|
838 | |
---|
839 | lemma occurs_exactly_once_None: |
---|
840 | ∀id,i,list_instr. |
---|
841 | occurs_exactly_once id (list_instr@[〈None …,i〉]) = |
---|
842 | occurs_exactly_once id list_instr. |
---|
843 | #id #i #list_instr elim list_instr |
---|
844 | [ % | #hd #tl #IH whd in ⊢ (??%%) >IH >does_not_occur_None %] |
---|
845 | qed. |
---|
846 | |
---|
847 | lemma index_of_internal_None: ∀i,id,instr_list,n. |
---|
848 | occurs_exactly_once id (instr_list@[〈None …,i〉]) → |
---|
849 | index_of_internal ? (instruction_matches_identifier id) instr_list n = |
---|
850 | index_of_internal ? (instruction_matches_identifier id) (instr_list@[〈None …,i〉]) n. |
---|
851 | #i #id #instr_list elim instr_list |
---|
852 | [ #n #abs whd in abs; cases abs |
---|
853 | | #hd #tl #IH #n whd in ⊢ (% → ??%%); whd in ⊢ (match % with [_ ⇒ ? | _ ⇒ ?] → ?) |
---|
854 | cases (instruction_matches_identifier id hd) whd in ⊢ (match % with [_ ⇒ ? | _ ⇒ ?] → ??%%) |
---|
855 | [ #H % |
---|
856 | | #H @IH whd in H; cases (occurs_exactly_once ??) in H ⊢ % |
---|
857 | [ #_ % | #abs cases abs ]]] |
---|
858 | qed. |
---|
859 | |
---|
860 | lemma address_of_word_labels_code_mem_None: ∀i,id,instr_list. |
---|
861 | occurs_exactly_once id (instr_list@[〈None …,i〉]) → |
---|
862 | address_of_word_labels_code_mem instr_list id = |
---|
863 | address_of_word_labels_code_mem (instr_list@[〈None …,i〉]) id. |
---|
864 | #i #id #instr_list #H whd in ⊢ (??%%) whd in ⊢ (??(??%?)(??%?)) |
---|
865 | >(index_of_internal_None … H) % |
---|
866 | qed. |
---|
867 | |
---|
868 | axiom tech_pc_sigma0_append: |
---|
869 | ∀preamble,instr_list,prefix,label,i,pc',code,pc,costs,costs'. |
---|
870 | Some … 〈pc,costs〉 = tech_pc_sigma0 〈preamble,prefix〉 → |
---|
871 | construct_costs 〈preamble,instr_list〉 … pc (λx.zero 16) (λx. zero 16) costs i = Some … 〈pc',code〉 → |
---|
872 | tech_pc_sigma0 〈preamble,prefix@[〈label,i〉]〉 = Some … 〈pc',costs'〉. |
---|
873 | |
---|
874 | axiom tech_pc_sigma0_append_None: |
---|
875 | ∀preamble,instr_list,prefix,i,pc,costs. |
---|
876 | Some … 〈pc,costs〉 = tech_pc_sigma0 〈preamble,prefix〉 → |
---|
877 | construct_costs 〈preamble,instr_list〉 … pc (λx.zero 16) (λx. zero 16) costs i = None … |
---|
878 | → False. |
---|
879 | |
---|
880 | |
---|
881 | definition build_maps' ≝ |
---|
882 | λpseudo_program. |
---|
883 | let 〈preamble,instr_list〉 ≝ pseudo_program in |
---|
884 | let result ≝ |
---|
885 | foldl_strong |
---|
886 | (option Identifier × pseudo_instruction) |
---|
887 | (λpre. Σres:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
888 | let pre' ≝ 〈preamble,pre〉 in |
---|
889 | let 〈labels,pc_costs〉 ≝ res in |
---|
890 | tech_pc_sigma0 pre' = Some … pc_costs ∧ |
---|
891 | ∀id. occurs_exactly_once id pre → |
---|
892 | lookup ?? id labels (zero …) = sigma pre' (address_of_word_labels_code_mem pre id)) |
---|
893 | instr_list |
---|
894 | (λprefix,i,tl,prf,t. |
---|
895 | let 〈labels, pc_costs〉 ≝ t in |
---|
896 | let 〈program_counter, costs〉 ≝ pc_costs in |
---|
897 | let 〈label, i'〉 ≝ i in |
---|
898 | let labels ≝ |
---|
899 | match label with |
---|
900 | [ None ⇒ labels |
---|
901 | | Some label ⇒ |
---|
902 | let program_counter_bv ≝ bitvector_of_nat ? program_counter in |
---|
903 | insert ? ? label program_counter_bv labels |
---|
904 | ] |
---|
905 | in |
---|
906 | match construct_costs 〈preamble,instr_list〉 program_counter (λx. zero ?) (λx. zero ?) costs i' with |
---|
907 | [ None ⇒ |
---|
908 | let dummy ≝ 〈labels,pc_costs〉 in |
---|
909 | dummy |
---|
910 | | Some construct ⇒ 〈labels, construct〉 |
---|
911 | ] |
---|
912 | ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 |
---|
913 | in |
---|
914 | let 〈labels, pc_costs〉 ≝ result in |
---|
915 | let 〈pc, costs〉 ≝ pc_costs in |
---|
916 | 〈labels, costs〉. |
---|
917 | [3: whd % // #id normalize in ⊢ (% → ?) #abs @⊥ // |
---|
918 | | whd cases construct in p3 #PC #CODE #JMEQ % |
---|
919 | [ @(tech_pc_sigma0_append ??????????? (jmeq_to_eq ??? JMEQ)) | #id #Hid ] |
---|
920 | | (* dummy case *) @⊥ |
---|
921 | @(tech_pc_sigma0_append_None ?? prefix ???? (jmeq_to_eq ??? p3)) ] |
---|
922 | [*: generalize in match (sig2 … t) whd in ⊢ (% → ?) |
---|
923 | >p whd in ⊢ (% → ?) >p1 * #IH0 #IH1 >IH0 // ] |
---|
924 | whd in ⊢ (??(????%?)?) -labels1; |
---|
925 | cases label in Hid |
---|
926 | [ #Hid whd in ⊢ (??(????%?)?) >IH1 -IH1 |
---|
927 | [ >(address_of_word_labels_code_mem_None … Hid) |
---|
928 | (* MANCA LEMMA: INDIRIZZO TROVATO NEL PROGRAMMA! *) |
---|
929 | | whd in Hid >occurs_exactly_once_None in Hid // ] |
---|
930 | | -label #label #Hid whd in ⊢ (??(????%?)?) |
---|
931 | |
---|
932 | ] |
---|
933 | qed. |
---|
934 | |
---|
935 | (* |
---|
936 | (* |
---|
937 | notation < "hvbox('let' 〈ident x,ident y〉 ≝ t 'in' s)" |
---|
938 | with precedence 10 |
---|
939 | for @{ match $t with [ pair ${ident x} ${ident y} ⇒ $s ] }. |
---|
940 | *) |
---|
941 | |
---|
942 | lemma build_maps_ok: |
---|
943 | ∀p:pseudo_assembly_program. |
---|
944 | let 〈labels,costs〉 ≝ build_maps' p in |
---|
945 | ∀pc. |
---|
946 | (nat_of_bitvector … pc) < length … (\snd p) → |
---|
947 | lookup ?? pc labels (zero …) = sigma p (\snd (fetch_pseudo_instruction (\snd p) pc)). |
---|
948 | #p cases p #preamble #instr_list |
---|
949 | elim instr_list |
---|
950 | [ whd #pc #abs normalize in abs; cases (not_le_Sn_O ?) [#H cases (H abs) ] |
---|
951 | | #hd #tl #IH |
---|
952 | whd in ⊢ (match % with [ _ ⇒ ?]) |
---|
953 | ] |
---|
954 | qed. |
---|
955 | *) |
---|
956 | |
---|
957 | (* |
---|
958 | lemma list_elim_rev: |
---|
959 | ∀A:Type[0].∀P:list A → Prop. |
---|
960 | P [ ] → (∀n,l. length l = n → P l → |
---|
961 | P [ ] → (∀l,a. P l → P (l@[a])) → |
---|
962 | ∀l. P l. |
---|
963 | #A #P |
---|
964 | qed.*) |
---|
965 | |
---|
966 | lemma rev_preserves_length: |
---|
967 | ∀A.∀l. length … (rev A l) = length … l. |
---|
968 | #A #l elim l |
---|
969 | [ % |
---|
970 | | #hd #tl #IH normalize >length_append normalize /2/ ] |
---|
971 | qed. |
---|
972 | |
---|
973 | lemma rev_append: |
---|
974 | ∀A.∀l1,l2. |
---|
975 | rev A (l1@l2) = rev A l2 @ rev A l1. |
---|
976 | #A #l1 elim l1 normalize // |
---|
977 | qed. |
---|
978 | |
---|
979 | lemma rev_rev: ∀A.∀l. rev … (rev A l) = l. |
---|
980 | #A #l elim l |
---|
981 | [ // |
---|
982 | | #hd #tl #IH normalize >rev_append normalize // ] |
---|
983 | qed. |
---|
984 | |
---|
985 | lemma split_len_Sn: |
---|
986 | ∀A:Type[0].∀l:list A.∀len. |
---|
987 | length … l = S len → |
---|
988 | Σl'.Σa. l = l'@[a] ∧ length … l' = len. |
---|
989 | #A #l elim l |
---|
990 | [ normalize #len #abs destruct |
---|
991 | | #hd #tl #IH #len |
---|
992 | generalize in match (rev_rev … tl) |
---|
993 | cases (rev A tl) in ⊢ (??%? → ?) |
---|
994 | [ #H <H normalize #EQ % [@[ ]] % [@hd] normalize /2/ |
---|
995 | | #a #l' #H <H normalize #EQ |
---|
996 | %[@(hd::rev … l')] %[@a] % // |
---|
997 | >length_append in EQ #EQ normalize in EQ; normalize; |
---|
998 | generalize in match (injective_S … EQ) #EQ2 /2/ ]] |
---|
999 | qed. |
---|
1000 | |
---|
1001 | lemma list_elim_rev: |
---|
1002 | ∀A:Type[0].∀P:list A → Type[0]. |
---|
1003 | P [ ] → (∀l,a. P l → P (l@[a])) → |
---|
1004 | ∀l. P l. |
---|
1005 | #A #P #H1 #H2 #l |
---|
1006 | generalize in match (refl … (length … l)) |
---|
1007 | generalize in ⊢ (???% → ?) #n generalize in match l |
---|
1008 | elim n |
---|
1009 | [ #L cases L [ // | #x #w #abs (normalize in abs) @⊥ // ] |
---|
1010 | | #m #IH #L #EQ |
---|
1011 | cases (split_len_Sn … EQ) #l' * #a * /3/ ] |
---|
1012 | qed. |
---|
1013 | |
---|
1014 | axiom is_prefix: ∀A:Type[0]. list A → list A → Prop. |
---|
1015 | axiom prefix_of_append: |
---|
1016 | ∀A:Type[0].∀l,l1,l2:list A. |
---|
1017 | is_prefix … l l1 → is_prefix … l (l1@l2). |
---|
1018 | axiom prefix_reflexive: ∀A,l. is_prefix A l l. |
---|
1019 | axiom nil_prefix: ∀A,l. is_prefix A [ ] l. |
---|
1020 | |
---|
1021 | record Propify (A:Type[0]) : Type[0] (*Prop*) ≝ { in_propify: A }. |
---|
1022 | |
---|
1023 | definition Propify_elim: ∀A. ∀P:Prop. (A → P) → (Propify A → P) ≝ |
---|
1024 | λA,P,H,x. match x with [ mk_Propify p ⇒ H p ]. |
---|
1025 | |
---|
1026 | definition app ≝ |
---|
1027 | λA:Type[0].λl1:Propify (list A).λl2:list A. |
---|
1028 | match l1 with |
---|
1029 | [ mk_Propify l1 ⇒ mk_Propify … (l1@l2) ]. |
---|
1030 | |
---|
1031 | lemma app_nil: ∀A,l1. app A l1 [ ] = l1. |
---|
1032 | #A * /3/ |
---|
1033 | qed. |
---|
1034 | |
---|
1035 | lemma app_assoc: ∀A,l1,l2,l3. app A (app A l1 l2) l3 = app A l1 (l2@l3). |
---|
1036 | #A * #l1 normalize // |
---|
1037 | qed. |
---|
1038 | |
---|
1039 | let rec foldli (A: Type[0]) (B: Propify (list A) → Type[0]) |
---|
1040 | (f: ∀prefix. B prefix → ∀x.B (app … prefix [x])) |
---|
1041 | (prefix: Propify (list A)) (b: B prefix) (l: list A) on l : |
---|
1042 | B (app … prefix l) ≝ |
---|
1043 | match l with |
---|
1044 | [ nil ⇒ ? (* b *) |
---|
1045 | | cons hd tl ⇒ ? (*foldli A B f (prefix@[hd]) (f prefix b hd) tl*) |
---|
1046 | ]. |
---|
1047 | [ applyS b |
---|
1048 | | <(app_assoc ?? [hd]) @(foldli A B f (app … prefix [hd]) (f prefix b hd) tl) ] |
---|
1049 | qed. |
---|
1050 | |
---|
1051 | (* |
---|
1052 | let rec foldli (A: Type[0]) (B: list A → Type[0]) (f: ∀prefix. B prefix → ∀x. B (prefix@[x])) |
---|
1053 | (prefix: list A) (b: B prefix) (l: list A) on l : B (prefix@l) ≝ |
---|
1054 | match l with |
---|
1055 | [ nil ⇒ ? (* b *) |
---|
1056 | | cons hd tl ⇒ |
---|
1057 | ? (*foldli A B f (prefix@[hd]) (f prefix b hd) tl*) |
---|
1058 | ]. |
---|
1059 | [ applyS b |
---|
1060 | | applyS (foldli A B f (prefix@[hd]) (f prefix b hd) tl) ] |
---|
1061 | qed. |
---|
1062 | *) |
---|
1063 | |
---|
1064 | definition foldll: |
---|
1065 | ∀A:Type[0].∀B: Propify (list A) → Type[0]. |
---|
1066 | (∀prefix. B prefix → ∀x. B (app … prefix [x])) → |
---|
1067 | B (mk_Propify … []) → ∀l: list A. B (mk_Propify … l) |
---|
1068 | ≝ λA,B,f. foldli A B f (mk_Propify … [ ]). |
---|
1069 | |
---|
1070 | axiom is_pprefix: ∀A:Type[0]. Propify (list A) → list A → Prop. |
---|
1071 | axiom pprefix_of_append: |
---|
1072 | ∀A:Type[0].∀l,l1,l2. |
---|
1073 | is_pprefix A l l1 → is_pprefix A l (l1@l2). |
---|
1074 | axiom pprefix_reflexive: ∀A,l. is_pprefix A (mk_Propify … l) l. |
---|
1075 | axiom nil_pprefix: ∀A,l. is_pprefix A (mk_Propify … [ ]) l. |
---|
1076 | |
---|
1077 | |
---|
1078 | axiom foldll': |
---|
1079 | ∀A:Type[0].∀l: list A. |
---|
1080 | ∀B: ∀prefix:Propify (list A). is_pprefix ? prefix l → Type[0]. |
---|
1081 | (∀prefix,proof. B prefix proof → ∀x,proof'. B (app … prefix [x]) proof') → |
---|
1082 | B (mk_Propify … [ ]) (nil_pprefix …) → B (mk_Propify … l) (pprefix_reflexive … l). |
---|
1083 | #A #l #B |
---|
1084 | generalize in match (foldll A (λprefix. is_pprefix ? prefix l)) #HH |
---|
1085 | |
---|
1086 | |
---|
1087 | #H #acc |
---|
1088 | @foldll |
---|
1089 | [ |
---|
1090 | | |
---|
1091 | ] |
---|
1092 | |
---|
1093 | ≝ λA,B,f. foldli A B f (mk_Propify … [ ]). |
---|
1094 | |
---|
1095 | |
---|
1096 | (* |
---|
1097 | record subset (A:Type[0]) (P: A → Prop): Type[0] ≝ |
---|
1098 | { subset_wit:> A; |
---|
1099 | subset_proof: P subset_wit |
---|
1100 | }. |
---|
1101 | *) |
---|
1102 | |
---|
1103 | definition build_maps' ≝ |
---|
1104 | λpseudo_program. |
---|
1105 | let 〈preamble,instr_list〉 ≝ pseudo_program in |
---|
1106 | let result ≝ |
---|
1107 | foldll |
---|
1108 | (option Identifier × pseudo_instruction) |
---|
1109 | (λprefix. |
---|
1110 | Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
1111 | match prefix return λ_.Prop with [mk_Propify prefix ⇒ tech_pc_sigma0 〈preamble,prefix〉 ≠ None ?]) |
---|
1112 | (λprefix,t,i. |
---|
1113 | let 〈labels, pc_costs〉 ≝ t in |
---|
1114 | let 〈program_counter, costs〉 ≝ pc_costs in |
---|
1115 | let 〈label, i'〉 ≝ i in |
---|
1116 | let labels ≝ |
---|
1117 | match label with |
---|
1118 | [ None ⇒ labels |
---|
1119 | | Some label ⇒ |
---|
1120 | let program_counter_bv ≝ bitvector_of_nat ? program_counter in |
---|
1121 | insert ? ? label program_counter_bv labels |
---|
1122 | ] |
---|
1123 | in |
---|
1124 | match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with |
---|
1125 | [ None ⇒ |
---|
1126 | let dummy ≝ 〈labels,pc_costs〉 in |
---|
1127 | dummy |
---|
1128 | | Some construct ⇒ 〈labels, construct〉 |
---|
1129 | ] |
---|
1130 | ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 instr_list |
---|
1131 | in |
---|
1132 | let 〈labels, pc_costs〉 ≝ result in |
---|
1133 | let 〈pc, costs〉 ≝ pc_costs in |
---|
1134 | 〈labels, costs〉. |
---|
1135 | [ |
---|
1136 | | @⊥ |
---|
1137 | | normalize % // |
---|
1138 | ] |
---|
1139 | qed. |
---|
1140 | |
---|
1141 | definition build_maps' ≝ |
---|
1142 | λpseudo_program. |
---|
1143 | let 〈preamble,instr_list〉 ≝ pseudo_program in |
---|
1144 | let result ≝ |
---|
1145 | foldl |
---|
1146 | (Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
1147 | ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧ |
---|
1148 | tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t))) |
---|
1149 | (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
1150 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
1151 | is_prefix ? instr_list_prefix' instr_list → |
---|
1152 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?) |
---|
1153 | (λt: Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))). |
---|
1154 | ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧ |
---|
1155 | tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t)). |
---|
1156 | λi: Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
1157 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
1158 | is_prefix ? instr_list_prefix' instr_list → |
---|
1159 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ? . |
---|
1160 | let 〈labels, pc_costs〉 ≝ t in |
---|
1161 | let 〈program_counter, costs〉 ≝ pc_costs in |
---|
1162 | let 〈label, i'〉 ≝ i in |
---|
1163 | let labels ≝ |
---|
1164 | match label with |
---|
1165 | [ None ⇒ labels |
---|
1166 | | Some label ⇒ |
---|
1167 | let program_counter_bv ≝ bitvector_of_nat ? program_counter in |
---|
1168 | insert ? ? label program_counter_bv labels |
---|
1169 | ] |
---|
1170 | in |
---|
1171 | match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with |
---|
1172 | [ None ⇒ |
---|
1173 | let dummy ≝ 〈labels,pc_costs〉 in |
---|
1174 | dummy |
---|
1175 | | Some construct ⇒ 〈labels, construct〉 |
---|
1176 | ] |
---|
1177 | ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 ?(*instr_list*) |
---|
1178 | in |
---|
1179 | let 〈labels, pc_costs〉 ≝ result in |
---|
1180 | let 〈pc, costs〉 ≝ pc_costs in |
---|
1181 | 〈labels, costs〉. |
---|
1182 | [4: @(list_elim_rev ? |
---|
1183 | (λinstr_list. list ( |
---|
1184 | (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix. |
---|
1185 | let instr_list_prefix' ≝ instr_list_prefix @ [i] in |
---|
1186 | is_prefix ? instr_list_prefix' instr_list → |
---|
1187 | tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?))) |
---|
1188 | ?? instr_list) (* CSC: BAD ORDER FOR CODE EXTRACTION *) |
---|
1189 | [ @[ ] |
---|
1190 | | #l' #a #limage %2 |
---|
1191 | [ %[@a] #PREFIX #PREFIX_OK |
---|
1192 | | (* CSC: EVEN WORST CODE FOR EXTRACTION: WE SHOULD STRENGTHEN |
---|
1193 | THE INDUCTION HYPOTHESIS INSTEAD *) |
---|
1194 | elim limage |
---|
1195 | [ %1 |
---|
1196 | | #HD #TL #IH @(?::IH) cases HD #ELEM #K1 %[@ELEM] #K2 #K3 |
---|
1197 | @K1 @(prefix_of_append ???? K3) |
---|
1198 | ] |
---|
1199 | ] |
---|
1200 | |
---|
1201 | |
---|
1202 | |
---|
1203 | |
---|
1204 | cases t in c2 ⊢ % #t' * #LIST_PREFIX * #H1t' #H2t' #HJMt' |
---|
1205 | % [@ (LIST_PREFIX @ [i])] % |
---|
1206 | [ cases (sig2 … i LIST_PREFIX) #K1 #K2 @K1 |
---|
1207 | | (* DOABLE IN PRINCIPLE *) |
---|
1208 | ] |
---|
1209 | | (* assert false case *) |
---|
1210 | |3: % [@ ([ ])] % [2: % | (* DOABLE *)] |
---|
1211 | | |
---|
1212 | |
---|
1213 | definition assembly_specification: |
---|
1214 | ∀assembly_program: pseudo_assembly_program. |
---|
1215 | ∀code_mem: BitVectorTrie Byte 16. Prop ≝ |
---|
1216 | λpseudo_assembly_program. |
---|
1217 | λcode_mem. |
---|
1218 | ∀pc: Word. |
---|
1219 | let 〈preamble, instr_list〉 ≝ pseudo_assembly_program in |
---|
1220 | let 〈pre_instr, pre_new_pc〉 ≝ fetch_pseudo_instruction instr_list pc in |
---|
1221 | let labels ≝ λx. sigma' pseudo_assembly_program (address_of_word_labels_code_mem instr_list x) in |
---|
1222 | let datalabels ≝ λx. sigma' pseudo_assembly_program (lookup ? ? x (construct_datalabels preamble) (zero ?)) in |
---|
1223 | let pre_assembled ≝ assembly_1_pseudoinstruction pseudo_assembly_program |
---|
1224 | (sigma' pseudo_assembly_program pc) labels datalabels pre_instr in |
---|
1225 | match pre_assembled with |
---|
1226 | [ None ⇒ True |
---|
1227 | | Some pc_code ⇒ |
---|
1228 | let 〈new_pc,code〉 ≝ pc_code in |
---|
1229 | encoding_check code_mem pc (sigma' pseudo_assembly_program pre_new_pc) code ]. |
---|
1230 | |
---|
1231 | axiom assembly_meets_specification: |
---|
1232 | ∀pseudo_assembly_program. |
---|
1233 | match assembly pseudo_assembly_program with |
---|
1234 | [ None ⇒ True |
---|
1235 | | Some code_mem_cost ⇒ |
---|
1236 | let 〈code_mem, cost〉 ≝ code_mem_cost in |
---|
1237 | assembly_specification pseudo_assembly_program (load_code_memory code_mem) |
---|
1238 | ]. |
---|
1239 | (* |
---|
1240 | # PROGRAM |
---|
1241 | [ cases PROGRAM |
---|
1242 | # PREAMBLE |
---|
1243 | # INSTR_LIST |
---|
1244 | elim INSTR_LIST |
---|
1245 | [ whd |
---|
1246 | whd in ⊢ (∀_. %) |
---|
1247 | # PC |
---|
1248 | whd |
---|
1249 | | # INSTR |
---|
1250 | # INSTR_LIST_TL |
---|
1251 | # H |
---|
1252 | whd |
---|
1253 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?]) |
---|
1254 | ] |
---|
1255 | | cases not_implemented |
---|
1256 | ] *) |
---|
1257 | |
---|
1258 | definition status_of_pseudo_status: PseudoStatus → option Status ≝ |
---|
1259 | λps. |
---|
1260 | let pap ≝ code_memory … ps in |
---|
1261 | match assembly pap with |
---|
1262 | [ None ⇒ None … |
---|
1263 | | Some p ⇒ |
---|
1264 | let cm ≝ load_code_memory (\fst p) in |
---|
1265 | let pc ≝ sigma' pap (program_counter ? ps) in |
---|
1266 | Some … |
---|
1267 | (mk_PreStatus (BitVectorTrie Byte 16) |
---|
1268 | cm |
---|
1269 | (low_internal_ram … ps) |
---|
1270 | (high_internal_ram … ps) |
---|
1271 | (external_ram … ps) |
---|
1272 | pc |
---|
1273 | (special_function_registers_8051 … ps) |
---|
1274 | (special_function_registers_8052 … ps) |
---|
1275 | (p1_latch … ps) |
---|
1276 | (p3_latch … ps) |
---|
1277 | (clock … ps)) ]. |
---|
1278 | |
---|
1279 | definition write_at_stack_pointer': |
---|
1280 | ∀M. ∀ps: PreStatus M. Byte → Σps':PreStatus M.(code_memory … ps = code_memory … ps') ≝ |
---|
1281 | λM: Type[0]. |
---|
1282 | λs: PreStatus M. |
---|
1283 | λv: Byte. |
---|
1284 | let 〈 nu, nl 〉 ≝ split … 4 4 (get_8051_sfr ? s SFR_SP) in |
---|
1285 | let bit_zero ≝ get_index_v… nu O ? in |
---|
1286 | let bit_1 ≝ get_index_v… nu 1 ? in |
---|
1287 | let bit_2 ≝ get_index_v… nu 2 ? in |
---|
1288 | let bit_3 ≝ get_index_v… nu 3 ? in |
---|
1289 | if bit_zero then |
---|
1290 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
1291 | v (low_internal_ram ? s) in |
---|
1292 | set_low_internal_ram ? s memory |
---|
1293 | else |
---|
1294 | let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl) |
---|
1295 | v (high_internal_ram ? s) in |
---|
1296 | set_high_internal_ram ? s memory. |
---|
1297 | [ cases l0 % |
---|
1298 | |2,3,4,5: normalize repeat (@ le_S_S) @ le_O_n ] |
---|
1299 | qed. |
---|
1300 | |
---|
1301 | definition execute_1_pseudo_instruction': (Word → nat) → ∀ps:PseudoStatus. |
---|
1302 | Σps':PseudoStatus.(code_memory … ps = code_memory … ps') |
---|
1303 | ≝ |
---|
1304 | λticks_of. |
---|
1305 | λs. |
---|
1306 | let 〈instr, pc〉 ≝ fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s) in |
---|
1307 | let ticks ≝ ticks_of (program_counter ? s) in |
---|
1308 | let s ≝ set_clock ? s (clock ? s + ticks) in |
---|
1309 | let s ≝ set_program_counter ? s pc in |
---|
1310 | match instr with |
---|
1311 | [ Instruction instr ⇒ |
---|
1312 | execute_1_preinstruction … (λx, y. address_of_word_labels y x) instr s |
---|
1313 | | Comment cmt ⇒ s |
---|
1314 | | Cost cst ⇒ s |
---|
1315 | | Jmp jmp ⇒ set_program_counter ? s (address_of_word_labels s jmp) |
---|
1316 | | Call call ⇒ |
---|
1317 | let a ≝ address_of_word_labels s call in |
---|
1318 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
1319 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
1320 | let 〈pc_bu, pc_bl〉 ≝ split ? 8 8 (program_counter ? s) in |
---|
1321 | let s ≝ write_at_stack_pointer' ? s pc_bl in |
---|
1322 | let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in |
---|
1323 | let s ≝ set_8051_sfr ? s SFR_SP new_sp in |
---|
1324 | let s ≝ write_at_stack_pointer' ? s pc_bu in |
---|
1325 | set_program_counter ? s a |
---|
1326 | | Mov dptr ident ⇒ |
---|
1327 | set_arg_16 ? s (get_arg_16 ? s (DATA16 (address_of_word_labels s ident))) dptr |
---|
1328 | ]. |
---|
1329 | [ |
---|
1330 | |2,3,4: % |
---|
1331 | | <(sig2 … l7) whd in ⊢ (??? (??%)) <(sig2 … l5) % |
---|
1332 | | |
---|
1333 | | % |
---|
1334 | ] |
---|
1335 | cases not_implemented |
---|
1336 | qed. |
---|
1337 | |
---|
1338 | (* |
---|
1339 | lemma execute_code_memory_unchanged: |
---|
1340 | ∀ticks_of,ps. code_memory ? ps = code_memory ? (execute_1_pseudo_instruction ticks_of ps). |
---|
1341 | #ticks #ps whd in ⊢ (??? (??%)) |
---|
1342 | cases (fetch_pseudo_instruction (\snd (code_memory pseudo_assembly_program ps)) |
---|
1343 | (program_counter pseudo_assembly_program ps)) #instr #pc |
---|
1344 | whd in ⊢ (??? (??%)) cases instr |
---|
1345 | [ #pre cases pre |
---|
1346 | [ #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
1347 | cases (split ????) #z1 #z2 % |
---|
1348 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
1349 | cases (split ????) #z1 #z2 % |
---|
1350 | | #a1 #a2 whd in ⊢ (??? (??%)) cases (sub_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%)) |
---|
1351 | cases (split ????) #z1 #z2 % |
---|
1352 | | #a1 whd in ⊢ (??? (??%)) cases a1 #x #H whd in ⊢ (??? (??%)) cases x |
---|
1353 | [ #x1 whd in ⊢ (??? (??%)) |
---|
1354 | | *: cases not_implemented |
---|
1355 | ] |
---|
1356 | | #comment % |
---|
1357 | | #cost % |
---|
1358 | | #label % |
---|
1359 | | #label whd in ⊢ (??? (??%)) cases (half_add ???) #x1 #x2 whd in ⊢ (??? (??%)) |
---|
1360 | cases (split ????) #y1 #y2 whd in ⊢ (??? (??%)) cases (half_add ???) #z1 #z2 |
---|
1361 | whd in ⊢ (??? (??%)) whd in ⊢ (??? (??%)) cases (split ????) #w1 #w2 |
---|
1362 | whd in ⊢ (??? (??%)) cases (get_index_v bool ????) whd in ⊢ (??? (??%)) |
---|
1363 | (* CSC: ??? *) |
---|
1364 | | #dptr #label (* CSC: ??? *) |
---|
1365 | ] |
---|
1366 | cases not_implemented |
---|
1367 | qed. |
---|
1368 | *) |
---|
1369 | |
---|
1370 | lemma status_of_pseudo_status_failure_depends_only_on_code_memory: |
---|
1371 | ∀ps,ps': PseudoStatus. |
---|
1372 | code_memory … ps = code_memory … ps' → |
---|
1373 | match status_of_pseudo_status ps with |
---|
1374 | [ None ⇒ status_of_pseudo_status ps' = None … |
---|
1375 | | Some _ ⇒ ∃w. status_of_pseudo_status ps' = Some … w |
---|
1376 | ]. |
---|
1377 | #ps #ps' #H whd in ⊢ (mat |
---|
1378 | ch % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
1379 | generalize in match (refl … (assembly (code_memory … ps))) |
---|
1380 | cases (assembly ?) in ⊢ (???% → %) |
---|
1381 | [ #K whd whd in ⊢ (??%?) <H >K % |
---|
1382 | | #x #K whd whd in ⊢ (?? (λ_.??%?)) <H >K % [2: % ] ] |
---|
1383 | qed.*) |
---|
1384 | |
---|
1385 | let rec encoding_check' (code_memory: BitVectorTrie Byte 16) (pc: Word) (encoding: list Byte) on encoding: Prop ≝ |
---|
1386 | match encoding with |
---|
1387 | [ nil ⇒ True |
---|
1388 | | cons hd tl ⇒ |
---|
1389 | let 〈new_pc, byte〉 ≝ next code_memory pc in |
---|
1390 | hd = byte ∧ encoding_check' code_memory new_pc tl |
---|
1391 | ]. |
---|
1392 | |
---|
1393 | lemma main_thm: |
---|
1394 | ∀ticks_of. |
---|
1395 | ∀ps: PseudoStatus. |
---|
1396 | match status_of_pseudo_status ps with [ None ⇒ True | Some s ⇒ |
---|
1397 | let ps' ≝ execute_1_pseudo_instruction ticks_of ps in |
---|
1398 | match status_of_pseudo_status ps' with [ None ⇒ True | Some s'' ⇒ |
---|
1399 | let s' ≝ execute_1 s in |
---|
1400 | s = s'']]. |
---|
1401 | #ticks_of #ps |
---|
1402 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
1403 | cases (assembly (code_memory pseudo_assembly_program ps)) [%] * #cm #costs whd |
---|
1404 | whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ]) |
---|
1405 | generalize in match (sig2 … (execute_1_pseudo_instruction' ticks_of ps)) |
---|
1406 | |
---|
1407 | cases (status_of_pseudo_status (execute_1_pseudo_instruction ticks_of ps)) [%] #s'' whd |
---|