-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathpan_to_targetProofScript.sml
2196 lines (2049 loc) · 86.7 KB
/
pan_to_targetProofScript.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
composing semantics correctness from pan to target
*)
open preamble
backendProofTheory pan_to_wordProofTheory
pan_to_targetTheory wordConvsProofTheory;
local open blastLib in end
val _ = new_theory "pan_to_targetProof";
Overload stack_remove_prog_comp[local] = ``stack_remove$prog_comp``
Overload stack_alloc_prog_comp[local] = ``stack_alloc$prog_comp``
Overload stack_names_prog_comp[local] = ``stack_names$prog_comp``
Overload word_to_word_compile[local] = ``word_to_word$compile``
Overload word_to_stack_compile[local] = ``word_to_stack$compile``
Overload stack_to_lab_compile[local] = ``stack_to_lab$compile``
Overload pan_to_word_compile_prog[local] = ``pan_to_word$compile_prog``
Definition pancake_good_code_def:
pancake_good_code pan_code =
EVERY (λ(name,params,body). EVERY (every_exp (λx. ∀op es. x = Panop op es ⇒ LENGTH es = 2)) (exps_of body)) pan_code
End
Theorem pan_to_lab_good_code_lemma:
compile c.stack_conf c.data_conf lim1 lim2 offs stack_prog = code ∧
compile asm_conf3 word_prog = (bm, wc, fs, stack_prog) ∧
word_to_word$compile word_conf asm_conf3 word_prog0 = (col, word_prog) ∧
compile_prog asm_conf3.ISA pan_prog = word_prog0 ∧
stack_to_labProof$labels_ok code ∧
all_enc_ok_pre conf code
⇒
lab_to_targetProof$good_code conf LN code
Proof
(* start of 'good_code' proof for initial compilation *)
rw []
\\ qmatch_asmsub_abbrev_tac `stack_to_labProof$labels_ok lab_prog`
\\ fs[lab_to_targetProofTheory.good_code_def]
\\ CONJ_TAC >- fs[Abbr `lab_prog`, stack_to_labTheory.compile_def]
\\ CONJ_ASM1_TAC >- (
fs [stack_to_labProofTheory.labels_ok_def]
\\ qpat_x_assum `all_enc_ok_pre _ _` kall_tac
\\ first_x_assum (fn t => mp_tac t \\ match_mp_tac EVERY_MONOTONIC)
\\ simp[] \\ Cases \\ simp[]
\\ metis_tac [labPropsTheory.EVERY_sec_label_ok]
)
\\ CONJ_TAC >- (
fs [stack_to_labProofTheory.labels_ok_def]
\\ qmatch_asmsub_abbrev_tac `ALL_DISTINCT (MAP ff _)`
\\ `ff = Section_num` by
(simp[Abbr`ff`,FUN_EQ_THM]>>Cases>>simp[])
\\ fs [])
\\ CONJ_TAC >- (
fs [stack_to_labProofTheory.labels_ok_def]
\\ first_x_assum (fn t => mp_tac t \\ match_mp_tac EVERY_MONOTONIC
\\ simp[] \\ Cases \\ simp[] \\ NO_TAC)
)
\\ qpat_x_assum`Abbrev(lab_prog = _)` mp_tac
\\ simp[markerTheory.Abbrev_def]
\\disch_then (assume_tac o SYM)
\\ drule stack_to_labProofTheory.stack_to_lab_stack_good_handler_labels
\\ simp []
\\ disch_then match_mp_tac
\\ qmatch_asmsub_abbrev_tac ‘word_to_word$compile _ _ wprog’
\\ pop_assum $ (assume_tac o GSYM o REWRITE_RULE [markerTheory.Abbrev_def])
\\ drule pan_to_word_good_handlers
\\ disch_tac
\\ drule word_good_handlers_word_to_word
\\ disch_then (qspecl_then [‘word_conf’, ‘asm_conf3’] assume_tac)
\\ drule (INST_TYPE [beta|->alpha] word_to_stackProofTheory.word_to_stack_good_handler_labels)
\\ strip_tac
\\ pop_assum $ irule
\\ simp []
\\ qexists_tac ‘asm_conf3’>>gs[]
QED
(* move *)
Theorem word_to_stack_compile_FST:
word_to_stack_compile mc.target.config wprog = (bitmaps,c'',fs,p) ⇒
MAP FST p =
raise_stub_location::store_consts_stub_location::MAP FST wprog
Proof
strip_tac>>gs[word_to_stackTheory.compile_def]>>
pairarg_tac>>gs[]>>rveq>>gs[]>>
drule_then irule word_to_stackProofTheory.MAP_FST_compile_word_to_stack
QED
Theorem pan_to_stack_first_ALL_DISTINCT:
pan_to_word_compile_prog mc.target.config.ISA pan_code = wprog0 ∧
word_to_word_compile c.word_to_word_conf mc.target.config wprog0 = (col,wprog) ∧
word_to_stack_compile mc.target.config wprog = (bitmaps,c'',fs,p) ∧
ALL_DISTINCT (MAP FST pan_code) ⇒
ALL_DISTINCT (MAP FST p)
Proof
strip_tac>>drule pan_to_wordProofTheory.first_compile_prog_all_distinct>>
strip_tac>>
drule backendProofTheory.compile_to_word_conventions2>>strip_tac>>
gs[]>>
qpat_x_assum ‘MAP FST wprog = _’ $ assume_tac o GSYM>>gs[]>>
drule word_to_stack_compile_FST>>
strip_tac>>gs[]>>
drule pan_to_wordProofTheory.pan_to_word_compile_prog_lab_min>>
strip_tac>>
gs[GSYM EVERY_MAP]>>EVAL_TAC>>gs[EVERY_MEM]>>
rw[]>- (first_x_assum $ qspec_then ‘5’ assume_tac>>gs[])>>
first_x_assum $ qspec_then ‘6’ assume_tac>>gs[]>>
metis_tac[FST,SND,PAIR]
QED
Theorem pan_to_stack_compile_lab_pres:
pan_to_word$compile_prog mc.target.config.ISA pan_code = wprog0 ∧
word_to_word_compile c.word_to_word_conf mc.target.config wprog0 =(col,wprog) ∧
word_to_stack_compile mc.target.config wprog = (bitmaps,c'',fs,p) ∧
ALL_DISTINCT (MAP FST pan_code) ⇒
ALL_DISTINCT (MAP FST p) ∧
EVERY (λn. n ≠ 0 ∧ n ≠ 1 ∧ n ≠ 2 ∧ n ≠ gc_stub_location) (MAP FST p) ∧
EVERY
(λ(n,p).
(let
labs = extract_labels p
in
EVERY (λ(l1,l2). l1 = n ∧ l2 ≠ 0 ∧ l2 ≠ 1) labs ∧
ALL_DISTINCT labs)) p
Proof
strip_tac>>
drule pan_to_wordProofTheory.pan_to_word_compile_lab_pres>>strip_tac>>
gs[]>>
drule backendProofTheory.compile_to_word_conventions2>>
strip_tac>>
drule pan_to_wordProofTheory.first_compile_prog_all_distinct>>
strip_tac>>gs[]>>
‘EVERY
(λ(n,m,p).
(let
labs = extract_labels p
in
EVERY (λ(l1,l2). l1 = n ∧ l2 ≠ 0 ∧ l2 ≠ 1) labs ∧
ALL_DISTINCT labs)) wprog’
by (gs[EVERY2_EVERY]>>gs[EVERY_EL]>>ntac 2 strip_tac>>
ntac 3 (first_x_assum $ qspec_then ‘n’ assume_tac)>>
pairarg_tac>>gs[EL_ZIP, wordConvsTheory.labels_rel_def]>>
pairarg_tac>>gs[EL_MAP]>>strip_tac>>strip_tac>>
‘EL n (MAP FST wprog) = EL n (MAP FST wprog0)’ by rfs[]>>
gs[EL_MAP]>>
pairarg_tac>>gs[]>>
‘(l1, l2) ∈ set (extract_labels p'')’
by (gs[MEM_SET_TO_LIST, SUBSET_DEF]>>
first_assum irule>>metis_tac[MEM_EL])>>
gs[MEM_EL]>>
first_x_assum $ qspec_then ‘n''''’ assume_tac>>
gs[]>>pairarg_tac>>gs[])>>
drule (INST_TYPE [beta|->alpha] word_to_stackProofTheory.word_to_stack_compile_lab_pres)>>
disch_then $ qspec_then ‘mc.target.config’ assume_tac>>
drule_all pan_to_stack_first_ALL_DISTINCT>>
strip_tac>>gs[]>>
strip_tac>>gs[backend_commonTheory.stack_num_stubs_def]>>
gs[backend_commonTheory.word_num_stubs_def,
wordLangTheory.store_consts_stub_location_def,
wordLangTheory.raise_stub_location_def,
stackLangTheory.gc_stub_location_def,
backend_commonTheory.stack_num_stubs_def]>>
drule pan_to_wordProofTheory.pan_to_word_compile_prog_lab_min>>
gs[GSYM EVERY_MAP, EVERY_MEM]>>ntac 3 strip_tac>>
first_x_assum $ qspec_then ‘n’ assume_tac>>gs[]
QED
Theorem pan_to_lab_labels_ok:
pan_to_word_compile_prog mc.target.config.ISA pan_code = wprog0 ∧
word_to_word_compile c.word_to_word_conf mc.target.config wprog0 = (col,wprog) ∧
word_to_stack_compile mc.target.config wprog = (bitmaps,c'',fs,p) ∧
stack_to_lab_compile c.stack_conf c.data_conf max_heap sp mc.target.config.addr_offset p = lprog ∧
ALL_DISTINCT (MAP FST pan_code) ⇒
labels_ok lprog
Proof
strip_tac>>
qpat_x_assum ‘_ = lprog’ (assume_tac o GSYM)>>gs[]>>
irule stack_to_labProofTheory.stack_to_lab_compile_lab_pres>>
drule_all pan_to_stack_compile_lab_pres>>gs[]
QED
(** stack_to_lab$good_code **)
Theorem word_to_stack_good_code_lemma:
word_to_word_compile c.word_to_word_conf mc.target.config
(pan_to_word_compile_prog mc.target.config.ISA pan_code) = (col,wprog) ∧
word_to_stack_compile mc.target.config wprog = (bitmaps,c'',fs,p) ∧
LENGTH mc.target.config.avoid_regs + 13 ≤ mc.target.config.reg_count ∧
(* from backend_config_ok c *)
ALL_DISTINCT (MAP FST pan_code) ⇒
good_code (mc.target.config.reg_count −
(LENGTH mc.target.config.avoid_regs + 3)) p
Proof
(* a bit slow *)
gs[stack_to_labProofTheory.good_code_def]>>strip_tac>>
qmatch_asmsub_abbrev_tac ‘word_to_word_compile _ _ wprog0 = _’>>
qpat_x_assum ‘Abbrev (wprog0 = _)’ (assume_tac o GSYM o REWRITE_RULE [markerTheory.Abbrev_def])>>
drule_at (Pat ‘word_to_word_compile _ _ _ = _’) pan_to_stack_compile_lab_pres>>
disch_then drule_all>>strip_tac>>gs[]>>
drule backendProofTheory.compile_to_word_conventions2>>
strip_tac>>
drule pan_to_wordProofTheory.first_compile_prog_all_distinct>>
strip_tac>>gs[]>>
drule word_to_stack_compile_FST>>strip_tac>>
drule word_to_stackProofTheory.word_to_stack_stack_convs>>
gs[]>>impl_tac
>- (gs[EVERY_EL]>>
ntac 2 strip_tac>>
ntac 3 (first_x_assum $ qspec_then ‘n’ assume_tac)>>
gs[]>>
pairarg_tac>>gs[]>>
pairarg_tac>>gs[]>>simp[EL_MAP])>>
strip_tac>>gs[backend_commonTheory.stack_num_stubs_def]>>
gs[EVERY_EL]>>rpt strip_tac>>
pairarg_tac>>gs[EL_MAP]>>
qpat_x_assum ‘∀n. _ ⇒ alloc_arg _’ $ qspec_then ‘n’ assume_tac>>
gs[]>>
drule pan_to_word_compile_prog_lab_min>>
gs[GSYM EVERY_MAP]>>
qpat_x_assum ‘MAP FST _ = MAP FST _’ $ assume_tac o GSYM>>
gs[]>>
gs[GSYM EVERY_MAP, EVERY_MEM]>>strip_tac>>
‘MEM k (MAP FST p)’
by (gs[MEM_MAP]>>gs[MEM_EL]>>gs[PULL_EXISTS]>>
first_assum $ irule_at (Pos last)>>gs[])>>
gs[backend_commonTheory.word_num_stubs_def,
wordLangTheory.store_consts_stub_location_def,
wordLangTheory.raise_stub_location_def,
backend_commonTheory.stack_num_stubs_def]>>
first_x_assum $ qspec_then ‘k’ assume_tac>>gs[]
QED
(* move *)
Theorem good_dimindex_0w_8w:
good_dimindex (:α) ⇒ (0w:α word) ≤ 8w ∧ -8w ≤ (0w:α word)
Proof
strip_tac>>
fs[WORD_LE,miscTheory.good_dimindex_def,word_2comp_n2w,
dimword_def,word_msb_n2w]
QED
(* move *)
Theorem FLOOKUP_MAP_KEYS_LINV:
f PERMUTES 𝕌(:α) ⇒
FLOOKUP (MAP_KEYS (LINV f 𝕌(:α)) m) (i:α) = FLOOKUP m (f i)
Proof
strip_tac>>
drule BIJ_LINV_INV>>strip_tac>>
drule BIJ_LINV_BIJ>>strip_tac>>
gs[BIJ_DEF]>>
mp_tac (GEN_ALL $ INST_TYPE [beta|->alpha,gamma|->beta] FLOOKUP_MAP_KEYS_MAPPED)>>
disch_then $ qspecl_then [‘m’, ‘f i’, ‘LINV f 𝕌(:α)’] mp_tac>>
gs[]>>
last_x_assum assume_tac>>
drule LINV_DEF>>
disch_then $ qspec_then ‘i’ mp_tac>>
impl_tac >- gs[]>>
strip_tac>>pop_assum (fn h => rewrite_tac[h])
QED
(* move to stack_to_labProof *)
Theorem full_make_init_be:
(FST(full_make_init a b c d e f g h i j k)).be ⇔ h.be
Proof
fs[stack_to_labProofTheory.full_make_init_def]>>
fs[stack_allocProofTheory.make_init_def]>>
simp[stack_removeProofTheory.make_init_any_def,
stack_removeProofTheory.make_init_opt_def]>>
every_case_tac>>fs[]>>
imp_res_tac stackPropsTheory.evaluate_consts>>
EVAL_TAC>>fs[]>>
EVAL_TAC>>fs[]
QED
Definition pan_installed_def:
pan_installed bytes cbspace bitmaps data_sp ffi_names (r1,r2) (mc_conf:('a,'state,'b) machine_config) shmem_extra ms p_mem p_dom sdm' ⇔
∃t m io_regs cc_regs bitmap_ptr bitmaps_dm sdm.
let heap_stack_dm = { w | t.regs r1 <=+ w ∧ w <+ t.regs r2 } in
(∀a. a ∈ p_dom ⇒ m a = p_mem a) ∧
good_init_state mc_conf ms bytes cbspace t m (heap_stack_dm ∪ bitmaps_dm) sdm io_regs cc_regs ∧ sdm' = sdm ∩ byte_aligned ∧
byte_aligned (t.regs r1) /\
byte_aligned (t.regs r2) /\
byte_aligned bitmap_ptr /\
t.regs r1 ≤₊ t.regs r2 /\
1024w * bytes_in_word ≤₊ t.regs r2 - t.regs r1 /\
DISJOINT heap_stack_dm bitmaps_dm ∧
m (t.regs r1) = Word bitmap_ptr ∧
m (t.regs r1 + bytes_in_word) =
Word (bitmap_ptr + bytes_in_word * n2w (LENGTH bitmaps)) ∧
m (t.regs r1 + 2w * bytes_in_word) =
Word (bitmap_ptr + bytes_in_word * n2w data_sp +
bytes_in_word * n2w (LENGTH bitmaps)) ∧
m (t.regs r1 + 3w * bytes_in_word) =
Word (mc_conf.target.get_pc ms + n2w (LENGTH bytes)) ∧
m (t.regs r1 + 4w * bytes_in_word) =
Word (mc_conf.target.get_pc ms + n2w cbspace + n2w (LENGTH bytes)) ∧
(word_list bitmap_ptr (MAP Word bitmaps) *
word_list_exists (bitmap_ptr + bytes_in_word * n2w (LENGTH bitmaps)) data_sp)
(fun2set (m,byte_aligned ∩ bitmaps_dm)) ∧
ffi_names = SOME mc_conf.ffi_names ∧
(!i. mmio_pcs_min_index mc_conf.ffi_names = SOME i ==>
MAP (\rec. rec.entry_pc + mc_conf.target.get_pc ms) shmem_extra =
DROP i mc_conf.ffi_entry_pcs ∧
mc_conf.mmio_info =
ZIP (GENLIST (λindex. index + i) (LENGTH shmem_extra),
(MAP (λrec. (rec.nbytes, rec.access_addr, rec.reg,
rec.exit_pc + mc_conf.target.get_pc ms))
shmem_extra)) ∧
cbspace + LENGTH bytes + ffi_offset * (i + 3) < dimword (:'a))
End
Theorem pan_installed_imp_installed:
pan_installed bytes cbspace bitmaps data_sp ffi_names (r1,r2) mc_conf shmem_extra ms p_mem p_dom sdm ⇒
installed bytes cbspace bitmaps data_sp ffi_names (r1,r2) mc_conf shmem_extra ms
Proof
rw[pan_installed_def, targetSemTheory.installed_def]>>
metis_tac[]
QED
(* memory update *)
Theorem fun2set_update_eq[simp]:
fun2set (m, md) = fun2set (m', md) ⇒
fun2set (m⦇x ↦ a⦈, md) = fun2set (m'⦇x ↦ a⦈, md)
Proof
strip_tac>>
gs[set_sepTheory.fun2set_eq,UPDATE_def]>>
IF_CASES_TAC>>gs[]
QED
Theorem get_var_const_memory[simp]:
wordSem$get_var x (y with memory := m) = get_var x y
Proof
gs[wordSemTheory.get_var_def]
QED
Theorem set_var_const_memory[simp]:
wordSem$set_var v x (y with memory := m) = (set_var v x y) with memory := m
Proof
gs[wordSemTheory.set_var_def]
QED
Theorem unset_var_const_memory[simp]:
wordSem$unset_var v (y with memory := m) = (unset_var v y) with memory := m
Proof
gs[wordSemTheory.unset_var_def]
QED
Theorem get_vars_const_memory[simp]:
wordSem$get_vars x (y with memory := m) = get_vars x y
Proof
Induct_on`x`>>srw_tac[][wordSemTheory.get_vars_def]
QED
Theorem set_vars_const_memory[simp]:
wordSem$set_vars vs xs (y with memory := m) = (set_vars vs xs y) with memory := m
Proof
Induct_on`xs`>>srw_tac[][wordSemTheory.set_vars_def]
QED
Theorem get_var_imm_const_memory[simp]:
wordSem$get_var_imm ri (s with memory := m) = get_var_imm ri s
Proof
Cases_on ‘ri’>>gs[wordSemTheory.get_var_imm_def]
QED
Theorem mem_load_const_memory[simp]:
fun2set (s.memory,s.mdomain) = fun2set (m,s.mdomain) ⇒
wordSem$mem_load ad (s with memory := m) = mem_load ad s
Proof
strip_tac>>gs[wordSemTheory.mem_load_def]>>
IF_CASES_TAC>>gs[set_sepTheory.fun2set_eq]
QED
Theorem mem_store_const_memory[simp]:
fun2set (s.memory,s.mdomain) = fun2set (m,s.mdomain) ⇒
(mem_store ad w s = NONE ⇔ wordSem$mem_store ad w (s with memory := m) = NONE) ∧
(mem_store ad w s = SOME (s with memory:= s.memory⦇ad↦w⦈) ⇔
wordSem$mem_store ad w (s with memory := m) =
SOME (s with memory := m⦇ad↦w⦈))
Proof
strip_tac>>gs[wordSemTheory.mem_store_def]
QED
Theorem word_exp_const_memory[simp]:
∀s exp m.
fun2set (s.memory,s.mdomain) = fun2set (m, s.mdomain) ⇒
wordSem$word_exp (s with memory := m) exp = word_exp s exp
Proof
recInduct wordSemTheory.word_exp_ind>>rw[wordSemTheory.word_exp_def]>>
fs[PULL_FORALL]>>fs[Once SWAP_FORALL_THM]>>
first_x_assum $ qspec_then ‘m’ assume_tac>>gs[]>>
‘the_words (MAP (λa. word_exp (s with memory := m) a) wexps) =
the_words (MAP (λa. word_exp s a) wexps)’
by (Induct_on ‘wexps’>>gs[]>>rpt strip_tac>>gs[]>>
Cases_on ‘word_exp s h’>>gs[]>>
gs[wordSemTheory.the_words_def])>>gs[]
QED
Theorem mem_load_byte_aux_const_memory[simp]:
fun2set (m,dm) = fun2set (m',dm) ⇒
wordSem$mem_load_byte_aux m' dm be w =
mem_load_byte_aux m dm be w
Proof
strip_tac>>gs[wordSemTheory.mem_load_byte_aux_def]>>
gs[set_sepTheory.fun2set_eq]>>
first_x_assum $ qspec_then ‘byte_align w’ assume_tac>>
rpt (CASE_TAC>>gs[])
QED
Theorem mem_store_byte_aux_const_memory:
fun2set (m,dm) = fun2set (m',dm) ⇒
(mem_store_byte_aux m dm be w b = NONE ⇔
mem_store_byte_aux m' dm be w b = NONE) ∧
(fun2set (THE (wordSem$mem_store_byte_aux m' dm be w b),dm) =
fun2set (THE (mem_store_byte_aux m dm be w b), dm))
Proof
gs[set_sepTheory.fun2set_eq]>>rpt strip_tac>>
gs[wordSemTheory.mem_store_byte_aux_def]
>- (first_x_assum $ qspec_then ‘byte_align w’ assume_tac>>
rpt (CASE_TAC>>gs[]))>>
first_assum $ qspec_then ‘a’ assume_tac>>
first_x_assum $ qspec_then ‘byte_align w’ assume_tac>>
rpt (CASE_TAC>>gs[])>>gs[UPDATE_def]>>IF_CASES_TAC>>gs[]
QED
Theorem read_bytearray_const_memory[simp]:
fun2set (m,dm) = fun2set (m',dm) ⇒
misc$read_bytearray ptr len (mem_load_byte_aux m dm be) =
read_bytearray ptr len (mem_load_byte_aux m' dm be)
Proof
strip_tac>>
imp_res_tac mem_load_byte_aux_const_memory>>
metis_tac[]
QED
Theorem write_bytearray_const_memory[simp]:
∀ls ptr m.
fun2set (m,dm) = fun2set (m',dm) ⇒
fun2set (wordSem$write_bytearray ptr ls m dm be, dm) =
fun2set (write_bytearray ptr ls m' dm be, dm)
Proof
Induct>>gs[wordSemTheory.write_bytearray_def]>>
rpt strip_tac>>gs[]>>
first_x_assum $ qspecl_then [‘ptr+1w’, ‘m’] assume_tac>>rfs[]>>
drule mem_store_byte_aux_const_memory>>strip_tac>>
first_x_assum $ qspecl_then [‘ptr’, ‘be’, ‘h’] assume_tac>>fs[]>>
rpt (CASE_TAC>>fs[])
QED
Theorem inst_const_memory:
fun2set (s.memory,s.mdomain) = fun2set (m, s.mdomain) ⇒
(inst i s = NONE ⇔ wordSem$inst i (s with memory := m) = NONE) ∧
(inst i s ≠ NONE ⇒
(∃m'. THE (wordSem$inst i (s with memory := m)) =
(THE (inst i s)) with memory := m' ∧
(let x = THE (inst i s) in
fun2set (x.memory,x.mdomain) = fun2set (m',x.mdomain))))
Proof
(* a bit slow *)
Induct_on ‘i’>>gs[wordSemTheory.inst_def]>>
strip_tac
>- metis_tac[]
>- (ntac 2 strip_tac>>
gs[wordSemTheory.assign_def, wordSemTheory.set_var_def]>>
CASE_TAC>>gs[word_exp_const_memory]>>gvs[]>>metis_tac[])
>- (rpt strip_tac>>
gs[wordSemTheory.assign_def, wordSemTheory.set_var_def]>>
rpt (CASE_TAC>>fs[])>>
gs[]>>rpt (FULL_CASE_TAC>>gs[])>>gvs[]>>metis_tac[])
>- (rpt strip_tac>>
rpt (CASE_TAC>>gs[])>>
imp_res_tac mem_load_byte_aux_const_memory>>gs[]>>
imp_res_tac mem_store_byte_aux_const_memory>>gs[]>>
imp_res_tac mem_store_const_memory>>gs[]>>
imp_res_tac mem_load_const_memory>>gs[]>>
ntac 2 $ first_x_assum $ qspecl_then [‘c''’, ‘s.be’, ‘w2w c’] assume_tac>>
gs[wordSemTheory.set_var_def]>>
gs[wordSemTheory.mem_store_def]>>
rpt (FULL_CASE_TAC>>gs[])>>gvs[]>>TRY (metis_tac[])>>
irule_at Any fun2set_update_eq>>gs[]>>metis_tac[])>>
rpt strip_tac>>
gs[wordSemTheory.get_fp_var_def,
wordSemTheory.set_fp_var_def,
wordSemTheory.get_var_def,
wordSemTheory.set_var_def]>>
rpt (CASE_TAC>>gs[])>>gvs[]>>
rpt (FULL_CASE_TAC>>gs[])>>gvs[]>>
metis_tac[]
QED
Theorem const_writes_const_memory:
∀c' c words m m' md.
fun2set (m,md) = fun2set (m',md) ⇒
fun2set (wordSem$const_writes c' c words m,md) =
fun2set (wordSem$const_writes c' c words m',md)
Proof
Induct_on ‘words’>>srw_tac[][wordSemTheory.const_writes_def]>>
rename1 ‘h::words’>>Cases_on ‘h’>>
gs[wordSemTheory.const_writes_def]
QED
Theorem share_inst_const_memory[simp]:
∀s op v c m.
fun2set (s.memory,s.mdomain) = fun2set (m, s.mdomain) ∧
share_inst op v c s = (res, t) ⇒
t.memory = s.memory ∧ t.mdomain = s.mdomain ∧
share_inst op v c (s with memory := m) = (res, t with memory := m)
Proof
rpt strip_tac>>Cases_on ‘op’>>
gs[wordSemTheory.share_inst_def,
wordSemTheory.sh_mem_load_def,
wordSemTheory.sh_mem_load_byte_def,
wordSemTheory.sh_mem_load32_def,
wordSemTheory.sh_mem_store_def,
wordSemTheory.sh_mem_store_byte_def,
wordSemTheory.sh_mem_store32_def,
ffiTheory.call_FFI_def]>>
every_case_tac>>gvs[]>>
fs[wordSemTheory.sh_mem_set_var_def,
wordSemTheory.set_var_def,
wordSemTheory.flush_state_def]>>gvs[]
QED
Triviality mem_upd_lemma:
((s : ('a, 'b, 'c) wordSem$state) with memory := ARB) = (t with memory := ARB) ==>
?m. s = (t with memory := m)
Proof
simp [wordSemTheory.state_component_equality]
QED
Triviality push_env_mem_upd:
! env params s.
push_env env params (s with memory := m) =
(push_env env params s with memory := m)
Proof
recInduct wordSemTheory.push_env_ind
\\ simp [wordSemTheory.push_env_def]
\\ rw []
\\ rpt (pairarg_tac \\ fs [])
\\ fs []
QED
Triviality push_env_mem_const:
! env params s.
(push_env env params s).memory = s.memory /\
(push_env env params s).mdomain = s.mdomain
Proof
recInduct wordSemTheory.push_env_ind
\\ simp [wordSemTheory.push_env_def]
\\ rw []
\\ rpt (pairarg_tac \\ fs [])
\\ fs []
QED
(* memory update lemma for evaluate *)
Triviality memory_swap_lemma1:
∀prog st res rst m.
wordSem$evaluate (prog, (st:(α,β,γ) wordSem$state)) = (res, rst) ∧
fun2set (st.memory, st.mdomain) = fun2set (m, st.mdomain) ∧
no_alloc_code st.code ∧ no_install_code st.code ∧
no_alloc prog ∧ no_install prog ⇒
(∃st'. evaluate (prog, st with memory := m) = (res, st') /\
(st' with memory := ARB) = (rst with memory := ARB) /\
fun2set (rst.memory, rst.mdomain) = fun2set (st'.memory, rst.mdomain))
Proof
recInduct (name_ind_cases [] wordSemTheory.evaluate_ind)
\\ srw_tac [] [wordSemTheory.evaluate_def]
\\ fs [wordSemTheory.call_env_def, wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def, wordSemTheory.flush_state_def,
wordSemTheory.dec_clock_def]
>~ [`Case (Inst i, _)`]
>- (
imp_res_tac inst_const_memory
\\ fs [CaseEq "option"] \\ gvs []
\\ rpt (first_x_assum (qspec_then `i` assume_tac))
\\ gs [GSYM IS_SOME_EQ_NOT_NONE, IS_SOME_EXISTS]
)
>~ [`Case (MustTerminate _, _)`]
>- (
fs [UNCURRY_eq_pair, CaseEq "bool"] \\ gvs []
\\ first_x_assum (qspec_then `m` assume_tac) \\ fs []
\\ imp_res_tac mem_upd_lemma
\\ gs []
)
>~ [`Case (Seq _ _, _)`]
>- (
gs [UNCURRY_eq_pair]
\\ first_x_assum (qspec_then `m` assume_tac)
\\ gs [CaseEq "bool"]
\\ imp_res_tac mem_upd_lemma
\\ fs []
\\ imp_res_tac wordPropsTheory.no_install_evaluate_const_code
\\ fs []
)
>~ [`Case (Raise _, rst)`]
>- (
fs [CaseEq "option"] \\ gvs []
\\ fs [wordSemTheory.jump_exc_def, CaseEq "list"]
\\ Cases_on `rst.handler < LENGTH rst.stack` \\ fs []
\\ gvs []
\\ every_case_tac \\ fs []
\\ gvs []
)
>~ [`Case (FFI _ _ _ _ _ _, _)`]
>- (
fs [CaseEq "option", CaseEq "word_loc"] \\ gvs []
\\ imp_res_tac read_bytearray_const_memory
\\ gs []
\\ every_case_tac \\ gvs []
)
>~ [`Case (ShareInst _ _ _, _)`]
>- (
fs [CaseEq "option", CaseEq "word_loc"] \\ gvs []
\\ drule_all share_inst_const_memory
\\ SIMP_TAC bool_ss []
\\ simp []
)
>~ [`Case (Call _ _ _ _, _)`]
>- (
fs [CaseEq "option", CaseEq "word_loc", CaseEq "bool"] \\ gvs []
\\ fs [CaseEq "prod"] \\ gvs []
\\ drule wordPropsTheory.no_alloc_find_code
\\ drule_at (Pos (el 2)) wordPropsTheory.no_install_find_code
\\ simp [] \\ rpt strip_tac
\\ fs [CaseEq "option", CaseEq "bool", CaseEq "prod"] \\ gvs []
\\ fs [CaseEq "wordSem$result"] \\ gvs []
\\ fs [push_env_mem_upd, push_env_mem_const]
\\ last_x_assum (qspec_then `m` assume_tac)
\\ gs[wordSemTheory.pop_env_def, wordSemTheory.set_var_def]
\\ fs [AllCaseEqs ()] \\ gvs []
\\ imp_res_tac mem_upd_lemma \\ gs []
\\ imp_res_tac wordPropsTheory.no_install_evaluate_const_code
\\ gs []
)
\\ (
fs [wordSemTheory.get_var_def, wordSemTheory.set_var_def,
wordSemTheory.unset_var_def, CaseEq "option", CaseEq "word_loc", CaseEq "bool",
get_vars_const_memory, UNCURRY_eq_pair]
\\ gvs []
\\ imp_res_tac mem_upd_lemma
\\ gs [wordSemTheory.set_vars_def, wordSemTheory.set_store_def,
const_writes_const_memory, wordSemTheory.mem_store_def]
\\ gvs []
\\ NO_TAC
)
QED
(* avoid changing subsequent proof by rephrasing back into earlier form *)
Triviality memory_swap_lemma:
∀prog st res rst m.
wordSem$evaluate (prog, (st:(α,β,γ) wordSem$state)) = (res, rst) ∧
fun2set (st.memory, st.mdomain) = fun2set (m, st.mdomain) ∧
no_alloc_code st.code ∧ no_install_code st.code ∧
no_alloc prog ∧ no_install prog ⇒
(∃m'. evaluate (prog, st with memory := m) = (res, rst with memory := m') ∧
fun2set (rst.memory, rst.mdomain) = fun2set (m', rst.mdomain))
Proof
rw []
\\ drule_all memory_swap_lemma1
\\ rw []
\\ imp_res_tac mem_upd_lemma
\\ simp []
\\ metis_tac []
QED
Theorem word_semantics_memory_update:
fun2set (s.memory,s.mdomain) = fun2set (m,s.mdomain) ∧
no_alloc_code s.code ∧ no_install_code s.code ⇒
wordSem$semantics ((s with memory := m):(α,β,'ffi) wordSem$state) start ≠ Fail ⇒
wordSem$semantics s start =
wordSem$semantics ((s with memory := m):(α,β,'ffi) wordSem$state) start
Proof
strip_tac>>
gs[wordSemTheory.semantics_def]>>
IF_CASES_TAC >> full_simp_tac(srw_ss())[] >>
DEEP_INTRO_TAC some_intro >> simp[] >>
strip_tac>>
strip_tac
>- (strip_tac>>gs[]>>
IF_CASES_TAC>>gs[]
>- (Cases_on ‘r=SOME TimeOut’>>gs[]>>
qmatch_asmsub_abbrev_tac ‘FST ev’>>
Cases_on ‘ev’>>gs[]>>rename1 ‘(q,r')’>>
drule memory_swap_lemma>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
qexists_tac ‘m’>>gs[]>>
strip_tac>>strip_tac>>
‘q = r’
by (Cases_on ‘k < k'’>>gs[]
>- (qpat_x_assum ‘evaluate _ = (r, _)’ assume_tac>>
drule wordPropsTheory.evaluate_add_clock>>
strip_tac>>pop_assum $ qspec_then ‘k' - k’ assume_tac>>gs[])>>
gs[NOT_LESS]>>
drule wordPropsTheory.evaluate_add_clock>>
strip_tac>>pop_assum $ qspec_then ‘k - k'’ assume_tac>>gs[]>>
Cases_on ‘q’>>rename1 ‘SOME x'’>>Cases_on ‘x'’>>gs[])>>
Cases_on ‘r’>>rename1 ‘SOME x'’>>Cases_on ‘x'’>>gs[]>>
first_x_assum $ qspec_then ‘k'’ assume_tac>>gs[])>>
DEEP_INTRO_TAC some_intro >> simp[] >>
strip_tac
>- (strip_tac>>
first_x_assum $ qspec_then ‘k’ assume_tac>>
qmatch_asmsub_abbrev_tac ‘FST ev’>>
Cases_on ‘ev’>>gs[]>>rename1 ‘(q,r')’>>
drule memory_swap_lemma>>fs[]>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
disch_then $ qspec_then ‘m’ assume_tac>>gs[]>>
strip_tac>>gs[]>>
Cases_on ‘r'' = SOME TimeOut’>>gs[]>>
Cases_on ‘q = SOME TimeOut’>>gs[]>>
‘q = r'' ∧ t'.ffi.io_events = r'.ffi.io_events’
by (Cases_on ‘k < k'’>>gs[]
>- (qpat_x_assum ‘evaluate _ = (q, _)’ assume_tac>>
drule wordPropsTheory.evaluate_add_clock>>
strip_tac>>pop_assum $ qspec_then ‘k' - k’ assume_tac>>gs[])>>
gs[NOT_LESS]>>
drule wordPropsTheory.evaluate_add_clock>>
strip_tac>>pop_assum $ qspec_then ‘k - k'’ assume_tac>>gs[])>>gs[]>>
Cases_on ‘r''’>>gs[]>>rename1 ‘SOME x''’>>Cases_on ‘x''’>>gs[])>>
first_x_assum $ qspec_then ‘k’ assume_tac>>
qmatch_asmsub_abbrev_tac ‘FST ev’>>
Cases_on ‘ev’>>gs[]>>rename1 ‘(q,r')’>>
qexists_tac ‘k’>>gs[]>>
drule memory_swap_lemma>>fs[]>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
disch_then $ qspec_then ‘m’ assume_tac>>gs[]>>metis_tac[])>>
IF_CASES_TAC>>gs[]
>- (qmatch_asmsub_abbrev_tac ‘FST ev’>>
Cases_on ‘ev’>>gs[]>>rename1 ‘(q,r)’>>
drule memory_swap_lemma>>fs[]>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
qexists_tac ‘m’>>gs[]>>
strip_tac>>
strip_tac>>
last_x_assum $ qspec_then ‘k’ assume_tac>>gs[]>>
last_x_assum $ qspec_then ‘k’ assume_tac>>gs[])>>
DEEP_INTRO_TAC some_intro >> simp[] >>
strip_tac>>strip_tac
>- (strip_tac>>
drule memory_swap_lemma>>fs[]>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
qexists_tac ‘m’>>gs[]>>
strip_tac>>
strip_tac>>gs[]>>
last_x_assum $ qspec_then ‘k’ assume_tac>>gs[]>>
last_x_assum $ qspec_then ‘k’ assume_tac>>gs[])>>
irule lprefix_lubTheory.IMP_build_lprefix_lub_EQ>>
conj_tac
>- (rw[lprefix_chain_def]>>
Cases_on ‘k < k'’
>- (irule OR_INTRO_THM1>>gs[LPREFIX_fromList]>>
gs[from_toList]>>
irule IS_PREFIX_TRANS>>
irule_at Any wordPropsTheory.evaluate_add_clock_io_events_mono>>gs[]>>
qexists_tac ‘k' - k’>>gs[])>>
irule OR_INTRO_THM2>>gs[LPREFIX_fromList]>>
gs[from_toList]>>
irule IS_PREFIX_TRANS>>
irule_at Any wordPropsTheory.evaluate_add_clock_io_events_mono>>gs[]>>
qexists_tac ‘k - k'’>>gs[])>>
conj_tac
>- (rw[lprefix_chain_def]>>
Cases_on ‘k < k'’
>- (irule OR_INTRO_THM1>>gs[LPREFIX_fromList]>>
gs[from_toList]>>
irule IS_PREFIX_TRANS>>
irule_at Any wordPropsTheory.evaluate_add_clock_io_events_mono>>gs[]>>
qexists_tac ‘k' - k’>>gs[])>>
irule OR_INTRO_THM2>>gs[LPREFIX_fromList]>>
gs[from_toList]>>
irule IS_PREFIX_TRANS>>
irule_at Any wordPropsTheory.evaluate_add_clock_io_events_mono>>gs[]>>
qexists_tac ‘k - k'’>>gs[])>>
conj_tac
>- (gs[lprefix_rel_def]>>strip_tac>>strip_tac>>gs[LPREFIX_fromList]>>
irule_at Any EQ_REFL>>gs[from_toList]>>
qmatch_goalsub_abbrev_tac ‘SND ev’>>
Cases_on ‘ev’>>gs[]>>
qexists_tac ‘k’>>gs[]>>
drule memory_swap_lemma>>gs[]>>strip_tac>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
first_x_assum $ qspec_then ‘m’ assume_tac>>gs[])>>
gs[lprefix_rel_def]>>strip_tac>>strip_tac>>gs[LPREFIX_fromList]>>
irule_at Any EQ_REFL>>gs[from_toList]>>
qexists_tac ‘k’>>gs[]>>
qpat_abbrev_tac ‘ev = evaluate (Call _ _ _ _, s with clock := _)’>>
Cases_on ‘ev’>>gs[]>>
drule memory_swap_lemma>>gs[]>>strip_tac>>
fs[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def]>>
first_x_assum $ qspec_then ‘m’ assume_tac>>gs[]
QED
(* accounting for the resources *)
Theorem word_to_word_compile_no_install_no_alloc:
word_to_word$compile wconf aconf progs0 = (col, progs) ∧
ALL_DISTINCT (MAP FST progs0) ∧
no_mt_code (fromAList progs0) ∧
no_install_code (fromAList progs0) ⇒
no_install_code (fromAList progs) ∧
(no_alloc_code (fromAList progs0) ⇒ no_alloc_code (fromAList progs))
Proof
strip_tac>>gs[word_to_wordTheory.compile_def]>>
rpt (pairarg_tac>>gs[])>>
gvs[]>>
DEP_REWRITE_TAC[word_to_wordProofTheory.no_mt_code_full_compile_single]>>
simp []>>
conj_asm1_tac >- (
fs[word_to_wordTheory.next_n_oracle_def]>>every_case_tac>>gvs[]
)>>
fs[wordPropsTheory.no_install_code_def, wordPropsTheory.no_alloc_code_def,
lookup_fromAList]>>
fs[wordConvsTheory.no_install_subprogs_def,
wordConvsTheory.no_alloc_subprogs_def]>>
rw[]>>drule ALOOKUP_MEM>>strip_tac>>
gs[PAIR_FST_SND_EQ, MEM_MAP]>>
irule wordConvsProofTheory.compile_single_not_created_subprogs>>
first_x_assum irule>>
gs[MEM_ZIP]>>
drule_at Any ALOOKUP_ALL_DISTINCT_EL>>
rw[]>>
drule_then (irule_at Any) EQ_TRANS>>
simp[PAIR_FST_SND_EQ]
QED
Theorem no_alloc_word_evaluate:
∀prog s res t.
wordSem$evaluate (prog,s) = (res,t) ∧
no_install_code s.code ∧ no_alloc_code s.code ∧
no_install prog ∧ no_alloc prog ⇒
res ≠ SOME NotEnoughSpace
Proof
recInduct (name_ind_cases [] wordSemTheory.evaluate_ind)>>
rw[wordConvsTheory.no_alloc_def,
wordConvsTheory.no_install_def,
wordConvsTheory.no_mt_def,
wordSemTheory.evaluate_def]
>~ [`Case (Call _ _ _ _, _)`]
>- (
fs [CaseEq "option", CaseEq "word_loc", CaseEq "bool"] >> gvs [] >>
fs [CaseEq "prod"] >> gvs [] >>
drule wordPropsTheory.no_alloc_find_code >>
drule_at (Pos (el 2)) wordPropsTheory.no_install_find_code >>
CCONTR_TAC >> gs [] >>
fs [CaseEq "option", CaseEq "bool", CaseEq "prod"] >>
imp_res_tac wordPropsTheory.no_install_evaluate_const_code >>
gvs [] >>
fs[AllCaseEqs (), UNCURRY_eq_pair, wordSemTheory.set_var_def,
wordSemTheory.pop_env_def] >> gvs []
)
>~ [`Case (ShareInst op _ _, _)`]
>- (
fs [CaseEq "option", CaseEq "word_loc"] >>
Cases_on `op` >>
gs[wordSemTheory.share_inst_def,
wordSemTheory.sh_mem_load_def, wordSemTheory.sh_mem_load_byte_def,
wordSemTheory.sh_mem_store_def, wordSemTheory.sh_mem_store_byte_def,
wordSemTheory.sh_mem_load32_def, wordSemTheory.sh_mem_store32_def,
ffiTheory.call_FFI_def]>>
every_case_tac>>
fs[wordSemTheory.sh_mem_set_var_def,
wordSemTheory.set_var_def, wordSemTheory.flush_state_def]>>
gvs[]
)
>>
CCONTR_TAC>> fs[]>>
fs[AllCaseEqs (), UNCURRY_eq_pair]>>
imp_res_tac wordPropsTheory.no_install_evaluate_const_code>>
gs[]
QED
Theorem panLang_wordSem_neq_NotEnoughSpace:
evaluate (Call NONE (SOME start) [0] NONE, s with clock := k) = (res, t) ∧
ALL_DISTINCT (MAP FST pan_code) ∧
word_to_word_compile c.word_to_word_conf mc.target.config
(pan_to_word_compile_prog mc.target.config.ISA pan_code) = (col,wprog) ∧
s.code = fromAList wprog ⇒
res ≠ SOME NotEnoughSpace
Proof
rw[]>>
qmatch_asmsub_abbrev_tac ‘wordSem$evaluate (prg, _) = _’ >>
‘no_install prg /\ no_alloc prg /\ no_mt prg’
by gs[wordConvsTheory.no_alloc_def, wordConvsTheory.no_install_def,
wordConvsTheory.no_mt_def, Abbr ‘prg’]>>
qmatch_asmsub_abbrev_tac ‘word_to_word_compile _ _ wprog0’>>
qpat_x_assum ‘Abbrev (_ = _)’ (assume_tac o GSYM o REWRITE_RULE [markerTheory.Abbrev_def])>>
‘ALL_DISTINCT (MAP FST wprog0)’
by (drule pan_to_wordProofTheory.first_compile_prog_all_distinct>>
strip_tac>>gvs[])>>
drule_then irule no_alloc_word_evaluate >>
imp_res_tac pan_to_word_compile_prog_no_install_code>>
imp_res_tac pan_to_word_compile_prog_no_alloc_code>>
imp_res_tac pan_to_word_compile_prog_no_mt_code>>
drule word_to_word_compile_no_install_no_alloc>>
simp []
QED
Theorem inst_stack_size_const_panLang:
∀i s t.
wordSem$inst i s = SOME t ==>
t.stack_size = s.stack_size
Proof
Induct>>rw[wordSemTheory.inst_def,wordSemTheory.assign_def]>>
fs [AllCaseEqs (), UNCURRY_eq_pair] >>
gvs [wordSemTheory.word_exp_def,
wordSemTheory.set_var_def,
wordSemTheory.mem_store_def,
wordSemTheory.get_fp_var_def,
wordSemTheory.get_var_def,
wordSemTheory.get_vars_def]
QED
Theorem inst_stack_limit_const_panLang:
∀i s t.
wordSem$inst i s = SOME t ==>
t.stack_limit = s.stack_limit
Proof
Induct>>rw[wordSemTheory.inst_def,wordSemTheory.assign_def]>>
fs [AllCaseEqs (), UNCURRY_eq_pair] >>
gvs[wordSemTheory.word_exp_def,
wordSemTheory.set_var_def,
wordSemTheory.mem_store_def,
wordSemTheory.get_fp_var_def,
wordSemTheory.get_var_def,
wordSemTheory.get_vars_def]
QED
Theorem inst_stack_max_const_panLang:
∀i s t.
wordSem$inst i s = SOME t ==>
t.stack_max = s.stack_max
Proof
Induct>>rw[wordSemTheory.inst_def,wordSemTheory.assign_def]>>
fs [AllCaseEqs (), UNCURRY_eq_pair] >>
gvs[wordSemTheory.word_exp_def,
wordSemTheory.set_var_def,
wordSemTheory.mem_store_def,
wordSemTheory.get_fp_var_def,
wordSemTheory.get_var_def,
wordSemTheory.get_vars_def]
QED
Theorem share_inst_modifies:
wordSem$share_inst op v ad s = (res, t) ==>
? ls ffi stk lsz.
t = (s with <| locals := ls; ffi := ffi;
stack := stk; locals_size := lsz |>)
Proof
Cases_on ‘op’>>
gs[wordSemTheory.share_inst_def,
wordSemTheory.sh_mem_load_def,
wordSemTheory.sh_mem_load_def,
wordSemTheory.sh_mem_load_byte_def,
wordSemTheory.sh_mem_load32_def,
wordSemTheory.sh_mem_store_def,
wordSemTheory.sh_mem_store_byte_def,
wordSemTheory.sh_mem_store32_def,
ffiTheory.call_FFI_def]>>
every_case_tac >>
fs[wordSemTheory.sh_mem_set_var_def,
wordSemTheory.set_var_def,
wordSemTheory.flush_state_def]>>gvs[] >>
rw [] >>
simp [wordSemTheory.state_component_equality]
QED
Theorem evaluate_stack_size_limit_const_panLang:
∀prog s res t.
wordSem$evaluate (prog, s) = (res,t) ∧
no_install prog ∧ no_install_code s.code ∧
no_alloc prog ∧ no_alloc_code s.code ==>
t.stack_size = s.stack_size /\ t.stack_limit = s.stack_limit
Proof
recInduct (name_ind_cases [] wordSemTheory.evaluate_ind)>>
simp[wordSemTheory.evaluate_def,wordSemTheory.flush_state_def]>>
rpt conj_tac>>rpt (gen_tac ORELSE disch_tac)>>
gs[wordConvsTheory.no_install_def,
wordConvsTheory.no_alloc_def,
wordConvsTheory.no_mt_def,
wordSemTheory.jump_exc_def,
wordSemTheory.get_var_def, wordSemTheory.mem_store_def]
>~ [`Case (Call _ _ _ _, _)`]
>- (
fs [CaseEq "option"]
\\ fs [CaseEq "option", CaseEq "prod", CaseEq "bool"] \\ gvs []
\\ imp_res_tac wordPropsTheory.no_install_find_code
\\ imp_res_tac wordPropsTheory.no_alloc_find_code
\\ imp_res_tac wordPropsTheory.no_install_evaluate_const_code
\\ gs []