diff options
Diffstat (limited to 'gcc/genconditions.c')
-rw-r--r-- | gcc/genconditions.c | 68 |
1 files changed, 29 insertions, 39 deletions
diff --git a/gcc/genconditions.c b/gcc/genconditions.c index bdb3d30..10dfc58 100644 --- a/gcc/genconditions.c +++ b/gcc/genconditions.c @@ -38,31 +38,10 @@ /* so we can include except.h in the generated file. */ static int saw_eh_return; -static htab_t condition_table; - -static void add_condition (const char *); static void write_header (void); static void write_conditions (void); static int write_one_condition (void **, void *); -/* Record the C test expression EXPR in the condition_table. - Duplicates clobber previous entries, which leaks memory, but - we don't care for this application. */ - -static void -add_condition (const char *expr) -{ - struct c_test *test; - - if (expr[0] == 0) - return; - - test = XNEW (struct c_test); - test->expr = expr; - - *(htab_find_slot (condition_table, test, INSERT)) = test; -} - /* Generate the header for insn-conditions.c. */ static void @@ -86,13 +65,6 @@ write_header (void) puts ("\ #include \"system.h\"\n\ -/* If we don't have __builtin_constant_p, or it's not acceptable in array\n\ - initializers, fall back to assuming that all conditions potentially\n\ - vary at run time. It works in 3.0.1 and later; 3.0 only when not\n\ - optimizing. */\n\ -#if GCC_VERSION < 3001\n\ -#include \"dummy-conditions.c\"\n\ -#else\n\ #include \"coretypes.h\"\n\ #include \"tm.h\"\n\ #include \"rtl.h\"\n\ @@ -172,15 +144,35 @@ write_conditions (void) Each condition is mapped to its truth value (0 or 1), or -1 if that\n\ cannot be calculated at compile time. */\n\ \n\ -const struct c_test insn_conditions[] = {"); +static const struct c_test insn_conditions[] = {\n \ +/* If we don't have __builtin_constant_p, or it's not acceptable in array\n\ + initializers, fall back to assuming that all conditions potentially\n\ + vary at run time. It works in 3.0.1 and later; 3.0 only when not\n\ + optimizing. */\n\ +#if GCC_VERSION >= 3001"); - htab_traverse (condition_table, write_one_condition, 0); + traverse_c_tests (write_one_condition, 0); - puts ("};\n"); + puts ("#endif\n};\n"); +} - printf ("const size_t n_insn_conditions = %lu;\n", - (unsigned long) htab_elements (condition_table)); - puts ("const int insn_elision_unavailable = 0;\n#endif"); +/* Emit code which will convert the C-format table to a + (define_conditions) form, which the MD reader can understand. + The result will be added to the set of files scanned by + 'downstream' generators. */ +static void +write_writer (void) +{ + puts ("int\nmain(void)\n{\n\ + unsigned int i;\n\ +\n\ + puts (\"(define_conditions [\");\n\ + for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n\ + printf (\" (%d \\\"%s\\\")\\n\",\n\ + insn_conditions[i].value, insn_conditions[i].expr);\n\ + puts (\"])\");\n\ + fflush (stdout);\n\ + return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);\n}"); } int @@ -195,10 +187,7 @@ main (int argc, char **argv) if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE) return (FATAL_EXIT_CODE); - condition_table = htab_create (1000, hash_c_test, cmp_c_test, NULL); - /* Read the machine description. */ - while (1) { desc = read_md_rtx (&pattern_lineno, &code); @@ -214,7 +203,7 @@ main (int argc, char **argv) case DEFINE_INSN: case DEFINE_EXPAND: - add_condition (XSTR (desc, 2)); + add_c_test (XSTR (desc, 2), -1); /* except.h needs to know whether there is an eh_return pattern in the machine description. */ if (!strcmp (XSTR (desc, 0), "eh_return")) @@ -224,13 +213,14 @@ main (int argc, char **argv) case DEFINE_SPLIT: case DEFINE_PEEPHOLE: case DEFINE_PEEPHOLE2: - add_condition (XSTR (desc, 1)); + add_c_test (XSTR (desc, 1), -1); break; } } write_header (); write_conditions (); + write_writer (); fflush (stdout); return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); |