#include "config.h"
#include "system.h"
#include "rtl.h"
#include "real.h"
#include "flags.h"
#include "basic-block.h"
#ifndef DEBUG_PRINT_REG
#define DEBUG_PRINT_REG(RTX, CODE, FILE) \
fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
#endif
#ifdef DEBUG_REGISTER_NAMES
static char *reg_names[] = DEBUG_REGISTER_NAMES;
#else
static char *reg_names[] = REGISTER_NAMES;
#endif
static FILE *outfile;
static const char xspaces[] = " ";
static int sawclose = 0;
static int indent;
extern char **insn_name_ptr;
static void print_rtx PROTO ((rtx));
int flag_dump_unnumbered = 0;
int dump_for_graph;
static void
print_rtx (in_rtx)
register rtx in_rtx;
{
register int i = 0;
register int j;
register char *format_ptr;
register int is_insn;
if (sawclose)
{
fprintf (outfile, "\n%s",
(xspaces + (sizeof xspaces - 1 - indent * 2)));
sawclose = 0;
}
if (in_rtx == 0)
{
fputs ("(nil)", outfile);
sawclose = 1;
return;
}
is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
if (dump_for_graph &&
(is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
|| GET_CODE (in_rtx) == BARRIER))
{
i = 3;
indent = 0;
}
else
{
fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
if (in_rtx->in_struct)
fputs ("/s", outfile);
if (in_rtx->volatil)
fputs ("/v", outfile);
if (in_rtx->unchanging)
fputs ("/u", outfile);
if (in_rtx->integrated)
fputs ("/i", outfile);
if (in_rtx->frame_related)
fputs ("/f", outfile);
if (in_rtx->jump)
fputs ("/j", outfile);
if (in_rtx->call)
fputs ("/c", outfile);
if (GET_MODE (in_rtx) != VOIDmode)
{
if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
else
fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
}
}
format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
switch (*format_ptr++)
{
case 'S':
case 's':
if (i == 3 && GET_CODE (in_rtx) == NOTE
&& (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_BEG
|| NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_END
|| NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_BEG
|| NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_END))
{
fprintf (outfile, " %d", NOTE_BLOCK_NUMBER (in_rtx));
sawclose = 1;
break;
}
if (i == 3 && GET_CODE (in_rtx) == NOTE
&& (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_START
|| NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_END
|| NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_LIVE))
{
indent += 2;
if (!sawclose)
fprintf (outfile, " ");
print_rtx (NOTE_RANGE_INFO (in_rtx));
indent -= 2;
break;
}
if (i == 3 && GET_CODE (in_rtx) == NOTE
&& NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BASIC_BLOCK)
{
basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
fprintf (outfile, " [bb %d]", bb->index);
break;
}
if (XSTR (in_rtx, i) == 0)
fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
else
fprintf (outfile, dump_for_graph ? " (\\\"%s\\\")" : " (\"%s\")",
XSTR (in_rtx, i));
sawclose = 1;
break;
case '0':
break;
case 'e':
indent += 2;
if (!sawclose)
fprintf (outfile, " ");
print_rtx (XEXP (in_rtx, i));
indent -= 2;
break;
case 'E':
case 'V':
indent += 2;
if (sawclose)
{
fprintf (outfile, "\n%s",
(xspaces + (sizeof xspaces - 1 - indent * 2)));
sawclose = 0;
}
fputs ("[ ", outfile);
if (NULL != XVEC (in_rtx, i))
{
indent += 2;
if (XVECLEN (in_rtx, i))
sawclose = 1;
for (j = 0; j < XVECLEN (in_rtx, i); j++)
print_rtx (XVECEXP (in_rtx, i, j));
indent -= 2;
}
if (sawclose)
fprintf (outfile, "\n%s",
(xspaces + (sizeof xspaces - 1 - indent * 2)));
fputs ("] ", outfile);
sawclose = 1;
indent -= 2;
break;
case 'w':
fprintf (outfile, " ");
fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
fprintf (outfile, " [");
fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
fprintf (outfile, "]");
break;
case 'i':
{
register int value = XINT (in_rtx, i);
if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
{
fputc (' ', outfile);
DEBUG_PRINT_REG (in_rtx, 0, outfile);
}
else if (flag_dump_unnumbered
&& (is_insn || GET_CODE (in_rtx) == NOTE))
fputc ('#', outfile);
else
fprintf (outfile, " %d", value);
}
if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
&& insn_name_ptr
&& XINT (in_rtx, i) >= 0)
fprintf (outfile, " {%s}", insn_name_ptr[XINT (in_rtx, i)]);
sawclose = 0;
break;
case 'n':
if (XINT (in_rtx, i) <= 0)
fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
else
fprintf (outfile, " %d", XINT (in_rtx, i));
sawclose = 0;
break;
case 'u':
if (XEXP (in_rtx, i) != NULL)
{
if (flag_dump_unnumbered)
fputc ('#', outfile);
else
fprintf (outfile, " %d", INSN_UID (XEXP (in_rtx, i)));
}
else
fputs (" 0", outfile);
sawclose = 0;
break;
case 'b':
if (XBITMAP (in_rtx, i) == NULL)
fputs (" {null}", outfile);
else
bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
sawclose = 0;
break;
case 't':
putc (' ', outfile);
fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
break;
case '*':
fputs (" Unknown", outfile);
sawclose = 0;
break;
default:
fprintf (stderr,
"switch format wrong in rtl.print_rtx(). format was: %c.\n",
format_ptr[-1]);
abort ();
}
if (GET_CODE (in_rtx) == MEM)
fprintf (outfile, " %d", MEM_ALIAS_SET (in_rtx));
#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && LONG_DOUBLE_TYPE_SIZE == 64
if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
{
double val;
REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
fprintf (outfile, " [%.16g]", val);
}
#endif
if (GET_CODE (in_rtx) == CODE_LABEL)
fprintf (outfile, " [num uses: %d]", LABEL_NUSES (in_rtx));
if (dump_for_graph
&& (is_insn || GET_CODE (in_rtx) == NOTE
|| GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
sawclose = 0;
else
{
fputc (')', outfile);
sawclose = 1;
}
}
void
print_inline_rtx (outf, x, ind)
FILE *outf;
rtx x;
int ind;
{
int oldsaw = sawclose;
int oldindent = indent;
sawclose = 0;
indent = ind;
outfile = outf;
print_rtx (x);
sawclose = oldsaw;
indent = oldindent;
}
void
debug_rtx (x)
rtx x;
{
outfile = stderr;
print_rtx (x);
fprintf (stderr, "\n");
}
int debug_rtx_count = 0;
void
debug_rtx_list (x, n)
rtx x;
int n;
{
int i,count;
rtx insn;
count = n == 0 ? 1 : n < 0 ? -n : n;
if (n < 0)
for (i = count / 2; i > 0; i--)
{
if (PREV_INSN (x) == 0)
break;
x = PREV_INSN (x);
}
for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
debug_rtx (insn);
}
rtx
debug_rtx_find (x, uid)
rtx x;
int uid;
{
while (x != 0 && INSN_UID (x) != uid)
x = NEXT_INSN (x);
if (x != 0)
{
debug_rtx_list (x, debug_rtx_count);
return x;
}
else
{
fprintf (stderr, "insn uid %d not found\n", uid);
return 0;
}
}
void
print_rtl (outf, rtx_first)
FILE *outf;
rtx rtx_first;
{
register rtx tmp_rtx;
outfile = outf;
sawclose = 0;
if (rtx_first == 0)
fputs ("(nil)\n", outf);
else
switch (GET_CODE (rtx_first))
{
case INSN:
case JUMP_INSN:
case CALL_INSN:
case NOTE:
case CODE_LABEL:
case BARRIER:
for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
{
if (! flag_dump_unnumbered
|| GET_CODE (tmp_rtx) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx) < 0)
{
print_rtx (tmp_rtx);
fprintf (outfile, "\n");
}
}
break;
default:
print_rtx (rtx_first);
}
}
int
print_rtl_single (outf, x)
FILE *outf;
rtx x;
{
outfile = outf;
sawclose = 0;
if (! flag_dump_unnumbered
|| GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
{
print_rtx (x);
putc ('\n', outf);
return 1;
}
return 0;
}