2 * Copyright (C) 2012-2023 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>
24 # define MININT 0x80000000
27 # define HEX_FMT "0x%x"
29 # define MININT 0x8000000000000000
31 # define DEC_FMT "%ld"
32 # define HEX_FMT "0x%lx"
36 #define print_chr(value) fputc(value, print_stream)
37 #define print_hex(value) \
39 if (value < 0 && value != MININT) \
40 fprintf(print_stream, "-" HEX_FMT, (jit_uword_t)-value); \
42 fprintf(print_stream, HEX_FMT, (jit_uword_t)value); \
44 #define print_dec(value) fprintf(print_stream, DEC_FMT, value)
45 #define print_int(value) fprintf(print_stream, INT_FMT, value)
46 #define print_flt(value) fprintf(print_stream, "%g", value)
47 #define print_str(value) fprintf(print_stream, "%s", value)
48 #define print_ptr(value) fprintf(print_stream, "%p", value)
49 #define print_reg(value) \
51 if ((value) & jit_regno_patch) \
53 print_str(_rvs[jit_regno(value)].name); \
55 #define print_arg(value) \
59 print_dec((value)->v.w); \
67 #include "jit_names.c"
71 static FILE *print_stream;
81 print_stream = stdout;
85 _jit_print(jit_state_t *_jit)
89 if ((node = _jitc->head)) {
91 for (node = node->next; node; node = node->next) {
100 _jit_print_node(jit_state_t *_jit, jit_node_t *node)
106 if (node->code == jit_code_label ||
107 node->code == jit_code_prolog || node->code == jit_code_epilog) {
109 print_dec(node->v.w);
111 block = _jitc->blocks.ptr + node->v.w;
112 for (offset = 0; offset < _jitc->reglen; offset++) {
113 if (jit_regset_tstbit(&block->reglive, offset)) {
118 if (node->code == jit_code_prolog ||
119 node->code == jit_code_epilog) {
121 print_str(code_name[node->code]);
126 value = jit_classify(node->code) &
127 (jit_cc_a0_int|jit_cc_a0_flt|jit_cc_a0_dbl|jit_cc_a0_jmp|
128 jit_cc_a0_reg|jit_cc_a0_rlh|jit_cc_a0_arg|
129 jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a1_int|
130 jit_cc_a1_flt|jit_cc_a1_dbl|jit_cc_a1_arg|
131 jit_cc_a2_reg|jit_cc_a2_int|jit_cc_a2_flt|jit_cc_a2_dbl|jit_cc_a2_rlh);
132 if (!(node->flag & jit_flag_synth) && ((value & jit_cc_a0_jmp) ||
133 node->code == jit_code_finishr ||
134 node->code == jit_code_finishi))
138 if (node->flag & jit_flag_synth)
140 print_str(code_name[node->code]);
141 switch (node->code) {
143 print_chr(' '); print_reg(node->u.w); return;
145 print_chr(' '); print_hex(node->u.w); return;
148 if (node->flag & jit_flag_data)
149 print_flt(*(jit_float32_t *)node->u.n->u.w);
151 print_flt(node->u.f);
155 if (node->flag & jit_flag_data)
156 print_flt(*(jit_float64_t *)node->u.n->u.w);
158 print_flt(node->u.d);
162 if (!(node->flag & jit_flag_node))
163 print_ptr(node->u.p);
166 print_dec(node->u.n->v.w);
170 print_chr(' '); print_arg(node); return;
172 print_chr(' '); print_reg(node->u.w);
173 print_chr(' '); print_reg(node->v.w); return;
175 print_chr(' '); print_reg(node->u.w);
176 print_chr(' '); print_hex(node->v.w); return;
178 print_chr(' '); print_reg(node->u.w);
180 if (node->flag & jit_flag_data)
181 print_flt(*(jit_float32_t *)node->v.n->u.w);
183 print_flt(node->v.f);
186 print_chr(' '); print_reg(node->u.w);
188 if (node->flag & jit_flag_data)
189 print_flt(*(jit_float64_t *)node->v.n->u.w);
191 print_flt(node->v.d);
194 print_chr(' '); print_reg(node->u.w);
195 print_chr(' '); print_arg(node->v.n);
198 print_chr(' '); print_hex(node->u.w);
199 print_chr(' '); print_reg(node->v.w); return;
201 print_chr(' '); print_hex(node->u.w);
202 print_chr(' '); print_hex(node->v.w); return;
204 print_chr(' '); print_hex(node->u.w);
205 print_chr(' '); print_arg(node->v.n);
209 if (node->flag & jit_flag_data)
210 print_flt(*(jit_float32_t *)node->u.n->u.w);
212 print_flt(node->u.f);
213 print_chr(' '); print_arg(node->v.n);
217 if (node->flag & jit_flag_data)
218 print_flt(*(jit_float64_t *)node->u.n->u.w);
220 print_flt(node->u.d);
221 print_chr(' '); print_arg(node->v.n);
224 print_chr(' '); print_reg(node->u.w);
225 print_chr(' '); print_reg(node->v.w);
226 print_chr(' '); print_reg(node->w.w); return;
228 print_chr(' '); print_reg(node->u.w);
229 print_chr(' '); print_reg(node->v.w);
230 print_chr(' '); print_hex(node->w.w); return;
232 print_chr(' '); print_reg(node->u.w);
233 print_chr(' '); print_hex(node->v.w);
235 if (node->code == jit_code_movi_ww_d)
236 print_hex(node->w.w);
238 print_dec(node->w.w);
241 print_chr(' '); print_hex(node->u.w);
242 print_chr(' '); print_reg(node->v.w);
243 print_chr(' '); print_dec(node->w.w); return;
245 print_str(" ("); print_reg(node->u.q.l);
246 print_chr(' '); print_reg(node->u.q.h);
247 print_str(") "); print_reg(node->v.w);
248 print_chr(' '); print_reg(node->w.w); return;
250 print_str(" ("); print_reg(node->u.q.l);
251 print_chr(' '); print_reg(node->u.q.h);
252 print_str(") "); print_reg(node->v.w);
253 print_chr(' '); print_hex(node->w.w); return;
255 print_chr(' '); print_reg(node->u.w);
256 print_chr(' '); print_reg(node->v.w);
257 print_str(" ("); print_reg(node->w.q.l);
258 print_chr(' '); print_reg(node->w.q.h);
259 print_str(") "); return;
261 print_chr(' '); print_reg(node->u.w);
262 print_chr(' '); print_hex(node->v.w);
263 print_str(" ("); print_reg(node->w.q.l);
264 print_chr(' '); print_reg(node->w.q.h);
265 print_str(") "); return;
267 print_chr(' '); print_reg(node->u.w);
268 print_chr(' '); print_reg(node->v.w);
269 print_str(" ("); print_int(node->w.q.l);
270 print_chr(' '); print_int(node->w.q.h);
271 print_str(") "); return;
273 print_chr(' '); print_reg(node->u.w);
274 print_chr(' '); print_hex(node->v.w);
275 print_str(" ("); print_int(node->w.q.l);
276 print_chr(' '); print_int(node->w.q.h);
277 print_str(") "); return;
279 print_chr(' '); print_reg(node->u.w);
280 print_str(" ("); print_reg(node->v.q.l);
281 print_chr(' '); print_reg(node->v.q.h);
282 print_str(") "); print_reg(node->w.w);
285 print_chr(' '); print_reg(node->u.w);
286 print_chr(' '); print_reg(node->v.w);
288 if (node->flag & jit_flag_data)
289 print_flt(*(jit_float32_t *)node->w.n->u.w);
291 print_flt(node->w.f);
294 print_chr(' '); print_reg(node->u.w);
295 print_str(" ("); print_reg(node->v.q.l);
296 print_chr(' '); print_reg(node->v.q.h);
298 if (node->flag & jit_flag_data)
299 print_flt(*(jit_float32_t *)node->w.n->u.w);
301 print_flt(node->w.f);
304 print_chr(' '); print_reg(node->u.w);
305 print_chr(' '); print_reg(node->v.w);
307 if (node->flag & jit_flag_data)
308 print_flt(*(jit_float64_t *)node->w.n->u.w);
310 print_flt(node->w.d);
313 print_chr(' '); print_reg(node->u.w);
314 print_str(" ("); print_reg(node->v.q.l);
315 print_chr(' '); print_reg(node->v.q.h);
317 if (node->flag & jit_flag_data)
318 print_flt(*(jit_float64_t *)node->w.n->u.w);
320 print_flt(node->w.d);
323 print_chr(' '); print_hex(node->u.w);
324 print_chr(' '); print_reg(node->v.w);
325 print_chr(' '); print_reg(node->w.w); return;
328 if (!(node->flag & jit_flag_node))
329 print_ptr(node->u.p);
332 print_dec(node->u.n->v.w);
334 print_chr(' '); print_reg(node->v.w);
335 print_chr(' '); print_reg(node->w.w); return;
338 if (!(node->flag & jit_flag_node))
339 print_ptr(node->u.p);
342 print_dec(node->u.n->v.w);
344 print_chr(' '); print_reg(node->v.w);
345 print_chr(' '); print_hex(node->w.w); return;
348 if (!(node->flag & jit_flag_node))
349 print_ptr(node->u.p);
352 print_dec(node->u.n->v.w);
354 print_chr(' '); print_reg(node->v.w);
356 if (node->flag & jit_flag_data)
357 print_flt(*(jit_float32_t *)node->w.n->u.w);
359 print_flt(node->w.f);
363 if (!(node->flag & jit_flag_node))
364 print_ptr(node->u.p);
367 print_dec(node->u.n->v.w);
369 print_chr(' '); print_reg(node->v.w);
371 if (node->flag & jit_flag_data)
372 print_flt(*(jit_float64_t *)node->w.n->u.w);
374 print_flt(node->w.d);
378 if (node->v.p && _jitc->emit)
379 print_str((char *)node->v.n->u.p);
383 if (node->v.p && _jitc->emit)
384 print_str((char *)node->v.n->u.p);
385 if (node->v.p && _jitc->emit && node->w.w)
388 print_dec(node->w.w);
392 case jit_code_ellipsis:
393 case jit_code_prolog: case jit_code_epilog:
394 case jit_code_ret: case jit_code_prepare:
396 case jit_code_save: case jit_code_load:
401 case jit_cc_a0_reg|jit_cc_a0_chg:
402 case jit_cc_a0_reg|jit_cc_a0_jmp:
412 case jit_cc_a0_int|jit_cc_a0_arg:
414 case jit_cc_a0_reg|jit_cc_a1_reg:
416 case jit_cc_a0_reg|jit_cc_a1_int:
418 case jit_cc_a0_reg|jit_cc_a1_flt:
420 case jit_cc_a0_reg|jit_cc_a1_dbl:
422 case jit_cc_a0_reg|jit_cc_a1_arg:
424 case jit_cc_a0_int|jit_cc_a1_reg:
426 case jit_cc_a0_int|jit_cc_a1_int:
428 case jit_cc_a0_int|jit_cc_a1_arg:
430 case jit_cc_a0_flt|jit_cc_a1_arg:
432 case jit_cc_a0_dbl|jit_cc_a1_arg:
434 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
436 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
438 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_int:
440 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_int:
442 case jit_cc_a0_reg|jit_cc_a0_rlh|
443 jit_cc_a1_reg|jit_cc_a2_reg:
445 case jit_cc_a0_reg|jit_cc_a0_rlh|
446 jit_cc_a1_reg|jit_cc_a2_int:
448 case jit_cc_a0_reg|jit_cc_a1_reg|
449 jit_cc_a2_reg|jit_cc_a2_rlh:
451 case jit_cc_a0_reg|jit_cc_a1_int|
452 jit_cc_a2_reg|jit_cc_a2_rlh:
454 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_rlh:
456 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_rlh:
458 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
460 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
462 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
464 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
466 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
468 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
470 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl:
472 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_reg:
474 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_flt:
476 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_dbl: