source: src/ERTL/ERTLToLTL.ma @ 1163

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

even more streamlining and fixes to get things type checking

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