* PATCH: Factor some code in xgcc
@ 2007-07-20 9:22 Dan Hipschman
2007-07-31 12:51 ` Diego Novillo
0 siblings, 1 reply; 3+ messages in thread
From: Dan Hipschman @ 2007-07-20 9:22 UTC (permalink / raw)
To: gcc-patches
I was just looking around the code and noticed a lot of duplication here.
This patch factors out some code used in accumulating parts of the specs
into command line arguments for the child processes. I've bootstrapped
and run the regression tests for gcc, g++, gfortran, and objc with no new
failures. Is this OK to commit?
Thanks,
Dan
2007-07-19 Dan Hipschman <dsh@google.com>
* gcc.c (end_going_arg): New function.
(do_spec_2): Use it.
(do_spec_1): Use it.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c (revision 126791)
+++ gcc/gcc.c (working copy)
@@ -4374,6 +4374,24 @@ static int input_from_pipe;
arguments. */
static const char *suffix_subst;
+static void
+end_going_arg (void)
+{
+ if (arg_going)
+ {
+ const char *string;
+
+ obstack_1grow (&obstack, 0);
+ string = XOBFINISH (&obstack, const char *);
+ if (this_is_library_file)
+ string = find_file (string);
+ store_arg (string, delete_this_arg, this_is_output_file);
+ if (this_is_output_file)
+ outfiles[input_file_number] = string;
+ arg_going = 0;
+ }
+}
+
/* Process the spec SPEC and run the commands specified therein.
Returns 0 if the spec is successfully processed; -1 if failed. */
@@ -4403,7 +4421,6 @@ do_spec (const char *spec)
static int
do_spec_2 (const char *spec)
{
- const char *string;
int result;
clear_args ();
@@ -4416,18 +4433,7 @@ do_spec_2 (const char *spec)
result = do_spec_1 (spec, 0, NULL);
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ end_going_arg ();
return result;
}
@@ -4588,7 +4594,6 @@ do_spec_1 (const char *spec, int inswitc
const char *p = spec;
int c;
int i;
- const char *string;
int value;
while ((c = *p++))
@@ -4597,19 +4602,7 @@ do_spec_1 (const char *spec, int inswitc
switch (inswitch ? 'a' : c)
{
case '\n':
- /* End of line: finish any pending argument,
- then run the pending command if one has been started. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
- arg_going = 0;
+ end_going_arg ();
if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
{
@@ -4643,17 +4636,7 @@ do_spec_1 (const char *spec, int inswitc
break;
case '|':
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
+ end_going_arg ();
/* Use pipe */
obstack_1grow (&obstack, c);
@@ -4662,19 +4645,9 @@ do_spec_1 (const char *spec, int inswitc
case '\t':
case ' ':
- /* Space or tab ends an argument if one is pending. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
+ end_going_arg ();
+
/* Reinitialize for a new argument. */
- arg_going = 0;
delete_this_arg = 0;
this_is_output_file = 0;
this_is_library_file = 0;
@@ -5100,18 +5073,7 @@ do_spec_1 (const char *spec, int inswitc
p = handle_braces (p + 1);
if (p == 0)
return -1;
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ end_going_arg ();
/* If any args were output, mark the last one for deletion
on failure. */
if (argbuf_index != cur_index)
@@ -5430,17 +5392,8 @@ do_spec_1 (const char *spec, int inswitc
/* End of string. If we are processing a spec function, we need to
end any pending argument. */
- if (processing_spec_function && arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ if (processing_spec_function)
+ end_going_arg ();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: Factor some code in xgcc
2007-07-20 9:22 PATCH: Factor some code in xgcc Dan Hipschman
@ 2007-07-31 12:51 ` Diego Novillo
2007-07-31 21:36 ` Dan Hipschman
0 siblings, 1 reply; 3+ messages in thread
From: Diego Novillo @ 2007-07-31 12:51 UTC (permalink / raw)
To: gcc-patches, Dan Hipschman
On 7/19/07 10:46 PM, Dan Hipschman wrote:
> * gcc.c (end_going_arg): New function.
> (do_spec_2): Use it.
> (do_spec_1): Use it.
> +static void
> +end_going_arg (void)
Needs comment. OK with that change.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: Factor some code in xgcc
2007-07-31 12:51 ` Diego Novillo
@ 2007-07-31 21:36 ` Dan Hipschman
0 siblings, 0 replies; 3+ messages in thread
From: Dan Hipschman @ 2007-07-31 21:36 UTC (permalink / raw)
To: gcc-patches
On Tue, Jul 31, 2007 at 08:25:43AM -0400, Diego Novillo wrote:
> On 7/19/07 10:46 PM, Dan Hipschman wrote:
>
> > * gcc.c (end_going_arg): New function.
> > (do_spec_2): Use it.
> > (do_spec_1): Use it.
>
> > +static void
> > +end_going_arg (void)
>
> Needs comment. OK with that change.
OK. Committed.
2007-07-31 Dan Hipschman <dsh@google.com>
* gcc.c (end_going_arg): New function.
(do_spec_2): Use it.
(do_spec_1): Use it.
--- trunk/gcc/gcc.c 2007/07/28 14:51:40 127017
+++ trunk/gcc/gcc.c 2007/07/31 21:16:26 127107
@@ -4373,6 +4373,26 @@
arguments. */
static const char *suffix_subst;
+/* If there is an argument being accumulated, terminate it and store it. */
+
+static void
+end_going_arg (void)
+{
+ if (arg_going)
+ {
+ const char *string;
+
+ obstack_1grow (&obstack, 0);
+ string = XOBFINISH (&obstack, const char *);
+ if (this_is_library_file)
+ string = find_file (string);
+ store_arg (string, delete_this_arg, this_is_output_file);
+ if (this_is_output_file)
+ outfiles[input_file_number] = string;
+ arg_going = 0;
+ }
+}
+
/* Process the spec SPEC and run the commands specified therein.
Returns 0 if the spec is successfully processed; -1 if failed. */
@@ -4402,7 +4422,6 @@
static int
do_spec_2 (const char *spec)
{
- const char *string;
int result;
clear_args ();
@@ -4415,18 +4434,7 @@
result = do_spec_1 (spec, 0, NULL);
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ end_going_arg ();
return result;
}
@@ -4587,7 +4595,6 @@
const char *p = spec;
int c;
int i;
- const char *string;
int value;
while ((c = *p++))
@@ -4596,19 +4603,7 @@
switch (inswitch ? 'a' : c)
{
case '\n':
- /* End of line: finish any pending argument,
- then run the pending command if one has been started. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
- arg_going = 0;
+ end_going_arg ();
if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
{
@@ -4642,17 +4637,7 @@
break;
case '|':
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
+ end_going_arg ();
/* Use pipe */
obstack_1grow (&obstack, c);
@@ -4661,19 +4646,9 @@
case '\t':
case ' ':
- /* Space or tab ends an argument if one is pending. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- }
+ end_going_arg ();
+
/* Reinitialize for a new argument. */
- arg_going = 0;
delete_this_arg = 0;
this_is_output_file = 0;
this_is_library_file = 0;
@@ -5101,18 +5076,7 @@
p = handle_braces (p + 1);
if (p == 0)
return -1;
- /* End any pending argument. */
- if (arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ end_going_arg ();
/* If any args were output, mark the last one for deletion
on failure. */
if (argbuf_index != cur_index)
@@ -5431,17 +5395,8 @@
/* End of string. If we are processing a spec function, we need to
end any pending argument. */
- if (processing_spec_function && arg_going)
- {
- obstack_1grow (&obstack, 0);
- string = XOBFINISH (&obstack, const char *);
- if (this_is_library_file)
- string = find_file (string);
- store_arg (string, delete_this_arg, this_is_output_file);
- if (this_is_output_file)
- outfiles[input_file_number] = string;
- arg_going = 0;
- }
+ if (processing_spec_function)
+ end_going_arg ();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-31 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-20 9:22 PATCH: Factor some code in xgcc Dan Hipschman
2007-07-31 12:51 ` Diego Novillo
2007-07-31 21:36 ` Dan Hipschman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).