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]

Option handling tweak


In trying to get f77 to use the same switch decoder as the C family, I
realized that the feature of my previous patch that moved c-options.{c,h}
to options.{c,h} was mistaken, so this patch reverts that.  Since the
options array is front-end-specific, it cannot be a language-independent
file.  This also means that opts.c, which is l-i, cannot use N_OPTS.

I also moved some declarations from the header generated by opts.sh
to opts.h, where they should have been in the first place.

It should now be easy to convert Fortran and the other front ends.

Neil.

	* Makefile.in: Rename options.c and options.h to c-options.c and
	c-options.h.
	(OBJS): Remove options.o.
	* c-opts.c: Don'tInclude c-options.h instead of options.h.
	* opts.c: Don't include options.h.
	(find_opt): Can't use enum opt_code or N_OPTS.
	* opts.h (struct cl_option, cl_options, cl_options_count): Move from...
	* opts.sh: ... here.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1074
diff -u -p -b -r1.1074 Makefile.in
--- Makefile.in	7 Jun 2003 13:23:08 -0000	1.1074
+++ Makefile.in	7 Jun 2003 22:05:24 -0000
@@ -793,7 +793,7 @@ CXX_TARGET_OBJS=@cxx_target_objs@
 # Language-specific object files for C and Objective C.
 C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
   c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
-  c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
+  c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o c-options.o prefix.o \
   c-objc-common.o c-dump.o c-pch.o libcpp.a $(C_TARGET_OBJS)
 
 # Language-specific object files for C.
@@ -812,7 +812,7 @@ OBJS = alias.o bb-reorder.o bitmap.o bui
  haifa-sched.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o	   \
  insn-extract.o insn-opinit.o insn-output.o insn-peep.o insn-recog.o	   \
  integrate.o intl.o jump.o  langhooks.o lcm.o lists.o local-alloc.o  	   \
- loop.o mbchar.o optabs.o options.o opts.o params.o predict.o		   \
+ loop.o mbchar.o optabs.o opts.o params.o predict.o			   \
  print-rtl.o print-tree.o						   \
  profile.o ra.o ra-build.o ra-colorize.o ra-debug.o ra-rewrite.o	   \
  real.o recog.o reg-stack.o regclass.o regmove.o regrename.o		   \
@@ -1317,14 +1317,15 @@ c-pretty-print.o : c-pretty-print.c c-pr
 
 c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
         c-pragma.h flags.h toplev.h langhooks.h tree-inline.h diagnostic.h \
-	intl.h debug.h $(C_COMMON_H) opts.h options.h
+	intl.h debug.h $(C_COMMON_H) opts.h c-options.h
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 		$< $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@
 
-options.c: c.opt $(srcdir)/opts.sh options.h
+c-options.c: c.opt $(srcdir)/opts.sh c-options.h
 
-options.h: c.opt $(srcdir)/opts.sh
-	AWK=$(AWK) $(SHELL) $(srcdir)/opts.sh options.c options.h $(srcdir)/c.opt
+c-options.h: c.opt $(srcdir)/opts.sh
+	AWK=$(AWK) $(SHELL) $(srcdir)/opts.sh c-options.c c-options.h \
+		$(srcdir)/c.opt
 
 c-cppbuiltin.o : c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
 	$(TREE_H) $(C_COMMON_H) c-pragma.h flags.h toplev.h langhooks.h \
@@ -1479,7 +1480,7 @@ fold-const.o : fold-const.c $(CONFIG_H) 
 diagnostic.o : diagnostic.c diagnostic.h real.h diagnostic.def \
    $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(TM_P_H) flags.h $(GGC_H) \
    input.h toplev.h intl.h langhooks.h $(LANGHOOKS_DEF_H)
-opts.o : opts.c opts.h options.h $(CONFIG_H) $(SYSTEM_H) \
+opts.o : opts.c opts.h c-options.h $(CONFIG_H) $(SYSTEM_H) \
 	coretypes.h $(TREE_H) $(TM_H) $(LANGHOOKS_H)
 toplev.o : toplev.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(RTL_H) \
    function.h flags.h xcoffout.h input.h $(INSN_ATTR_H) output.h diagnostic.h \
@@ -2787,7 +2788,7 @@ mostlyclean: $(INTL_MOSTLYCLEAN) lang.mo
 	-rm -f xlimits.h
 # Delete other built files.
 	-rm -f xsys-protos.hT
-	-rm -f specs.h options_.h gencheck.h options.c options.h
+	-rm -f specs.h options_.h gencheck.h c-options.c c-options.h
 # Delete the stamp and temporary files.
 	-rm -f s-* tmp-* stamp-* stmp-*
 	-rm -f */stamp-* */tmp-*
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.53
diff -u -p -b -r1.53 c-opts.c
--- c-opts.c	7 Jun 2003 11:10:39 -0000	1.53
+++ c-opts.c	7 Jun 2003 22:05:24 -0000
@@ -36,7 +36,7 @@ Software Foundation, 59 Temple Place - S
 #include "c-incpath.h"
 #include "debug.h"		/* For debug_hooks.  */
 #include "opts.h"
-#include "options.h"
+#include "c-options.h"
 
 #ifndef DOLLARS_IN_IDENTIFIERS
 # define DOLLARS_IN_IDENTIFIERS true
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.1
diff -u -p -b -r1.1 opts.c
--- opts.c	7 Jun 2003 11:10:39 -0000	1.1
+++ opts.c	7 Jun 2003 22:05:24 -0000
@@ -26,9 +26,8 @@ Software Foundation, 59 Temple Place - S
 #include "tree.h"
 #include "langhooks.h"
 #include "opts.h"
-#include "options.h"
 
-static enum opt_code find_opt (const char *, int);
+static size_t find_opt (const char *, int);
 
 /* Perform a binary search to find which option the command-line INPUT
    matches.  Returns its index in the option array, and N_OPTS on
@@ -41,16 +40,16 @@ static enum opt_code find_opt (const cha
    doesn't match any alternatives for the true front end, the index of
    the matched switch is returned anyway.  The caller should check for
    this case.  */
-static enum opt_code
+static size_t
 find_opt (const char *input, int lang_mask)
 {
   size_t md, mn, mx;
   size_t opt_len;
-  enum opt_code result = N_OPTS;
+  size_t result = cl_options_count;
   int comp;
 
   mn = 0;
-  mx = N_OPTS;
+  mx = cl_options_count;
 
   while (mx > mn)
     {
@@ -84,7 +83,7 @@ find_opt (const char *input, int lang_ma
 		  /* If subsequently we don't find a better match,
 		     return this and let the caller report it as a bad
 		     match.  */
-		  result = (enum opt_code) md;
+		  result = md;
 		  continue;
 		}
 
@@ -97,7 +96,7 @@ find_opt (const char *input, int lang_ma
 		 return the longest valid option-accepting match (mx).
 		 This loops at most twice with current options.  */
 	      mx = md;
-	      for (md = md + 1; md < N_OPTS; md++)
+	      for (md = md + 1; md < cl_options_count; md++)
 		{
 		  opt_len = cl_options[md].opt_len;
 		  if (strncmp (input, cl_options[md].opt_text, opt_len))
@@ -137,7 +136,7 @@ handle_option (int argc, char **argv, in
   /* Interpret "-" or a non-switch as a file name.  */
   if (opt[0] != '-' || opt[1] == '\0')
     {
-      opt_index = N_OPTS;
+      opt_index = cl_options_count;
       arg = opt;
       result = 1;
     }
@@ -159,7 +158,7 @@ handle_option (int argc, char **argv, in
 
       /* Skip over '-'.  */
       opt_index = find_opt (opt + 1, lang_mask);
-      if (opt_index == N_OPTS)
+      if (opt_index == cl_options_count)
 	goto done;
 
       option = &cl_options[opt_index];
Index: opts.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.h,v
retrieving revision 1.1
diff -u -p -b -r1.1 opts.h
--- opts.h	7 Jun 2003 11:10:39 -0000	1.1
+++ opts.h	7 Jun 2003 22:05:24 -0000
@@ -23,6 +23,16 @@ Software Foundation, 59 Temple Place - S
 
 extern int handle_option (int argc, char **argv, int lang_mask);
 
+struct cl_option
+{
+  const char *opt_text;
+  unsigned char opt_len;
+  unsigned char flags;
+};
+
+extern const struct cl_option cl_options[];
+extern const unsigned int cl_options_count;
+
 #define CL_C			(1 << 0) /* Only C.  */
 #define CL_OBJC			(1 << 1) /* Only ObjC.  */
 #define CL_CXX			(1 << 2) /* Only C++.  */
Index: opts.sh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.sh,v
retrieving revision 1.5
diff -u -p -b -r1.5 opts.sh
--- opts.sh	7 Jun 2003 11:10:39 -0000	1.5
+++ opts.sh	7 Jun 2003 22:05:24 -0000
@@ -61,15 +61,10 @@ cat "$@" | ${AWK} '
 	FS = "\034"
 	print "/* This file is auto-generated by opts.sh.  */\n" > h_file
 	print "/* This file is auto-generated by opts.sh.  */\n" > c_file
-	print "struct cl_option\n{"			>> h_file
-	print "  const char *opt_text;"			>> h_file
-	print "  unsigned char opt_len;"		>> h_file
-	print "  unsigned char flags;"			>> h_file
-	print "};\n\n"					>> h_file
-	print "extern const struct cl_option cl_options[];\n" >> h_file
 	print "enum opt_code\n{"			>> h_file
-	print "#include \"options.h\""			>> c_file
+	print "#include \"" h_file "\""			>> c_file
 	print "#include \"opts.h\"\n"			>> c_file
+	print "const unsigned int cl_options_count = N_OPTS;\n" >> c_file
 	print "const struct cl_option cl_options[] =\n{" >> c_file
     }
 


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