Fix a bug that broke -freorder-functions
[official-gcc.git] / gcc / genattr-common.c
blobd219fd1e613e58396173605d439aeea901720456
1 /* Generate attribute information shared between driver and core
2 compilers (insn-attr-common.h) from machine description. Split out
3 of genattr.c.
4 Copyright (C) 1991, 1994, 1996, 1998, 1999, 2000, 2003, 2004, 2007, 2008,
5 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 #include "bconfig.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "errors.h"
30 #include "read-md.h"
31 #include "gensupport.h"
33 static void
34 write_upcase (const char *str)
36 for (; *str; str++)
37 putchar (TOUPPER(*str));
40 static void
41 gen_attr (rtx attr)
43 const char *p, *tag;
45 p = XSTR (attr, 1);
46 if (*p != '\0')
48 printf ("enum attr_%s {", XSTR (attr, 0));
50 while ((tag = scan_comma_elt (&p)) != 0)
52 write_upcase (XSTR (attr, 0));
53 putchar ('_');
54 while (tag != p)
55 putchar (TOUPPER (*tag++));
56 if (*p == ',')
57 fputs (", ", stdout);
59 fputs ("};\n", stdout);
63 int
64 main (int argc, char **argv)
66 rtx desc;
67 bool have_delay = false;
68 bool have_sched = false;
70 progname = "genattr-common";
72 if (!init_rtx_reader_args (argc, argv))
73 return (FATAL_EXIT_CODE);
75 puts ("/* Generated automatically by the program `genattr-common'");
76 puts (" from the machine description file `md'. */\n");
77 puts ("#ifndef GCC_INSN_ATTR_COMMON_H");
78 puts ("#define GCC_INSN_ATTR_COMMON_H\n");
80 /* Read the machine description. */
82 while (1)
84 int line_no, insn_code_number;
86 desc = read_md_rtx (&line_no, &insn_code_number);
87 if (desc == NULL)
88 break;
90 if (GET_CODE (desc) == DEFINE_ATTR)
91 gen_attr (desc);
93 if (GET_CODE (desc) == DEFINE_DELAY)
95 if (!have_delay)
97 printf ("#define DELAY_SLOTS\n");
98 have_delay = true;
101 else if (GET_CODE (desc) == DEFINE_INSN_RESERVATION)
103 if (!have_sched)
105 printf ("#define INSN_SCHEDULING\n");
106 have_sched = true;
110 puts ("\n#endif /* GCC_INSN_ATTR_COMMON_H */");
112 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
113 return FATAL_EXIT_CODE;
115 return SUCCESS_EXIT_CODE;