public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFA: Lose another langhook
@ 2001-11-13 15:03 Neil Booth
  2001-11-13 15:03 ` Richard Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Neil Booth @ 2001-11-13 15:03 UTC (permalink / raw)
  To: gcc-patches

This loses finish_parse, by merging it in with the "finish" langhook.

It also moves finalization code out of compile_file into its own
subroutine, so we clean up properly in all circumstances.  This
reorganization also means I can properly handle an error from
cpp_read_main_file, avoiding a segfault.

Bootstrapped all non-Ada on x86 Linux, without regressions.  OK to
commit?

Neil.

	* Makefile.in (c-parse.o, c-common.o): Update dependencies.
	* c-common.c: Include diagnostic.h.
	(c_common_finish): New.
	* c-common.h (c_common_finish): New.
	* c-lang.c (LANG_HOOKS_FINISH): Override.
	* c-parse.in: Don't include diagnostic.h.
	(finish_parse): Remove.
	* langhooks.h: Update comments.
	* toplev.c (lang_dependent_init): New prototype.
	(finalize): New.
	(compile_file): Split cleanup code out to finalize.
	(lang_dependent_init): Stop if lang_hooks.init fails.
	(toplev_main): Update.
	* tree.h (finish_parse): Remove.

ada:	* misc.c (gnat_decode_option, gnat_init_options): Make definitions
	static too.
	(gnat_init): Don't return NULL.
	(finish_parse): Remove.
cp:	* lex.c (cxx_finish): Call c_common_finish.
	(finish_parse): Remove.
f:	* com.c (finish_parse): Remove.
	(ffe_finish): Move body of finish_parse.
java:	* lang.c (finish_parse): Rename to java_finish.
	(LANG_HOOKS_FINISH, java_finish): New.
objc:	* objc-act.c (LANG_HOOKS_FINISH): Override.

============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	2001/11/14 13:51:08	1.781
+++ gcc/Makefile.in	2001/11/15 15:09:09
@@ -1151,8 +1151,7 @@ s-crt0:	$(CRT0_S) $(MCRT0_S) $(GCC_PASSE
 c-errors.o: c-errors.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) flags.h \
     diagnostic.h $(TM_P_H)
 c-parse.o : $(srcdir)/c-parse.c $(CONFIG_H) $(TREE_H) c-lex.h $(GGC_H) intl.h \
-    $(C_TREE_H) input.h flags.h $(SYSTEM_H) toplev.h output.h $(CPPLIB_H) \
-    diagnostic.h
+    $(C_TREE_H) input.h flags.h $(SYSTEM_H) toplev.h output.h $(CPPLIB_H)
 	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $(srcdir)/c-parse.c
 
 $(srcdir)/c-parse.c: $(srcdir)/c-parse.y
@@ -1249,7 +1248,8 @@ s-under: $(GCC_PASSES)
 
 c-common.o : c-common.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(OBSTACK_H) \
 	$(C_COMMON_H) flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
-	$(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def $(TARGET_H)
+	$(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def $(TARGET_H) \
+	diagnostic.h
 
 # A file used by all variants of C and some other languages.
 
============================================================
Index: gcc/c-common.c
--- gcc/c-common.c	2001/11/15 10:00:20	1.272
+++ gcc/c-common.c	2001/11/15 15:09:18
@@ -30,6 +30,7 @@ Software Foundation, 59 Temple Place - S
 #include "ggc.h"
 #include "expr.h"
 #include "c-common.h"
+#include "diagnostic.h"
 #include "tm_p.h"
 #include "obstack.h"
 #include "c-lex.h"
@@ -3839,6 +3840,17 @@ c_common_lang_init (filename)
     c_init_attributes ();
 
   return filename;
+}
+
+/* Common finish hook for the C, ObjC and C++ front ends.  */
+void
+c_common_finish ()
+{
+  cpp_finish (parse_in);
+
+  /* For performance, avoid tearing down cpplib's internal structures.
+     Call cpp_errors () instead of cpp_destroy ().  */
+  errorcount += cpp_errors (parse_in);
 }
 
 static void
============================================================
Index: gcc/c-common.h
--- gcc/c-common.h	2001/11/15 10:00:23	1.96
+++ gcc/c-common.h	2001/11/15 15:09:21
@@ -541,6 +541,7 @@ extern void c_common_nodes_and_builtins	
 extern tree build_va_arg			PARAMS ((tree, tree));
 
 extern const char *c_common_lang_init		PARAMS ((const char *));
+extern void c_common_finish			PARAMS ((void));
 extern HOST_WIDE_INT c_common_get_alias_set	PARAMS ((tree));
 extern bool c_promoting_integer_type_p		PARAMS ((tree));
 extern int self_promoting_args_p		PARAMS ((tree));
============================================================
Index: gcc/c-lang.c
--- gcc/c-lang.c	2001/11/15 10:00:24	1.64
+++ gcc/c-lang.c	2001/11/15 15:09:22
@@ -54,6 +54,8 @@ static int c_cannot_inline_tree_fn PARAM
 #define LANG_HOOKS_NAME "GNU C"
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT c_init
+#undef LANG_HOOKS_FINISH
+#define LANG_HOOKS_FINISH c_common_finish
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS c_init_options
 #undef LANG_HOOKS_DECODE_OPTION
============================================================
Index: gcc/c-parse.in
--- gcc/c-parse.in	2001/11/15 10:00:25	1.113
+++ gcc/c-parse.in	2001/11/15 15:09:29
@@ -50,7 +50,6 @@ end ifc
 #include "output.h"
 #include "toplev.h"
 #include "ggc.h"
-#include "diagnostic.h"  
   
 #ifdef MULTIBYTE_CHARS
 #include <locale.h>
@@ -3528,14 +3527,6 @@ init_reswords ()
       C_IS_RESERVED_WORD (id) = 1;
       ridpointers [(int) reswords[i].rid] = id;
     }
-}
-
-void
-finish_parse ()
-{
-  cpp_finish (parse_in);
-  /* Call to cpp_destroy () omitted for performance reasons.  */
-  errorcount += cpp_errors (parse_in);
 }
 
 #define NAME(type) cpp_type2name (type)
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	2001/11/15 10:00:28	1.9
+++ gcc/langhooks.h	2001/11/15 15:09:29
@@ -61,7 +61,10 @@ struct lang_hooks
 
   /* Called after options parsing, to initialize the front end.  The
      main input filename is passed, which may be NULL; the front end
-     should return the original filename (e.g. foo.i -> foo.c).  */
+     should return the original filename (e.g. foo.i -> foo.c).
+     Return NULL to indicate a serious error of some sort; in that
+     case no compilation is performed, and the finish hook is called
+     immediately.  */
   const char * (*init) PARAMS ((const char *));
 
   /* Called last, as a finalizer.  */
============================================================
Index: gcc/toplev.c
--- gcc/toplev.c	2001/11/15 13:59:47	1.539
+++ gcc/toplev.c	2001/11/15 15:09:42
@@ -165,8 +165,9 @@ static void general_init PARAMS ((char *
 static void parse_options_and_default_flags PARAMS ((int, char **));
 static void process_options PARAMS ((void));
 static void lang_independent_init PARAMS ((void));
-static void lang_dependent_init PARAMS ((const char *));
+static int lang_dependent_init PARAMS ((const char *));
 static void init_asm_output PARAMS ((const char *));
+static void finalize PARAMS ((void));
 
 static void set_target_switch PARAMS ((const char *));
 static const char *decl_name PARAMS ((tree, int));
@@ -2168,7 +2169,7 @@ compile_file ()
   timevar_pop (TV_PARSE);
 
   if (flag_syntax_only)
-    goto finish_syntax;
+    return;
 
   globals = getdecls ();
 
@@ -2250,19 +2251,6 @@ compile_file ()
 	     IDENT_ASM_OP, version_string);
 #endif
 
-  /* Language-specific end of compilation actions.  */
- finish_syntax:
-  (*lang_hooks.finish) ();
-
-  /* Close the dump files.  */
-
-  if (flag_gen_aux_info)
-    {
-      fclose (aux_info_file);
-      if (errorcount)
-	unlink (aux_info_file_name);
-    }
-
   if (optimize > 0 && open_dump_file (DFI_combine, NULL))
     {
       timevar_push (TV_DUMP);
@@ -2270,45 +2258,6 @@ compile_file ()
       close_dump_file (DFI_combine, NULL, NULL_RTX);
       timevar_pop (TV_DUMP);
     }
-
-  /* Close non-debugging input and output files.  Take special care to note
-     whether fclose returns an error, since the pages might still be on the
-     buffer chain while the file is open.  */
-
-  finish_parse ();
-
-  if (ferror (asm_out_file) != 0)
-    fatal_io_error ("error writing to %s", asm_file_name);
-  if (fclose (asm_out_file) != 0)
-    fatal_io_error ("error closing %s", asm_file_name);
-
-  /* Do whatever is necessary to finish printing the graphs.  */
-  if (graph_dump_format != no_graph)
-    {
-      int i;
-
-      for (i = 0; i < (int) DFI_MAX; ++i)
-	if (dump_file[i].initialized && dump_file[i].graph_dump_p)
-	  {
-	    char seq[16];
-	    char *suffix;
-
-	    sprintf (seq, ".%02d.", i);
-	    suffix = concat (seq, dump_file[i].extension, NULL);
-	    finish_graph_dump_file (dump_base_name, suffix);
-	    free (suffix);
-	  }
-    }
-
-  if (mem_report)
-    {
-      ggc_print_statistics ();
-      stringpool_statistics ();
-      dump_tree_statistics ();
-    }
-
-  /* Free up memory for the benefit of leak detectors.  */
-  free_reg_info ();
 }
 \f
 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
@@ -5112,8 +5061,8 @@ lang_independent_init ()
   expand_dummy_function_end ();
 }
 \f
-/* Language-dependent initialization.  */
-static void
+/* Language-dependent initialization.  Returns non-zero on success.  */
+static int
 lang_dependent_init (name)
      const char *name;
 {
@@ -5125,10 +5074,11 @@ lang_dependent_init (name)
      not done yet.  This routine must return the original filename
      (e.g. foo.i -> foo.c) so can correctly initialize debug output.  */
   name = (*lang_hooks.init) (name);
-
-  if (name)
-    name = ggc_strdup (name);
+  if (name == NULL)
+    return 0;
 
+  /* Is this duplication necessary?  */
+  name = ggc_strdup (name);
   main_input_filename = input_filename = name;
   init_asm_output (name);
 
@@ -5154,6 +5104,65 @@ lang_dependent_init (name)
   (*debug_hooks->init) (name);
 
   timevar_pop (TV_SYMOUT);
+
+  return 1;
+}
+\f
+/* Clean up: close opened files, etc.  */
+
+static void
+finalize ()
+{
+  /* Close the dump files.  */
+  if (flag_gen_aux_info)
+    {
+      fclose (aux_info_file);
+      if (errorcount)
+	unlink (aux_info_file_name);
+    }
+
+  /* Close non-debugging input and output files.  Take special care to note
+     whether fclose returns an error, since the pages might still be on the
+     buffer chain while the file is open.  */
+
+  if (asm_out_file)
+    {
+      if (ferror (asm_out_file) != 0)
+	fatal_io_error ("error writing to %s", asm_file_name);
+      if (fclose (asm_out_file) != 0)
+	fatal_io_error ("error closing %s", asm_file_name);
+    }
+
+  /* Do whatever is necessary to finish printing the graphs.  */
+  if (graph_dump_format != no_graph)
+    {
+      int i;
+
+      for (i = 0; i < (int) DFI_MAX; ++i)
+	if (dump_file[i].initialized && dump_file[i].graph_dump_p)
+	  {
+	    char seq[16];
+	    char *suffix;
+
+	    sprintf (seq, ".%02d.", i);
+	    suffix = concat (seq, dump_file[i].extension, NULL);
+	    finish_graph_dump_file (dump_base_name, suffix);
+	    free (suffix);
+	  }
+    }
+
+  if (mem_report)
+    {
+      ggc_print_statistics ();
+      stringpool_statistics ();
+      dump_tree_statistics ();
+    }
+
+  /* Free up memory for the benefit of leak detectors.  */
+  free_reg_info ();
+
+  /* Language-specific end of compilation actions.  */
+  (*lang_hooks.finish) ();
 }
 \f
 /* Entry point of cc1, cc1plus, jc1, f771, etc.
@@ -5179,8 +5188,6 @@ toplev_main (argc, argv)
   if (exit_after_options)
     return (SUCCESS_EXIT_CODE);
 
-  /* Start timing total execution time.  */
-
   /* The bulk of command line switch processing.  */
   process_options ();
 
@@ -5193,10 +5200,11 @@ toplev_main (argc, argv)
      hashes etc.  */
   lang_independent_init ();
 
-  /* Language-dependent initialization.  */
-  lang_dependent_init (filename);
+  /* Language-dependent initialization.  Returns true on success.  */
+  if (lang_dependent_init (filename))
+    compile_file ();
 
-  compile_file ();
+  finalize ();
 
   /* Stop timing and print the times.  */
   timevar_stop (TV_TOTAL);
============================================================
Index: gcc/tree.h
--- gcc/tree.h	2001/11/15 10:00:29	1.282
+++ gcc/tree.h	2001/11/15 15:09:52
@@ -2647,8 +2647,6 @@ extern const char *(*decl_printable_name
 
 extern void (*incomplete_decl_finalize_hook)	PARAMS ((tree));
 
-extern void finish_parse			PARAMS ((void));
-
 /* Declare a predefined function.  Return the declaration.  This function is
    provided by each language frontend.  */
 extern tree builtin_function			PARAMS ((const char *, tree, int,
============================================================
Index: gcc/ada/misc.c
--- gcc/ada/misc.c	2001/11/15 10:00:53	1.12
+++ gcc/ada/misc.c	2001/11/15 15:09:54
@@ -192,7 +192,7 @@ yyparse ()
    it cannot decode. This routine returns 1 if it is successful, otherwise
    it returns 0. */
 
-int
+static int
 gnat_decode_option (argc, argv)
      int argc ATTRIBUTE_UNUSED;
      char **argv;
@@ -251,7 +251,7 @@ gnat_decode_option (argc, argv)
 
 /* Initialize for option processing.  */
 
-void
+static void
 gnat_init_options ()
 {
   /* Initialize gnat_argv with save_argv size */
@@ -394,6 +394,9 @@ gnat_init (filename)
   dwarf2out_set_demangle_name_func (convert_ada_name_to_qualified_name);
 #endif
 
+  if (filename == 0)
+    filename = "";
+
   return filename;
 }
 
@@ -877,11 +880,6 @@ insert_code_for (gnat_node)
       end_sequence ();
       emit_insns_after (insns, RTL_EXPR_RTL (get_gnu_tree (gnat_node)));
     }
-}
-
-void
-finish_parse ()
-{
 }
 
 #if 0
============================================================
Index: gcc/cp/lex.c
--- gcc/cp/lex.c	2001/11/15 10:00:58	1.256
+++ gcc/cp/lex.c	2001/11/15 15:09:58
@@ -265,7 +265,8 @@ void
 cxx_finish ()
 {
   if (flag_gnu_xref)
-    GNU_xref_end (errorcount+sorrycount);
+    GNU_xref_end (errorcount + sorrycount);
+  c_common_finish ();
 }
 
 static int *
@@ -739,14 +740,6 @@ cxx_init (filename)
   init_repo (filename);
 
   return filename;
-}
-
-void
-finish_parse ()
-{
-  cpp_finish (parse_in);
-  /* Call to cpp_destroy () omitted for performance reasons.  */
-  errorcount += cpp_errors (parse_in);
 }
 \f
 inline void
============================================================
Index: gcc/f/com.c
--- gcc/f/com.c	2001/11/15 10:01:03	1.140
+++ gcc/f/com.c	2001/11/15 15:10:30
@@ -14189,12 +14189,6 @@ ffecom_init_decl_processing ()
   ffe_init_0 ();
 }
 
-void
-finish_parse ()
-{
-  fclose (finput);
-}
-
 /* Delete the node BLOCK from the current binding level.
    This is used for the block inside a stmt expr ({...})
    so that the block can be reinserted where appropriate.  */
@@ -14303,6 +14297,8 @@ ffe_finish ()
 
   if (ffe_is_ffedebug ())
     malloc_pool_display (malloc_pool_image ());
+
+  fclose (finput);
 }
 
 static void
============================================================
Index: gcc/java/lang.c
--- gcc/java/lang.c	2001/11/15 10:01:08	1.79
+++ gcc/java/lang.c	2001/11/15 15:10:31
@@ -49,6 +49,7 @@ struct string_option
 };
 
 static const char *java_init PARAMS ((const char *));
+static void java_finish PARAMS ((void));
 static void java_init_options PARAMS ((void));
 static int java_decode_option PARAMS ((int, char **));
 static void put_decl_string PARAMS ((const char *, int));
@@ -199,6 +200,8 @@ static int dependency_tracking = 0;
 #define LANG_HOOKS_NAME "GNU Java"
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT java_init
+#undef LANG_HOOKS_FINISH
+#define LANG_HOOKS_FINISH java_finish
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS java_init_options
 #undef LANG_HOOKS_DECODE_OPTION
@@ -508,8 +511,8 @@ java_init (filename)
   return filename;
 }
 
-void
-finish_parse ()
+static void
+java_finish ()
 {
   jcf_dependency_write ();
 }
============================================================
Index: gcc/objc/objc-act.c
--- gcc/objc/objc-act.c	2001/11/15 10:01:10	1.105
+++ gcc/objc/objc-act.c	2001/11/15 15:10:45
@@ -456,6 +456,8 @@ static int print_struct_values = 0;
 #define LANG_HOOKS_NAME "GNU Objective-C"
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT objc_init
+#undef LANG_HOOKS_FINISH
+#define LANG_HOOKS_FINISH c_common_finish
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS objc_init_options
 #undef LANG_HOOKS_DECODE_OPTION

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: RFA: Lose another langhook
  2001-11-13 15:03 RFA: Lose another langhook Neil Booth
@ 2001-11-13 15:03 ` Richard Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2001-11-13 15:03 UTC (permalink / raw)
  To: Neil Booth; +Cc: gcc-patches

On Thu, Nov 15, 2001 at 07:20:16PM +0000, Neil Booth wrote:
> This loses finish_parse, by merging it in with the "finish" langhook.

Ok.


r~

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-18  4:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-13 15:03 RFA: Lose another langhook Neil Booth
2001-11-13 15:03 ` Richard Henderson

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