source: src/joint/semanticsUtils.ma @ 2952

Last change on this file since 2952 was 2952, checked in by tranquil, 7 years ago
  • corrected all back-end premains to not pass any arguments to the main
  • premain fetching is made by fetch_function in joint_semantics.ma
  • reorganised some definition between Traces.ma and joint_fullexec.ma
File size: 27.9 KB
Line 
1include "joint/joint_semantics.ma".
2include alias "common/Identifiers.ma".
3include "utilities/hide.ma".
4include "ASM/BitVectorTrie.ma".
5include "joint/TranslateUtils.ma".
6include "common/ExtraMonads.ma".
7include "common/extraGlobalenvs.ma".
8
9definition reg_store ≝ λreg,v,locals.add RegisterTag beval locals reg v.
10
11definition reg_retrieve : register_env beval → register → res beval ≝
12 λlocals,reg. opt_to_res … [MSG BadRegister; CTX ? reg] (lookup … locals reg).
13
14record hw_register_env : Type[0] ≝
15  { reg_env : BitVectorTrie beval 6
16  ; other_bit : bebit
17  }.
18
19include alias "ASM/BitVectorTrie.ma".
20
21definition hwreg_retrieve: hw_register_env → Register → beval ≝
22 λenv,r. lookup … (bitvector_of_register r) (reg_env env) BVundef.
23
24definition hwreg_store: Register → beval → hw_register_env → hw_register_env ≝
25 λr,v,env.mk_hw_register_env (insert … (bitvector_of_register r) v (reg_env env))
26  (other_bit env).
27
28definition hwreg_set_other : bebit → hw_register_env → hw_register_env ≝
29λv,env.mk_hw_register_env (reg_env env) v.
30
31definition hwreg_retrieve_sp : hw_register_env → res xpointer ≝
32λenv.
33let spl ≝ hwreg_retrieve env RegisterSPL in
34let sph ≝ hwreg_retrieve env RegisterSPH in
35! ptr ← pointer_of_address 〈spl, sph〉 ;
36match ptype ptr return λx.ptype ptr = x → res xpointer with
37[ XData ⇒ λprf.return «ptr, prf»
38| _ ⇒ λ_.Error … [MSG BadPointer]
39] (refl …).
40
41definition hwreg_store_sp : hw_register_env → xpointer → hw_register_env ≝
42λenv,sp.
43let 〈spl, sph〉 ≝ beval_pair_of_pointer sp in
44hwreg_store RegisterSPH sph (hwreg_store RegisterSPL spl env).
45
46definition init_hw_register_env: xpointer → hw_register_env ≝
47 hwreg_store_sp (mk_hw_register_env (Stub …) BBundef).
48
49(*** Store/retrieve on pseudo-registers ***)
50include alias "common/Identifiers.ma".
51
52unification hint 0 ≔ X ⊢ register_env X ≡ identifier_map RegisterTag X.
53
54(******************************** GRAPHS **************************************)
55
56record sem_graph_params : Type[1] ≝
57{ sgp_pars : uns_params
58; sgp_sup : ∀F.sem_unserialized_params sgp_pars F
59; graph_pre_main_generator :
60  ∀p : joint_program (mk_graph_params sgp_pars).
61  joint_closed_internal_function (mk_graph_params sgp_pars) (prog_var_names … p)
62}.
63
64
65definition sem_graph_params_to_graph_params :
66  ∀pars : sem_graph_params.graph_params ≝
67  λpars.mk_graph_params (sgp_pars pars).
68
69coercion graph_params_from_sem_graph_params nocomposites :
70  ∀pars : sem_graph_params.
71  graph_params ≝ sem_graph_params_to_graph_params
72  on _pars : sem_graph_params to graph_params.
73
74definition sem_graph_params_to_sem_params :
75  ∀pars : sem_graph_params.
76  sem_params ≝
77  λpars.
78  mk_sem_params
79    (mk_serialized_params
80      (pars : graph_params)
81      (sgp_sup pars ?)
82      (word_of_identifier ?)
83      (an_identifier ?)
84      ? (refl …))
85    (graph_pre_main_generator pars).
86* #p % qed.
87
88coercion sem_params_from_sem_graph_params :
89  ∀pars : sem_graph_params.
90  sem_params ≝ sem_graph_params_to_sem_params
91  on _pars : sem_graph_params to sem_params.
92
93
94(******************************** LINEAR **************************************)
95
96lemma succ_pos_of_nat_of_pos : ∀p.succ_pos_of_nat (nat_of_pos p) = succ p.
97@pos_elim [%]
98#p #IH >nat_possucc whd in ⊢ (??%?); >IH % qed.
99
100record sem_lin_params : Type[1] ≝
101{ slp_pars : uns_params
102; slp_sup : ∀F.sem_unserialized_params slp_pars F
103; lin_pre_main_generator :
104  ∀p : joint_program (mk_lin_params slp_pars).
105  joint_closed_internal_function (mk_lin_params slp_pars) (prog_var_names … p)
106}.
107
108definition sem_lin_params_to_lin_params :
109  ∀pars : sem_lin_params.lin_params ≝
110  λpars.mk_lin_params (slp_pars pars).
111
112coercion lin_params_from_sem_lin_params nocomposites :
113  ∀pars : sem_lin_params.
114  lin_params ≝ sem_lin_params_to_lin_params
115  on _pars : sem_lin_params to lin_params.
116
117definition sem_lin_params_to_sem_params :
118  ∀pars : sem_lin_params.
119  sem_params ≝
120  λpars.
121  mk_sem_params
122    (mk_serialized_params
123      (pars : lin_params)
124      (slp_sup pars ?)
125      succ_pos_of_nat
126      (λp.pred (nat_of_pos p))
127      ??)
128    (lin_pre_main_generator pars).
129[ @pos_cases [%] #p >nat_possucc @succ_pos_of_nat_of_pos
130| #n >nat_succ_pos %
131] qed.
132
133coercion sem_params_from_sem_lin_params :
134  ∀pars : sem_lin_params.
135  sem_params ≝ sem_lin_params_to_sem_params
136  on _pars : sem_lin_params to sem_params.
137
138(* TODO move elsewhere *)
139lemma lookup_opt_pm_set_elim : ∀A.∀P : option A → Prop.∀p,q,o,m.
140  (p = q → P o) →
141  (p ≠ q → P (lookup_opt A p m)) →
142  P (lookup_opt A p (pm_set A q o m)).
143#A #P #p #q
144@(eqb_elim p q) #H #o #m #H1 #H2
145[ >H >lookup_opt_pm_set_hit @H1 @H
146| >lookup_opt_pm_set_miss [ @H2 ] @H
147]
148qed.
149
150lemma lookup_add_elim : ∀tag,A.∀P : option A → Prop.∀m,i,j,x.
151  (i = j → P (Some ? x)) →
152  (i ≠ j → P (lookup tag A m j)) →
153  P (lookup tag A (add tag A m i x) j).
154#tag #A #P * #m * #p * #q #x
155#H1 #H2 whd in ⊢ (?%); normalize nodelta whd in match insert; normalize nodelta
156@lookup_opt_pm_set_elim #H destruct
157[ @H1 % | @H2 % #EQ destruct cases H #H @H % ]
158qed.
159
160lemma fetch_statement_eq : ∀p:sem_params.∀g.
161  ∀ge : genv p g.∀ptr : program_counter.
162  ∀i,fn,s.
163  fetch_internal_function … ge (pc_block ptr) = OK … 〈i, fn〉 →
164  let pt ≝ point_of_pc … ptr in
165  stmt_at … (joint_if_code … fn) pt = Some ? s →
166  fetch_statement … ge ptr = OK … 〈i, fn, s〉.
167#p #g #ge #ptr #i #f #s #EQ1 #EQ2
168whd in match fetch_statement; normalize nodelta >EQ1 >m_return_bind
169>EQ2 %
170qed.
171
172lemma fetch_statement_inv : ∀p:sem_params.∀g.
173  ∀ge : genv p g.∀ptr : program_counter.
174  ∀i,fn,s.
175  fetch_statement … ge ptr = OK … 〈i, fn, s〉 →
176  fetch_internal_function … ge (pc_block ptr) = OK … 〈i, fn〉 ∧
177  let pt ≝ point_of_pc p ptr in
178  stmt_at … (joint_if_code … fn) pt = Some ? s.
179#p #g #ge #ptr #i #fn #s #H
180elim (bind_inversion ????? H) * #i #f' * #EQ1 -H #H
181elim (bind_inversion ????? H) #s' * -H #H
182lapply (opt_eq_from_res ???? H) -H #EQ2
183whd in ⊢ (??%%→?); #EQ destruct(EQ) %{EQ1 EQ2}
184qed.
185
186definition pm_P : ∀A,B.∀P : A → B → Prop.positive_map A → positive_map B → Prop ≝
187λA,B,P,mA,mB.
188∀p.
189match lookup_opt … p mA with
190[ Some a ⇒
191  match lookup_opt … p mB with
192  [ Some b ⇒ P a b
193  | _ ⇒ False
194  ]
195| _ ⇒ match lookup_opt … p mB with
196  [ Some _ ⇒ False
197  | _ ⇒ True
198  ]
199].
200
201definition match_funct_map :
202  ∀M : matching.
203  ∀vars.positive_map (m_A M vars) → positive_map (m_B M vars) → Prop ≝
204  λM,vars.pm_P … (match_fundef M ?).
205
206lemma pm_P_insert :
207  ∀A,B,P.
208  ∀p,a1,a2,m1,m2.P a1 a2 → pm_P A B P m1 m2 →
209  pm_P … P (insert … p a1 m1) (insert … p a2 m2).
210#A #B #P #p #a1 #a2 #m1 #m2 #Pa1a2 #Pm1m2
211#p'
212@(eqb_elim p' p) #H destruct
213[ >lookup_opt_insert_hit >lookup_opt_insert_hit @Pa1a2
214| >(lookup_opt_insert_miss … a1 … H) >(lookup_opt_insert_miss … a2 … H)
215  @Pm1m2
216]
217qed.
218
219lemma pm_P_set_None :
220  ∀A,B,P.
221  ∀p,m1,m2.pm_P A B P m1 m2 →
222  pm_P … P (pm_set … p (None ?) m1) (pm_set … p (None ?) m2).
223#A #B #P #p #m1 #m2 #Pm1m2
224#p'
225@(eqb_elim p' p) #H destruct
226[ >lookup_opt_pm_set_hit >lookup_opt_pm_set_hit %
227| >(lookup_opt_pm_set_miss … H) >(lookup_opt_pm_set_miss … H)
228  @Pm1m2
229]
230qed.
231
232record match_genv_t (M : matching)
233  (vars : list ident)
234  (ge1 : genv_t (m_A M vars)) (ge2 : genv_t (m_B M vars)) : Prop ≝
235{ symbols_eq : symbols … ge1 = symbols … ge2
236; nextfunction_eq : nextfunction … ge1 = nextfunction … ge2
237; functions_match : pm_P … (match_fundef M ?) (functions … ge1) (functions … ge2)
238}.
239
240lemma add_globals_match :
241  ∀M : matching.∀initV,initW.
242  ∀vars1,vars2.
243  ∀vars.
244(*  let vars1' ≝ map … (λx.\fst (\fst x)) vars1 in
245  let vars2' ≝ map … (λx.\fst (\fst x)) vars2 in *)
246  ∀env_mem1 : genv_t (m_A M vars) × mem.
247  ∀env_mem2 : genv_t (m_B M vars) × mem.
248  All2 (ident×region×(m_V M)) (ident×region×(m_W M))
249      (match_var_entry M) vars1 vars2 →
250  nextblock … (\snd env_mem1) = nextblock … (\snd env_mem2) →
251  match_genv_t M vars
252    (\fst env_mem1) (\fst env_mem2) →
253  match_genv_t M vars
254    (\fst (add_globals … initV env_mem1 vars1))
255    (\fst (add_globals … initW env_mem2 vars2)).
256#M #init1 #init2 #vars1
257elim vars1 -vars1 [2: ** #id1 #r1 #v1 #tl1 #IH ]
258* [2,4: ** #id2 #r2 #v2 #tl2 ]
259#vars * #env1 #mem1 * #env2 #mem2 *
260[2: #_ #H @H ]
261#H inversion H #id' #r' #v1' #v2' #P #EQ1 #EQ2 #_ destruct -H #H
262#EQnxtbl #G @(IH tl2 … H)
263cases mem1 in EQnxtbl; -mem1 #mem1 #nbl1 #prf1
264cases mem2 -mem2 #mem2 #nbl2 #prf2 #EQ destruct
265[ % ]
266normalize nodelta %
267whd in match add_symbol;
268whd in match drop_fn; normalize nodelta
269[ >(symbols_eq … G) %
270| @(nextfunction_eq … G)
271| >(symbols_eq … G) cases (lookup ? block ??) normalize nodelta
272  [2: ** [2,3: #p] normalize nodelta ]
273  try @pm_P_set_None
274  @(functions_match … G)
275]
276qed.
277
278lemma add_functs_match :
279  ∀M : matching.
280  ∀vars.
281  ∀functs1,functs2.
282(*  let vars1' ≝ map … (λx.\fst (\fst x)) vars1 in
283  let vars2' ≝ map … (λx.\fst (\fst x)) vars2 in *)
284  ∀env1 : genv_t (m_A M vars).
285  ∀env2 : genv_t (m_B M vars).
286  All2 …
287    (match_funct_entry M vars vars) functs1 functs2 →
288  match_genv_t M vars env1 env2 →
289  match_genv_t M vars
290    (add_functs … env1 functs1)
291    (add_functs … env2 functs2).
292#M #vars #functs1 elim functs1 -functs1 [2: * #id1 #f1 #tl1 #IH ]
293* [2,4: * #id2 #f2 #tl2 ]
294#env1 #env2 *
295[2: #H @H ]
296#H
297cut (id1 = id2 ∧ match_fundef M … f1 f2)
298[ @(match_funct_entry_inv M ??????? H) #v #i #f1 #f2 #H %{H} % ]
299* #EQ destruct #Pf1f2 #Ptl1tl2 #G
300lapply (IH … Ptl1tl2 G) -G #G
301%
302whd in
303  match (add_functs ?? (? :: tl1));
304whd in
305  match (add_functs ?? (? :: tl2));
306change with (add_functs ?? tl1) in match (foldr ???? tl1);
307change with (add_functs ?? tl2) in match (foldr ???? tl2);
308whd in match drop_fn; normalize nodelta
309[ >(nextfunction_eq … G)  >(symbols_eq … G) %
310| >(nextfunction_eq … G) %
311| >(symbols_eq … G) cases (lookup ? block ??) normalize nodelta
312  [2: ** [2,3: #p] normalize nodelta ]
313  >(nextfunction_eq … G)
314  @(pm_P_insert … Pf1f2)
315  try @pm_P_set_None @(functions_match … G)
316]
317qed.
318
319lemma globalenv_match:
320    ∀M:matching.∀initV,initW.
321     (∀v,w. match_var_entry M v w →
322      size_init_data_list (initV (\snd v)) = size_init_data_list (initW (\snd w))) →
323    ∀p: program (m_A M) (m_V M). ∀p': program (m_B M) (m_W M).
324    ∀MATCH:match_program … M p p'.
325    match_genv_t M ? (globalenv … initV p)
326      (globalenv … initW p' ⌈prog_var_names … p' ↦ prog_var_names … p⌉).
327[2: @sym_eq @(matching_vars … (mp_vars … MATCH)) ]
328* #A #B #V #W #Pf #Pv #iV #iW #init_eq
329* #vars1 #functs1 #main1
330* #vars2 #functs2 #main2
331*
332whd in match prog_var_names;
333normalize nodelta;
334#Mvars #Mfns #EQmain destruct
335lapply (sym_eq ????)
336#E
337lapply Mfns lapply functs2 -functs2
338whd in match globalenv; whd in match globalenv_allocmem;
339whd in match prog_var_names in E ⊢ %;
340normalize nodelta in E ⊢ %;
341>E normalize nodelta #functs2 #Mfns
342@add_globals_match [ assumption | % ]
343@add_functs_match [ assumption ]
344% try % #p %
345qed.
346
347lemma symbols_transf:
348 ∀A,B,V,init.∀prog_in : program A V.
349 ∀trans : ∀vars.A vars → B vars.
350 let prog_out ≝ transform_program … prog_in trans in
351 symbols … (globalenv … init prog_out) = symbols … (globalenv … init prog_in).
352#A #B #V #iV #p #tf whd
353lapply (transform_program_match … tf p)
354#MATCH
355>(symbols_eq … (globalenv_match … MATCH))
356[2: @iV |3: #v #w * // ]
357lapply (sym_eq ????)
358whd in match (prog_var_names ???); whd in match (prog_vars B ??);
359#E >(K ?? E) normalize nodelta %
360qed.
361
362lemma functions_transf:
363 ∀A,B,V,init.∀prog_in : program A V.
364 ∀trans : ∀vars.A vars → B vars.
365 let prog_out ≝ transform_program … prog_in trans in
366 ∀p.lookup_opt … p (functions … (globalenv … init prog_out)) =
367 option_map ?? (trans ?) (lookup_opt … p (functions … (globalenv … init prog_in))).
368#A #B #V #iV #p #tf #n
369lapply (transform_program_match … tf p)
370#MATCH
371whd in match globalenv; whd in match globalenv_allocmem;
372normalize nodelta
373lapply (functions_match … (globalenv_match … MATCH) n)
374[ @iV | @iV | #v #w * // ]
375lapply (sym_eq ????)
376whd in match (prog_var_names ???); whd in match (prog_vars B ??);
377#E >(K ?? E) normalize nodelta
378cases (lookup_opt ???) [2: #x ] normalize nodelta
379cases (lookup_opt ???) [2,4: #y ] normalize nodelta
380[ #EQ <EQ % |*: * % ]
381qed.
382
383lemma symbol_for_block_transf :
384 ∀A,B,V,init.∀prog_in : program A V.
385 ∀trans : ∀vars.A vars → B vars.
386 let prog_out ≝ transform_program … prog_in trans in
387 ∀bl.
388 symbol_for_block … (globalenv … init prog_out) bl =
389 symbol_for_block … (globalenv … init prog_in) bl.
390#A #B #V #iV #p #tf whd
391#bl
392whd in match symbol_for_block; normalize nodelta
393>(symbols_transf … tf) %
394qed.
395
396include alias "common/Pointers.ma".
397
398(* TODO move *)
399lemma Exists_mp : ∀A,P,Q,l.(∀x.P x → Q x) → Exists A P l → Exists A Q l.
400#A #P #Q #l #H elim l -l [2: #hd #tl #IH] * #G whd /3 by or_introl, or_intror/ qed.
401
402definition joint_globalenv :
403  ∀p : sem_params.∀pr:joint_program p.
404    (ident → option ℕ) → genv p (prog_var_names … pr) ≝
405λp,prog,stacksizes.
406let genv ≝ globalenv … (λx.x) prog in
407mk_genv_gen ?? genv ? stacksizes (pre_main_generator … p prog).
408#s #H
409elim (find_symbol_exists ?? (λx.x) … prog s ?)
410[ #bl #EQ >EQ % #ABS destruct ]
411@Exists_append_r
412@(Exists_mp … H) //
413qed.
414
415lemma opt_to_res_bind : ∀X,Y,m,f,e.opt_to_res Y e (! x ← m ; f x) =
416  ! x ← opt_to_res X e m ; opt_to_res Y e (f x).
417#X #Y * [2: #x] #f #e % qed.
418
419lemma fetch_function_transf:
420 ∀src,dst : sem_params.∀prog_in : joint_program src.
421 ∀stacksizes.
422 ∀trans : ∀vars.joint_function src vars → joint_function dst vars.
423 let prog_out ≝
424  mk_joint_program dst
425    (transform_program … prog_in trans) (init_cost_label … prog_in) in
426 ∀bl.
427 fetch_function … (joint_globalenv … prog_out stacksizes) bl =
428 if eqZb (block_id bl) (-1) then
429   return 〈pre_main_id, Internal ? (pre_main_generator … dst prog_out)〉
430 else
431   ! 〈id, f〉 ← fetch_function … (joint_globalenv … prog_in stacksizes) bl ;
432   return 〈id, trans … f〉.
433#src #dst #p #sizes #tf whd
434lapply (transform_program_match … tf p)
435#MATCH
436whd in match fetch_function;
437whd in match joint_globalenv; normalize nodelta
438#bl @eqZb_elim #Hbl normalize nodelta [ % ]
439>symbol_for_block_transf
440>opt_to_res_bind >opt_to_res_bind in ⊢ (???%); >m_bind_bind
441@m_bind_ext_eq #id
442whd in match find_funct_ptr; normalize nodelta
443cases bl -bl ** [2,3: #p] normalize nodelta #_ try %
444lapply (functions_match … (globalenv_match … MATCH) p) try @(λx.x)
445[#v #w * //]
446lapply (sym_eq ????)
447whd in match prog_var_names; normalize nodelta
448#E >(K ?? E) -E normalize nodelta
449cases (lookup_opt ???) [2: #x ] normalize nodelta
450cases (lookup_opt ???) [2,4: #y ] normalize nodelta
451* %
452qed.
453
454lemma fetch_internal_function_transf :
455 ∀src,dst : sem_params.∀prog_in : joint_program src.
456 ∀stacksizes.
457 ∀trans : ∀vars.joint_closed_internal_function src vars → joint_closed_internal_function dst vars.
458 let prog_out ≝
459  mk_joint_program dst
460    (transform_program … prog_in (λvars.transf_fundef … (trans vars))) (init_cost_label … prog_in) in
461 ∀bl.
462 fetch_internal_function … (joint_globalenv … prog_out stacksizes) bl =
463 if eqZb (block_id bl) (-1) then
464   return 〈pre_main_id, pre_main_generator … dst prog_out〉
465 else
466   ! 〈i, f〉 ← fetch_internal_function … (joint_globalenv … prog_in stacksizes) bl ;
467   return 〈i, trans … f〉.
468#src #dst #p #sizes #tf whd
469#bl whd in match fetch_internal_function; normalize nodelta
470>(fetch_function_transf … p)
471@eqZb_elim #Hbl [%] normalize nodelta >m_bind_bind >m_bind_bind
472@m_bind_ext_eq * #id * #f %
473qed.
474
475include alias "utilities/binary/positive.ma".
476
477lemma pm_map_add_ind : ∀A.∀P : positive_map A → Prop.
478(∀m.(∀p.lookup_opt A p m = None ?) → P m) →
479(∀m,p,v.P m → lookup_opt A p m = None ? → P (insert A p v m)) →
480∀m.P m.
481#A #P #H1 #H2 #m lapply H2 lapply H1 lapply P -P elim m -m
482[ #P #H1 #_ @H1 #p % ]
483#o #l #r #IHl #IHr #P #H1 #H2
484@IHl #l'
485[ #empty_l' @IHr #r'
486  [ #empty_r' cases o [ @H1 * try #p normalize // ]
487    #v change with (P (insert ? one v (pm_node ? (None ?) ??)))
488    @H2 [ @H1 * try #p normalize // | % ]
489  ]
490]
491#p #v #H #G
492[ change with (P (insert ? (p1 p) v (pm_node ? ???)))
493| change with (P (insert ? (p0 p) v (pm_node ? ???)))
494] @H2 assumption
495qed.
496
497include alias "basics/logic.ma".
498include alias "common/PositiveMap.ma".
499
500lemma swap_neg : ∀A,B : Prop.(A → B) → ¬B → ¬A.
501#A #B #impl * #Bf % #At @Bf @impl @At qed-.
502
503definition b_graph_transform_program_props ≝
504  λsrc,dst : sem_graph_params.
505  λstacksizes.
506  λdata,prog_in.
507  λinit_regs : block → list register.
508  λf_lbls : block → label → list label.
509  λf_regs : block → label → list register.
510   let prog_out ≝ b_graph_transform_program src dst data prog_in in
511   let src_genv ≝ joint_globalenv src prog_in stacksizes in
512   let dst_genv ≝ joint_globalenv dst prog_out stacksizes in
513  ∀bl,def_in.
514  block_id … bl ≠ -1 →
515  find_funct_ptr … src_genv bl = return (Internal ? def_in) →
516  ∃init_data,def_out.
517  find_funct_ptr … dst_genv bl = return (Internal ? def_out) ∧
518  bind_new_instantiates … init_data (data … def_in) (init_regs bl) ∧
519  b_graph_translate_props src dst ? init_data
520    def_in def_out (f_lbls bl) (f_regs bl).
521
522lemma make_b_graph_transform_program_props :
523 ∀src,dst:sem_graph_params.
524 ∀stacksizes.
525 ∀data : ∀globals.joint_closed_internal_function src globals →
526  bound_b_graph_translate_data src dst globals.
527 ∀prog_in : joint_program src.
528 let prog_out ≝ b_graph_transform_program … data prog_in in
529 let src_genv ≝ joint_globalenv src prog_in stacksizes in
530 let dst_genv ≝ joint_globalenv dst prog_out stacksizes in
531 ∃init_regs : block → list register.
532 ∃f_lbls : block → label → list label.
533 ∃f_regs : block → label → list register.
534 b_graph_transform_program_props src dst stacksizes data prog_in init_regs f_lbls f_regs.
535cases daemon (* TOREDO
536#src #dst #data #prog_in
537whd in match b_graph_transform_program_props; normalize nodelta
538whd in match joint_globalenv; normalize nodelta
539letin prog_out ≝ (b_graph_transform_program … data prog_in)
540letin src_genv ≝ (globalenv … (λx.x) prog_in)
541letin dst_genv ≝ (globalenv … (λx.x) prog_out)
542cut (∀p.lookup_opt ? p (functions ? dst_genv) =
543     option_map ?? (transf_fundef … (λf.b_graph_translate … (data … f) f))
544      (lookup_opt ? p (functions ? src_genv)))
545[ @functions_transf ]
546cut (symbols ? dst_genv = symbols ? src_genv)
547[ @symbols_transf ]
548cases dst_genv #functs2 #nextf2 #symbols2 #H2
549cases src_genv #functs1 #nextf1 #symbols1 #H1 #EQ destruct
550lapply H2 lapply H1 lapply functs2
551@(pm_map_add_ind … functs1) -functs1 -functs2 #functs1
552[ #functs1_empty | #p #f #IH #p_not_in ]
553#functs2 #H1 #H2 #transf
554[ %{(λ_.[ ])} %{(λ_.λ_.[])} %{(λ_.λ_.[])}
555  #bl #def_in #ABS1 #ABS2 @⊥ lapply ABS2 -ABS2 lapply ABS1 -ABS1
556  whd in match find_funct_ptr;
557  whd in match find_symbol;
558  normalize nodelta
559  cases bl; * normalize nodelta
560  [2,3: #p ]
561  [1,3: #_ whd in ⊢ (???%→?); #EQ destruct ]
562  >lookup_add_hit
563  #H >lookup_opt_insert_miss
564  [2: @(swap_neg … H) #EQ >EQ % ]
565  whd in match drop_fn; normalize nodelta
566  cases (lookup … symbols1 pre_main_id)
567  normalize nodelta
568  [ >functs1_empty | ** [2,3: #p' ] normalize nodelta
569    [1,3: >functs1_empty
570    | @lookup_opt_pm_set_elim #H destruct
571      [2: >functs1_empty ]
572    ]
573  ] whd in ⊢ (???%→?); #EQ destruct
574]
575cases (IH (pm_set … p (None ?) functs2) ???)
576[|*: @hide_prf
577  [ #b #G @(H1 b ?) @(swap_neg … G) -G
578    whd in match insert; normalize nodelta
579    @lookup_opt_pm_set_elim
580    [ #EQ #ABS destruct ]
581    #NEQ #H @H
582  | #b #G @(H2 b ?) @(swap_neg … G) -G
583    @lookup_opt_pm_set_elim
584    [ #_ #_ % ]
585    #_ #H @H
586  | #b @lookup_opt_pm_set_elim
587    [ #EQ destruct >p_not_in % ]
588    #NEQ >transf
589    >(lookup_opt_insert_miss ? f b p … NEQ) %
590  ]
591]
592#init_regs * #f_lbls * #f_regs #props
593-IH cases f in H1 transf; -f #f #H1 #transf
594[ (* internal *)
595  letin upd ≝ (λA : Type[0].λf : block → A.
596    λid.λv,id'.
597    if eq_block id id' then v else f id')
598  cases (pi2 ?? (b_graph_translate … (data … f) f))
599  #loc_data * #loc_init_regs * #loc_f_lbls * #loc_f_regs *
600  #inst_loc_data #loc_props
601  letin bl ≝ (mk_block (neg p))
602  %{(upd … init_regs bl loc_init_regs)}
603  %{(upd … f_lbls bl loc_f_lbls)}
604  %{(upd … f_regs bl loc_f_regs)}
605| (* external, nothing changes *)
606  %{init_regs}
607  %{f_lbls}
608  %{f_regs}
609]
610* #p' #def_in
611whd in match find_funct_ptr; normalize nodelta
612whd in match (block_region (mk_block p'));
613cases p' -p' [2,3,5,6: #p' ] normalize nodelta
614[1,3,5,6: #_ #ABS normalize in ABS; destruct]
615whd in match find_symbol;
616whd in match insert; normalize nodelta
617#bl_prf
618@lookup_opt_pm_set_elim #pp' destruct
619[1,3: whd in ⊢ (??%%→?); #EQ destruct(EQ)
620  [ %{loc_data} %
621    [2: % [ % ]
622      [ >lookup_opt_insert_hit %
623      |*: >eq_block_b_b assumption
624      ]
625    |]
626|*: >(lookup_opt_insert_miss ???? functs1 … pp')
627  [ @eq_block_elim [ #EQ destruct cases (absurd ?? pp') % ] #_ normalize nodelta]
628  #EQ lapply (props (mk_block (neg p')) def_in EQ)
629  whd in match find_funct_ptr; normalize nodelta
630  >(lookup_opt_pm_set_miss … functs2 … pp') #H @H
631] *)
632qed.
633
634lemma if_elim' : ∀A : Type[0].∀P : A → Prop.∀b : bool.∀c1,c2 : A.
635  (b → P c1) → (¬(bool_to_Prop b) → P c2) → P (if b then c1 else c2).
636#A #P * /3 by Prop_notb/ qed.
637
638lemma b_graph_transform_program_fetch_internal_function :
639 ∀src,dst:sem_graph_params.
640 ∀stacksizes.
641 ∀data : ∀globals.joint_closed_internal_function src globals →
642  bound_b_graph_translate_data src dst globals.
643 ∀prog_in : joint_program src.
644 ∀init_regs : block → list register.
645 ∀f_lbls : block → label → list label.
646 ∀f_regs : block → label → list register.
647 b_graph_transform_program_props … stacksizes data prog_in init_regs f_lbls f_regs →
648 let prog_out ≝ b_graph_transform_program … data prog_in in
649 let src_genv ≝ joint_globalenv src prog_in stacksizes in
650 let dst_genv ≝ joint_globalenv dst prog_out stacksizes in
651 ∀bl : Σbl.block_region … bl = Code.∀id,def_in.
652 block_id … bl ≠ -1 →
653 fetch_internal_function … src_genv bl = return 〈id, def_in〉 →
654 ∃init_data,def_out.
655 fetch_internal_function … dst_genv bl = return 〈id, def_out〉 ∧
656 bind_new_instantiates … init_data (data … def_in) (init_regs bl) ∧
657 b_graph_translate_props src dst ? init_data
658    def_in def_out (f_lbls bl) (f_regs bl).
659#src #dst #stacksizes #data #prog_in
660#init_regs #f_lbls #f_regs #props
661#bl #id #def_in #NEQ
662#H @('bind_inversion H) * #id' * #def_in' -H
663normalize nodelta [2: #_ whd in ⊢ (??%%→?); #ABS destruct ]
664whd in match fetch_function; normalize nodelta
665>(eqZb_false … NEQ) normalize nodelta
666#H @('bind_inversion (opt_eq_from_res … H)) -H #id'' #EQ1
667#H @('bind_inversion H) -H #def_in'' #H
668whd in ⊢ (??%%→??%%→?); #EQ2 #EQ3 destruct
669cases (props … NEQ H)
670#loc_data * #def_out ** #H1 #H2 #H3
671%{loc_data} %{def_out}
672%{H3} %{H2}
673whd in match fetch_internal_function;
674whd in match fetch_function; normalize nodelta
675>(eqZb_false … NEQ) normalize nodelta
676>symbol_for_block_transf >EQ1 >m_return_bind
677>H1 %
678qed.
679
680lemma b_graph_transform_program_fetch_statement :
681 ∀src,dst:sem_graph_params.∀stacksizes.
682 ∀data : ∀globals.joint_closed_internal_function src globals →
683  bound_b_graph_translate_data src dst globals.
684 ∀prog_in : joint_program src.
685 ∀init_regs : block → list register.
686 ∀f_lbls : block → label → list label.
687 ∀f_regs : block → label → list register.
688 b_graph_transform_program_props … stacksizes data prog_in init_regs f_lbls f_regs →
689 let prog_out ≝ b_graph_transform_program … data prog_in in
690 let src_genv ≝ joint_globalenv src prog_in stacksizes in
691 let dst_genv ≝ joint_globalenv dst prog_out stacksizes in
692 ∀pc,id,def_in,s.
693 block_id … (pc_block … pc) ≠ -1 →
694 fetch_statement … src_genv pc = return 〈id, def_in, s〉 →
695 ∃init_data,def_out.
696 let bl ≝ pc_block pc in
697 fetch_internal_function … dst_genv bl = return 〈id, def_out〉 ∧
698 bind_new_instantiates … init_data (data … def_in) (init_regs bl) ∧
699 let l ≝ point_of_pc dst pc in
700 ∃lbls,regs.
701 f_lbls bl l = lbls ∧
702 f_regs bl l = regs ∧
703  match s with
704  [ sequential s' nxt ⇒
705    let block ≝
706      if eq_identifier … (joint_if_entry … def_in) l then
707        append_seq_list … (f_step … init_data l s') (added_prologue … init_data)
708      else
709        f_step … init_data l s' in
710    l ~❨block, l::lbls, regs❩~> nxt in joint_if_code … def_out
711  | final s' ⇒
712    l ~❨f_fin … init_data l s', l::lbls, regs❩~> it in joint_if_code … def_out
713  | FCOND abs _ _ _ ⇒ Ⓧabs
714  ].
715#src #dst #stacksizes #data #prog_in
716#init_regs #f_lbls #f_regs #props
717#pc #id #def_in #s #NEQ
718#H @('bind_inversion H) * #id' #def_in' -H
719#EQfif
720#H @('bind_inversion H) -H #s
721#H lapply (opt_eq_from_res ???? H) -H
722#EQstmt_at whd in ⊢ (??%%→?); #EQ destruct
723cases (b_graph_transform_program_fetch_internal_function … props … NEQ EQfif)
724#a * #b ** #H1 #H2 #H3 %{a} %{b} %
725[ %{H1 H2}
726| % [2: % [2: % [% %]] | skip] @(multi_fetch_ok … H3 … EQstmt_at) ]
727qed.
728
729lemma b_graph_transform_program_fetch_statement_plus :
730 ∀src,dst:sem_graph_params.∀stacksizes.
731 ∀data : ∀globals.joint_closed_internal_function src globals →
732  bound_b_graph_translate_data src dst globals.
733 ∀prog_in : joint_program src.
734 ∀init_regs : block → list register.
735 ∀f_lbls : block → label → list label.
736 ∀f_regs : block → label → list register.
737 b_graph_transform_program_props … stacksizes data prog_in init_regs f_lbls f_regs →
738 let prog_out ≝ b_graph_transform_program … data prog_in in
739 let src_genv ≝ joint_globalenv src prog_in stacksizes in
740 let dst_genv ≝ joint_globalenv dst prog_out stacksizes in
741 ∀pc,id,def_in,s.
742 block_id … (pc_block … pc) ≠ -1 →
743 fetch_statement … src_genv pc = return 〈id, def_in, s〉 →
744 ∃init_data,def_out.
745 let bl ≝ pc_block pc in
746 fetch_internal_function … dst_genv bl = return 〈id, def_out〉 ∧
747 bind_new_instantiates … init_data (data … def_in) (init_regs bl) ∧
748 let l ≝ point_of_pc dst pc in
749 ∃lbls,regs.
750 f_lbls bl l = lbls ∧
751 f_regs bl l = regs ∧
752 joint_if_entry … def_out = joint_if_entry … def_in ∧
753 partial_partition … (f_lbls bl) ∧
754 partial_partition … (f_regs bl) ∧
755 (∀l.All …
756    (λlbl.¬fresh_for_univ … lbl (joint_if_luniverse … def_in) ∧
757           fresh_for_univ … lbl (joint_if_luniverse … def_out)) (f_lbls bl l)) ∧
758  (∀l.All …
759    (λreg.¬fresh_for_univ … reg (joint_if_runiverse … def_in) ∧
760           fresh_for_univ … reg (joint_if_runiverse … def_out)) (f_regs bl l)) ∧
761  match s with
762  [ sequential s' nxt ⇒
763    let block ≝
764      if eq_identifier … (joint_if_entry … def_in) l then
765        append_seq_list … (f_step … init_data l s') (added_prologue … init_data)
766      else
767        f_step … init_data l s' in
768    l ~❨block, l::lbls, regs❩~> nxt in joint_if_code … def_out
769  | final s' ⇒
770    l ~❨f_fin … init_data l s', l::lbls, regs❩~> it in joint_if_code … def_out
771  | FCOND abs _ _ _ ⇒ Ⓧabs
772  ].
773#src #dst #stacksizes #data #prog_in
774#init_regs #f_lbls #f_regs #props
775#pc #id #def_in #s #NEQ
776#H @('bind_inversion H) * #id' #def_in' -H
777#EQfif
778#H @('bind_inversion H) -H #s
779#H lapply (opt_eq_from_res ???? H) -H
780#EQstmt_at whd in ⊢ (??%%→?); #EQ destruct
781cases (b_graph_transform_program_fetch_internal_function … props … NEQ EQfif)
782#a * #b ** #H1 #H2 #H3 %{a} %{b} %
783[ %{H1 H2}
784| %
785   [2:
786      %
787        [2: %
788            [%
789               [%
790                  [%
791                     [%
792                        [%
793                           [%
794                              %
795                            | @(entry_eq … H3)
796                            ]
797                        | @(partition_lbls … H3)
798                        ]
799                     |  @(partition_regs … H3)
800                     ]
801                  | @(freshness_lbls … H3)
802                  ]
803               |  @(freshness_regs … H3)
804               ]
805            |  @(multi_fetch_ok … H3 … EQstmt_at)
806            ]
807        |
808        ]
809   |
810   ]
811]         
812qed.
Note: See TracBrowser for help on using the repository browser.