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
;
38 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { # ENUM, NAME, FORMAT },
40 struct rtx_definition defs
[] =
42 #include "rtl.def" /* rtl expressions are documented here */
45 const char *formats
[NUM_RTX_CODE
];
48 type_from_format (char c
)
55 return "HOST_WIDE_INT";
69 accessor_from_format (char c
)
93 return (strchr (fmt
, '*') != 0
94 || strchr (fmt
, 'V') != 0
95 || strchr (fmt
, 'S') != 0
96 || strchr (fmt
, 'n') != 0);
103 return (strcmp (defs
[idx
].enumname
, "CONST_INT") == 0
104 || strcmp (defs
[idx
].enumname
, "REG") == 0);
112 for (i
= 0; i
< NUM_RTX_CODE
; ++i
)
116 if (special_format (defs
[i
].format
))
119 for (f
= formats
; *f
; ++f
)
120 if (!strcmp(*f
, defs
[i
].format
))
136 fprintf (f
, "extern rtx gen_rtx_fmt_%s PROTO((RTX_CODE, enum machine_mode mode",
138 for (p
= format
, i
= 0; *p
; ++p
)
140 fprintf (f
, ", %s arg%d", type_from_format (*p
), i
++);
141 fprintf (f
, "));\n");
152 fprintf (f
, "#define gen_rtx_%s%s(mode",
153 (special_rtx (idx
) ? "raw_" : ""), defs
[idx
].enumname
);
155 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
157 fprintf (f
, ", arg%d", i
++);
160 fprintf (f
, "gen_rtx_fmt_%s(%s,(mode)", defs
[idx
].format
, defs
[idx
].enumname
);
161 for (p
= defs
[idx
].format
, i
= 0; *p
; ++p
)
163 fprintf (f
, ",(arg%d)", i
++);
175 fprintf (f
, "rtx\ngen_rtx_fmt_%s (code, mode", format
);
176 for (p
= format
, i
= 0; *p
; ++p
)
178 fprintf (f
, ", arg%d", i
++);
180 fprintf (f
, ")\n RTX_CODE code;\n enum machine_mode mode;\n");
181 for (p
= format
, i
= 0; *p
; ++p
)
183 fprintf (f
, " %s arg%d;\n", type_from_format (*p
), i
++);
185 /* See rtx_alloc in rtl.c for comments. */
187 fprintf (f
, " register int length = sizeof (struct rtx_def)");
188 fprintf (f
, " + %d * sizeof (rtunion);\n", strlen (format
) - 1);
189 fprintf (f
, " rtx rt = (rtx)obstack_alloc (rtl_obstack, length);\n");
191 fprintf (f
, " if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(int))\n");
192 fprintf (f
, " *(int *)rt = 0;\n");
193 fprintf (f
, " else if (sizeof(struct rtx_def) - sizeof(rtunion) == sizeof(HOST_WIDE_INT))\n");
194 fprintf (f
, " *(HOST_WIDE_INT *)rt = 0;\n");
195 fprintf (f
, " else\n");
196 fprintf (f
, " bzero(rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n");
198 fprintf (f
, " PUT_CODE (rt, code);\n");
199 fprintf (f
, " PUT_MODE (rt, mode);\n");
201 for (p
= format
, i
= j
= 0; *p
; ++p
, ++i
)
204 fprintf (f
, " %s (rt, %d) = arg%d;\n",
205 accessor_from_format (*p
), i
, j
++);
208 fprintf (f
, "\n return rt;\n}\n\n");
215 fprintf (f
, "/* Generated automaticaly by the program `gengenrtl'\n");
216 fprintf (f
, " from the RTL description file `rtl.def' */\n\n");
226 for (fmt
= formats
; *fmt
; ++fmt
)
231 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
233 if (special_format (defs
[i
].format
))
245 fprintf(f
, "#include \"config.h\"\n");
246 fprintf(f
, "#include \"obstack.h\"\n");
247 fprintf(f
, "#include \"rtl.h\"\n\n");
248 fprintf(f
, "extern struct obstack *rtl_obstack;\n\n");
250 for (fmt
= formats
; *fmt
; ++fmt
)
266 f
= fopen (argv
[1], "w");
276 f
= fopen (argv
[2], "w");