OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [opt-functions.awk] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
#  Copyright (C) 2003,2004, 2007 Free Software Foundation, Inc.
#  Copyright (C) 2003,2004, 2007 Free Software Foundation, Inc.
#  Contributed by Kelley Cook, June 2004.
#  Contributed by Kelley Cook, June 2004.
#  Original code from Neil Booth, May 2003.
#  Original code from Neil Booth, May 2003.
#
#
# This program is free software; you can redistribute it and/or modify it
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any
# Free Software Foundation; either version 3, or (at your option) any
# later version.
# later version.
#
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# along with this program; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.
# <http://www.gnu.org/licenses/>.
 
 
# Some common subroutines for use by opt[ch]-gen.awk.
# Some common subroutines for use by opt[ch]-gen.awk.
 
 
# Return nonzero if FLAGS contains a flag matching REGEX.
# Return nonzero if FLAGS contains a flag matching REGEX.
function flag_set_p(regex, flags)
function flag_set_p(regex, flags)
{
{
        return (" " flags " ") ~ (" " regex " ")
        return (" " flags " ") ~ (" " regex " ")
}
}
 
 
# Return STRING if FLAGS contains a flag matching regexp REGEX,
# Return STRING if FLAGS contains a flag matching regexp REGEX,
# otherwise return the empty string.
# otherwise return the empty string.
function test_flag(regex, flags, string)
function test_flag(regex, flags, string)
{
{
        if (flag_set_p(regex, flags))
        if (flag_set_p(regex, flags))
                return string
                return string
        return ""
        return ""
}
}
 
 
# If FLAGS contains a "NAME(...argument...)" flag, return the value
# If FLAGS contains a "NAME(...argument...)" flag, return the value
# of the argument.  Return the empty string otherwise.
# of the argument.  Return the empty string otherwise.
function opt_args(name, flags)
function opt_args(name, flags)
{
{
        flags = " " flags
        flags = " " flags
        if (flags !~ " " name "\\(")
        if (flags !~ " " name "\\(")
                return ""
                return ""
        sub(".* " name "\\(", "", flags)
        sub(".* " name "\\(", "", flags)
        sub("\\).*", "", flags)
        sub("\\).*", "", flags)
 
 
        return flags
        return flags
}
}
 
 
# Return the Nth comma-separated element of S.  Return the empty string
# Return the Nth comma-separated element of S.  Return the empty string
# if S does not contain N elements.
# if S does not contain N elements.
function nth_arg(n, s)
function nth_arg(n, s)
{
{
        while (n-- > 0) {
        while (n-- > 0) {
                if (s !~ ",")
                if (s !~ ",")
                        return ""
                        return ""
                sub("[^,]*, *", "", s)
                sub("[^,]*, *", "", s)
        }
        }
        sub(",.*", "", s)
        sub(",.*", "", s)
        return s
        return s
}
}
 
 
# Return a bitmask of CL_* values for option flags FLAGS.
# Return a bitmask of CL_* values for option flags FLAGS.
function switch_flags (flags)
function switch_flags (flags)
{
{
        result = "0"
        result = "0"
        for (j = 0; j < n_langs; j++) {
        for (j = 0; j < n_langs; j++) {
                regex = langs[j]
                regex = langs[j]
                gsub ( "\\+", "\\+", regex )
                gsub ( "\\+", "\\+", regex )
                result = result test_flag(regex, flags, " | " macros[j])
                result = result test_flag(regex, flags, " | " macros[j])
        }
        }
        result = result \
        result = result \
          test_flag("Common", flags, " | CL_COMMON") \
          test_flag("Common", flags, " | CL_COMMON") \
          test_flag("Target", flags, " | CL_TARGET") \
          test_flag("Target", flags, " | CL_TARGET") \
          test_flag("Joined", flags, " | CL_JOINED") \
          test_flag("Joined", flags, " | CL_JOINED") \
          test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
          test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
          test_flag("Separate", flags, " | CL_SEPARATE") \
          test_flag("Separate", flags, " | CL_SEPARATE") \
          test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
          test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
          test_flag("UInteger", flags, " | CL_UINTEGER") \
          test_flag("UInteger", flags, " | CL_UINTEGER") \
          test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
          test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
          test_flag("Report", flags, " | CL_REPORT")
          test_flag("Report", flags, " | CL_REPORT")
        sub( "^0 \\| ", "", result )
        sub( "^0 \\| ", "", result )
        return result
        return result
}
}
 
 
# If FLAGS includes a Var flag, return the name of the variable it specifies.
# If FLAGS includes a Var flag, return the name of the variable it specifies.
# Return the empty string otherwise.
# Return the empty string otherwise.
function var_name(flags)
function var_name(flags)
{
{
        return nth_arg(0, opt_args("Var", flags))
        return nth_arg(0, opt_args("Var", flags))
}
}
 
 
# Return true if the option described by FLAGS has a globally-visible state.
# Return true if the option described by FLAGS has a globally-visible state.
function global_state_p(flags)
function global_state_p(flags)
{
{
        return (var_name(flags) != "" \
        return (var_name(flags) != "" \
                || opt_args("Mask", flags) != "" \
                || opt_args("Mask", flags) != "" \
                || opt_args("InverseMask", flags) != "")
                || opt_args("InverseMask", flags) != "")
}
}
 
 
# Return true if the option described by FLAGS must have some state
# Return true if the option described by FLAGS must have some state
# associated with it.
# associated with it.
function needs_state_p(flags)
function needs_state_p(flags)
{
{
        return flag_set_p("Target", flags)
        return flag_set_p("Target", flags)
}
}
 
 
# If FLAGS describes an option that needs a static state variable,
# If FLAGS describes an option that needs a static state variable,
# return the name of that variable, otherwise return "".  NAME is
# return the name of that variable, otherwise return "".  NAME is
# the name of the option.
# the name of the option.
function static_var(name, flags)
function static_var(name, flags)
{
{
        if (global_state_p(flags) || !needs_state_p(flags))
        if (global_state_p(flags) || !needs_state_p(flags))
                return ""
                return ""
        gsub ("[^A-Za-z0-9]", "_", name)
        gsub ("[^A-Za-z0-9]", "_", name)
        return "VAR_" name
        return "VAR_" name
}
}
 
 
# Return the type of variable that should be associated with the given flags.
# Return the type of variable that should be associated with the given flags.
function var_type(flags)
function var_type(flags)
{
{
        if (!flag_set_p("Joined.*", flags))
        if (!flag_set_p("Joined.*", flags))
                return "int "
                return "int "
        else if (flag_set_p("UInteger", flags))
        else if (flag_set_p("UInteger", flags))
                return "int "
                return "int "
        else
        else
                return "const char *"
                return "const char *"
}
}
 
 
# Given that an option has flags FLAGS, return an initializer for the
# Given that an option has flags FLAGS, return an initializer for the
# "var_cond" and "var_value" fields of its cl_options[] entry.
# "var_cond" and "var_value" fields of its cl_options[] entry.
function var_set(flags)
function var_set(flags)
{
{
        s = nth_arg(1, opt_args("Var", flags))
        s = nth_arg(1, opt_args("Var", flags))
        if (s != "")
        if (s != "")
                return "CLVC_EQUAL, " s
                return "CLVC_EQUAL, " s
        s = opt_args("Mask", flags);
        s = opt_args("Mask", flags);
        if (s != "") {
        if (s != "") {
                vn = var_name(flags);
                vn = var_name(flags);
                if (vn)
                if (vn)
                        return "CLVC_BIT_SET, OPTION_MASK_" s
                        return "CLVC_BIT_SET, OPTION_MASK_" s
                else
                else
                        return "CLVC_BIT_SET, MASK_" s
                        return "CLVC_BIT_SET, MASK_" s
        }
        }
        s = nth_arg(0, opt_args("InverseMask", flags));
        s = nth_arg(0, opt_args("InverseMask", flags));
        if (s != "") {
        if (s != "") {
                vn = var_name(flags);
                vn = var_name(flags);
                if (vn)
                if (vn)
                        return "CLVC_BIT_CLEAR, OPTION_MASK_" s
                        return "CLVC_BIT_CLEAR, OPTION_MASK_" s
                else
                else
                        return "CLVC_BIT_CLEAR, MASK_" s
                        return "CLVC_BIT_CLEAR, MASK_" s
        }
        }
        if (var_type(flags) == "const char *")
        if (var_type(flags) == "const char *")
                return "CLVC_STRING, 0"
                return "CLVC_STRING, 0"
        return "CLVC_BOOLEAN, 0"
        return "CLVC_BOOLEAN, 0"
}
}
 
 
# Given that an option called NAME has flags FLAGS, return an initializer
# Given that an option called NAME has flags FLAGS, return an initializer
# for the "flag_var" field of its cl_options[] entry.
# for the "flag_var" field of its cl_options[] entry.
function var_ref(name, flags)
function var_ref(name, flags)
{
{
        name = var_name(flags) static_var(name, flags)
        name = var_name(flags) static_var(name, flags)
        if (name != "")
        if (name != "")
                return "&" name
                return "&" name
        if (opt_args("Mask", flags) != "")
        if (opt_args("Mask", flags) != "")
                return "&target_flags"
                return "&target_flags"
        if (opt_args("InverseMask", flags) != "")
        if (opt_args("InverseMask", flags) != "")
                return "&target_flags"
                return "&target_flags"
        return "0"
        return "0"
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.