]>
Commit | Line | Data |
---|---|---|
3439974c | 1 | /* Generate from machine description: |
3439974c | 2 | - some flags HAVE_... saying which simple standard instructions are |
3 | available for this machine. | |
fbd26352 | 4 | Copyright (C) 1987-2019 Free Software Foundation, Inc. |
3439974c | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
3439974c | 7 | |
f12b58b3 | 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 | |
8c4c00c1 | 10 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 11 | version. |
3439974c | 12 | |
f12b58b3 | 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. | |
3439974c | 17 | |
18 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
3439974c | 21 | |
22 | ||
805e22b2 | 23 | #include "bconfig.h" |
5ce88198 | 24 | #include "system.h" |
805e22b2 | 25 | #include "coretypes.h" |
26 | #include "tm.h" | |
3439974c | 27 | #include "rtl.h" |
28 | #include "obstack.h" | |
04b58880 | 29 | #include "errors.h" |
960ebfe7 | 30 | #include "read-md.h" |
c5ddd6b5 | 31 | #include "gensupport.h" |
3439974c | 32 | |
2ed6c343 | 33 | /* Obstack to remember insns with. */ |
34 | static struct obstack obstack; | |
fb084c16 | 35 | |
36 | /* Max size of names encountered. */ | |
37 | static int max_id_len; | |
38 | ||
0d2d46ac | 39 | /* Max operand encountered in a scan over some insn. */ |
40 | static int max_opno; | |
12693c81 | 41 | |
1a97be37 | 42 | static void max_operand_1 (rtx); |
43 | static int num_operands (rtx); | |
44 | static void gen_proto (rtx); | |
12693c81 | 45 | |
fb084c16 | 46 | /* Count the number of match_operand's found. */ |
a92771b8 | 47 | |
0d2d46ac | 48 | static void |
1a97be37 | 49 | max_operand_1 (rtx x) |
fb084c16 | 50 | { |
19cb6b50 | 51 | RTX_CODE code; |
52 | int i; | |
53 | int len; | |
54 | const char *fmt; | |
fb084c16 | 55 | |
0d2d46ac | 56 | if (x == 0) |
57 | return; | |
fb084c16 | 58 | |
0d2d46ac | 59 | code = GET_CODE (x); |
fb084c16 | 60 | |
0d2d46ac | 61 | if (code == MATCH_OPERAND || code == MATCH_OPERATOR |
62 | || code == MATCH_PARALLEL) | |
63 | max_opno = MAX (max_opno, XINT (x, 0)); | |
64 | ||
65 | fmt = GET_RTX_FORMAT (code); | |
66 | len = GET_RTX_LENGTH (code); | |
67 | for (i = 0; i < len; i++) | |
fb084c16 | 68 | { |
0d2d46ac | 69 | if (fmt[i] == 'e' || fmt[i] == 'u') |
70 | max_operand_1 (XEXP (x, i)); | |
71 | else if (fmt[i] == 'E') | |
fb084c16 | 72 | { |
0d2d46ac | 73 | int j; |
74 | for (j = 0; j < XVECLEN (x, i); j++) | |
75 | max_operand_1 (XVECEXP (x, i, j)); | |
fb084c16 | 76 | } |
77 | } | |
0d2d46ac | 78 | } |
fb084c16 | 79 | |
0d2d46ac | 80 | static int |
1a97be37 | 81 | num_operands (rtx insn) |
0d2d46ac | 82 | { |
19cb6b50 | 83 | int len = XVECLEN (insn, 1); |
84 | int i; | |
0d2d46ac | 85 | |
86 | max_opno = -1; | |
87 | ||
88 | for (i = 0; i < len; i++) | |
89 | max_operand_1 (XVECEXP (insn, 1, i)); | |
90 | ||
91 | return max_opno + 1; | |
fb084c16 | 92 | } |
93 | ||
b70bd542 | 94 | /* Print out prototype information for a generator function. If the |
95 | insn pattern has been elided, print out a dummy generator that | |
96 | does nothing. */ | |
a92771b8 | 97 | |
fb084c16 | 98 | static void |
1a97be37 | 99 | gen_proto (rtx insn) |
fb084c16 | 100 | { |
101 | int num = num_operands (insn); | |
b70bd542 | 102 | int i; |
2ed6c343 | 103 | const char *name = XSTR (insn, 0); |
b70bd542 | 104 | int truth = maybe_eval_c_test (XSTR (insn, 2)); |
2ed6c343 | 105 | |
b70bd542 | 106 | if (truth != 0) |
1a97be37 | 107 | printf ("extern rtx gen_%-*s (", max_id_len, name); |
b70bd542 | 108 | else |
1a97be37 | 109 | printf ("static inline rtx gen_%-*s (", max_id_len, name); |
fb084c16 | 110 | |
111 | if (num == 0) | |
b70bd542 | 112 | fputs ("void", stdout); |
fb084c16 | 113 | else |
114 | { | |
b70bd542 | 115 | for (i = 1; i < num; i++) |
116 | fputs ("rtx, ", stdout); | |
1a97be37 | 117 | |
b70bd542 | 118 | fputs ("rtx", stdout); |
fb084c16 | 119 | } |
120 | ||
1a97be37 | 121 | puts (");"); |
b70bd542 | 122 | |
123 | /* Some back ends want to take the address of generator functions, | |
124 | so we cannot simply use #define for these dummy definitions. */ | |
125 | if (truth == 0) | |
126 | { | |
127 | printf ("static inline rtx\ngen_%s", name); | |
128 | if (num > 0) | |
129 | { | |
130 | putchar ('('); | |
131 | for (i = 0; i < num-1; i++) | |
9a03a746 | 132 | printf ("rtx ARG_UNUSED (%c), ", 'a' + i); |
133 | printf ("rtx ARG_UNUSED (%c))\n", 'a' + i); | |
b70bd542 | 134 | } |
135 | else | |
f82b06e0 | 136 | puts ("(void)"); |
b70bd542 | 137 | puts ("{\n return 0;\n}"); |
138 | } | |
fb084c16 | 139 | |
fb084c16 | 140 | } |
141 | ||
3439974c | 142 | static void |
c04601c1 | 143 | gen_insn (md_rtx_info *info) |
3439974c | 144 | { |
c04601c1 | 145 | rtx insn = info->def; |
9a356c3c | 146 | const char *name = XSTR (insn, 0); |
147 | const char *p; | |
cbb955b0 | 148 | const char *lt, *gt; |
fb084c16 | 149 | int len; |
b70bd542 | 150 | int truth = maybe_eval_c_test (XSTR (insn, 2)); |
3439974c | 151 | |
48e1416a | 152 | lt = strchr (name, '<'); |
cbb955b0 | 153 | if (lt && strchr (lt + 1, '>')) |
154 | { | |
c04601c1 | 155 | error_at (info->loc, "unresolved iterator"); |
cbb955b0 | 156 | return; |
157 | } | |
158 | ||
48e1416a | 159 | gt = strchr (name, '>'); |
cbb955b0 | 160 | if (lt || gt) |
161 | { | |
c04601c1 | 162 | error_at (info->loc, "unmatched angle brackets, likely " |
163 | "an error in iterator syntax"); | |
cbb955b0 | 164 | return; |
165 | } | |
166 | ||
a0761610 | 167 | /* Don't mention instructions whose names are the null string |
168 | or begin with '*'. They are in the machine description just | |
169 | to be recognized. */ | |
170 | if (name[0] == 0 || name[0] == '*') | |
3439974c | 171 | return; |
172 | ||
a0761610 | 173 | len = strlen (name); |
174 | ||
fb084c16 | 175 | if (len > max_id_len) |
176 | max_id_len = len; | |
177 | ||
b70bd542 | 178 | if (truth == 0) |
21dda4ee | 179 | /* Emit nothing. */; |
b70bd542 | 180 | else if (truth == 1) |
181 | printf ("#define HAVE_%s 1\n", name); | |
3439974c | 182 | else |
183 | { | |
184 | /* Write the macro definition, putting \'s at the end of each line, | |
185 | if more than one. */ | |
b70bd542 | 186 | printf ("#define HAVE_%s (", name); |
3439974c | 187 | for (p = XSTR (insn, 2); *p; p++) |
188 | { | |
337057dd | 189 | if (IS_VSPACE (*p)) |
b70bd542 | 190 | fputs (" \\\n", stdout); |
3439974c | 191 | else |
b70bd542 | 192 | putchar (*p); |
3439974c | 193 | } |
b70bd542 | 194 | fputs (")\n", stdout); |
3439974c | 195 | } |
5ba9164e | 196 | |
2ed6c343 | 197 | obstack_grow (&obstack, &insn, sizeof (rtx)); |
3439974c | 198 | } |
3439974c | 199 | |
3439974c | 200 | int |
16570c04 | 201 | main (int argc, const char **argv) |
3439974c | 202 | { |
fb084c16 | 203 | rtx dummy; |
2ed6c343 | 204 | rtx *insns; |
fb084c16 | 205 | rtx *insn_ptr; |
3439974c | 206 | |
04b58880 | 207 | progname = "genflags"; |
2ed6c343 | 208 | obstack_init (&obstack); |
3439974c | 209 | |
b70bd542 | 210 | /* We need to see all the possibilities. Elided insns may have |
211 | direct calls to their generators in C code. */ | |
212 | insn_elision = 0; | |
213 | ||
77ba95d0 | 214 | if (!init_rtx_reader_args (argc, argv)) |
c5ddd6b5 | 215 | return (FATAL_EXIT_CODE); |
1a97be37 | 216 | |
d0c809e1 | 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"); | |
3439974c | 221 | |
222 | /* Read the machine description. */ | |
223 | ||
c04601c1 | 224 | md_rtx_info info; |
225 | while (read_md_rtx (&info)) | |
226 | switch (GET_CODE (info.def)) | |
227 | { | |
228 | case DEFINE_INSN: | |
229 | case DEFINE_EXPAND: | |
230 | gen_insn (&info); | |
231 | break; | |
3439974c | 232 | |
c04601c1 | 233 | default: |
c5ddd6b5 | 234 | break; |
c04601c1 | 235 | } |
3439974c | 236 | |
fb084c16 | 237 | /* Print out the prototypes now. */ |
a92771b8 | 238 | dummy = (rtx) 0; |
2ed6c343 | 239 | obstack_grow (&obstack, &dummy, sizeof (rtx)); |
4fac984f | 240 | insns = XOBFINISH (&obstack, rtx *); |
fb084c16 | 241 | |
2ed6c343 | 242 | for (insn_ptr = insns; *insn_ptr; insn_ptr++) |
fb084c16 | 243 | gen_proto (*insn_ptr); |
244 | ||
9af5ce0c | 245 | puts ("\n#endif /* GCC_INSN_FLAGS_H */"); |
d0c809e1 | 246 | |
cbb955b0 | 247 | if (have_error || ferror (stdout) || fflush (stdout) || fclose (stdout)) |
d0c809e1 | 248 | return FATAL_EXIT_CODE; |
249 | ||
250 | return SUCCESS_EXIT_CODE; | |
3439974c | 251 | } |