b140743b8d7ab94e28da444482e7d8610ad73fa3
1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #define obstack_chunk_alloc xmalloc
27 #define obstack_chunk_free free
35 const char *enumname
, *name
, *format
;
38 #if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
39 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { # ENUM, NAME, FORMAT },
41 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { "ENUM", NAME, FORMAT },
44 struct rtx_definition defs
[] =
46 #include "rtl.def" /* rtl expressions are documented here */
49 const char *formats
[NUM_RTX_CODE
];
51 static const char *type_from_format
PROTO((char));
52 static const char *accessor_from_format
PROTO((char));
53 static int special_format
PROTO((const char *));
54 static int special_rtx
PROTO((int));
55 static void find_formats
PROTO((void));
56 static void gendecl
PROTO((FILE *, const char *));
57 static void genmacro
PROTO((FILE *, int));
58 static void gendef
PROTO((FILE *, const char *));
59 static void genlegend
PROTO((FILE *));
60 static void genheader
PROTO((FILE *));
61 static void gencode
PROTO((FILE *));
72 return "HOST_WIDE_INT";
86 accessor_from_format (c
)
111 return (strchr (fmt
, '*') != 0
112 || strchr (fmt
, 'V') != 0
113 || strchr (fmt
, 'S') != 0
114 || strchr (fmt
, 'n') != 0);
121 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
122 || strcmp (defs
[idx
].enumname
, "REG") == 0);
130 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
134 if (special_format (defs
[i
].format
))
137 for (f
= formats
; *f
; ++f
)
138 if (!strcmp(*f
, defs
[i
].format
))
154 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
156 for (p
= format
, i
= 0; *p
; ++p
)
158 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
159 fprintf (f
, "));\n");
170 fprintf (f
, "#define gen_rtx_%s%s(mode",
171 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
173 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
175 fprintf (f
, ", arg%d", i
++);
178 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
179 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
181 fprintf (f
, ",(arg%d)", i
++);
193 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
194 for (p
= format
, i
= 0; *p
; ++p
)
196 fprintf (f
, ", arg%d", i
++);
198 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
199 for (p
= format
, i
= 0; *p
; ++p
)
201 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
203 /* See rtx_alloc in rtl.c for comments. */
205 fprintf (f
, " rtx rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
206 (int) strlen (format
) - 1);
208 fprintf (f
, " PUT_CODE (rt, code);\n");
209 fprintf (f
, " PUT_MODE (rt, mode);\n");
211 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
214 fprintf (f
, " %s (rt, %d) = arg%d;\n",
215 accessor_from_format (*p
), i
, j
++);
218 fprintf (f
, "\n return rt;\n}\n\n");
225 fprintf (f
, "/* Generated automaticaly by the program `gengenrtl'\n");
226 fprintf (f
, " from the RTL description file `rtl.def' */\n\n");
236 for (fmt
= formats
; *fmt
; ++fmt
)
241 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
243 if (special_format (defs
[i
].format
))
255 fputs ("#include \"config.h\"\n", f
);
256 fputs ("#include \"system.h\"\n", f
);
257 fputs ("#include \"obstack.h\"\n", f
);
258 fputs ("#include \"rtl.h\"\n\n", f
);
259 fputs ("extern struct obstack *rtl_obstack;\n\n", f
);
260 fputs ("static rtx obstack_alloc_rtx PROTO((int length));\n", f
);
261 fputs ("static rtx obstack_alloc_rtx (length)\n", f
);
262 fputs (" register int length;\n{\n", f
);
263 fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f
);
264 fputs (" if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(int))\n", f
);
265 fputs (" *(int *)rt = 0;\n", f
);
266 fputs (" else if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(HOST_WIDE_INT))\n", f
);
267 fputs (" *(HOST_WIDE_INT *)rt = 0;\n", f
);
268 fputs (" else\n", f
);
269 fputs (" bzero(rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f
);
270 fputs (" return rt;\n}\n\n", f
);
272 for (fmt
= formats
; *fmt
; ++fmt
)
276 #if defined(USE_C_ALLOCA) && !defined(__GNUC__)
281 char *tmp
= (char *) malloc (nbytes
);
285 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n", nbytes
);
286 exit (FATAL_EXIT_CODE
);
291 #endif /* USE_C_ALLOCA && !__GNUC__ */
305 f
= fopen (argv
[1], "w");
315 f
= fopen (argv
[2], "w");