1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997, 1998, 1999, 2000 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.
34 We need to go out to e0wwwww, since REAL_ARITHMETIC assumes 16-bits
35 per element in REAL_VALUE_TYPE.
37 This is duplicated in rtl.c.
39 A number of places assume that there are always at least two 'w'
40 slots in a CONST_DOUBLE, so we provide them even if one would suffice. */
42 #ifdef REAL_ARITHMETIC
43 #if MAX_LONG_DOUBLE_TYPE_SIZE == 96
44 #define REAL_WIDTH (11*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
45 #elif MAX_LONG_DOUBLE_TYPE_SIZE == 128
46 #define REAL_WIDTH (19*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
47 #elif HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
48 #define REAL_WIDTH (7*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
50 #endif /* REAL_ARITHMETIC */
53 #if HOST_BITS_PER_WIDE_INT*2 >= MAX_LONG_DOUBLE_TYPE_SIZE
55 #elif HOST_BITS_PER_WIDE_INT*3 >= MAX_LONG_DOUBLE_TYPE_SIZE
57 #elif HOST_BITS_PER_WIDE_INT*4 >= MAX_LONG_DOUBLE_TYPE_SIZE
60 #endif /* REAL_WIDTH */
63 #define CONST_DOUBLE_FORMAT "e0ww"
65 #define CONST_DOUBLE_FORMAT "e0ww"
67 #define CONST_DOUBLE_FORMAT "e0www"
69 #define CONST_DOUBLE_FORMAT "e0wwww"
71 #define CONST_DOUBLE_FORMAT "e0wwwww"
73 #define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */
79 const char *enumname
, *name
, *format
;
82 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { STRINGIFY(ENUM), NAME, FORMAT },
84 struct rtx_definition defs
[] =
86 #include "rtl.def" /* rtl expressions are documented here */
89 const char *formats
[NUM_RTX_CODE
];
91 static const char *type_from_format
PARAMS ((int));
92 static const char *accessor_from_format
PARAMS ((int));
93 static int special_format
PARAMS ((const char *));
94 static int special_rtx
PARAMS ((int));
95 static void find_formats
PARAMS ((void));
96 static void gendecl
PARAMS ((const char *));
97 static void genmacro
PARAMS ((int));
98 static void gendef
PARAMS ((const char *));
99 static void genlegend
PARAMS ((void));
100 static void genheader
PARAMS ((void));
101 static void gencode
PARAMS ((void));
103 /* Decode a format letter into a C type string. */
115 return "HOST_WIDE_INT ";
118 return "const char *";
126 return "struct bitmap_head_def *"; /* bitmap - typedef not available */
128 return "union tree_node *"; /* tree - typedef not available */
134 /* Decode a format letter into the proper accessor function. */
137 accessor_from_format (c
)
168 /* Return nonzero if we should ignore FMT, an RTL format, when making
169 the list of formats we write routines to create. */
175 return (strchr (fmt
, '*') != 0
176 || strchr (fmt
, 'V') != 0
177 || strchr (fmt
, 'S') != 0
178 || strchr (fmt
, 'n') != 0);
181 /* Return nonzero if the RTL code given by index IDX is one that we should not
182 generate a gen_RTX_FOO function foo (because that function is present
183 elsewhere in the compiler. */
189 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
190 || strcmp (defs
[idx
].enumname
, "CONST_DOUBLE") == 0
191 || strcmp (defs
[idx
].enumname
, "REG") == 0
192 || strcmp (defs
[idx
].enumname
, "MEM") == 0);
195 /* Place a list of all format specifiers we use into the array FORMAT. */
202 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
206 if (special_format (defs
[i
].format
))
209 for (f
= formats
; *f
; f
++)
210 if (! strcmp (*f
, defs
[i
].format
))
218 /* Write the declarations for the routine to allocate RTL with FORMAT. */
227 printf ("extern rtx gen_rtx_fmt_%s\tPARAMS ((RTX_CODE, ", format
);
228 printf ("enum machine_mode mode");
230 /* Write each parameter that is needed and start a new line when the line
232 for (p
= format
, i
= 0, pos
= 75; *p
!= 0; p
++)
235 int ourlen
= strlen (type_from_format (*p
)) + 6 + (i
> 9);
238 if (pos
+ ourlen
> 76)
239 printf ("\n\t\t\t\t "), pos
= 39;
241 printf (" %sarg%d", type_from_format (*p
), i
++);
248 /* Generate macros to generate RTL of code IDX using the functions we
258 /* We write a macro that defines gen_rtx_RTLCODE to be an equivalent to
259 gen_rtx_fmt_FORMAT where FORMAT is the RTX_FORMAT of RTLCODE. */
261 printf ("#define gen_rtx_%s%s(MODE",
262 special_rtx (idx
) ? "raw_" : "", defs
[idx
].enumname
);
264 for (p
= defs
[idx
].format
, i
= 0; *p
!= 0; p
++)
266 printf (", ARG%d", i
++);
268 printf (") \\\n gen_rtx_fmt_%s (%s, (MODE)",
269 defs
[idx
].format
, defs
[idx
].enumname
);
271 for (p
= defs
[idx
].format
, i
= 0; *p
!= 0; p
++)
273 printf (", (ARG%d)", i
++);
278 /* Generate the code for the function to generate RTL whose
288 /* Start by writing the definition of the function name and the types
291 printf ("rtx\ngen_rtx_fmt_%s (code, mode", format
);
292 for (p
= format
, i
= 0; *p
!= 0; p
++)
294 printf (", arg%d", i
++);
296 printf (")\n RTX_CODE code;\n enum machine_mode mode;\n");
297 for (p
= format
, i
= 0; *p
!= 0; p
++)
299 printf (" %sarg%d;\n", type_from_format (*p
), i
++);
301 /* Now write out the body of the function itself, which allocates
302 the memory and initializes it. */
304 printf (" rtx rt;\n");
305 printf (" if (ggc_p)\n");
306 printf (" rt = ggc_alloc_rtx (%d);\n",
307 (int) strlen (format
));
309 printf (" rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
310 (int) strlen (format
) - 1);
312 printf (" PUT_CODE (rt, code);\n");
313 printf (" PUT_MODE (rt, mode);\n");
315 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
317 printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p
), i
, j
++);
319 printf ("\n return rt;\n}\n\n");
322 /* Generate the documentation header for files we write. */
327 printf ("/* Generated automaticaly by the program `gengenrtl'\n");
328 printf (" from the RTL description file `rtl.def' */\n\n");
331 /* Generate the text of the header file we make, genrtl.h. */
339 for (fmt
= formats
; *fmt
; ++fmt
)
344 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
345 if (! special_format (defs
[i
].format
))
349 /* Generate the text of the code file we write, genrtl.c. */
356 puts ("#include \"config.h\"\n");
357 puts ("#include \"system.h\"\n");
358 puts ("#include \"obstack.h\"\n");
359 puts ("#include \"rtl.h\"\n");
360 puts ("#include \"ggc.h\"\n\n");
361 puts ("extern struct obstack *rtl_obstack;\n\n");
362 puts ("static rtx obstack_alloc_rtx PARAMS ((int length));\n");
363 puts ("static rtx obstack_alloc_rtx (length)\n");
364 puts (" register int length;\n{\n");
365 puts (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n");
366 puts (" memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n");
367 puts (" return rt;\n}\n\n");
369 for (fmt
= formats
; *fmt
!= 0; fmt
++)
373 #if defined(USE_C_ALLOCA)
378 register PTR tmp
= (PTR
) malloc (nbytes
);
382 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n",
384 exit (FATAL_EXIT_CODE
);
389 #endif /* USE_C_ALLOCA */
391 /* This is the main program. We accept only one argument, "-h", which
392 says we are writing the genrtl.h file. Otherwise we are writing the
394 extern int main
PARAMS ((int, char **));
404 if (argc
== 2 && argv
[1][0] == '-' && argv
[1][1] == 'h')
410 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);