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
26 # define HEX_FMT "0x%x"
28 # define MININT 0x8000000000000000
29 # define DEC_FMT "%ld"
30 # define HEX_FMT "0x%lx"
34 #define print_chr(value) fputc(value, print_stream)
35 #define print_hex(value) \
37 if (value < 0 && value != MININT) \
38 fprintf(print_stream, "-" HEX_FMT, (jit_uword_t)-value); \
40 fprintf(print_stream, HEX_FMT, (jit_uword_t)value); \
42 #define print_dec(value) fprintf(print_stream, DEC_FMT, value)
43 #define print_flt(value) fprintf(print_stream, "%g", value)
44 #define print_str(value) fprintf(print_stream, "%s", value)
45 #define print_ptr(value) fprintf(print_stream, "%p", value)
46 #define print_reg(value) \
48 if ((value) & jit_regno_patch) \
50 print_str(_rvs[jit_regno(value)].name); \
52 #define print_arg(value) \
56 print_dec((value)->v.w); \
64 #include "jit_names.c"
68 static FILE *print_stream;
78 print_stream = stdout;
82 _jit_print(jit_state_t *_jit)
86 if ((node = _jitc->head)) {
88 for (node = node->next; node; node = node->next) {
97 _jit_print_node(jit_state_t *_jit, jit_node_t *node)
103 if (node->code == jit_code_label ||
104 node->code == jit_code_prolog || node->code == jit_code_epilog) {
106 print_dec(node->v.w);
108 block = _jitc->blocks.ptr + node->v.w;
109 for (offset = 0; offset < _jitc->reglen; offset++) {
110 if (jit_regset_tstbit(&block->reglive, offset)) {
115 if (node->code == jit_code_prolog ||
116 node->code == jit_code_epilog) {
118 print_str(code_name[node->code]);
123 value = jit_classify(node->code) &
124 (jit_cc_a0_int|jit_cc_a0_flt|jit_cc_a0_dbl|jit_cc_a0_jmp|
125 jit_cc_a0_reg|jit_cc_a0_rlh|jit_cc_a0_arg|
126 jit_cc_a1_reg|jit_cc_a1_int|jit_cc_a1_flt|jit_cc_a1_dbl|jit_cc_a1_arg|
127 jit_cc_a2_reg|jit_cc_a2_int|jit_cc_a2_flt|jit_cc_a2_dbl|jit_cc_a2_rlh);
128 if (!(node->flag & jit_flag_synth) && ((value & jit_cc_a0_jmp) ||
129 node->code == jit_code_finishr ||
130 node->code == jit_code_finishi))
134 if (node->flag & jit_flag_synth)
136 print_str(code_name[node->code]);
137 switch (node->code) {
139 print_chr(' '); print_reg(node->u.w); return;
141 print_chr(' '); print_hex(node->u.w); return;
144 if (node->flag & jit_flag_data)
145 print_flt(*(jit_float32_t *)node->u.n->u.w);
147 print_flt(node->u.f);
151 if (node->flag & jit_flag_data)
152 print_flt(*(jit_float64_t *)node->u.n->u.w);
154 print_flt(node->u.d);
158 if (!(node->flag & jit_flag_node))
159 print_ptr(node->u.p);
162 print_dec(node->u.n->v.w);
166 print_chr(' '); print_arg(node); return;
168 print_chr(' '); print_reg(node->u.w);
169 print_chr(' '); print_reg(node->v.w); return;
171 print_chr(' '); print_reg(node->u.w);
172 print_chr(' '); print_hex(node->v.w); return;
174 print_chr(' '); print_reg(node->u.w);
176 if (node->flag & jit_flag_data)
177 print_flt(*(jit_float32_t *)node->v.n->u.w);
179 print_flt(node->v.f);
182 print_chr(' '); print_reg(node->u.w);
184 if (node->flag & jit_flag_data)
185 print_flt(*(jit_float64_t *)node->v.n->u.w);
187 print_flt(node->v.d);
190 print_chr(' '); print_reg(node->u.w);
191 print_chr(' '); print_arg(node->v.n);
194 print_chr(' '); print_hex(node->u.w);
195 print_chr(' '); print_reg(node->v.w); return;
197 print_chr(' '); print_hex(node->u.w);
198 print_chr(' '); print_hex(node->v.w); return;
200 print_chr(' '); print_hex(node->u.w);
201 print_chr(' '); print_arg(node->v.n);
205 if (node->flag & jit_flag_data)
206 print_flt(*(jit_float32_t *)node->u.n->u.w);
208 print_flt(node->u.f);
209 print_chr(' '); print_arg(node->v.n);
213 if (node->flag & jit_flag_data)
214 print_flt(*(jit_float64_t *)node->u.n->u.w);
216 print_flt(node->u.d);
217 print_chr(' '); print_arg(node->v.n);
220 print_chr(' '); print_reg(node->u.w);
221 print_chr(' '); print_reg(node->v.w);
222 print_chr(' '); print_reg(node->w.w); return;
224 print_chr(' '); print_reg(node->u.w);
225 print_chr(' '); print_reg(node->v.w);
226 print_chr(' '); print_hex(node->w.w); return;
228 print_str(" ("); print_reg(node->u.q.l);
229 print_chr(' '); print_reg(node->u.q.h);
230 print_str(") "); print_reg(node->v.w);
231 print_chr(' '); print_reg(node->w.w); return;
233 print_str(" ("); print_reg(node->u.q.l);
234 print_chr(' '); print_reg(node->u.q.h);
235 print_str(") "); print_reg(node->v.w);
236 print_chr(' '); print_hex(node->w.w); return;
238 print_chr(' '); print_reg(node->u.w);
239 print_chr(' '); print_reg(node->v.w);
240 print_str(" ("); print_reg(node->w.q.l);
241 print_chr(' '); print_reg(node->w.q.h);
242 print_str(") "); return;
244 print_chr(' '); print_reg(node->u.w);
245 print_chr(' '); print_hex(node->v.w);
246 print_str(" ("); print_reg(node->w.q.l);
247 print_chr(' '); print_reg(node->w.q.h);
248 print_str(") "); return;
250 print_chr(' '); print_reg(node->u.w);
251 print_chr(' '); print_reg(node->v.w);
253 if (node->flag & jit_flag_data)
254 print_flt(*(jit_float32_t *)node->w.n->u.w);
256 print_flt(node->w.f);
259 print_chr(' '); print_reg(node->u.w);
260 print_chr(' '); print_reg(node->v.w);
262 if (node->flag & jit_flag_data)
263 print_flt(*(jit_float64_t *)node->w.n->u.w);
265 print_flt(node->w.d);
268 print_chr(' '); print_hex(node->u.w);
269 print_chr(' '); print_reg(node->v.w);
270 print_chr(' '); print_reg(node->w.w); return;
273 if (!(node->flag & jit_flag_node))
274 print_ptr(node->u.p);
277 print_dec(node->u.n->v.w);
279 print_chr(' '); print_reg(node->v.w);
280 print_chr(' '); print_reg(node->w.w); return;
283 if (!(node->flag & jit_flag_node))
284 print_ptr(node->u.p);
287 print_dec(node->u.n->v.w);
289 print_chr(' '); print_reg(node->v.w);
290 print_chr(' '); print_hex(node->w.w); return;
293 if (!(node->flag & jit_flag_node))
294 print_ptr(node->u.p);
297 print_dec(node->u.n->v.w);
299 print_chr(' '); print_reg(node->v.w);
301 if (node->flag & jit_flag_data)
302 print_flt(*(jit_float32_t *)node->w.n->u.w);
304 print_flt(node->w.f);
308 if (!(node->flag & jit_flag_node))
309 print_ptr(node->u.p);
312 print_dec(node->u.n->v.w);
314 print_chr(' '); print_reg(node->v.w);
316 if (node->flag & jit_flag_data)
317 print_flt(*(jit_float64_t *)node->w.n->u.w);
319 print_flt(node->w.d);
323 if (node->v.p && _jitc->emit)
324 print_str((char *)node->v.n->u.p);
328 if (node->v.p && _jitc->emit)
329 print_str((char *)node->v.n->u.p);
330 if (node->v.p && _jitc->emit && node->w.w)
333 print_dec(node->w.w);
337 case jit_code_ellipsis:
338 case jit_code_prolog: case jit_code_epilog:
339 case jit_code_ret: case jit_code_prepare:
341 case jit_code_save: case jit_code_load:
346 case jit_cc_a0_reg|jit_cc_a0_chg:
347 case jit_cc_a0_reg|jit_cc_a0_jmp:
357 case jit_cc_a0_int|jit_cc_a0_arg:
359 case jit_cc_a0_reg|jit_cc_a1_reg:
361 case jit_cc_a0_reg|jit_cc_a1_int:
363 case jit_cc_a0_reg|jit_cc_a1_flt:
365 case jit_cc_a0_reg|jit_cc_a1_dbl:
367 case jit_cc_a0_reg|jit_cc_a1_arg:
369 case jit_cc_a0_int|jit_cc_a1_reg:
371 case jit_cc_a0_int|jit_cc_a1_int:
373 case jit_cc_a0_int|jit_cc_a1_arg:
375 case jit_cc_a0_flt|jit_cc_a1_arg:
377 case jit_cc_a0_dbl|jit_cc_a1_arg:
379 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
381 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
383 case jit_cc_a0_reg|jit_cc_a0_rlh|
384 jit_cc_a1_reg|jit_cc_a2_reg:
386 case jit_cc_a0_reg|jit_cc_a0_rlh|
387 jit_cc_a1_reg|jit_cc_a2_int:
389 case jit_cc_a0_reg|jit_cc_a1_reg|
390 jit_cc_a2_reg|jit_cc_a2_rlh:
392 case jit_cc_a0_reg|jit_cc_a1_int|
393 jit_cc_a2_reg|jit_cc_a2_rlh:
395 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
397 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
399 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
401 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
403 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
405 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
407 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl: