diff options
Diffstat (limited to 'contrib/gcc/gengenrtl.c')
-rw-r--r-- | contrib/gcc/gengenrtl.c | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/contrib/gcc/gengenrtl.c b/contrib/gcc/gengenrtl.c index ade07ff..bf98a71 100644 --- a/contrib/gcc/gengenrtl.c +++ b/contrib/gcc/gengenrtl.c @@ -1,5 +1,5 @@ /* Generate code to allocate RTL structures. - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of GNU CC. @@ -21,10 +21,7 @@ Boston, MA 02111-1307, USA. */ #include "hconfig.h" #include "system.h" - -#include "obstack.h" -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free +#undef abort #define NO_GENRTL_H #include "rtl.h" @@ -56,6 +53,8 @@ static void genlegend PROTO((FILE *)); static void genheader PROTO((FILE *)); static void gencode PROTO((FILE *)); +/* Decode a format letter into a C type string. */ + static const char * type_from_format (c) int c; @@ -88,6 +87,8 @@ type_from_format (c) } } +/* Decode a format letter into the proper accessor function. */ + static const char * accessor_from_format (c) int c; @@ -114,6 +115,8 @@ accessor_from_format (c) } } +/* Return true if a format character doesn't need normal processing. */ + static int special_format (fmt) const char *fmt; @@ -124,15 +127,20 @@ special_format (fmt) || strchr (fmt, 'n') != 0); } +/* Return true if an rtx requires special processing. */ + static int special_rtx (idx) int idx; { return (strcmp (defs[idx].enumname, "CONST_INT") == 0 + || strcmp (defs[idx].enumname, "CONST_DOUBLE") == 0 || strcmp (defs[idx].enumname, "REG") == 0 || strcmp (defs[idx].enumname, "MEM") == 0); } +/* Fill `formats' with all unique format strings. */ + static void find_formats () { @@ -146,7 +154,7 @@ find_formats () continue; for (f = formats; *f ; ++f) - if (!strcmp(*f, defs[i].format)) + if (! strcmp (*f, defs[i].format)) break; if (!*f) @@ -154,6 +162,8 @@ find_formats () } } +/* Emit a prototype for the rtx generator for a format. */ + static void gendecl (f, format) FILE *f; @@ -170,6 +180,8 @@ gendecl (f, format) fprintf (f, "));\n"); } +/* Emit a define mapping an rtx code to the generator for its format. */ + static void genmacro (f, idx) FILE *f; @@ -193,6 +205,8 @@ genmacro (f, idx) fprintf (f, ")\n"); } +/* Emit the implementation for the rtx generator for a format. */ + static void gendef (f, format) FILE *f; @@ -229,14 +243,18 @@ gendef (f, format) fprintf (f, "\n return rt;\n}\n\n"); } +/* Emit the `do not edit' banner. */ + static void genlegend (f) FILE *f; { - fprintf (f, "/* Generated automaticaly by the program `gengenrtl'\n"); - fprintf (f, " from the RTL description file `rtl.def' */\n\n"); + fputs ("/* Generated automaticaly by the program `gengenrtl'\n", f); + fputs (" from the RTL description file `rtl.def' */\n\n", f); } +/* Emit "genrtl.h". */ + static void genheader (f) FILE *f; @@ -247,7 +265,7 @@ genheader (f) for (fmt = formats; *fmt; ++fmt) gendecl (f, *fmt); - fprintf(f, "\n"); + fprintf (f, "\n"); for (i = 0; i < NUM_RTX_CODE; i++) { @@ -257,6 +275,8 @@ genheader (f) } } +/* Emit "genrtl.c". */ + static void gencode (f) FILE *f; @@ -272,34 +292,30 @@ gencode (f) fputs ("static rtx obstack_alloc_rtx (length)\n", f); fputs (" register int length;\n{\n", f); fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f); - fputs (" if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(int))\n", f); - fputs (" *(int *)rt = 0;\n", f); - fputs (" else if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(HOST_WIDE_INT))\n", f); - fputs (" *(HOST_WIDE_INT *)rt = 0;\n", f); - fputs (" else\n", f); - fputs (" bzero((char *) rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f); + fputs (" memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f); fputs (" return rt;\n}\n\n", f); for (fmt = formats; *fmt; ++fmt) gendef (f, *fmt); } -#if defined(USE_C_ALLOCA) && !defined(__GNUC__) -char * +#if defined(USE_C_ALLOCA) +PTR xmalloc (nbytes) - int nbytes; + size_t nbytes; { - char *tmp = (char *) malloc (nbytes); + register PTR tmp = (PTR) malloc (nbytes); if (!tmp) { - fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", nbytes); + fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", + nbytes); exit (FATAL_EXIT_CODE); } return tmp; } -#endif /* USE_C_ALLOCA && !__GNUC__ */ +#endif /* USE_C_ALLOCA */ int main(argc, argv) @@ -316,22 +332,22 @@ main(argc, argv) f = fopen (argv[1], "w"); if (f == NULL) { - perror(argv[1]); + perror (argv[1]); exit (1); } genlegend (f); genheader (f); - fclose(f); + fclose (f); f = fopen (argv[2], "w"); if (f == NULL) { - perror(argv[2]); + perror (argv[2]); exit (1); } genlegend (f); gencode (f); - fclose(f); + fclose (f); exit (0); } |