Commit f7c8e4fc by Zack Weinberg

genconditions.c (write_header): In generated code...

	* genconditions.c (write_header): In generated code, #ifdef out
	all includes and fake declarations, except includes of bconfig.h
	and system.h, unless GCC_VERSION >= 3001.  Do not include
	gensupport.h in any case.
	(write_conditions): Generate a definition of struct c_test.  Add
	a comment to the generated #endif.
	(write_one_condition): Escape backslashes in string too.
	(write_writer): Generated code must escape backslashes and quote
	marks (but not newlines) in the strings it writes.
	* Makefile.in (build/gencondmd.o): Update dependencies.

From-SVN: r110275
parent 63622a81
2006-01-26 Zack Weinberg <zackw@panix.com>
* genconditions.c (write_header): In generated code, #ifdef out
all includes and fake declarations, except includes of bconfig.h
and system.h, unless GCC_VERSION >= 3001. Do not include
gensupport.h in any case.
(write_conditions): Generate a definition of struct c_test. Add
a comment to the generated #endif.
(write_one_condition): Escape backslashes in string too.
(write_writer): Generated code must escape backslashes and quote
marks (but not newlines) in the strings it writes.
* Makefile.in (build/gencondmd.o): Update dependencies.
2006-01-26 Steve Ellcey <sje@cup.hp.com> 2006-01-26 Steve Ellcey <sje@cup.hp.com>
PR target/25961 PR target/25961
......
...@@ -2900,10 +2900,10 @@ build/rtl.o: rtl.c $(BCONFIG_H) coretypes.h $(GTM_H) $(SYSTEM_H) \ ...@@ -2900,10 +2900,10 @@ build/rtl.o: rtl.c $(BCONFIG_H) coretypes.h $(GTM_H) $(SYSTEM_H) \
$(RTL_H) real.h $(GGC_H) errors.h $(RTL_H) real.h $(GGC_H) errors.h
build/vec.o : vec.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) coretypes.h vec.h \ build/vec.o : vec.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) coretypes.h vec.h \
$(GGC_H) toplev.h $(GGC_H) toplev.h
build/gencondmd.o : build/gencondmd.c $(CONFIG_H) $(SYSTEM_H) $(GTM_H) \ build/gencondmd.o : build/gencondmd.c $(BCONFIG_H) $(SYSTEM_H) \
$(RTL_H) $(TM_P_H) $(REGS_H) $(FUNCTION_H) $(RECOG_H) real.h output.h \ coretypes.h $(GTM_H) insn-constants.h $(RTL_H) $(TM_P_H) \
$(FLAGS_H) hard-reg-set.h $(RESOURCE_H) toplev.h reload.h \ $(FUNCTION_H) $(REGS_H) $(RECOG_H) real.h output.h $(FLAGS_H) \
gensupport.h insn-constants.h coretypes.h $(RESOURCE_H) toplev.h reload.h except.h
# ...these are the programs themselves. # ...these are the programs themselves.
build/genattr.o : genattr.c $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \ build/genattr.o : genattr.c $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \
......
...@@ -52,9 +52,14 @@ write_header (void) ...@@ -52,9 +52,14 @@ write_header (void)
machine description file. */\n\ machine description file. */\n\
\n\ \n\
#include \"bconfig.h\"\n\ #include \"bconfig.h\"\n\
#include \"insn-constants.h\"\n"); #include \"system.h\"\n");
puts ("\ puts ("\
/* 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\ /* Do not allow checking to confuse the issue. */\n\
#undef ENABLE_CHECKING\n\ #undef ENABLE_CHECKING\n\
#undef ENABLE_TREE_CHECKING\n\ #undef ENABLE_TREE_CHECKING\n\
...@@ -64,9 +69,9 @@ write_header (void) ...@@ -64,9 +69,9 @@ write_header (void)
#undef ENABLE_GC_ALWAYS_COLLECT\n"); #undef ENABLE_GC_ALWAYS_COLLECT\n");
puts ("\ puts ("\
#include \"system.h\"\n\
#include \"coretypes.h\"\n\ #include \"coretypes.h\"\n\
#include \"tm.h\"\n\ #include \"tm.h\"\n\
#include \"insn-constants.h\"\n\
#include \"rtl.h\"\n\ #include \"rtl.h\"\n\
#include \"tm_p.h\"\n\ #include \"tm_p.h\"\n\
#include \"function.h\"\n"); #include \"function.h\"\n");
...@@ -86,8 +91,7 @@ write_header (void) ...@@ -86,8 +91,7 @@ write_header (void)
#include \"hard-reg-set.h\"\n\ #include \"hard-reg-set.h\"\n\
#include \"resource.h\"\n\ #include \"resource.h\"\n\
#include \"toplev.h\"\n\ #include \"toplev.h\"\n\
#include \"reload.h\"\n\ #include \"reload.h\"\n");
#include \"gensupport.h\"\n");
if (saw_eh_return) if (saw_eh_return)
puts ("#define HAVE_eh_return 1"); puts ("#define HAVE_eh_return 1");
...@@ -97,7 +101,9 @@ write_header (void) ...@@ -97,7 +101,9 @@ write_header (void)
/* Dummy external declarations. */\n\ /* Dummy external declarations. */\n\
extern rtx insn;\n\ extern rtx insn;\n\
extern rtx ins1;\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 /* Write out one entry in the conditions table, using the data pointed
...@@ -118,11 +124,13 @@ write_one_condition (void **slot, void * ARG_UNUSED (dummy)) ...@@ -118,11 +124,13 @@ write_one_condition (void **slot, void * ARG_UNUSED (dummy))
fputs (" { \"", stdout); fputs (" { \"", stdout);
for (p = test->expr; *p; p++) for (p = test->expr; *p; p++)
{ {
if (*p == '\n') switch (*p)
fputs ("\\n\\\n", stdout); {
else if (*p == '"') case '\n': fputs ("\\n\\", stdout); break;
fputs ("\\\"", stdout); case '\\':
else case '\"': putchar ('\\'); break;
default: break;
}
putchar (*p); putchar (*p);
} }
...@@ -140,20 +148,29 @@ static void ...@@ -140,20 +148,29 @@ static void
write_conditions (void) write_conditions (void)
{ {
puts ("\ 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");
puts ("\
/* This table lists each condition found in the machine description.\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\ Each condition is mapped to its truth value (0 or 1), or -1 if that\n\
cannot be calculated at compile time. */\n\ cannot be calculated at compile time.\n\
\n\ If we don't have __builtin_constant_p, or it's not acceptable in array\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\
initializers, fall back to assuming that all conditions potentially\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\ vary at run time. It works in 3.0.1 and later; 3.0 only when not\n\
optimizing. */\n\ optimizing. */\n\
#if GCC_VERSION >= 3001"); \n\
static const struct c_test insn_conditions[] = {\n\
#if GCC_VERSION >= 3001\n");
traverse_c_tests (write_one_condition, 0); traverse_c_tests (write_one_condition, 0);
puts ("#endif\n};\n"); puts ("\n#endif /* gcc >= 3.0.1 */\n};\n");
} }
/* Emit code which will convert the C-format table to a /* Emit code which will convert the C-format table to a
...@@ -163,16 +180,31 @@ static const struct c_test insn_conditions[] = {\n \ ...@@ -163,16 +180,31 @@ static const struct c_test insn_conditions[] = {\n \
static void static void
write_writer (void) write_writer (void)
{ {
puts ("int\nmain(void)\n{\n\ puts ("int\n"
unsigned int i;\n\ "main(void)\n"
\n\ "{\n"
puts (\"(define_conditions [\");\n\ " unsigned int i;\n"
for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n\ " const char *p;\n"
printf (\" (%d \\\"%s\\\")\\n\",\n\ " puts (\"(define_conditions [\");\n"
insn_conditions[i].value, insn_conditions[i].expr);\n\ " for (i = 0; i < ARRAY_SIZE (insn_conditions); i++)\n"
puts (\"])\");\n\ " {\n"
fflush (stdout);\n\ " printf (\" (%d \\\"\", insn_conditions[i].value);\n"
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);\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"
" }");
puts (" puts (\"])\");\n"
" fflush (stdout);\n"
"return ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;\n"
"}");
} }
int int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment