]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gengenrtl.c
1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997, 1998, 1999 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 /* Calculate the format for CONST_DOUBLE. This depends on the relative
32 widths of HOST_WIDE_INT and REAL_VALUE_TYPE.
33 We only need to go out to e0wwww, since min(HOST_WIDE_INT)==32 and
34 max(LONG_DOUBLE_TYPE_SIZE)==128.
35 This is duplicated in rtl.c.
36 A number of places assume that there are always at least two 'w'
37 slots in a CONST_DOUBLE, so we provide them even if one would suffice. */
38 #if HOST_BITS_PER_WIDE_INT >= LONG_DOUBLE_TYPE_SIZE
39 #define CONST_DOUBLE_FORMAT "e0ww"
40 #elif HOST_BITS_PER_WIDE_INT*2 >= LONG_DOUBLE_TYPE_SIZE
41 #define CONST_DOUBLE_FORMAT "e0ww"
42 #elif HOST_BITS_PER_WIDE_INT*3 >= LONG_DOUBLE_TYPE_SIZE
43 #define CONST_DOUBLE_FORMAT "e0www"
44 #elif HOST_BITS_PER_WIDE_INT*4 >= LONG_DOUBLE_TYPE_SIZE
45 #define CONST_DOUBLE_FORMAT "e0wwww"
47 #define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */
53 const char *enumname
, *name
, *format
;
56 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { STRINGIFY(ENUM), NAME, FORMAT },
58 struct rtx_definition defs
[] =
60 #include "rtl.def" /* rtl expressions are documented here */
63 const char *formats
[NUM_RTX_CODE
];
65 static const char *type_from_format
PROTO((int));
66 static const char *accessor_from_format
PROTO((int));
67 static int special_format
PROTO((const char *));
68 static int special_rtx
PROTO((int));
69 static void find_formats
PROTO((void));
70 static void gendecl
PROTO((const char *));
71 static void genmacro
PROTO((int));
72 static void gendef
PROTO((const char *));
73 static void genlegend
PROTO((void));
74 static void genheader
PROTO((void));
75 static void gencode
PROTO((void));
77 /* Decode a format letter into a C type string. */
89 return "HOST_WIDE_INT ";
100 return "struct bitmap_head_def *"; /* bitmap - typedef not available */
102 return "union tree_node *"; /* tree - typedef not available */
108 /* Decode a format letter into the proper accessor function. */
111 accessor_from_format (c
)
142 /* Return nonzero if we should ignore FMT, an RTL format, when making
143 the list of formats we write routines to create. */
149 return (strchr (fmt
, '*') != 0
150 || strchr (fmt
, 'V') != 0
151 || strchr (fmt
, 'S') != 0
152 || strchr (fmt
, 'n') != 0);
155 /* Return nonzero if the RTL code given by index IDX is one that we should not
156 generate a gen_RTX_FOO function foo (because that function is present
157 elsewhere in the compiler. */
163 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
164 || strcmp (defs
[idx
].enumname
, "CONST_DOUBLE") == 0
165 || strcmp (defs
[idx
].enumname
, "REG") == 0
166 || strcmp (defs
[idx
].enumname
, "MEM") == 0);
169 /* Place a list of all format specifiers we use into the array FORMAT. */
176 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
180 if (special_format (defs
[i
].format
))
183 for (f
= formats
; *f
; f
++)
184 if (! strcmp (*f
, defs
[i
].format
))
192 /* Write the declarations for the routine to allocate RTL with FORMAT. */
201 printf ("extern rtx gen_rtx_fmt_%s\tPROTO((RTX_CODE, ", format
);
202 printf ("enum machine_mode mode");
204 /* Write each parameter that is needed and start a new line when the line
206 for (p
= format
, i
= 0, pos
= 75; *p
!= 0; p
++)
209 int ourlen
= strlen (type_from_format (*p
)) + 6 + (i
> 9);
212 if (pos
+ ourlen
> 76)
213 printf ("\n\t\t\t\t "), pos
= 39;
215 printf (" %sarg%d", type_from_format (*p
), i
++);
222 /* Generate macros to generate RTL of code IDX using the functions we
232 /* We write a macro that defines gen_rtx_RTLCODE to be an equivalent to
233 gen_rtx_fmt_FORMAT where FORMAT is the RTX_FORMAT of RTLCODE. */
235 printf ("#define gen_rtx_%s%s(MODE",
236 special_rtx (idx
) ? "raw_" : "", defs
[idx
].enumname
);
238 for (p
= defs
[idx
].format
, i
= 0; *p
!= 0; p
++)
240 printf (", ARG%d", i
++);
242 printf (") \\\n gen_rtx_fmt_%s (%s, (MODE)",
243 defs
[idx
].format
, defs
[idx
].enumname
);
245 for (p
= defs
[idx
].format
, i
= 0; *p
!= 0; p
++)
247 printf (", (ARG%d)", i
++);
252 /* Generate the code for the function to generate RTL whose
262 /* Start by writing the definition of the function name and the types
265 printf ("rtx\ngen_rtx_fmt_%s (code, mode", format
);
266 for (p
= format
, i
= 0; *p
!= 0; p
++)
268 printf (", arg%d", i
++);
270 printf (")\n RTX_CODE code;\n enum machine_mode mode;\n");
271 for (p
= format
, i
= 0; *p
!= 0; p
++)
273 printf (" %sarg%d;\n", type_from_format (*p
), i
++);
275 /* Now write out the body of the function itself, which allocates
276 the memory and initializes it. */
278 printf (" rtx rt;\n");
279 printf (" if (ggc_p)\n");
280 printf (" rt = ggc_alloc_rtx (%d);\n",
281 (int) strlen (format
));
283 printf (" rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
284 (int) strlen (format
) - 1);
286 printf (" PUT_CODE (rt, code);\n");
287 printf (" PUT_MODE (rt, mode);\n");
289 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
291 printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p
), i
, j
++);
293 printf ("\n return rt;\n}\n\n");
296 /* Generate the documentation header for files we write. */
301 printf ("/* Generated automaticaly by the program `gengenrtl'\n");
302 printf (" from the RTL description file `rtl.def' */\n\n");
305 /* Generate the text of the header file we make, genrtl.h. */
313 for (fmt
= formats
; *fmt
; ++fmt
)
318 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
319 if (! special_format (defs
[i
].format
))
323 /* Generate the text of the code file we write, genrtl.c. */
330 puts ("#include \"config.h\"\n");
331 puts ("#include \"system.h\"\n");
332 puts ("#include \"obstack.h\"\n");
333 puts ("#include \"rtl.h\"\n");
334 puts ("#include \"ggc.h\"\n\n");
335 puts ("extern struct obstack *rtl_obstack;\n\n");
336 puts ("static rtx obstack_alloc_rtx PROTO((int length));\n");
337 puts ("static rtx obstack_alloc_rtx (length)\n");
338 puts (" register int length;\n{\n");
339 puts (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n");
340 puts (" memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n");
341 puts (" return rt;\n}\n\n");
343 for (fmt
= formats
; *fmt
!= 0; fmt
++)
347 #if defined(USE_C_ALLOCA)
352 register PTR tmp
= (PTR
) malloc (nbytes
);
356 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n",
358 exit (FATAL_EXIT_CODE
);
363 #endif /* USE_C_ALLOCA */
365 /* This is the main program. We accept only one argument, "-h", which
366 says we are writing the genrtl.h file. Otherwise we are writing the
377 if (argc
== 2 && argv
[1][0] == '-' && argv
[1][1] == 'h')
383 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);