OSDN Git Service

libcpp/:
[pf3gnuchains/gcc-fork.git] / gcc / genconditions.c
index 10dfc58..65f64c0 100644 (file)
@@ -1,11 +1,12 @@
 /* Process machine description and calculate constant conditions.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007
+   Free Software Foundation, Inc.
 
    This file is part of GCC.
 
    GCC is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
+   the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
    GCC is distributed in the hope that it will be useful,
@@ -14,9 +15,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GCC; see the file COPYING.  If not, write to
-   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
 
 /* In a machine description, all of the insn patterns - define_insn,
    define_expand, define_split, define_peephole, define_peephole2 -
@@ -52,32 +52,33 @@ write_header (void)
    machine description file.  */\n\
 \n\
 #include \"bconfig.h\"\n\
-#include \"insn-constants.h\"\n");
-
-  puts ("\
+#include \"system.h\"\n\
+\n\
+/* It is necessary, but not entirely safe, to include the headers below\n\
+   in a generator program.  As a defensive measure, don't do so when the\n\
+   table isn't going to have anything in it.  */\n\
+#if GCC_VERSION >= 3001\n\
+\n\
 /* Do not allow checking to confuse the issue.  */\n\
 #undef ENABLE_CHECKING\n\
 #undef ENABLE_TREE_CHECKING\n\
 #undef ENABLE_RTL_CHECKING\n\
 #undef ENABLE_RTL_FLAG_CHECKING\n\
 #undef ENABLE_GC_CHECKING\n\
-#undef ENABLE_GC_ALWAYS_COLLECT\n");
-
-  puts ("\
-#include \"system.h\"\n\
+#undef ENABLE_GC_ALWAYS_COLLECT\n\
+\n\
 #include \"coretypes.h\"\n\
 #include \"tm.h\"\n\
+#include \"insn-constants.h\"\n\
 #include \"rtl.h\"\n\
 #include \"tm_p.h\"\n\
-#include \"function.h\"\n");
-
-  puts ("\
+#include \"function.h\"\n\
+\n\
 /* Fake - insn-config.h doesn't exist yet.  */\n\
 #define MAX_RECOG_OPERANDS 10\n\
 #define MAX_DUP_OPERANDS 10\n\
-#define MAX_INSNS_PER_SPLIT 5\n");
-
-  puts ("\
+#define MAX_INSNS_PER_SPLIT 5\n\
+\n\
 #include \"regs.h\"\n\
 #include \"recog.h\"\n\
 #include \"real.h\"\n\
@@ -87,7 +88,7 @@ write_header (void)
 #include \"resource.h\"\n\
 #include \"toplev.h\"\n\
 #include \"reload.h\"\n\
-#include \"gensupport.h\"\n");
+#include \"tm-constrs.h\"\n");
 
   if (saw_eh_return)
     puts ("#define HAVE_eh_return 1");
@@ -97,7 +98,9 @@ write_header (void)
 /* Dummy external declarations.  */\n\
 extern rtx insn;\n\
 extern rtx ins1;\n\
-extern rtx operands[];\n");
+extern rtx operands[];\n\
+\n\
+#endif /* gcc >= 3.0.1 */\n");
 }
 
 /* Write out one entry in the conditions table, using the data pointed
@@ -118,19 +121,21 @@ write_one_condition (void **slot, void * ARG_UNUSED (dummy))
   fputs ("  { \"", stdout);
   for (p = test->expr; *p; p++)
     {
-      if (*p == '\n')
-       fputs ("\\n\\\n", stdout);
-      else if (*p == '"')
-       fputs ("\\\"", stdout);
-      else
-       putchar (*p);
+      switch (*p)
+       {
+       case '\n': fputs ("\\n\\", stdout); break;
+       case '\\':
+       case '\"': putchar ('\\'); break;
+       default: break;
+       }
+      putchar (*p);
     }
 
-  printf ("\",\n    __builtin_constant_p ");
+  fputs ("\",\n    __builtin_constant_p ", stdout);
   print_c_condition (test->expr);
-  printf ("\n    ? (int) ");
+  fputs ("\n    ? (int) ", stdout);
   print_c_condition (test->expr);
-  printf ("\n    : -1 },\n");
+  fputs ("\n    : -1 },\n", stdout);
   return 1;
 }
 
@@ -140,20 +145,28 @@ static void
 write_conditions (void)
 {
   puts ("\
+/* Structure definition duplicated from gensupport.h rather than\n\
+   drag in that file and its dependencies.  */\n\
+struct c_test\n\
+{\n\
+  const char *expr;\n\
+  int value;\n\
+};\n\
+\n\
 /* This table lists each condition found in the machine description.\n\
    Each condition is mapped to its truth value (0 or 1), or -1 if that\n\
-   cannot be calculated at compile time. */\n\
-\n\
-static const struct c_test insn_conditions[] = {\n                     \
-/* If we don't have __builtin_constant_p, or it's not acceptable in array\n\
+   cannot be calculated at compile time.\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\
+#if GCC_VERSION >= 3001\n\
+static const struct c_test insn_conditions[] = {\n");
 
   traverse_c_tests (write_one_condition, 0);
 
-  puts ("#endif\n};\n");
+  puts ("\n};\n#endif /* gcc >= 3.0.1 */\n");
 }
 
 /* Emit code which will convert the C-format table to a
@@ -163,16 +176,33 @@ static const struct c_test insn_conditions[] = {\n                        \
 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}");
+  puts ("int\n"
+       "main(void)\n"
+       "{\n"
+       "  unsigned int i;\n"
+        "  const char *p;\n"
+        "  puts (\"(define_conditions [\");\n"
+       "#if GCC_VERSION >= 3001\n"
+       "  for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n"
+       "    {\n"
+       "      printf (\"  (%d \\\"\", insn_conditions[i].value);\n"
+       "      for (p = insn_conditions[i].expr; *p; p++)\n"
+       "        {\n"
+       "          switch (*p)\n"
+       "            {\n"
+       "            case '\\\\':\n"
+       "            case '\\\"': putchar ('\\\\'); break;\n"
+       "            default: break;\n"
+       "            }\n"
+       "          putchar (*p);\n"
+       "        }\n"
+        "      puts (\"\\\")\");\n"
+        "    }\n"
+       "#endif /* gcc >= 3.0.1 */\n"
+       "  puts (\"])\");\n"
+        "  fflush (stdout);\n"
+        "return ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;\n"
+       "}");
 }
 
 int