source: src/ASM/Interpret2.ma @ 2907

Last change on this file since 2907 was 2907, checked in by sacerdot, 8 years ago
  1. a few bugs fixed
  2. as_return implemented for ASM & OC
File size: 4.3 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 … st))
45   (initialise_status … (load_code_memory (oc 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
107definition ASM_abstract_status:
108 ∀prog:pseudo_assembly_program.∀sigma,policy.abstract_status ≝
109  λprog,sigma,policy.
110    mk_abstract_status
111      (PseudoStatus prog)
112      (λs1,s2. execute_1_pseudo_instruction' … sigma policy s1 = s2)
113      word_deqset
114      (program_counter …)
115      (ASM_classify …)
116      (ASM_as_label_of_pc prog …)
117      (ASM_next_instruction_properly_relates_program_counters prog)
118      (ASM_as_result …)
119      ?
120      ?.
121  #x cases daemon (* XXX: (tail)call_ident function *)
122qed.
123
124definition ASM_preclassified_system:
125 pseudo_assembly_program → ∀sigma,policy. preclassified_system ≝
126 λc,sigma,policy.
127  mk_preclassified_system_of_abstract_status
128   (pseudo_assembly_program × (Word → Word) × (Word → bool))
129   (ASM_abstract_status c sigma policy)
130   (λst. return (execute_1_pseudo_instruction' … sigma policy st))
131   (initialise_status … c).
Note: See TracBrowser for help on using the repository browser.