/* Generate code from machine description to extract operands from insn as rtl.
- Copyright (C) 1987, 1991, 1992, 1993 Free Software Foundation, Inc.
+ Copyright (C) 1987, 1991, 1992, 1993, 1997, 1998,
+ 1999, 2000 Free Software Foundation, Inc.
-This file is part of GNU CC.
+This file is part of GCC.
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+along with GCC; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
-#include <stdio.h>
#include "hconfig.h"
+#include "system.h"
#include "rtl.h"
-#include "obstack.h"
+#include "errors.h"
#include "insn-config.h"
+#include "gensupport.h"
-static struct obstack obstack;
-struct obstack *rtl_obstack = &obstack;
-
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
-extern void free ();
-extern rtx read_rtx ();
-
-/* Names for patterns. Need to allow linking with print-rtl. */
-char **insn_name_ptr;
/* This structure contains all the information needed to describe one
set of extractions methods. Each method may be used by more than
static struct extraction *extractions;
+/* Holds an array of names indexed by insn_code_number. */
+static char **insn_name_ptr = 0;
+static int insn_name_ptr_size = 0;
+
/* Number instruction patterns handled, starting at 0 for first one. */
static int insn_code_number;
static struct code_ptr *peepholes;
-static void walk_rtx ();
-static void print_path ();
-char *xmalloc ();
-char *xrealloc ();
-static void fatal ();
-static char *copystr ();
-static void mybzero ();
-void fancy_abort ();
-\f
+static void gen_insn PARAMS ((rtx));
+static void walk_rtx PARAMS ((rtx, const char *));
+static void print_path PARAMS ((const char *));
+static void record_insn_name PARAMS ((int, const char *));
+
static void
gen_insn (insn)
rtx insn;
{
- register int i;
- register struct extraction *p;
- register struct code_ptr *link;
+ int i;
+ struct extraction *p;
+ struct code_ptr *link;
op_count = 0;
dup_count = 0;
/* No operands seen so far in this pattern. */
- mybzero (oplocs, sizeof oplocs);
+ memset (oplocs, 0, sizeof oplocs);
/* Walk the insn's pattern, remembering at all times the path
down to the walking point. */
else
for (i = XVECLEN (insn, 1) - 1; i >= 0; i--)
{
- char *path = (char *) alloca (2);
+ char path[2];
path[0] = 'a' + i;
path[1] = 0;
link = (struct code_ptr *) xmalloc (sizeof (struct code_ptr));
link->insn_code = insn_code_number;
- /* See if we find something that already had this extraction method. */
+ /* See if we find something that already had this extraction method. */
for (p = extractions; p; p = p->next)
{
static void
walk_rtx (x, path)
rtx x;
- char *path;
+ const char *path;
{
- register RTX_CODE code;
- register int i;
- register int len;
- register char *fmt;
- register struct code_ptr *link;
+ RTX_CODE code;
+ int i;
+ int len;
+ const char *fmt;
int depth = strlen (path);
char *newpath;
case MATCH_OPERAND:
case MATCH_SCRATCH:
- oplocs[XINT (x, 0)] = copystr (path);
+ oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
break;
case MATCH_DUP:
- case MATCH_PAR_DUP:
- duplocs[dup_count] = copystr (path);
+ duplocs[dup_count] = xstrdup (path);
dupnums[dup_count] = XINT (x, 0);
dup_count++;
break;
+ case MATCH_PAR_DUP:
case MATCH_OP_DUP:
- duplocs[dup_count] = copystr (path);
+ duplocs[dup_count] = xstrdup (path);
dupnums[dup_count] = XINT (x, 0);
dup_count++;
- newpath = (char *) alloca (depth + 2);
+ newpath = (char *) xmalloc (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
for (i = XVECLEN (x, 1) - 1; i >= 0; i--)
{
- newpath[depth] = '0' + i;
+ newpath[depth] = (code == MATCH_OP_DUP ? '0' : 'a') + i;
walk_rtx (XVECEXP (x, 1, i), newpath);
}
+ free (newpath);
return;
case MATCH_OPERATOR:
- oplocs[XINT (x, 0)] = copystr (path);
+ oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
- newpath = (char *) alloca (depth + 2);
+ newpath = (char *) xmalloc (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
newpath[depth] = '0' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
}
+ free (newpath);
return;
case MATCH_PARALLEL:
- oplocs[XINT (x, 0)] = copystr (path);
+ oplocs[XINT (x, 0)] = xstrdup (path);
op_count = MAX (op_count, XINT (x, 0) + 1);
- newpath = (char *) alloca (depth + 2);
+ newpath = (char *) xmalloc (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
newpath[depth] = 'a' + i;
walk_rtx (XVECEXP (x, 2, i), newpath);
}
+ free (newpath);
return;
case ADDRESS:
walk_rtx (XEXP (x, 0), path);
return;
+
+ default:
+ break;
}
- newpath = (char *) alloca (depth + 2);
+ newpath = (char *) xmalloc (depth + 2);
strcpy (newpath, path);
newpath[depth + 1] = 0;
}
}
}
+ free (newpath);
}
/* Given a PATH, representing a path down the instruction's
static void
print_path (path)
- char *path;
+ const char *path;
{
- register int len = strlen (path);
- register int i;
+ int len = strlen (path);
+ int i;
+
+ if (len == 0)
+ {
+ /* Don't emit "pat", since we may try to take the address of it,
+ which isn't what is intended. */
+ printf("PATTERN (insn)");
+ return;
+ }
/* We first write out the operations (XEXP or XVECEXP) in reverse
order, then write "insn", then the indices in forward order. */
for (i = len - 1; i >=0 ; i--)
{
- if (path[i] >= 'a' && path[i] <= 'z')
+ if (ISLOWER(path[i]))
printf ("XVECEXP (");
- else if (path[i] >= '0' && path[i] <= '9')
+ else if (ISDIGIT(path[i]))
printf ("XEXP (");
else
abort ();
for (i = 0; i < len; i++)
{
- if (path[i] >= 'a' && path[i] <= 'z')
+ if (ISLOWER(path[i]))
printf (", 0, %d)", path[i] - 'a');
- else if (path[i] >= '0' && path[i] <= '9')
+ else if (ISDIGIT(path[i]))
printf (", %d)", path[i] - '0');
else
abort ();
}
}
\f
-char *
-xmalloc (size)
- unsigned size;
-{
- register char *val = (char *) malloc (size);
-
- if (val == 0)
- fatal ("virtual memory exhausted");
- return val;
-}
-
-char *
-xrealloc (ptr, size)
- char *ptr;
- unsigned size;
-{
- char *result = (char *) realloc (ptr, size);
- if (!result)
- fatal ("virtual memory exhausted");
- return result;
-}
-
-static void
-fatal (s, a1, a2)
- char *s;
-{
- fprintf (stderr, "genextract: ");
- fprintf (stderr, s, a1, a2);
- fprintf (stderr, "\n");
- exit (FATAL_EXIT_CODE);
-}
-
-/* More 'friendly' abort that prints the line and file.
- config.h can #define abort fancy_abort if you like that sort of thing. */
-
-void
-fancy_abort ()
-{
- fatal ("Internal gcc abort.");
-}
-
-static char *
-copystr (s1)
- char *s1;
-{
- register char *tem;
-
- if (s1 == 0)
- return 0;
-
- tem = (char *) xmalloc (strlen (s1) + 1);
- strcpy (tem, s1);
+extern int main PARAMS ((int, char **));
- return tem;
-}
-
-static void
-mybzero (b, length)
- register char *b;
- register unsigned length;
-{
- while (length-- > 0)
- *b++ = 0;
-}
-\f
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
- FILE *infile;
- register int c, i;
+ int i;
struct extraction *p;
struct code_ptr *link;
+ const char *name;
- obstack_init (rtl_obstack);
+ progname = "genextract";
if (argc <= 1)
- fatal ("No input file name.");
-
- infile = fopen (argv[1], "r");
- if (infile == 0)
- {
- perror (argv[1]);
- exit (FATAL_EXIT_CODE);
- }
+ fatal ("no input file name");
- init_rtl ();
+ if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
+ return (FATAL_EXIT_CODE);
/* Assign sequential codes to all entries in the machine description
in parallel with the tables in insn-output.c. */
from the machine description file `md'. */\n\n");
printf ("#include \"config.h\"\n");
- printf ("#include \"rtl.h\"\n\n");
+ printf ("#include \"system.h\"\n");
+ printf ("#include \"rtl.h\"\n");
+ printf ("#include \"insn-config.h\"\n");
+ printf ("#include \"recog.h\"\n");
+ printf ("#include \"toplev.h\"\n\n");
/* This variable exists only so it can be the "location"
of any missing operand whose numbers are skipped by a given pattern. */
- printf ("static rtx junk;\n");
-
- printf ("extern rtx recog_operand[];\n");
- printf ("extern rtx *recog_operand_loc[];\n");
- printf ("extern rtx *recog_dup_loc[];\n");
- printf ("extern char recog_dup_num[];\n");
+ printf ("static rtx junk ATTRIBUTE_UNUSED;\n");
printf ("void\ninsn_extract (insn)\n");
printf (" rtx insn;\n");
printf ("{\n");
- printf (" register rtx *ro = recog_operand;\n");
- printf (" register rtx **ro_loc = recog_operand_loc;\n");
+ printf (" rtx *ro = recog_data.operand;\n");
+ printf (" rtx **ro_loc = recog_data.operand_loc;\n");
printf (" rtx pat = PATTERN (insn);\n");
+ printf (" int i ATTRIBUTE_UNUSED;\n\n");
+ printf (" memset (ro, 0, sizeof (*ro) * MAX_RECOG_OPERANDS);\n");
+ printf (" memset (ro_loc, 0, sizeof (*ro_loc) * MAX_RECOG_OPERANDS);\n");
printf (" switch (INSN_CODE (insn))\n");
printf (" {\n");
printf (" case -1:\n");
while (1)
{
- c = read_skip_spaces (infile);
- if (c == EOF)
+ int line_no;
+
+ desc = read_md_rtx (&line_no, &insn_code_number);
+ if (desc == NULL)
break;
- ungetc (c, infile);
- desc = read_rtx (infile);
- if (GET_CODE (desc) == DEFINE_INSN)
+ if (GET_CODE (desc) == DEFINE_INSN)
{
+ record_insn_name (insn_code_number, XSTR (desc, 0));
gen_insn (desc);
- ++insn_code_number;
}
else if (GET_CODE (desc) == DEFINE_PEEPHOLE)
link->insn_code = insn_code_number;
link->next = peepholes;
peepholes = link;
- ++insn_code_number;
}
-
- else if (GET_CODE (desc) == DEFINE_EXPAND
- || GET_CODE (desc) == DEFINE_SPLIT)
- ++insn_code_number;
}
/* Write out code to handle peepholes and the insn_codes that it should
/* The vector in the insn says how many operands it has.
And all it contains are operands. In fact, the vector was
- created just for the sake of this function. */
- printf ("#if __GNUC__ > 1 && !defined (bcopy)\n");
- printf ("#define bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)\n");
- printf ("#endif\n");
- printf (" bcopy (&XVECEXP (pat, 0, 0), ro,\n");
- printf (" sizeof (rtx) * XVECLEN (pat, 0));\n");
+ created just for the sake of this function. We need to set the
+ location of the operands for sake of simplifications after
+ extraction, like eliminating subregs. */
+ printf (" for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)\n");
+ printf (" ro[i] = *(ro_loc[i] = &XVECEXP (pat, 0, i));\n");
printf (" break;\n\n");
}
for (p = extractions; p; p = p->next)
{
for (link = p->insns; link; link = link->next)
- printf (" case %d:\n", link->insn_code);
-
+ {
+ i = link->insn_code;
+ name = get_insn_name (i);
+ if (name)
+ printf (" case %d: /* %s */\n", i, name);
+ else
+ printf (" case %d:\n", i);
+ }
+
for (i = 0; i < p->op_count; i++)
{
if (p->oplocs[i] == 0)
for (i = 0; i < p->dup_count; i++)
{
- printf (" recog_dup_loc[%d] = &", i);
+ printf (" recog_data.dup_loc[%d] = &", i);
print_path (p->duplocs[i]);
printf (";\n");
- printf (" recog_dup_num[%d] = %d;\n", i, p->dupnums[i]);
+ printf (" recog_data.dup_num[%d] = %d;\n", i, p->dupnums[i]);
}
printf (" break;\n\n");
printf (" }\n}\n");
fflush (stdout);
- exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
- /* NOTREACHED */
- return 0;
+ return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
}
+
+/* Define this so we can link with print-rtl.o to get debug_rtx function. */
+const char *
+get_insn_name (code)
+ int code ATTRIBUTE_UNUSED;
+{
+ if (code < insn_name_ptr_size)
+ return insn_name_ptr[code];
+ else
+ return NULL;
+}
+
+static void
+record_insn_name (code, name)
+ int code;
+ const char *name;
+{
+ static const char *last_real_name = "insn";
+ static int last_real_code = 0;
+ char *new;
+
+ if (insn_name_ptr_size <= code)
+ {
+ int new_size;
+ new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512);
+ insn_name_ptr =
+ (char **) xrealloc (insn_name_ptr, sizeof(char *) * new_size);
+ memset (insn_name_ptr + insn_name_ptr_size, 0,
+ sizeof(char *) * (new_size - insn_name_ptr_size));
+ insn_name_ptr_size = new_size;
+ }
+
+ if (!name || name[0] == '\0')
+ {
+ new = xmalloc (strlen (last_real_name) + 10);
+ sprintf (new, "%s+%d", last_real_name, code - last_real_code);
+ }
+ else
+ {
+ last_real_name = new = xstrdup (name);
+ last_real_code = code;
+ }
+
+ insn_name_ptr[code] = new;
+}