[PATCH, trunk] Add Save/Explicit option support

Michael Meissner michael.meissner@amd.com
Mon Jun 9 17:07:00 GMT 2008


Nobody commented on the patch I submitted on the 6th.  I suspect it got lost
with my other messages about commits to the branch.  This patch fixes a bug
that prevented the default flag (target_flags) from being saved and restored,
when the options are linked in the gcc driver.

Is this ok to submit?

-- 
Michael Meissner, AMD
90 Central Street, MS 83-29, Boxborough, MA, 01719, USA
michael.meissner@amd.com
-------------- next part --------------
2008-06-09  Michael Meissner  <michael.meissner@amd.com>
	    Karthik Kumar  <karthikkumar@gmail.com>

	* opth-gen.awk: Add support for a 'Save' flag which says to give
	the port a way to save and preserve selected command line
	options.  Add support for an 'Explicit' flag which says to add an
	additional variable for noting when the switch has been explicitly
	set.  Do not emit the same declaration more than once.

	* optc-gen.awk: If a 'Save' flag is used, create the
	cl_options_save and cl_options_restore to save/restore the
	selected options.

	* doc/options.texi (Save): Document.
	(Explicit): Ditto.

Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 136408)
+++ gcc/doc/options.texi	(working copy)
@@ -221,4 +221,14 @@ The option should only be accepted if pr
 option will be present even if @var{cond} is false; @var{cond} simply
 controls whether the option is accepted and whether it is printed in
 the @option{--help} output.
+
+@item Save
+Build the @code{cl_option_save} structure to hold a copy of the
+option, add the functions @code{cl_options_save} and
+@code{cl_options_restore} to save and restore the option.
+
+@item Explicit
+If the option is a @code{MASK} option, create an additional variable
+@var{var}_explicit which is available to hold whether the option was
+set explicitly or implicitly via another option.
 @end table
Index: gcc/optc-gen.awk
===================================================================
--- gcc/optc-gen.awk	(revision 136408)
+++ gcc/optc-gen.awk	(working copy)
@@ -67,7 +67,11 @@ print "int target_flags;"
 print "#endif /* GCC_DRIVER */"
 print ""
 
+have_save = 0;
 for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("Save", flags[i]))
+		have_save = 1;
+
 	name = var_name(flags[i]);
 	if (name == "")
 		continue;
@@ -93,6 +97,8 @@ for (i = 0; i < n_opts; i++) {
 	print "/* Set by -" opts[i] "."
 	print "   " help[i] "  */"
 	print var_type(flags[i]) name init ";"
+	if (flag_set_p("Explicit", flags[i]))
+		print var_type(flags[i]) name "_explicit;"
 	if (gcc_driver == 1)
 		print "#endif /* GCC_DRIVER */"
 	print ""
@@ -210,4 +216,57 @@ for (i = 0; i < n_opts; i++) {
 }
 
 print "};"
+
+if (have_save) {
+	print "";
+	print "#ifndef GCC_DRIVER"
+	print "/* Save selected option variables into a structure.  */"
+	print "void";
+	print "cl_options_save (struct cl_option_save *ptr)";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i]);
+			if (name == "")
+				name = "target_flags";
+
+			if (name in var_seen_save)
+				continue;
+
+			var_seen_save[name] = 1;
+			print "  ptr->" name " = " name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  ptr->" name "_explicit = " name "_explicit;";
+		}
+	}
+
+	print "}";
+
+	print "";
+	print "/* Restore selected current options from a structure.  */";
+	print "void";
+	print "cl_options_restore (struct cl_option_save *ptr)";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i]);
+			if (name == "")
+				name = "target_flags";
+
+			if (name in var_seen_restore)
+				continue;
+
+			var_seen_restore[name] = 1;
+			print "  " name " = ptr->" name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  " name "_explicit = ptr->" name "_explicit;";
+		}
+	}
+
+	print "}";
+	print "#endif";
+}
+
 }
Index: gcc/opth-gen.awk
===================================================================
--- gcc/opth-gen.awk	(revision 136408)
+++ gcc/opth-gen.awk	(working copy)
@@ -64,15 +64,65 @@ print "extern int target_flags;"
 print "extern int target_flags_explicit;"
 print ""
 
+have_save = 0;
+
 for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("Save", flags[i]))
+		have_save = 1;
+
 	name = var_name(flags[i]);
 	if (name == "")
 		continue;
 
+	if (name in var_seen)
+		continue;
+
+	var_seen[name] = 1;
 	print "extern " var_type(flags[i]) name ";"
+
+	if (flag_set_p("Explicit", flags[i]) && !(name in var_explicit)) {
+	    var_explicit[name] = 1;
+	    print "extern " var_type(flags[i]) name "_explicit;";
+	}
+
 }
 print ""
 
+if (have_save) {
+	# Define this even if we are in the gcc driver in case the tm.h
+	# file includes this structure in another one.
+	print "/* Structure to save/restore selected options.  */";
+	print "struct cl_option_save GTY(())";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i])
+			if(name == "")
+				name = "target_flags";
+
+			if(name in var_save_seen)
+				continue;
+
+			var_save_seen[name]++;
+			print "  " var_type(flags[i]) name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  " var_type(flags[i]) name "_explicit;";
+		}
+	}
+
+	print "};";
+	print "";
+	print "#ifndef GCC_DRIVER"
+	print "/* Save selected option variables into a structure.  */"
+	print "extern void cl_options_save (struct cl_option_save *);";
+	print "";
+	print "/* Restore selected current options from a structure.  */";
+	print "extern void cl_options_restore (struct cl_option_save *);";
+	print "#endif";
+	print "";
+}
+
 for (i = 0; i < n_opts; i++) {
 	name = opt_args("Mask", flags[i])
 	vname = var_name(flags[i])


More information about the Gcc-patches mailing list