From aaf932068245d39888fc1efd7f887a6d60de76e5 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 24 Mar 2002 12:27:45 +0000 Subject: [PATCH] Removal of separate preprocessor cpp0. * Makefile.in (GCC_PASSES, STAGESTUFF, LIBCPP_OBJS, cpp0, install-common): Update. * c-common.c (flag_preprocess_only): New. (c_common_init): Preprocess for -E. * c-common.h (flag_preprocess_only): New. * c-decl.c (c_decode_option): Handle -E, and -std=c++98. * c-objc-common.c (c_init_decl_processing): Exit quickly for NULL return from c_common_init. * cpplib.h (cpp_preprocess_file): New. * cppmain.c (main, general_init, pfile, progname): Remove. (do_preprocessing): Rename cpp_preprocess_file, don't call cpp_finish. Don't close stdout here. (setup_callbacks): Update prototype. * gcc.c (trad_capable_cpp, cpp_unique_options, default_compilers): Update. * tradcpp.c (main): Ignore -quiet. cp: * decl2.c (cxx_decode_option): Handle -E. * lang-specs.h (default_compilers): Preprocess with cc1plus. * lex.c (cxx_init): Exit quickly if c_common_init returns NULL. objc: * lang-specs.h (default_compilers): Preprocess with cc1obj. Co-Authored-By: Aldy Hernandez From-SVN: r51256 --- gcc/ChangeLog | 24 ++++++++++++ gcc/Makefile.in | 12 ++---- gcc/c-common.c | 10 +++++ gcc/c-common.h | 3 ++ gcc/c-decl.c | 4 ++ gcc/c-objc-common.c | 2 + gcc/cp/ChangeLog | 6 +++ gcc/cp/decl2.c | 2 + gcc/cp/lang-specs.h | 4 +- gcc/cp/lex.c | 2 + gcc/cpplib.h | 3 ++ gcc/cppmain.c | 89 ++++++++----------------------------------- gcc/gcc.c | 5 ++- gcc/objc/lang-specs.h | 2 +- gcc/tradcpp.c | 4 ++ 15 files changed, 84 insertions(+), 88 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f75a46379ed..3f568562ca2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,27 @@ +2002-03-24 Neil Booth + Aldy Hernandez + + Removal of separate preprocessor cpp0. + + * Makefile.in (GCC_PASSES, STAGESTUFF, LIBCPP_OBJS, + cpp0, install-common): Update. + * c-common.c (flag_preprocess_only): New. + (c_common_init): Preprocess for -E. + * c-common.h (flag_preprocess_only): New. + * c-decl.c (c_decode_option): Handle -E and -std=c++98. + * c-objc-common.c (c_init_decl_processing): Exit quickly + for NULL return from c_common_init. + * cpplib.h (cpp_preprocess_file): New. + * cppmain.c (main, general_init, pfile, progname): Remove. + (do_preprocessing): Rename cpp_preprocess_file, don't call + cpp_finish. Don't close stdout here. + (setup_callbacks): Update prototype. + * gcc.c (trad_capable_cpp, cpp_unique_options, default_compilers): + Update. + * tradcpp.c (main): Ignore -quiet. +objc: + * lang-specs.h (default_compilers): Preprocess with cc1obj. + 2002-03-24 Richard Henderson PR optimization/5742 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 462e20e4c68..e9642fc4422 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -450,7 +450,7 @@ COMPILERS = cc1$(exeext) @all_compilers@ # List of things which should already be built whenever we try to use xgcc # to compile anything (without linking). -GCC_PASSES=xgcc$(exeext) cc1$(exeext) cpp0$(exeext) specs $(EXTRA_PASSES) +GCC_PASSES=xgcc$(exeext) cc1$(exeext) specs $(EXTRA_PASSES) # List of things which should already be built whenever we try to use xgcc # to link anything. @@ -753,7 +753,7 @@ STAGESTUFF = *$(objext) insn-flags.h insn-config.h insn-codes.h \ genattr$(build_exeext) genopinit$(build_exeext) gengenrtl$(build_exeext) \ gencheck$(build_exeext) genpreds$(build_exeext) genconstants$(build_exeext) \ genrtl.c genrtl.h \ - xgcc$(exeext) cpp$(exeext) cc1$(exeext) cpp0$(exeext) $(EXTRA_PASSES) \ + xgcc$(exeext) cpp$(exeext) cc1$(exeext) $(EXTRA_PASSES) \ $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) cc1obj$(exeext) \ enquire$(exeext) protoize$(exeext) unprotoize$(exeext) \ specs collect2$(exeext) $(USE_COLLECT2) underscore.c tradcpp0$(exeext) \ @@ -1963,7 +1963,7 @@ PREPROCESSOR_DEFINES = \ -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" LIBCPP_OBJS = cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o \ - cpphash.o cpperror.o cppinit.o cppdefault.o \ + cpphash.o cpperror.o cppinit.o cppdefault.o cppmain.o \ hashtable.o line-map.o mkdeps.o prefix.o version.o mbchar.o LIBCPP_DEPS = $(CPPLIB_H) cpphash.h line-map.h hashtable.h intl.h \ @@ -1976,10 +1976,6 @@ libcpp.a: $(LIBCPP_OBJS) $(AR) $(AR_FLAGS) libcpp.a $(LIBCPP_OBJS) -$(RANLIB) libcpp.a -cpp0$(exeext): cppmain.o intl.o libcpp.a $(LIBDEPS) - $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o cpp0$(exeext) cppmain.o \ - intl.o libcpp.a $(LIBS) - cppmain.o: cppmain.c $(CONFIG_H) $(CPPLIB_H) intl.h $(SYSTEM_H) cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS) @@ -2626,8 +2622,6 @@ install-common: native $(EXTRA_PARTS) lang.install-common $(INSTALL_DATA) SYSCALLS.c.X $(libsubdir)/SYSCALLS.c.X; \ chmod a-x $(libsubdir)/SYSCALLS.c.X; \ fi - -rm -f $(libsubdir)/cpp0$(exeext) - $(INSTALL_PROGRAM) cpp0$(exeext) $(libsubdir)/cpp0$(exeext) -rm -f $(libsubdir)/tradcpp0$(exeext) $(INSTALL_PROGRAM) tradcpp0$(exeext) $(libsubdir)/tradcpp0$(exeext) # Install gcov if it was compiled. diff --git a/gcc/c-common.c b/gcc/c-common.c index 228f41b10fe..0d5e1e810c5 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -181,6 +181,9 @@ enum c_language_kind c_language; tree c_global_trees[CTI_MAX]; +/* Nonzero if prepreprocessing only. */ +int flag_preprocess_only; + /* Nonzero means don't recognize the non-ANSI builtin functions. */ int flag_no_builtin; @@ -4141,6 +4144,13 @@ const char * c_common_init (filename) const char *filename; { + /* NULL is passed up to toplev.c and we exit quickly. */ + if (flag_preprocess_only) + { + cpp_preprocess_file (parse_in); + return NULL; + } + /* Do this before initializing pragmas, as then cpplib's hash table has been set up. */ filename = init_c_lex (filename); diff --git a/gcc/c-common.h b/gcc/c-common.h index 0e8fa954ace..3bd5ba01547 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -372,6 +372,9 @@ extern void c_mark_lang_decl PARAMS ((struct c_lang_decl *)); extern c_language_kind c_language; +/* Nonzero if prepreprocessing only. */ +extern int flag_preprocess_only; + /* Nonzero means give string constants the type `const char *', rather than `char *'. */ diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 4e0dccd4b0a..a727b2707dd 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -581,6 +581,8 @@ c_decode_option (argc, argv) flag_isoc99 = 1; flag_isoc94 = 1; } + else if (!strcmp (argstart, "c++98")) + ; /* Handled by cpplib. */ else error ("unknown C standard `%s'", argstart); } @@ -685,6 +687,8 @@ c_decode_option (argc, argv) /* Only warn about unknown pragmas that are not in system headers. */ warn_unknown_pragmas = 1; } + else if (!strcmp (p, "-E")) + flag_preprocess_only = 1; else { size_t i; diff --git a/gcc/c-objc-common.c b/gcc/c-objc-common.c index 6c0aef673f7..62fd84955b3 100644 --- a/gcc/c-objc-common.c +++ b/gcc/c-objc-common.c @@ -217,6 +217,8 @@ c_objc_common_init (filename) c_init_decl_processing (); filename = c_common_init (filename); + if (filename == NULL) + return NULL; lang_unsafe_for_reeval = c_unsafe_for_reeval; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c61b19185fe..df1bd5718ef 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-03-24 Neil Booth + + * decl2.c (cxx_decode_option): Handle -E. + * lang-specs.h (default_compilers): Preprocess with cc1plus. + * lex.c (cxx_init): Exit quickly if c_common_init returns NULL. + 2002-03-23 Jakub Jelinek PR c++/6037 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 2dbb6636a98..6763b4591ac 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -700,6 +700,8 @@ cxx_decode_option (argc, argv) } else return strings_processed; } + else if (!strcmp (p, "-E")) + flag_preprocess_only = 1; else if (!strcmp (p, "-ansi")) flag_no_nonansi_builtin = 1, flag_ansi = 1, flag_noniso_default_format_attributes = 0, flag_no_gnu_keywords = 1; diff --git a/gcc/cp/lang-specs.h b/gcc/cp/lang-specs.h index e48bf7436f1..771ab59963f 100644 --- a/gcc/cp/lang-specs.h +++ b/gcc/cp/lang-specs.h @@ -35,13 +35,13 @@ Boston, MA 02111-1307, USA. */ {"@c++", /* cc1plus has an integrated ISO C preprocessor. We should invoke the external preprocessor if -save-temps is given. */ - "%{E|M|MM:cpp0 -lang-c++ %{!no-gcc:-D__GNUG__=%v1}\ + "%{E|M|MM:cc1plus -E -lang-c++ %{!no-gcc:-D__GNUG__=%v1}\ %{!Wno-deprecated:-D__DEPRECATED}\ %{!fno-exceptions:-D__EXCEPTIONS}\ -D__GXX_ABI_VERSION=100\ %{ansi:-D__STRICT_ANSI__ -trigraphs -$} %(cpp_options)}\ %{!E:%{!M:%{!MM:\ - %{save-temps:cpp0 -lang-c++ \ + %{save-temps:cc1plus -E -lang-c++ \ %{!no-gcc:-D__GNUG__=%v1}\ %{!Wno-deprecated:-D__DEPRECATED}\ %{!fno-exceptions:-D__EXCEPTIONS}\ diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 593f3121474..f0c6389935d 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -685,6 +685,8 @@ cxx_init (filename) interface_unknown = 1; filename = c_common_init (filename); + if (filename == NULL) + return NULL; init_cp_pragma (); diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 783b25835b0..e8298be1fae 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -603,6 +603,9 @@ extern unsigned char *cpp_quote_string PARAMS ((unsigned char *, extern int cpp_included PARAMS ((cpp_reader *, const char *)); extern void cpp_make_system_header PARAMS ((cpp_reader *, int, int)); +/* In cppmain.c */ +extern void cpp_preprocess_file PARAMS ((cpp_reader *)); + #ifdef __cplusplus } #endif diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 99ca2deb90b..0d427292662 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -1,4 +1,4 @@ -/* CPP main program, using CPP Library. +/* Preprocess only, using cpplib. Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. Written by Per Bothner, 1994-95. @@ -38,10 +38,7 @@ struct printer unsigned char printed; /* Nonzero if something output at line. */ }; -int main PARAMS ((int, char **)); -static void general_init PARAMS ((const char *)); -static void do_preprocessing PARAMS ((int, char **)); -static void setup_callbacks PARAMS ((void)); +static void setup_callbacks PARAMS ((cpp_reader *)); /* General output routines. */ static void scan_translation_unit PARAMS ((cpp_reader *)); @@ -64,74 +61,15 @@ static void cb_ident PARAMS ((cpp_reader *, unsigned int, static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *)); static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int)); -const char *progname; /* Needs to be global. */ -static cpp_reader *pfile; /* An opaque handle. */ static cpp_options *options; /* Options of pfile. */ static struct printer print; -int -main (argc, argv) - int argc; - char **argv; +/* Preprocess and output. */ +void +cpp_preprocess_file (pfile) + cpp_reader *pfile; { - general_init (argv[0]); - - /* Construct a reader with default language GNU C89. */ - pfile = cpp_create_reader (CLK_GNUC89); options = cpp_get_options (pfile); - - do_preprocessing (argc, argv); - - if (cpp_destroy (pfile)) - return FATAL_EXIT_CODE; - - return SUCCESS_EXIT_CODE; -} - -/* Store the program name, and set the locale. */ -static void -general_init (argv0) - const char *argv0; -{ - progname = argv0 + strlen (argv0); - - while (progname != argv0 && ! IS_DIR_SEPARATOR (progname[-1])) - --progname; - - xmalloc_set_program_name (progname); - - hex_init (); - gcc_init_libintl (); -} - -/* Handle switches, preprocess and output. */ -static void -do_preprocessing (argc, argv) - int argc; - char **argv; -{ - int argi = 1; /* Next argument to handle. */ - - argi += cpp_handle_options (pfile, argc - argi , argv + argi); - if (CPP_FATAL_ERRORS (pfile)) - return; - - if (argi < argc) - { - cpp_fatal (pfile, "invalid option %s", argv[argi]); - return; - } - - cpp_post_options (pfile); - if (CPP_FATAL_ERRORS (pfile)) - return; - - /* If cpp_handle_options saw --help or --version on the command - line, it will have set pfile->help_only to indicate this. Exit - successfully. [The library does not exit itself, because - e.g. cc1 needs to print its own --help message at this point.] */ - if (options->help_only) - return; /* Initialize the printer structure. Setting print.line to -1 here is a trick to guarantee that the first token of the file will @@ -156,7 +94,7 @@ do_preprocessing (argc, argv) } } - setup_callbacks (); + setup_callbacks (pfile); if (cpp_read_main_file (pfile, options->in_fname, NULL)) { @@ -172,21 +110,24 @@ do_preprocessing (argc, argv) /* -dM command line option. Should this be in cpp_finish? */ if (options->dump_macros == dump_only) cpp_forall_identifiers (pfile, dump_macro, NULL); - - cpp_finish (pfile); } /* Flush any pending output. */ if (print.printed) putc ('\n', print.outf); - if (ferror (print.outf) || fclose (print.outf)) - cpp_notice_from_errno (pfile, options->out_fname); + /* Don't close stdout (dependencies have yet to be output). */ + if (print.outf != stdout) + { + if (ferror (print.outf) || fclose (print.outf)) + cpp_notice_from_errno (pfile, options->out_fname); + } } /* Set up the callbacks as appropriate. */ static void -setup_callbacks () +setup_callbacks (pfile) + cpp_reader *pfile; { cpp_callbacks *cb = cpp_get_callbacks (pfile); diff --git a/gcc/gcc.c b/gcc/gcc.c index 5f8ada04c0a..436b97baf27 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -658,11 +658,12 @@ static const char *link_libgcc_spec = LINK_LIBGCC_SPEC; appropriate -B options. */ static const char *trad_capable_cpp = -"%{traditional|ftraditional|traditional-cpp:trad}cpp0"; +"%{traditional|ftraditional|traditional-cpp:tradcpp0}\ + %{!traditional:%{!ftraditional:%{!traditional-cpp:cc1 -E}}}"; static const char *cpp_unique_options = "%{C:%{!E:%eGNU C does not support -C without using -E}}\ - %{nostdinc*} %{C} %{v} %{I*} %{P} %{$} %I\ + %{!Q:-quiet} %{nostdinc*} %{C} %{v} %{I*} %{P} %{$} %I\ %{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\ %{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\ %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ diff --git a/gcc/objc/lang-specs.h b/gcc/objc/lang-specs.h index c6e2eb8808c..c6d1f9aa0e1 100644 --- a/gcc/objc/lang-specs.h +++ b/gcc/objc/lang-specs.h @@ -29,7 +29,7 @@ Boston, MA 02111-1307, USA. */ %{!E:%{!M:%{!MM:\ %{traditional|ftraditional|traditional-cpp:\ %eGNU Objective C no longer supports traditional compilation}\ - %{save-temps:cpp0 -lang-objc %{ansi:-std=c89}\ + %{save-temps:cc1obj -E -lang-objc %{ansi:-std=c89}\ %(cpp_options) %b.mi \n\ cc1obj -fpreprocessed %b.mi %(cc1_options) %{gen-decls}}\ %{!save-temps:\ diff --git a/gcc/tradcpp.c b/gcc/tradcpp.c index 3cff998e406..4ed6332ac7f 100644 --- a/gcc/tradcpp.c +++ b/gcc/tradcpp.c @@ -779,6 +779,10 @@ main (argc, argv) no_standard_includes = 1; break; + case 'q': + /* Accept -quiet silently. */ + break; + case '\0': /* JF handle '-' as file name meaning stdin or stdout */ if (in_fname == NULL) { in_fname = "";