This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Alternate patch eliminating MD_CALL_PROTOTYPES
- To: gcc-patches at gcc dot gnu dot org
- Subject: Alternate patch eliminating MD_CALL_PROTOTYPES
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 20 May 2000 12:53:15 -0700
This is an alternate possibility for eliminating MD_CALL_PROTOTYPES,
suggested by rth: put wrapper macros around the problematic
generators. Its advantage is that it requires no changes to
arch-specific code. Its disadvantage is that it's a bit uglier.
I'm agnostic here; either approach works.
This has been tested on i386-linux, with prototype warnings enabled.
zw
* Makefile.in (WARN_CFLAGS): Add -Wstrict-prototypes
-Wmissing-prototypes.
* gcc.texi: Remove explanation of MD_CALL_PROTOTYPES.
* builtins.c, calls.c: Change all instances of gen_call_* or
gen_sibcall_* to GEN_CALL_* and GEN_SIBCALL_*.
* calls.c (struct_value_size_rtx): Separate definition from
initialization to avoid unused variable warning.
* genflags.c (gen_macro): New function.
(gen_proto): Call it for gen_call_* and gen_sibcall_*.
(gen_nonproto): Delete.
(gen_insn): Put all insns on the same obstack.
(main): Generate prototypes for everything unconditionally.
===================================================================
Index: Makefile.in
--- Makefile.in 2000/05/20 11:48:03 1.450
+++ Makefile.in 2000/05/20 19:49:36
@@ -76,7 +76,8 @@ XCFLAGS =
TCFLAGS =
CFLAGS = -g @stage1_warn_cflags@
BOOT_CFLAGS = -O2 $(CFLAGS)
-WARN_CFLAGS = -W -Wall -Wtraditional -pedantic -Wno-long-long -Wwrite-strings
+WARN_CFLAGS = -W -Wall -Wtraditional -pedantic -Wno-long-long \
+ -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
LOOSE_CFLAGS = `echo $(CFLAGS)|sed -e 's/-pedantic//g' -e 's/-Wtraditional//g'`
# These exists to be overridden by the x-* and t-* files, respectively.
X_CFLAGS =
===================================================================
Index: builtins.c
--- builtins.c 2000/04/20 10:54:51 1.48
+++ builtins.c 2000/05/20 19:49:37
@@ -981,7 +981,7 @@ expand_builtin_apply (function, argument
valreg = gen_rtx_REG (mode, regno);
}
- emit_call_insn (gen_call_value (valreg,
+ emit_call_insn (GEN_CALL_VALUE (valreg,
gen_rtx_MEM (FUNCTION_MODE, function),
const0_rtx, NULL_RTX, const0_rtx));
===================================================================
Index: calls.c
--- calls.c 2000/05/15 19:12:54 1.135
+++ calls.c 2000/05/20 19:49:38
@@ -449,12 +449,13 @@ emit_call_1 (funexp, fndecl, funtype, st
int ecf_flags;
{
rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
-#if defined (HAVE_call) && defined (HAVE_call_value)
- rtx struct_value_size_rtx = GEN_INT (struct_value_size);
-#endif
rtx call_insn;
int already_popped = 0;
HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
+#if defined (HAVE_call) && defined (HAVE_call_value)
+ rtx struct_value_size_rtx;
+ struct_value_size_rtx = GEN_INT (struct_value_size);
+#endif
/* Ensure address is valid. SYMBOL_REF is already valid, so no need,
and we don't want to load it into a register as an optimization,
@@ -475,12 +476,12 @@ emit_call_1 (funexp, fndecl, funtype, st
if possible, for the sake of frame pointer elimination. */
if (valreg)
- pat = gen_sibcall_value_pop (valreg,
+ pat = GEN_SIBCALL_VALUE_POP (valreg,
gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg,
n_pop);
else
- pat = gen_sibcall_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
+ pat = GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg, n_pop);
emit_call_insn (pat);
@@ -508,11 +509,11 @@ emit_call_1 (funexp, fndecl, funtype, st
if possible, for the sake of frame pointer elimination. */
if (valreg)
- pat = gen_call_value_pop (valreg,
+ pat = GEN_CALL_VALUE_POP (valreg,
gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg, n_pop);
else
- pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
+ pat = GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg, n_pop);
emit_call_insn (pat);
@@ -526,12 +527,12 @@ emit_call_1 (funexp, fndecl, funtype, st
&& HAVE_sibcall && HAVE_sibcall_value)
{
if (valreg)
- emit_call_insn (gen_sibcall_value (valreg,
+ emit_call_insn (GEN_SIBCALL_VALUE (valreg,
gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx,
next_arg_reg, NULL_RTX));
else
- emit_call_insn (gen_sibcall (gen_rtx_MEM (FUNCTION_MODE, funexp),
+ emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg,
struct_value_size_rtx));
}
@@ -542,12 +543,12 @@ emit_call_1 (funexp, fndecl, funtype, st
if (HAVE_call && HAVE_call_value)
{
if (valreg)
- emit_call_insn (gen_call_value (valreg,
+ emit_call_insn (GEN_CALL_VALUE (valreg,
gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg,
NULL_RTX));
else
- emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
+ emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
rounded_stack_size_rtx, next_arg_reg,
struct_value_size_rtx));
}
===================================================================
Index: gcc.texi
--- gcc.texi 2000/05/19 04:43:18 1.48
+++ gcc.texi 2000/05/20 19:49:40
@@ -3911,15 +3911,6 @@ GCC. If @samp{USE_PROTOTYPES} is not de
determined automatically whether your compiler supports
prototypes by checking if @samp{__STDC__} is defined.
-@findex MD_CALL_PROTOTYPES
-@item MD_CALL_PROTOTYPES
-Define this if you wish to generate prototypes for the @code{gen_call}
-or @code{gen_call_value} functions generated from the machine
-description file. If @samp{USE_PROTOTYPES} is defined to be 0, or the
-host compiler does not support prototypes, this macro has no effect. As
-soon as all of the machine descriptions are modified to have the
-appropriate number of arguments, this macro will be removed.
-
@findex PATH_SEPARATOR
@item PATH_SEPARATOR
Define this macro to be a C character constant representing the
===================================================================
Index: genflags.c
--- genflags.c 2000/05/18 22:05:14 1.34
+++ genflags.c 2000/05/20 19:49:40
@@ -33,8 +33,8 @@ Boston, MA 02111-1307, USA. */
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
-/* Obstacks to remember normal, and call insns. */
-static struct obstack call_obstack, normal_obstack;
+/* Obstack to remember insns with. */
+static struct obstack obstack;
/* Max size of names encountered. */
static int max_id_len;
@@ -45,7 +45,7 @@ static int max_opno;
static void max_operand_1 PARAMS ((rtx));
static int num_operands PARAMS ((rtx));
static void gen_proto PARAMS ((rtx));
-static void gen_nonproto PARAMS ((rtx));
+static void gen_macro PARAMS ((const char *, int, int));
static void gen_insn PARAMS ((rtx));
/* Count the number of match_operand's found. */
@@ -98,6 +98,36 @@ num_operands (insn)
return max_opno + 1;
}
+/* Print out a wrapper macro for a function which corrects the number
+ of arguments it takes. Any missing arguments are assumed to be at
+ the end. */
+static void
+gen_macro (name, real, expect)
+ const char *name;
+ int real, expect;
+{
+ int i;
+
+ if (real > expect)
+ abort ();
+ if (real == 0)
+ abort ();
+
+ /* #define GEN_CALL(A, B, C, D) gen_call((A), (B)) */
+ fputs ("#define GEN_", stdout);
+ for (i = 0; name[i]; i++)
+ putchar (TOUPPER (name[i]));
+
+ putchar('(');
+ for (i = 0; i < expect - 1; i++)
+ printf ("%c, ", i + 'A');
+ printf ("%c) gen_%s (", i + 'A', name);
+
+ for (i = 0; i < real - 1; i++)
+ printf ("(%c), ", i + 'A');
+ printf ("(%c))\n", i + 'A');
+}
+
/* Print out prototype information for a function. */
static void
@@ -105,7 +135,28 @@ gen_proto (insn)
rtx insn;
{
int num = num_operands (insn);
- printf ("extern rtx gen_%-*s PARAMS ((", max_id_len, XSTR (insn, 0));
+ const char *name = XSTR (insn, 0);
+
+ /* Many md files don't refer to the last two operands passed to the
+ call patterns. This means their generator functions will be two
+ arguments too short. Instead of changing every md file to touch
+ those operands, we wrap the prototypes in macros that take the
+ correct number of arguments. */
+ if (name[0] == 'c' || name[0] == 's')
+ {
+ if (!strcmp (name, "call")
+ || !strcmp (name, "call_pop")
+ || !strcmp (name, "sibcall")
+ || !strcmp (name, "sibcall_pop"))
+ gen_macro (name, num, 4);
+ else if (!strcmp (name, "call_value")
+ || !strcmp (name, "call_value_pop")
+ || !strcmp (name, "sibcall_value")
+ || !strcmp (name, "sibcall_value_pop"))
+ gen_macro (name, num, 5);
+ }
+
+ printf ("extern rtx gen_%-*s PARAMS ((", max_id_len, name);
if (num == 0)
printf ("void");
@@ -118,15 +169,7 @@ gen_proto (insn)
}
printf ("));\n");
-}
-
-/* Print out a function declaration without a prototype. */
-static void
-gen_nonproto (insn)
- rtx insn;
-{
- printf ("extern rtx gen_%s ();\n", XSTR (insn, 0));
}
static void
@@ -135,7 +178,6 @@ gen_insn (insn)
{
const char *name = XSTR (insn, 0);
const char *p;
- struct obstack *obstack_ptr;
int len;
/* Don't mention instructions whose names are the null string
@@ -167,24 +209,7 @@ gen_insn (insn)
printf (")\n");
}
- /* Save the current insn, so that we can later put out appropriate
- prototypes. At present, most md files have the wrong number of
- arguments for the call insns (call, call_value, call_pop,
- call_value_pop) ignoring the extra arguments that are passed for
- some machines, so by default, turn off the prototype. */
-
- obstack_ptr = ((name[0] == 'c' || name[0] == 's')
- && (!strcmp (name, "call")
- || !strcmp (name, "call_value")
- || !strcmp (name, "call_pop")
- || !strcmp (name, "call_value_pop")
- || !strcmp (name, "sibcall")
- || !strcmp (name, "sibcall_value")
- || !strcmp (name, "sibcall_pop")
- || !strcmp (name, "sibcall_value_pop")))
- ? &call_obstack : &normal_obstack;
-
- obstack_grow (obstack_ptr, &insn, sizeof (rtx));
+ obstack_grow (&obstack, &insn, sizeof (rtx));
}
extern int main PARAMS ((int, char **));
@@ -196,13 +221,11 @@ main (argc, argv)
{
rtx desc;
rtx dummy;
- rtx *call_insns;
- rtx *normal_insns;
+ rtx *insns;
rtx *insn_ptr;
progname = "genflags";
- obstack_init (&call_obstack);
- obstack_init (&normal_obstack);
+ obstack_init (&obstack);
if (argc <= 1)
fatal ("No input file name.");
@@ -228,24 +251,11 @@ from the machine description file `md'.
/* Print out the prototypes now. */
dummy = (rtx) 0;
- obstack_grow (&call_obstack, &dummy, sizeof (rtx));
- call_insns = (rtx *) obstack_finish (&call_obstack);
-
- obstack_grow (&normal_obstack, &dummy, sizeof (rtx));
- normal_insns = (rtx *) obstack_finish (&normal_obstack);
+ obstack_grow (&obstack, &dummy, sizeof (rtx));
+ insns = (rtx *) obstack_finish (&obstack);
- for (insn_ptr = normal_insns; *insn_ptr; insn_ptr++)
+ for (insn_ptr = insns; *insn_ptr; insn_ptr++)
gen_proto (*insn_ptr);
-
- printf ("\n#ifdef MD_CALL_PROTOTYPES\n");
- for (insn_ptr = call_insns; *insn_ptr; insn_ptr++)
- gen_proto (*insn_ptr);
-
- printf ("\n#else /* !MD_CALL_PROTOTYPES */\n");
- for (insn_ptr = call_insns; *insn_ptr; insn_ptr++)
- gen_nonproto (*insn_ptr);
-
- printf ("#endif /* !MD_CALL_PROTOTYPES */\n");
fflush (stdout);
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);