source: src/ASM/Interpret2.ma @ 2999

Last change on this file since 2999 was 2999, checked in by sacerdot, 7 years ago

code_memory added to labelled_object_code to avoid recomputing it every time.
This gives a major speed up in the semantics of the extracted code.

File size: 5.0 KB
Line 
1include "ASM/ASMCosts.ma".
2include "common/Measurable.ma".
3
4(* Move where abstract_status is defined! *)
5definition mk_trans_system_of_abstract_status:
6 ∀S:abstract_status. (S → IOMonad io_out io_in S) → trans_system io_out io_in
7
8 λS,as_eval.
9  mk_trans_system ?? unit (λ_.as_status S) (λ_.as_result S)
10   (λ_.λstatus.
11     let tr ≝
12      match as_label … status with
13      [ Some cst ⇒ Echarge cst
14      | None ⇒ E0 ] in
15     ! status' ← as_eval … status ;
16     return 〈 tr, status' 〉).
17
18definition mk_fullexec_of_abstract_status:
19 ∀program: Type[0].
20  ∀S:abstract_status. (S → IOMonad io_out io_in S) → as_status S → fullexec io_out io_in
21≝ λprogram,S,as_eval,as_init.
22   mk_fullexec ?? program (mk_trans_system_of_abstract_status S as_eval) (λ_.it)
23    (λ_.return as_init).
24
25definition mk_preclassified_system_of_abstract_status:
26 ∀program: Type[0].
27  ∀S:abstract_status. (S → IOMonad io_out io_in S) → as_status S → preclassified_system
28≝ λprogram,S,as_eval,as_init.
29   mk_preclassified_system
30    (mk_fullexec_of_abstract_status program S as_eval as_init)
31    (λ_.λst. ¬(is_none … (as_label … st)))
32    (λ_.as_classify S)
33    (λ_.λst,prf. as_call_ident S «st,?»).
34 @hide_prf cases (as_classify ??) in prf; normalize // *
35qed.
36
37(* End move *)
38
39definition OC_preclassified_system: labelled_object_code → preclassified_system ≝
40 λc:labelled_object_code.
41  mk_preclassified_system_of_abstract_status
42   labelled_object_code
43   (OC_abstract_status c)
44   (λst. return (execute_1 (cm c) … st))
45   (initialise_status … (cm c)).
46
47(* Pre-classified system for ASM *)
48
49include "ASM/Assembly.ma".
50
51(* Move next function in interpret? *)
52definition execute_1_pseudo_instruction':
53 ∀cm. ∀sigma,policy.PseudoStatus cm → PseudoStatus cm ≝
54 λcm,sigma,policy,status.
55  execute_1_pseudo_instruction cm
56   (ticks_of cm  sigma policy) status ….
57cases daemon (*CSC: we need to prove that we remain inside the program
58 (code closed), which is impossible in case of function pointers.
59 But the type does not allow to fail (yet?) *)
60qed.
61
62definition classify_pseudo_instruction: pseudo_instruction → status_class ≝
63 λinstr.
64  match instr with
65  [ Instruction pre ⇒ ASM_classify00 … pre
66  | Comment _ ⇒ cl_other
67  | Cost _ ⇒ cl_other
68  | Jmp _ ⇒ cl_other
69  | Jnz _ _ _ ⇒ cl_jump
70  | MovSuccessor _ _ _ ⇒ cl_other
71  | Call _ ⇒ cl_call
72  | Mov _ _ ⇒ cl_other ].
73
74definition ASM_classify: ∀cm. PseudoStatus cm → status_class ≝
75λcm,s.
76 classify_pseudo_instruction
77  (\fst (fetch_pseudo_instruction (code cm) (program_counter … s) ?)).
78cases daemon (*CSC: again*)
79qed.
80
81definition ASM_next_instruction_properly_relates_program_counters ≝
82  λcm.
83  λbefore: PseudoStatus cm.
84  λafter : PseudoStatus cm.
85    let 〈instruction, program_counter_after〉 ≝
86     fetch_pseudo_instruction (code cm) (program_counter … before) ?
87    in
88     program_counter ?? after = program_counter_after.
89cases daemon (*CSC: again*)
90qed.
91
92definition ASM_as_label_of_pc:
93 ∀prog:pseudo_assembly_program. Word → option costlabel
94
95 λprog,pc.
96 match \fst (fetch_pseudo_instruction (code prog) pc ?) with
97 [ Cost label ⇒ Some … label
98 | _ ⇒ None ? ].
99cases daemon (*CSC: again*)
100qed.
101
102definition ASM_as_result: ∀prog. PseudoStatus prog → option int ≝
103 λprog,st.
104  let finaladdr ≝ address_of_word_labels (code prog) (final_label … prog) in
105   as_result_of_finaladdr … st finaladdr.
106
107include "common/AssocList.ma".
108
109definition ASM_as_call_ident:
110 ∀prog,sigma,policy.(Σs:PseudoStatus prog. ASM_classify … s = cl_call) → ident
111
112 λprog,sigma,policy,s0.
113  let st ≝ execute_1_pseudo_instruction' prog sigma policy s0 in
114  let 〈lbl, instr〉 ≝ nth_safe … (nat_of_bitvector ? (program_counter … st)) … (code prog) ? in
115  match lbl with
116  [ None ⇒ ⊥
117  | Some lbl' ⇒
118     match assoc_list_lookup ?? lbl' (eq_identifier …) (renamed_symbols prog) with
119     [ None ⇒ ⊥ | Some id ⇒ id ]].
120cases daemon (*CSC: we need a specification of the renamed_symbols for this *)
121qed.
122
123definition ASM_abstract_status:
124 ∀prog:pseudo_assembly_program.∀sigma,policy.abstract_status ≝
125  λprog,sigma,policy.
126    mk_abstract_status
127      (PseudoStatus prog)
128      (λs1,s2. execute_1_pseudo_instruction' … sigma policy s1 = s2)
129      word_deqset
130      (program_counter …)
131      (ASM_classify …)
132      (ASM_as_label_of_pc prog …)
133      (ASM_next_instruction_properly_relates_program_counters prog)
134      (ASM_as_result …)
135      (ASM_as_call_ident prog sigma policy …)
136      ?.
137 * #st whd in ⊢ (??%? → ?); cases (\fst (fetch_pseudo_instruction ???)) [*]
138 normalize try (#x #y #abs) try (#x #abs) try #abs destruct (abs)
139qed.
140
141definition ASM_preclassified_system:
142 pseudo_assembly_program → ∀sigma,policy. preclassified_system ≝
143 λc,sigma,policy.
144  mk_preclassified_system_of_abstract_status
145   (pseudo_assembly_program × (Word → Word) × (Word → bool))
146   (ASM_abstract_status c sigma policy)
147   (λst. return (execute_1_pseudo_instruction' … sigma policy st))
148   (initialise_status … c).
Note: See TracBrowser for help on using the repository browser.