1 /* Generate from machine description:
2 - some flags HAVE_... saying which simple standard instructions are
3 available for this machine.
4 Copyright (C) 1987, 1991, 1995, 1998,
5 1999, 2000, 2003, 2004 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 2, or (at your option) any later
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
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "coretypes.h"
32 #include "gensupport.h"
34 /* Obstack to remember insns with. */
35 static struct obstack obstack
;
37 /* Max size of names encountered. */
38 static int max_id_len
;
40 /* Max operand encountered in a scan over some insn. */
43 static void max_operand_1 (rtx
);
44 static int num_operands (rtx
);
45 static void gen_proto (rtx
);
46 static void gen_macro (const char *, int, int);
47 static void gen_insn (rtx
);
49 /* Count the number of match_operand's found. */
64 if (code
== MATCH_OPERAND
|| code
== MATCH_OPERATOR
65 || code
== MATCH_PARALLEL
)
66 max_opno
= MAX (max_opno
, XINT (x
, 0));
68 fmt
= GET_RTX_FORMAT (code
);
69 len
= GET_RTX_LENGTH (code
);
70 for (i
= 0; i
< len
; i
++)
72 if (fmt
[i
] == 'e' || fmt
[i
] == 'u')
73 max_operand_1 (XEXP (x
, i
));
74 else if (fmt
[i
] == 'E')
77 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
78 max_operand_1 (XVECEXP (x
, i
, j
));
84 num_operands (rtx insn
)
86 int len
= XVECLEN (insn
, 1);
91 for (i
= 0; i
< len
; i
++)
92 max_operand_1 (XVECEXP (insn
, 1, i
));
97 /* Print out a wrapper macro for a function which corrects the number
98 of arguments it takes. Any missing arguments are assumed to be at
101 gen_macro (const char *name
, int real
, int expect
)
105 gcc_assert (real
<= expect
);
108 /* #define GEN_CALL(A, B, C, D) gen_call((A), (B)) */
109 fputs ("#define GEN_", stdout
);
110 for (i
= 0; name
[i
]; i
++)
111 putchar (TOUPPER (name
[i
]));
114 for (i
= 0; i
< expect
- 1; i
++)
115 printf ("%c, ", i
+ 'A');
116 printf ("%c) gen_%s (", i
+ 'A', name
);
118 for (i
= 0; i
< real
- 1; i
++)
119 printf ("(%c), ", i
+ 'A');
120 printf ("(%c))\n", i
+ 'A');
123 /* Print out prototype information for a generator function. If the
124 insn pattern has been elided, print out a dummy generator that
130 int num
= num_operands (insn
);
132 const char *name
= XSTR (insn
, 0);
133 int truth
= maybe_eval_c_test (XSTR (insn
, 2));
135 /* Many md files don't refer to the last two operands passed to the
136 call patterns. This means their generator functions will be two
137 arguments too short. Instead of changing every md file to touch
138 those operands, we wrap the prototypes in macros that take the
139 correct number of arguments. */
140 if (name
[0] == 'c' || name
[0] == 's')
142 if (!strcmp (name
, "call")
143 || !strcmp (name
, "call_pop")
144 || !strcmp (name
, "sibcall")
145 || !strcmp (name
, "sibcall_pop"))
146 gen_macro (name
, num
, 4);
147 else if (!strcmp (name
, "call_value")
148 || !strcmp (name
, "call_value_pop")
149 || !strcmp (name
, "sibcall_value")
150 || !strcmp (name
, "sibcall_value_pop"))
151 gen_macro (name
, num
, 5);
155 printf ("extern rtx gen_%-*s (", max_id_len
, name
);
157 printf ("static inline rtx gen_%-*s (", max_id_len
, name
);
160 fputs ("void", stdout
);
163 for (i
= 1; i
< num
; i
++)
164 fputs ("rtx, ", stdout
);
166 fputs ("rtx", stdout
);
171 /* Some back ends want to take the address of generator functions,
172 so we cannot simply use #define for these dummy definitions. */
175 printf ("static inline rtx\ngen_%s", name
);
179 for (i
= 0; i
< num
-1; i
++)
180 printf ("rtx ARG_UNUSED (%c), ", 'a' + i
);
181 printf ("rtx ARG_UNUSED (%c))\n", 'a' + i
);
185 puts ("{\n return 0;\n}");
193 const char *name
= XSTR (insn
, 0);
196 int truth
= maybe_eval_c_test (XSTR (insn
, 2));
198 /* Don't mention instructions whose names are the null string
199 or begin with '*'. They are in the machine description just
201 if (name
[0] == 0 || name
[0] == '*')
206 if (len
> max_id_len
)
212 printf ("#define HAVE_%s 1\n", name
);
215 /* Write the macro definition, putting \'s at the end of each line,
217 printf ("#define HAVE_%s (", name
);
218 for (p
= XSTR (insn
, 2); *p
; p
++)
221 fputs (" \\\n", stdout
);
225 fputs (")\n", stdout
);
228 obstack_grow (&obstack
, &insn
, sizeof (rtx
));
232 main (int argc
, char **argv
)
239 progname
= "genflags";
240 obstack_init (&obstack
);
242 /* We need to see all the possibilities. Elided insns may have
243 direct calls to their generators in C code. */
246 if (init_md_reader_args (argc
, argv
) != SUCCESS_EXIT_CODE
)
247 return (FATAL_EXIT_CODE
);
249 puts ("/* Generated automatically by the program `genflags'");
250 puts (" from the machine description file `md'. */\n");
251 puts ("#ifndef GCC_INSN_FLAGS_H");
252 puts ("#define GCC_INSN_FLAGS_H\n");
254 /* Read the machine description. */
258 int line_no
, insn_code_number
= 0;
260 desc
= read_md_rtx (&line_no
, &insn_code_number
);
263 if (GET_CODE (desc
) == DEFINE_INSN
|| GET_CODE (desc
) == DEFINE_EXPAND
)
267 /* Print out the prototypes now. */
269 obstack_grow (&obstack
, &dummy
, sizeof (rtx
));
270 insns
= XOBFINISH (&obstack
, rtx
*);
272 for (insn_ptr
= insns
; *insn_ptr
; insn_ptr
++)
273 gen_proto (*insn_ptr
);
275 puts("\n#endif /* GCC_INSN_FLAGS_H */");
277 if (ferror (stdout
) || fflush (stdout
) || fclose (stdout
))
278 return FATAL_EXIT_CODE
;
280 return SUCCESS_EXIT_CODE
;
283 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
285 get_insn_name (int ARG_UNUSED (code
))