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 "errors.h"
00033 #include "hashtab.h"
00034 #include "gensupport.h"
00035
00036
00037 static int saw_eh_return;
00038
00039 static htab_t condition_table;
00040
00041 static void add_condition PARAMS ((const char *));
00042 static void write_header PARAMS ((void));
00043 static void write_conditions PARAMS ((void));
00044 static int write_one_condition PARAMS ((PTR *, PTR));
00045
00046 extern int main PARAMS ((int, char **));
00047
00048
00049
00050
00051
00052 static void
00053 add_condition (expr)
00054 const char *expr;
00055 {
00056 struct c_test *test;
00057
00058 if (expr[0] == 0)
00059 return;
00060
00061 test = (struct c_test *) xmalloc (sizeof (struct c_test));
00062 test->expr = expr;
00063
00064 *(htab_find_slot (condition_table, test, INSERT)) = test;
00065 }
00066
00067
00068
00069 static void
00070 write_header ()
00071 {
00072 puts ("\
00073 /* Generated automatically by the program `genconditions' from the target\n\
00074 machine description file. */\n\
00075 \n\
00076 #include \"hconfig.h\"\n\
00077 #include \"insn-constants.h\"\n");
00078
00079 puts ("\
00080 /* Do not allow checking to confuse the issue. */\n\
00081 #undef ENABLE_CHECKING\n\
00082 #undef ENABLE_TREE_CHECKING\n\
00083 #undef ENABLE_RTL_CHECKING\n\
00084 #undef ENABLE_RTL_FLAG_CHECKING\n\
00085 #undef ENABLE_GC_CHECKING\n\
00086 #undef ENABLE_GC_ALWAYS_COLLECT\n");
00087
00088 puts ("\
00089 #include \"system.h\"\n\
00090 #include \"rtl.h\"\n\
00091 #include \"tm_p.h\"\n\
00092 #include \"function.h\"\n");
00093
00094 puts ("\
00095 /* Fake - insn-config.h doesn't exist yet. */\n\
00096 #define MAX_RECOG_OPERANDS 10\n\
00097 #define MAX_DUP_OPERANDS 10\n\
00098 #define MAX_INSNS_PER_SPLIT 5\n");
00099
00100 puts ("\
00101 #include \"regs.h\"\n\
00102 #include \"recog.h\"\n\
00103 #include \"real.h\"\n\
00104 #include \"output.h\"\n\
00105 #include \"flags.h\"\n\
00106 #include \"hard-reg-set.h\"\n\
00107 #include \"resource.h\"\n\
00108 #include \"toplev.h\"\n\
00109 #include \"reload.h\"\n\
00110 #include \"gensupport.h\"\n");
00111
00112 if (saw_eh_return)
00113 puts ("#define HAVE_eh_return 1");
00114 puts ("#include \"except.h\"\n");
00115
00116 puts ("\
00117 /* Dummy external declarations. */\n\
00118 extern rtx insn;\n\
00119 extern rtx ins1;\n\
00120 extern rtx operands[];\n\
00121 extern int next_insn_tests_no_inequality PARAMS ((rtx));\n");
00122
00123 puts ("\
00124 /* If we don't have __builtin_constant_p, or it's not acceptable in\n\
00125 array initializers, fall back to assuming that all conditions\n\
00126 potentially vary at run time. It works in 3.0.1 and later; 3.0\n\
00127 only when not optimizing. */\n\
00128 #if (GCC_VERSION >= 3001) || ((GCC_VERSION == 3000) && !__OPTIMIZE__)\n\
00129 # define MAYBE_EVAL(expr) (__builtin_constant_p(expr) ? (int) (expr) : -1)\n\
00130 #else\n\
00131 # define MAYBE_EVAL(expr) -1\n\
00132 #endif\n");
00133 }
00134
00135
00136
00137
00138
00139
00140 static int
00141 write_one_condition (slot, dummy)
00142 PTR *slot;
00143 PTR dummy ATTRIBUTE_UNUSED;
00144 {
00145 const struct c_test *test = * (const struct c_test **) slot;
00146 const char *p;
00147
00148 fputs (" { \"", stdout);
00149 for (p = test->expr; *p; p++)
00150 {
00151 if (*p == '\n')
00152 fputs ("\\n\\\n", stdout);
00153 else if (*p == '"')
00154 fputs ("\\\"", stdout);
00155 else
00156 putchar (*p);
00157 }
00158
00159 printf ("\",\n MAYBE_EVAL (%s) },\n", test->expr);
00160 return 1;
00161 }
00162
00163
00164
00165 static void
00166 write_conditions ()
00167 {
00168 puts ("\
00169 /* This table lists each condition found in the machine description.\n\
00170 Each condition is mapped to its truth value (0 or 1), or -1 if that\n\
00171 cannot be calculated at compile time. */\n\
00172 \n\
00173 const struct c_test insn_conditions[] = {");
00174
00175 htab_traverse (condition_table, write_one_condition, 0);
00176
00177 puts ("};\n");
00178
00179 printf ("const size_t n_insn_conditions = %lu;\n",
00180 (unsigned long) htab_elements (condition_table));
00181 puts ("const int insn_elision_unavailable = 0;");
00182 }
00183
00184 int
00185 main (argc, argv)
00186 int argc;
00187 char **argv;
00188 {
00189 rtx desc;
00190 int pattern_lineno;
00191 int code;
00192
00193 progname = "genconditions";
00194
00195 if (argc <= 1)
00196 fatal ("No input file name.");
00197
00198 if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
00199 return (FATAL_EXIT_CODE);
00200
00201 condition_table = htab_create (1000, hash_c_test, cmp_c_test, NULL);
00202
00203
00204
00205 while (1)
00206 {
00207 desc = read_md_rtx (&pattern_lineno, &code);
00208 if (desc == NULL)
00209 break;
00210
00211
00212
00213 switch (GET_CODE (desc))
00214 {
00215 default:
00216 break;
00217
00218 case DEFINE_INSN:
00219 case DEFINE_EXPAND:
00220 add_condition (XSTR (desc, 2));
00221
00222
00223 if (!strcmp (XSTR (desc, 0), "eh_return"))
00224 saw_eh_return = 1;
00225 break;
00226
00227 case DEFINE_SPLIT:
00228 case DEFINE_PEEPHOLE:
00229 case DEFINE_PEEPHOLE2:
00230 add_condition (XSTR (desc, 1));
00231 break;
00232 }
00233 }
00234
00235 write_header ();
00236 write_conditions ();
00237
00238 fflush (stdout);
00239 return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
00240 }