source: src/ERTL/ERTLtoERTLptrOK.ma @ 2891

Last change on this file since 2891 was 2891, checked in by piccolo, 8 years ago

added precondition on seq statement and tested correct in the ERTl-ERTLptr passed

File size: 66.5 KB
Line 
1
2(**************************************************************************)
3(*       ___                                                              *)
4(*      ||M||                                                             *)
5(*      ||A||       A project by Andrea Asperti                           *)
6(*      ||T||                                                             *)
7(*      ||I||       Developers:                                           *)
8(*      ||T||         The HELM team.                                      *)
9(*      ||A||         http://helm.cs.unibo.it                             *)
10(*      \   /                                                             *)
11(*       \ /        This file is distributed under the terms of the       *)
12(*        v         GNU General Public License Version 2                  *)
13(*                                                                        *)
14(**************************************************************************)
15
16include "ERTL/ERTLtoERTLptrUtils.ma".
17
18
19
20(*
21lemma get_internal_function_from_ident_ok :
22∀p : sem_params. ∀globals : list ident. ∀ge : genv_t (joint_function p globals).
23∀bl,f,fn. fetch_internal_function ? ge bl = return 〈f,fn〉 →
24get_internal_function_from_ident p globals ge f= return fn.
25#p #globals #ge #bl #f #fn #EQf
26@('bind_inversion EQf) * #f1 * #fn1 whd in match fetch_function;
27normalize nodelta #H lapply(opt_eq_from_res ???? H) -H #H @('bind_inversion H) -H
28#f2 #EQf2 #H @('bind_inversion H) -H #fn2 #EQfn2 whd in ⊢ (??%% → ??%% → ?);
29#EQ1 #EQ2 destruct whd in match get_internal_function_from_ident; normalize nodelta
30>(symbol_of_block_rev … EQf2) >m_return_bind
31cut(code_block_of_block bl = return bl)
32 [ whd in match code_block_of_block; normalize nodelta @match_reg_elim
33   [ >(pi2 ?? bl) #ABS destruct] elim bl #bl1 #EQ #prf % ] #EQbl >EQbl
34>m_return_bind >EQf %
35qed.
36*)
37
38
39
40 
41(*
42  whd in match sigma_frames_opt; whd in match m_list_map; normalize nodelta
43whd in match sigma_state in ⊢ (???????%%); normalize nodelta
44cases(st_frms … st) normalize nodelta [ @res_preserve_error1]
45* #loc_mem #bl #tl inversion(sigma_frames ????)
46[ #_ normalize nodelta @res_preserve_error1] * #loc_mem1 #bl1 #tl1
47whd in match sigma_frames; normalize nodelta inversion(sigma_frames_opt ????)
48[ #_ normalize nodelta #_ #ABS destruct] #l whd in match sigma_frames_opt;
49whd in match m_list_map; normalize nodelta whd in match (foldr ?????);
50normalize nodelta inversion(fetch_internal_function ???)
51[2: #e #_ whd in ⊢ (??%% → ?); #ABS destruct] * #id1 #fn1 #EQfn1 >m_return_bind
52normalize nodelta #H @('bind_inversion H) -H #l1
53change with (sigma_frames_opt ???? = ? → ?) #EQl1
54cut (sigma_frames prog f_lbls f_regs tl = l1)
55[whd in match sigma_frames; normalize nodelta >EQl1 %] #EQl11
56cases l [ whd in ⊢ (??%? → ?); #EQ destruct] #x #y
57whd in ⊢ (??%? → ?); #EQ1 #_ #EQ2 destruct @mfr_bind1
58[2: whd in match set_regs; whd in match set_frms; normalize nodelta
59    >EQl1 in ⊢ (???????%?); normalize nodelta
60cut(sigma_regs prog f_lbls (added_registers ERTL (prog_var_names … prog) fn1 (f_regs bl1))
61    〈loc_mem,\snd (regs … st)〉 =  〈map RegisterTag beval beval loc_mem
62       (λbv:beval.sigma_beval prog f_lbls bv)∖
63         added_registers ERTL (prog_var_names … prog) fn1 (f_regs bl1),
64   \snd  (sigma_regs prog f_lbls restr (regs ERTLptr_semantics st))〉)
65[ whd in match sigma_regs; normalize nodelta @eq_f2 [ %] cases(regs ? st)
66     #x #y %] #EQ <EQ -EQ
67change with (sigma_state ???? (set_regs ERTL_semantics 〈loc_mem,\snd (regs … st)〉
68            (set_frms ERTL_semantics tl st))) in ⊢ (???????(??%)?);
69@pop_ra_ok |
70| * #st1 #pc1 @if_elim [2: #_ @res_preserve_error1] normalize nodelta
71@eq_block_elim [2: #_ *] #EQbl1 * @if_elim
72[2: >EQbl1 @eq_block_elim [#_ *] * #H @⊥ @H <pc_block_eq [%] %
73    cases bl1 in EQbl1 EQfn1; #p1 #p2 #EQ destruct lapply p2
74    whd in match sigma_stored_pc; normalize nodelta cases(sigma_pc_opt ???)
75    normalize nodelta [2: #pc2] #p2 [#_ #EQ destruct]
76    >fetch_internal_function_no_zero [2: %] #EQ destruct
77] @eq_block_elim [2: #_ *] #EQbl11 * @mfr_return_eq1 normalize nodelta
78  cases bl1 in EQbl11 EQfn1; #p1 #p2 #EQ destruct
79  lapply p2 cases(pc_block pc1) #p11 #p22 #e #EQfn1 >EQfn1
80  %
81]
82qed.
83*)
84
85
86definition ERTLptrStatusSimulation :
87∀ prog : ertl_program.
88let trans_prog ≝ ertl_to_ertlptr prog in
89∀stack_sizes.∀ f_lbls : lbl_funct. ∀ f_regs : regs_funct.
90∀f_bl_r.
91b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
92     translate_data prog f_bl_r f_lbls f_regs →
93status_rel (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) ≝
94λprog,stack_sizes,f_lbls,f_regs,f_lb_r,good.
95  let trans_prog ≝ ertl_to_ertlptr prog in
96    mk_status_rel ??
97    (* sem_rel ≝ *) (λs1:ERTL_status prog stack_sizes
98       .λs2:ERTLptr_status trans_prog stack_sizes
99        .s1=sigma_state_pc prog f_lbls f_regs s2)
100    (* call_rel ≝ *) 
101          (λs1:Σs:ERTL_status prog stack_sizes
102               .as_classifier (ERTL_status prog stack_sizes) s cl_call
103       .λs2:Σs:ERTLptr_status trans_prog stack_sizes
104                .as_classifier (ERTLptr_status trans_prog stack_sizes) s cl_call
105        .
106        pc (mk_prog_params ERTL_semantics prog stack_sizes) s1
107         =sigma_stored_pc prog f_lbls
108          (pc
109           (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_sizes)
110           s2))
111    (* sim_final ≝ *) ?.
112cases daemon
113qed.
114
115include "joint/semantics_blocks.ma".
116
117
118
119lemma as_label_ok : ∀ prog : ertl_program.
120let trans_prog ≝ ertl_to_ertlptr prog in
121∀ f_lbls,f_regs,stack_sizes.
122∀f_bl_r.
123b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
124     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
125∀st,fn,id,stmt.
126fetch_statement ERTL_semantics (prog_var_names … prog)
127      (globalenv_noinit … prog) (pc … (sigma_state_pc prog f_lbls f_regs st)) =
128               return 〈id,fn,stmt〉 →
129as_label (ERTLptr_status trans_prog stack_sizes) st = as_label
130(ERTL_status prog stack_sizes) (sigma_state_pc prog f_lbls f_regs st).
131#prog #f_lbls #f_regs #stack_size #f_lb_r #good #st #fn #id #stmt #EQfetch
132whd in match as_label; normalize nodelta change with (pc ? ?) in ⊢ (??(??%)(??%));
133cases(b_graph_transform_program_fetch_statement … good … EQfetch)
134#init_data * #t_fn ** #EQt_fn whd in ⊢ (% → ?); cases(f_lb_r ?)
135normalize nodelta [2: #r #tl *] #EQinit destruct(EQinit) * #l_labs * #l_regs **
136#_ #_ cases stmt in EQfetch;
137[ * [ #c | * [ #c_id | #c_ptr ] #c_arg #c_dest | #reg #lbl | #s ] #nxt | #fin | * ]
138#EQfetch normalize nodelta * #bl * [1,2,3,4,5: >if_merge_right in ⊢ (% → ?); try %]
139whd in ⊢ (%→?); cases l_regs normalize nodelta [2,4,5,8,10,12: [3: *] #x #y *]
140[1,2,4,5,6:| #r #tl whd in ⊢ (% → ?); cases tl -tl normalize nodelta [2: #r1 #tl1 *]]
141#EQ destruct(EQ)
142[1,2,3,4,6: * #pre_l * #mid1 * #mid2 * #post_l *** #EQmid1
143            whd in match map_eval in ⊢ (% → ?); normalize nodelta
144            whd in ⊢ (?????%?? → ?);
145            whd in match (seq_list_in_code ???????) in ⊢ (%→?); *
146           [1,2,3,4: #EQ1 #EQ2 destruct(EQ1 EQ2) whd in EQmid1 : (???%);
147                     destruct(EQmid1) * #nxt1 * #EQt_stmt #_ #_
148           |        * #lbl1 * #rest ** #EQ destruct(EQ) * #nxt1 *
149                    #EQt_stmt #_ #_ #_ #_
150           ]
151|           * #pre_l * #mid ** #EQmid whd in ⊢ (% → ?); * #EQ destruct(EQ)
152            whd in EQmid : (???%); destruct(EQmid) #EQ destruct(EQ)
153            whd in ⊢ (% → ?); #EQt_stmt
154]
155whd in ⊢ (??%%); >EQfetch normalize nodelta whd in match fetch_statement;
156normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn;
157#EQt_fn >EQt_fn >m_return_bind >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_stmt;
158#EQt_stmt >EQt_stmt %
159qed.
160
161include "joint/StatusSimulationHelper.ma".
162include alias "basics/lists/listb.ma".
163
164lemma make_ERTL_To_ERTLptr_good_state_relation :
165∀prog : ertl_program.
166let p_out ≝ ertl_to_ertlptr prog in
167∀stack_sizes.
168∃init_regs : block → list register.
169∃f_lbls : block → label → list label.
170∃f_regs : block → label → list register.
171∃good : b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
172        (λglobals,fn.«translate_data globals fn,(refl …)»)
173        prog init_regs f_lbls f_regs.
174good_state_relation ERTL_semantics ERTLptr_semantics prog stack_sizes
175 (λglobals,fn.«translate_data globals fn,(refl …)»)
176 (sem_rel … (ERTLptrStatusSimulation prog … good)).
177#prog #stack_sizes
178cases(make_b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
179          (λglobals,fn.«translate_data globals fn,(refl …)») prog)
180#init_regs * #f_lbls * #f_regs #good %{init_regs} %{f_lbls} %{f_regs} %{good}
181%
182[#s1 #s2 #f #fn #stmt whd in ⊢ (% → ?); #EQ destruct(EQ) @fetch_stmt_ok_sigma_pc_ok
183| #st1 #st2 #f #fn #stmt #EQfetch whd in ⊢ (% → ?); #EQ destruct(EQ)
184  lapply(as_label_ok … good st2 … EQfetch) #EQ <EQ in ⊢ (??%?); %
185| normalize nodelta whd in ⊢ (% → % → % → ?); #st1 #st1' #st2 #f #fn
186  #a #ltrue #lfalse #EQfetch cases(fetch_statement_inv … EQfetch) #EQfn #EQstmt
187   whd in match eval_state; whd in match eval_statement_no_pc;
188  normalize nodelta >EQfetch >m_return_bind normalize nodelta >m_return_bind
189  whd in match eval_statement_advance; normalize nodelta
190  change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
191  #H lapply(err_eq_from_io ????? H) -H #H @('bind_inversion H) -H
192  #bv whd in match set_no_pc; normalize nodelta #EQbv
193   #H @('bind_inversion H) -H * #EQbool normalize nodelta
194   [whd in match goto; normalize nodelta >(pc_of_label_eq … EQfn)
195    >m_return_bind] whd in ⊢ (??%% → ?); #EQ destruct(EQ)
196  whd in ⊢ (% → ?); #EQ destruct(EQ) >(fetch_stmt_ok_sigma_state_ok … EQfetch) in EQbv;
197  whd in match sigma_state; normalize nodelta #EQbv
198  cases(ps_reg_retrieve_ok ?????? EQbv) #bv1 * #EQbv1 #EQ destruct(EQ)
199  cases(bool_of_beval_ok … EQbool) #b * #EQb #EQ destruct(EQ) #t_fn #EQt_fn
200  whd %{(refl …)} #mid #EQt_stmt %{(st_no_pc … st2)} %{(refl …)}
201  % [1,3: %{(refl …)} %]
202  %{(set_pc ? (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) ?) st2)}
203  [@ltrue |3: @lfalse] whd in match fetch_statement; normalize nodelta
204  >EQt_fn >m_return_bind >point_of_pc_of_point >EQt_stmt >m_return_bind
205  normalize nodelta >m_return_bind
206  change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
207  >EQbv1 >m_return_bind >EQb >m_return_bind normalize nodelta
208  [ >(pc_of_label_eq … EQt_fn) >m_return_bind] %{(refl …)}
209  whd whd in match sigma_state_pc; normalize nodelta
210  change with (pc_block (pc … st2)) in match (pc_block ?);
211  <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQfn %
212| #st1 #st1' #st2 #f #fn #stmt #nxt #EQfetch whd in match eval_state;
213  whd in match eval_statement_no_pc; normalize nodelta >EQfetch >m_return_bind
214  normalize nodelta #H @('bind_inversion H) -H #st1_no_pc' #EQst1_no_pc'
215  whd in ⊢ (??%% → ?); #EQ destruct(EQ) whd in ⊢ (%→?); #EQ destruct(EQ)
216  whd in match sigma_state_pc in EQst1_no_pc'; normalize  nodelta in EQst1_no_pc';
217  cases(fetch_statement_inv … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
218  #EQfn #EQstmt >EQfn in EQst1_no_pc'; normalize nodelta #EQst1_no_pc'
219  #t_fn #EQt_fn whd % [2: %{(refl …)} |] lapply(err_eq_from_io ????? EQst1_no_pc')
220  -EQst1_no_pc' #EQst1_no_pc'
221  cases(eval_seq_no_pc_no_call_ok prog f_lbls f_regs ???????? EQst1_no_pc')
222  [ #st2_no_pc' * #EQst2_no_pc' #EQ destruct(EQ)
223  %{(mk_state_pc ? st2_no_pc'
224     (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) nxt)
225     (last_pop … st2))} %
226     [ whd in ⊢ (??%?); >EQst2_no_pc' %
227     | whd whd in match sigma_state_pc; normalize nodelta >EQfn %
228     ]
229  |  #lbl whd in match code_has_label; whd in match code_has_point; normalize nodelta
230  inversion(stmt_at ????) [#_ *] #stmt1 #EQstmt1 #_
231  cut(fetch_statement ERTL_semantics (prog_var_names … prog) (globalenv_noinit … prog)
232                      (pc_of_point ERTL_semantics (pc_block (pc … st2)) lbl) =
233                 return 〈f,fn,stmt1〉)
234   [ whd in ⊢ (??%?); >EQfn normalize nodelta >point_of_pc_of_point >EQstmt1 %] #EQf_stmt1
235  cases(b_graph_transform_program_fetch_statement_plus … good … EQf_stmt1)
236  #init * #t_fn' ** #EQt_fn' whd in ⊢ (% → ?); cases(init_regs ?) [2: #x #y *]
237  normalize nodelta #EQ destruct(EQ) * #labels * #registers
238  ******* #EQlabels >point_of_pc_of_point change with (pc_block (pc … st2)) in match (pc_block ?);
239  #EQregisters #_ #_ #_ #_ #fresh_regs #_ >EQregisters
240  cases(excluded_middle_list ? (λreg.bool_to_Prop(¬(reg∈registers)))
241         (get_used_registers_from_seq … (functs ERTL) stmt) ?)
242  [3: #a #_ cases(¬a∈registers) // |1: #H assumption] #H @⊥
243  cases(Exists_All … H (regs_are_in_univers … (pi2 ?? fn) … EQstmt))
244   #reg ** #H1 #H2 @H1 -H1 @notb_Prop % #H1 lapply(fresh_regs … lbl) >EQregisters
245  #H3 lapply(All_memb … H3 H1) ** #H4 #_ @H4 assumption
246  ]
247]
248qed.
249
250include alias "basics/lists/listb.ma".
251
252lemma eval_seq_no_call_ok :
253 ∀prog.
254 let trans_prog ≝ ertl_to_ertlptr prog in
255 ∀ f_lbls,f_regs,stack_sizes.
256 ∀f_bl_r.
257 b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
258     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
259 ∀st2 : state_pc ERTLptr_semantics.
260 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
261 ∀st1' : state_pc ERTL_semantics.
262 ∀f,fn,stmt,nxt.
263   fetch_statement ERTL_semantics
264     (prog_var_names (joint_function ERTL_semantics) ℕ prog)
265    (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes))
266    (pc … st1) =
267      return 〈f, fn,  sequential … (step_seq ERTL … stmt) nxt〉 →
268   eval_state ERTL_semantics
269   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
270   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
271   st1 =
272    return st1' →
273 ∃st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
274 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
275  st2
276  st2'.
277 if taaf_non_empty … taf then True else
278(¬as_costed (ERTL_status prog stack_sizes) st1 ∨
279 ¬as_costed (ERTL_status prog stack_sizes) st1').
280#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #stmt #nxt
281#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
282#H @('bind_inversion H)-H #st_no_pc
283whd in match eval_statement_no_pc; normalize nodelta #EQnopc
284whd in match eval_statement_advance; normalize nodelta
285whd in match set_no_pc; whd in match next; whd in match set_pc;
286normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ) lapply EQfetch
287>(fetch_stmt_ok_sigma_pc_ok … EQfetch) #EQfetch'
288cases(b_graph_transform_program_fetch_statement_plus … good … EQfetch')
289#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
290[2: #r #tl *] #EQ destruct(EQ) * #labs * #regs ******* #EQlabs #EQregs #_ #_ #_ #_
291#fresh_regs * #bl * >if_merge_right in ⊢ (% → ?); [2: %]
292whd in ⊢ (% → ?); cases regs in EQregs; normalize nodelta [2: #x #y #_ *] #EQregs
293#EQ destruct(EQ) #eval_spec
294lapply(err_eq_from_io ????? EQnopc) -EQnopc >(fetch_stmt_ok_sigma_state_ok … EQfetch)
295#EQnopc
296cases(eval_seq_no_pc_no_call_ok prog f_lbls f_regs ???????? EQnopc)
297[ #stnopc'' * #EQstnopc'' #EQsem %
298  [ % [@stnopc'' | @(succ_pc ERTL_semantics (pc … st2) nxt) | @(last_pop … st2)]]
299  %
300  [ whd in match sigma_state_pc; normalize nodelta @('bind_inversion EQfetch)
301    * #f1 #fn1 >(fetch_stmt_ok_sigma_pc_ok … EQfetch) #EQfn1
302    #H @('bind_inversion H) -H #stmt1 #_ whd in ⊢ (??%% → ?); #EQ destruct(EQ)
303    >EQfn1 normalize nodelta >EQsem % ]
304  % [ @(produce_trace_any_any_free_coerced) [ @f | @t_fn1 |6: @eval_spec ||| @EQt_fn1]
305    whd in match repeat_eval_seq_no_pc; normalize nodelta whd in ⊢ (??%?);
306    >EQstnopc'' %] @if_elim [#_ @I] #_ %1 % whd in match as_costed;
307    normalize nodelta * #H @H whd in ⊢ (??%?); >EQfetch %
308| #lbl whd in match code_has_label; whd in match code_has_point; normalize nodelta
309  inversion(stmt_at ????) [#_ *] #stmt1 #EQstmt1 #_
310  cut(fetch_statement ERTL_semantics (prog_var_names … prog) (globalenv_noinit … prog)
311                      (pc_of_point ERTL_semantics (pc_block (pc … st2)) lbl) =
312                 return 〈f,fn,stmt1〉)
313   [ lapply(fetch_statement_inv … EQfetch') * #EQfn #_ whd in ⊢ (??%?);
314     >EQfn normalize nodelta >point_of_pc_of_point >EQstmt1 %] #EQf_stmt1
315  cases(b_graph_transform_program_fetch_statement_plus … good … EQf_stmt1)
316  #init * #t_fn' ** #EQt_fn' whd in ⊢ (% → ?); cases(f_bl_r ?) [2: #x #y *]
317  normalize nodelta #EQ destruct(EQ) * #labels * #registers
318  ******* #EQlabels >point_of_pc_of_point change with (pc_block (pc … st2)) in match (pc_block ?);
319  #EQregisters #_ #_ #_ #_ #_ #_ >EQregisters
320  cases(excluded_middle_list ? (λreg.bool_to_Prop(¬(reg∈registers)))
321         (get_used_registers_from_seq … (functs ERTL) stmt) ?)
322  [3: #a #_ cases(¬a∈registers) // |1: #H assumption] #H @⊥
323  lapply(fetch_statement_inv … EQfetch') * #_ normalize nodelta #EQstmt
324  cases(Exists_All … H (regs_are_in_univers … (pi2 ?? fn) … EQstmt))
325   #reg ** #H1 #H2 @H1 -H1 @notb_Prop % #H1 lapply(fresh_regs … lbl) >EQregisters
326  whd in ⊢ (% → ?); #H3 lapply(All_memb … H3 H1) ** #H4 #_ @H4 assumption
327]
328qed.
329
330lemma eval_goto_ok :
331 ∀prog : ertl_program.
332 let trans_prog ≝ ertl_to_ertlptr prog in
333∀ f_lbls,f_regs,stack_sizes.
334 ∀f_bl_r.
335 b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
336     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs →
337 ∀st2.
338 let st1 ≝ (sigma_state_pc prog f_lbls f_regs st2) in
339 ∀st1',f,fn,nxt.
340   fetch_statement ERTL_semantics …
341    (globalenv_noinit ? prog) (pc … st1) =
342      return 〈f, fn,  final … (GOTO ERTL … nxt)〉 →
343   eval_state ERTL_semantics
344   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
345   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
346   st1 =
347    return st1' →
348    ∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
349 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
350  st2
351  st2'.
352  bool_to_Prop (taaf_non_empty … taf).
353#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #nxt #EQfetch
354whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
355whd in match eval_statement_no_pc; normalize nodelta
356>m_return_bind whd in match eval_statement_advance; whd in match set_no_pc;
357whd in match goto; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
358#H @('bind_inversion H) -H #new_pc lapply(fetch_statement_inv … EQfetch) *
359#EQfn #_ >(pc_of_label_eq … EQfn) whd in ⊢ (??%% → ??%% → ?);
360#EQ1 #EQ2 destruct(EQ1 EQ2)
361% [ % [ @st2 | @(mk_program_counter (pc_block (pc … st2))
362                         (offset_of_point ERTL_semantics nxt)) | @(last_pop … st2)]]
363% [ >(fetch_stmt_ok_sigma_state_ok … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
364    >(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match sigma_state_pc;
365    normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn
366    >EQfn %]
367cases(b_graph_transform_program_fetch_statement … good … EQfetch)
368#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
369[2: #r #tl *] #EQ destruct(EQ) * #labs **
370[2: #hd #tl ** #_ #_ ** #pre #inst * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
371whd in match translate_fin_step; normalize nodelta * #bl *
372whd in ⊢ (% → ?); #EQ destruct(EQ) **
373[2: #lb #tl * #mid ** #EQmid whd in ⊢ (% → ?); * #ABS destruct(ABS)] * #mid **
374whd in ⊢ (???% → ?); #EQ destruct(EQ) * #_ #_ change with (stmt_at ???? = ? → ?)
375#EQstmt >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn1; #EQt_fn1
376>(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQstmt; #EQstmt
377%{(taaf_step … (taa_base …) …)}
378[ whd in match as_classifier; normalize nodelta whd in ⊢ (??%?);
379  whd in match fetch_statement; normalize nodelta 
380  >EQt_fn1 >m_return_bind >EQstmt %
381| whd whd in match eval_state; normalize nodelta whd in match fetch_statement;
382  normalize nodelta  >EQt_fn1 >m_return_bind >EQstmt >m_return_bind
383  whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
384  whd in match eval_statement_advance; normalize nodelta
385  whd in match goto; normalize nodelta >(pc_of_label_eq … EQt_fn1) %
386] @I
387qed.
388
389
390
391(*
392lemma list_elim_on_last : ∀A : Type[0].∀ P : (list A) → Prop. ∀ l.
393                 P ([ ]) → (∀pre,last. P (pre@[last])) → P l.
394#A #P #l #H1 #H2 cut(∀A.∀l : list A.l = [ ] ∨ ∃pre,last. l = pre@[last])
395[ #A #l elim l [ %1 % | #a #tl * [ #EQ destruct %2 %{([ ])} %{a} %]
396* #l1 * #a1 #EQ destruct %2 %{(a::l1)} %{a1} %]] #APP1
397lapply(APP1 … l) * [ #EQ >EQ assumption]
398 * #pre * #last #EQ >EQ @H2
399qed.*)
400
401
402
403lemma eval_return_ok :
404∀prog : ertl_program.
405let trans_prog ≝ ertl_to_ertlptr prog in
406∀ f_lbls,f_regs,stack_sizes.
407 ∀f_bl_r.
408 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
409     translate_data prog f_bl_r f_lbls f_regs.
410∀st2, st1',f,fn.
411 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
412 fetch_statement ERTL_semantics …
413  (globalenv_noinit ? prog) (pc … st1) =
414    return 〈f, fn,  final … (RETURN ERTL … )〉 →
415 eval_state ERTL_semantics
416   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
417   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
418   st1 =
419  return st1' →
420joint_classify (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)
421  st2 = cl_return ∧
422∃st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
423∃st2_after_ret.
424∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes) (* always empty in this case *)
425st2_after_ret
426st2'.
427(if taaf_non_empty … taf then
428  ¬as_costed (ERTLptr_status trans_prog stack_sizes)
429    st2_after_ret
430 else True) ∧
431eval_state … (ev_genv …  (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) st2 =
432return st2_after_ret ∧
433ret_rel ?? (ERTLptrStatusSimulation prog stack_sizes ??? good) st1' st2_after_ret.
434#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #EQfetch
435whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
436#H @('bind_inversion H) -H #st1_tmp whd in ⊢ (??%%→?); #EQ destruct
437whd in match set_no_pc in ⊢ (%→?); whd in match eval_statement_advance in ⊢ (%→?);
438whd in match eval_return; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
439#H @('bind_inversion H) -H * #n_st #n_pc change with (ertl_pop_frame ? = ? → ?)
440>(fetch_stmt_ok_sigma_state_ok … EQfetch) #EQpop_frame
441cases(pop_frame_ok ?????? EQpop_frame) * #t_n_st #t_n_pc * #EQt_pop_frame
442normalize nodelta
443inversion (fetch_internal_function ??) normalize nodelta
444[ * #id1 #fn1 | #err ] normalize nodelta #EQfetch_fn1 #EQ destruct(EQ)
445#H @('bind_inversion H) -H #next_of_n_pc
446[2: >next_of_call_pc_error [2: % %] whd in ⊢ (???% → ?); #EQ destruct(EQ)]
447#EQnext_of_n_pc cases(next_of_call_pc_ok … good … EQnext_of_n_pc)
448#pc1 * #EQpc1 cut(pc1 = t_n_pc)
449[ @(sigma_stored_pc_inj prog f_lbls)
450  lapply EQnext_of_n_pc; <EQpc1 whd in match sigma_stored_pc; normalize nodelta
451  inversion(sigma_pc_opt ???) [1,3: #_ >next_of_call_pc_error [2,4: % %]
452  whd in ⊢ (???% → ?); #EQ destruct| #x #_ #_ % #EQ destruct] #x #EQx #_
453  lapply EQnext_of_n_pc whd in match sigma_stored_pc; normalize nodelta
454  inversion (sigma_pc_opt ???) [ #_ >next_of_call_pc_error [2: % %]
455  whd in ⊢ (???% → ?); #EQ destruct] #y #EQy #_ lapply EQpc1
456  whd in match sigma_stored_pc; normalize nodelta >EQx >EQy normalize nodelta
457  #EQ destruct %
458] #EQ destruct(EQ) #EQnxt whd in match next; whd in match set_last_pop;
459whd in match set_pc; normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ)
460cases(b_graph_transform_program_fetch_statement … good … EQfetch)
461#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
462[2: #r #tl *] #EQ destruct(EQ) * #labs **
463[2: #hd #tl ** #_ #_ * #ibl * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
464whd in match translate_fin_step; normalize nodelta * #bl *
465whd in ⊢ (% → ?); #EQ destruct(EQ) **
466[2: #lb #tl * #mid ** #EQmid whd in ⊢ (% → ?); * #ABS destruct(ABS)] * #mid **
467whd in ⊢ (???% → ?); #EQ destruct(EQ) * #_ #_ change with (stmt_at ???? = ? → ?)
468#EQstmt %
469[ whd in match joint_classify; normalize nodelta whd in match fetch_statement;
470  normalize nodelta <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
471  >EQstmt %
472| %
473    [ %
474        [ @t_n_st
475        | @(succ_pc ERTL_semantics (sigma_stored_pc prog f_lbls t_n_pc) next_of_n_pc)
476        | @t_n_pc]
477    ]
478  % 
479    [ whd in match sigma_state_pc; normalize nodelta
480      lapply(next_of_call_pc_inv … EQnext_of_n_pc) * #id2 * #fn2 * #c_id * #c_arg
481      * #c_dest #EQfetch1 whd in match (succ_pc ???);
482      >(fetch_stmt_ok_sigma_pc_block_ok … EQfetch1) >EQfetch_fn1
483      normalize nodelta %
484    ]
485  %
486    [ %
487        [ @t_n_st
488        | @(succ_pc ERTL_semantics (sigma_stored_pc prog f_lbls t_n_pc) next_of_n_pc)
489        | @t_n_pc]
490    ]
491  %{(taaf_base … )} normalize nodelta % [% [@I]]
492    [ whd in match fetch_statement; normalize nodelta <(fetch_stmt_ok_sigma_pc_ok … EQfetch)
493      >EQt_fn1 >m_return_bind >EQstmt >m_return_bind whd in match eval_statement_no_pc;
494      normalize nodelta >m_return_bind whd in match eval_statement_advance;
495      whd in match eval_return; normalize nodelta 
496      change with (ertl_pop_frame ?) in match (pop_frame ????????);
497      >EQt_pop_frame >m_return_bind >EQnxt >m_return_bind whd in match next;
498      whd in match set_pc; whd in match set_last_pop; whd in match succ_pc;
499      normalize nodelta lapply(next_of_call_pc_inv … EQnext_of_n_pc)
500      * #id2 * #fn2 * #c_id * #c_arg * #c_dest #EQfetch1 whd in match (succ_pc ???);
501      >(fetch_stmt_ok_sigma_pc_block_ok … EQfetch1) %
502    | whd * #s1_pre #s1_call
503      cases (joint_classify_call … s1_call)
504      * #calling_i #calling * #call_spec * #arg * #dest * #nxt' #EQfetch_call
505      * #s2_pre #s2_call whd in ⊢ (% → ?); >EQfetch_call normalize nodelta
506      * #s1_pre_prf #EQpc_s2_pre whd in ⊢ (% → ?); #EQ1
507      >EQ1 in EQfetch_call; #EQfetch_call
508      cases(fetch_call_commute … good … EQfetch_call) #calling' * #pc1 *
509      #EQ1 cut(pc … s2_pre = pc1)
510      [ @(sigma_stored_pc_inj prog f_lbls) lapply(EQfetch_call)
511        whd in match sigma_stored_pc; normalize nodelta inversion(sigma_pc_opt ???)
512        [1,3: #_ >fetch_statement_no_zero [2,4: %] #EQ destruct(EQ)| #x #_ #_ % #EQ destruct]
513        #pc2 #EQpc2 #_ lapply EQ1 whd in match sigma_stored_pc;
514        normalize nodelta >EQpc2 normalize nodelta cases(sigma_pc_opt ???)
515        [2: #x normalize nodelta #EQ >EQ %] normalize nodelta #EQ <EQ in EQpc2;
516        #EQ1 lapply EQfetch_call >fetch_statement_no_zero [ #ABS destruct(ABS)]
517        whd in match sigma_stored_pc; normalize nodelta >EQ1 %
518      ] #EQ2 destruct(EQ2) #EQt_fetch_call whd >EQt_fetch_call normalize nodelta %
519       [ >EQ1 in s1_pre_prf; #EQ @(sigma_stored_pc_inj prog f_lbls)
520        lapply EQnext_of_n_pc whd in match sigma_stored_pc; normalize nodelta
521        inversion(sigma_pc_opt ???) [1,3: #_ >next_of_call_pc_error [2,4: % %]
522        whd in ⊢ (???% → ?); #EQ destruct] #pc1 #EQpc1 #_ [ % #EQ destruct]
523        lapply EQ whd in match sigma_stored_pc; normalize nodelta
524        >EQpc1 normalize nodelta inversion(sigma_pc_opt ???)
525        [2: #pc2 #_ normalize nodelta #EQ >EQ %] normalize nodelta
526        #ABS #ABS1 lapply EQnext_of_n_pc whd in match sigma_stored_pc;
527        normalize nodelta >EQpc1 >ABS1 normalize nodelta
528        >next_of_call_pc_error [2: % %] whd in ⊢ (???% → ?); #EQ destruct
529       | whd in match succ_pc; normalize nodelta
530        change with next_of_n_pc in match (point_of_succ ???);
531        change with nxt' in match (point_of_succ ???);
532        lapply EQpc_s2_pre whd in match succ_pc; normalize nodelta
533        change with next_of_n_pc in match (point_of_succ ???);
534        change with nxt' in match (point_of_succ ???); #EQ >EQ
535        cut(pc_block (pc … s1_pre) = pc_block (pc … s2_pre))
536        [2: #EQ >EQ %] >EQ1 <(pc_block_eq prog f_lbls …) [%]
537        lapply EQfetch_call whd in match sigma_stored_pc; normalize nodelta
538        cases(sigma_pc_opt ???) [ >fetch_statement_no_zero [2: %] #EQ destruct]
539        #x #_ % #EQ destruct
540       ]
541     ]
542]
543qed.
544
545
546
547lemma eval_cond_ok :
548∀prog.
549let trans_prog ≝ ertl_to_ertlptr prog in
550∀ f_lbls,f_regs,stack_sizes.
551 ∀f_bl_r.
552 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
553     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
554∀st2,st1',f,fn,a,ltrue,lfalse.
555let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
556 fetch_statement ERTL_semantics …
557  (globalenv_noinit ? prog) (pc … st1) =
558    return 〈f, fn,  sequential … (COND ERTL … a ltrue) lfalse〉 →
559 eval_state ERTL_semantics
560   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
561   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
562   st1 = return st1' →
563as_costed (ERTL_status prog stack_sizes) st1' →
564∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
565∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
566st2 st2'.
567bool_to_Prop (taaf_non_empty … taf).
568#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn #a #ltrue #lfalse
569#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
570whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
571whd in match eval_statement_advance; normalize nodelta
572change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
573#H lapply(err_eq_from_io ????? H) -H #H @('bind_inversion H) -H
574#bv >(fetch_stmt_ok_sigma_state_ok … EQfetch) in ⊢ (% → ?); whd in match set_no_pc;
575normalize nodelta #EQbv #H @('bind_inversion H) -H * #EQbool normalize nodelta
576 lapply(fetch_statement_inv … EQfetch) * #EQfn #_
577[ whd in match goto; normalize nodelta >(pc_of_label_eq ??????? EQfn) >m_return_bind
578| whd in match next; normalize nodelta
579] whd in match set_pc; normalize nodelta
580>(fetch_stmt_ok_sigma_state_ok … EQfetch) whd in match set_no_pc; normalize nodelta
581>(fetch_stmt_ok_sigma_pc_ok … EQfetch) >(fetch_stmt_ok_sigma_last_pop_ok … EQfetch)
582whd in ⊢ (??%% → ?); #EQ destruct #n_cost
583%{(mk_state_pc ? (st_no_pc … st2)
584                 (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) ?)
585                 (last_pop … st2))} [ @ltrue |3: @lfalse]
586% [1,3: whd in match sigma_state_pc; normalize nodelta
587        >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %]
588cases(b_graph_transform_program_fetch_statement … good … EQfetch)
589#init_data * #t_fn1 ** #EQt_fn1 whd in ⊢ (% → ?); cases (f_bl_r ?) normalize nodelta
590[2,4: #r #tl *] #EQ destruct(EQ) >if_merge_right in ⊢ (% → ?); [2,4: %] * #labs **
591[2,4: #hd #tl ** #_ #_ *** #pre #inst #post * whd in ⊢ (%→?); *] ** #EQlabs #EQf_regs
592whd in match translate_step; normalize nodelta * #bl *
593whd in ⊢ (% → ?); #EQ destruct(EQ) whd in ⊢ (% → ?); * #l1 * #mid1 * #mid2 * #l2
594*** #EQmid1 whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) whd in ⊢ (% → ?); *
595#nxt1 * #EQcond #EQ destruct(EQ) whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2)
596whd in EQmid1 : (??%%); destruct(EQmid1)
597%{(taaf_step_jump … (taa_base …) …) I}
598[2,5: whd whd in ⊢ (??%?); whd in match fetch_statement; normalize nodelta 
599      <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
600      >EQcond %
601|3,6: whd whd in match eval_state; normalize nodelta whd in match eval_statement_no_pc;
602      normalize nodelta whd in match fetch_statement; normalize nodelta
603      <(fetch_stmt_ok_sigma_pc_ok … EQfetch) >EQt_fn1 >m_return_bind
604      >EQcond >m_return_bind normalize nodelta >m_return_bind
605      whd in match eval_statement_advance; normalize nodelta
606      change with (ps_reg_retrieve ??) in match (acca_retrieve ?????);
607      cases(ps_reg_retrieve_ok … EQbv) #bv1 * #EQbv1 #EQsem >EQbv1
608      >m_return_bind >EQsem in EQbool; #EQbool cases(bool_of_beval_ok … EQbool)
609      #bool1 * #EQbool1 #EQ destruct(EQ) >EQbool1 >m_return_bind normalize nodelta
610      >(fetch_stmt_ok_sigma_pc_ok … EQfetch) [2: %] whd in match goto;
611      normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQt_fn1; #EQt_fn1
612      >(pc_of_label_eq … EQt_fn1) >m_return_bind %
613|*: lapply n_cost whd in match as_costed; normalize nodelta
614    [ cut((mk_state_pc ERTL_semantics
615   (sigma_state prog f_lbls f_regs
616    (added_registers ERTL (prog_var_names (joint_function ERTL) ℕ prog) fn
617     (f_regs (pc_block (pc ERTLptr_semantics st2)))) st2)
618   (pc_of_point ERTL_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
619   (sigma_stored_pc prog f_lbls (last_pop ERTLptr_semantics st2))) =
620   sigma_state_pc prog f_lbls f_regs (mk_state_pc ERTLptr_semantics st2
621    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
622    (last_pop ERTLptr_semantics st2))) [ whd in match sigma_state_pc; normalize  nodelta
623    >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %]
624    #EQ >EQ >(as_label_ok … good … (mk_state_pc ERTLptr_semantics st2
625    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2)) ltrue)
626    (last_pop ERTLptr_semantics st2))) [#H @H] cases daemon (*needs lemma see below *)
627    | cut((mk_state_pc ERTL_semantics
628   (sigma_state prog f_lbls f_regs
629    (added_registers ERTL (prog_var_names (joint_function ERTL) ℕ prog) fn
630     (f_regs (pc_block (pc ERTLptr_semantics st2)))) st2)
631   (succ_pc ERTL_semantics (pc ERTLptr_semantics st2)
632    (point_of_succ ERTLptr_semantics
633     (point_of_pc ERTLptr_semantics
634      (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
635   (sigma_stored_pc prog f_lbls (last_pop ERTLptr_semantics st2))) =
636   sigma_state_pc prog f_lbls f_regs (mk_state_pc ERTLptr_semantics st2
637    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2))
638     (point_of_succ ERTLptr_semantics
639      (point_of_pc ERTLptr_semantics
640       (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
641    (last_pop ERTLptr_semantics st2))) [ whd in match sigma_state_pc; normalize  nodelta
642    >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in EQfn; #EQfn >EQfn %] #EQ >EQ
643    >(as_label_ok … good … (mk_state_pc ERTLptr_semantics st2
644    (pc_of_point ERTLptr_semantics (pc_block (pc ERTLptr_semantics st2))
645     (point_of_succ ERTLptr_semantics
646      (point_of_pc ERTLptr_semantics
647       (pc ERTL_semantics (sigma_state_pc prog f_lbls f_regs st2))) nxt1))
648    (last_pop ERTLptr_semantics st2))) [#H @H] cases daemon (*needs lemma see below ! *)
649]
650qed.
651     
652lemma eval_cost_ok :
653∀prog.
654let trans_prog ≝ ertl_to_ertlptr prog in
655∀ f_lbls,f_regs,stack_sizes.
656 ∀f_bl_r.
657 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
658     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
659∀st2,st1',f,fn,c,nxt.
660let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
661 fetch_statement ERTL_semantics …
662  (globalenv_noinit ? prog) (pc … st1) =
663    return 〈f, fn,  sequential … (COST_LABEL ERTL … c) nxt〉 →
664 eval_state ERTL_semantics
665   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
666   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
667   st1 = return st1' →
668∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
669∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
670st2 st2'.
671bool_to_Prop (taaf_non_empty … taf).
672#prog #f_lbls #f_regs #stack_Size #f_bl_r #good #st2 #st1' #f #fn #c #nxt
673#EQfetch whd in match eval_state; normalize nodelta >EQfetch >m_return_bind
674whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
675whd in match eval_statement_advance; normalize nodelta
676>(fetch_stmt_ok_sigma_state_ok … EQfetch) whd in match set_no_pc;
677normalize nodelta >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
678>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match next;
679whd in match set_pc; normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ)
680%{(set_pc ? (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) nxt) st2)}
681% [ whd in match sigma_state_pc; normalize nodelta
682    lapply(fetch_statement_inv … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch) *
683    #EQfn #_ >EQfn %] lapply EQfetch >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
684#EQfetch'
685cases(b_graph_transform_program_fetch_statement … good … EQfetch')
686#init_data * #t_fn ** #EQt_fn whd in ⊢ (% → ?); cases(f_bl_r ?) [2: #x #y *]
687normalize nodelta #EQ destruct(EQ) * #lbls * #regs ** #_ #_ whd in ⊢ (% → ?);
688* #bl * >if_merge_right [2: %] whd in ⊢ (% → ?); cases regs [2: #x #y *]
689normalize nodelta #EQ destruct(EQ) whd in ⊢ (% → ?); * #l1 * #mid1 * #mid2 * #l2
690*** #EQmid whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) whd in EQmid : (???%);
691destruct(EQmid) whd in ⊢ (% → ?); * #nxt1 * #EQstmt #EQ destruct(EQ)
692whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) %{(taaf_step … (taa_base …) …)}
693[1,2: whd [ whd in ⊢ (??%?); | whd in match eval_state; ] 
694      whd in match fetch_statement; normalize nodelta >EQt_fn >m_return_bind
695      >EQstmt [%] >m_return_bind whd in match eval_statement_no_pc;
696      normalize nodelta >m_return_bind %] @I
697qed.
698
699
700lemma eval_call_ok   :
701 ∀prog : ertl_program.
702 let trans_prog ≝ ertl_to_ertlptr prog in
703∀ f_lbls,f_regs,stack_sizes.
704 ∀f_bl_r.
705 ∀ good :b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
706     (λglobals,fn.«translate_data globals fn,(refl …)») prog f_bl_r f_lbls f_regs.
707 ∀st2,st1',f,fn,called,args,dest,nxt.
708 let st1 ≝ sigma_state_pc prog f_lbls f_regs st2 in
709  fetch_statement ERTL_semantics …
710    (globalenv_noinit ? prog) (pc … st1) =
711      return 〈f, fn,
712        sequential … (CALL ERTL … called args dest ) nxt〉 →
713   eval_state … (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes)) st1 =
714    return st1' →
715∃is_call,st2_pre_call,is_call'.
716as_call_ident (ERTLptr_status trans_prog stack_sizes)
717 («st2_pre_call,is_call'») = as_call_ident (ERTL_status prog stack_sizes)
718  («st1, is_call») ∧
719(pc … st1) = sigma_stored_pc prog f_lbls (pc … st2_pre_call) ∧
720∃taa2 : trace_any_any (ERTLptr_status trans_prog stack_sizes) st2 st2_pre_call.
721∃ st2'. st1' = sigma_state_pc prog f_lbls f_regs st2' ∧
722eval_state ERTLptr_semantics …
723 (ev_genv … (mk_prog_params ERTLptr_semantics trans_prog stack_sizes)) st2_pre_call
724 =return st2'.
725#prog #f_lbls #f_regs #stack_size #f_bl_r #good #st2 #st1' #f #fn * [#c_id | * #c_ptr1 #c_ptr2 ]
726#args #dest #nxt #EQfetch whd in match eval_state; normalize nodelta >EQfetch
727>m_return_bind whd in match eval_statement_no_pc; normalize nodelta >m_return_bind
728whd in match eval_statement_advance; whd in match eval_call; normalize nodelta
729>(fetch_stmt_ok_sigma_state_ok … EQfetch) >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
730>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) #H @('bind_inversion H) -H
731#c_bl whd in match set_no_pc; normalize nodelta #H lapply(err_eq_from_io ????? H) -H
732#EQc_bl cases(block_of_call_ok ??????? EQc_bl) #c_bl' * #EQc_bl' #EQ destruct(EQ)
733#H @('bind_inversion H) -H * #f1 * [1,3: #fn1 |*: #ext_f] #H
734lapply(err_eq_from_io ????? H) -H  #EQfn1 normalize nodelta
735[3,4: #H @('bind_inversion H) -H #st whd in match eval_external_call; normalize nodelta
736      #H @('bind_inversion H) -H #list_val #_ #H @('bind_inversion H) -H #x
737      #_ #H @('bind_inversion H) -H #y whd in match do_io; normalize nodelta
738      whd in ⊢ (???% → ?); #ABS destruct(ABS) ] #H lapply(err_eq_from_io ????? H) -H
739#H @('bind_inversion H) -H #st1'' >(fetch_stmt_ok_sigma_pc_ok … EQfetch)
740>(fetch_stmt_ok_sigma_last_pop_ok … EQfetch) whd in match kind_of_call;
741normalize nodelta change with (ertl_save_frame ? it ?) in ⊢ (??%? → ?);
742[2: @ID |4: @PTR] #EQst1''  #H @('bind_inversion H) -H #st1'''
743whd in match eval_internal_call; normalize nodelta #H @('bind_inversion H) -H
744#s_size #H lapply(opt_eq_from_res ???? H) -H
745change with (stack_size ?) in ⊢ (??%? → ?); #EQs_size whd in ⊢ (??%? → ?);
746whd in ⊢ (???% → ??%% → ?); #EQ #EQ1 destruct(EQ EQ1)
747lapply EQfetch >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in ⊢ (% → ?);
748#EQfetch' lapply(fetch_statement_inv … EQfetch') * #EQfn normalize nodelta #EQstmt
749cases(b_graph_transform_program_fetch_statement_plus … good … EQfetch')
750#init_data * #calling' ** #EQcalling' whd in ⊢ (% → ?); cases(f_bl_r ?)
751[2,4: #x #y *] normalize nodelta #EQ destruct(EQ) * #labels * #registers
752******* #EQlabels #EQregisters #_ #_ #_ #_ #fresh_regs
753normalize nodelta >if_merge_right [2,4: %] whd in match translate_step;
754normalize nodelta * #bl * cases registers in EQregisters; -registers
755normalize nodelta [2,3: [ #x #y] #_ *|4: #r #tl] #EQregisters
756[ whd in ⊢ (% → ?); cases tl in EQregisters; -tl [2: #x #y #_ *] normalize nodelta
757#EQregisters | whd in ⊢ (% → ?);] #EQ destruct(EQ)
758* #pre_l * #mid1 * #mid2 * #post_l *** #EQmid1 #m_fetch_pre whd in ⊢ (% → ?);
759* #nxt1 * #EQcall change with nxt1 in ⊢ (??%? → ?); #EQ destruct(EQ)
760whd in ⊢ (% → ?); * #EQ1 #EQ2 destruct(EQ1 EQ2) cases(pre_l) in m_fetch_pre EQmid1;
761[* #x * #y ** #ABS destruct(ABS)
762|4: #lab #tl * #ABS destruct(ABS)
763| #l1 #tl #m_fetch_pre whd in ⊢ (???% → ?); #EQ destruct(EQ)
764| * #_ #EQ destruct(EQ) whd in ⊢ (???% → ?); #EQ destruct(EQ)
765]
766%
767[1,3: @hide_prf whd in ⊢ (??%?); >EQfetch %]
768cases(ertl_save_frame_ok prog f_lbls f_regs ?
769  (added_registers ERTL (prog_var_names … prog) fn1 (f_regs c_bl')) ? st1''' ?)
770[2: @PTR
771|3,7: [ %{(mk_state_pc ? (st_no_pc … st2)
772                     (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
773                     (last_pop … st2))}
774      |%{(st2)}
775      ] @hide_prf whd in match sigma_pc_opt; normalize nodelta @if_elim
776      [1,3: @eqZb_elim [2,4: #_ *] #EQbl >fetch_internal_function_no_minus_one in EQfn;
777           [1,3: #EQ destruct(EQ) |*: assumption]]
778      #_ [>point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
779         | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
780         ] >m_return_bind % whd in ⊢ (??%? → ?); #ABS destruct(ABS)
781|6: @ID
782|4,8: [change with (pc_block (pc … st2)) in match (pc_block ?);
783       >EQfn in ⊢ (??(???match % with [_ ⇒ ?| _ ⇒ ?])?);
784      |>EQfn in ⊢ (??(???match % with [_ ⇒ ?| _ ⇒ ?])?);
785      ] normalize nodelta whd in match (st_no_pc ??);
786      whd in match sigma_stored_pc in ⊢ (??(???(???%?))?);
787      whd in match sigma_pc_opt; normalize nodelta @if_elim
788     [1,3: @eqZb_elim [2,4: #_ *] #EQbl >fetch_internal_function_no_minus_one in EQfn;
789           [1,3: #EQ destruct(EQ) |*: assumption]]
790      #_ [>point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
791         | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
792         ] >m_return_bind normalize nodelta
793         change with (pc_block (pc … st2)) in match (pc_block ?);
794         >pc_of_point_of_pc assumption
795] #st_no_pc_after_call normalize nodelta *
796[ #H @('bind_inversion H) -H #st_no_pc_pre_call #EQst_no_pc_pre_call
797  whd in match set_no_pc; normalize nodelta]
798#EQst_no_pc_after_call #EQ destruct(EQ)
799[ letin pairpc ≝ (beval_pair_of_pc
800                     (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1))
801  %{(mk_state_pc ? (set_regs ERTL_state
802                      (〈add ?? (\fst (regs … st2)) r (\snd pairpc),\snd(regs … st2)〉)
803                      st_no_pc_pre_call)
804                   (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
805                   (last_pop … st2))}
806| %{st2}
807]
808%
809[1,3: @hide_prf whd in ⊢ (??%?); whd in match fetch_statement; normalize nodelta
810      >EQcalling' >m_return_bind [>point_of_pc_of_point ] >EQcall >m_return_bind %]
811%
812[1,3: %
813  [1,3: whd in ⊢ (??%%); whd in match fetch_statement in ⊢ (??%?);
814        normalize nodelta >EQcalling' in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);
815        >m_return_bind in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);
816       [ >point_of_pc_of_point in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?);]
817       >EQcall in ⊢ (??(match % with [_ ⇒ ? | _ ⇒ ?])?); normalize nodelta
818       >(fetch_stmt_ok_sigma_pc_ok … EQfetch) in ⊢ (???(match % with [_ ⇒ ? | _ ⇒ ?]));
819       >EQfetch' in ⊢ (???(match % with [_ ⇒ ? | _ ⇒ ?])); %
820  |*:  whd in match sigma_stored_pc; whd in match sigma_pc_opt; normalize nodelta
821      @if_elim change with (pc_block(pc … st2)) in match (pc_block ?);
822      [1,3: @eqZb_elim [2,4: #_ *] #EQbl #_
823      >fetch_internal_function_no_minus_one in EQcalling'; [2,4: assumption]
824      whd in ⊢ (???% → ?); #ABS destruct(ABS) ] #_
825      [ >point_of_pc_of_point >(get_sigma_last … good … EQfn EQstmt EQlabels)
826      | >(get_sigma_idempotent … good … EQfn EQstmt EQlabels)
827      ]
828      >m_return_bind >pc_of_point_of_pc %
829  ]
830|4: %{(taa_base …)}
831| %{(taaf_to_taa ???
832      (produce_trace_any_any_free
833           (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
834           st2 ?????
835           (mk_state_pc ?
836                (set_regs ERTL_state
837                      (〈add ?? (\fst (regs … st2)) r (\snd pairpc),\snd(regs … st2)〉)
838                      st_no_pc_pre_call)
839                (pc_of_point ERTLptr_semantics (pc_block (pc … st2)) mid1)
840                (last_pop … st2))
841           EQcalling' m_fetch_pre ?) ?)}
842  [ @if_elim [2: #_ @I] #_ % whd in ⊢ (% → ?); whd in match (as_label ??);
843    whd in match (as_pc_of ??); whd in match fetch_statement; normalize nodelta
844    >EQcalling' >m_return_bind whd in match point_of_pc; normalize nodelta
845    >point_of_offset_of_point >EQcall >m_return_bind normalize nodelta
846    whd in match cost_label_of_stmt; normalize nodelta * #H @H %
847  | whd in match repeat_eval_seq_no_pc; normalize nodelta whd in ⊢ (??%?);
848    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
849    normalize nodelta whd in match (eval_ext_seq ????????);
850    whd in match (get_pc_from_label ?????); whd in match block_of_funct_id;
851    normalize nodelta @('bind_inversion EQfn) * #f2 * #fn2
852    whd in match fetch_function; normalize nodelta #H
853    lapply(opt_eq_from_res ???? H) -H #H @('bind_inversion H) -H #f3 #EQf3
854    #H @('bind_inversion H) -H #fn4 #_ whd in ⊢ (??%%→ ??%% → ?); #EQ1 #EQ2
855    destruct(EQ1 EQ2)
856    >(find_symbol_transf …
857            (λvars.transf_fundef … (λfn.(b_graph_translate … fn))) prog f)
858    >(symbol_of_block_rev … EQf3) >m_return_bind >code_block_of_block_eq
859    normalize nodelta >(pc_of_label_eq … EQcalling') normalize nodelta
860    whd in ⊢ (??%?);
861    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
862    normalize nodelta whd in match (eval_ext_seq ????????);
863    whd in match acca_arg_retrieve; normalize nodelta
864    change with (ps_reg_retrieve ??) in match (acca_arg_retrieve_ ?????);
865    whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
866    >lookup_add_hit >m_return_bind whd in match set_regs; normalize nodelta
867    @('bind_inversion EQst_no_pc_pre_call) #new_st whd in match push in ⊢ (%→ ?);
868    normalize nodelta #H @('bind_inversion H) -H #is1 #EQis1 whd in ⊢ (??%% → ?);
869    #EQ destruct(EQ) #H @('bind_inversion H) -H #is2 #EQis2 whd in match set_istack;
870    normalize nodelta whd in ⊢ (??%% → ?); #EQ destruct(EQ) whd in match push;
871    normalize nodelta >EQis1 >m_return_bind whd in match set_istack; normalize nodelta
872    whd in ⊢ (??%?); whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
873    normalize nodelta whd in match (eval_ext_seq ????????);
874    whd in match (get_pc_from_label ?????); whd in match block_of_funct_id;
875    normalize nodelta
876    >(find_symbol_transf …
877            (λvars.transf_fundef … (λfn.(b_graph_translate … fn))) prog f)
878    >(symbol_of_block_rev … EQf3) >m_return_bind >code_block_of_block_eq
879    normalize nodelta >(pc_of_label_eq … EQcalling') normalize nodelta
880    whd in ⊢ (??%?);
881    whd in match eval_seq_no_pc in ⊢ (??match % with [_ ⇒ ?| _ ⇒ ?]?);
882    normalize nodelta whd in match (eval_ext_seq ????????);
883    whd in match acca_arg_retrieve; normalize nodelta
884    change with (ps_reg_retrieve ??) in match (acca_arg_retrieve_ ?????);
885    whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
886    >lookup_add_hit >m_return_bind whd in match set_regs; normalize nodelta
887    whd in match push; normalize nodelta >EQis2 >m_return_bind normalize nodelta
888    whd in ⊢ (??%?); @eq_f whd in match set_istack; normalize nodelta
889    whd in match reg_store; normalize  nodelta >add_idempotent %
890  | cut(∀st,st',kind.ertlptr_save_frame kind it st = return st' →
891                ∃hd,tl.st_frms … st' = return (cons ? hd tl) ∧
892                \snd hd = pc_block (pc … st))
893    [ #st * #frms #is #b #regs #m * whd in match ertlptr_save_frame;
894      normalize nodelta [ >m_return_bind | #H @('bind_inversion H) -H #st'' #EQst'']
895      #H @('bind_inversion H) -H #frames #H lapply(opt_eq_from_res ???? H) -H
896      #EQframes whd in ⊢ (??%% → ?); whd in match set_frms; whd in match set_regs;
897      normalize nodelta #EQ destruct(EQ) %{(〈\fst (regs ERTLptr_semantics ?),pc_block (pc … st)〉)}
898      [2,4: %{frames} % [1,3: %] |1,3:] %]
899    ] #save_frame_non_empty cases(save_frame_non_empty … EQst_no_pc_after_call)
900    * #fst_hd #snd_hd * #rest * #EQrest #EQhd
901  ]
902cases(b_graph_transform_program_fetch_internal_function … good c_bl' f1 fn1 ?)
903[2,4: whd in match fetch_internal_function; normalize nodelta >EQfn1 %]
904#init * #t_fn1 ** #EQt_fn1 #_ * #_ #_ #_ #EQentry #_ #_ #_ #_ #_ #_ #_
905[ %{(mk_state_pc ? st_no_pc_after_call
906        (pc_of_point
907            (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
908             c_bl' (joint_if_entry … t_fn1))
909        (last_pop … st2))}
910|
911%{(mk_state_pc ? (set_frms ERTL_state (〈(add ?? (fst_hd) r (\snd pairpc)),snd_hd〉
912                                 :: rest)
913                          st_no_pc_after_call)
914        (pc_of_point
915            (mk_prog_params ERTLptr_semantics (ertl_to_ertlptr prog) stack_size)
916             c_bl' (joint_if_entry … t_fn1))
917        (last_pop … st2))}
918]
919%
920[1,3: whd in match sigma_state_pc; normalize nodelta
921      whd in match pc_of_point in ⊢ (???%); normalize nodelta
922      whd in match fetch_internal_function; normalize nodelta >EQfn1
923      >m_return_bind normalize nodelta @eq_f3
924      [1,3,6: % |2,5: >EQentry %]
925      whd in match sigma_state; normalize nodelta
926      cut(∀ a1,a2,b1,b2,c1,c2,d1,d2,e1,e2.
927                    a1=a2 → b1 = b2 → c1 = c2 → d1 = d2 → e1 = e2 →
928                      mk_state ERTL_semantics a1 b1 c1 d1 e1 =
929                      mk_state ERTL_semantics a2 b2 c2 d2 e2)
930       [1,3: #H1 #H2 #H3 #H4 #H5 #H6 #H7 #H8 #H9 #H10 #H11 #H12 #H13 #H14
931                    #H15 //] #APP @APP try %
932       whd in match set_frms; normalize nodelta >EQrest
933       whd in match sigma_frames; normalize nodelta >m_return_bind
934       >m_return_bind whd in match sigma_frames_opt; whd in match m_list_map;
935       normalize nodelta whd in match (foldr ?????) in ⊢ (???%);
936       normalize nodelta >EQhd >EQfn >m_return_bind normalize nodelta
937       whd in match (foldr ?????); normalize nodelta
938       >EQfn >m_return_bind normalize nodelta 
939       change with (sigma_frames_opt prog f_lbls f_regs ?)
940                                            in match (foldr ?????);
941       change with (sigma_frames_opt prog f_lbls f_regs ?)
942                                                         in match (foldr ?????);
943       cases(sigma_frames_opt ????) [%] #t_rest >m_return_bind >m_return_bind
944       @eq_f @eq_f2 [2: %] @eq_f2 [2: %]
945       change with (pc_block (pc … st2)) in match (pc_block ?);
946       change with (pc_block (pc … st2)) in match (pc_block ?);
947       whd in match sigma_register_env; normalize nodelta
948       >map_add >set_minus_add [%] @list_as_set_mem @in_added_registers
949       [@(point_of_pc ERTL_semantics (pc ERTLptr_semantics st2))
950       | whd in match code_has_label; whd in match code_has_point; normalize nodelta
951         >EQstmt % | >EQregisters % % ]
952|*:    whd in match fetch_statement; normalize nodelta; >EQcalling' >m_return_bind
953       [2: >point_of_pc_of_point ] >EQcall >m_return_bind normalize nodelta
954       >m_return_bind
955       [2: >EQc_bl' >m_return_bind
956       | whd in match block_of_call; normalize nodelta
957         @('bind_inversion EQst_no_pc_pre_call) #st3 #H @('bind_inversion H) -H
958         #is3 inversion(istack … st2) [2: #bv |3: #bv1 #bv2] #EQis3
959         whd in match is_push; normalize nodelta whd in ⊢ (??%% → ??%% → ?);
960         #EQ1 #EQ2 destruct(EQ1 EQ2) #H @('bind_inversion H) -H #is3
961         whd in ⊢ (??%% → ??%% → ?); #EQ1 #EQ2 destruct(EQ1 EQ2)
962         whd in match set_regs; whd in match dpl_arg_retrieve; normalize nodelta
963         change with (ps_arg_retrieve ??) in match (dpl_arg_retrieve_ ?????);
964         @('bind_inversion EQc_bl') #c_bl'' whd in match dpl_arg_retrieve; normalize nodelta
965         change with (ps_arg_retrieve ??) in match (dpl_arg_retrieve_ ?????);
966         #H @('bind_inversion H) -H #bv_ptr1 whd in match ps_arg_retrieve;
967         normalize nodelta cases (c_ptr1) in EQstmt; [#r_ptr1 | #b_ptr1] #EQstmt
968         normalize nodelta
969         [ whd in match ps_reg_retrieve; whd in match reg_retrieve; normalize nodelta
970           #H lapply(opt_eq_from_res ???? H) -H #EQbv_ptr1
971         | whd in ⊢ (??%% → ?); #EQ destruct(EQ)
972         ]
973         whd in match dph_arg_retrieve; normalize nodelta
974         change with (ps_arg_retrieve ??) in match (dph_arg_retrieve_ ?????);
975         whd in match ps_arg_retrieve; normalize nodelta cases c_ptr2 in EQstmt;
976         [1,3: #r_ptr2 |*: #b_ptr2] #EQstmt normalize nodelta
977         [1,2: whd in match ps_reg_retrieve; whd in match reg_retrieve;
978               normalize nodelta #H @('bind_inversion H) -H
979               #bv_ptr2 #H lapply(opt_eq_from_res ???? H) -H #EQbv_ptr2
980         |*:   >m_return_bind
981         ] #H @('bind_inversion H) -H #ptr #EQptr @if_elim #ptr_ok whd in ⊢ (??%% → ?);
982         #EQ destruct(EQ) #H lapply(opt_eq_from_res ???? H) -H #EQptr_code
983         [2,4: >m_return_bind
984         |*: >lookup_add_miss
985             [1,3: >EQbv_ptr1 >m_return_bind
986             |*: % #ABS destruct(ABS)
987                lapply(fresh_regs (point_of_pc ERTL_semantics (pc … st2)))
988                >EQregisters whd in ⊢ (% → ?); *** #ABS #_ #_ @ABS
989                lapply(regs_are_in_univers … (pi2 ?? fn) … EQstmt) whd in match stmt_registers;
990                whd in match get_used_registers_from_step; normalize nodelta
991                whd in ⊢ (???% → ?); * //
992             ]
993         ]
994         change with (ps_arg_retrieve ??) in match (dph_arg_retrieve_ ?????);
995         whd in match ps_arg_retrieve; normalize nodelta
996         [2,4: >m_return_bind   
997         |*: whd in match ps_reg_retrieve; whd in match reg_retrieve;
998             normalize nodelta >lookup_add_miss
999             [1,3: >EQbv_ptr2 >m_return_bind
1000             |*: % #ABS destruct(ABS)
1001                lapply(fresh_regs (point_of_pc ERTL_semantics (pc … st2)))
1002                >EQregisters whd in ⊢ (% → ?); *** #ABS #_ #_ @ABS
1003                lapply(regs_are_in_univers … (pi2 ?? fn) … EQstmt) whd in match stmt_registers;
1004                whd in match get_used_registers_from_step; normalize nodelta
1005                whd in ⊢ (???% → ?); * // #_ * //
1006             ]
1007         ]
1008         >EQptr >m_return_bind @if_elim [2,4,6,8: >ptr_ok *] #_ >m_return_bind
1009         >EQptr_code >m_return_bind
1010       ]
1011       @('bind_inversion EQt_fn1) * #f2 * #fn2 #EQfn2 normalize nodelta
1012       whd in ⊢ (??%% → ?); #EQ destruct(EQ) >EQfn2 >m_return_bind normalize nodelta
1013       [   change with (ertlptr_save_frame ? it ?) in match (save_frame ??????);
1014           cut(st2 = mk_state_pc ? st2 (pc … st2) (last_pop … st2))
1015           [ cases st2 #H1 #H2 #H3 %] #EQ <EQ -EQ >EQst_no_pc_after_call
1016           >m_return_bind
1017       |*: change with (ertlptr_save_frame PTR it ?) in match (save_frame ??????);
1018           @('bind_inversion EQst_no_pc_after_call) #st4 whd in ⊢ (??%% → ?);
1019           #EQ destruct(EQ) #H @('bind_inversion H) -H #frms4 #H
1020           lapply(opt_eq_from_res ???? H) -H #EQfrms4 whd in ⊢ (??%% → ?);
1021           #EQ destruct(EQ) whd in match ertlptr_save_frame; normalize nodelta
1022           >m_return_bind whd in EQrest : (???%); destruct(EQrest) >EQfrms4
1023           >m_return_bind
1024       ]
1025       change with (stack_size ?) in match (stack_sizes ????); >EQs_size
1026       >m_return_bind %
1027]
1028qed.
1029         
1030
1031inductive ex_Type1 (A:Type[1]) (P:A → Prop) : Prop ≝
1032    ex1_intro: ∀ x:A. P x →  ex_Type1 A P.
1033(*interpretation "exists in Type[1]" 'exists x = (ex_Type1 ? x).*)
1034
1035lemma ertl_to_ertlptr_ok:
1036∀prog.∀stack_sizes.
1037let trans_prog ≝ ertl_to_ertlptr prog in
1038   ex_Type1 … (λR.
1039   status_simulation
1040    (ERTL_status prog stack_sizes) (ERTLptr_status trans_prog stack_sizes) R).
1041#prog #stack_size
1042cases(make_b_graph_transform_program_props ERTL_semantics ERTLptr_semantics
1043          (λglobals,fn.«translate_data globals fn,(refl …)») prog)
1044#fregs * #f_lbls * #f_bl_r #good %
1045[@ERTLptrStatusSimulation assumption]
1046whd in match status_simulation; normalize nodelta
1047whd in match ERTL_status; whd in match ERTLptr_status; normalize nodelta
1048whd in ⊢ (% → % → % → % → ?); #st1 #st1' #st2
1049change with
1050  (eval_state ERTL_semantics (prog_var_names ???) ?? = ? → ?) 
1051#EQeval @('bind_inversion EQeval)
1052** #id #fn #stmt #H lapply (err_eq_from_io ????? H) -H #EQfetch
1053#_  whd in match ERTLptrStatusSimulation; normalize nodelta #EQst2 destruct
1054cases stmt in EQfetch; -stmt
1055[ * [ #cost | #called_id #args #dest| #reg #lbl | #seq] #nxt | #fin_step | *]
1056#EQfetch
1057change with (joint_classify ??) in
1058                     ⊢ (match % with [ _ ⇒ ? | _ ⇒ ? | _ ⇒ ? | _ ⇒ ? | _ ⇒ ? ]);
1059[ (*COST*) whd in match joint_classify; normalize nodelta >EQfetch normalize nodelta
1060  cases(eval_cost_ok … good … EQfetch EQeval) #st2' * #EQst2' * #taf #tafne
1061  %{st2'} %{taf} >tafne normalize nodelta % [ % [@I | assumption]]
1062  whd >EQst2' >(as_label_ok … good … st2') [%] cases daemon (* needs lemma see below!! *)
1063| (*CALL*)  whd in match joint_classify; normalize nodelta >EQfetch
1064          normalize nodelta #is_call_st1
1065          cases(eval_call_ok … good … EQfetch EQeval) #is_call_st1'
1066          * #st2_pre_call * #is_call_st2_pre_call * * #Hcall
1067          #call_rel * #taa * #st2' * #sem_rel #eval_rel
1068          %{(«st2_pre_call,is_call_st2_pre_call»)} % [ % assumption]
1069          %{st2'} %{st2'} %{taa} %{(taa_base …)} % [ % assumption]
1070          whd >sem_rel >(as_label_ok … good … st2') [%] cases daemon (*TODO*)
1071| (*COND*) whd in match joint_classify; normalize nodelta >EQfetch
1072          normalize nodelta #n_costed
1073          cases(eval_cond_ok … good … EQfetch EQeval) [2: @n_costed]
1074          #st2' * #EQst2' * #taf #tafne %{st2'} %{taf} >tafne % [% [@I|assumption]]
1075          whd >EQst2' >(as_label_ok … good … st2') [%] cases daemon (*TODO*)
1076| (*seq*) whd in match joint_classify; normalize nodelta >EQfetch
1077          normalize nodelta
1078          cases (eval_seq_no_call_ok … good … EQfetch EQeval)
1079          #st3 * #EQ destruct *  #taf #taf_spec %{st3} %{taf} 
1080          % [% //] whd >(as_label_ok … good … st3) [%]
1081          cases daemon (*needs lemma about preservation of fetch_statement *)
1082|  cases fin_step in EQfetch;
1083  [ (*GOTO*) #lbl #EQfetch  whd in match joint_classify; normalize nodelta
1084     >EQfetch normalize nodelta
1085    cases (eval_goto_ok … good  … EQfetch EQeval)
1086    #st3 * #EQ destruct * #taf #tarne %{st3} %{taf} >tarne normalize nodelta
1087    % [% //] whd >(as_label_ok … good … st3) [%]
1088    cases daemon (*needs lemma about preservation of fetch_statement *)
1089  | (*RETURN*) #EQfetch
1090     whd in match joint_classify; normalize nodelta
1091    >EQfetch  normalize nodelta
1092    cases (eval_return_ok … good … EQfetch EQeval) #is_ret
1093    * #st3 * #EQ destruct * #after_ret * #taf ** #taf_prf #EQeval' #ret_prf
1094    % [2: % [2: % [2: %{(taa_base …)} %{taf}] |*: ] |*:]
1095    % [2: whd >(as_label_ok … good … st3) [%] cases daemon (*needs lemma *)]
1096    % [2: assumption] % [2: %] % [2: assumption] % assumption
1097  | (*TAILCALL*) *
1098  ]
1099]
1100qed.
1101
1102(*
1103lemma foo :
1104 ∀P1_unser,P2_unser: unserialized_params.
1105 ∀P1_sem_unser,P2_sem_unser.
1106 let P1_sem ≝ make_sem_graph_params P1_unser P1_sem_unser in
1107 let P2_sem ≝ make_sem_graph_params P2_unser P2_sem_unser in
1108 ∀init,translate_step.
1109 ∀translate_fin_step.
1110 ∀closed_graph_translate.
1111 let translate_internal :
1112  ∀globals.
1113   joint_closed_internal_function P1_sem globals →
1114   joint_closed_internal_function P2_sem globals
1115  ≝
1116  λglobals,fun.
1117   «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals
1118    (init globals)
1119    (translate_step globals)
1120    (translate_fin_step globals)
1121    (pi1 … fun), closed_graph_translate globals fun» in
1122 ∀prog.
1123 let trans_prog ≝ transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames)) in
1124 ∀stack_size.
1125 ∀sigma_state_pc.
1126 (∀s. pc_block (pc … (sigma_state_pc s)) = pc_block … (pc … s)) →
1127 ∀st : state_pc P2_sem.
1128 ∀st' : state_pc P1_sem.
1129 ∀f.
1130 ∀fn: joint_closed_internal_function P1_sem (globals (mk_prog_params P1_sem prog stack_size)).
1131 luniverse_ok … fn →
1132 ∀stmt,nxt.
1133 ∀P : (state_pc P2_sem) → Prop.
1134 (∀pre_Instrs',last_Instrs',dst.
1135   ∃st''.∃st'''.∃st''''.
1136    repeat_eval_seq_no_pc (mk_prog_params P2_sem trans_prog stack_size)
1137     f (translate_internal ? fn) (map_eval ?? pre_Instrs' dst) st = return st''' ∧
1138    eval_seq_no_pc ? (prog_var_names … trans_prog) (ev_genv … (mk_prog_params P2_sem trans_prog stack_size))
1139                      f (translate_internal … fn) (last_Instrs' dst) st''' = return st'''' ∧
1140    st'' = (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size)
1141     st'''' (pc_of_point P2_sem (pc_block (pc … (sigma_state_pc st))) dst) (last_pop … st)) ∧
1142    P st'' (*st' = sigma_state_pc st''*) ∧
1143    let P2_prog_params ≝ mk_prog_params P2_sem trans_prog stack_size in
1144    let P2_globals ≝ globals P2_prog_params in
1145     All
1146      (joint_seq … P2_globals)
1147      (no_cost_label … P2_globals)
1148      (map_eval (code_point P2_sem) (joint_seq … P2_globals) pre_Instrs' dst)) →
1149 fetch_statement …
1150  (prog_var_names (joint_function P1_sem) ℕ prog)
1151  (ev_genv (mk_prog_params P1_sem prog stack_size))
1152  (pc … (sigma_state_pc st)) =
1153    return 〈f, fn,  sequential … (step_seq P1_sem … stmt) nxt〉 →
1154 eval_state …
1155 (prog_var_names (joint_function P1_sem) ℕ prog)
1156 (ev_genv … (mk_prog_params P1_sem prog stack_size))
1157 (sigma_state_pc st) = return st' →
1158 ∃st''. (*CSC: this needs to be linked back again st' = sigma_state_pc ? good st'' ∧*)
1159 P st'' ∧
1160 ∃taf : trace_any_any_free (joint_abstract_status (mk_prog_params P2_sem trans_prog stack_size)) st st''.
1161(if taaf_non_empty … taf then True else
1162(¬as_costed (joint_abstract_status (mk_prog_params P1_sem prog stack_size)) (sigma_state_pc st) ∨
1163 ¬as_costed (joint_abstract_status (mk_prog_params P1_sem prog stack_size)) st'))
1164 (* the length of taf is the same of the length of ??? *).
1165#P1_unser #P2_unser #P1_sem_unser #P2_sem_unser
1166letin P1_sem ≝ (make_sem_graph_params P1_unser P1_sem_unser)
1167letin P2_sem ≝ (make_sem_graph_params P2_unser P2_sem_unser)
1168#init #translate_step #translate_fin_step #closed_graph_translate.
1169letin translate_internal ≝
1170 (λglobals,fun.
1171   «b_graph_translate (mk_graph_params P1_sem) (mk_graph_params P2_sem) globals
1172    (init globals)
1173    (translate_step globals)
1174    (translate_fin_step globals)
1175    (pi1 … fun), closed_graph_translate globals fun»)
1176#prog
1177letin trans_prog ≝ (transform_program ??? prog (λvarnames. transf_fundef ?? (translate_internal varnames)))
1178#stack_size #sigma_state_pc #sigma_state_pc_ok #st #st' #f #fn #fn_universe_ok #stmt #nxt #P
1179#Hpass #EQfetch lapply(fetch_statement_inv … EQfetch) * #EQfn #EQstmt
1180cases
1181 (b_graph_translate_ok … (init …) (translate_step …) (translate_fin_step …) … fn_universe_ok)
1182#_ * #MK_fresh_labels * #MK_fresh_registers **** #_ #_ #_ #_ (*CSC: useful things thrown out here *)
1183#MULTI_FETCH_OK cases (MULTI_FETCH_OK … EQstmt)
1184#list_b_last * #fresh_registers ** #EQlist_b_last #EQfresh_registers
1185normalize nodelta * #Instrs * #fresh_registers_spec whd in ⊢ (% → ?);
1186@pair_elim #pre_Instrs #last_Instrs #EQInstrs * #dst * #Multi_fetch #STEP_in_code
1187#EQeval
1188cut((list
1189   (code_point P2_sem
1190    →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog)))) [ cases daemon (*Paolo should fix the lemma*)]
1191#pre_Instrs'
1192cut((code_point P2_sem
1193   →joint_seq P2_sem (prog_var_names (joint_function P1_sem) ℕ prog))) [ cases daemon (*Paolo should fix the lemma*)]
1194#last_Instrs'
1195cases (Hpass pre_Instrs' last_Instrs' dst (* MANY MORE HERE *))
1196#st'' * #st''' * #st'''' **** #REPEAT #EVAL_NO_PC_Last #EQst'' #EQst' #NO_COSTED
1197lapply(produce_trace_any_any_free … NO_COSTED … REPEAT)
1198[ cases daemon (* should be @Multi_fetch *)
1199| <sigma_state_pc_ok @(fetch_internal_function_transf … (λvars.translate_internal vars))
1200  assumption
1201| @dst
1202| @list_b_last (*wrong, should dst be destination or the last of list_b_last *)
1203] #TAAF
1204lapply
1205  (produce_step_trace (mk_prog_params P2_sem trans_prog stack_size)
1206    (mk_state_pc (mk_prog_params P2_sem trans_prog stack_size)
1207       st''' (pc_of_point P2_sem (pc_block (pc … st)) dst) (last_pop … st))
1208    f (translate_internal ? fn) (last_Instrs' dst) nxt st'''' … EVAL_NO_PC_Last)
1209[ cases daemon (* should be @STEP_In_code *)
1210| <sigma_state_pc_ok
1211  @(fetch_internal_function_transf … (λvars. translate_internal vars) … EQfn) ]
1212#LAST_STEP
1213cases daemon
1214qed.
1215
1216lemma eval_seq_no_call_ok :
1217 ∀prog.
1218 let trans_prog ≝ ertl_to_ertlptr prog in
1219 ∀good : (∀fn.good_state_transformation prog fn).     
1220 ∀stack_sizes.
1221 (*? →*)
1222 ∀st : state_pc ERTLptr_semantics.
1223 ∀st' : state_pc ERTL_semantics.
1224 ∀f,fn,stmt,nxt.
1225   fetch_statement ERTL_semantics
1226     (prog_var_names (joint_function ERTL_semantics) ℕ prog)
1227    (ev_genv (mk_prog_params ERTL_semantics prog stack_sizes))
1228    (pc … (sigma_state_pc ? good st)) =
1229      return 〈f, fn,  sequential … (step_seq ERTL … stmt) nxt〉 →
1230   eval_state ERTL_semantics
1231   (prog_var_names (joint_function ERTL_semantics) ℕ prog)
1232   (ev_genv … (mk_prog_params ERTL_semantics prog stack_sizes))
1233   (sigma_state_pc ? good st) =
1234    return st' →
1235 ∃st''. st' = sigma_state_pc ? good st'' ∧
1236 ∃taf : trace_any_any_free (ERTLptr_status trans_prog stack_sizes)
1237  st
1238  st''.
1239 bool_to_Prop (taaf_non_empty … taf).
1240#prog #good #stack_size #st #st' #f #fn #stmt #nxt #EQfetch #EQeval
1241cases (foo … translate_step translate_fin_step … EQfetch EQeval)
1242[2,3: cases daemon (* first one, take out init definition from ERTLtoERTLptr;
1243                      second one to be taken from somewhere *)
1244|4: #x cases daemon (* TO BE DONE, EASY *)
1245|5: cases daemon (* to be taken in input *)
1246|6: @(λst''.st' = sigma_state_pc ? good st'')
1247|7: cases daemon
1248| #st'' * #EQ destruct * change with ERTL_uns in match (mk_unserialized_params ???????????????);
1249  change with ERTLptr_uns in match (mk_unserialized_params ???????????????);
1250  (* change with ERTL_semantics in match (make_sem_graph_params ??);
1251  change with ERTLptr_semantics in match (make_sem_graph_params ??); *)
1252#taaf #Htaaf %{st''}
1253 % [%] cases daemon
1254 qed. *)
Note: See TracBrowser for help on using the repository browser.