+# dg-final-generate -- process code to run after the profile-generate step
+#
+# ARGS is the line number of the directive followed by the commands.
+#
+proc dg-final-generate { args } {
+ global generate_final_code
+
+ if { [llength $args] > 2 } {
+ error "[lindex $args 0]: too many arguments"
+ return
+ }
+ append generate_final_code "[lindex $args 1]\n"
+}
+
+#
+# dg-final-use -- process code to run after the profile-use step
+#
+# ARGS is the line number of the directive followed by the commands.
+#
+proc dg-final-use { args } {
+ global use_final_code
+
+ if { [llength $args] > 2 } {
+ error "[lindex $args 0]: too many arguments"
+ return
+ }
+ append use_final_code "[lindex $args 1]\n"
+}
+
+#
+# profopt-final-code -- run final code
+#
+# WHICH is "generate" or "use".
+# FINAL_CODE is the TCL code to run.
+# TESTCASE is the name of the test, for error messages.
+#
+proc profopt-final-code { which final_code name } {
+ # This is copied from dg-test in dg.exp of DejaGnu.
+ regsub -all "\\\\(\[{}\])" $final_code "\\1" final_code
+ proc profopt-final-proc { args } $final_code
+ if [catch "profopt-final-proc $name" errmsg] {
+ perror "$name: error executing dg-final-${which}: $errmsg"
+ unresolved "$name: Error executing dg-final-${which}: $errmsg"
+ }
+}
+
+#
+# profopt-get-options -- process test directives
+#
+# SRC is the full pathname of the testcase.
+#
+proc profopt-get-options { src } {
+ # dg-options sets a variable called dg-extra-tool-flags.
+ set dg-extra-tool-flags ""
+
+ # dg-require-* sets dg-do-what.
+ upvar dg-do-what dg-do-what
+
+ set tmp [dg-get-options $src]
+ foreach op $tmp {
+ set cmd [lindex $op 0]
+ if { ![string compare "dg-options" $cmd] \
+ || ![string compare "dg-skip-if" $cmd] \
+ || ![string compare "dg-final-generate" $cmd] \
+ || ![string compare "dg-final-use" $cmd] \
+ || [string match "dg-require-*" $cmd] } {
+ set status [catch "$op" errmsg]
+ if { $status != 0 } {
+ perror "src: $errmsg for \"$op\"\n"
+ unresolved "$src: $errmsg for \"$op\""
+ return
+ }
+ } else {
+ # Ignore unrecognized dg- commands, but warn about them.
+ warning "compat.exp does not support $cmd"
+ }
+ }
+
+ # Return flags to use for compiling the primary source file and for
+ # linking.
+ return ${dg-extra-tool-flags}
+}
+
+#