00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "hconfig.h"
00030 #include "system.h"
00031 #include "rtl.h"
00032 #include "obstack.h"
00033 #include "errors.h"
00034 #include "gensupport.h"
00035
00036
00037 static struct obstack obstack;
00038
00039
00040 static int max_id_len;
00041
00042
00043 static int max_opno;
00044
00045 static void max_operand_1 PARAMS ((rtx));
00046 static int num_operands PARAMS ((rtx));
00047 static void gen_proto PARAMS ((rtx));
00048 static void gen_macro PARAMS ((const char *, int, int));
00049 static void gen_insn PARAMS ((rtx));
00050
00051
00052
00053 static void
00054 max_operand_1 (x)
00055 rtx x;
00056 {
00057 RTX_CODE code;
00058 int i;
00059 int len;
00060 const char *fmt;
00061
00062 if (x == 0)
00063 return;
00064
00065 code = GET_CODE (x);
00066
00067 if (code == MATCH_OPERAND || code == MATCH_OPERATOR
00068 || code == MATCH_PARALLEL)
00069 max_opno = MAX (max_opno, XINT (x, 0));
00070
00071 fmt = GET_RTX_FORMAT (code);
00072 len = GET_RTX_LENGTH (code);
00073 for (i = 0; i < len; i++)
00074 {
00075 if (fmt[i] == 'e' || fmt[i] == 'u')
00076 max_operand_1 (XEXP (x, i));
00077 else if (fmt[i] == 'E')
00078 {
00079 int j;
00080 for (j = 0; j < XVECLEN (x, i); j++)
00081 max_operand_1 (XVECEXP (x, i, j));
00082 }
00083 }
00084 }
00085
00086 static int
00087 num_operands (insn)
00088 rtx insn;
00089 {
00090 int len = XVECLEN (insn, 1);
00091 int i;
00092
00093 max_opno = -1;
00094
00095 for (i = 0; i < len; i++)
00096 max_operand_1 (XVECEXP (insn, 1, i));
00097
00098 return max_opno + 1;
00099 }
00100
00101
00102
00103
00104 static void
00105 gen_macro (name, real, expect)
00106 const char *name;
00107 int real, expect;
00108 {
00109 int i;
00110
00111 if (real > expect)
00112 abort ();
00113 if (real == 0)
00114 abort ();
00115
00116
00117 fputs ("#define GEN_", stdout);
00118 for (i = 0; name[i]; i++)
00119 putchar (TOUPPER (name[i]));
00120
00121 putchar('(');
00122 for (i = 0; i < expect - 1; i++)
00123 printf ("%c, ", i + 'A');
00124 printf ("%c) gen_%s (", i + 'A', name);
00125
00126 for (i = 0; i < real - 1; i++)
00127 printf ("(%c), ", i + 'A');
00128 printf ("(%c))\n", i + 'A');
00129 }
00130
00131
00132
00133
00134
00135 static void
00136 gen_proto (insn)
00137 rtx insn;
00138 {
00139 int num = num_operands (insn);
00140 int i;
00141 const char *name = XSTR (insn, 0);
00142 int truth = maybe_eval_c_test (XSTR (insn, 2));
00143
00144
00145
00146
00147
00148
00149 if (name[0] == 'c' || name[0] == 's')
00150 {
00151 if (!strcmp (name, "call")
00152 || !strcmp (name, "call_pop")
00153 || !strcmp (name, "sibcall")
00154 || !strcmp (name, "sibcall_pop"))
00155 gen_macro (name, num, 4);
00156 else if (!strcmp (name, "call_value")
00157 || !strcmp (name, "call_value_pop")
00158 || !strcmp (name, "sibcall_value")
00159 || !strcmp (name, "sibcall_value_pop"))
00160 gen_macro (name, num, 5);
00161 }
00162
00163 if (truth != 0)
00164 printf ("extern rtx gen_%-*s PARAMS ((", max_id_len, name);
00165 else
00166 printf ("static inline rtx gen_%-*s PARAMS ((", max_id_len, name);
00167
00168 if (num == 0)
00169 fputs ("void", stdout);
00170 else
00171 {
00172 for (i = 1; i < num; i++)
00173 fputs ("rtx, ", stdout);
00174
00175 fputs ("rtx", stdout);
00176 }
00177
00178 puts ("));");
00179
00180
00181
00182 if (truth == 0)
00183 {
00184 printf ("static inline rtx\ngen_%s", name);
00185 if (num > 0)
00186 {
00187 putchar ('(');
00188 for (i = 0; i < num-1; i++)
00189 printf ("%c, ", 'a' + i);
00190 printf ("%c)\n", 'a' + i);
00191 for (i = 0; i < num; i++)
00192 printf (" rtx %c ATTRIBUTE_UNUSED;\n", 'a' + i);
00193 }
00194 else
00195 puts ("()");
00196 puts ("{\n return 0;\n}");
00197 }
00198
00199 }
00200
00201 static void
00202 gen_insn (insn)
00203 rtx insn;
00204 {
00205 const char *name = XSTR (insn, 0);
00206 const char *p;
00207 int len;
00208 int truth = maybe_eval_c_test (XSTR (insn, 2));
00209
00210
00211
00212
00213 if (name[0] == 0 || name[0] == '*')
00214 return;
00215
00216 len = strlen (name);
00217
00218 if (len > max_id_len)
00219 max_id_len = len;
00220
00221 if (truth == 0)
00222 ;
00223 else if (truth == 1)
00224 printf ("#define HAVE_%s 1\n", name);
00225 else
00226 {
00227
00228
00229 printf ("#define HAVE_%s (", name);
00230 for (p = XSTR (insn, 2); *p; p++)
00231 {
00232 #ifndef SGI_MONGOOSE
00233 if (IS_VSPACE (*p))
00234 #else
00235 if (*p == '\n')
00236 #endif
00237 fputs (" \\\n", stdout);
00238 else
00239 putchar (*p);
00240 }
00241 fputs (")\n", stdout);
00242 }
00243
00244 obstack_grow (&obstack, &insn, sizeof (rtx));
00245 }
00246
00247 extern int main PARAMS ((int, char **));
00248
00249 int
00250 main (argc, argv)
00251 int argc;
00252 char **argv;
00253 {
00254 rtx desc;
00255 rtx dummy;
00256 rtx *insns;
00257 rtx *insn_ptr;
00258
00259 progname = "genflags";
00260 obstack_init (&obstack);
00261
00262
00263
00264 insn_elision = 0;
00265
00266 if (argc <= 1)
00267 fatal ("no input file name");
00268
00269 if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
00270 return (FATAL_EXIT_CODE);
00271
00272 puts ("/* Generated automatically by the program `genflags'");
00273 puts (" from the machine description file `md'. */\n");
00274 puts ("#ifndef GCC_INSN_FLAGS_H");
00275 puts ("#define GCC_INSN_FLAGS_H\n");
00276
00277
00278
00279 while (1)
00280 {
00281 int line_no, insn_code_number = 0;
00282
00283 desc = read_md_rtx (&line_no, &insn_code_number);
00284 if (desc == NULL)
00285 break;
00286 if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
00287 gen_insn (desc);
00288 }
00289
00290
00291 dummy = (rtx) 0;
00292 obstack_grow (&obstack, &dummy, sizeof (rtx));
00293 insns = (rtx *) obstack_finish (&obstack);
00294
00295 for (insn_ptr = insns; *insn_ptr; insn_ptr++)
00296 gen_proto (*insn_ptr);
00297
00298 puts("\n#endif /* GCC_INSN_FLAGS_H */");
00299
00300 if (ferror (stdout) || fflush (stdout) || fclose (stdout))
00301 return FATAL_EXIT_CODE;
00302
00303 return SUCCESS_EXIT_CODE;
00304 }
00305
00306
00307 const char *
00308 get_insn_name (code)
00309 int code ATTRIBUTE_UNUSED;
00310 {
00311 return NULL;
00312 }