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]

init_options langhook tweak


This passes down argc and argv, which is useful to some front ends,
and removes the need for the global variables save_argc and save_argv.

Bootstrapped all except Ada.

Neil.

	* c-common.h (c_common_init_options): New prototype.
	* c-opts.c (deferred_size): Remove.
	(defer_opt): Array is now pre-allocated.
	(c_common_init_options): Pre-allocate deferred_opts.  Make
	lang_flags unsigned.
	(push_command_line_options): Free deferred_opts.
	* hooks.c (hook_uint_uint_constcharptrptr_0): New.
	* hooks.h (hook_uint_uint_constcharptrptr_0): New.
	* langhooks-def.h (LANG_HOOKS_INIT_OPTIONS): Update.
	* langhooks.h (struct lang_hooks): New prototype for init_options.
	* main.c (main): Cast argv.
	* opts.c (handle_option, handle_options): Update prototypes.
	(decode_options): save_argc, save_argv are not global.  Constify.
	* opts.h (decode_options): New prototype.
	* toplev.c (general_init): New protoype.
	(save_argv): Make static.
	(save_argc): Remove.
	(print_switch_values, general_init): Constify.
	(toplev_main): Save argv.
	* toplev.h (toplev_main): Update prototype.
	(save_argc, save_argv): Remove.
ada:
	* misc.c (save_argc, save_argv): Make static.
	(gnat_init_options): New prototype.
	(gnat_init_options): Update.
f:
	* top.c (ffe_init_options): Update prototype.
	* top.h (ffe_init_options): Update prototype.
java:
	* lang.c (java_init_options): Update prototype.
treelang:
	* tree1.c (treelang_init_options): Update prototype.
	* treelang.h (treelang_init_options): Update prototype.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.185
diff -u -p -r1.185 c-common.h
--- c-common.h	30 Jun 2003 19:36:20 -0000	1.185
+++ c-common.h	1 Jul 2003 21:29:02 -0000
@@ -953,7 +953,7 @@ extern void disable_builtin_function (co
 
 extern tree build_va_arg (tree, tree);
 
-extern int c_common_init_options (void);
+extern unsigned int c_common_init_options (unsigned int, const char **);
 extern bool c_common_post_options (const char **);
 extern bool c_common_init (void);
 extern void c_common_finish (void);
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.65
diff -u -p -r1.65 c-opts.c
--- c-opts.c	30 Jun 2003 19:36:20 -0000	1.65
+++ c-opts.c	1 Jul 2003 21:29:02 -0000
@@ -92,8 +92,8 @@ static bool quote_chain_split;
 /* If -Wunused-macros.  */
 static bool warn_unused_macros;
 
-/* Number of deferred options, deferred options array size.  */
-static size_t deferred_count, deferred_size;
+/* Number of deferred options.  */
+static size_t deferred_count;
 
 /* Number of deferred options scanned for -include.  */
 static size_t include_cursor;
@@ -191,29 +191,16 @@ missing_arg (enum opt_code code)
 static void
 defer_opt (enum opt_code code, const char *arg)
 {
-  /* FIXME: this should be in c_common_init_options, which should take
-     argc and argv.  */
-  if (!deferred_opts)
-    {
-      extern int save_argc;
-      deferred_size = save_argc;
-      deferred_opts = (struct deferred_opt *)
-	xmalloc (deferred_size * sizeof (struct deferred_opt));
-    }
-
-  if (deferred_count == deferred_size)
-    abort ();
-
   deferred_opts[deferred_count].code = code;
   deferred_opts[deferred_count].arg = arg;
   deferred_count++;
 }
 
 /* Common initialization before parsing options.  */
-int
-c_common_init_options (void)
+unsigned int
+c_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED)
 {
-  static const int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
+  static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
 
   /* This is conditionalized only because that is the way the front
      ends used to do it.  Maybe this should be unconditional?  */
@@ -242,6 +229,9 @@ c_common_init_options (void)
   flag_exceptions = c_dialect_cxx ();
   warn_pointer_arith = c_dialect_cxx ();
 
+  deferred_opts = (struct deferred_opt *)
+    xmalloc (argc * sizeof (struct deferred_opt));
+
   return lang_flags[c_language];
 }
 
@@ -1406,6 +1396,7 @@ push_command_line_include (void)
 
   if (include_cursor == deferred_count)
     {
+      free (deferred_opts);
       /* Restore the line map from <command line>.  */
       cpp_change_file (parse_in, LC_RENAME, main_input_filename);
       /* -Wunused-macros should only warn about macros defined hereafter.  */
Index: hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.c,v
retrieving revision 1.17
diff -u -p -r1.17 hooks.c
--- hooks.c	20 Jun 2003 17:30:01 -0000	1.17
+++ hooks.c	1 Jul 2003 21:29:02 -0000
@@ -133,6 +133,13 @@ hook_int_size_t_constcharptr_int_0 (size
   return 0;
 }
 
+unsigned int
+hook_uint_uint_constcharptrptr_0 (unsigned int a ATTRIBUTE_UNUSED,
+				  const char **b ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
 void
 hook_void_tree (a)
      tree a ATTRIBUTE_UNUSED;
Index: hooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.h,v
retrieving revision 1.18
diff -u -p -r1.18 hooks.h
--- hooks.h	20 Jun 2003 17:30:02 -0000	1.18
+++ hooks.h	1 Jul 2003 21:29:02 -0000
@@ -44,6 +44,8 @@ int hook_int_void_0 (void);
 int hook_int_size_t_constcharptr_int_0 (size_t, const char *, int);
 int hook_int_void_no_regs (void);
 
+unsigned hook_uint_uint_constcharptrptr_0 (unsigned, const char **);
+
 bool default_can_output_mi_thunk_no_vcall
   PARAMS ((tree, HOST_WIDE_INT, HOST_WIDE_INT, tree));
 
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.52
diff -u -p -r1.52 langhooks-def.h
--- langhooks-def.h	25 Jun 2003 17:29:13 -0000	1.52
+++ langhooks-def.h	1 Jul 2003 21:29:02 -0000
@@ -90,8 +90,8 @@ void write_global_declarations PARAMS ((
 #define LANG_HOOKS_FINISH		lhd_do_nothing
 #define LANG_HOOKS_PARSE_FILE		lhd_do_nothing_i
 #define LANG_HOOKS_CLEAR_BINDING_STACK	lhd_clear_binding_stack
-#define LANG_HOOKS_INIT_OPTIONS		hook_int_void_0
-#define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constharptr_int_0
+#define LANG_HOOKS_INIT_OPTIONS		hook_uint_uint_constcharptrptr_0
+#define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constcharptr_int_0
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
 #define LANG_HOOKS_GET_ALIAS_SET	lhd_get_alias_set
 #define LANG_HOOKS_EXPAND_CONSTANT	lhd_return_tree
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.60
diff -u -p -r1.60 langhooks.h
--- langhooks.h	25 Jun 2003 17:29:13 -0000	1.60
+++ langhooks.h	1 Jul 2003 21:29:02 -0000
@@ -207,7 +207,7 @@ struct lang_hooks
   /* The first callback made to the front end, for simple
      initialization needed before any calls to handle_option.  Return
      the language mask to filter the switch array with.  */
-  int (*init_options) PARAMS ((void));
+  unsigned int (*init_options) (unsigned int argc, const char **argv);
 
   /* Handle the switch CODE, which has real type enum opt_code from
      options.h.  If the switch takes an argument, it is passed in ARG
Index: main.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/main.c,v
retrieving revision 1.5
diff -u -p -r1.5 main.c
--- main.c	16 Dec 2002 18:19:43 -0000	1.5
+++ main.c	1 Jul 2003 21:29:02 -0000
@@ -34,5 +34,5 @@ main (argc, argv)
   int argc;
   char **argv;
 {
-  return toplev_main (argc, argv);
+  return toplev_main (argc, (const char **) argv);
 }
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.20
diff -u -p -r1.20 opts.c
--- opts.c	29 Jun 2003 01:17:54 -0000	1.20
+++ opts.c	1 Jul 2003 21:29:03 -0000
@@ -131,11 +131,11 @@ static size_t find_opt (const char *, in
 static int common_handle_option (size_t scode, const char *arg, int value);
 static void handle_param (const char *);
 static void set_Wextra (int);
-static unsigned int handle_option (char **argv, unsigned int lang_mask);
+static unsigned int handle_option (const char **argv, unsigned int lang_mask);
 static char *write_langs (unsigned int lang_mask);
 static void complain_wrong_lang (const char *, const struct cl_option *,
 				 unsigned int lang_mask);
-static void handle_options (unsigned int, char **, unsigned int lang_mask);
+static void handle_options (unsigned int, const char **, unsigned int);
 
 /* Perform a binary search to find which option the command-line INPUT
    matches.  Returns its index in the option array, and N_OPTS
@@ -286,7 +286,7 @@ complain_wrong_lang (const char *text, c
 /* Handle the switch beginning at ARGV for the language indicated by
    LANG_MASK.  Returns the number of switches consumed.  */
 static unsigned int
-handle_option (char **argv, unsigned int lang_mask)
+handle_option (const char **argv, unsigned int lang_mask)
 {
   size_t opt_index;
   const char *opt, *arg = 0;
@@ -408,7 +408,7 @@ handle_option (char **argv, unsigned int
    contains has a single bit set representing the current
    language.  */
 static void
-handle_options (unsigned int argc, char **argv, unsigned int lang_mask)
+handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
 {
   unsigned int n, i;
 
@@ -427,16 +427,12 @@ handle_options (unsigned int argc, char 
 /* Parse command line options and set default flag values.  Do minimal
    options processing.  */
 void
-decode_options (int argc, char **argv)
+decode_options (unsigned int argc, const char **argv)
 {
-  int i, lang_mask;
-
-  /* Save in case md file wants to emit args as a comment.  */
-  save_argc = argc;
-  save_argv = argv;
+  unsigned int i, lang_mask;
 
   /* Perform language-specific options initialization.  */
-  lang_mask = (*lang_hooks.init_options) ();
+  lang_mask = (*lang_hooks.init_options) (argc, argv);
 
   /* Scan to see what optimization level has been specified.  That will
      determine the default value of many flags.  */
@@ -450,7 +446,7 @@ decode_options (int argc, char **argv)
       else if (argv[i][0] == '-' && argv[i][1] == 'O')
 	{
 	  /* Handle -Os, -O2, -O3, -O69, ...  */
-	  char *p = &argv[i][2];
+	  const char *p = &argv[i][2];
 
 	  if ((p[0] == 's') && (p[1] == 0))
 	    {
Index: opts.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.h,v
retrieving revision 1.8
diff -u -p -r1.8 opts.h
--- opts.h	28 Jun 2003 06:18:10 -0000	1.8
+++ opts.h	1 Jul 2003 21:29:03 -0000
@@ -21,7 +21,7 @@ Software Foundation, 59 Temple Place - S
 #ifndef GCC_OPTS_H
 #define GCC_OPTS_H
 
-extern void decode_options (int argc, char **argv);
+extern void decode_options (unsigned int argc, const char **argv);
 
 struct cl_option
 {
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.795
diff -u -p -r1.795 toplev.c
--- toplev.c	1 Jul 2003 12:18:01 -0000	1.795
+++ toplev.c	1 Jul 2003 21:29:04 -0000
@@ -104,7 +104,7 @@ extern tree last_assemble_variable_decl;
 
 extern void reg_alloc (void);
 
-static void general_init (char *);
+static void general_init (const char *);
 static void do_compile (void);
 static void process_options (void);
 static void backend_init (void);
@@ -172,9 +172,8 @@ static bool no_backend;
 
 const char *progname;
 
-/* Copy of arguments to toplev_main.  */
-int save_argc;
-char **save_argv;
+/* Copy of argument vector to toplev_main.  */
+static const char **save_argv;
 
 /* Name of top-level original source file (what was input to cpp).
    This comes from the #-command at the beginning of the actual input.
@@ -4408,7 +4407,7 @@ print_switch_values (FILE *file, int pos
 		     const char *indent, const char *sep, const char *term)
 {
   size_t j;
-  char **p;
+  const char **p;
 
   /* Fill in the -frandom-seed option, if the user didn't pass it, so
      that it can be printed below.  This helps reproducibility.  Of
@@ -4537,9 +4536,9 @@ init_asm_output (const char *name)
    options are parsed.  Signal handlers, internationalization etc.
    ARGV0 is main's argv[0].  */
 static void
-general_init (char *argv0)
+general_init (const char *argv0)
 {
-  char *p;
+  const char *p;
 
   p = argv0 + strlen (argv0);
   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
@@ -4975,8 +4974,10 @@ do_compile (void)
    It is not safe to call this function more than once.  */
 
 int
-toplev_main (int argc, char **argv)
+toplev_main (unsigned int argc, const char **argv)
 {
+  save_argv = argv;
+
   /* Initialization of GCC's environment, and diagnostics.  */
   general_init (argv[0]);
 
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.102
diff -u -p -r1.102 toplev.h
--- toplev.h	28 Jun 2003 06:18:10 -0000	1.102
+++ toplev.h	1 Jul 2003 21:29:04 -0000
@@ -26,7 +26,7 @@ Software Foundation, 59 Temple Place - S
 #define skip_leading_substring(whole,  part) \
    (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
 
-extern int toplev_main			(int, char **);
+extern int toplev_main			(unsigned int, const char **);
 extern int read_integral_parameter	(const char *, const char *,
 					 const int);
 extern void strip_off_ending		(char *, int);
@@ -101,10 +101,6 @@ extern const char *aux_info_file_name;
 extern const char *asm_file_name;
 extern bool exit_after_options;
 extern bool version_flag;
-
-/* Copy of arguments to toplev_main.  */
-extern int save_argc;
-extern char **save_argv;
 
 extern int target_flags_explicit;
 
Index: ada/misc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/misc.c,v
retrieving revision 1.58
diff -u -p -r1.58 misc.c
--- ada/misc.c	27 Jun 2003 09:49:39 -0000	1.58
+++ ada/misc.c	1 Jul 2003 21:29:04 -0000
@@ -78,12 +78,10 @@
 #include "options.h"
 
 extern FILE *asm_out_file;
-extern int save_argc;
-extern char **save_argv;
 
 static size_t gnat_tree_size		PARAMS ((enum tree_code));
 static bool gnat_init			PARAMS ((void));
-static int gnat_init_options		PARAMS ((void));
+static unsigned int gnat_init_options	(unsigned int, const char **);
 static int gnat_handle_option (size_t scode, const char *arg, int value);
 static HOST_WIDE_INT gnat_get_alias_set	PARAMS ((tree));
 static void gnat_print_decl		PARAMS ((FILE *, tree, int));
@@ -181,6 +179,10 @@ const char *const tree_code_name[] = {
 };
 #undef DEFTREECODE
 
+/* Command-line argc and argv.  */
+static unsigned int save_argc;
+static const char **save_argv;
+
 /* gnat standard argc argv */
 
 extern int gnat_argc;
@@ -222,7 +224,7 @@ gnat_handle_option (size_t scode, const 
 {
   enum opt_code code = (enum opt_code) scode;
   char *q;
-  int i;
+  unsigned int i;
 
   /* Ignore file names.  */
   if (code == N_OPTS)
@@ -279,13 +281,16 @@ gnat_handle_option (size_t scode, const 
 
 /* Initialize for option processing.  */
 
-static int
-gnat_init_options ()
+static unsigned int
+gnat_init_options (unsigned int argc, const char **argv)
 {
-  /* Initialize gnat_argv with save_argv size */
-  gnat_argv = (char **) xmalloc ((save_argc + 1) * sizeof (gnat_argv[0])); 
-  gnat_argv[0] = save_argv[0];     /* name of the command */ 
+  /* Initialize gnat_argv with save_argv size.  */
+  gnat_argv = (char **) xmalloc ((argc + 1) * sizeof (argv[0])); 
+  gnat_argv[0] = argv[0];     /* name of the command */ 
   gnat_argc = 1;
+
+  save_argc = argc;
+  save_argv = argv;
 
   return CL_Ada;
 }
Index: f/top.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/top.c,v
retrieving revision 1.36
diff -u -p -r1.36 top.c
--- f/top.c	26 Jun 2003 06:05:35 -0000	1.36
+++ f/top.c	1 Jul 2003 21:29:05 -0000
@@ -156,8 +156,9 @@ ffe_is_digit_string_ (const char *s)
 }
 
 /* Get ready for options handling.  */
-int
-ffe_init_options ()
+unsigned int
+ffe_init_options (unsigned int argc ATTRIBUTE_UNUSED,
+		  const char **argv ATTRIBUTE_UNUSED)
 {
   /* Set default options for Fortran.  */
   flag_move_all_movables = 1;
Index: f/top.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/top.h,v
retrieving revision 1.16
diff -u -p -r1.16 top.h
--- f/top.h	14 Jun 2003 12:26:35 -0000	1.16
+++ f/top.h	1 Jul 2003 21:29:05 -0000
@@ -141,7 +141,7 @@ extern bool ffe_in_4;
 
 /* Declare functions with prototypes. */
 
-int ffe_init_options (void);
+unsigned int ffe_init_options (unsigned int, const char **);
 int ffe_handle_option (size_t code, const char *arg, int on);
 void ffe_file (ffewhereFile wf, FILE *f);
 void ffe_init_0 (void);
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.137
diff -u -p -r1.137 lang.c
--- java/lang.c	26 Jun 2003 06:05:36 -0000	1.137
+++ java/lang.c	1 Jul 2003 21:29:05 -0000
@@ -50,7 +50,7 @@ The Free Software Foundation is independ
 
 static bool java_init (void);
 static void java_finish (void);
-static int java_init_options (void);
+static unsigned int java_init_options (unsigned int, const char **);
 static bool java_post_options (const char **);
 
 static int java_handle_option (size_t scode, const char *arg, int value);
@@ -664,8 +664,9 @@ void lang_init_source (int level)
   inhibit_error_function_printing = (level == 1);
 }
 
-static int
-java_init_options (void)
+static unsigned int
+java_init_options (unsigned int argc ATTRIBUTE_UNUSED,
+		   const char **argv ATTRIBUTE_UNUSED)
 {
   flag_bounds_check = 1;
   flag_exceptions = 1;
Index: treelang/tree1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/tree1.c,v
retrieving revision 1.12
diff -u -p -r1.12 tree1.c
--- treelang/tree1.c	1 Jul 2003 21:25:52 -0000	1.12
+++ treelang/tree1.c	1 Jul 2003 21:29:08 -0000
@@ -92,8 +92,9 @@ static int version_done = 0;
 static unsigned int work_nesting_level = 0;
 
 /* Prepare to handle switches.  */
-int
-treelang_init_options (void)
+unsigned int
+treelang_init_options (unsigned int argc ATTRIBUTE_UNUSED,
+		       const char **argv ATTRIBUTE_UNUSED)
 {
   return CL_Treelang;
 }
Index: treelang/treetree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.h,v
retrieving revision 1.7
diff -u -p -r1.7 treetree.h
--- treelang/treetree.h	14 Jun 2003 12:26:36 -0000	1.7
+++ treelang/treetree.h	1 Jul 2003 21:29:08 -0000
@@ -63,7 +63,7 @@ tree tree_code_get_type (int type_num);
 void treelang_init_decl_processing (void);
 void treelang_finish (void);
 bool treelang_init (void);
-int treelang_init_options (void);
+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);
 void push_var_level (void);


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