1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997, 1998 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. */
31 const char *enumname
, *name
, *format
;
34 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { STRINGIFY(ENUM), NAME, FORMAT },
36 struct rtx_definition defs
[] =
38 #include "rtl.def" /* rtl expressions are documented here */
41 const char *formats
[NUM_RTX_CODE
];
43 static const char *type_from_format
PROTO((int));
44 static const char *accessor_from_format
PROTO((int));
45 static int special_format
PROTO((const char *));
46 static int special_rtx
PROTO((int));
47 static void find_formats
PROTO((void));
48 static void gendecl
PROTO((FILE *, const char *));
49 static void genmacro
PROTO((FILE *, int));
50 static void gendef
PROTO((FILE *, const char *));
51 static void genlegend
PROTO((FILE *));
52 static void genheader
PROTO((FILE *));
53 static void gencode
PROTO((FILE *));
64 return "HOST_WIDE_INT";
72 /* ?!? These should be bitmap and tree respectively, but those types
73 are not available in many of the files which include the output
76 These are only used in prototypes, so I think we can assume that
88 accessor_from_format (c
)
117 return (strchr (fmt
, '*') != 0
118 || strchr (fmt
, 'V') != 0
119 || strchr (fmt
, 'S') != 0
120 || strchr (fmt
, 'n') != 0);
127 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
128 || strcmp (defs
[idx
].enumname
, "REG") == 0
129 || strcmp (defs
[idx
].enumname
, "MEM") == 0);
137 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
141 if (special_format (defs
[i
].format
))
144 for (f
= formats
; *f
; ++f
)
145 if (!strcmp(*f
, defs
[i
].format
))
161 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
163 for (p
= format
, i
= 0; *p
; ++p
)
165 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
166 fprintf (f
, "));\n");
177 fprintf (f
, "#define gen_rtx_%s%s(mode",
178 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
180 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
182 fprintf (f
, ", arg%d", i
++);
185 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
186 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
188 fprintf (f
, ",(arg%d)", i
++);
200 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
201 for (p
= format
, i
= 0; *p
; ++p
)
203 fprintf (f
, ", arg%d", i
++);
205 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
206 for (p
= format
, i
= 0; *p
; ++p
)
208 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
210 /* See rtx_alloc in rtl.c for comments. */
212 fprintf (f
, " rtx rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
213 (int) strlen (format
) - 1);
215 fprintf (f
, " PUT_CODE (rt, code);\n");
216 fprintf (f
, " PUT_MODE (rt, mode);\n");
218 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
221 fprintf (f
, " %s (rt, %d) = arg%d;\n",
222 accessor_from_format (*p
), i
, j
++);
225 fprintf (f
, "\n return rt;\n}\n\n");
232 fprintf (f
, "/* Generated automaticaly by the program `gengenrtl'\n");
233 fprintf (f
, " from the RTL description file `rtl.def' */\n\n");
243 for (fmt
= formats
; *fmt
; ++fmt
)
248 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
250 if (special_format (defs
[i
].format
))
262 fputs ("#include \"config.h\"\n", f
);
263 fputs ("#include \"system.h\"\n", f
);
264 fputs ("#include \"obstack.h\"\n", f
);
265 fputs ("#include \"rtl.h\"\n\n", f
);
266 fputs ("extern struct obstack *rtl_obstack;\n\n", f
);
267 fputs ("static rtx obstack_alloc_rtx PROTO((int length));\n", f
);
268 fputs ("static rtx obstack_alloc_rtx (length)\n", f
);
269 fputs (" register int length;\n{\n", f
);
270 fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f
);
271 fputs (" bzero((char *) rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f
);
272 fputs (" return rt;\n}\n\n", f
);
274 for (fmt
= formats
; *fmt
; ++fmt
)
278 #if defined(USE_C_ALLOCA)
283 register PTR tmp
= (PTR
) malloc (nbytes
);
287 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n",
289 exit (FATAL_EXIT_CODE
);
294 #endif /* USE_C_ALLOCA */
308 f
= fopen (argv
[1], "w");
318 f
= fopen (argv
[2], "w");