Commit f22735ae by David Malcolm Committed by David Malcolm

read-rtl.c: split out read_rtx_operand from read_rtx_code

gcc/ChangeLog:
	* read-rtl.c (read_rtx_code): Rename local "i" to "idx", and use
	"c" instead when parsing characters.  Move operand parsing into...
	(read_rtx_operand): ...this new function, renaming "i" to "idx",
	and tightening the scope of various locals.

From-SVN: r240502
parent 2fd88f4f
2016-09-26 David Malcolm <dmalcolm@redhat.com>
* read-rtl.c (read_rtx_code): Rename local "i" to "idx", and use
"c" instead when parsing characters. Move operand parsing into...
(read_rtx_operand): ...this new function, renaming "i" to "idx",
and tightening the scope of various locals.
2016-09-26 LH Mouse <lh_mouse@126.com>
* config/i386/cygming.h (ASM_OUTPUT_DWARF_OFFSET): Fix typo.
......
......@@ -107,6 +107,7 @@ const char *current_iterator_name;
static void validate_const_int (const char *);
static rtx read_rtx_code (const char *);
static void read_rtx_operand (rtx, int);
static rtx read_nested_rtx (void);
static rtx read_rtx_variadic (rtx);
......@@ -1089,17 +1090,12 @@ read_rtx (const char *rtx_name, vec<rtx> *rtxen)
static rtx
read_rtx_code (const char *code_name)
{
int i;
RTX_CODE code;
struct mapping *iterator, *m;
struct mapping *iterator;
const char *format_ptr;
struct md_name name;
rtx return_rtx;
int c;
HOST_WIDE_INT tmp_wide;
char *str;
char *start, *end, *ptr;
char tmpstr[256];
/* Linked list structure for making RTXs: */
struct rtx_list
......@@ -1128,17 +1124,91 @@ read_rtx_code (const char *code_name)
/* If what follows is `: mode ', read it and
store the mode in the rtx. */
i = read_skip_spaces ();
if (i == ':')
c = read_skip_spaces ();
if (c == ':')
{
read_name (&name);
record_potential_iterator_use (&modes, return_rtx, name.string);
}
else
unread_char (i);
unread_char (c);
for (i = 0; format_ptr[i] != 0; i++)
switch (format_ptr[i])
for (int idx = 0; format_ptr[idx] != 0; idx++)
read_rtx_operand (return_rtx, idx);
if (CONST_WIDE_INT_P (return_rtx))
{
read_name (&name);
validate_const_wide_int (name.string);
{
const char *s = name.string;
int len;
int index = 0;
int gs = HOST_BITS_PER_WIDE_INT/4;
int pos;
char * buf = XALLOCAVEC (char, gs + 1);
unsigned HOST_WIDE_INT wi;
int wlen;
/* Skip the leading spaces. */
while (*s && ISSPACE (*s))
s++;
/* Skip the leading 0x. */
gcc_assert (s[0] == '0');
gcc_assert (s[1] == 'x');
s += 2;
len = strlen (s);
pos = len - gs;
wlen = (len + gs - 1) / gs; /* Number of words needed */
return_rtx = const_wide_int_alloc (wlen);
while (pos > 0)
{
#if HOST_BITS_PER_WIDE_INT == 64
sscanf (s + pos, "%16" HOST_WIDE_INT_PRINT "x", &wi);
#else
sscanf (s + pos, "%8" HOST_WIDE_INT_PRINT "x", &wi);
#endif
CWI_ELT (return_rtx, index++) = wi;
pos -= gs;
}
strncpy (buf, s, gs - pos);
buf [gs - pos] = 0;
sscanf (buf, "%" HOST_WIDE_INT_PRINT "x", &wi);
CWI_ELT (return_rtx, index++) = wi;
/* TODO: After reading, do we want to canonicalize with:
value = lookup_const_wide_int (value); ? */
}
}
c = read_skip_spaces ();
/* Syntactic sugar for AND and IOR, allowing Lisp-like
arbitrary number of arguments for them. */
if (c == '('
&& (GET_CODE (return_rtx) == AND
|| GET_CODE (return_rtx) == IOR))
return read_rtx_variadic (return_rtx);
unread_char (c);
return return_rtx;
}
/* Subroutine of read_rtx_code. Parse operand IDX within RETURN_RTX,
based on the corresponding format character within GET_RTX_FORMAT
for the GET_CODE (RETURN_RTX). */
static void
read_rtx_operand (rtx return_rtx, int idx)
{
RTX_CODE code = GET_CODE (return_rtx);
const char *format_ptr = GET_RTX_FORMAT (code);
int c;
struct md_name name;
switch (format_ptr[idx])
{
/* 0 means a field for internal use only.
Don't expect it to be present in the input. */
......@@ -1149,7 +1219,7 @@ read_rtx_code (const char *code_name)
case 'e':
case 'u':
XEXP (return_rtx, i) = read_nested_rtx ();
XEXP (return_rtx, idx) = read_nested_rtx ();
break;
case 'V':
......@@ -1159,7 +1229,7 @@ read_rtx_code (const char *code_name)
unread_char (c);
if (c == ')')
{
XVEC (return_rtx, i) = 0;
XVEC (return_rtx, idx) = 0;
break;
}
/* Now process the vector. */
......@@ -1190,9 +1260,9 @@ read_rtx_code (const char *code_name)
memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
list_counter * sizeof (rtx));
}
else if (format_ptr[i] == 'E')
else if (format_ptr[idx] == 'E')
fatal_with_file_and_line ("vector must have at least one element");
XVEC (return_rtx, i) = return_vec;
XVEC (return_rtx, idx) = return_vec;
obstack_free (&vector_stack, NULL);
/* close bracket gotten */
}
......@@ -1212,7 +1282,7 @@ read_rtx_code (const char *code_name)
/* 'S' fields are optional and should be NULL if no string
was given. Also allow normal 's' and 'T' strings to be
omitted, treating them in the same way as empty strings. */
XSTR (return_rtx, i) = (format_ptr[i] == 'S' ? NULL : "");
XSTR (return_rtx, idx) = (format_ptr[idx] == 'S' ? NULL : "");
break;
}
......@@ -1220,7 +1290,7 @@ read_rtx_code (const char *code_name)
DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
gets a star inserted as its first character, if it is
written with a brace block instead of a string constant. */
star_if_braced = (format_ptr[i] == 'T');
star_if_braced = (format_ptr[idx] == 'T');
stringbuf = read_string (star_if_braced);
......@@ -1229,7 +1299,7 @@ read_rtx_code (const char *code_name)
given name is blank. These are only for define_insn and
define_insn_and_split, to aid debugging. */
if (*stringbuf == '\0'
&& i == 0
&& idx == 0
&& (GET_CODE (return_rtx) == DEFINE_INSN
|| GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
{
......@@ -1248,6 +1318,9 @@ read_rtx_code (const char *code_name)
}
/* Find attr-names in the string. */
char *str;
char *start, *end, *ptr;
char tmpstr[256];
ptr = &tmpstr[0];
end = stringbuf;
while ((start = strchr (end, '<')) && (end = strchr (start, '>')))
......@@ -1261,7 +1334,8 @@ read_rtx_code (const char *code_name)
}
else
break;
m = (struct mapping *) htab_find (substs.attrs, &ptr);
struct mapping *m
= (struct mapping *) htab_find (substs.attrs, &ptr);
if (m != 0)
{
/* Here we should find linked subst-iter. */
......@@ -1276,13 +1350,15 @@ read_rtx_code (const char *code_name)
}
if (star_if_braced)
XTMPL (return_rtx, i) = stringbuf;
XTMPL (return_rtx, idx) = stringbuf;
else
XSTR (return_rtx, i) = stringbuf;
XSTR (return_rtx, idx) = stringbuf;
}
break;
case 'w':
{
HOST_WIDE_INT tmp_wide;
read_name (&name);
validate_const_int (name.string);
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
......@@ -1300,14 +1376,15 @@ read_rtx_code (const char *code_name)
#endif
#endif
#endif
XWINT (return_rtx, i) = tmp_wide;
XWINT (return_rtx, idx) = tmp_wide;
}
break;
case 'i':
case 'n':
/* Can be an iterator or an integer constant. */
read_name (&name);
record_potential_iterator_use (&ints, &XINT (return_rtx, i),
record_potential_iterator_use (&ints, &XINT (return_rtx, idx),
name.string);
break;
......@@ -1321,65 +1398,6 @@ read_rtx_code (const char *code_name)
default:
gcc_unreachable ();
}
if (CONST_WIDE_INT_P (return_rtx))
{
read_name (&name);
validate_const_wide_int (name.string);
{
const char *s = name.string;
int len;
int index = 0;
int gs = HOST_BITS_PER_WIDE_INT/4;
int pos;
char * buf = XALLOCAVEC (char, gs + 1);
unsigned HOST_WIDE_INT wi;
int wlen;
/* Skip the leading spaces. */
while (*s && ISSPACE (*s))
s++;
/* Skip the leading 0x. */
gcc_assert (s[0] == '0');
gcc_assert (s[1] == 'x');
s += 2;
len = strlen (s);
pos = len - gs;
wlen = (len + gs - 1) / gs; /* Number of words needed */
return_rtx = const_wide_int_alloc (wlen);
while (pos > 0)
{
#if HOST_BITS_PER_WIDE_INT == 64
sscanf (s + pos, "%16" HOST_WIDE_INT_PRINT "x", &wi);
#else
sscanf (s + pos, "%8" HOST_WIDE_INT_PRINT "x", &wi);
#endif
CWI_ELT (return_rtx, index++) = wi;
pos -= gs;
}
strncpy (buf, s, gs - pos);
buf [gs - pos] = 0;
sscanf (buf, "%" HOST_WIDE_INT_PRINT "x", &wi);
CWI_ELT (return_rtx, index++) = wi;
/* TODO: After reading, do we want to canonicalize with:
value = lookup_const_wide_int (value); ? */
}
}
c = read_skip_spaces ();
/* Syntactic sugar for AND and IOR, allowing Lisp-like
arbitrary number of arguments for them. */
if (c == '('
&& (GET_CODE (return_rtx) == AND
|| GET_CODE (return_rtx) == IOR))
return read_rtx_variadic (return_rtx);
unread_char (c);
return return_rtx;
}
/* Read a nested rtx construct from the MD file and return it. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment