[incremental] Patch: FYI: rearrange BUILTINS_LOCATION

Tom Tromey tromey@redhat.com
Wed Mar 5 18:56:00 GMT 2008


I'm checking this in on the incremental-compiler branch.

I found out this week that the magic value of "2" for
BUILTINS_LOCATION is determined by having each front end open the file
"<built-in>" at the appropriate point in time.  Aside from being ugly,
this causes problems with the incremental compiler, where we prefer to
do things in a different order.  Furthermore, nothing actually
verifies that this actually happens properly.

This patch changes BUILTINS_LOCATION and changes gcc to enforce its
setting.  Currently this is done very early, but later (when I really
make mapped locations work in the server) this will change.

This updates all the other front ends, but I have not tried them at
all yet.

Tom

ChangeLog:
2008-03-05  Tom Tromey  <tromey@redhat.com>

	* c-opts.c (finish_options): Set input_location.
	* toplev.c (general_init): Create builtins location.
	* input.h (BUILTINS_LOCATION): Change value.

java/ChangeLog:
2008-03-05  Tom Tromey  <tromey@redhat.com>

	* lang.c (java_post_options): Don't initialize builtins location.
	Rename to main file.

fortran/ChangeLog:
2008-03-05  Tom Tromey  <tromey@redhat.com>

	* f95-lang.c (gfc_init): Don't set up builtins location.  Rename
	to main file.

treelang/ChangeLog:
2008-03-05  Tom Tromey  <tromey@redhat.com>

	* treetree.h (treelang_post_options): Declare.
	* treetree.c (LANG_HOOKS_POST_OPTIONS): New define.
	* tree1.c (treelang_post_options): New function.
	(treelang_init): Don't initialize builtins location.

Index: java/lang.c
===================================================================
--- java/lang.c	(revision 132841)
+++ java/lang.c	(working copy)
@@ -656,8 +656,7 @@
 	}
     }
 #ifdef USE_MAPPED_LOCATION
-  linemap_add (line_table, LC_ENTER, false, false, filename, 0);
-  linemap_add (line_table, LC_RENAME, false, false, "<built-in>", 0);
+  linemap_add (line_table, LC_RENAME, false, false, filename, 0);
 #endif
 
   /* Initialize the compiler back end.  */
Index: input.h
===================================================================
--- input.h	(revision 132841)
+++ input.h	(working copy)
@@ -1,6 +1,6 @@
 /* Declarations for variables relating to reading the source file.
    Used by parsers, lexical analyzers, and error message routines.
-   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007
+   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -26,7 +26,7 @@
 extern GTY(()) struct line_maps *line_table;
 
 /* The location for declarations in "<built-in>" */
-#define BUILTINS_LOCATION ((source_location) 2)
+#define BUILTINS_LOCATION ((source_location) 1)
 
 /* Note: if any of the types defined inside this #ifdef are changed,
    gengtype.c:define_location_structures must be updated to match.  */
Index: toplev.c
===================================================================
--- toplev.c	(revision 132841)
+++ toplev.c	(working copy)
@@ -1725,6 +1725,7 @@
 general_init (const char *argv0)
 {
   const char *p;
+  location_t loc;
 
   p = argv0 + strlen (argv0);
   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
@@ -1778,6 +1779,10 @@
   line_table = GGC_NEW (struct line_maps);
   linemap_init (line_table);
   line_table->reallocator = realloc_for_line_map;
+  linemap_add (line_table, LC_RENAME, 0, 0, _("<built-in>"), 0);
+  loc = linemap_line_start (line_table, 0, 1);
+  gcc_assert (loc == BUILTINS_LOCATION);
+
   init_ttree ();
 
   /* Initialize register usage now so switches may override.  */
Index: fortran/f95-lang.c
===================================================================
--- fortran/f95-lang.c	(revision 132841)
+++ fortran/f95-lang.c	(working copy)
@@ -277,8 +277,7 @@
 gfc_init (void)
 {
 #ifdef USE_MAPPED_LOCATION
-  linemap_add (line_table, LC_ENTER, false, false, gfc_source_file, 1);
-  linemap_add (line_table, LC_RENAME, false, false, "<built-in>", 0);
+  linemap_add (line_table, LC_RENAME, false, false, gfc_source_file, 1);
 #endif
 
   /* First initialize the backend.  */
Index: treelang/treetree.c
===================================================================
--- treelang/treetree.c	(revision 132841)
+++ treelang/treetree.c	(working copy)
@@ -5,7 +5,7 @@
    you are in the right place.
 
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
    Free Software Foundation, Inc.
 
    This code is based on toy.c written by Richard Kenner.
@@ -165,6 +165,8 @@
 */
 /* Hook routines and data unique to treelang.  */
 
+#undef LANG_HOOKS_POST_OPTIONS
+#define LANG_HOOKS_POST_OPTIONS treelang_post_options
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT treelang_init
 #undef LANG_HOOKS_NAME
Index: treelang/tree1.c
===================================================================
--- treelang/tree1.c	(revision 132841)
+++ treelang/tree1.c	(working copy)
@@ -134,20 +134,31 @@
   return 1;
 }
 
-/* Language dependent parser setup.  */
-
 bool
-treelang_init (void)
+treelang_post_options (const char **pfilename ATTRIBUTE_UNUSED)
 {
+  /* Init decls, etc.  */
+  treelang_init_decl_processing ();
+
 #ifndef USE_MAPPED_LOCATION
   input_filename = main_input_filename;
 #else
-  linemap_add (line_table, LC_ENTER, false, false, main_input_filename, 1);
+  linemap_add (line_table, LC_RENAME, false, false, main_input_filename, 1);
 #endif
 
+  return false;
+}
+
+/* Language dependent parser setup.  */
+
+bool
+treelang_init (void)
+{
   /* This error will not happen from GCC as it will always create a
      fake input file.  */
-  if (!input_filename || input_filename[0] == ' ' || !input_filename[0]) 
+  if (!main_input_filename
+      || main_input_filename[0] == ' '
+      || !main_input_filename[0]) 
     {
       if (!version_done)
         {
@@ -158,21 +169,13 @@
       return false;
     }
 
-  yyin = fopen (input_filename, "r");
+  yyin = fopen (main_input_filename, "r");
   if (!yyin)
     {
-      fprintf (stderr, "Unable to open input file %s\n", input_filename);
+      fprintf (stderr, "Unable to open input file %s\n", main_input_filename);
       exit (1);
     }
 
-#ifdef USE_MAPPED_LOCATION
-  linemap_add (line_table, LC_RENAME, false, false, "<built-in>", 1);
-  linemap_line_start (line_table, 0, 1);
-#endif
-
-  /* Init decls, etc.  */
-  treelang_init_decl_processing ();
-
   return true;
 }
 
Index: treelang/treetree.h
===================================================================
--- treelang/treetree.h	(revision 132841)
+++ treelang/treetree.h	(working copy)
@@ -2,7 +2,7 @@
    (compiler back end interface).
    
    Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2007 Free Software Foundation, Inc.
+   2004, 2005, 2007, 2008 Free Software Foundation, Inc.
    
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -58,6 +58,7 @@
 void treelang_init_decl_processing (void);
 void treelang_finish (void);
 bool treelang_init (void);
+bool treelang_post_options (const char **);
 unsigned int treelang_init_options (unsigned int, const char **);
 int treelang_handle_option (size_t scode, const char *arg, int value);
 void treelang_parse_file (int debug_flag);
Index: c-opts.c
===================================================================
--- c-opts.c	(revision 132841)
+++ c-opts.c	(working copy)
@@ -1538,6 +1538,10 @@
       cb_file_change (parse_in,
 		      linemap_add (line_table, LC_RENAME, 0, 0,
 				   _("<built-in>"), 0));
+      /* This is odd, but the above is historical spaghetti which
+	 looks a bit hard to change, and we really want things to end
+	 up with the proper builtins location.  */
+      input_location = BUILTINS_LOCATION;
 
       cpp_init_builtins (parse_in, flag_hosted);
       c_cpp_builtins (parse_in);



More information about the Gcc-patches mailing list