1 | include "common/BackEndOps.ma". |
---|
2 | include "common/CostLabel.ma". |
---|
3 | include "common/Registers.ma". |
---|
4 | include "ASM/I8051.ma". |
---|
5 | include "common/Graphs.ma". |
---|
6 | include "utilities/lists.ma". |
---|
7 | include "common/LabelledObjects.ma". |
---|
8 | include "ASM/Util.ma". |
---|
9 | include "common/StructuredTraces.ma". |
---|
10 | |
---|
11 | (* Here is the structure of parameter records (downward edges are coercions, |
---|
12 | the ↓ edges are the only explicitly defined coercions). lin_params and |
---|
13 | graph_params are simple wrappers of unserialized_params, and the coercions |
---|
14 | from them to params instantiate the missing bits with values for linarized |
---|
15 | programs and graph programs respectively. |
---|
16 | |
---|
17 | lin_params graph_params |
---|
18 | | \_____ /____ | |
---|
19 | | / \ | |
---|
20 | | / ↓ ↓ |
---|
21 | | | params |
---|
22 | | | | |
---|
23 | | | stmt_params |
---|
24 | | | / |
---|
25 | unserialized_params |
---|
26 | |
---|
27 | unserialized_params : things unrelated to being in graph or linear form |
---|
28 | stmt_params : adds successor type needed to define statements |
---|
29 | params : adds type of code and related properties *) |
---|
30 | |
---|
31 | inductive possible_flows : Type[0] ≝ |
---|
32 | | Labels : list label → possible_flows |
---|
33 | | Call : possible_flows. |
---|
34 | |
---|
35 | inductive argument (T : Type[0]) : Type[0] ≝ |
---|
36 | | Reg : T → argument T |
---|
37 | | Imm : beval → argument T. |
---|
38 | |
---|
39 | definition psd_argument ≝ argument register. |
---|
40 | |
---|
41 | definition psd_argument_from_reg : register → psd_argument ≝ Reg register. |
---|
42 | coercion reg_to_psd_argument : ∀r : register.psd_argument ≝ psd_argument_from_reg |
---|
43 | on _r : register to psd_argument. |
---|
44 | |
---|
45 | definition psd_argument_from_beval : beval → psd_argument ≝ Imm register. |
---|
46 | coercion beval_to_psd_argument : ∀b : beval.psd_argument ≝ psd_argument_from_beval |
---|
47 | on _b : beval to psd_argument. |
---|
48 | |
---|
49 | definition psd_argument_from_byte : Byte → psd_argument ≝ λb.Imm ? (BVByte b). |
---|
50 | coercion byte_to_psd_argument : ∀b : Byte.psd_argument ≝ psd_argument_from_byte |
---|
51 | on _b : Byte to psd_argument. |
---|
52 | |
---|
53 | definition hdw_argument ≝ argument Register. |
---|
54 | |
---|
55 | definition hdw_argument_from_reg : Register → hdw_argument ≝ Reg Register. |
---|
56 | coercion reg_to_hdw_argument : ∀r : Register.hdw_argument ≝ hdw_argument_from_reg |
---|
57 | on _r : Register to hdw_argument. |
---|
58 | |
---|
59 | definition hdw_argument_from_beval : beval → hdw_argument ≝ Imm Register. |
---|
60 | coercion beval_to_hdw_argument : ∀b : beval.hdw_argument ≝ hdw_argument_from_beval |
---|
61 | on _b : beval to hdw_argument. |
---|
62 | |
---|
63 | definition hdw_argument_from_byte : Byte → hdw_argument ≝ λb.Imm ? (BVByte b). |
---|
64 | coercion byte_to_hdw_argument : ∀b : Byte.psd_argument ≝ psd_argument_from_byte |
---|
65 | on _b : Byte to hdw_argument. |
---|
66 | |
---|
67 | definition byte_of_nat : nat → Byte ≝ bitvector_of_nat 8. |
---|
68 | definition zero_byte : Byte ≝ bv_zero 8. |
---|
69 | |
---|
70 | record unserialized_params : Type[1] ≝ |
---|
71 | { acc_a_reg: Type[0] (* registers that will eventually need to be A *) |
---|
72 | ; acc_b_reg: Type[0] (* registers that will eventually need to be B *) |
---|
73 | ; acc_a_arg: Type[0] (* arguments that will eventually need to be A *) |
---|
74 | ; acc_b_arg: Type[0] (* arguments that will eventually need to be B *) |
---|
75 | ; dpl_reg: Type[0] (* low address registers *) |
---|
76 | ; dph_reg: Type[0] (* high address registers *) |
---|
77 | ; dpl_arg: Type[0] (* low address registers *) |
---|
78 | ; dph_arg: Type[0] (* high address registers *) |
---|
79 | ; snd_arg : Type[0] (* second argument of binary op *) |
---|
80 | ; pair_move: Type[0] (* argument of move instructions *) |
---|
81 | ; call_args: Type[0] (* arguments of function calls *) |
---|
82 | ; call_dest: Type[0] (* possible destination of function computation *) |
---|
83 | (* other instructions not fitting in the general framework *) |
---|
84 | ; ext_seq : Type[0] |
---|
85 | (* ; ext_branch : Type[0] |
---|
86 | ; ext_branch_labels : ext_branch → list label*) |
---|
87 | ; ext_call : Type[0] |
---|
88 | ; ext_tailcall : Type[0] |
---|
89 | (* if needed: ; ext_fin_branch : Type[0] ; ext_fin_branch_labels : ext_fin_branch → list label *) |
---|
90 | ; paramsT : Type[0] |
---|
91 | ; localsT: Type[0] |
---|
92 | }. |
---|
93 | |
---|
94 | inductive joint_seq (p:unserialized_params) (globals: list ident): Type[0] ≝ |
---|
95 | | COMMENT: String → joint_seq p globals |
---|
96 | | COST_LABEL: costlabel → joint_seq p globals |
---|
97 | | MOVE: pair_move p → joint_seq p globals |
---|
98 | | POP: acc_a_reg p → joint_seq p globals |
---|
99 | | PUSH: acc_a_arg p → joint_seq p globals |
---|
100 | | ADDRESS: ∀i: ident. (member i (eq_identifier ?) globals) → dpl_reg p → dph_reg p → joint_seq p globals |
---|
101 | | OPACCS: OpAccs → acc_a_reg p → acc_b_reg p → acc_a_arg p → acc_b_arg p → joint_seq p globals |
---|
102 | | OP1: Op1 → acc_a_reg p → acc_a_reg p → joint_seq p globals |
---|
103 | | OP2: Op2 → acc_a_reg p → acc_a_arg p → snd_arg p → joint_seq p globals |
---|
104 | (* int done with generic move *) |
---|
105 | (*| INT: generic_reg p → Byte → joint_seq p globals *) |
---|
106 | | CLEAR_CARRY: joint_seq p globals |
---|
107 | | SET_CARRY: joint_seq p globals |
---|
108 | | LOAD: acc_a_reg p → dpl_arg p → dph_arg p → joint_seq p globals |
---|
109 | | STORE: dpl_arg p → dph_arg p → acc_a_arg p → joint_seq p globals |
---|
110 | | CALL_ID: ident → call_args p → call_dest p → joint_seq p globals |
---|
111 | | extension_seq : ext_seq p → joint_seq p globals |
---|
112 | | extension_call : ext_call p → joint_seq p globals. |
---|
113 | |
---|
114 | axiom EmptyString : String. |
---|
115 | definition NOOP ≝ λp,globals.COMMENT p globals EmptyString. |
---|
116 | |
---|
117 | notation "r ← a1 .op. a2" with precedence 60 for |
---|
118 | @{'op2 $op $r $a1 $a2}. |
---|
119 | notation "r ← . op . a" with precedence 60 for |
---|
120 | @{'op1 $op $r $a}. |
---|
121 | notation "r ← a" with precedence 60 for |
---|
122 | @{'mov $r $a}. (* to be set in individual languages *) |
---|
123 | notation "❮r, s❯ ← a1 . op . a2" with precedence 55 for |
---|
124 | @{'opaccs $op $r $s $a1 $a2}. |
---|
125 | |
---|
126 | interpretation "op2" 'op2 op r a1 a2 = (OP2 ? ? op r a1 a2). |
---|
127 | interpretation "op1" 'op1 op r a = (OP1 ? ? op r a). |
---|
128 | interpretation "opaccs" 'opaccs op r s a1 a2 = (OPACCS ? ? op r s a1 a2). |
---|
129 | |
---|
130 | coercion extension_seq_to_seq : ∀p,globals.∀s : ext_seq p.joint_seq p globals ≝ |
---|
131 | extension_seq on _s : ext_seq ? to joint_seq ??. |
---|
132 | coercion extension_call_to_seq : ∀p,globals.∀s : ext_call p.joint_seq p globals ≝ |
---|
133 | extension_call on _s : ext_call ? to joint_seq ??. |
---|
134 | |
---|
135 | (* inductive joint_branch (p : step_params) : Type[0] ≝ |
---|
136 | | COND: acc_a_reg p → label → joint_branch p |
---|
137 | | extension_branch : ext_branch p → joint_branch p.*) |
---|
138 | |
---|
139 | (*coercion extension_to_branch : ∀p.∀s : ext_branch p.joint_branch p ≝ |
---|
140 | extension_branch on _s : ext_branch ? to joint_branch ?.*) |
---|
141 | |
---|
142 | inductive joint_step (p : unserialized_params) (globals : list ident) : Type[0] ≝ |
---|
143 | | step_seq : joint_seq p globals → joint_step p globals |
---|
144 | | COND: acc_a_reg p → label → joint_step p globals. |
---|
145 | |
---|
146 | coercion seq_to_step : ∀p,globals.∀s : joint_seq p globals.joint_step p globals ≝ |
---|
147 | step_seq on _s : joint_seq ?? to joint_step ??. |
---|
148 | |
---|
149 | definition step_flows ≝ λp,globals.λs : joint_step p globals. |
---|
150 | match s with |
---|
151 | [ step_seq s ⇒ |
---|
152 | match s with |
---|
153 | [ CALL_ID _ _ _ ⇒ Call |
---|
154 | | extension_call _ ⇒ Call |
---|
155 | | _ ⇒ Labels … [ ] |
---|
156 | ] |
---|
157 | | COND _ l ⇒ Labels … [l] |
---|
158 | ]. |
---|
159 | |
---|
160 | definition step_labels ≝ |
---|
161 | λp, globals.λs : joint_step p globals. |
---|
162 | match step_flows … s with |
---|
163 | [ Labels lbls ⇒ lbls |
---|
164 | | Call ⇒ [ ] |
---|
165 | ]. |
---|
166 | |
---|
167 | definition step_forall_labels : ∀p.∀globals. |
---|
168 | (label → Prop) → joint_step p globals → Prop ≝ |
---|
169 | λp,g,P,inst. All … P (step_labels … inst). |
---|
170 | |
---|
171 | definition step_classifier : |
---|
172 | ∀p.∀globals. |
---|
173 | joint_step p globals → status_class ≝ λp,g,s. |
---|
174 | match s with |
---|
175 | [ step_seq s ⇒ |
---|
176 | match s with |
---|
177 | [ CALL_ID l _ _ ⇒ cl_call l |
---|
178 | | extension_call _ ⇒ cl_call ? (* pointer stuff not yet implemented, it seems *) |
---|
179 | | _ ⇒ cl_other |
---|
180 | ] |
---|
181 | | COND _ _ ⇒ cl_jump |
---|
182 | ]. |
---|
183 | cases daemon |
---|
184 | qed. |
---|
185 | |
---|
186 | record stmt_params : Type[1] ≝ |
---|
187 | { uns_pars :> unserialized_params |
---|
188 | ; succ : Type[0] |
---|
189 | ; succ_label : succ → option label |
---|
190 | }. |
---|
191 | |
---|
192 | inductive joint_fin_step (p: unserialized_params): Type[0] ≝ |
---|
193 | | GOTO: label → joint_fin_step p |
---|
194 | | RETURN: joint_fin_step p |
---|
195 | | tailcall : ext_tailcall p → joint_fin_step p. |
---|
196 | |
---|
197 | definition fin_step_flows ≝ λp.λs : joint_fin_step p. |
---|
198 | match s with |
---|
199 | [ GOTO l ⇒ Labels … [l] |
---|
200 | | tailcall _ ⇒ Call (* tailcalls will need to be integrated in structured traces *) |
---|
201 | | _ ⇒ Labels … [ ] |
---|
202 | ]. |
---|
203 | |
---|
204 | definition fin_step_labels ≝ |
---|
205 | λp.λs : joint_fin_step p. |
---|
206 | match fin_step_flows … s with |
---|
207 | [ Labels lbls ⇒ lbls |
---|
208 | | Call ⇒ [ ] |
---|
209 | ]. |
---|
210 | |
---|
211 | definition fin_step_classifier : |
---|
212 | ∀p : stmt_params. |
---|
213 | joint_fin_step p → status_class |
---|
214 | ≝ λp,s. |
---|
215 | match s with |
---|
216 | [ GOTO _ ⇒ cl_other |
---|
217 | | _ ⇒ cl_return |
---|
218 | ]. |
---|
219 | |
---|
220 | inductive joint_statement (p: stmt_params) (globals: list ident): Type[0] ≝ |
---|
221 | | sequential: joint_step p globals → succ p → joint_statement p globals |
---|
222 | | final: joint_fin_step p → joint_statement p globals. |
---|
223 | |
---|
224 | definition stmt_classifier : |
---|
225 | ∀p : stmt_params.∀globals. |
---|
226 | joint_statement p globals → status_class |
---|
227 | ≝ λp,g,s. |
---|
228 | match s with |
---|
229 | [ sequential stp _ ⇒ step_classifier p g stp |
---|
230 | | final stp ⇒ fin_step_classifier p stp |
---|
231 | ]. |
---|
232 | |
---|
233 | coercion extension_fin_to_fin_step : ∀p : stmt_params. |
---|
234 | ∀s : ext_tailcall p.joint_fin_step p ≝ |
---|
235 | tailcall on _s : ext_tailcall ? to joint_fin_step ?. |
---|
236 | |
---|
237 | coercion fin_step_to_stmt : ∀p : stmt_params.∀globals. |
---|
238 | ∀s : joint_fin_step p.joint_statement p globals ≝ |
---|
239 | final on _s : joint_fin_step ? to joint_statement ??. |
---|
240 | |
---|
241 | record params : Type[1] ≝ |
---|
242 | { stmt_pars :> stmt_params |
---|
243 | ; codeT: list ident → Type[0] |
---|
244 | ; code_point : Type[0] |
---|
245 | ; stmt_at : ∀globals.codeT globals → code_point → option (joint_statement stmt_pars globals) |
---|
246 | ; point_of_label : ∀globals.codeT globals → label → option code_point |
---|
247 | ; point_of_succ : code_point → succ stmt_pars → code_point |
---|
248 | }. |
---|
249 | |
---|
250 | definition code_has_point ≝ |
---|
251 | λp,globals,c,pt.match stmt_at p globals c pt with [Some _ ⇒ true | None ⇒ false]. |
---|
252 | |
---|
253 | (* interpretation "code membership" 'mem p c = (code_has_point ?? c p). *) |
---|
254 | |
---|
255 | definition point_in_code ≝ λp,globals,code.Σpt.bool_to_Prop (code_has_point p globals code pt). |
---|
256 | unification hint 0 ≔ p, globals, code ⊢ point_in_code p globals code ≡ Sig (code_point p) (λpt.bool_to_Prop (code_has_point p globals code pt)). |
---|
257 | |
---|
258 | definition stmt_at_safe ≝ λp,globals,code.λpt : point_in_code p globals code. |
---|
259 | match pt with |
---|
260 | [ mk_Sig pt' pt_prf ⇒ |
---|
261 | match stmt_at … code pt' return λx.stmt_at … code pt' = x → ? with |
---|
262 | [ Some x ⇒ λ_.x |
---|
263 | | None ⇒ λabs.⊥ |
---|
264 | ] (refl …) |
---|
265 | ]. normalize in pt_prf; |
---|
266 | >abs in pt_prf; // qed. |
---|
267 | |
---|
268 | definition forall_statements : ∀p : params.∀globals.pred_transformer (joint_statement p globals) (codeT p globals) ≝ |
---|
269 | λp,globals,P,c. ∀pt,s.stmt_at ?? c pt = Some ? s → P s. |
---|
270 | |
---|
271 | definition forall_statements_i : |
---|
272 | ∀p : params.∀globals.(code_point p → joint_statement p globals → Prop) → |
---|
273 | codeT p globals → Prop ≝ |
---|
274 | λp,globals,P,c. ∀pt,s.stmt_at ?? c pt = Some ? s → P pt s. |
---|
275 | |
---|
276 | lemma forall_statements_mp : ∀p,globals.modus_ponens ?? (forall_statements p globals). |
---|
277 | #p #globals #P #Q #H #y #G #pnt #s #EQ @H @(G … EQ) qed. |
---|
278 | |
---|
279 | lemma forall_statements_i_mp : ∀p,globals.∀P,Q.(∀pt,s.P pt s → Q pt s) → |
---|
280 | ∀c.forall_statements_i p globals P c → forall_statements_i p globals Q c. |
---|
281 | #p #globals #P #Q #H #y #G #pnt #s #EQ @H @(G … EQ) qed. |
---|
282 | |
---|
283 | definition code_has_label ≝ λp,globals,c,l. |
---|
284 | match point_of_label p globals c l with |
---|
285 | [ Some pt ⇒ code_has_point … c pt |
---|
286 | | None ⇒ false |
---|
287 | ]. |
---|
288 | |
---|
289 | definition stmt_explicit_labels : |
---|
290 | ∀p,globals. |
---|
291 | joint_statement p globals → list label ≝ |
---|
292 | λp,globals,stmt. match stmt with |
---|
293 | [ sequential c _ ⇒ step_labels … c |
---|
294 | | final c ⇒ fin_step_labels … c |
---|
295 | ]. |
---|
296 | |
---|
297 | definition stmt_implicit_label : ∀p,globals.joint_statement p globals → |
---|
298 | option label ≝ |
---|
299 | λp,globals,s.match s with [ sequential _ s ⇒ succ_label … s | _ ⇒ None ?]. |
---|
300 | |
---|
301 | definition stmt_labels : ∀p : stmt_params.∀globals. |
---|
302 | joint_statement p globals → list label ≝ |
---|
303 | λp,g,stmt. |
---|
304 | (match stmt_implicit_label … stmt with |
---|
305 | [ Some l ⇒ [l] |
---|
306 | | None ⇒ [ ] |
---|
307 | ]) @ stmt_explicit_labels … stmt. |
---|
308 | |
---|
309 | definition stmt_forall_labels ≝ |
---|
310 | λp, globals.λ P : label → Prop.λs : joint_statement p globals. |
---|
311 | All … P (stmt_labels … s). |
---|
312 | |
---|
313 | lemma stmt_forall_labels_explicit : ∀p,globals,P.∀s : joint_statement p globals. |
---|
314 | stmt_forall_labels … P s → All … P (stmt_explicit_labels … s). |
---|
315 | #p#globals#P #s |
---|
316 | whd in ⊢ (% → ?); |
---|
317 | whd in ⊢ (???% → ?); |
---|
318 | elim (stmt_implicit_label ???) [2: #next * #_] // |
---|
319 | qed. |
---|
320 | |
---|
321 | lemma stmt_forall_labels_implicit : ∀p,globals,P.∀s : joint_statement p globals. |
---|
322 | stmt_forall_labels … P s → |
---|
323 | opt_All … P (stmt_implicit_label … s). |
---|
324 | #p#globals#P#s |
---|
325 | whd in ⊢ (% → ?); |
---|
326 | whd in ⊢ (???% → ?); |
---|
327 | elim (stmt_implicit_label ???) |
---|
328 | [ // |
---|
329 | | #next * #Pnext #_ @Pnext |
---|
330 | ] |
---|
331 | qed. |
---|
332 | |
---|
333 | definition code_forall_labels ≝ |
---|
334 | λp,globals,P,c.forall_statements p globals (stmt_forall_labels … P) c. |
---|
335 | |
---|
336 | lemma code_forall_labels_mp : ∀p,globals,P,Q.(∀l.P l → Q l) → |
---|
337 | ∀c.code_forall_labels p globals P c → code_forall_labels … Q c ≝ |
---|
338 | λp,globals,P,Q,H.forall_statements_mp … (λs. All_mp … H ?). |
---|
339 | |
---|
340 | record lin_params : Type[1] ≝ |
---|
341 | { l_u_pars : unserialized_params }. |
---|
342 | |
---|
343 | lemma index_of_label_length : ∀tag,A,lbl,l.occurs_exactly_once ?? lbl l → lt (index_of_label tag A lbl l) (|l|). |
---|
344 | #tag #A #lbl #l elim l [*] |
---|
345 | ** [2: #id] #a #tl #IH |
---|
346 | [ change with (if (eq_identifier ???) then ? else ?) in match (occurs_exactly_once ????); |
---|
347 | change with (if (eq_identifier ???) then ? else ?) in match (index_of_label ????); |
---|
348 | @eq_identifier_elim #Heq normalize nodelta |
---|
349 | [ #_ normalize / by /] |
---|
350 | | whd in ⊢ (?%→?%?); |
---|
351 | ] |
---|
352 | #H >(index_of_label_from_internal … H) |
---|
353 | @le_S_S @(IH H) |
---|
354 | qed. |
---|
355 | |
---|
356 | (* mv *) |
---|
357 | lemma nth_opt_hit_length : ∀A,l,n,x.nth_opt A n l = Some ? x → n < |l|. |
---|
358 | #A #l elim l normalize [ #n #x #ABS destruct(ABS)] |
---|
359 | #hd #tl #IH * [2:#n] #x normalize [#H @le_S_S @(IH … H)] /2 by / |
---|
360 | qed. |
---|
361 | |
---|
362 | lemma nth_opt_miss_length : ∀A,l,n.nth_opt A n l = None ? → n ≥ |l|. |
---|
363 | #A #l elim l [//] #hd #tl #IH * normalize [#ABS destruct(ABS)] |
---|
364 | #n' #H @le_S_S @(IH … H) |
---|
365 | qed. |
---|
366 | |
---|
367 | lemma nth_opt_safe : ∀A,l,n,prf.nth_opt A n l = Some ? (nth_safe A n l prf). |
---|
368 | #A #l elim l |
---|
369 | [ #n #ABS @⊥ /2 by absurd/ |
---|
370 | | #hd #tl #IH * normalize // |
---|
371 | ] |
---|
372 | qed. |
---|
373 | |
---|
374 | definition lin_params_to_params ≝ |
---|
375 | λlp : lin_params. |
---|
376 | mk_params |
---|
377 | (mk_stmt_params (l_u_pars lp) unit (λ_.None ?)) |
---|
378 | (* codeT ≝ *)(λglobals.list ((option label) × (joint_statement ? globals))) |
---|
379 | (* code_point ≝ *)ℕ |
---|
380 | (* stmt_at ≝ *)(λglobals,code,point.! ls ← nth_opt ? point code ; return \snd ls) |
---|
381 | (* point_of_label ≝ *)(λglobals,c,lbl. |
---|
382 | If occurs_exactly_once ?? lbl c then with prf do |
---|
383 | return index_of_label ?? lbl c |
---|
384 | else |
---|
385 | None ?) |
---|
386 | (* point_of_succ ≝ *)(λcurrent.λ_.S (current)). |
---|
387 | |
---|
388 | coercion lp_to_p : ∀lp : lin_params.params ≝ lin_params_to_params |
---|
389 | on _lp : lin_params to params. |
---|
390 | |
---|
391 | lemma lin_code_has_point : ∀lp : lin_params.∀globals.∀code:codeT lp globals. |
---|
392 | ∀pt.code_has_point … code pt = leb (S pt) (|code|). |
---|
393 | #lp #globals #code elim code |
---|
394 | [ #pt % |
---|
395 | | #hd #tl #IH * [%] |
---|
396 | #n @IH |
---|
397 | ]qed. |
---|
398 | |
---|
399 | lemma lin_code_has_label : ∀lp : lin_params.∀globals.∀code:codeT lp globals. |
---|
400 | ∀lbl.code_has_label … code lbl = occurs_exactly_once ?? lbl code. |
---|
401 | #lp #globals #code #lbl |
---|
402 | whd in match (code_has_label ????); |
---|
403 | whd in match (point_of_label ????); |
---|
404 | elim (true_or_false_Prop (occurs_exactly_once ?? lbl code)) |
---|
405 | #Heq >Heq normalize nodelta |
---|
406 | [ >lin_code_has_point @(leb_elim (S ?)) [#_ | |
---|
407 | #ABS elim(absurd ?? ABS) -ABS |
---|
408 | @index_of_label_length assumption ]] % |
---|
409 | qed. |
---|
410 | |
---|
411 | record graph_params : Type[1] ≝ |
---|
412 | { g_u_pars : unserialized_params }. |
---|
413 | |
---|
414 | (* One common instantiation of params via Graphs of joint_statements |
---|
415 | (all languages but LIN) *) |
---|
416 | definition graph_params_to_params ≝ |
---|
417 | λgp : graph_params. |
---|
418 | mk_params |
---|
419 | (mk_stmt_params (g_u_pars gp) label (Some ?)) |
---|
420 | (* codeT ≝ *)(λglobals.graph (joint_statement ? globals)) |
---|
421 | (* code_point ≝ *)label |
---|
422 | (* stmt_at ≝ *)(λglobals,code.lookup LabelTag ? code) |
---|
423 | (* point_of_label ≝ *)(λ_.λ_.λlbl.return lbl) |
---|
424 | (* point_of_succ ≝ *)(λ_.λlbl.lbl). |
---|
425 | |
---|
426 | coercion gp_to_p : ∀gp:graph_params.params ≝ graph_params_to_params |
---|
427 | on _gp : graph_params to params. |
---|
428 | |
---|
429 | lemma graph_code_has_point : ∀gp : graph_params.∀globals.∀code:codeT gp globals. |
---|
430 | ∀pt.code_has_point … code pt = (pt ∈ code). // qed. |
---|
431 | |
---|
432 | lemma graph_code_has_label : ∀gp : graph_params.∀globals.∀code:codeT gp globals. |
---|
433 | ∀lbl.code_has_label … code lbl = (lbl ∈ code). // qed. |
---|
434 | |
---|
435 | definition stmt_forall_succ ≝ λp,globals.λP : succ p → Prop. |
---|
436 | λs : joint_statement p globals. |
---|
437 | match s with |
---|
438 | [ sequential _ n ⇒ P n |
---|
439 | | _ ⇒ True |
---|
440 | ]. |
---|
441 | |
---|
442 | definition statement_closed : ∀globals.∀p : params. |
---|
443 | codeT p globals → code_point p → (joint_statement p globals) → Prop ≝ |
---|
444 | λglobals,p,code,pt,s. |
---|
445 | All ? (λl.bool_to_Prop (code_has_label ?? code l)) (stmt_explicit_labels … s) ∧ |
---|
446 | stmt_forall_succ … (λn.bool_to_Prop (code_has_point … code (point_of_succ ? pt n))) s. |
---|
447 | |
---|
448 | definition code_closed : ∀p : params.∀globals. |
---|
449 | codeT p globals → Prop ≝ λp,globals,code. |
---|
450 | forall_statements_i … (statement_closed … code) code. |
---|
451 | |
---|
452 | record joint_internal_function (p:params) (globals: list ident) : Type[0] ≝ |
---|
453 | { joint_if_luniverse: universe LabelTag; (*CSC: used only for compilation*) |
---|
454 | joint_if_runiverse: universe RegisterTag; (*CSC: used only for compilation*) |
---|
455 | (* Paolo: if we want this machinery to work for RTLabs too, we will need the |
---|
456 | following, right? *) |
---|
457 | (* joint_if_sig: signature; -- dropped in front end *) |
---|
458 | joint_if_result : call_dest p; |
---|
459 | joint_if_params : paramsT p; |
---|
460 | joint_if_locals : list (localsT p); (* use void where no locals are present *) |
---|
461 | (*CSC: XXXXX stacksize unused for LTL-...*) |
---|
462 | joint_if_stacksize: nat; |
---|
463 | joint_if_code : codeT p globals ; |
---|
464 | joint_if_entry : point_in_code … joint_if_code ; |
---|
465 | joint_if_exit : point_in_code … joint_if_code |
---|
466 | }. |
---|
467 | |
---|
468 | definition joint_closed_internal_function ≝ |
---|
469 | λp,globals. |
---|
470 | Σdef : joint_internal_function globals p. code_closed … (joint_if_code … def). |
---|
471 | |
---|
472 | definition set_joint_code ≝ |
---|
473 | λglobals: list ident. |
---|
474 | λpars: params. |
---|
475 | λint_fun: joint_internal_function pars globals. |
---|
476 | λgraph: codeT pars globals. |
---|
477 | λentry. |
---|
478 | λexit. |
---|
479 | mk_joint_internal_function pars globals |
---|
480 | (joint_if_luniverse … int_fun) (joint_if_runiverse … int_fun) (joint_if_result … int_fun) |
---|
481 | (joint_if_params … int_fun) (joint_if_locals … int_fun) (joint_if_stacksize … int_fun) |
---|
482 | graph entry exit. |
---|
483 | |
---|
484 | definition set_joint_if_graph ≝ |
---|
485 | λglobals.λpars : graph_params. |
---|
486 | λgraph. |
---|
487 | λp:joint_internal_function pars globals. |
---|
488 | λentry_prf. |
---|
489 | λexit_prf. |
---|
490 | set_joint_code globals pars p |
---|
491 | graph |
---|
492 | (mk_Sig ?? (joint_if_entry ?? p) entry_prf) |
---|
493 | (mk_Sig … (joint_if_exit ?? p) exit_prf). |
---|
494 | |
---|
495 | definition set_luniverse ≝ |
---|
496 | λglobals,pars. |
---|
497 | λp : joint_internal_function globals pars. |
---|
498 | λluniverse: universe LabelTag. |
---|
499 | mk_joint_internal_function globals pars |
---|
500 | luniverse (joint_if_runiverse … p) (joint_if_result … p) |
---|
501 | (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p) |
---|
502 | (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p). |
---|
503 | |
---|
504 | definition set_runiverse ≝ |
---|
505 | λglobals,pars. |
---|
506 | λp : joint_internal_function globals pars. |
---|
507 | λruniverse: universe RegisterTag. |
---|
508 | mk_joint_internal_function globals pars |
---|
509 | (joint_if_luniverse … p) runiverse (joint_if_result … p) |
---|
510 | (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p) |
---|
511 | (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p). |
---|
512 | |
---|
513 | (* Specialized for graph_params *) |
---|
514 | definition add_graph ≝ |
---|
515 | λg_pars : graph_params.λglobals.λl:label.λstmt. |
---|
516 | λp:joint_internal_function g_pars globals. |
---|
517 | let code ≝ add … (joint_if_code … p) l stmt in |
---|
518 | mk_joint_internal_function … |
---|
519 | (joint_if_luniverse … p) (joint_if_runiverse … p) (joint_if_result … p) |
---|
520 | (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p) |
---|
521 | code |
---|
522 | (pi1 … (joint_if_entry … p)) |
---|
523 | (pi1 … (joint_if_exit … p)). |
---|
524 | >graph_code_has_point whd in match code; >mem_set_add |
---|
525 | @orb_Prop_r [elim (joint_if_entry ???) | elim (joint_if_exit ???) ] |
---|
526 | #x #H <graph_code_has_point @H |
---|
527 | qed. |
---|
528 | |
---|
529 | definition set_locals ≝ |
---|
530 | λpars,globals. |
---|
531 | λp : joint_internal_function pars globals. |
---|
532 | λlocals. |
---|
533 | mk_joint_internal_function pars globals |
---|
534 | (joint_if_luniverse … p) (joint_if_runiverse … p) (joint_if_result … p) |
---|
535 | (joint_if_params … p) locals (joint_if_stacksize … p) |
---|
536 | (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p). |
---|
537 | |
---|
538 | definition joint_function ≝ λp,globals. fundef (joint_internal_function p globals). |
---|
539 | |
---|
540 | definition joint_program ≝ |
---|
541 | λp:params. program (joint_function p) nat. |
---|