This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Death of separate preprocessor cpp0.


This is a re-work of Aldy's patch to remove cpp0.  It exports one new
function from cpplib, and limits changes to c-common.c and lower, so it
doesn't involve toplev.c.

There is still work to do in this area, but it tends to come under my
ongoing work on cleaning up the initialization of toplev.c, the three
C front ends, and improving the langhooks.  cppmain.c also needs to
be updated to not use global variables, and become a proper part of
cpplib using cpphash.h.

I also want to get tradcpp in cpplib.  But that should probably wait
till after some lexer improvements I have planned.

Bootstrapped x86 Linux.

Neil.

2002-03-24  Neil Booth  <neil@daikokuya.demon.co.uk>
	    Aldy Hernandez <aldyh@redhat.com>

	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.
	* 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.

============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	2002/03/22 11:11:20	1.844
+++ gcc/Makefile.in	2002/03/24 08:28:41
@@ -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 ins
  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) la
 	    $(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.
============================================================
Index: gcc/c-common.c
--- gcc/c-common.c	2002/03/21 23:15:28	1.302
+++ gcc/c-common.c	2002/03/24 08:28:47
@@ -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);
============================================================
Index: gcc/c-common.h
--- gcc/c-common.h	2002/03/21 18:39:11	1.120
+++ gcc/c-common.h	2002/03/24 08:28:51
@@ -372,6 +372,9 @@ extern void c_mark_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 *'.  */
 
============================================================
Index: gcc/c-decl.c
--- gcc/c-decl.c	2002/03/22 22:51:40	1.307
+++ gcc/c-decl.c	2002/03/24 08:29:07
@@ -685,6 +685,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;
============================================================
Index: gcc/c-objc-common.c
--- gcc/c-objc-common.c	2002/03/21 23:15:27	1.6
+++ gcc/c-objc-common.c	2002/03/24 08:29:08
@@ -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;
 
============================================================
Index: gcc/cpplib.h
--- gcc/cpplib.h	2002/03/22 21:59:00	1.204
+++ gcc/cpplib.h	2002/03/24 08:29:10
@@ -603,6 +603,9 @@ extern unsigned char *cpp_quote_string	P
 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
============================================================
Index: gcc/cppmain.c
--- gcc/cppmain.c	2002/03/22 22:28:50	1.93
+++ gcc/cppmain.c	2002/03/24 08:29:12
@@ -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,75 +61,16 @@ static void cb_ident	  PARAMS ((cpp_read
 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
      cause a linemarker to be output by maybe_print_line.  */
@@ -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);
 
============================================================
Index: gcc/gcc.c
--- gcc/gcc.c	2002/03/09 19:53:22	1.301
+++ gcc/gcc.c	2002/03/24 08:29:26
@@ -658,11 +658,12 @@ static const char *link_libgcc_spec = LI
    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*}\
@@ -827,11 +828,9 @@ static const struct compiler default_com
       %{!E:%{!M:%{!MM:\
           %{traditional|ftraditional:\
 %eGNU C no longer supports -traditional without -E}\
-	  %{save-temps|traditional-cpp:%(trad_capable_cpp) \
-		-lang-c %{ansi:-std=c89} %(cpp_options) %b.i \n\
+	  %{save-temps:cc1 -E -lang-c %{ansi:-std=c89} %(cpp_options) %b.i \n\
 		    cc1 -fpreprocessed %b.i %(cc1_options)}\
-	  %{!save-temps:%{!traditional-cpp:\
-		cc1 -lang-c %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}\
+	  %{!save-temps:cc1 -lang-c %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}\
         %{!fsyntax-only:%(invoke_as)}}}}", 0},
   {"-",
    "%{!E:%e-E required when input is from standard input}\
============================================================
Index: gcc/tradcpp.c
--- gcc/tradcpp.c	2002/02/02 18:56:35	1.47
+++ gcc/tradcpp.c	2002/03/24 08:29:40
@@ -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 = "";
============================================================
Index: gcc/cp/decl2.c
--- gcc/cp/decl2.c	2002/03/20 19:50:09	1.525
+++ gcc/cp/decl2.c	2002/03/24 08:29:51
@@ -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;
============================================================
Index: gcc/cp/lang-specs.h
--- gcc/cp/lang-specs.h	2002/01/29 12:09:36	1.46
+++ gcc/cp/lang-specs.h	2002/03/24 08:29:51
@@ -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}\
============================================================
Index: gcc/cp/lex.c
--- gcc/cp/lex.c	2002/03/20 07:58:34	1.270
+++ gcc/cp/lex.c	2002/03/24 08:29:54
@@ -685,6 +685,8 @@ cxx_init (filename)
   interface_unknown = 1;
 
   filename = c_common_init (filename);
+  if (filename == NULL)
+    return NULL;
 
   init_cp_pragma ();
 
============================================================
Index: gcc/objc/lang-specs.h
--- gcc/objc/lang-specs.h	2002/02/27 18:48:02	1.22
+++ gcc/objc/lang-specs.h	2002/03/24 08:29:54
@@ -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:\


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]