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]

[PATCH] Refactor expansion of -D and -I specs


This patch is the first of two patches to support top-level
bootstrap in the GCC driver.  This one has no behavioral
change, it only refactors gcc.c so that the same routine
used to output multilib paths is used to output include
paths.  The suffix used (like for example "nof" or "le"
in ppc multilibs) is "include", so the include_prefixes
will not end with "include" anymore.

This part also includes the removal and poisoning of
SPACE_AFTER_L_OPTION.

I also attach a sdiff between the old code for do_spec_1 and
the new do_spec_path routine, with the whitespace a bit
tweaked in the hope of aiding the review of the patch.
You can see that multilib_dir becomes dir_for_machine_suffix,
and multi_dir become dir_for_no_suffix.

Bootstrapped/regtested i686-pc-linux-gnu, ok for mainline?

Paolo

2004-04-30 Paolo Bonzini <bonzini@gnu.org>

	* gcc.c (struct prefix_list): Add forward declaration.
	(do_spec_path): New function, extracted from...
	(do_spec_1) <'D'>: ... here.  Drop support for
	SPACE_AFTER_L_OPTION.
	(do_spec_1) <'I'>: Use do_spec_path.
	(process_command): Do not store the 'include' suffix
	in include_prefixes.
	* system.h: Poison SPACE_AFTER_L_OPTION.

diff -cp gcc-backup/gcc/gcc.c gcc/gcc/gcc.c
*** gcc-backup/gcc/gcc.c	Fri Apr 30 18:28:51 2004
--- gcc/gcc/gcc.c	Fri Apr 30 20:02:09 2004
*************** static struct rusage rus, prus;
*** 290,295 ****
--- 290,296 ----
  
  /* Forward declaration for prototypes.  */
  struct path_prefix;
+ struct prefix_list;
  
  static void init_spec (void);
  static void store_arg (const char *, int, int);
*************** static const char *eval_spec_function (c
*** 323,328 ****
--- 324,330 ----
  static const char *handle_spec_function (const char *);
  static char *save_string (const char *, int);
  static void set_collect_gcc_options (void);
+ static void do_spec_path (struct prefix_list *, const char *, int, int, int, const char *, const char *);
  static int do_spec_1 (const char *, int, const char *);
  static int do_spec_2 (const char *);
  static void do_option_spec (const char *, const char *);
*************** process_command (int argc, const char **
*** 3276,3284 ****
  		nstore[endp - startp] = 0;
  	      add_prefix (&exec_prefixes, nstore, 0,
  			  PREFIX_PRIORITY_LAST, 0, NULL, 0);
! 	      add_prefix (&include_prefixes,
! 			  concat (nstore, "include", NULL),
! 			  0, PREFIX_PRIORITY_LAST, 0, NULL, 0);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
--- 3278,3285 ----
  		nstore[endp - startp] = 0;
  	      add_prefix (&exec_prefixes, nstore, 0,
  			  PREFIX_PRIORITY_LAST, 0, NULL, 0);
! 	      add_prefix (&include_prefixes, nstore, 0,
! 			  PREFIX_PRIORITY_LAST, 0, NULL, 0);
  	      if (*endp == 0)
  		break;
  	      endp = startp = endp + 1;
*************** warranty; not even for MERCHANTABILITY o
*** 3630,3654 ****
  		    && (IS_DIR_SEPARATOR (value[len - 1])))
  		  {
  		    if (len == 7)
! 		      add_prefix (&include_prefixes, "include", NULL,
  				  PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		    else
  		      {
! 			char * string = xmalloc (len + 1);
! 
! 			strncpy (string, value, len - 7);
! 			strcpy (string + len - 7, "include");
! 			add_prefix (&include_prefixes, string, NULL,
  				    PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		      }
  		  }
  
  		add_prefix (&exec_prefixes, value, NULL,
  			    PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
  		add_prefix (&startfile_prefixes, value, NULL,
  			    PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
! 		add_prefix (&include_prefixes, concat (value, "include", NULL),
! 			    NULL, PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		n_switches++;
  	      }
  	      break;
--- 3631,3654 ----
  		    && (IS_DIR_SEPARATOR (value[len - 1])))
  		  {
  		    if (len == 7)
! 		      add_prefix (&include_prefixes, "./", NULL,
  				  PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		    else
  		      {
! 		        char *string = xmalloc (len - 6);
! 			memcpy (string, value, len - 7);
! 			string[len - 7] = 0;
! 		        add_prefix (&include_prefixes, string, NULL,
  				    PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		      }
  		  }
  
  		add_prefix (&exec_prefixes, value, NULL,
  			    PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
  		add_prefix (&startfile_prefixes, value, NULL,
  			    PREFIX_PRIORITY_B_OPT, 0, &warn_B, 0);
! 		add_prefix (&include_prefixes, value, NULL,
! 			    PREFIX_PRIORITY_B_OPT, 0, NULL, 0);
  		n_switches++;
  	      }
  	      break;
*************** do_self_spec (const char *spec)
*** 4361,4366 ****
--- 4367,4473 ----
      }
  }
  
+ void
+ do_spec_path (struct prefix_list *pl, const char *option,
+ 	      int omit_if_relative, int separate_options,
+ 	      int only_subdir,
+ 	      const char *dir_for_machine_suffix,
+ 	      const char *dir_for_no_suffix)
+ {
+   static size_t bufsize = 0;
+   static char *buffer;
+   int idx;
+ 
+   /* Used on systems which record the specified -L dirs
+      and use them to search for dynamic linking.  */
+   /* Relative directories always come from -B,
+      and it is better not to use them for searching
+      at run time.  In particular, stage1 loses.  */
+   if (omit_if_relative
+       && !IS_ABSOLUTE_PATH (pl->prefix))
+     return;
+ 
+   /* Try subdirectory if there is one.  */
+   if (machine_suffix && dir_for_machine_suffix)
+     {
+       if (strlen (pl->prefix) + strlen (machine_suffix)
+ 	  >= bufsize)
+ 	bufsize = (strlen (pl->prefix)
+ 		  + strlen (machine_suffix)) * 2 + 1;
+       buffer = xrealloc (buffer, bufsize);
+       strcpy (buffer, pl->prefix);
+       strcat (buffer, machine_suffix);
+       if (is_directory (buffer, dir_for_machine_suffix, 1))
+ 	{
+ 	  do_spec_1 (option, separate_options, NULL);
+ 	  if (separate_options)
+ 	    do_spec_1 (" ", 0, NULL);
+ 	  do_spec_1 (buffer, 1, NULL);
+ 	  do_spec_1 (dir_for_machine_suffix, 1, NULL);
+ 	  /* Make this a separate argument.  */
+ 	  do_spec_1 (" ", 0, NULL);
+ 	}
+     }
+   if (!pl->require_machine_suffix && dir_for_no_suffix)
+     {
+       if (is_directory (pl->prefix, dir_for_no_suffix, 1))
+ 	{
+ 	  do_spec_1 (option, separate_options, NULL);
+ 	  if (separate_options)
+ 	    do_spec_1 (" ", 0, NULL);
+ 	  do_spec_1 (pl->prefix, 1, NULL);
+ 	  do_spec_1 (dir_for_no_suffix, 1, NULL);
+ 	  /* Make this a separate argument.  */
+ 	  do_spec_1 (" ", 0, NULL);
+ 	}
+     }
+ 
+   if (only_subdir)
+     return;
+ 
+   if (machine_suffix)
+     {
+       if (is_directory (pl->prefix, machine_suffix, 1))
+ 	{
+ 	  do_spec_1 (option, separate_options, NULL);
+ 	  if (separate_options)
+ 	    do_spec_1 (" ", 0, NULL);
+ 	  do_spec_1 (pl->prefix, 1, NULL);
+ 	  /* Remove slash from machine_suffix.  */
+ 	  if (strlen (machine_suffix) >= bufsize)
+ 	    bufsize = strlen (machine_suffix) * 2 + 1;
+ 	  buffer = xrealloc (buffer, bufsize);
+ 	  strcpy (buffer, machine_suffix);
+ 	  idx = strlen (buffer);
+ 	  if (IS_DIR_SEPARATOR (buffer[idx - 1]))
+ 	    buffer[idx - 1] = 0;
+ 	  do_spec_1 (buffer, 1, NULL);
+ 	  /* Make this a separate argument.  */
+ 	  do_spec_1 (" ", 0, NULL);
+ 	}
+     }
+   if (!pl->require_machine_suffix)
+     {
+       if (is_directory (pl->prefix, "", 1))
+ 	{
+ 	  do_spec_1 (option, separate_options, NULL);
+ 	  if (separate_options)
+ 	    do_spec_1 (" ", 0, NULL);
+ 	  /* Remove slash from pl->prefix.  */
+ 	  if (strlen (pl->prefix) >= bufsize)
+ 	    bufsize = strlen (pl->prefix) * 2 + 1;
+ 	  buffer = xrealloc (buffer, bufsize);
+ 	  strcpy (buffer, pl->prefix);
+ 	  idx = strlen (buffer);
+ 	  if (IS_DIR_SEPARATOR (buffer[idx - 1]))
+ 	    buffer[idx - 1] = 0;
+ 	  do_spec_1 (buffer, 1, NULL);
+ 	  /* Make this a separate argument.  */
+ 	  do_spec_1 (" ", 0, NULL);
+ 	}
+     }
+ }
+ 
  /* Process the sub-spec SPEC as a portion of a larger spec.
     This is like processing a whole spec except that we do
     not initialize at the beginning and we do not supply a
*************** do_spec_1 (const char *spec, int inswitc
*** 4497,4606 ****
  	  case 'D':
  	    {
  	      struct prefix_list *pl = startfile_prefixes.plist;
- 	      size_t bufsize = 100;
- 	      char *buffer = xmalloc (bufsize);
- 	      int idx;
  
  	      for (; pl; pl = pl->next)
  		{
  #ifdef RELATIVE_PREFIX_NOT_LINKDIR
! 		  /* Used on systems which record the specified -L dirs
! 		     and use them to search for dynamic linking.  */
! 		  /* Relative directories always come from -B,
! 		     and it is better not to use them for searching
! 		     at run time.  In particular, stage1 loses.  */
! 		  if (!IS_ABSOLUTE_PATH (pl->prefix))
! 		    continue;
  #endif
! 		  const char *multi_dir;
! 
! 		  multi_dir = pl->os_multilib ? multilib_os_dir
! 					      : multilib_dir;
! 		  /* Try subdirectory if there is one.  */
! 		  if (multilib_dir != NULL || (pl->os_multilib && multilib_os_dir != NULL))
! 		    {
! 		      if (machine_suffix && multilib_dir)
! 		        {
! 			  if (strlen (pl->prefix) + strlen (machine_suffix)
! 			      >= bufsize)
! 			    bufsize = (strlen (pl->prefix)
! 				       + strlen (machine_suffix)) * 2 + 1;
! 			    buffer = xrealloc (buffer, bufsize);
! 			    strcpy (buffer, pl->prefix);
! 			    strcat (buffer, machine_suffix);
! 			    if (is_directory (buffer, multilib_dir, 1))
! 			      {
! 			        do_spec_1 ("-L", 0, NULL);
! 			        do_spec_1 (buffer, 1, NULL);
! 			        do_spec_1 (multilib_dir, 1, NULL);
! 			        /* Make this a separate argument.  */
! 			        do_spec_1 (" ", 0, NULL);
! 	   		      }
! 		        }
!   		     if (!pl->require_machine_suffix)
!    		       {
! 		         if (is_directory (pl->prefix, multi_dir, 1))
! 			    {
! 			      do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! 			      do_spec_1 (" ", 0, NULL);
! #endif
! 			      do_spec_1 (pl->prefix, 1, NULL);
! 			      do_spec_1 (multi_dir, 1, NULL);
! 			      /* Make this a separate argument.  */
! 			      do_spec_1 (" ", 0, NULL);
! 			    }
! 			}
! 		    }
! 		  if (machine_suffix)
! 		    {
! 		      if (is_directory (pl->prefix, machine_suffix, 1))
! 			{
! 			  do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! 			  do_spec_1 (" ", 0, NULL);
! #endif
! 			  do_spec_1 (pl->prefix, 1, NULL);
! 			  /* Remove slash from machine_suffix.  */
! 			  if (strlen (machine_suffix) >= bufsize)
! 			    bufsize = strlen (machine_suffix) * 2 + 1;
! 			  buffer = xrealloc (buffer, bufsize);
! 			  strcpy (buffer, machine_suffix);
! 			  idx = strlen (buffer);
! 			  if (IS_DIR_SEPARATOR (buffer[idx - 1]))
! 			    buffer[idx - 1] = 0;
! 			  do_spec_1 (buffer, 1, NULL);
! 			  /* Make this a separate argument.  */
! 			  do_spec_1 (" ", 0, NULL);
! 			}
! 		    }
! 		  if (!pl->require_machine_suffix)
! 		    {
! 		      if (is_directory (pl->prefix, "", 1))
! 			{
! 			  do_spec_1 ("-L", 0, NULL);
! #ifdef SPACE_AFTER_L_OPTION
! 			  do_spec_1 (" ", 0, NULL);
! #endif
! 			  /* Remove slash from pl->prefix.  */
! 			  if (strlen (pl->prefix) >= bufsize)
! 			    bufsize = strlen (pl->prefix) * 2 + 1;
! 			  buffer = xrealloc (buffer, bufsize);
! 			  strcpy (buffer, pl->prefix);
! 			  idx = strlen (buffer);
! 			  if (IS_DIR_SEPARATOR (buffer[idx - 1]))
! 			    buffer[idx - 1] = 0;
! 			  do_spec_1 (buffer, 1, NULL);
! 			  /* Make this a separate argument.  */
! 			  do_spec_1 (" ", 0, NULL);
! 			}
! 		    }
  		}
- 	      free (buffer);
  	    }
  	    break;
  
--- 4604,4625 ----
  	  case 'D':
  	    {
  	      struct prefix_list *pl = startfile_prefixes.plist;
  
  	      for (; pl; pl = pl->next)
  		{
+ 		  const char *no_suffix_multilib_dir;
+ 
+ 		  no_suffix_multilib_dir = pl->os_multilib ? multilib_os_dir
+ 					   : multilib_dir;
+ 		  /* Do not separate options, include non-multilibbed variant.  */
+ 		  do_spec_path (pl, "-L",
  #ifdef RELATIVE_PREFIX_NOT_LINKDIR
! 				1,
! #else
! 				0,
  #endif
! 				0, 0, multilib_dir, no_suffix_multilib_dir);
  		}
  	    }
  	    break;
  
*************** do_spec_1 (const char *spec, int inswitc
*** 4852,4864 ****
  		}
  
  	      for (; pl; pl = pl->next)
! 		{
! 		  do_spec_1 ("-isystem", 1, NULL);
! 		  /* Make this a separate argument.  */
! 		  do_spec_1 (" ", 0, NULL);
! 		  do_spec_1 (pl->prefix, 1, NULL);
! 		  do_spec_1 (" ", 0, NULL);
! 		}
  	    }
  	    break;
  
--- 4871,4878 ----
  		}
  
  	      for (; pl; pl = pl->next)
! 		/* Separate options, don't include non-suffixed variant.  */
! 		do_spec_path (pl, "-isystem", 0, 1, 1, "include", "include");
  	    }
  	    break;
  
diff -cp gcc-backup/gcc/system.h gcc/gcc/system.h
*** gcc-backup/gcc/system.h	Fri Apr 30 18:28:51 2004
--- gcc/gcc/system.h	Fri Apr 30 20:16:17 2004
*************** typedef char _Bool;
*** 641,647 ****
  	FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE		   \
  	TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE		   \
  	DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE		   \
! 	SUNOS4_SHARED_LIBRARIES
  
  /* Hooks that are no longer used.  */
   #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE	\
--- 641,647 ----
  	FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE		   \
  	TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE		   \
  	DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE		   \
! 	SUNOS4_SHARED_LIBRARIES SPACE_AFTER_L_OPTION
  
  /* Hooks that are no longer used.  */
   #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE	\
							      >	void
							      >	do_spec_path (struct prefix_list *pl, const char *option,
							      >	              int omit_if_relative, int separate_options,
							      >	              int only_subdir,
							      >	              const char *dir_for_machine_suffix,
							      >	              const char *dir_for_no_suffix)
							      >	{
							      >	  static size_t bufsize = 0;
							      >	  static char *buffer;
#ifdef RELATIVE_PREFIX_NOT_LINKDIR			      |	  int idx;
  /* Used on systems which record the specified -L dirs	
     and use them to search for dynamic linking.  */	
  /* Relative directories always come from -B,		
     and it is better not to use them for searching	
     at run time.  In particular, stage1 loses.  */	
  if (!IS_ABSOLUTE_PATH (pl->prefix))			      |	  if (omit_if_relative
    continue;						      |	      && !IS_ABSOLUTE_PATH (pl->prefix))
#endif							      |	    return;
  multi_dir = pl->os_multilib ? multilib_os_dir : multilib_di <
							
  /* Try subdirectory if there is one.  */		
  if (multilib_dir != NULL				      |	      if (machine_suffix && dir_for_machine_suffix)
      || (pl->os_multilib && multilib_os_dir != NULL))	      <
    {							      <
      if (machine_suffix && multilib_dir)		      <
        {						
          if (strlen (pl->prefix) + strlen (machine_suffix)
              >= bufsize)				
            bufsize = (strlen (pl->prefix)		
                       + strlen (machine_suffix)) * 2 + 1;
          buffer = xrealloc (buffer, bufsize);		
          strcpy (buffer, pl->prefix);			
          strcat (buffer, machine_suffix);		
          if (is_directory (buffer, multilib_dir, 1))	      |	          if (is_directory (buffer, dir_for_machine_suffix, 1
            {						
              do_spec_1 ("-L", 0, NULL);		      |	              do_spec_1 (option, separate_options, NULL);
#ifdef SPACE_AFTER_L_OPTION				      |	              if (separate_options)
              do_spec_1 (" ", 0, NULL);			      |	                do_spec_1 (" ", 0, NULL);
#endif							      <
              do_spec_1 (buffer, 1, NULL);		
              do_spec_1 (multilib_dir, 1, NULL);	      |	              do_spec_1 (dir_for_machine_suffix, 1, NULL);
              /* Make this a separate argument.  */	
              do_spec_1 (" ", 0, NULL);			
            }						
        }						
      if (!pl->require_machine_suffix)			      |	      if (!pl->require_machine_suffix && dir_for_no_suffix)
        {						
          if (is_directory (pl->prefix, multi_dir, 1))	      |	          if (is_directory (pl->prefix, dir_for_no_suffix, 1)
            {						
              do_spec_1 ("-L", 0, NULL);		      |	              do_spec_1 (option, separate_options, NULL);
#ifdef SPACE_AFTER_L_OPTION				      |	              if (separate_options)
              do_spec_1 (" ", 0, NULL);			      |	                do_spec_1 (" ", 0, NULL);
#endif							      <
              do_spec_1 (pl->prefix, 1, NULL);		
              do_spec_1 (multi_dir, 1, NULL);		      |	              do_spec_1 (dir_for_no_suffix, 1, NULL);
              /* Make this a separate argument.  */	
              do_spec_1 (" ", 0, NULL);			
            }						
        }						
    }							      |
							      >	  if (only_subdir)
							      >	    return;
							      >
  if (machine_suffix)					
    {							
      if (is_directory (pl->prefix, machine_suffix, 1))	
        {						
          do_spec_1 ("-L", 0, NULL);			      |	          do_spec_1 (option, separate_options, NULL);
#ifdef SPACE_AFTER_L_OPTION				      |	          if (separate_options)
          do_spec_1 (" ", 0, NULL);			      |	            do_spec_1 (" ", 0, NULL);
#endif							      <
          do_spec_1 (pl->prefix, 1, NULL);		
          /* Remove slash from machine_suffix.  */	
          if (strlen (machine_suffix) >= bufsize)	
            bufsize = strlen (machine_suffix) * 2 + 1;	
          buffer = xrealloc (buffer, bufsize);		
          strcpy (buffer, machine_suffix);		
          idx = strlen (buffer);			
          if (IS_DIR_SEPARATOR (buffer[idx - 1]))	
            buffer[idx - 1] = 0;			
          do_spec_1 (buffer, 1, NULL);			
          /* Make this a separate argument.  */		
          do_spec_1 (" ", 0, NULL);			
        }						
    }							
  if (!pl->require_machine_suffix)			
    {							
      if (is_directory (pl->prefix, "", 1))		
        {						
          do_spec_1 ("-L", 0, NULL);			      |	          do_spec_1 (option, separate_options, NULL);
#ifdef SPACE_AFTER_L_OPTION				      |	          if (separate_options)
          do_spec_1 (" ", 0, NULL);			      |	            do_spec_1 (" ", 0, NULL);
#endif							      <
          /* Remove slash from pl->prefix.  */		
          if (strlen (pl->prefix) >= bufsize)		
            bufsize = strlen (pl->prefix) * 2 + 1;	
          buffer = xrealloc (buffer, bufsize);		
          strcpy (buffer, pl->prefix);			
          idx = strlen (buffer);			
          if (IS_DIR_SEPARATOR (buffer[idx - 1]))	
            buffer[idx - 1] = 0;			
          do_spec_1 (buffer, 1, NULL);			
          /* Make this a separate argument.  */		
          do_spec_1 (" ", 0, NULL);			
        }						
    }							
							      >	}

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