source: src/joint/joint_printer.ma @ 2847

Last change on this file since 2847 was 2847, checked in by sacerdot, 7 years ago

...

File size: 8.8 KB
Line 
1(**************************************************************************)
2(*       ___                                                              *)
3(*      ||M||                                                             *)
4(*      ||A||       A project by Andrea Asperti                           *)
5(*      ||T||                                                             *)
6(*      ||I||       Developers:                                           *)
7(*      ||T||         The HELM team.                                      *)
8(*      ||A||         http://helm.cs.unibo.it                             *)
9(*      \   /                                                             *)
10(*       \ /        This file is distributed under the terms of the       *)
11(*        v         GNU General Public License Version 2                  *)
12(*                                                                        *)
13(**************************************************************************)
14
15include "joint/Joint.ma".
16
17inductive keyword : Type[0] ≝
18  | kwCOMMENT: keyword
19  | kwMOVE: keyword
20  | kwPOP: keyword
21  | kwPUSH: keyword
22  | kwADDRESS: keyword
23  | kwOPACCS: keyword
24  | kwOP1: keyword
25  | kwOP2: keyword
26  | kwCLEAR_CARRY: keyword
27  | kwSET_CARRY: keyword
28  | kwLOAD: keyword
29  | kwSTORE: keyword
30  | kwCOST_LABEL: keyword
31  | kwCOND: keyword
32  | kwCALL: keyword
33  | kwGOTO: keyword
34  | kwRETURN: keyword
35  | kwTAILCALL: keyword
36  | kwFCOND: keyword.
37
38record printing_pass_independent_params (string: Type[0]) : Type[0] ≝
39 { print_String: String → string
40 ; print_keyword: keyword → string
41 ; print_concat: string → string → string
42 ; print_empty: string
43 ; print_ident: ident → string
44 ; print_costlabel: costlabel → string
45 ; print_label: label → string
46 ; print_OpAccs: OpAccs → string
47 ; print_Op1: Op1 → string
48 ; print_Op2: Op2 → string }.
49
50record printing_params (string: Type[0]) (P: unserialized_params) : Type[0] ≝
51 { print_pass_ind:> printing_pass_independent_params string
52 ; print_acc_a_reg: acc_a_reg P → string
53 ; print_acc_b_reg: acc_b_reg P → string
54 ; print_acc_a_arg: acc_a_arg P → string
55 ; print_acc_b_arg: acc_b_arg P → string
56 ; print_dpl_reg: dpl_reg P → string   (* low address registers *)
57 ; print_dph_reg: dph_reg P → string   (* high address registers *)
58 ; print_dpl_arg: dpl_arg P → string   (* low address registers *)
59 ; print_dph_arg: dph_arg P → string   (* high address registers *)
60 ; print_snd_arg : snd_arg P → string  (* second argument of binary op *)
61 ; print_pair_move: pair_move P → string (* argument of move instructions *)
62 ; print_call_args: call_args P → string (* arguments of function calls *)
63 ; print_call_dest: call_dest P → string (* possible destination of function computation *)
64 (* other instructions not fitting in the general framework *)
65 ; print_ext_seq : ext_seq P → string
66 }.
67
68record code_iteration_params (string: Type[0]) (p:params) (globals) : Type[1] ≝
69 { fold_code:
70    ∀A:Type[0].
71     (code_point p → joint_statement p globals → A → A) →
72      codeT p globals → A → A
73 ; print_succ: succ … p → string
74 }.
75
76definition graph_code_iteration_params:
77 ∀string,graph_params,globals.
78  printing_params string (graph_params_to_params graph_params) →
79   code_iteration_params string (graph_params_to_params graph_params) globals ≝
80 λstring,gp,globals,pp.
81  mk_code_iteration_params ???
82   (λA.λf:code_point (graph_params_to_params …) → ?.
83     graph_fold … (λn. f (an_identifier … n)) …) (print_label … pp).
84
85definition print_list:
86 ∀string. printing_pass_independent_params string → list string → string ≝
87 λstring,pp.
88  foldr ?? (print_concat … pp) (print_empty … pp). 
89
90definition print_joint_seq :
91 ∀p. ∀globals. ∀string. printing_params string p → joint_seq p globals → string ≝
92 λp,globals,string,pp,seq.
93  match seq with
94  [ COMMENT str ⇒
95     print_list … pp [print_keyword … pp kwCOMMENT; print_String … pp str]
96  | MOVE pm ⇒
97     print_list … pp [print_keyword … pp kwMOVE; print_pair_move … pp pm]
98  | POP arg ⇒
99     print_list … pp [print_keyword … pp kwPOP; print_acc_a_reg … pp arg]
100  | PUSH arg ⇒
101     print_list … pp [print_keyword … pp kwPUSH; print_acc_a_arg … pp arg]
102  | ADDRESS i Hi arg1 arg2 ⇒
103     print_list … pp
104      [print_keyword … pp kwADDRESS;
105       print_ident … pp i;
106       print_dpl_reg … pp arg1;
107       print_dph_reg … pp arg2]
108  | OPACCS opa arg1 arg2 arg3 arg4 ⇒
109     print_list … pp
110      [print_keyword … pp kwOPACCS;
111       print_OpAccs … pp opa;
112       print_acc_a_reg … pp arg1;
113       print_acc_b_reg … pp arg2;
114       print_acc_a_arg … pp arg3;
115       print_acc_b_arg … pp arg4]
116  | OP1 op1 arg1 arg2 ⇒
117     print_list … pp
118      [print_keyword … pp kwOP1;
119       print_Op1 … pp op1;
120       print_acc_a_reg … pp arg1;
121       print_acc_a_reg … pp arg2]
122  | OP2 op2 arg1 arg2 arg3 ⇒
123     print_list … pp
124      [print_keyword … pp kwOP2;
125       print_Op2 … pp op2;
126       print_acc_a_reg … pp arg1;
127       print_acc_a_arg … pp arg2;
128       print_snd_arg … pp arg3]
129  (* int done with generic move *)
130  | CLEAR_CARRY ⇒ print_keyword … pp kwCLEAR_CARRY
131  | SET_CARRY ⇒ print_keyword … pp kwSET_CARRY
132  | LOAD arg1 arg2 arg3 ⇒
133     print_list … pp
134      [print_keyword … pp kwLOAD;
135       print_acc_a_reg … pp arg1;
136       print_dpl_arg … pp arg2;
137       print_dph_arg … pp arg3]
138  | STORE arg1 arg2 arg3 ⇒
139     print_list … pp
140      [print_keyword … pp kwSTORE;
141       print_dpl_arg … pp arg1;
142       print_dph_arg … pp arg2;
143       print_acc_a_arg … pp arg3]
144  | extension_seq ext ⇒ print_ext_seq … pp ext].
145
146definition print_joint_step:
147 ∀p,globals. ∀string. printing_params string p → joint_step p globals → string ≝
148 λp,globals,string,pp,step.
149  match step with
150   [ COST_LABEL arg ⇒
151      print_list ? pp
152       [print_keyword … pp kwCOST_LABEL;
153        print_costlabel … pp arg]
154   | CALL arg1 arg2 arg3 ⇒
155      print_list … pp
156       [print_keyword … pp kwCALL;
157        match arg1 with
158        [ inl id ⇒ print_ident … pp id
159        | inr arg11_arg12 ⇒
160           print_concat … pp
161            (print_dpl_arg … pp (\fst arg11_arg12))
162            (print_dph_arg … pp (\snd arg11_arg12))];
163        print_call_args … pp arg2;
164        print_call_dest … pp arg3]
165   | COND arg1 arg2 ⇒
166      print_list … pp
167       [print_keyword … pp kwCOND;
168        print_acc_a_reg … pp arg1;
169        print_label … pp arg2]
170   | step_seq seq ⇒ print_joint_seq … pp seq ].
171
172definition print_joint_fin_step:
173 ∀p. ∀string. printing_params string p → joint_fin_step p → string ≝
174 λp,string,pp,fin.
175  match fin with
176   [ GOTO l ⇒
177      print_list ? pp
178       [ print_keyword … pp kwGOTO;
179         print_label … pp l]
180   | RETURN ⇒ print_keyword … pp kwRETURN
181   | TAILCALL has arg1 arg2 ⇒
182      print_list … pp
183       [print_keyword … pp kwTAILCALL;
184        match arg1 with
185        [ inl id ⇒ print_ident … pp id
186        | inr arg11_arg12 ⇒
187           print_concat … pp
188            (print_dpl_arg … pp (\fst arg11_arg12))
189            (print_dph_arg … pp (\snd arg11_arg12))];
190        print_call_args … pp arg2]].
191
192definition print_joint_statement:
193 ∀p:params.∀globals. ∀string. printing_params string p →
194  code_iteration_params string p globals → joint_statement p globals → string ≝
195 λp,globals,string,pp,cip,stmt.
196  match stmt with
197  [ sequential js arg1 ⇒
198     print_concat … pp (print_joint_step … pp js) (print_succ … cip arg1)
199  | final fin ⇒ print_joint_fin_step … pp fin
200  | FCOND has arg1 arg2 arg3 ⇒
201     print_list ? pp
202      [ print_keyword … pp kwFCOND;
203        print_acc_a_reg … pp arg1;
204        print_label … pp arg2;
205        print_label … pp arg3 ]].
206
207definition print_joint_internal_function:
208 ∀p:params. ∀globals. ∀string. code_iteration_params string p globals →
209  printing_params string p → joint_internal_function p globals → string
210≝ λp,globals,string,cip,pp,f.
211   fold_code … cip … (λcp.λstmt. print_concat … pp (print_joint_statement … pp cip stmt))
212    (joint_if_code … f) (print_empty … pp).
213
214definition print_joint_function:
215 ∀p:params. ∀globals. ∀string. code_iteration_params string p globals → printing_params string p →
216  joint_function p globals → string ≝
217 λp,globals,string,cip,pp,f.
218  match f with
219  [ Internal f ⇒ print_joint_internal_function … cip … pp f
220  | External f ⇒ print_empty … pp ].
221
222definition print_joint_program:
223 ∀p:params. ∀string.
224  printing_params string p →
225  ∀prog:joint_program p.
226   code_iteration_params string p (map … (λx. \fst (\fst x)) (prog_vars ?? prog)) → string ≝
227 λp,string,pp,prog,cip.
228  foldr ?? (λf. print_concat … pp (print_joint_function … cip … pp (\snd f)))
229   (print_empty … pp) (prog_funct … prog).
Note: See TracBrowser for help on using the repository browser.