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); return;
240 print_chr(' '); print_hex(node->u.w);
241 print_chr(' '); print_reg(node->v.w);
242 print_chr(' '); print_dec(node->w.w); return;
244 print_str(" ("); print_reg(node->u.q.l);
245 print_chr(' '); print_reg(node->u.q.h);
246 print_str(") "); print_reg(node->v.w);
247 print_chr(' '); print_reg(node->w.w); return;
249 print_str(" ("); print_reg(node->u.q.l);
250 print_chr(' '); print_reg(node->u.q.h);
251 print_str(") "); print_reg(node->v.w);
252 print_chr(' '); print_hex(node->w.w); return;
254 print_chr(' '); print_reg(node->u.w);
255 print_chr(' '); print_reg(node->v.w);
256 print_str(" ("); print_reg(node->w.q.l);
257 print_chr(' '); print_reg(node->w.q.h);
258 print_str(") "); return;
260 print_chr(' '); print_reg(node->u.w);
261 print_chr(' '); print_hex(node->v.w);
262 print_str(" ("); print_reg(node->w.q.l);
263 print_chr(' '); print_reg(node->w.q.h);
264 print_str(") "); return;
266 print_chr(' '); print_reg(node->u.w);
267 print_chr(' '); print_reg(node->v.w);
268 print_str(" ("); print_int(node->w.q.l);
269 print_chr(' '); print_int(node->w.q.h);
270 print_str(") "); return;
272 print_chr(' '); print_reg(node->u.w);
273 print_chr(' '); print_hex(node->v.w);
274 print_str(" ("); print_int(node->w.q.l);
275 print_chr(' '); print_int(node->w.q.h);
276 print_str(") "); return;
278 print_chr(' '); print_reg(node->u.w);
279 print_str(" ("); print_reg(node->v.q.l);
280 print_chr(' '); print_reg(node->v.q.h);
281 print_str(") "); print_reg(node->w.w);
284 print_chr(' '); print_reg(node->u.w);
285 print_chr(' '); print_reg(node->v.w);
287 if (node->flag & jit_flag_data)
288 print_flt(*(jit_float32_t *)node->w.n->u.w);
290 print_flt(node->w.f);
293 print_chr(' '); print_reg(node->u.w);
294 print_str(" ("); print_reg(node->v.q.l);
295 print_chr(' '); print_reg(node->v.q.h);
297 if (node->flag & jit_flag_data)
298 print_flt(*(jit_float32_t *)node->w.n->u.w);
300 print_flt(node->w.f);
303 print_chr(' '); print_reg(node->u.w);
304 print_chr(' '); print_reg(node->v.w);
306 if (node->flag & jit_flag_data)
307 print_flt(*(jit_float64_t *)node->w.n->u.w);
309 print_flt(node->w.d);
312 print_chr(' '); print_reg(node->u.w);
313 print_str(" ("); print_reg(node->v.q.l);
314 print_chr(' '); print_reg(node->v.q.h);
316 if (node->flag & jit_flag_data)
317 print_flt(*(jit_float64_t *)node->w.n->u.w);
319 print_flt(node->w.d);
322 print_chr(' '); print_hex(node->u.w);
323 print_chr(' '); print_reg(node->v.w);
324 print_chr(' '); print_reg(node->w.w); return;
327 if (!(node->flag & jit_flag_node))
328 print_ptr(node->u.p);
331 print_dec(node->u.n->v.w);
333 print_chr(' '); print_reg(node->v.w);
334 print_chr(' '); print_reg(node->w.w); return;
337 if (!(node->flag & jit_flag_node))
338 print_ptr(node->u.p);
341 print_dec(node->u.n->v.w);
343 print_chr(' '); print_reg(node->v.w);
344 print_chr(' '); print_hex(node->w.w); return;
347 if (!(node->flag & jit_flag_node))
348 print_ptr(node->u.p);
351 print_dec(node->u.n->v.w);
353 print_chr(' '); print_reg(node->v.w);
355 if (node->flag & jit_flag_data)
356 print_flt(*(jit_float32_t *)node->w.n->u.w);
358 print_flt(node->w.f);
362 if (!(node->flag & jit_flag_node))
363 print_ptr(node->u.p);
366 print_dec(node->u.n->v.w);
368 print_chr(' '); print_reg(node->v.w);
370 if (node->flag & jit_flag_data)
371 print_flt(*(jit_float64_t *)node->w.n->u.w);
373 print_flt(node->w.d);
377 if (node->v.p && _jitc->emit)
378 print_str((char *)node->v.n->u.p);
382 if (node->v.p && _jitc->emit)
383 print_str((char *)node->v.n->u.p);
384 if (node->v.p && _jitc->emit && node->w.w)
387 print_dec(node->w.w);
391 case jit_code_ellipsis:
392 case jit_code_prolog: case jit_code_epilog:
393 case jit_code_ret: case jit_code_prepare:
395 case jit_code_save: case jit_code_load:
400 case jit_cc_a0_reg|jit_cc_a0_chg:
401 case jit_cc_a0_reg|jit_cc_a0_jmp:
411 case jit_cc_a0_int|jit_cc_a0_arg:
413 case jit_cc_a0_reg|jit_cc_a1_reg:
415 case jit_cc_a0_reg|jit_cc_a1_int:
417 case jit_cc_a0_reg|jit_cc_a1_flt:
419 case jit_cc_a0_reg|jit_cc_a1_dbl:
421 case jit_cc_a0_reg|jit_cc_a1_arg:
423 case jit_cc_a0_int|jit_cc_a1_reg:
425 case jit_cc_a0_int|jit_cc_a1_int:
427 case jit_cc_a0_int|jit_cc_a1_arg:
429 case jit_cc_a0_flt|jit_cc_a1_arg:
431 case jit_cc_a0_dbl|jit_cc_a1_arg:
433 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
435 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
437 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_int:
439 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_int:
441 case jit_cc_a0_reg|jit_cc_a0_rlh|
442 jit_cc_a1_reg|jit_cc_a2_reg:
444 case jit_cc_a0_reg|jit_cc_a0_rlh|
445 jit_cc_a1_reg|jit_cc_a2_int:
447 case jit_cc_a0_reg|jit_cc_a1_reg|
448 jit_cc_a2_reg|jit_cc_a2_rlh:
450 case jit_cc_a0_reg|jit_cc_a1_int|
451 jit_cc_a2_reg|jit_cc_a2_rlh:
453 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_rlh:
455 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_rlh:
457 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
459 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
461 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
463 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
465 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
467 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
469 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl:
471 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_reg:
473 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_flt:
475 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_dbl: