source: src/ASM/AssemblyProof.ma @ 870

Last change on this file since 870 was 870, checked in by mulligan, 8 years ago

more changes

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