# source:src/ASM/AssemblyProof.ma@869

Last change on this file since 869 was 869, checked in by sacerdot, 10 years ago

More progress.

File size: 38.0 KB
Line
1include "ASM/Assembly.ma".
2include "ASM/Interpret.ma".
3
4(* RUSSEL **)
5
6include "basics/jmeq.ma".
7
8notation > "hvbox(a break ≃ b)"
9  non associative with precedence 45
10for @{ 'jmeq ? \$a ? \$b }.
11
12notation < "hvbox(term 46 a break maction (≃) (≃\sub(t,u)) term 46 b)"
13  non associative with precedence 45
14for @{ 'jmeq \$t \$a \$u \$b }.
15
16interpretation "john major's equality" 'jmeq t x u y = (jmeq t x u y).
17
18lemma eq_to_jmeq:
19  ∀A: Type[0].
20  ∀x, y: A.
21    x = y → x ≃ y.
22  //
23qed.
24
25definition inject : ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ λA,P,a,p. dp … a p.
26definition eject : ∀A.∀P: A → Prop.(Σx:A.P x) → A ≝ λA,P,c.match c with [ dp w p ⇒ w].
27
28coercion inject nocomposites: ∀A.∀P:A → Prop.∀a.∀p:P a.Σx:A.P x ≝ inject on a:? to Σx:?.?.
29coercion eject nocomposites: ∀A.∀P:A → Prop.∀c:Σx:A.P x.A ≝ eject on _c:Σx:?.? to ?.
30
31axiom VOID: Type[0].
32axiom assert_false: VOID.
33definition bigbang: ∀A:Type[0].False → VOID → A.
34 #A #abs cases abs
35qed.
36
37coercion bigbang nocomposites: ∀A:Type[0].False → ∀v:VOID.A ≝ bigbang on _v:VOID to ?.
38
39lemma sig2: ∀A.∀P:A → Prop. ∀p:Σx:A.P x. P (eject … p).
40 #A #P #p cases p #w #q @q
41qed.
42
43lemma jmeq_to_eq: ∀A:Type[0]. ∀x,y:A. x≃y → x=y.
44 #A #x #y #JMEQ @(jmeq_elim ? x … JMEQ) %
45qed.
46
47coercion 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
51let 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  ]
67qed.
68
69definition 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
77definition bit_elim: ∀P: bool → bool. bool ≝
78  λP.
79    P true ∧ P false.
80
81let 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  ].
96qed.
97
98definition 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  ]
106qed.
107
108axiom 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
118lemma 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  ]
131qed.
132
133lemma 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 //
138qed.
139
140lemma 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  ]
161qed.
162
163lemma 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  ]
182qed.
183
184lemma 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    ]
222qed.
223
224lemma 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  ]
234qed.
235
236corollary 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 ]])
248qed.
249
250lemma eq_a_reflexive:
251  ∀a. eq_a a a = true.
252  # A
253  cases A
254  %
255qed.
256
257lemma is_in_monotonic_wrt_append:
258  ∀m, n: nat.
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  ]
278qed.
279
280corollary is_in_hd_tl:
283  ∀n: nat.
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  ]
297qed.
298
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
323      | relative ⇒ λP.bitvector_elim 8 (λx. P (RELATIVE 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  | cases prf in tl H; #tl
336    normalize in ⊢ (∀_: %. ?)
337    # H
338    whd
339    normalize in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?])
340    cases (is_a hd (subaddressing_modeel y tl H)) whd // ]
341qed.
342
343definition product_elim ≝
344  λm, n: nat.
345  λv: Vector addressing_mode_tag (S m).
346  λq: Vector addressing_mode_tag (S n).
347  λP: (Vector addressing_mode_tag (S m) × (Vector addressing_mode_tag (S n))) → bool.
348    P 〈v, q〉.
349
350axiom union_elim:
351  ∀m, n: nat. ((Vector addressing_mode_tag m ⊎ Vector addressing_mode_tag n) → bool) → bool.
352
353definition preinstruction_elim: ∀P: preinstruction [[ relative ]] → bool. bool ≝
354  λP.
357    list_addressing_mode_tags_elim ? [[ registr ; direct ; indirect ; data ]] (λaddr. P (SUBB ? ACC_A addr)) ∧
358    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ; dptr ]] (λaddr. P (INC ? addr)) ∧
359    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (DEC ? addr)) ∧
365    P (DA ? ACC_A) ∧
366    P (JC ? ?) ∧
367    P (JNC ? ?) ∧
368    P (JZ ? ?) ∧
369    P (JNZ ? ?) ∧
370    bitvector_elim 8 (λx. P (JB ? (BIT_ADDR x))). ∧
371    P (JNB ? [[ bit_addr ]] ?) ∧
372    P (JBC ? [[ bit_addr ]] ?) ∧
373    P (RL ? ACC_A).
374
375
376
377
378
379
381
382    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (ANL ? addr)) ∧
383    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (ORL ? addr)) ∧
384    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (XRL ? addr)) ∧
385    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (RL ? addr)) ∧
386    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (RLC ? addr)) ∧
387    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (RR ? addr)) ∧
388    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (RRC ? addr)) ∧
389    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (SWAP ? addr)) ∧
390    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (MOV ? addr)) ∧
391    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (MOVX ? addr)) ∧
392    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (SETB ? addr)) ∧
393    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (PUSH ? addr)) ∧
394    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (POP ? addr)) ∧
395    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (XCH ? addr)) ∧
396    list_addressing_mode_tags_elim ? [[ acc_a ; registr ; direct ; indirect ]] (λaddr. P (XCHD ? addr)) ∧
397    P (RET ?) ∧
398    P (RETI ?) ∧
399    P (NOP ?).
400
401
402definition instruction_elim: ∀P: instruction → bool. bool.
403
404
405lemma instruction_elim_correct:
406  ∀i: instruction.
407  ∀P: instruction → bool.
408    instruction_elim P = true → ∀j. P j = true.
409
410lemma test:
411  ∀i: instruction.
412  ∃pc.
413  let assembled ≝ assembly1 i in
414  let code_memory ≝ load_code_memory assembled in
415  let fetched ≝ fetch code_memory pc in
416  let 〈instr_pc, ticks〉 ≝ fetched in
417    \fst instr_pc = i.
418  # INSTR
419  @ (ex_intro ?)
420  [ @ (zero 16)
421  | @ (instruction_elim INSTR)
422  ].
423
424(* This establishes the correspondence between pseudo program counters and
425   program counters. It is at the heart of the proof. *)
426(*CSC: code taken from build_maps *)
427definition sigma0: pseudo_assembly_program → option (nat × (nat × (BitVectorTrie Word 16))) ≝
428 λinstr_list.
429  foldl ??
430    (λt. λi.
431       match t with
432       [ None ⇒ None ?
433       | Some ppc_pc_map ⇒
434         let 〈ppc,pc_map〉 ≝ ppc_pc_map in
435         let 〈program_counter, sigma_map〉 ≝ pc_map in
436         let 〈label, i〉 ≝ i in
437          match construct_costs instr_list program_counter (λx. zero ?) (λx. zero ?) (Stub …) i with
438           [ None ⇒ None ?
439           | Some pc_ignore ⇒
440              let 〈pc,ignore〉 ≝ pc_ignore in
441              Some … 〈S ppc,〈pc, insert ? ? (bitvector_of_nat ? ppc) (bitvector_of_nat ? pc) sigma_map〉〉 ]
442       ]) (Some ? 〈0, 〈0, (Stub ? ?)〉〉) (\snd instr_list).
443
444definition tech_pc_sigma0: pseudo_assembly_program → option (nat × (BitVectorTrie Word 16)) ≝
445 λinstr_list.
446  match sigma0 instr_list with
447   [ None ⇒ None …
448   | Some result ⇒
449      let 〈ppc,pc_sigma_map〉 ≝ result in
450       Some … pc_sigma_map ].
451
452definition sigma_safe: pseudo_assembly_program → option (Word → Word) ≝
453 λinstr_list.
454  match sigma0 instr_list with
455  [ None ⇒ None ?
456  | Some result ⇒
457    let 〈ppc,pc_sigma_map〉 ≝ result in
458    let 〈pc, sigma_map〉 ≝ pc_sigma_map in
459      if gtb pc (2^16) then
460        None ?
461      else
462        Some ? (λx.lookup ?? x sigma_map (zero …)) ].
463
464axiom policy_ok: ∀p. sigma_safe p ≠ None ….
465
466definition sigma: pseudo_assembly_program → Word → Word ≝
467 λp.
468  match sigma_safe p return λr:option (Word → Word). r ≠ None … → Word → Word with
469   [ None ⇒ λabs. ⊥
470   | Some r ⇒ λ_.r] (policy_ok p).
471 cases abs //
472qed.
473
474lemma length_append:
475 ∀A.∀l1,l2:list A.
476  |l1 @ l2| = |l1| + |l2|.
477 #A #l1 elim l1
478  [ //
479  | #hd #tl #IH #l2 normalize <IH //]
480qed.
481
482let rec does_not_occur (id:Identifier) (l:list labelled_instruction) on l: bool ≝
483 match l with
484  [ nil ⇒ true
485  | cons hd tl ⇒ notb (instruction_matches_identifier id hd) ∧ does_not_occur id tl].
486
487lemma does_not_occur_None:
488 ∀id,i,list_instr.
489  does_not_occur id (list_instr@[〈None …,i〉]) =
490  does_not_occur id list_instr.
491 #id #i #list_instr elim list_instr
492  [ % | #hd #tl #IH whd in ⊢ (??%%) >IH %]
493qed.
494
495let rec occurs_exactly_once (id:Identifier) (l:list labelled_instruction) on l : bool ≝
496 match l with
497  [ nil ⇒ false
498  | cons hd tl ⇒
499     if instruction_matches_identifier id hd then
500      does_not_occur id tl
501     else
502      occurs_exactly_once id tl ].
503
504lemma occurs_exactly_once_None:
505 ∀id,i,list_instr.
506  occurs_exactly_once id (list_instr@[〈None …,i〉]) =
507  occurs_exactly_once id list_instr.
508 #id #i #list_instr elim list_instr
509  [ % | #hd #tl #IH whd in ⊢ (??%%) >IH >does_not_occur_None %]
510qed.
511
512coercion bool_to_Prop: ∀b:bool. Prop ≝ bool_to_Prop on _b:bool to Type[0].
513
514lemma index_of_internal_None: ∀i,id,instr_list,n.
515 occurs_exactly_once id (instr_list@[〈None …,i〉]) →
516  index_of_internal ? (instruction_matches_identifier id) instr_list n =
517   index_of_internal ? (instruction_matches_identifier id) (instr_list@[〈None …,i〉]) n.
518 #i #id #instr_list elim instr_list
519  [ #n #abs whd in abs; cases abs
520  | #hd #tl #IH #n whd in ⊢ (% → ??%%); whd in ⊢ (match % with [_ ⇒ ? | _ ⇒ ?] → ?)
521    cases (instruction_matches_identifier id hd) whd in ⊢ (match % with [_ ⇒ ? | _ ⇒ ?] → ??%%)
522    [ #H %
523    | #H @IH whd in H; cases (occurs_exactly_once ??) in H ⊢ %
524      [ #_ % | #abs cases abs ]]]
525qed.
526
528 occurs_exactly_once id (instr_list@[〈None …,i〉]) →
531 #i #id #instr_list #H whd in ⊢ (??%%) whd in ⊢ (??(??%?)(??%?))
532 >(index_of_internal_None … H) %
533qed.
534
535axiom tech_pc_sigma0_append:
536 ∀preamble,instr_list,prefix,label,i,pc',code,pc,costs,costs'.
537  Some … 〈pc,costs〉 = tech_pc_sigma0 〈preamble,prefix〉 →
538   construct_costs 〈preamble,instr_list〉 … pc (λx.zero 16) (λx. zero 16) costs i = Some … 〈pc',code〉 →
539    tech_pc_sigma0 〈preamble,prefix@[〈label,i〉]〉 = Some … 〈pc',costs'〉.
540
541axiom tech_pc_sigma0_append_None:
542 ∀preamble,instr_list,prefix,i,pc,costs.
543  Some … 〈pc,costs〉 = tech_pc_sigma0 〈preamble,prefix〉 →
544   construct_costs 〈preamble,instr_list〉 … pc (λx.zero 16) (λx. zero 16) costs i = None …
545    → False.
546
547lemma BitVectorTrie_O:
548 ∀A:Type[0].∀v:BitVectorTrie A 0.(∃w. v ≃ Leaf A w) ∨ v ≃ Stub A 0.
549 #A #v generalize in match (refl … O) cases v in ⊢ (??%? → (?(??(λ_.?%%??)))(?%%??))
550  [ #w #_ %1 %[@w] %
551  | #n #l #r #abs @⊥ //
552  | #n #EQ %2 >EQ %]
553qed.
554
555lemma BitVectorTrie_Sn:
556 ∀A:Type[0].∀n.∀v:BitVectorTrie A (S n).(∃l,r. v ≃ Node A n l r) ∨ v ≃ Stub A (S n).
557 #A #n #v generalize in match (refl … (S n)) cases v in ⊢ (??%? → (?(??(λ_.??(λ_.?%%??))))%)
558  [ #m #abs @⊥ //
559  | #m #l #r #EQ %1 <(injective_S … EQ) %[@l] %[@r] //
560  | #m #EQ %2 // ]
561qed.
562
563lemma lookup_prepare_trie_for_insertion_hit:
564 ∀A:Type[0].∀a,v:A.∀n.∀b:BitVector n.
565  lookup … b (prepare_trie_for_insertion … b v) a = v.
566 #A #a #v #n #b elim b // #m #hd #tl #IH cases hd normalize //
567qed.
568
569lemma lookup_insert_hit:
570 ∀A:Type[0].∀a,v:A.∀n.∀b:BitVector n.∀t:BitVectorTrie A n.
571  lookup … b (insert … b v t) a = v.
572 #A #a #v #n #b elim b -b -n //
573 #n #hd #tl #IH #t cases(BitVectorTrie_Sn … t)
574  [ * #l * #r #JMEQ >JMEQ cases hd normalize //
575  | #JMEQ >JMEQ cases hd normalize @lookup_prepare_trie_for_insertion_hit ]
576qed.
577
578lemma BitVector_O: ∀v:BitVector 0. v ≃ VEmpty bool.
579 #v generalize in match (refl … 0) cases v in ⊢ (??%? → ?%%??) //
580 #n #hd #tl #abs @⊥ //
581qed.
582
583lemma BitVector_Sn: ∀n.∀v:BitVector (S n).
584 ∃hd.∃tl.v ≃ VCons bool n hd tl.
585 #n #v generalize in match (refl … (S n)) cases v in ⊢ (??%? → ??(λ_.??(λ_.?%%??)))
586 [ #abs @⊥ //
587 | #m #hd #tl #EQ <(injective_S … EQ) %[@hd] %[@tl] // ]
588qed.
589
590lemma lookup_insert_miss:
591 ∀A:Type[0].∀a,v:A.∀n.∀c,b:BitVector n.∀t:BitVectorTrie A n.
592  (notb (eq_bv ? b c)) → lookup … b (insert … c v t) a = lookup … b t a.
593 #A #a #v #n #c elim c -c -n
594  [ #b #t #DIFF @⊥ whd in DIFF; >(BitVector_O … b) in DIFF //
595  | #n #hd #tl #IH #b cases(BitVector_Sn … b) #hd' * #tl' #JMEQ >JMEQ
596    #t cases(BitVectorTrie_Sn … t)
597    [ * #l * #r #JMEQ >JMEQ cases hd #H CSC
598     normalize in H;
599
600      normalize //
601    | #JMEQ >JMEQ cases hd normalize @lookup_prepare_trie_for_insertion_hit ]
602qed.
603
604definition build_maps' ≝
605  λpseudo_program.
606  let 〈preamble,instr_list〉 ≝ pseudo_program in
607  let result ≝
608   foldl_strong
609    (option Identifier × pseudo_instruction)
610    (λpre. Σres:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))).
611      let pre' ≝ 〈preamble,pre〉 in
612      let 〈labels,pc_costs〉 ≝ res in
613       tech_pc_sigma0 pre' = Some … pc_costs ∧
614       ∀id. occurs_exactly_once id pre →
615        lookup ?? id labels (zero …) = sigma pre' (address_of_word_labels_code_mem pre id))
616    instr_list
617    (λprefix,i,tl,prf,t.
618      let 〈labels, pc_costs〉 ≝ t in
619      let 〈program_counter, costs〉 ≝ pc_costs in
620       let 〈label, i'〉 ≝ i in
621       let labels ≝
622         match label with
623         [ None ⇒ labels
624         | Some label ⇒
625           let program_counter_bv ≝ bitvector_of_nat ? program_counter in
626             insert ? ? label program_counter_bv labels
627         ]
628       in
629         match construct_costs 〈preamble,instr_list〉 program_counter (λx. zero ?) (λx. zero ?) costs i' with
630         [ None ⇒
631            let dummy ≝ 〈labels,pc_costs〉 in
632             dummy
633         | Some construct ⇒ 〈labels, construct〉
634         ]
635    ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉
636  in
637   let 〈labels, pc_costs〉 ≝ result in
638   let 〈pc, costs〉 ≝ pc_costs in
639    〈labels, costs〉.
640 [3: whd % // #id normalize in ⊢ (% → ?) #abs @⊥ //
641 | whd cases construct in p3 #PC #CODE #JMEQ %
642    [ @(tech_pc_sigma0_append ??????????? (jmeq_to_eq ??? JMEQ)) | #id #Hid ]
643 | (* dummy case *) @⊥
644   @(tech_pc_sigma0_append_None ?? prefix ???? (jmeq_to_eq ??? p3)) ]
645 [*: generalize in match (sig2 … t) whd in ⊢ (% → ?)
646     >p whd in ⊢ (% → ?) >p1 * #IH0 #IH1 >IH0 // ]
647 whd in ⊢ (??(????%?)?) -labels1;
648 cases label in Hid
649  [ #Hid whd in ⊢ (??(????%?)?) >IH1 -IH1
651       (* MANCA LEMMA: INDIRIZZO TROVATO NEL PROGRAMMA! *)
652     | whd in Hid >occurs_exactly_once_None in Hid // ]
653  | -label #label #Hid whd in ⊢ (??(????%?)?)
654
655  ]
656qed.
657
658(*
659(*
660notation < "hvbox('let' 〈ident x,ident y〉 ≝ t 'in' s)"
661 with precedence 10
662for @{ match \$t with [ pair \${ident x} \${ident y} ⇒ \$s ] }.
663*)
664
665lemma build_maps_ok:
666 ∀p:pseudo_assembly_program.
667  let 〈labels,costs〉 ≝ build_maps' p in
668   ∀pc.
669    (nat_of_bitvector … pc) < length … (\snd p) →
670     lookup ?? pc labels (zero …) = sigma p (\snd (fetch_pseudo_instruction (\snd p) pc)).
671 #p cases p #preamble #instr_list
672  elim instr_list
673   [ whd #pc #abs normalize in abs; cases (not_le_Sn_O ?) [#H cases (H abs) ]
674   | #hd #tl #IH
675    whd in ⊢ (match % with [ _ ⇒ ?])
676   ]
677qed.
678*)
679
680(*
681lemma list_elim_rev:
682 ∀A:Type[0].∀P:list A → Prop.
683  P [ ] → (∀n,l. length l = n → P l →
684  P [ ] → (∀l,a. P l → P (l@[a])) →
685   ∀l. P l.
686 #A #P
687qed.*)
688
689lemma rev_preserves_length:
690 ∀A.∀l. length … (rev A l) = length … l.
691  #A #l elim l
692   [ %
693   | #hd #tl #IH normalize >length_append normalize /2/ ]
694qed.
695
696lemma rev_append:
697 ∀A.∀l1,l2.
698  rev A (l1@l2) = rev A l2 @ rev A l1.
699 #A #l1 elim l1 normalize //
700qed.
701
702lemma rev_rev: ∀A.∀l. rev … (rev A l) = l.
703 #A #l elim l
704  [ //
705  | #hd #tl #IH normalize >rev_append normalize // ]
706qed.
707
708lemma split_len_Sn:
709 ∀A:Type[0].∀l:list A.∀len.
710  length … l = S len →
711   Σl'.Σa. l = l'@[a] ∧ length … l' = len.
712 #A #l elim l
713  [ normalize #len #abs destruct
714  | #hd #tl #IH #len
715    generalize in match (rev_rev … tl)
716    cases (rev A tl) in ⊢ (??%? → ?)
717     [ #H <H normalize #EQ % [@[ ]] % [@hd] normalize /2/
718     | #a #l' #H <H normalize #EQ
719      %[@(hd::rev … l')] %[@a] % //
720      >length_append in EQ #EQ normalize in EQ; normalize;
721      generalize in match (injective_S … EQ) #EQ2 /2/ ]]
722qed.
723
724lemma list_elim_rev:
725 ∀A:Type[0].∀P:list A → Type[0].
726  P [ ] → (∀l,a. P l → P (l@[a])) →
727   ∀l. P l.
728 #A #P #H1 #H2 #l
729 generalize in match (refl … (length … l))
730 generalize in ⊢ (???% → ?) #n generalize in match l
731 elim n
732  [ #L cases L [ // | #x #w #abs (normalize in abs) @⊥ // ]
733  | #m #IH #L #EQ
734    cases (split_len_Sn … EQ) #l' * #a * /3/ ]
735qed.
736
737axiom is_prefix: ∀A:Type[0]. list A → list A → Prop.
738axiom prefix_of_append:
739 ∀A:Type[0].∀l,l1,l2:list A.
740  is_prefix … l l1 → is_prefix … l (l1@l2).
741axiom prefix_reflexive: ∀A,l. is_prefix A l l.
742axiom nil_prefix: ∀A,l. is_prefix A [ ] l.
743
744record Propify (A:Type[0]) : Type[0] (*Prop*) ≝ { in_propify: A }.
745
746definition Propify_elim: ∀A. ∀P:Prop. (A → P) → (Propify A → P) ≝
747 λA,P,H,x. match x with [ mk_Propify p ⇒ H p ].
748
749definition app ≝
750 λA:Type[0].λl1:Propify (list A).λl2:list A.
751  match l1 with
752   [ mk_Propify l1 ⇒ mk_Propify … (l1@l2) ].
753
754lemma app_nil: ∀A,l1. app A l1 [ ] = l1.
755 #A * /3/
756qed.
757
758lemma app_assoc: ∀A,l1,l2,l3. app A (app A l1 l2) l3 = app A l1 (l2@l3).
759 #A * #l1 normalize //
760qed.
761
762let rec foldli (A: Type[0]) (B: Propify (list A) → Type[0])
763 (f: ∀prefix. B prefix → ∀x.B (app … prefix [x]))
764 (prefix: Propify (list A)) (b: B prefix) (l: list A) on l :
765 B (app … prefix l) ≝
766  match l with
767  [ nil ⇒ ? (* b *)
768  | cons hd tl ⇒ ? (*foldli A B f (prefix@[hd]) (f prefix b hd) tl*)
769  ].
770 [ applyS b
771 | <(app_assoc ?? [hd]) @(foldli A B f (app … prefix [hd]) (f prefix b hd) tl) ]
772qed.
773
774(*
775let rec foldli (A: Type[0]) (B: list A → Type[0]) (f: ∀prefix. B prefix → ∀x. B (prefix@[x]))
776 (prefix: list A) (b: B prefix) (l: list A) on l : B (prefix@l) ≝
777  match l with
778  [ nil ⇒ ? (* b *)
779  | cons hd tl ⇒
780     ? (*foldli A B f (prefix@[hd]) (f prefix b hd) tl*)
781  ].
782 [ applyS b
783 | applyS (foldli A B f (prefix@[hd]) (f prefix b hd) tl) ]
784qed.
785*)
786
787definition foldll:
788 ∀A:Type[0].∀B: Propify (list A) → Type[0].
789  (∀prefix. B prefix → ∀x. B (app … prefix [x])) →
790   B (mk_Propify … []) → ∀l: list A. B (mk_Propify … l)
791 ≝ λA,B,f. foldli A B f (mk_Propify … [ ]).
792
793axiom is_pprefix: ∀A:Type[0]. Propify (list A) → list A → Prop.
794axiom pprefix_of_append:
795 ∀A:Type[0].∀l,l1,l2.
796  is_pprefix A l l1 → is_pprefix A l (l1@l2).
797axiom pprefix_reflexive: ∀A,l. is_pprefix A (mk_Propify … l) l.
798axiom nil_pprefix: ∀A,l. is_pprefix A (mk_Propify … [ ]) l.
799
800
801axiom foldll':
802 ∀A:Type[0].∀l: list A.
803  ∀B: ∀prefix:Propify (list A). is_pprefix ? prefix l → Type[0].
804  (∀prefix,proof. B prefix proof → ∀x,proof'. B (app … prefix [x]) proof') →
805   B (mk_Propify … [ ]) (nil_pprefix …) → B (mk_Propify … l) (pprefix_reflexive … l).
806 #A #l #B
807 generalize in match (foldll A (λprefix. is_pprefix ? prefix l)) #HH
808
809
810  #H #acc
811 @foldll
812  [
813  |
814  ]
815
816 ≝ λA,B,f. foldli A B f (mk_Propify … [ ]).
817
818
819(*
820record subset (A:Type[0]) (P: A → Prop): Type[0] ≝
821 { subset_wit:> A;
822   subset_proof: P subset_wit
823 }.
824*)
825
826definition build_maps' ≝
827  λpseudo_program.
828  let 〈preamble,instr_list〉 ≝ pseudo_program in
829  let result ≝
830   foldll
831    (option Identifier × pseudo_instruction)
832    (λprefix.
833      Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))).
834       match prefix return λ_.Prop with [mk_Propify prefix ⇒ tech_pc_sigma0 〈preamble,prefix〉 ≠ None ?])
835    (λprefix,t,i.
836      let 〈labels, pc_costs〉 ≝ t in
837      let 〈program_counter, costs〉 ≝ pc_costs in
838       let 〈label, i'〉 ≝ i in
839       let labels ≝
840         match label with
841         [ None ⇒ labels
842         | Some label ⇒
843           let program_counter_bv ≝ bitvector_of_nat ? program_counter in
844             insert ? ? label program_counter_bv labels
845         ]
846       in
847         match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with
848         [ None ⇒
849            let dummy ≝ 〈labels,pc_costs〉 in
850              dummy
851         | Some construct ⇒ 〈labels, construct〉
852         ]
853    ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 instr_list
854  in
855   let 〈labels, pc_costs〉 ≝ result in
856   let 〈pc, costs〉 ≝ pc_costs in
857    〈labels, costs〉.
858 [
859 | @⊥
860 | normalize % //
861 ]
862qed.
863
864definition build_maps' ≝
865  λpseudo_program.
866  let 〈preamble,instr_list〉 ≝ pseudo_program in
867  let result ≝
868   foldl
869    (Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))).
870          ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧
871           tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t)))
872    (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix.
873          let instr_list_prefix' ≝ instr_list_prefix @ [i] in
874           is_prefix ? instr_list_prefix' instr_list →
875           tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?)
876    (λt: Σt:((BitVectorTrie Word 16) × (nat × (BitVectorTrie Word 16))).
877          ∃instr_list_prefix. is_prefix ? instr_list_prefix instr_list ∧
878           tech_pc_sigma0 〈preamble,instr_list_prefix〉 = Some ? (\fst (\snd t)).
879     λi: Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix.
880          let instr_list_prefix' ≝ instr_list_prefix @ [i] in
881           is_prefix ? instr_list_prefix' instr_list →
882           tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ? .
883      let 〈labels, pc_costs〉 ≝ t in
884      let 〈program_counter, costs〉 ≝ pc_costs in
885       let 〈label, i'〉 ≝ i in
886       let labels ≝
887         match label with
888         [ None ⇒ labels
889         | Some label ⇒
890           let program_counter_bv ≝ bitvector_of_nat ? program_counter in
891             insert ? ? label program_counter_bv labels
892         ]
893       in
894         match construct_costs pseudo_program program_counter (λx. zero ?) (λx. zero ?) costs i' with
895         [ None ⇒
896            let dummy ≝ 〈labels,pc_costs〉 in
897              dummy
898         | Some construct ⇒ 〈labels, construct〉
899         ]
900    ) 〈(Stub ? ?), 〈0, (Stub ? ?)〉〉 ?(*instr_list*)
901  in
902   let 〈labels, pc_costs〉 ≝ result in
903   let 〈pc, costs〉 ≝ pc_costs in
904    〈labels, costs〉.
905 [4: @(list_elim_rev ?
906       (λinstr_list. list (
907        (Σi:option Identifier × pseudo_instruction. ∀instr_list_prefix.
908          let instr_list_prefix' ≝ instr_list_prefix @ [i] in
909           is_prefix ? instr_list_prefix' instr_list →
910           tech_pc_sigma0 〈preamble,instr_list_prefix'〉 ≠ None ?)))
911       ?? instr_list) (* CSC: BAD ORDER FOR CODE EXTRACTION *)
912      [ @[ ]
913      | #l' #a #limage %2
914        [ %[@a] #PREFIX #PREFIX_OK
915        | (* CSC: EVEN WORST CODE FOR EXTRACTION: WE SHOULD STRENGTHEN
916             THE INDUCTION HYPOTHESIS INSTEAD *)
917          elim limage
918           [ %1
919           | #HD #TL #IH @(?::IH) cases HD #ELEM #K1 %[@ELEM] #K2 #K3
920             @K1 @(prefix_of_append ???? K3)
921           ]
922        ]
923
924
925
926
927  cases t in c2 ⊢ % #t' * #LIST_PREFIX * #H1t' #H2t' #HJMt'
928     % [@ (LIST_PREFIX @ [i])] %
929      [ cases (sig2 … i LIST_PREFIX) #K1 #K2 @K1
930      | (* DOABLE IN PRINCIPLE *)
931      ]
932 | (* assert false case *)
933 |3: % [@ ([ ])] % [2: % | (* DOABLE *)]
934 |
935
936let rec encoding_check (code_memory: BitVectorTrie Byte 16) (pc: Word) (final_pc: Word)
937                       (encoding: list Byte) on encoding: Prop ≝
938  match encoding with
939  [ nil ⇒ final_pc = pc
940  | cons hd tl ⇒
941    let 〈new_pc, byte〉 ≝ next code_memory pc in
942      hd = byte ∧ encoding_check code_memory new_pc final_pc tl
943  ].
944
945definition assembly_specification:
946  ∀assembly_program: pseudo_assembly_program.
947  ∀code_mem: BitVectorTrie Byte 16. Prop ≝
948  λpseudo_assembly_program.
949  λcode_mem.
950    ∀pc: Word.
951      let 〈preamble, instr_list〉 ≝ pseudo_assembly_program in
952      let 〈pre_instr, pre_new_pc〉 ≝ fetch_pseudo_instruction instr_list pc in
953      let labels ≝ λx. sigma' pseudo_assembly_program (address_of_word_labels_code_mem instr_list x) in
954      let datalabels ≝ λx. sigma' pseudo_assembly_program (lookup ? ? x (construct_datalabels preamble) (zero ?)) in
955      let pre_assembled ≝ assembly_1_pseudoinstruction pseudo_assembly_program
956       (sigma' pseudo_assembly_program pc) labels datalabels pre_instr in
957      match pre_assembled with
958       [ None ⇒ True
959       | Some pc_code ⇒
960          let 〈new_pc,code〉 ≝ pc_code in
961           encoding_check code_mem pc (sigma' pseudo_assembly_program pre_new_pc) code ].
962
963axiom assembly_meets_specification:
964  ∀pseudo_assembly_program.
965    match assembly pseudo_assembly_program with
966    [ None ⇒ True
967    | Some code_mem_cost ⇒
968      let 〈code_mem, cost〉 ≝ code_mem_cost in
970    ].
971(*
972  # PROGRAM
973  [ cases PROGRAM
974    # PREAMBLE
975    # INSTR_LIST
976    elim INSTR_LIST
977    [ whd
978      whd in ⊢ (∀_. %)
979      # PC
980      whd
981    | # INSTR
982      # INSTR_LIST_TL
983      # H
984      whd
985      whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ?])
986    ]
987  | cases not_implemented
988  ] *)
989
990definition status_of_pseudo_status: PseudoStatus → option Status ≝
991 λps.
992  let pap ≝ code_memory … ps in
993   match assembly pap with
994    [ None ⇒ None …
995    | Some p ⇒
996       let cm ≝ load_code_memory (\fst p) in
997       let pc ≝ sigma' pap (program_counter ? ps) in
998        Some …
999         (mk_PreStatus (BitVectorTrie Byte 16)
1000           cm
1001           (low_internal_ram … ps)
1002           (high_internal_ram … ps)
1003           (external_ram … ps)
1004           pc
1005           (special_function_registers_8051 … ps)
1006           (special_function_registers_8052 … ps)
1007           (p1_latch … ps)
1008           (p3_latch … ps)
1009           (clock … ps)) ].
1010
1011definition write_at_stack_pointer':
1012 ∀M. ∀ps: PreStatus M. Byte → Σps':PreStatus M.(code_memory … ps = code_memory … ps') ≝
1013  λM: Type[0].
1014  λs: PreStatus M.
1015  λv: Byte.
1016    let 〈 nu, nl 〉 ≝ split … 4 4 (get_8051_sfr ? s SFR_SP) in
1017    let bit_zero ≝ get_index_v… nu O ? in
1018    let bit_1 ≝ get_index_v… nu 1 ? in
1019    let bit_2 ≝ get_index_v… nu 2 ? in
1020    let bit_3 ≝ get_index_v… nu 3 ? in
1021      if bit_zero then
1022        let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl)
1023                              v (low_internal_ram ? s) in
1024          set_low_internal_ram ? s memory
1025      else
1026        let memory ≝ insert … ([[ bit_1 ; bit_2 ; bit_3 ]] @@ nl)
1027                              v (high_internal_ram ? s) in
1028          set_high_internal_ram ? s memory.
1029  [ cases l0 %
1030  |2,3,4,5: normalize repeat (@ le_S_S) @ le_O_n ]
1031qed.
1032
1033definition execute_1_pseudo_instruction': (Word → nat) → ∀ps:PseudoStatus.
1034 Σps':PseudoStatus.(code_memory … ps = code_memory … ps')
1035
1036  λticks_of.
1037  λs.
1038  let 〈instr, pc〉 ≝ fetch_pseudo_instruction (\snd (code_memory ? s)) (program_counter ? s) in
1039  let ticks ≝ ticks_of (program_counter ? s) in
1040  let s ≝ set_clock ? s (clock ? s + ticks) in
1041  let s ≝ set_program_counter ? s pc in
1042    match instr with
1043    [ Instruction instr ⇒
1044       execute_1_preinstruction … (λx, y. address_of_word_labels y x) instr s
1045    | Comment cmt ⇒ s
1046    | Cost cst ⇒ s
1047    | Jmp jmp ⇒ set_program_counter ? s (address_of_word_labels s jmp)
1048    | Call call ⇒
1049      let a ≝ address_of_word_labels s call in
1050      let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in
1051      let s ≝ set_8051_sfr ? s SFR_SP new_sp in
1052      let 〈pc_bu, pc_bl〉 ≝ split ? 8 8 (program_counter ? s) in
1053      let s ≝ write_at_stack_pointer' ? s pc_bl in
1054      let 〈carry, new_sp〉 ≝ half_add ? (get_8051_sfr ? s SFR_SP) (bitvector_of_nat 8 1) in
1055      let s ≝ set_8051_sfr ? s SFR_SP new_sp in
1056      let s ≝ write_at_stack_pointer' ? s pc_bu in
1057        set_program_counter ? s a
1058    | Mov dptr ident ⇒
1059       set_arg_16 ? s (get_arg_16 ? s (DATA16 (address_of_word_labels s ident))) dptr
1060    ].
1061 [
1062 |2,3,4: %
1063 | <(sig2 … l7) whd in ⊢ (??? (??%)) <(sig2 … l5) %
1064 |
1065 | %
1066 ]
1067 cases not_implemented
1068qed.
1069
1070(*
1071lemma execute_code_memory_unchanged:
1072 ∀ticks_of,ps. code_memory ? ps = code_memory ? (execute_1_pseudo_instruction ticks_of ps).
1073 #ticks #ps whd in ⊢ (??? (??%))
1074 cases (fetch_pseudo_instruction (\snd (code_memory pseudo_assembly_program ps))
1075  (program_counter pseudo_assembly_program ps)) #instr #pc
1076 whd in ⊢ (??? (??%)) cases instr
1077  [ #pre cases pre
1078     [ #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1079       cases (split ????) #z1 #z2 %
1080     | #a1 #a2 whd in ⊢ (??? (??%)) cases (add_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1081       cases (split ????) #z1 #z2 %
1082     | #a1 #a2 whd in ⊢ (??? (??%)) cases (sub_8_with_carry ???) #y1 #y2 whd in ⊢ (??? (??%))
1083       cases (split ????) #z1 #z2 %
1084     | #a1 whd in ⊢ (??? (??%)) cases a1 #x #H whd in ⊢ (??? (??%)) cases x
1085       [ #x1 whd in ⊢ (??? (??%))
1086     | *: cases not_implemented
1087     ]
1088  | #comment %
1089  | #cost %
1090  | #label %
1091  | #label whd in ⊢ (??? (??%)) cases (half_add ???) #x1 #x2 whd in ⊢ (??? (??%))
1092    cases (split ????) #y1 #y2 whd in ⊢ (??? (??%)) cases (half_add ???) #z1 #z2
1093    whd in ⊢ (??? (??%)) whd in ⊢ (??? (??%)) cases (split ????) #w1 #w2
1094    whd in ⊢ (??? (??%)) cases (get_index_v bool ????) whd in ⊢ (??? (??%))
1095    (* CSC: ??? *)
1096  | #dptr #label (* CSC: ??? *)
1097  ]
1098  cases not_implemented
1099qed.
1100*)
1101
1102lemma status_of_pseudo_status_failure_depends_only_on_code_memory:
1103 ∀ps,ps': PseudoStatus.
1104  code_memory … ps = code_memory … ps' →
1105   match status_of_pseudo_status ps with
1106    [ None ⇒ status_of_pseudo_status ps' = None …
1107    | Some _ ⇒ ∃w. status_of_pseudo_status ps' = Some … w
1108    ].
1109 #ps #ps' #H whd in ⊢ (mat
1110 ch % with [ _ ⇒ ? | _ ⇒ ? ])
1111 generalize in match (refl … (assembly (code_memory … ps)))
1112 cases (assembly ?) in ⊢ (???% → %)
1113  [ #K whd whd in ⊢ (??%?) <H >K %
1114  | #x #K whd whd in ⊢ (?? (λ_.??%?)) <H >K % [2: % ] ]
1115qed.*)
1116
1117let rec encoding_check' (code_memory: BitVectorTrie Byte 16) (pc: Word) (encoding: list Byte) on encoding: Prop ≝
1118  match encoding with
1119  [ nil ⇒ True
1120  | cons hd tl ⇒
1121    let 〈new_pc, byte〉 ≝ next code_memory pc in
1122      hd = byte ∧ encoding_check' code_memory new_pc tl
1123  ].
1124
1125(* prove later *)
1126axiom test:
1127  ∀pc: Word.
1128  ∀code_memory: BitVectorTrie Byte 16.
1129  ∀i: instruction.
1130    let assembled ≝ assembly1 i in
1131      encoding_check' code_memory pc assembled →
1132        let 〈instr_pc, ignore〉 ≝ fetch code_memory pc in
1133        let 〈instr, pc〉 ≝ instr_pc in
1134          instr = i.
1135
1136lemma main_thm:
1137 ∀ticks_of.
1138 ∀ps: PseudoStatus.
1139  match status_of_pseudo_status ps with [ None ⇒ True | Some s ⇒
1140  let ps' ≝ execute_1_pseudo_instruction ticks_of ps in
1141  match status_of_pseudo_status ps' with [ None ⇒ True | Some s'' ⇒
1142  let s' ≝ execute_1 s in
1143   s = s'']].
1144 #ticks_of #ps
1145 whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ])
1146 cases (assembly (code_memory pseudo_assembly_program ps)) [%] * #cm #costs whd
1147 whd in ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? ])
1148 generalize in match (sig2 … (execute_1_pseudo_instruction' ticks_of ps))
1149
1150 cases (status_of_pseudo_status (execute_1_pseudo_instruction ticks_of ps)) [%] #s'' whd
Note: See TracBrowser for help on using the repository browser.