This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[incremental] Patch: FYI: re-initializing C option parsing
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 31 Aug 2007 14:07:04 -0600
- Subject: [incremental] Patch: FYI: re-initializing C option parsing
- Reply-to: Tom Tromey <tromey at redhat dot com>
I'm checking this in on the incremental-compiler branch.
This changes C option processing so that it can be re-initialized. It
also enables unit-at-a-time when in server mode.
Naturally the server still crashes if you try to feed it a second job.
Anything after the front end is not ready for this mode of operation.
The incpath part of this fix is perhaps suitable for merge to the
trunk. However first I have to fix the darwin port here.
Tom
ChangeLog:
2007-08-31 Tom Tromey <tromey@redhat.com>
* toplev.c (toplev_main): Set flag_unit_at_a_time when in server
mode.
* opts.c (clean_up): New function.
(decode_options): Call it.
* fix-header.c (TARGET_EXTRA_INCLUDES): Add c_incpath argument.
(TARGET_EXTRA_PRE_INCLUDES): Likewise.
* c-incpath.h (struct target_c_incpath_s) <extra_pre_includes,
extra_includes>: Add c_incpath argument.
(struct c_incpath): Declare.
(new_c_incpath, delete_c_incpath): Likewise.
(split_quote_chain, add_path, register_include_chains,
add_cpp_dir_path): Add c_incpath argument.
* c-incpath.c (new_c_incpath): New function.
(struct c_incpath): New struct.
(heads, tails, quote_ignores_source_dir): No longer global.
(delete_c_incpath): New function.
(add_sysroot_to_chain): Added 'incpath' argument.
(merge_include_chains): Likewise.
(split_quote_chain): Likewise.
(add_cpp_dir_path): Likewise.
(add_path): Likewise.
(register_include_chains): Likewise.
(add_env_var_paths): Likewise.
(add_standard_paths): Likewise.
(hook_void_charptr_charptr_int): Likewise.
* c-opts.c (clean_up): New function.
(c_common_init_options): Use it. Set include_chains.
(include_chains): New global.
(c_common_handle_option): Update.
(add_prefixed_path): Added c_incpath argument.
(c_common_post_options): Update.
(c_common_post_options): Don't parse first file here...
(c_common_parse_file): ... parse it here.
Index: toplev.c
===================================================================
--- toplev.c (revision 127930)
+++ toplev.c (working copy)
@@ -2205,8 +2205,8 @@
GCC itself seems to write to stderr a lot ... */
dup2 (fd, 2);
- /* FIXME: reset errorcount and sorrycount? Make a new
- global_dc? */
+ /* FIXME: reset errorcount and sorrycount. Maybe make a new
+ global_dc? Arrange to unlink assembler output file on error. */
px = start_as (as_argv);
@@ -2248,6 +2248,9 @@
if (argc == 2 && !strncmp (argv[1], "-fserver=", 9))
{
int fd = atoi (argv[1] + 9);
+ /* Unit-at-a-time is needed to enable the C type-merging
+ machinery. */
+ flag_unit_at_a_time = 1;
server_main_loop (argv[0], fd);
return SUCCESS_EXIT_CODE;
}
Index: fix-header.c
===================================================================
--- fix-header.c (revision 127650)
+++ fix-header.c (working copy)
@@ -83,7 +83,8 @@
#ifdef TARGET_EXTRA_INCLUDES
void
-TARGET_EXTRA_INCLUDES (const char *sysroot ATTRIBUTE_UNUSED,
+TARGET_EXTRA_INCLUDES (struct c_incpath *incpath ATTRIBUTE_UNUSED,
+ const char *sysroot ATTRIBUTE_UNUSED,
const char *iprefix ATTRIBUTE_UNUSED,
int stdinc ATTRIBUTE_UNUSED)
{
@@ -92,7 +93,8 @@
#ifdef TARGET_EXTRA_PRE_INCLUDES
void
-TARGET_EXTRA_PRE_INCLUDES (const char *sysroot ATTRIBUTE_UNUSED,
+TARGET_EXTRA_PRE_INCLUDES (struct c_incpath *incpath ATTRIBUTE_UNUSED,
+ const char *sysroot ATTRIBUTE_UNUSED,
const char *iprefix ATTRIBUTE_UNUSED,
int stdinc ATTRIBUTE_UNUSED)
{
Index: opts.c
===================================================================
--- opts.c (revision 127650)
+++ opts.c (working copy)
@@ -729,6 +729,18 @@
}
}
+/* Reset this module. */
+static void
+clean_up (void)
+{
+ if (in_fnames)
+ {
+ free (in_fnames);
+ in_fnames = NULL;
+ num_in_fnames = 0;
+ }
+}
+
/* Parse command line options and set default flag values. Do minimal
options processing. */
void
@@ -736,6 +748,9 @@
{
unsigned int i, lang_mask;
+ /* Clean up from previous run. */
+ clean_up ();
+
/* Perform language-specific options initialization. */
lang_mask = lang_hooks.init_options (argc, argv);
Index: c-opts.c
===================================================================
--- c-opts.c (revision 127671)
+++ c-opts.c (working copy)
@@ -107,6 +107,9 @@
/* Number of deferred options scanned for -include. */
static size_t include_cursor;
+/* Include chains. */
+static struct c_incpath *include_chains;
+
static void set_Wimplicit (int);
static void handle_OPT_d (const char *);
static void set_std_cxx98 (int);
@@ -116,7 +119,7 @@
static void check_deps_environment_vars (void);
static void handle_deferred_opts (void);
static void sanitize_cpp_opts (void);
-static void add_prefixed_path (const char *, size_t);
+static void add_prefixed_path (struct c_incpath *, const char *, size_t);
static void push_command_line_include (void);
static void cb_file_change (cpp_reader *, const struct line_map *);
static void cb_dir_change (cpp_reader *, const char *);
@@ -197,6 +200,40 @@
deferred_count++;
}
+/* Clean up if this module has previously been initialized. */
+static void
+clean_up (void)
+{
+ cpp_opts = NULL;
+ if (parse_in)
+ {
+ cpp_destroy (parse_in);
+ parse_in = NULL;
+ }
+ out_fname = NULL;
+ out_stream = NULL;
+ deps_file = NULL;
+ iprefix = NULL;
+ imultilib = NULL;
+ sysroot = TARGET_SYSTEM_ROOT;
+ std_inc = true;
+ std_cxx_inc = true;
+ quote_chain_split = false;
+ /* FIXME: reset all warning options, etc. */
+ deferred_count = 0;
+ include_cursor = 0;
+ if (deferred_opts)
+ {
+ XDELETEVEC (deferred_opts);
+ deferred_opts = NULL;
+ }
+ if (include_chains)
+ {
+ delete_c_incpath (include_chains);
+ include_chains = NULL;
+ }
+}
+
/* Common initialization before parsing options. */
unsigned int
c_common_init_options (unsigned int argc, const char **argv)
@@ -204,6 +241,10 @@
static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
unsigned int i, result;
+ clean_up ();
+
+ include_chains = new_c_incpath ();
+
/* This is conditionalized only because that is the way the front
ends used to do it. Maybe this should be unconditional? */
if (c_dialect_cxx ())
@@ -329,13 +370,13 @@
case OPT_I:
if (strcmp (arg, "-"))
- add_path (xstrdup (arg), BRACKET, 0, true);
+ add_path (include_chains, xstrdup (arg), BRACKET, 0, true);
else
{
if (quote_chain_split)
error ("-I- specified twice");
quote_chain_split = true;
- split_quote_chain ();
+ split_quote_chain (include_chains);
inform ("obsolete option -I- used, please use -iquote instead");
}
break;
@@ -851,7 +892,7 @@
break;
case OPT_idirafter:
- add_path (xstrdup (arg), AFTER, 0, true);
+ add_path (include_chains, xstrdup (arg), AFTER, 0, true);
break;
case OPT_imacros:
@@ -868,7 +909,7 @@
break;
case OPT_iquote:
- add_path (xstrdup (arg), QUOTE, 0, true);
+ add_path (include_chains, xstrdup (arg), QUOTE, 0, true);
break;
case OPT_isysroot:
@@ -876,15 +917,15 @@
break;
case OPT_isystem:
- add_path (xstrdup (arg), SYSTEM, 0, true);
+ add_path (include_chains, xstrdup (arg), SYSTEM, 0, true);
break;
case OPT_iwithprefix:
- add_prefixed_path (arg, SYSTEM);
+ add_prefixed_path (include_chains, arg, SYSTEM);
break;
case OPT_iwithprefixbefore:
- add_prefixed_path (arg, BRACKET);
+ add_prefixed_path (include_chains, arg, BRACKET);
break;
case OPT_lang_asm:
@@ -1030,7 +1071,8 @@
sanitize_cpp_opts ();
- register_include_chains (parse_in, sysroot, iprefix, imultilib,
+ register_include_chains (include_chains,
+ parse_in, sysroot, iprefix, imultilib,
std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
#ifdef C_COMMON_OVERRIDE_OPTIONS
@@ -1190,14 +1232,7 @@
immediately. */
errorcount += cpp_errors (parse_in);
- *pfilename = this_input_filename
- = cpp_read_main_file (parse_in, in_fnames[0]);
- /* Don't do any compilation or preprocessing if there is no input file. */
- if (this_input_filename == NULL)
- {
- errorcount++;
- return false;
- }
+ *pfilename = in_fnames[0]; /* FIXME: not quite as nice ... ? */
if (flag_working_directory
&& flag_preprocess_only && !flag_no_line_commands)
@@ -1267,9 +1302,14 @@
gcc_unreachable ();
}
- i = 0;
- for (;;)
+ for (i = 0; i < num_in_fnames; ++i)
{
+ cpp_undef_all (parse_in);
+ this_input_filename = cpp_read_main_file (parse_in, in_fnames[i]);
+ /* If an input file is missing, abandon further compilation.
+ cpplib has issued a diagnostic. */
+ if (!this_input_filename)
+ break;
/* Start the main input file, if the debug writer wants it. */
if (debug_hooks->start_end_main_source_file)
(*debug_hooks->start_source_file) (0, this_input_filename);
@@ -1282,15 +1322,6 @@
/* And end the main input file, if the debug writer wants it */
if (debug_hooks->start_end_main_source_file)
(*debug_hooks->end_source_file) (0);
- if (++i >= num_in_fnames)
- break;
- cpp_undef_all (parse_in);
- this_input_filename
- = cpp_read_main_file (parse_in, in_fnames[i]);
- /* If an input file is missing, abandon further compilation.
- cpplib has issued a diagnostic. */
- if (!this_input_filename)
- break;
}
}
@@ -1457,7 +1488,7 @@
/* Add include path with a prefix at the front of its name. */
static void
-add_prefixed_path (const char *suffix, size_t chain)
+add_prefixed_path (struct c_incpath *incpath, const char *suffix, size_t chain)
{
char *path;
const char *prefix;
@@ -1472,7 +1503,7 @@
memcpy (path + prefix_len, suffix, suffix_len);
path[prefix_len + suffix_len] = '\0';
- add_path (path, chain, 0, false);
+ add_path (incpath, path, chain, 0, false);
}
/* Handle -D, -U, -A, -imacros, and the first -include. */
Index: c-incpath.c
===================================================================
--- c-incpath.c (revision 127650)
+++ c-incpath.c (working copy)
@@ -48,21 +48,41 @@
static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
-static void add_env_var_paths (const char *, int);
-static void add_standard_paths (const char *, const char *, const char *, int);
+static void add_env_var_paths (struct c_incpath *, const char *, int);
+static void add_standard_paths (struct c_incpath *, const char *,
+ const char *, const char *, int);
static void free_path (struct cpp_dir *, int);
-static void merge_include_chains (const char *, cpp_reader *, int);
-static void add_sysroot_to_chain (const char *, int);
-static struct cpp_dir *remove_duplicates (cpp_reader *, struct cpp_dir *,
- struct cpp_dir *,
- struct cpp_dir *, int);
+static void merge_include_chains (struct c_incpath *, const char *,
+ cpp_reader *, int);
+static void add_sysroot_to_chain (struct c_incpath *, const char *, int);
+static struct cpp_dir *remove_duplicates (cpp_reader *,
+ struct cpp_dir *,
+ struct cpp_dir *,
+ struct cpp_dir *, int);
-/* Include chains heads and tails. */
-static struct cpp_dir *heads[4];
-static struct cpp_dir *tails[4];
-static bool quote_ignores_source_dir;
+struct c_incpath
+{
+ /* Include chains heads and tails. */
+ struct cpp_dir *heads[4];
+ struct cpp_dir *tails[4];
+ bool quote_ignores_source_dir;
+};
+
enum { REASON_QUIET = 0, REASON_NOENT, REASON_DUP, REASON_DUP_SYS };
+struct c_incpath *
+new_c_incpath (void)
+{
+ return XCNEW (struct c_incpath);
+}
+
+void
+delete_c_incpath (struct c_incpath *incpath)
+{
+ /* FIXME: clean up the chains too... */
+ XDELETE (incpath);
+}
+
/* Free an element of the include chain, possibly giving a reason. */
static void
free_path (struct cpp_dir *path, int reason)
@@ -94,7 +114,7 @@
/* Read ENV_VAR for a PATH_SEPARATOR-separated list of file names; and
append all the names to the search path CHAIN. */
static void
-add_env_var_paths (const char *env_var, int chain)
+add_env_var_paths (struct c_incpath *incpath, const char *env_var, int chain)
{
char *p, *q, *path;
@@ -118,13 +138,14 @@
path[q - p] = '\0';
}
- add_path (path, chain, chain == SYSTEM, false);
+ add_path (incpath, path, chain, chain == SYSTEM, false);
}
}
/* Append the standard include chain defined in cppdefault.c. */
static void
-add_standard_paths (const char *sysroot, const char *iprefix,
+add_standard_paths (struct c_incpath *incpath,
+ const char *sysroot, const char *iprefix,
const char *imultilib, int cxx_stdinc)
{
const struct default_include *p;
@@ -150,7 +171,7 @@
char *str = concat (iprefix, p->fname + len, NULL);
if (p->multilib && imultilib)
str = concat (str, dir_separator_str, imultilib, NULL);
- add_path (str, SYSTEM, p->cxx_aware, false);
+ add_path (incpath, str, SYSTEM, p->cxx_aware, false);
}
}
}
@@ -196,7 +217,7 @@
if (p->multilib && imultilib)
str = concat (str, dir_separator_str, imultilib, NULL);
- add_path (str, SYSTEM, p->cxx_aware, false);
+ add_path (incpath, str, SYSTEM, p->cxx_aware, false);
}
}
}
@@ -287,11 +308,11 @@
"=". */
static void
-add_sysroot_to_chain (const char *sysroot, int chain)
+add_sysroot_to_chain (struct c_incpath *incpath, const char *sysroot, int chain)
{
struct cpp_dir *p;
- for (p = heads[chain]; p != NULL; p = p->next)
+ for (p = incpath->heads[chain]; p != NULL; p = p->next)
if (p->name[0] == '=' && p->user_supplied_p)
p->name = concat (sysroot, p->name + 1, NULL);
}
@@ -307,34 +328,38 @@
written -iquote bar -Ifoo -Iquux. */
static void
-merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose)
+merge_include_chains (struct c_incpath *incpath, const char *sysroot,
+ cpp_reader *pfile, int verbose)
{
/* Add the sysroot to user-supplied paths starting with "=". */
if (sysroot)
{
- add_sysroot_to_chain (sysroot, QUOTE);
- add_sysroot_to_chain (sysroot, BRACKET);
- add_sysroot_to_chain (sysroot, SYSTEM);
- add_sysroot_to_chain (sysroot, AFTER);
+ add_sysroot_to_chain (incpath, sysroot, QUOTE);
+ add_sysroot_to_chain (incpath, sysroot, BRACKET);
+ add_sysroot_to_chain (incpath, sysroot, SYSTEM);
+ add_sysroot_to_chain (incpath, sysroot, AFTER);
}
/* Join the SYSTEM and AFTER chains. Remove duplicates in the
resulting SYSTEM chain. */
- if (heads[SYSTEM])
- tails[SYSTEM]->next = heads[AFTER];
+ if (incpath->heads[SYSTEM])
+ incpath->tails[SYSTEM]->next = incpath->heads[AFTER];
else
- heads[SYSTEM] = heads[AFTER];
- heads[SYSTEM] = remove_duplicates (pfile, heads[SYSTEM], 0, 0, verbose);
+ incpath->heads[SYSTEM] = incpath->heads[AFTER];
+ incpath->heads[SYSTEM] = remove_duplicates (pfile, incpath->heads[SYSTEM],
+ 0, 0, verbose);
/* Remove duplicates from BRACKET that are in itself or SYSTEM, and
join it to SYSTEM. */
- heads[BRACKET] = remove_duplicates (pfile, heads[BRACKET], heads[SYSTEM],
- heads[SYSTEM], verbose);
+ incpath->heads[BRACKET] = remove_duplicates (pfile, incpath->heads[BRACKET],
+ incpath->heads[SYSTEM],
+ incpath->heads[SYSTEM], verbose);
/* Remove duplicates from QUOTE that are in itself or SYSTEM, and
join it to BRACKET. */
- heads[QUOTE] = remove_duplicates (pfile, heads[QUOTE], heads[SYSTEM],
- heads[BRACKET], verbose);
+ incpath->heads[QUOTE] = remove_duplicates (pfile, incpath->heads[QUOTE],
+ incpath->heads[SYSTEM],
+ incpath->heads[BRACKET], verbose);
/* If verbose, print the list of dirs to search. */
if (verbose)
@@ -342,9 +367,9 @@
struct cpp_dir *p;
fprintf (stderr, _("#include \"...\" search starts here:\n"));
- for (p = heads[QUOTE];; p = p->next)
+ for (p = incpath->heads[QUOTE];; p = p->next)
{
- if (p == heads[BRACKET])
+ if (p == incpath->heads[BRACKET])
fprintf (stderr, _("#include <...> search starts here:\n"));
if (!p)
break;
@@ -359,32 +384,33 @@
(Note that -I. -I- is not the same as the default setup; -I. uses
the compiler's working dir.) */
void
-split_quote_chain (void)
+split_quote_chain (struct c_incpath *incpath)
{
- heads[QUOTE] = heads[BRACKET];
- tails[QUOTE] = tails[BRACKET];
- heads[BRACKET] = NULL;
- tails[BRACKET] = NULL;
+ incpath->heads[QUOTE] = incpath->heads[BRACKET];
+ incpath->tails[QUOTE] = incpath->tails[BRACKET];
+ incpath->heads[BRACKET] = NULL;
+ incpath->tails[BRACKET] = NULL;
/* This is NOT redundant. */
- quote_ignores_source_dir = true;
+ incpath->quote_ignores_source_dir = true;
}
/* Add P to the chain specified by CHAIN. */
void
-add_cpp_dir_path (cpp_dir *p, int chain)
+add_cpp_dir_path (struct c_incpath *incpath, cpp_dir *p, int chain)
{
- if (tails[chain])
- tails[chain]->next = p;
+ if (incpath->tails[chain])
+ incpath->tails[chain]->next = p;
else
- heads[chain] = p;
- tails[chain] = p;
+ incpath->heads[chain] = p;
+ incpath->tails[chain] = p;
}
/* Add PATH to the include chain CHAIN. PATH must be malloc-ed and
NUL-terminated. */
void
-add_path (char *path, int chain, int cxx_aware, bool user_supplied_p)
+add_path (struct c_incpath *incpath, char *path, int chain,
+ int cxx_aware, bool user_supplied_p)
{
cpp_dir *p;
@@ -413,13 +439,14 @@
p->construct = 0;
p->user_supplied_p = user_supplied_p;
- add_cpp_dir_path (p, chain);
+ add_cpp_dir_path (incpath, p, chain);
}
/* Exported function to handle include chain merging, duplicate
removal, and registration with cpplib. */
void
-register_include_chains (cpp_reader *pfile, const char *sysroot,
+register_include_chains (struct c_incpath *incpath,
+ cpp_reader *pfile, const char *sysroot,
const char *iprefix, const char *imultilib,
int stdinc, int cxx_stdinc, int verbose)
{
@@ -436,24 +463,25 @@
/* CPATH and language-dependent environment variables may add to the
include chain. */
- add_env_var_paths ("CPATH", BRACKET);
- add_env_var_paths (lang_env_vars[idx], SYSTEM);
+ add_env_var_paths (incpath, "CPATH", BRACKET);
+ add_env_var_paths (incpath, lang_env_vars[idx], SYSTEM);
- target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);
+ target_c_incpath.extra_pre_includes (incpath, sysroot, iprefix, stdinc);
/* Finally chain on the standard directories. */
if (stdinc)
- add_standard_paths (sysroot, iprefix, imultilib, cxx_stdinc);
+ add_standard_paths (incpath, sysroot, iprefix, imultilib, cxx_stdinc);
- target_c_incpath.extra_includes (sysroot, iprefix, stdinc);
+ target_c_incpath.extra_includes (incpath, sysroot, iprefix, stdinc);
- merge_include_chains (sysroot, pfile, verbose);
+ merge_include_chains (incpath, sysroot, pfile, verbose);
- cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET],
- quote_ignores_source_dir);
+ cpp_set_include_chains (pfile, incpath->heads[QUOTE], incpath->heads[BRACKET],
+ incpath->quote_ignores_source_dir);
}
#if !(defined TARGET_EXTRA_INCLUDES) || !(defined TARGET_EXTRA_PRE_INCLUDES)
-static void hook_void_charptr_charptr_int (const char *sysroot ATTRIBUTE_UNUSED,
+static void hook_void_charptr_charptr_int (struct c_incpath *incpath ATTRIBUTE_UNUSED,
+ const char *sysroot ATTRIBUTE_UNUSED,
const char *iprefix ATTRIBUTE_UNUSED,
int stdinc ATTRIBUTE_UNUSED)
{
Index: c-incpath.h
===================================================================
--- c-incpath.h (revision 127650)
+++ c-incpath.h (working copy)
@@ -15,17 +15,25 @@
along with this program; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-extern void split_quote_chain (void);
-extern void add_path (char *, int, int, bool);
-extern void register_include_chains (cpp_reader *, const char *,
+/* An instance of this holds all the state for a given set of include
+ chains. This structure is intentionally opaque. */
+struct c_incpath;
+
+extern struct c_incpath *new_c_incpath (void);
+extern void delete_c_incpath (struct c_incpath *);
+extern void split_quote_chain (struct c_incpath *);
+extern void add_path (struct c_incpath *, char *, int, int, bool);
+extern void register_include_chains (struct c_incpath *,
+ cpp_reader *, const char *,
const char *, const char *,
int, int, int);
-extern void add_cpp_dir_path (struct cpp_dir *, int);
+extern void add_cpp_dir_path (struct c_incpath *, struct cpp_dir *, int);
struct target_c_incpath_s {
/* Do extra includes processing. STDINC is false iff -nostdinc was given. */
- void (*extra_pre_includes) (const char *, const char *, int);
- void (*extra_includes) (const char *, const char *, int);
+ void (*extra_pre_includes) (struct c_incpath *, const char *,
+ const char *, int);
+ void (*extra_includes) (struct c_incpath *, const char *, const char *, int);
};
extern struct target_c_incpath_s target_c_incpath;