]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gengenrtl.c
5a3211f64feb51f02fe83c085815a8ce8e316e6c
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((FILE *, const char *));
71 static void genmacro
PROTO((FILE *, int));
72 static void gendef
PROTO((FILE *, const char *));
73 static void genlegend
PROTO((FILE *));
74 static void genheader
PROTO((FILE *));
75 static void gencode
PROTO((FILE *));
77 /* Decode a format letter into a C type string. */
88 return "HOST_WIDE_INT";
97 return "struct bitmap_head_def *"; /* bitmap - typedef not available */
99 return "union tree_node *"; /* tree - typedef not available */
105 /* Decode a format letter into the proper accessor function. */
108 accessor_from_format (c
)
133 /* Return true if a format character doesn't need normal processing. */
139 return (strchr (fmt
, '*') != 0
140 || strchr (fmt
, 'V') != 0
141 || strchr (fmt
, 'S') != 0
142 || strchr (fmt
, 'n') != 0);
145 /* Return true if an rtx requires special processing. */
151 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
152 || strcmp (defs
[idx
].enumname
, "CONST_DOUBLE") == 0
153 || strcmp (defs
[idx
].enumname
, "REG") == 0
154 || strcmp (defs
[idx
].enumname
, "MEM") == 0);
157 /* Fill `formats' with all unique format strings. */
164 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
168 if (special_format (defs
[i
].format
))
171 for (f
= formats
; *f
; ++f
)
172 if (! strcmp (*f
, defs
[i
].format
))
180 /* Emit a prototype for the rtx generator for a format. */
190 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
192 for (p
= format
, i
= 0; *p
; ++p
)
194 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
195 fprintf (f
, "));\n");
198 /* Emit a define mapping an rtx code to the generator for its format. */
208 fprintf (f
, "#define gen_rtx_%s%s(mode",
209 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
211 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
213 fprintf (f
, ", arg%d", i
++);
216 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
217 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
219 fprintf (f
, ",(arg%d)", i
++);
223 /* Emit the implementation for the rtx generator for a format. */
233 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
234 for (p
= format
, i
= 0; *p
; ++p
)
236 fprintf (f
, ", arg%d", i
++);
238 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
239 for (p
= format
, i
= 0; *p
; ++p
)
241 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
243 /* See rtx_alloc in rtl.c for comments. */
245 fprintf (f
, " rtx rt;\n");
246 fprintf (f
, " if (ggc_p)\n");
247 fprintf (f
, " rt = ggc_alloc_rtx (%d);\n",
248 (int) strlen (format
));
249 fprintf (f
, " else\n");
250 fprintf (f
, " rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
251 (int) strlen (format
) - 1);
253 fprintf (f
, " PUT_CODE (rt, code);\n");
254 fprintf (f
, " PUT_MODE (rt, mode);\n");
256 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
259 fprintf (f
, " %s (rt, %d) = arg%d;\n",
260 accessor_from_format (*p
), i
, j
++);
263 fprintf (f
, "\n return rt;\n}\n\n");
266 /* Emit the `do not edit' banner. */
272 fputs ("/* Generated automaticaly by the program `gengenrtl'\n", f
);
273 fputs (" from the RTL description file `rtl.def' */\n\n", f
);
276 /* Emit "genrtl.h". */
285 for (fmt
= formats
; *fmt
; ++fmt
)
290 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
292 if (special_format (defs
[i
].format
))
298 /* Emit "genrtl.c". */
306 fputs ("#include \"config.h\"\n", f
);
307 fputs ("#include \"system.h\"\n", f
);
308 fputs ("#include \"obstack.h\"\n", f
);
309 fputs ("#include \"rtl.h\"\n", f
);
310 fputs ("#include \"ggc.h\"\n\n", f
);
311 fputs ("extern struct obstack *rtl_obstack;\n\n", f
);
312 fputs ("static rtx obstack_alloc_rtx PROTO((int length));\n", f
);
313 fputs ("static rtx obstack_alloc_rtx (length)\n", f
);
314 fputs (" register int length;\n{\n", f
);
315 fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f
);
316 fputs (" memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f
);
317 fputs (" return rt;\n}\n\n", f
);
319 for (fmt
= formats
; *fmt
; ++fmt
)
323 #if defined(USE_C_ALLOCA)
328 register PTR tmp
= (PTR
) malloc (nbytes
);
332 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n",
334 exit (FATAL_EXIT_CODE
);
339 #endif /* USE_C_ALLOCA */
353 f
= fopen (argv
[1], "w");
363 f
= fopen (argv
[2], "w");