comparison gcc/gengenrtl.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Generate code to allocate RTL structures. 1 /* Generate code to allocate RTL structures.
2 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007 2 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2010
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
39 #include "rtl.def" /* rtl expressions are documented here */ 39 #include "rtl.def" /* rtl expressions are documented here */
40 }; 40 };
41 #define NUM_RTX_CODE ARRAY_SIZE(defs) 41 #define NUM_RTX_CODE ARRAY_SIZE(defs)
42 42
43 static const char *formats[NUM_RTX_CODE]; 43 static const char *formats[NUM_RTX_CODE];
44
45 static const char *type_from_format (int);
46 static const char *accessor_from_format (int);
47 static int special_format (const char *);
48 static int special_rtx (int);
49 static int excluded_rtx (int);
50 static void find_formats (void);
51 static void gendecl (const char *);
52 static void genmacro (int);
53 static void gendef (const char *);
54 static void genlegend (void);
55 static void genheader (void);
56 static void gencode (void);
57 44
58 /* Decode a format letter into a C type string. */ 45 /* Decode a format letter into a C type string. */
59 46
60 static const char * 47 static const char *
61 type_from_format (int c) 48 type_from_format (int c)
176 if (*f == 0) 163 if (*f == 0)
177 *f = defs[i].format; 164 *f = defs[i].format;
178 } 165 }
179 } 166 }
180 167
181 /* Write the declarations for the routine to allocate RTL with FORMAT. */
182
183 static void
184 gendecl (const char *format)
185 {
186 const char *p;
187 int i, pos;
188
189 printf ("extern rtx gen_rtx_fmt_%s_stat\t (RTX_CODE, ", format);
190 printf ("enum machine_mode mode");
191
192 /* Write each parameter that is needed and start a new line when the line
193 would overflow. */
194 for (p = format, i = 0, pos = 75; *p != 0; p++)
195 if (*p != '0')
196 {
197 int ourlen = strlen (type_from_format (*p)) + 6 + (i > 9);
198
199 printf (",");
200 if (pos + ourlen > 76)
201 printf ("\n\t\t\t\t "), pos = 39;
202
203 printf (" %sarg%d", type_from_format (*p), i++);
204 pos += ourlen;
205 }
206 printf (" MEM_STAT_DECL");
207
208 printf (");\n");
209 printf ("#define gen_rtx_fmt_%s(c, m", format);
210 for (p = format, i = 0; *p != 0; p++)
211 if (*p != '0')
212 printf (", p%i",i++);
213 printf (")\\\n gen_rtx_fmt_%s_stat (c, m", format);
214 for (p = format, i = 0; *p != 0; p++)
215 if (*p != '0')
216 printf (", p%i",i++);
217 printf (" MEM_STAT_INFO)\n\n");
218 }
219 168
220 /* Generate macros to generate RTL of code IDX using the functions we 169 /* Generate macros to generate RTL of code IDX using the functions we
221 write. */ 170 write. */
222 171
223 static void 172 static void
260 int i, j; 209 int i, j;
261 210
262 /* Start by writing the definition of the function name and the types 211 /* Start by writing the definition of the function name and the types
263 of the arguments. */ 212 of the arguments. */
264 213
265 printf ("rtx\ngen_rtx_fmt_%s_stat (RTX_CODE code, enum machine_mode mode", format); 214 printf ("static inline rtx\ngen_rtx_fmt_%s_stat (RTX_CODE code, enum machine_mode mode", format);
266 for (p = format, i = 0; *p != 0; p++) 215 for (p = format, i = 0; *p != 0; p++)
267 if (*p != '0') 216 if (*p != '0')
268 printf (",\n\t%sarg%d", type_from_format (*p), i++); 217 printf (",\n\t%sarg%d", type_from_format (*p), i++);
269 218
270 puts (" MEM_STAT_DECL)"); 219 puts (" MEM_STAT_DECL)");
282 printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p), i, j++); 231 printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p), i, j++);
283 else 232 else
284 printf (" X0EXP (rt, %d) = NULL_RTX;\n", i); 233 printf (" X0EXP (rt, %d) = NULL_RTX;\n", i);
285 234
286 puts ("\n return rt;\n}\n"); 235 puts ("\n return rt;\n}\n");
236 printf ("#define gen_rtx_fmt_%s(c, m", format);
237 for (p = format, i = 0; *p != 0; p++)
238 if (*p != '0')
239 printf (", p%i",i++);
240 printf (")\\\n gen_rtx_fmt_%s_stat (c, m", format);
241 for (p = format, i = 0; *p != 0; p++)
242 if (*p != '0')
243 printf (", p%i",i++);
244 printf (" MEM_STAT_INFO)\n\n");
287 } 245 }
288 246
289 /* Generate the documentation header for files we write. */ 247 /* Generate the documentation header for files we write. */
290 248
291 static void 249 static void
305 puts ("#ifndef GCC_GENRTL_H"); 263 puts ("#ifndef GCC_GENRTL_H");
306 puts ("#define GCC_GENRTL_H\n"); 264 puts ("#define GCC_GENRTL_H\n");
307 puts ("#include \"statistics.h\"\n"); 265 puts ("#include \"statistics.h\"\n");
308 266
309 for (fmt = formats; *fmt; ++fmt) 267 for (fmt = formats; *fmt; ++fmt)
310 gendecl (*fmt); 268 gendef (*fmt);
311 269
312 putchar ('\n'); 270 putchar ('\n');
313 271
314 for (i = 0; i < NUM_RTX_CODE; i++) 272 for (i = 0; i < NUM_RTX_CODE; i++)
315 if (! special_format (defs[i].format)) 273 if (! special_format (defs[i].format))
316 genmacro (i); 274 genmacro (i);
317 275
318 puts ("\n#endif /* GCC_GENRTL_H */"); 276 puts ("\n#endif /* GCC_GENRTL_H */");
319 } 277 }
320 278
321 /* Generate the text of the code file we write, genrtl.c. */ 279 /* This is the main program. */
322
323 static void
324 gencode (void)
325 {
326 const char **fmt;
327
328 puts ("#include \"config.h\"");
329 puts ("#include \"system.h\"");
330 puts ("#include \"coretypes.h\"");
331 puts ("#include \"tm.h\"");
332 puts ("#include \"obstack.h\"");
333 puts ("#include \"rtl.h\"");
334 puts ("#include \"ggc.h\"\n");
335
336 for (fmt = formats; *fmt != 0; fmt++)
337 gendef (*fmt);
338 }
339
340 /* This is the main program. We accept only one argument, "-h", which
341 says we are writing the genrtl.h file. Otherwise we are writing the
342 genrtl.c file. */
343 280
344 int 281 int
345 main (int argc, char **argv) 282 main (void)
346 { 283 {
347 find_formats (); 284 find_formats ();
348 genlegend (); 285 genlegend ();
349 286
350 if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h') 287 genheader ();
351 genheader ();
352 else
353 gencode ();
354 288
355 if (ferror (stdout) || fflush (stdout) || fclose (stdout)) 289 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
356 return FATAL_EXIT_CODE; 290 return FATAL_EXIT_CODE;
357 291
358 return SUCCESS_EXIT_CODE; 292 return SUCCESS_EXIT_CODE;