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