source: src/ERTL/ERTLToLTL.ma @ 1160

Last change on this file since 1160 was 1160, checked in by mulligan, 9 years ago

changes to unfunctorised code in ertltoltl.ma

File size: 21.2 KB
Line 
1include "ERTL/ERTL.ma".
2include "LTL/LTL.ma".
3include "ERTL/spill.ma".
4include "ASM/Arithmetic.ma".
5
6(* XXX: change from O'Caml: former contents of ERTLToLTLI.ma *)
7
8inductive decision: Type[0] ≝
9  | decision_spill: Byte → decision
10  | decision_colour: Register → decision.
11 
12axiom lookup: register → decision.
13
14definition fresh_label ≝
15  λglobals: list ident.
16  λluniv.
17    fresh LabelTag luniv.
18
19definition add_graph ≝
20  λglobals.
21  λlabel.
22  λstmt: ltl_statement globals.
23  λgraph: ltl_statement_graph globals.
24    add LabelTag ? graph label stmt.
25
26definition generate ≝
27  λglobals: list ident.
28  λluniv.
29  λgraph: ltl_statement_graph globals.
30  λstmt: ltl_statement globals.
31  let 〈l, luniv〉 ≝ fresh_label globals luniv in
32  let graph ≝ add_graph globals l stmt graph in
33    〈l, 〈graph, luniv〉〉.
34
35definition num_locals ≝
36  λint_fun.
37    colour_locals + (ertl_if_stacksize int_fun).
38
39definition stacksize ≝
40  λint_fun.
41    colour_locals + (ertl_if_stacksize int_fun).
42
43definition adjust_off ≝
44  λint_fun.
45  λoff.
46  let 〈ignore, int_off〉 ≝ half_add ? int_size off in
47  let 〈sub, ignore〉 ≝ sub_8_with_carry (bitvector_of_nat ? (num_locals int_fun)) int_off false in
48    sub.
49
50definition get_stack ≝
51  λint_fun.
52  λglobals.
53  λgraph: graph (ltl_statement (globals)).
54  λr.
55  λoff.
56  λl.
57    let off ≝ adjust_off int_fun off in
58    let luniv ≝ ertl_if_luniverse int_fun in
59    let 〈l, 〈graph, luniv〉〉 ≝ generate globals luniv graph (joint_st_sequential ? globals (joint_instr_from_acc globals r) l) in
60    let 〈l, graph〉 ≝ generate globals luniv graph (joint_st_sequential ? globals (joint_instr_load globals) l) in
61    let 〈l, graph〉 ≝ generate globals luniv graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPH) l) in
62    let 〈l, graph〉 ≝ generate globals (ertl_if_luniverse int_fun) graph (joint_st_sequential ? globals (joint_instr_op2 globals Addc RegisterSPH) l) in
63    let 〈l, graph〉 ≝ generate globals (ertl_if_luniverse int_fun) graph (joint_st_sequential ? globals (joint_instr_int globals RegisterA (zero ?)) l) in
64    let 〈l, graph〉 ≝ generate globals (ertl_if_luniverse int_fun) graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPL) l) in
65    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Add RegisterSPL) l) in
66      〈joint_st_sequential ? globals (joint_instr_int globals RegisterA off) l, graph〉.
67
68definition set_stack ≝
69  λint_fun.
70  λglobals.
71  λgraph: graph (ltl_statement (globals)).
72  λoff.
73  λr.
74  λl.
75  let off ≝ adjust_off int_fun off in
76  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_store globals) l) in
77  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals r) l) in
78  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPH) l) in
79  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Addc RegisterSPH) l) in
80  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_int globals RegisterA (zero ?)) l) in
81  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPL) l) in
82  let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Add RegisterSPL) l) in
83    〈joint_st_sequential ? globals (joint_instr_int globals RegisterA off) l, graph〉.
84
85definition write ≝
86  λint_fun.
87  λglobals.
88  λgraph: graph (ltl_statement (globals)).
89  λr: register.
90  λl: label.
91  match lookup r with
92  [ decision_spill off ⇒
93    let 〈stmt, graph〉 ≝ set_stack int_fun globals graph off RegisterSST l in
94      〈RegisterSST, generate globals graph stmt〉
95  | decision_colour hwr ⇒ 〈hwr, 〈l, graph〉〉
96  ].
97
98definition read ≝
99  λint_fun.
100  λglobals.
101  λgraph: graph (ltl_statement (globals)).
102  λr: register.
103  λstmt: Register → ltl_statement globals.
104  match lookup r with
105  [ decision_colour hwr ⇒ generate globals graph (stmt hwr)
106  | decision_spill off ⇒
107    let temphwr ≝ RegisterSST in
108    let 〈l, graph〉 ≝ generate globals graph (stmt temphwr) in
109    let 〈stmt, graph〉 ≝ get_stack int_fun globals graph temphwr off l in
110      generate globals graph stmt
111  ].
112
113definition move ≝
114  λint_fun.
115  λglobals: list ident.
116  λgraph: graph (ltl_statement globals).
117  λdest: decision.
118  λsrc: decision.
119  λl: label.
120  match dest with
121  [ decision_colour dest_hwr ⇒
122    match src with
123    [ decision_colour src_hwr ⇒
124      if eq_Register dest_hwr src_hwr then
125        〈joint_st_goto ? globals l, graph〉
126      else
127        let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals dest_hwr) l) in
128          〈joint_st_sequential ? globals (joint_instr_to_acc globals src_hwr) l, graph〉
129    | decision_spill src_off ⇒ get_stack int_fun globals graph dest_hwr src_off l
130    ]
131  | decision_spill dest_off ⇒
132    match src with
133    [ decision_colour src_hwr ⇒ set_stack int_fun globals graph dest_off src_hwr l
134    | decision_spill src_off ⇒
135      if eq_bv ? dest_off src_off then
136        〈joint_st_goto ? globals l, graph〉
137      else
138        let temp_hwr ≝ RegisterSST in
139        let 〈stmt, graph〉 ≝ set_stack int_fun globals graph dest_off temp_hwr l in
140        let 〈l, graph〉 ≝ generate globals graph stmt in
141          get_stack int_fun globals graph temp_hwr src_off l
142    ]
143  ].
144
145definition newframe ≝
146  λint_fun.
147  λglobals.
148  λgraph: graph (ltl_statement globals).
149  λl.
150  if eq_nat (stacksize int_fun) 0 then
151    〈joint_st_goto ? globals l, graph〉
152  else
153    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterSPH) l) in
154    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Sub RegisterDPH) l) in
155    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_int globals RegisterDPH (zero ?)) l) in
156    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterSPH) l) in
157    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterSPL) l) in
158    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Sub RegisterDPL) l) in
159    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_clear_carry globals) l) in
160    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_int globals RegisterDPL (bitvector_of_nat ? (stacksize int_fun))) l) in
161      〈joint_st_sequential ? globals (joint_instr_to_acc globals RegisterSPL) l, graph〉.
162
163definition delframe ≝
164  λint_fun.
165  λglobals.
166  λgraph: graph (ltl_statement globals).
167  λl.
168  if eq_nat (stacksize int_fun) 0 then
169    〈joint_st_goto ? globals l, graph〉
170  else
171    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterSPH) l) in
172    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Addc RegisterSPH) l) in
173    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_int globals RegisterA (zero ?)) l) in
174    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterSPL) l) in
175    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals Add RegisterSPL) l) in
176      〈joint_st_sequential ? globals (joint_instr_int globals RegisterA (bitvector_of_nat ? (stacksize int_fun))) l, graph〉.
177
178definition translate_statement ≝
179  λint_fun.
180  λglobals: list ident.
181  λgraph: graph (ltl_statement globals).
182  λstmt: ertl_statement.
183  match stmt with
184  [ ertl_st_skip l ⇒ 〈joint_st_goto ? globals l, graph〉
185  | ertl_st_comment s l ⇒ 〈joint_st_sequential ? globals (joint_instr_comment globals s) l, graph〉
186  | ertl_st_cost cost_lbl l ⇒ 〈joint_st_sequential ? globals (joint_instr_cost_label globals cost_lbl) l, graph〉
187  | ertl_st_get_hdw destr sourcehwr l ⇒ move int_fun globals graph (lookup destr) (decision_colour sourcehwr) l
188  | ertl_st_set_hdw desthwr srcr l ⇒ move int_fun globals graph (decision_colour desthwr) (lookup srcr) l
189  | ertl_st_hdw_to_hdw r1 r2 l ⇒
190    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals r1) l) in
191      〈joint_st_sequential ? globals (joint_instr_to_acc globals r2) l, graph〉
192  | ertl_st_new_frame l ⇒ newframe int_fun globals graph l
193  | ertl_st_del_frame l ⇒ delframe int_fun globals graph l
194  | ertl_st_frame_size r l ⇒
195    let 〈hdw, l〉 ≝ write int_fun globals graph r l in
196    let 〈l, graph〉 ≝ l in
197      〈joint_st_sequential ? globals (joint_instr_int globals hdw (bitvector_of_nat ? (stacksize int_fun))) l, graph〉
198  | ertl_st_pop r l ⇒
199    let 〈hdw, l〉 ≝ write int_fun globals graph r l in
200    let 〈l, graph〉 ≝ l in
201    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
202      〈joint_st_sequential ? globals (joint_instr_pop globals) l, graph〉
203  | ertl_st_push r l ⇒
204    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_push globals) l) in
205    let 〈l, graph〉 ≝ read int_fun globals graph r (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
206      〈joint_st_goto ? globals l, graph〉
207  | ertl_st_addr rl rh x l ⇒
208    let 〈hdw1, l〉 ≝ write int_fun globals graph rh l in
209    let 〈l, graph〉 ≝ l in
210    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw1) l) in
211    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterDPH) l) in
212    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_address globals x ?) l) in
213    let 〈hdw2, l〉 ≝ write int_fun globals graph rl l in
214    let 〈l, graph〉 ≝ l in
215    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw2) l) in
216    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterDPL) l) in
217      〈joint_st_sequential ? globals (joint_instr_address globals x ?) l, graph〉
218(*  | ertl_st_addr_h r x l ⇒
219    let 〈hdw, l〉 ≝ write int_fun globals graph r l in
220    let 〈l, graph〉 ≝ generate globals graph (ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l)) in
221    let 〈l, graph〉 ≝ generate globals graph (ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterDPH) l)) in
222      ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_address globals x ?) l)
223  | ertl_st_addr_l r x l ⇒
224    let 〈hdw, l〉 ≝ write int_fun globals graph r l in
225    let 〈l, graph〉 ≝ generate globals graph (ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l)) in
226    let 〈l, graph〉 ≝ generate globals graph (ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterDPL) l)) in
227      ltl_st_lift globals (joint_st_sequential ? globals (joint_instr_address globals x ?) l)
228*)
229  | ertl_st_int r i l ⇒
230    let 〈hdw, l〉 ≝ write int_fun globals graph r l in
231    let 〈l, graph〉 ≝ l in
232      〈joint_st_sequential ? globals (joint_instr_int globals hdw i) l, graph〉
233  | ertl_st_move r1 r2 l ⇒ move int_fun globals graph (lookup r1) (lookup r2) l
234  | ertl_st_opaccs opaccs destr1 destr2 srcr1 srcr2 l ⇒
235    let 〈hdw, l〉 ≝ write int_fun globals graph destr1 l in
236    let 〈l, graph〉 ≝ l in
237    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
238    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_opaccs globals opaccs) l) in
239    let 〈l, graph〉 ≝ read int_fun globals graph srcr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
240    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterB) l) in
241    let 〈l, graph〉 ≝ read int_fun globals graph srcr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
242    let 〈l, graph〉 ≝ generate globals graph (joint_st_goto ? globals l) in
243    let 〈hdw, l〉 ≝ write int_fun globals graph destr2 l in
244    let 〈l, graph〉 ≝ l in
245    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
246    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterB) l) in
247    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_opaccs globals opaccs) l) in
248    let 〈l, graph〉 ≝ read int_fun globals graph srcr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
249    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterB) l) in
250    let 〈l, graph〉 ≝ read int_fun globals graph srcr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
251      〈joint_st_goto ? globals l, graph〉
252(*
253  | ertl_st_opaccs_a opaccs destr srcr1 srcr2 l ⇒
254    let 〈hdw, l〉 ≝ write int_fun globals graph destr l in
255    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
256    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_opaccs globals opaccs) l) in
257    let 〈l, graph〉 ≝ read int_fun globals graph srcr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
258    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterB) l) in
259    let 〈l, graph〉 ≝ read int_fun globals graph srcr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
260      joint_st_goto ? globals l
261  | ertl_st_opaccs_b opaccs destr srcr1 srcr2 l ⇒
262    let 〈hdw, l〉 ≝ write int_fun globals graph destr l in
263    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
264    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterB) l) in
265    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_opaccs globals opaccs) l) in
266    let 〈l, graph〉 ≝ read int_fun globals graph srcr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
267    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterB) l) in
268    let 〈l, graph〉 ≝ read int_fun globals graph srcr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
269      joint_st_goto ? globals l
270*)
271  | ertl_st_op1 op1 destr srcr l ⇒
272    let 〈hdw, l〉 ≝ write int_fun globals graph destr l in
273    let 〈l, graph〉 ≝ l in
274    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
275    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op1 globals op1) l) in
276    let 〈l, graph〉 ≝ read int_fun globals graph srcr (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
277      〈joint_st_goto ? globals l, graph〉
278  | ertl_st_op2 op2 destr srcr1 srcr2 l ⇒
279    let 〈hdw, l〉 ≝ write int_fun globals graph destr l in
280    let 〈l, graph〉 ≝ l in
281    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
282    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_op2 globals op2 RegisterB) l) in
283    let 〈l, graph〉 ≝ read int_fun globals graph srcr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
284    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterB) l) in
285    let 〈l, graph〉 ≝ read int_fun globals graph srcr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
286      〈joint_st_goto ? globals l, graph〉
287  | ertl_st_clear_carry l ⇒ 〈joint_st_sequential ? globals (joint_instr_clear_carry globals) l, graph〉
288  | ertl_st_set_carry l ⇒ 〈joint_st_sequential ? globals (joint_instr_set_carry globals) l, graph〉
289  | ertl_st_load destr addr1 addr2 l ⇒
290    let 〈hdw, l〉 ≝ write int_fun globals graph destr l in
291    let 〈l, graph〉 ≝ l in
292    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals hdw) l) in
293    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_load globals) l) in
294    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPH) l) in
295    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterST0) l) in
296    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPL) l) in
297    let 〈l, graph〉 ≝ read int_fun globals graph addr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
298    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterST0) l) in
299    let 〈l, graph〉 ≝ read int_fun globals graph addr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
300      〈joint_st_goto ? globals l, graph〉
301  | ertl_st_store addr1 addr2 srcr l ⇒
302    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_store globals) l) in
303    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterST1) l) in
304    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPH) l) in
305    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_to_acc globals RegisterST0) l) in
306    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterDPL) l) in
307    let 〈l, graph〉 ≝ read int_fun globals graph addr1 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
308    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterST0) l) in
309    let 〈l, graph〉 ≝ read int_fun globals graph addr2 (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
310    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_from_acc globals RegisterST1) l) in
311    let 〈l, graph〉 ≝ read int_fun globals graph srcr (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
312      〈joint_st_goto ? globals l, graph〉
313  | ertl_st_call_id f ignore l ⇒ 〈joint_st_sequential ? globals (joint_instr_call_id globals f) l, graph〉
314  | ertl_st_cond srcr lbl_true lbl_false ⇒
315    let 〈l, graph〉 ≝ generate globals graph (joint_st_sequential ? globals (joint_instr_cond_acc globals lbl_true) lbl_false) in
316    let 〈l, graph〉 ≝ read int_fun globals graph srcr (λhdw. joint_st_sequential ? globals (joint_instr_to_acc globals hdw) l) in
317      〈joint_st_goto ? globals l, graph〉
318  | ertl_st_return ⇒ 〈joint_st_return ? globals, graph〉
319  ].
320  cases daemon (* XXX: todo -- proofs regarding gvars *)
321qed.
322
323(* **** *)
324
325definition translate_internal ≝
326  λglobals: list ident.
327  λf.
328  λint_fun: ertl_internal_function.
329  let lookup ≝ λr.
330    match lookup r with
331    | colour_spill ->
332        ERTLToLTLI.Spill (Interference.Vertex.Map.find (Interference.lookup H.graph r) S.coloring)
333    | colour_colour color ->
334        ERTLToLTLI.Color color
335  in
336  let locals ≝ colour_locals + (ertl_if_stacksize int_fun) in
337  let stacksize ≝ (ertl_if_params int_fun) + locals in
338    mk_ltl_internal_function
339      globals
340      (ertl_if_luniverse int_fun)
341      (ertl_if_runiverse int_fun)
342      stacksize.
343
344  let () =
345    Label.Map.iter (fun label stmt ->
346      let stmt =
347        match Liveness.eliminable (G.liveafter label) stmt with
348        | Some successor ->
349            LTL.St_skip successor
350        | None ->
351            I.translate_statement stmt
352      in
353      graph := Label.Map.add label stmt !graph
354    ) int_fun.ERTL.f_graph
355  in
356
357definition translate_funct ≝
358  λname_def.
359  let 〈name, def〉 ≝ name_def in
360  let def' ≝
361    match def with
362    [ Internal def ⇒ Internal ? (translate_internal name def)
363    | External def ⇒ External ? def
364    ]
365  in
366    〈name, def'〉.
367
368definition translate ≝
369  λp.
370  let functs' ≝ map ? ? translate_funct (ertl_pr_functs p) in
371    mk_ltl_program (ertl_pr_globals p) functs' (ertl_pr_main p).
Note: See TracBrowser for help on using the repository browser.