Initial revision

From-SVN: r47
This commit is contained in:
Tom Wood 1991-10-24 17:21:48 +00:00
parent 4217c4568b
commit 41299f4171
5 changed files with 4579 additions and 0 deletions

251
gcc/genattr.c Normal file
View File

@ -0,0 +1,251 @@
/* Generate attribute information (insn-attr.h) from machine description.
Copyright (C) 1989 Free Software Foundation, Inc.
Contributed by Richard Kenner (kenner@nyu.edu)
This file is part of GNU CC.
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.
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.
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. */
#include <stdio.h>
#include "config.h"
#include "rtl.h"
#include "obstack.h"
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
extern void free ();
extern int atoi ();
char *xmalloc ();
static void fatal ();
void fancy_abort ();
static void
write_upcase (str)
char *str;
{
for (; *str; str++)
if (*str >= 'a' && *str <= 'z')
printf ("%c", *str - 'a' + 'A');
else
printf ("%c", *str);
}
static void
gen_attr (attr)
rtx attr;
{
char *p;
printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
/* If numeric attribute, don't need to write an enum. */
if (*XSTR (attr, 1) == '\0')
printf ("extern int get_attr_%s ();\n", XSTR (attr, 0));
else
{
printf ("enum attr_%s {", XSTR (attr, 0));
write_upcase (XSTR (attr, 0));
printf ("_");
for (p = XSTR (attr, 1); *p != '\0'; p++)
{
if (*p == ',')
{
printf (", ");
write_upcase (XSTR (attr, 0));
printf ("_");
}
else if (*p >= 'a' && *p <= 'z')
printf ("%c", *p - 'a' + 'A');
else
printf ("%c", *p);
}
printf ("};\n");
printf ("extern enum attr_%s get_attr_%s ();\n\n",
XSTR (attr, 0), XSTR (attr, 0));
}
/* If `length' attribute, write additional function definitions and define
variables used by `insn_current_length'. */
if (! strcmp (XSTR (attr, 0), "length"))
{
printf ("extern void init_lengths ();\n");
printf ("extern void shorten_branches ();\n");
printf ("extern int insn_default_length ();\n");
printf ("extern int insn_variable_length_p ();\n");
printf ("extern int insn_current_length ();\n\n");
printf ("extern int *insn_addresses;\n");
printf ("extern int insn_current_address;\n\n");
}
}
static void
write_units ()
{
printf ("#define INSN_SCHEDULING\n\n");
printf ("extern int result_ready_cost ();\n");
printf ("extern int function_units_used ();\n\n");
printf ("extern struct function_unit_desc\n");
printf ("{\n");
printf (" char *name;\n");
printf (" int bitmask;\n");
printf (" int multiplicity;\n");
printf (" int simultaneity;\n");
printf (" int default_cost;\n");
printf (" int (*ready_cost_function) ();\n");
printf (" int (*conflict_cost_function) ();\n");
printf ("} function_units[];\n\n");
}
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, "genattr: ");
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.");
}
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
extern rtx read_rtx ();
register int c;
int have_delay = 0;
int have_annul_true = 0;
int have_annul_false = 0;
int have_units = 0;
int i;
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
exit (FATAL_EXIT_CODE);
}
init_rtl ();
printf ("/* Generated automatically by the program `genattr'\n\
from the machine description file `md'. */\n\n");
/* For compatibility, define the attribute `alternative', which is just
a reference to the variable `which_alternative'. */
printf ("#define HAVE_ATTR_alternative\n");
printf ("#define get_attr_alternative(insn) which_alternative\n");
/* Read the machine description. */
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_ATTR)
gen_attr (desc);
else if (GET_CODE (desc) == DEFINE_DELAY)
{
if (! have_delay)
{
printf ("#define DELAY_SLOTS\n");
printf ("extern int num_delay_slots ();\n");
printf ("extern int eligible_for_delay ();\n\n");
have_delay = 1;
}
for (i = 0; i < XVECLEN (desc, 1); i += 3)
{
if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
{
printf ("#define ANNUL_IFTRUE_SLOTS\n");
printf ("extern int eligible_for_annul_true ();\n");
have_annul_true = 1;
}
if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
{
printf ("#define ANNUL_IFFALSE_SLOTS\n");
printf ("extern int eligible_for_annul_false ();\n");
have_annul_false = 1;
}
}
}
else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT && ! have_units)
{
have_units = 1;
write_units ();
}
}
fflush (stdout);
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
/* NOTREACHED */
return 0;
}

3604
gcc/genattrtab.c Normal file

File diff suppressed because it is too large Load Diff

159
gcc/gencodes.c Normal file
View File

@ -0,0 +1,159 @@
/* Generate from machine description:
- some macros CODE_FOR_... giving the insn_code_number value
for each of the defined standard insn names.
Copyright (C) 1987 Free Software Foundation, Inc.
This file is part of GNU CC.
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.
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.
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. */
#include <stdio.h>
#include "config.h"
#include "rtl.h"
#include "obstack.h"
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
extern void free ();
char *xmalloc ();
static void fatal ();
void fancy_abort ();
static int insn_code_number;
static void
gen_insn (insn)
rtx insn;
{
/* Don't mention instructions whose names are the null string.
They are in the machine description just to be recognized. */
if (strlen (XSTR (insn, 0)) != 0)
printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0),
insn_code_number);
}
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, "gencodes: ");
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.");
}
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
extern rtx read_rtx ();
register int c;
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
exit (FATAL_EXIT_CODE);
}
init_rtl ();
printf ("/* Generated automatically by the program `gencodes'\n\
from the machine description file `md'. */\n\n");
printf ("#ifndef MAX_INSN_CODE\n\n");
/* Read the machine description. */
insn_code_number = 0;
printf ("enum insn_code {\n");
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
{
gen_insn (desc);
insn_code_number++;
}
if (GET_CODE (desc) == DEFINE_PEEPHOLE
|| GET_CODE (desc) == DEFINE_SPLIT)
{
insn_code_number++;
}
}
printf (" CODE_FOR_nothing };\n");
printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
printf ("#endif /* MAX_INSN_CODE */\n");
fflush (stdout);
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
/* NOTREACHED */
return 0;
}

405
gcc/genextract.c Normal file
View File

@ -0,0 +1,405 @@
/* Generate code from machine description to extract operands from insn as rtl.
Copyright (C) 1987 Free Software Foundation, Inc.
This file is part of GNU CC.
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.
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.
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. */
#include <stdio.h>
#include "config.h"
#include "rtl.h"
#include "obstack.h"
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
extern void free ();
/* Number instruction patterns handled, starting at 0 for first one. */
static int insn_code_number;
/* Number the occurrences of MATCH_DUP in each instruction,
starting at 0 for the first occurrence. */
static int dup_count;
/* Record which operand numbers have been seen in the current pattern.
This table is made longer as needed. */
static char *operand_seen;
/* Current allocated length of operand_seen. */
static int operand_seen_length;
/* Have we got any peephole patterns yet? */
static int peephole_seen;
/* While tree-walking an instruction pattern, we keep a chain
of these `struct link's to record how to get down to the
current position. In each one, POS is the operand number,
and if the operand is a vector VEC is the element number.
VEC is -1 if the operand is not a vector. */
struct link
{
struct link *next;
int pos;
int vecelt;
};
static void walk_rtx ();
static void print_path ();
char *xmalloc ();
char *xrealloc ();
static void fatal ();
void fancy_abort ();
static void
gen_insn (insn)
rtx insn;
{
register int i;
dup_count = 0;
/* No operands seen so far in this pattern. */
bzero (operand_seen, operand_seen_length);
printf (" case %d:\n", insn_code_number);
/* Walk the insn's pattern, remembering at all times the path
down to the walking point. */
if (XVECLEN (insn, 1) == 1)
walk_rtx (XVECEXP (insn, 1, 0), 0);
else
for (i = XVECLEN (insn, 1) - 1; i >= 0; i--)
{
struct link link;
link.next = 0;
link.pos = 0;
link.vecelt = i;
walk_rtx (XVECEXP (insn, 1, i), &link);
}
/* If the operand numbers used in the pattern are not consecutive,
don't leave an operand uninitialized. */
for (i = operand_seen_length - 1; i >= 0; i--)
if (operand_seen[i])
break;
for (; i >= 0; i--)
if (!operand_seen[i])
{
printf (" recog_operand[%d] = const0_rtx;\n", i);
printf (" recog_operand_loc[%d] = &junk;\n", i);
}
printf (" break;\n");
}
/* Record that we have seen an operand with number OPNO in this pattern. */
static void
mark_operand_seen (opno)
int opno;
{
if (opno >= operand_seen_length)
{
operand_seen_length *= 2;
operand_seen = (char *) xrealloc (operand_seen_length);
}
operand_seen[opno] = 1;
}
static void
walk_rtx (x, path)
rtx x;
struct link *path;
{
register RTX_CODE code;
register int i;
register int len;
register char *fmt;
struct link link;
if (x == 0)
return;
code = GET_CODE (x);
switch (code)
{
case PC:
case CC0:
case CONST_INT:
case SYMBOL_REF:
return;
case MATCH_OPERAND:
case MATCH_SCRATCH:
mark_operand_seen (XINT (x, 0));
printf (" recog_operand[%d] = *(recog_operand_loc[%d]\n = &",
XINT (x, 0), XINT (x, 0));
print_path (path);
printf (");\n");
break;
case MATCH_DUP:
case MATCH_OP_DUP:
printf (" recog_dup_loc[%d] = &", dup_count);
print_path (path);
printf (";\n");
printf (" recog_dup_num[%d] = %d;\n", dup_count, XINT (x, 0));
dup_count++;
break;
case MATCH_OPERATOR:
mark_operand_seen (XINT (x, 0));
printf (" recog_operand[%d] = *(recog_operand_loc[%d]\n = &",
XINT (x, 0), XINT (x, 0));
print_path (path);
printf (");\n");
link.next = path;
link.vecelt = -1;
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
link.pos = i;
walk_rtx (XVECEXP (x, 2, i), &link);
}
return;
case MATCH_PARALLEL:
mark_operand_seen (XINT (x, 0));
printf (" recog_operand[%d] = *(recog_operand_loc[%d]\n = &",
XINT (x, 0), XINT (x, 0));
print_path (path);
printf (");\n");
link.next = path;
link.pos = 0;
for (i = XVECLEN (x, 2) - 1; i >= 0; i--)
{
link.vecelt = i;
walk_rtx (XVECEXP (x, 2, i), &link);
}
return;
case ADDRESS:
walk_rtx (XEXP (x, 0), path);
return;
}
link.next = path;
link.vecelt = -1;
fmt = GET_RTX_FORMAT (code);
len = GET_RTX_LENGTH (code);
for (i = 0; i < len; i++)
{
link.pos = i;
if (fmt[i] == 'e' || fmt[i] == 'u')
{
walk_rtx (XEXP (x, i), &link);
}
else if (fmt[i] == 'E')
{
int j;
for (j = XVECLEN (x, i) - 1; j >= 0; j--)
{
link.vecelt = j;
walk_rtx (XVECEXP (x, i, j), &link);
}
}
}
}
/* Given a PATH, representing a path down the instruction's
pattern from the root to a certain point, output code to
evaluate to the rtx at that point. */
static void
print_path (path)
struct link *path;
{
if (path == 0)
printf ("insn");
else if (path->vecelt >= 0)
{
printf ("XVECEXP (");
print_path (path->next);
printf (", %d, %d)", path->pos, path->vecelt);
}
else
{
printf ("XEXP (");
print_path (path->next);
printf (", %d)", path->pos);
}
}
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.");
}
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
extern rtx read_rtx ();
register int c, i;
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
exit (FATAL_EXIT_CODE);
}
init_rtl ();
/* Assign sequential codes to all entries in the machine description
in parallel with the tables in insn-output.c. */
insn_code_number = 0;
operand_seen_length = 40;
operand_seen = (char *) xmalloc (40);
printf ("/* Generated automatically by the program `genextract'\n\
from the machine description file `md'. */\n\n");
printf ("#include \"config.h\"\n");
printf ("#include \"rtl.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 ("extern void fatal_insn_not_found ();\n\n");
printf ("void\ninsn_extract (insn)\n");
printf (" rtx insn;\n");
printf ("{\n");
printf (" int insn_code = INSN_CODE (insn);\n");
printf (" if (insn_code == -1) fatal_insn_not_found (insn);\n");
printf (" insn = PATTERN (insn);\n");
printf (" switch (insn_code)\n");
printf (" {\n");
/* Read the machine description. */
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_INSN)
{
gen_insn (desc);
++insn_code_number;
}
if (GET_CODE (desc) == DEFINE_PEEPHOLE)
{
printf (" case %d: goto peephole;\n", insn_code_number);
++insn_code_number;
++peephole_seen;
}
if (GET_CODE (desc) == DEFINE_EXPAND || GET_CODE (desc) == DEFINE_SPLIT)
{
printf (" case %d: break;\n", insn_code_number);
++insn_code_number;
}
}
/* This should never be reached. */
printf ("\n default:\n abort ();\n");
if (peephole_seen)
{
/* 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 (" peephole:\n");
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 (insn, 0, 0), recog_operand,\n");
printf (" sizeof (rtx) * XVECLEN (insn, 0));\n");
printf (" break;\n");
}
printf (" }\n}\n");
fflush (stdout);
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
/* NOTREACHED */
return 0;
}

160
gcc/genflags.c Normal file
View File

@ -0,0 +1,160 @@
/* Generate from machine description:
- some flags HAVE_... saying which simple standard instructions are
available for this machine.
Copyright (C) 1987 Free Software Foundation, Inc.
This file is part of GNU CC.
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.
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.
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. */
#include <stdio.h>
#include "config.h"
#include "rtl.h"
#include "obstack.h"
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
extern void free ();
char *xmalloc ();
static void fatal ();
void fancy_abort ();
static void
gen_insn (insn)
rtx insn;
{
char *p;
/* Don't mention instructions whose names are the null string.
They are in the machine description just to be recognized. */
if (strlen (XSTR (insn, 0)) == 0)
return;
printf ("#define HAVE_%s ", XSTR (insn, 0));
if (strlen (XSTR (insn, 2)) == 0)
printf ("1\n");
else
{
/* Write the macro definition, putting \'s at the end of each line,
if more than one. */
printf ("(");
for (p = XSTR (insn, 2); *p; p++)
{
if (*p == '\n')
printf (" \\\n");
else
printf ("%c", *p);
}
printf (")\n");
}
printf ("extern rtx gen_%s ();\n", XSTR (insn, 0));
}
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, "genflags: ");
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.");
}
int
main (argc, argv)
int argc;
char **argv;
{
rtx desc;
FILE *infile;
extern rtx read_rtx ();
register int c;
obstack_init (rtl_obstack);
if (argc <= 1)
fatal ("No input file name.");
infile = fopen (argv[1], "r");
if (infile == 0)
{
perror (argv[1]);
exit (FATAL_EXIT_CODE);
}
init_rtl ();
printf ("/* Generated automatically by the program `genflags'\n\
from the machine description file `md'. */\n\n");
/* Read the machine description. */
while (1)
{
c = read_skip_spaces (infile);
if (c == EOF)
break;
ungetc (c, infile);
desc = read_rtx (infile);
if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
gen_insn (desc);
}
fflush (stdout);
exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
/* NOTREACHED */
return 0;
}