source: src/joint/semantics_blocks.ma @ 2674

Last change on this file since 2674 was 2674, checked in by tranquil, 8 years ago
  • another change in block definition
  • RTLabs -> RTL and ERTL -> ERTLptr passes fixed, others stil broken
File size: 8.1 KB
Line 
1include "joint/blocks.ma".
2include "joint/Traces.ma".
3include "joint/semanticsUtils.ma".
4
5include "common/StatusSimulation.ma". (* for trace_any_any_free *)
6
7(* let rec seq_list_labels p g (b : list (joint_step p g)) on b : list label ≝
8  match b with
9  [ nil ⇒ [ ]
10  | cons hd tl ⇒ step_labels … hd @ seq_list_labels … tl
11  ].*)
12
13definition repeat_eval_seq_no_pc ≝
14  λp : evaluation_params.λcurr_id,curr_fn.
15  m_fold … (eval_seq_no_pc … (ev_genv … p) curr_id curr_fn).
16
17definition taaf_cons : ∀S : abstract_status.∀s1,s2,s3.
18  as_execute S s1 s2 →
19  as_classifier … s1 cl_other →
20  ∀taaf : trace_any_any_free S s2 s3.
21  (if taaf_non_empty … taaf then ¬as_costed … s2 else True) →
22  trace_any_any_free S s1 s3 ≝
23λS,s1,s2,s3,H,I,tl.
24match tl return λs2,s3,tl.
25  as_execute … s1 s2 →
26  if taaf_non_empty … tl then ¬as_costed … s2 else True →
27  trace_any_any_free S s1 s3
28with
29[ taaf_base s2 ⇒ λH.λ_.taaf_step … (taa_base …) H I
30| taaf_step s2 s3 s4 taa H' I' ⇒
31  λH,J.taaf_step … (taa_step … H I J taa) H' I'
32| taaf_step_jump s2 s3 s4 taa H' I' K' ⇒
33  λH,J.taaf_step_jump … (taa_step ???? H I J taa) H' I' K'
34] H.
35
36lemma taaf_cons_non_empty : ∀S,s1,s2,s3,H,I,tl,J.
37bool_to_Prop (taaf_non_empty … (taaf_cons S s1 s2 s3 H I tl J)).
38#S #s1 #s2 #s3 #H #I #tl lapply H -H cases tl
39[ #s #H * % |*: #s2 #s3 #s4 #taa #H' #I' [2: #K'] #H #J % ]
40qed.
41
42lemma produce_step_trace :
43  ∀p : evaluation_params.
44  ∀st : state_pc p.
45  ∀curr_id,curr_fn.
46  ∀s : joint_seq p (globals p).
47  ∀dst : code_point p.
48  ∀st' : state p.
49  fetch_internal_function … (ev_genv p) (pc_block (pc … st)) =
50    return 〈curr_id, curr_fn〉 →
51  let src ≝ point_of_pc p (pc … st) in
52  step_in_code … (joint_if_code … curr_fn) src s dst →
53  eval_seq_no_pc p (globals p) (ev_genv p) curr_id curr_fn s st = return st' →
54  as_execute (joint_abstract_status p) st
55    (mk_state_pc ? st' (pc_of_point p (pc_block (pc … st)) dst) (last_pop … st)) ∧
56  as_classifier (joint_abstract_status p) st cl_other.
57#p #st#curr_id #curr_fn #s #dst #st' #EQfetch * #nxt * #EQstmt_at #EQdst
58#EQeval whd in ⊢ (?%%); whd in ⊢ (?(??%?)(??%?));
59whd in match eval_statement_no_pc;
60whd in match fetch_statement; normalize nodelta >EQfetch >m_return_bind
61>m_return_bind >EQstmt_at >m_return_bind normalize nodelta
62% [2: % ]
63whd in ⊢ (??%?); normalize nodelta >EQeval whd in ⊢ (??%%);
64@eq_f whd in ⊢ (??%?); @eq_f2 [2: %]
65whd in match succ_pc; normalize nodelta @eq_f @EQdst
66qed.
67
68let rec produce_trace_any_any_free_aux
69  (p : evaluation_params)
70  (st : state_pc p)
71  curr_id curr_fn
72  (b : list (joint_seq p (globals p))) on b :
73  ∀l : list (code_point p).
74  ∀dst : code_point p.
75  ∀st' : state p.
76  fetch_internal_function … (ev_genv p) (pc_block (pc … st)) =
77    return 〈curr_id, curr_fn〉 →
78  let src ≝ point_of_pc p (pc … st) in
79  seq_list_in_code … (joint_if_code … curr_fn) src b l dst →
80  All ? (no_cost_label …) b →
81  repeat_eval_seq_no_pc p curr_id curr_fn b st = return st' →
82  Σtaaf : trace_any_any_free (joint_abstract_status p) st
83    (mk_state_pc ? st' (pc_of_point p (pc_block (pc … st)) dst) (last_pop … st)).
84  (not_empty … b ↔ bool_to_Prop (taaf_non_empty … taaf)) ≝
85  match b
86  return λb.∀l,dst.?→?→?→?→?→ Σtaaf.(not_empty ? b ↔ bool_to_Prop (taaf_non_empty … taaf))
87  with
88  [ nil ⇒
89    λl,dst,st',fd_prf,in_code,all_other,EQ1.
90    «taaf_base (joint_abstract_status p) st
91    ⌈trace_any_any_free ??? ↦ ?⌉,?»
92  | cons hd tl ⇒
93    λl.
94    match l return λx.∀dst,st'.?→?→?→?→Σtaaf.(True ↔ bool_to_Prop (taaf_non_empty … taaf)) with
95    [ nil ⇒ λdst,st',fd_prf,in_code.⊥
96    | cons _ rest ⇒ λdst.
97      let mid ≝ match rest with [ nil ⇒ dst | cons mid _ ⇒ mid ] in
98      λst',fd_prf,in_code,all_other,EQ1.
99      let mid_pc ≝ pc_of_point p (pc_block (pc … st)) mid in
100      match eval_seq_no_pc … (ev_genv p) curr_id curr_fn hd st
101      return λx.eval_seq_no_pc … (ev_genv p) curr_id curr_fn hd st = x →
102      Σtaaf : trace_any_any_free (joint_abstract_status p) st
103        (mk_state_pc ? st' (pc_of_point p (pc_block (pc … st)) dst) (last_pop … st)).
104        (True ↔ bool_to_Prop (taaf_non_empty … taaf)) with
105      [ OK st_mid ⇒ λEQ2.
106        let tr_tl ≝ produce_trace_any_any_free_aux ?
107            (mk_state_pc ? st_mid mid_pc (last_pop … st))
108            curr_id curr_fn tl rest dst ????? in
109        «taaf_cons … tr_tl ?,?»
110      | _ ⇒ λEQ2.⊥
111      ] (refl …)
112    ]
113  ].
114@hide_prf
115[1,2: [2: % [*] generalize in ⊢ (?(???? (match % with [ _ ⇒ ?])) → ?); ]
116  whd in EQ1 : (??%%);
117  cases l in in_code; whd in ⊢ (%→?); [2,4: #hd #tl * #ABS destruct ] * #_ #EQ destruct
118  >pc_of_point_of_pc cases st // #a #b #c #e >(K ?? e) normalize nodelta *
119| cases in_code #a * #b ** #ABS destruct
120|12: whd in EQ1 : (??%%); >EQ2 in EQ1; whd in ⊢ (??%?→?); #EQ1 destruct(EQ1)
121|4: cases tr_tl -tr_tl #tr_tl * #_ #H
122  @if_elim [2: #_ % ] #G lapply (H G) -H -G
123 cases tl in in_code all_other; [ #_ #_ * ]
124 #hd' #tl' * #mid' * #rest' ** #EQ * #nxt * #EQstmt_at #EQ_nxt
125 * #mid'' * #rest'' ** #EQ' * #nxt' * #EQstmt_at' #EQnxt' #_
126 normalize nodelta -mid_pc destruct
127 * #_ * #H #_ #_ % whd in ⊢ (%→?);
128 whd in ⊢ (?(??%?)→?); whd in match (as_pc_of ??);
129  >fetch_statement_eq [2: whd in match point_of_pc;
130  normalize nodelta >point_of_offset_of_point @EQstmt_at' |3: @fd_prf |*:]
131  normalize nodelta
132  >(no_label_uncosted … H) * #ABS @ABS %
133|7: % [2: #_ %] #_ @taaf_cons_non_empty
134]
135change with (! y ← ? ; repeat_eval_seq_no_pc ????? = ?) in EQ1;
136>EQ2 in EQ1; >m_return_bind
137cases in_code -in_code #mid' * #rest' ** #EQ1 #step_in cases (step_in)
138#nxt * #EQ_stmt_at #EQ_mid' #rest_in_code
139normalize nodelta
140cases all_other -all_other #hd_no_cost #tl_other
141#EQ3 destruct skip (mid_pc)
142try assumption
143[ whd whd in ⊢ (??%?);
144  >(fetch_statement_eq … fd_prf EQ_stmt_at) normalize nodelta %
145|*:
146  cases tl in rest_in_code;
147  [1,3: * #EQ4 #EQ5 destruct normalize nodelta
148  |*: #hd' #tl' * #mid'' * #rest'' ** #EQ4 #step_in' #rest_in_code'
149    destruct normalize nodelta
150  ]
151  [1,3: @(proj1 … (produce_step_trace … fd_prf … EQ2)) assumption
152  |2: %[%] @point_of_pc_of_point
153  |4: >point_of_pc_of_point %[| %[| %{rest_in_code'} %{step_in'} %]]
154  ]
155]
156qed.
157
158definition produce_trace_any_any_free :
159  ∀p : evaluation_params.
160  ∀st : state_pc p.
161  ∀curr_id,curr_fn.
162  ∀b : list (joint_seq p (globals p)).
163  ∀l : list (code_point p).
164  ∀dst : code_point p.
165  ∀st' : state p.
166  fetch_internal_function … (ev_genv p) (pc_block (pc … st)) =
167    return 〈curr_id, curr_fn〉 →
168  let src ≝ point_of_pc p (pc … st) in
169  seq_list_in_code … (joint_if_code … curr_fn) src b l dst →
170  All ? (no_cost_label …) b →
171  repeat_eval_seq_no_pc p curr_id curr_fn b st = return st' →
172  trace_any_any_free (joint_abstract_status p) st
173    (mk_state_pc ? st' (pc_of_point p (pc_block (pc … st)) dst) (last_pop … st)) ≝
174  λp,st,curr_id,curr_fn,b,l,dst,st',prf1,prf2,prf3,prf4.
175  produce_trace_any_any_free_aux p st curr_id curr_fn b l dst st' prf1 prf2 prf3 prf4.
176
177(* when a seq_list is coerced to a step_block *)
178definition produce_trace_any_any_free_coerced :
179  ∀p : evaluation_params.
180  ∀st : state_pc p.
181  ∀curr_id,curr_fn.
182  ∀b : list (joint_seq p (globals p)).
183  ∀l : list (code_point p).
184  ∀dst : code_point p.
185  ∀st' : state p.
186  fetch_internal_function … (ev_genv p) (pc_block (pc … st)) =
187    return 〈curr_id, curr_fn〉 →
188  let src ≝ point_of_pc p (pc … st) in
189  src ~❨b, l❩~> dst in joint_if_code … curr_fn →
190  All ? (no_cost_label …) b →
191  repeat_eval_seq_no_pc p curr_id curr_fn b st = return st' →
192  trace_any_any_free (joint_abstract_status p) st
193    (mk_state_pc ? st' (pc_of_point p (pc_block (pc … st)) dst) (last_pop … st)) ≝
194  λp,st,curr_id,curr_fn,b.?.
195#l #dst #st' #fd_prf #prf
196lapply (coerced_step_list_in_code … prf)
197inversion b normalize nodelta
198[ #_ #in_code #_ whd in ⊢ (??%%→?); #EQ destruct
199  cases (produce_step_trace … fd_prf … in_code (refl …))
200  #H #G
201  %2{(taa_base …)} assumption
202| #hd #tl #_ #EQ <EQ -hd -tl @produce_trace_any_any_free assumption
203]
204qed.
Note: See TracBrowser for help on using the repository browser.