]>
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. */
32 const char *enumname
, *name
, *format
;
35 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { STRINGIFY(ENUM), NAME, FORMAT },
37 struct rtx_definition defs
[] =
39 #include "rtl.def" /* rtl expressions are documented here */
42 const char *formats
[NUM_RTX_CODE
];
44 static const char *type_from_format
PROTO((int));
45 static const char *accessor_from_format
PROTO((int));
46 static int special_format
PROTO((const char *));
47 static int special_rtx
PROTO((int));
48 static void find_formats
PROTO((void));
49 static void gendecl
PROTO((FILE *, const char *));
50 static void genmacro
PROTO((FILE *, int));
51 static void gendef
PROTO((FILE *, const char *));
52 static void genlegend
PROTO((FILE *));
53 static void genheader
PROTO((FILE *));
54 static void gencode
PROTO((FILE *));
56 /* Decode a format letter into a C type string. */
67 return "HOST_WIDE_INT";
76 return "struct bitmap_head_def *"; /* bitmap - typedef not available */
78 return "union tree_node *"; /* tree - typedef not available */
84 /* Decode a format letter into the proper accessor function. */
87 accessor_from_format (c
)
112 /* Return true if a format character doesn't need normal processing. */
118 return (strchr (fmt
, '*') != 0
119 || strchr (fmt
, 'V') != 0
120 || strchr (fmt
, 'S') != 0
121 || strchr (fmt
, 'n') != 0);
124 /* Return true if an rtx requires special processing. */
130 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
131 || strcmp (defs
[idx
].enumname
, "CONST_DOUBLE") == 0
132 || strcmp (defs
[idx
].enumname
, "REG") == 0
133 || strcmp (defs
[idx
].enumname
, "MEM") == 0);
136 /* Fill `formats' with all unique format strings. */
143 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
147 if (special_format (defs
[i
].format
))
150 for (f
= formats
; *f
; ++f
)
151 if (! strcmp (*f
, defs
[i
].format
))
159 /* Emit a prototype for the rtx generator for a format. */
169 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
171 for (p
= format
, i
= 0; *p
; ++p
)
173 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
174 fprintf (f
, "));\n");
177 /* Emit a define mapping an rtx code to the generator for its format. */
187 fprintf (f
, "#define gen_rtx_%s%s(mode",
188 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
190 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
192 fprintf (f
, ", arg%d", i
++);
195 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
196 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
198 fprintf (f
, ",(arg%d)", i
++);
202 /* Emit the implementation for the rtx generator for a format. */
212 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
213 for (p
= format
, i
= 0; *p
; ++p
)
215 fprintf (f
, ", arg%d", i
++);
217 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
218 for (p
= format
, i
= 0; *p
; ++p
)
220 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
222 /* See rtx_alloc in rtl.c for comments. */
224 fprintf (f
, " rtx rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
225 (int) strlen (format
) - 1);
227 fprintf (f
, " PUT_CODE (rt, code);\n");
228 fprintf (f
, " PUT_MODE (rt, mode);\n");
230 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
233 fprintf (f
, " %s (rt, %d) = arg%d;\n",
234 accessor_from_format (*p
), i
, j
++);
237 fprintf (f
, "\n return rt;\n}\n\n");
240 /* Emit the `do not edit' banner. */
246 fputs ("/* Generated automaticaly by the program `gengenrtl'\n", f
);
247 fputs (" from the RTL description file `rtl.def' */\n\n", f
);
250 /* Emit "genrtl.h". */
259 for (fmt
= formats
; *fmt
; ++fmt
)
264 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
266 if (special_format (defs
[i
].format
))
272 /* Emit "genrtl.c". */
280 fputs ("#include \"config.h\"\n", f
);
281 fputs ("#include \"system.h\"\n", f
);
282 fputs ("#include \"obstack.h\"\n", f
);
283 fputs ("#include \"rtl.h\"\n\n", f
);
284 fputs ("extern struct obstack *rtl_obstack;\n\n", f
);
285 fputs ("static rtx obstack_alloc_rtx PROTO((int length));\n", f
);
286 fputs ("static rtx obstack_alloc_rtx (length)\n", f
);
287 fputs (" register int length;\n{\n", f
);
288 fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f
);
289 fputs (" memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f
);
290 fputs (" return rt;\n}\n\n", f
);
292 for (fmt
= formats
; *fmt
; ++fmt
)
296 #if defined(USE_C_ALLOCA)
301 register PTR tmp
= (PTR
) malloc (nbytes
);
305 fprintf (stderr
, "can't allocate %d bytes (out of virtual memory)\n",
307 exit (FATAL_EXIT_CODE
);
312 #endif /* USE_C_ALLOCA */
326 f
= fopen (argv
[1], "w");
336 f
= fopen (argv
[2], "w");