2015-08-04 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / gcc / genattr-common.c
blob0ff8da984dd7f7c030658877528cd22e3f138056
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-2015 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #include "bconfig.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "errors.h"
29 #include "read-md.h"
30 #include "gensupport.h"
32 static void
33 write_upcase (const char *str)
35 for (; *str; str++)
36 putchar (TOUPPER (*str));
39 static void
40 gen_attr (md_rtx_info *info)
42 const char *p, *tag;
44 rtx attr = info->def;
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 bool have_delay = false;
67 bool have_sched = false;
69 progname = "genattr-common";
71 if (!init_rtx_reader_args (argc, argv))
72 return (FATAL_EXIT_CODE);
74 puts ("/* Generated automatically by the program `genattr-common'");
75 puts (" from the machine description file `md'. */\n");
76 puts ("#ifndef GCC_INSN_ATTR_COMMON_H");
77 puts ("#define GCC_INSN_ATTR_COMMON_H\n");
79 /* Read the machine description. */
81 md_rtx_info info;
82 while (read_md_rtx (&info))
83 switch (GET_CODE (info.def))
85 case DEFINE_ATTR:
86 gen_attr (&info);
87 break;
89 case DEFINE_DELAY:
90 if (!have_delay)
92 printf ("#define DELAY_SLOTS\n");
93 have_delay = true;
95 break;
97 case DEFINE_INSN_RESERVATION:
98 if (!have_sched)
100 printf ("#define INSN_SCHEDULING\n");
101 have_sched = true;
103 break;
105 default:
106 break;
108 puts ("\n#endif /* GCC_INSN_ATTR_COMMON_H */");
110 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
111 return FATAL_EXIT_CODE;
113 return SUCCESS_EXIT_CODE;