]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gengenrtl.c
1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997 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. */
26 #define obstack_chunk_alloc xmalloc
27 #define obstack_chunk_free free
35 const char *enumname
, *name
, *format
;
39 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { # ENUM, NAME, FORMAT },
41 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { "ENUM", NAME, FORMAT },
44 struct rtx_definition defs
[] =
46 #include "rtl.def" /* rtl expressions are documented here */
49 const char *formats
[NUM_RTX_CODE
];
52 type_from_format (char c
)
59 return "HOST_WIDE_INT";
73 accessor_from_format (char c
)
97 return (strchr (fmt
, '*') != 0
98 || strchr (fmt
, 'V') != 0
99 || strchr (fmt
, 'S') != 0
100 || strchr (fmt
, 'n') != 0);
107 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
108 || strcmp (defs
[idx
].enumname
, "REG") == 0);
116 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
120 if (special_format (defs
[i
].format
))
123 for (f
= formats
; *f
; ++f
)
124 if (!strcmp(*f
, defs
[i
].format
))
140 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
142 for (p
= format
, i
= 0; *p
; ++p
)
144 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
145 fprintf (f
, "));\n");
156 fprintf (f
, "#define gen_rtx_%s%s(mode",
157 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
159 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
161 fprintf (f
, ", arg%d", i
++);
164 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
165 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
167 fprintf (f
, ",(arg%d)", i
++);
179 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
180 for (p
= format
, i
= 0; *p
; ++p
)
182 fprintf (f
, ", arg%d", i
++);
184 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
185 for (p
= format
, i
= 0; *p
; ++p
)
187 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
189 /* See rtx_alloc in rtl.c for comments. */
191 fprintf (f
, " rtx rt = obstack_alloc_rtx (sizeof (struct rtx_def) + %d * sizeof (rtunion));\n",
192 (int) strlen (format
) - 1);
194 fprintf (f
, " PUT_CODE (rt, code);\n");
195 fprintf (f
, " PUT_MODE (rt, mode);\n");
197 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
200 fprintf (f
, " %s (rt, %d) = arg%d;\n",
201 accessor_from_format (*p
), i
, j
++);
204 fprintf (f
, "\n return rt;\n}\n\n");
211 fprintf (f
, "/* Generated automaticaly by the program `gengenrtl'\n");
212 fprintf (f
, " from the RTL description file `rtl.def' */\n\n");
222 for (fmt
= formats
; *fmt
; ++fmt
)
227 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
229 if (special_format (defs
[i
].format
))
241 fputs ("#include \"config.h\"\n", f
);
242 fputs ("#include \"obstack.h\"\n", f
);
243 fputs ("#include \"rtl.h\"\n\n", f
);
244 fputs ("extern struct obstack *rtl_obstack;\n\n", f
);
245 fputs ("static rtx obstack_alloc_rtx PROTO((int length));\n", f
);
246 fputs ("static rtx obstack_alloc_rtx (length)\n", f
);
247 fputs (" register int length;\n{\n", f
);
248 fputs (" rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f
);
249 fputs (" if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(int))\n", f
);
250 fputs (" *(int *)rt = 0;\n", f
);
251 fputs (" else if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(HOST_WIDE_INT))\n", f
);
252 fputs (" *(HOST_WIDE_INT *)rt = 0;\n", f
);
253 fputs (" else\n", f
);
254 fputs (" bzero(rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f
);
255 fputs (" return rt;\n}\n\n", f
);
257 for (fmt
= formats
; *fmt
; ++fmt
)
273 f
= fopen (argv
[1], "w");
283 f
= fopen (argv
[2], "w");