1 /* Generate from machine description:
2 - some flags HAVE_... saying which simple standard instructions are
3 available for this machine.
4 Copyright (C) 1987-2020 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
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
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/>. */
25 #include "coretypes.h"
31 #include "gensupport.h"
33 /* Obstack to remember insns with. */
34 static struct obstack obstack
;
36 /* Max size of names encountered. */
37 static int max_id_len
;
39 /* Max operand encountered in a scan over some insn. */
42 static void max_operand_1 (rtx
);
43 static int num_operands (rtx
);
44 static void gen_proto (rtx
);
46 /* Count the number of match_operand's found. */
61 if (code
== MATCH_OPERAND
|| code
== MATCH_OPERATOR
62 || code
== MATCH_PARALLEL
)
63 max_opno
= MAX (max_opno
, XINT (x
, 0));
65 fmt
= GET_RTX_FORMAT (code
);
66 len
= GET_RTX_LENGTH (code
);
67 for (i
= 0; i
< len
; i
++)
69 if (fmt
[i
] == 'e' || fmt
[i
] == 'u')
70 max_operand_1 (XEXP (x
, i
));
71 else if (fmt
[i
] == 'E')
74 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
75 max_operand_1 (XVECEXP (x
, i
, j
));
81 num_operands (rtx insn
)
83 int len
= XVECLEN (insn
, 1);
88 for (i
= 0; i
< len
; i
++)
89 max_operand_1 (XVECEXP (insn
, 1, i
));
94 /* Print out prototype information for a generator function. If the
95 insn pattern has been elided, print out a dummy generator that
101 int num
= num_operands (insn
);
103 const char *name
= XSTR (insn
, 0);
104 int truth
= maybe_eval_c_test (XSTR (insn
, 2));
107 printf ("extern rtx gen_%-*s (", max_id_len
, name
);
109 printf ("static inline rtx gen_%-*s (", max_id_len
, name
);
112 fputs ("void", stdout
);
115 for (i
= 1; i
< num
; i
++)
116 fputs ("rtx, ", stdout
);
118 fputs ("rtx", stdout
);
123 /* Some back ends want to take the address of generator functions,
124 so we cannot simply use #define for these dummy definitions. */
127 printf ("static inline rtx\ngen_%s", name
);
131 for (i
= 0; i
< num
-1; i
++)
132 printf ("rtx ARG_UNUSED (%c), ", 'a' + i
);
133 printf ("rtx ARG_UNUSED (%c))\n", 'a' + i
);
137 puts ("{\n return 0;\n}");
143 gen_insn (md_rtx_info
*info
)
145 rtx insn
= info
->def
;
146 const char *name
= XSTR (insn
, 0);
150 int truth
= maybe_eval_c_test (XSTR (insn
, 2));
152 lt
= strchr (name
, '<');
153 if (lt
&& strchr (lt
+ 1, '>'))
155 error_at (info
->loc
, "unresolved iterator");
159 gt
= strchr (name
, '>');
162 error_at (info
->loc
, "unmatched angle brackets, likely "
163 "an error in iterator syntax");
167 /* Don't mention instructions whose names are the null string
168 or begin with '*'. They are in the machine description just
170 if (name
[0] == 0 || name
[0] == '*')
175 if (len
> max_id_len
)
181 printf ("#define HAVE_%s 1\n", name
);
184 /* Write the macro definition, putting \'s at the end of each line,
186 printf ("#define HAVE_%s (", name
);
187 for (p
= XSTR (insn
, 2); *p
; p
++)
190 fputs (" \\\n", stdout
);
194 fputs (")\n", stdout
);
197 obstack_grow (&obstack
, &insn
, sizeof (rtx
));
201 main (int argc
, const char **argv
)
207 progname
= "genflags";
208 obstack_init (&obstack
);
210 /* We need to see all the possibilities. Elided insns may have
211 direct calls to their generators in C code. */
214 if (!init_rtx_reader_args (argc
, argv
))
215 return (FATAL_EXIT_CODE
);
217 puts ("/* Generated automatically by the program `genflags'");
218 puts (" from the machine description file `md'. */\n");
219 puts ("#ifndef GCC_INSN_FLAGS_H");
220 puts ("#define GCC_INSN_FLAGS_H\n");
222 /* Read the machine description. */
225 while (read_md_rtx (&info
))
226 switch (GET_CODE (info
.def
))
237 /* Print out the prototypes now. */
239 obstack_grow (&obstack
, &dummy
, sizeof (rtx
));
240 insns
= XOBFINISH (&obstack
, rtx
*);
242 for (insn_ptr
= insns
; *insn_ptr
; insn_ptr
++)
243 gen_proto (*insn_ptr
);
245 puts ("\n#endif /* GCC_INSN_FLAGS_H */");
247 if (have_error
|| ferror (stdout
) || fflush (stdout
) || fclose (stdout
))
248 return FATAL_EXIT_CODE
;
250 return SUCCESS_EXIT_CODE
;