]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/opt-functions.awk
Update copyright years.
[thirdparty/gcc.git] / gcc / opt-functions.awk
index 94816a2d363af58bc5a7c0a794fd84dbab5e7dee..2f0442dc5633a0ca7e3e86c523f333d0ff847b66 100644 (file)
@@ -1,5 +1,4 @@
-#  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
-#  Free Software Foundation, Inc.
+#  Copyright (C) 2003-2020 Free Software Foundation, Inc.
 #  Contributed by Kelley Cook, June 2004.
 #  Original code from Neil Booth, May 2003.
 #
 
 # Some common subroutines for use by opt[ch]-gen.awk.
 
+# Define some helpful character classes, for portability.
+BEGIN {
+       lower = "abcdefghijklmnopqrstuvwxyz"
+       upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+       digit = "0123456789"
+       alnum = lower "" upper "" digit
+}
+
 # Return nonzero if FLAGS contains a flag matching REGEX.
 function flag_set_p(regex, flags)
 {
-       return (" " flags " ") ~ (" " regex " ")
+    # Ignore the arguments of flags with arguments.
+    gsub ("\\([^)]+\\)", "", flags);
+    return (" " flags " ") ~ (" " regex " ")
 }
 
 # Return STRING if FLAGS contains a flag matching regexp REGEX,
@@ -34,6 +43,16 @@ function test_flag(regex, flags, string)
        return ""
 }
 
+# Return a field initializer, with trailing comma, for a field that is
+# 1 if FLAGS contains a flag matching REGEX and 0 otherwise.
+function flag_init(regex, flags)
+{
+       if (flag_set_p(regex, flags))
+               return "1 /* " regex " */, "
+       else
+               return "0, "
+}
+
 # If FLAGS contains a "NAME(...argument...)" flag, return the value
 # of the argument.  Return the empty string otherwise.
 function opt_args(name, flags)
@@ -42,10 +61,10 @@ function opt_args(name, flags)
        if (flags !~ " " name "\\(")
                return ""
        sub(".* " name "\\(", "", flags)
-       if (flags ~ "^{")
+       if (flags ~ "^[{]")
        {
-               sub ("^{", "", flags)
-               sub("}\\).*", "", flags)
+               sub ("^[{]", "", flags)
+               sub ("}\\).*", "", flags)
        }
        else
                sub("\\).*", "", flags)
@@ -78,23 +97,72 @@ function switch_flags (flags)
        result = result \
          test_flag("Common", flags, " | CL_COMMON") \
          test_flag("Target", flags, " | CL_TARGET") \
+         test_flag("PchIgnore", flags, " | CL_PCH_IGNORE") \
          test_flag("Driver", flags, " | CL_DRIVER") \
-         test_flag("RejectDriver", flags, " | CL_REJECT_DRIVER") \
-         test_flag("NoDriverArg", flags, " | CL_NO_DRIVER_ARG") \
-         test_flag("Save", flags, " | CL_SAVE") \
          test_flag("Joined", flags, " | CL_JOINED") \
-         test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
+         test_flag("JoinedOrMissing", flags, " | CL_JOINED") \
          test_flag("Separate", flags, " | CL_SEPARATE") \
-         test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
-         test_flag("UInteger", flags, " | CL_UINTEGER") \
          test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
+         test_flag("NoDWARFRecord", flags,  " | CL_NO_DWARF_RECORD") \
          test_flag("Warning", flags,  " | CL_WARNING") \
-         test_flag("Optimization", flags,  " | CL_OPTIMIZATION") \
-         test_flag("Report", flags, " | CL_REPORT")
+         test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION") \
+         test_flag("Param", flags,  " | CL_PARAMS")
        sub( "^0 \\| ", "", result )
        return result
 }
 
+# Return bit-field initializers for option flags FLAGS.
+function switch_bit_fields (flags)
+{
+       uinteger_flag = ""
+       vn = var_name(flags);
+       if (host_wide_int[vn] == "yes")
+               hwi = "Host_Wide_Int"
+       else if (flag_set_p("Host_Wide_Int", flags)) {
+               hwi = "Host_Wide_Int"
+               uinteger_flag = flag_init("UInteger", flags)
+       }
+       else
+               hwi = ""
+       result = ""
+       sep_args = opt_args("Args", flags)
+       if (sep_args == "")
+               sep_args = 0
+       else
+               sep_args--
+       result = result sep_args ", "
+
+       if (uinteger_flag == "")
+               uinteger_flag = flag_init("UInteger", flags)
+
+       hwi_flag = flag_init("Host_Wide_Int", hwi)
+       byte_size_flag = flag_init("ByteSize", flags)
+
+       if (substr(byte_size_flag, 1, 1) != "0" \
+           && substr(uinteger_flag, 1, 1) == "0" \
+           && substr(hwi_flag, 1, 1) == "0")
+         print "#error only UInteger amd Host_Wide_Int options can specify a ByteSize suffix"
+
+       # The following flags need to be in the same order as
+       # the corresponding members of struct cl_option defined
+       # in gcc/opts.h.
+       result = result \
+         flag_init("SeparateAlias", flags) \
+         flag_init("NegativeAlias", flags) \
+         flag_init("NoDriverArg", flags) \
+         flag_init("RejectDriver", flags) \
+         flag_init("RejectNegative", flags) \
+         flag_init("JoinedOrMissing", flags) \
+         uinteger_flag \
+         hwi_flag \
+         flag_init("ToLower", flags) \
+         flag_init("Report", flags) \
+         byte_size_flag
+
+       sub(", $", "", result)
+       return result
+}
+
 # If FLAGS includes a Var flag, return the name of the variable it specifies.
 # Return the empty string otherwise.
 function var_name(flags)
@@ -102,6 +170,17 @@ function var_name(flags)
        return nth_arg(0, opt_args("Var", flags))
 }
 
+# Return the name of the variable if FLAGS has a HOST_WIDE_INT variable. 
+# Return the empty string otherwise.
+function host_wide_int_var_name(flags)
+{
+       split (flags, array, "[ \t]+")
+       if (array[1] == "HOST_WIDE_INT")
+               return array[2]
+       else
+               return ""
+}
+
 # Return true if the option described by FLAGS has a globally-visible state.
 function global_state_p(flags)
 {
@@ -119,22 +198,30 @@ function needs_state_p(flags)
                && !flag_set_p("Ignore", flags))
 }
 
-# If FLAGS describes an option that needs a static state variable,
-# return the name of that variable, otherwise return "".  NAME is
-# the name of the option.
+# If FLAGS describes an option that needs state without a public
+# variable name, return the name of that field, minus the initial
+# "x_", otherwise return "".  NAME is the name of the option.
 function static_var(name, flags)
 {
        if (global_state_p(flags) || !needs_state_p(flags))
                return ""
-       gsub ("[^A-Za-z0-9]", "_", name)
+       gsub ("[^" alnum "]", "_", name)
        return "VAR_" name
 }
 
 # Return the type of variable that should be associated with the given flags.
 function var_type(flags)
 {
-       if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags))
+       if (flag_set_p("Defer", flags))
+               return "void *"
+       else if (flag_set_p("Enum.*", flags)) {
+               en = opt_args("Enum", flags);
+               return enum_type[en] " "
+       }
+       else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags))
                return "int "
+       else if (flag_set_p("Host_Wide_Int", flags))
+               return "HOST_WIDE_INT "
        else if (flag_set_p("UInteger", flags))
                return "int "
        else
@@ -146,11 +233,24 @@ function var_type(flags)
 # type instead of int to save space.
 function var_type_struct(flags)
 {
-       if (flag_set_p("UInteger", flags))
-               return "int "
+       if (flag_set_p("UInteger", flags)) {
+               if (host_wide_int[var_name(flags)] == "yes")
+                       return "HOST_WIDE_INT ";
+               if (flag_set_p("ByteSize", flags))
+                       return "HOST_WIDE_INT "
+         return "int "
+       }
+       else if (flag_set_p("Enum.*", flags)) {
+               en = opt_args("Enum", flags);
+               return enum_type[en] " "
+       }
        else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) {
-               if (flag_set_p(".*Mask.*", flags))
-                       return "int "
+               if (flag_set_p(".*Mask.*", flags)) {
+                       if (host_wide_int[var_name(flags)] == "yes")
+                               return "HOST_WIDE_INT "
+                       else
+                               return "/* - */ int "
+               }
                else
                        return "signed char "
        }
@@ -159,31 +259,39 @@ function var_type_struct(flags)
 }
 
 # Given that an option has flags FLAGS, return an initializer for the
-# "var_cond" and "var_value" fields of its cl_options[] entry.
+# "var_enum", "var_type" and "var_value" fields of its cl_options[] entry.
 function var_set(flags)
 {
+       if (flag_set_p("Defer", flags))
+               return "0, CLVC_DEFER, 0"
        s = nth_arg(1, opt_args("Var", flags))
        if (s != "")
-               return "CLVC_EQUAL, " s
+               return "0, CLVC_EQUAL, " s
        s = opt_args("Mask", flags);
        if (s != "") {
                vn = var_name(flags);
                if (vn)
-                       return "CLVC_BIT_SET, OPTION_MASK_" s
+                       return "0, CLVC_BIT_SET, OPTION_MASK_" s
                else
-                       return "CLVC_BIT_SET, MASK_" s
+                       return "0, CLVC_BIT_SET, MASK_" s
        }
        s = nth_arg(0, opt_args("InverseMask", flags));
        if (s != "") {
                vn = var_name(flags);
                if (vn)
-                       return "CLVC_BIT_CLEAR, OPTION_MASK_" s
+                       return "0, CLVC_BIT_CLEAR, OPTION_MASK_" s
                else
-                       return "CLVC_BIT_CLEAR, MASK_" s
+                       return "0, CLVC_BIT_CLEAR, MASK_" s
+       }
+       if (flag_set_p("Enum.*", flags)) {
+               en = opt_args("Enum", flags);
+               return enum_index[en] ", CLVC_ENUM, 0"
        }
        if (var_type(flags) == "const char *")
-               return "CLVC_STRING, 0"
-       return "CLVC_BOOLEAN, 0"
+               return "0, CLVC_STRING, 0"
+       if (flag_set_p("ByteSize", flags))
+               return "0, CLVC_SIZE, 0"
+       return "0, CLVC_BOOLEAN, 0"
 }
 
 # Given that an option called NAME has flags FLAGS, return an initializer
@@ -192,20 +300,18 @@ function var_ref(name, flags)
 {
        name = var_name(flags) static_var(name, flags)
        if (name != "")
-               return "&" name
+               return "offsetof (struct gcc_options, x_" name ")"
        if (opt_args("Mask", flags) != "")
-               return "&target_flags"
+               return "offsetof (struct gcc_options, x_target_flags)"
        if (opt_args("InverseMask", flags) != "")
-               return "&target_flags"
-       return "0"
+               return "offsetof (struct gcc_options, x_target_flags)"
+       return "(unsigned short) -1"
 }
 
 # Given the option called NAME return a sanitized version of its name.
 function opt_sanitized_name(name)
 {
-       if (name == "gdwarf+")
-               name = "gdwarfplus"
-       gsub ("[^A-Za-z0-9]", "_", name)
+       gsub ("[^" alnum "]", "_", name)
        return name
 }
 
@@ -214,3 +320,76 @@ function opt_enum(name)
 {
        return "OPT_" opt_sanitized_name(name)
 }
+
+# Given the language called NAME return a sanitized version of its name.
+function lang_sanitized_name(name)
+{
+    gsub( "[^" alnum "_]", "X", name )
+    return name
+}
+
+# Search for a valid var_name among all OPTS equal to option NAME.
+# If not found, return "".
+function search_var_name(name, opt_numbers, opts, flags, n_opts)
+{
+    opt_var_name = var_name(flags[opt_numbers[name]]);
+    if (opt_var_name != "") {
+        return opt_var_name;
+    }
+    for (k = 0; k < n_opts; k++) {
+        if (opts[k] == name && var_name(flags[k]) != "") {
+            return var_name(flags[k]);
+        }
+    }
+    return ""
+}
+
+function integer_range_info(range_option, init, option)
+{
+    if (range_option != "") {
+       ival = init + 0;
+       start = nth_arg(0, range_option) + 0;
+       end = nth_arg(1, range_option) + 0;
+       if (init != "" && init != "-1" && (ival < start || ival > end))
+         print "#error initial value " init " of '" option "' must be in range [" start "," end "]"
+       return start ", " end
+    }
+    else
+        return "-1, -1"
+}
+
+# Handle LangEnabledBy(ENABLED_BY_LANGS, ENABLEDBY_NAME, ENABLEDBY_POSARG,
+# ENABLEDBY_NEGARG). This function does not return anything.
+function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg)
+{
+    n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " ");
+    if (enabledby_posarg != "" && enabledby_negarg != "") {
+        with_args = "," enabledby_posarg "," enabledby_negarg
+    } else if (enabledby_posarg == "" && enabledby_negarg == "") {
+        with_args = ""
+    } else {
+        print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \
+            enabledby_posarg", " enabledby_negargs                  \
+            ") with three arguments, it should have either 2 or 4"
+    }
+
+    n_enabledby_array = split(enabledby_name, enabledby_array, " \\|\\| ");
+    for (k = 1; k <= n_enabledby_array; k++) {
+        enabledby_index = opt_numbers[enabledby_array[k]];
+        if (enabledby_index == "") {
+             print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \
+                 enabledby_posarg", " enabledby_negargs"), unknown option '" enabledby_name "'"
+        } else {
+            for (j = 1; j <= n_enabledby_arg_langs; j++) {
+                 lang_name = lang_sanitized_name(enabledby_arg_langs[j]);
+                 lang_index = lang_numbers[enabledby_arg_langs[j]];
+                 if (enables[lang_name,enabledby_array[k]] == "") {
+                     enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k];
+                     n_enabledby_lang[lang_index]++;
+                 }
+                 enables[lang_name,enabledby_array[k]] \
+                     = enables[lang_name,enabledby_array[k]] opts[i] with_args ";";
+            }
+        }
+    }
+}