2 * Copyright (C) 2012-2019 Free Software Foundation, Inc.
4 * This file is part of GNU lightning.
6 * GNU lightning is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 3, or (at your option)
11 * GNU lightning is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
17 * Paulo Cesar Pereira de Andrade
20 #include <lightning.h>
21 #include <lightning/jit_private.h>
23 #define print_chr(value) fputc(value, print_stream)
24 #define print_hex(value) fprintf(print_stream, "0x%lx", value)
25 #define print_dec(value) fprintf(print_stream, "%ld", value)
26 #define print_flt(value) fprintf(print_stream, "%g", value)
27 #define print_str(value) fprintf(print_stream, "%s", value)
28 #define print_ptr(value) fprintf(print_stream, "%p", value)
29 #define print_reg(value) \
31 if ((value) & jit_regno_patch) \
33 print_str(_rvs[jit_regno(value)].name); \
35 #define print_arg(value) \
39 print_dec((value)->v.w); \
47 #include "jit_names.c"
51 static FILE *print_stream;
61 print_stream = stdout;
65 _jit_print(jit_state_t *_jit)
69 if ((node = _jitc->head)) {
71 for (node = node->next; node; node = node->next) {
80 _jit_print_node(jit_state_t *_jit, jit_node_t *node)
86 if (node->code == jit_code_label ||
87 node->code == jit_code_prolog || node->code == jit_code_epilog) {
91 block = _jitc->blocks.ptr + node->v.w;
92 for (offset = 0; offset < _jitc->reglen; offset++) {
93 if (jit_regset_tstbit(&block->reglive, offset)) {
98 if (node->code == jit_code_prolog ||
99 node->code == jit_code_epilog) {
101 print_str(code_name[node->code]);
106 value = jit_classify(node->code) &
107 (jit_cc_a0_int|jit_cc_a0_flt|jit_cc_a0_dbl|jit_cc_a0_jmp|
108 jit_cc_a0_reg|jit_cc_a0_rlh|jit_cc_a0_arg|
109 jit_cc_a1_reg|jit_cc_a1_int|jit_cc_a1_flt|jit_cc_a1_dbl|jit_cc_a1_arg|
110 jit_cc_a2_reg|jit_cc_a2_int|jit_cc_a2_flt|jit_cc_a2_dbl|jit_cc_a2_rlh);
111 if (!(node->flag & jit_flag_synth) && ((value & jit_cc_a0_jmp) ||
112 node->code == jit_code_finishr ||
113 node->code == jit_code_finishi))
117 if (node->flag & jit_flag_synth)
119 print_str(code_name[node->code]);
120 switch (node->code) {
122 print_chr(' '); print_reg(node->u.w); return;
124 print_chr(' '); print_hex(node->u.w); return;
127 if (node->flag & jit_flag_data)
128 print_flt(*(jit_float32_t *)node->u.n->u.w);
130 print_flt(node->u.f);
134 if (node->flag & jit_flag_data)
135 print_flt(*(jit_float64_t *)node->u.n->u.w);
137 print_flt(node->u.d);
141 if (!(node->flag & jit_flag_node))
142 print_ptr(node->u.p);
145 print_dec(node->u.n->v.w);
149 print_chr(' '); print_arg(node); return;
151 print_chr(' '); print_reg(node->u.w);
152 print_chr(' '); print_reg(node->v.w); return;
154 print_chr(' '); print_reg(node->u.w);
155 print_chr(' '); print_hex(node->v.w); return;
157 print_chr(' '); print_reg(node->u.w);
159 if (node->flag & jit_flag_data)
160 print_flt(*(jit_float32_t *)node->v.n->u.w);
162 print_flt(node->v.f);
165 print_chr(' '); print_reg(node->u.w);
167 if (node->flag & jit_flag_data)
168 print_flt(*(jit_float64_t *)node->v.n->u.w);
170 print_flt(node->v.d);
173 print_chr(' '); print_reg(node->u.w);
174 print_chr(' '); print_arg(node->v.n);
177 print_chr(' '); print_hex(node->u.w);
178 print_chr(' '); print_reg(node->v.w); return;
180 print_chr(' '); print_hex(node->u.w);
181 print_chr(' '); print_hex(node->v.w); return;
183 print_chr(' '); print_hex(node->u.w);
184 print_chr(' '); print_arg(node->v.n);
188 if (node->flag & jit_flag_data)
189 print_flt(*(jit_float32_t *)node->u.n->u.w);
191 print_flt(node->u.f);
192 print_chr(' '); print_arg(node->v.n);
196 if (node->flag & jit_flag_data)
197 print_flt(*(jit_float64_t *)node->u.n->u.w);
199 print_flt(node->u.d);
200 print_chr(' '); print_arg(node->v.n);
203 print_chr(' '); print_reg(node->u.w);
204 print_chr(' '); print_reg(node->v.w);
205 print_chr(' '); print_reg(node->w.w); return;
207 print_chr(' '); print_reg(node->u.w);
208 print_chr(' '); print_reg(node->v.w);
209 print_chr(' '); print_hex(node->w.w); return;
211 print_str(" ("); print_reg(node->u.q.l);
212 print_chr(' '); print_reg(node->u.q.h);
213 print_str(") "); print_reg(node->v.w);
214 print_chr(' '); print_reg(node->w.w); return;
216 print_str(" ("); print_reg(node->u.q.l);
217 print_chr(' '); print_reg(node->u.q.h);
218 print_str(") "); print_reg(node->v.w);
219 print_chr(' '); print_hex(node->w.w); return;
221 print_chr(' '); print_reg(node->u.w);
222 print_chr(' '); print_reg(node->v.w);
223 print_str(" ("); print_reg(node->w.q.l);
224 print_chr(' '); print_reg(node->w.q.h);
225 print_str(") "); return;
227 print_chr(' '); print_reg(node->u.w);
228 print_chr(' '); print_hex(node->v.w);
229 print_str(" ("); print_reg(node->w.q.l);
230 print_chr(' '); print_reg(node->w.q.h);
231 print_str(") "); return;
233 print_chr(' '); print_reg(node->u.w);
234 print_chr(' '); print_reg(node->v.w);
236 if (node->flag & jit_flag_data)
237 print_flt(*(jit_float32_t *)node->w.n->u.w);
239 print_flt(node->w.f);
242 print_chr(' '); print_reg(node->u.w);
243 print_chr(' '); print_reg(node->v.w);
245 if (node->flag & jit_flag_data)
246 print_flt(*(jit_float64_t *)node->w.n->u.w);
248 print_flt(node->w.d);
251 print_chr(' '); print_hex(node->u.w);
252 print_chr(' '); print_reg(node->v.w);
253 print_chr(' '); print_reg(node->w.w); return;
256 if (!(node->flag & jit_flag_node))
257 print_ptr(node->u.p);
260 print_dec(node->u.n->v.w);
262 print_chr(' '); print_reg(node->v.w);
263 print_chr(' '); print_reg(node->w.w); return;
266 if (!(node->flag & jit_flag_node))
267 print_ptr(node->u.p);
270 print_dec(node->u.n->v.w);
272 print_chr(' '); print_reg(node->v.w);
273 print_chr(' '); print_hex(node->w.w); return;
276 if (!(node->flag & jit_flag_node))
277 print_ptr(node->u.p);
280 print_dec(node->u.n->v.w);
282 print_chr(' '); print_reg(node->v.w);
284 if (node->flag & jit_flag_data)
285 print_flt(*(jit_float32_t *)node->w.n->u.w);
287 print_flt(node->w.f);
291 if (!(node->flag & jit_flag_node))
292 print_ptr(node->u.p);
295 print_dec(node->u.n->v.w);
297 print_chr(' '); print_reg(node->v.w);
299 if (node->flag & jit_flag_data)
300 print_flt(*(jit_float64_t *)node->w.n->u.w);
302 print_flt(node->w.d);
306 if (node->v.p && _jitc->emit)
307 print_str(node->v.n->u.p);
311 if (node->v.p && _jitc->emit)
312 print_str(node->v.n->u.p);
313 if (node->v.p && _jitc->emit && node->w.w)
316 print_dec(node->w.w);
320 case jit_code_ellipsis:
321 case jit_code_prolog: case jit_code_epilog:
322 case jit_code_ret: case jit_code_prepare:
324 case jit_code_save: case jit_code_load:
329 case jit_cc_a0_reg|jit_cc_a0_chg:
330 case jit_cc_a0_reg|jit_cc_a0_jmp:
340 case jit_cc_a0_int|jit_cc_a0_arg:
342 case jit_cc_a0_reg|jit_cc_a1_reg:
344 case jit_cc_a0_reg|jit_cc_a1_int:
346 case jit_cc_a0_reg|jit_cc_a1_flt:
348 case jit_cc_a0_reg|jit_cc_a1_dbl:
350 case jit_cc_a0_reg|jit_cc_a1_arg:
352 case jit_cc_a0_int|jit_cc_a1_reg:
354 case jit_cc_a0_int|jit_cc_a1_int:
356 case jit_cc_a0_int|jit_cc_a1_arg:
358 case jit_cc_a0_flt|jit_cc_a1_arg:
360 case jit_cc_a0_dbl|jit_cc_a1_arg:
362 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
364 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
366 case jit_cc_a0_reg|jit_cc_a0_rlh|
367 jit_cc_a1_reg|jit_cc_a2_reg:
369 case jit_cc_a0_reg|jit_cc_a0_rlh|
370 jit_cc_a1_reg|jit_cc_a2_int:
372 case jit_cc_a0_reg|jit_cc_a1_reg|
373 jit_cc_a2_reg|jit_cc_a2_rlh:
375 case jit_cc_a0_reg|jit_cc_a1_int|
376 jit_cc_a2_reg|jit_cc_a2_rlh:
378 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
380 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
382 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
384 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
386 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
388 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
390 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl: