From 3d321079b949a20bcde465aacc8fc4ef1d9f0e12 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 31 Dec 2006 16:39:48 +0000 Subject: [PATCH] svn:eol-style native, svn:keywords Author Date Id Revision git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4546 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- support/cpp2/opt-functions.awk | 338 +++++++++++++++--------------- support/cpp2/opt-gather.awk | 108 +++++----- support/cpp2/optc-gen.awk | 336 +++++++++++++++--------------- support/cpp2/opth-gen.awk | 370 ++++++++++++++++----------------- 4 files changed, 576 insertions(+), 576 deletions(-) diff --git a/support/cpp2/opt-functions.awk b/support/cpp2/opt-functions.awk index f392060c..3e4c8059 100644 --- a/support/cpp2/opt-functions.awk +++ b/support/cpp2/opt-functions.awk @@ -1,169 +1,169 @@ -# Copyright (C) 2003,2004 Free Software Foundation, Inc. -# Contributed by Kelley Cook, June 2004. -# Original code from Neil Booth, May 2003. -# -# 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 -# Free Software Foundation; either version 2, or (at your option) any -# later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# Some common subroutines for use by opt[ch]-gen.awk. - -# Return nonzero if FLAGS contains a flag matching REGEX. -function flag_set_p(regex, flags) -{ - return (" " flags " ") ~ (" " regex " ") -} - -# Return STRING if FLAGS contains a flag matching regexp REGEX, -# otherwise return the empty string. -function test_flag(regex, flags, string) -{ - if (flag_set_p(regex, flags)) - return string - return "" -} - -# If FLAGS contains a "NAME(...argument...)" flag, return the value -# of the argument. Return the empty string otherwise. -function opt_args(name, flags) -{ - flags = " " flags - if (flags !~ " " name "\\(") - return "" - sub(".* " name "\\(", "", flags) - sub("\\).*", "", flags) - - return flags -} - -# Return the Nth comma-separated element of S. Return the empty string -# if S does not contain N elements. -function nth_arg(n, s) -{ - while (n-- > 0) { - if (s !~ ",") - return "" - sub("[^,]*, *", "", s) - } - sub(",.*", "", s) - return s -} - -# Return a bitmask of CL_* values for option flags FLAGS. -function switch_flags (flags) -{ - result = "0" - for (j = 0; j < n_langs; j++) { - regex = langs[j] - gsub ( "\\+", "\\+", regex ) - result = result test_flag(regex, flags, " | " macros[j]) - } - result = result \ - test_flag("Common", flags, " | CL_COMMON") \ - test_flag("Target", flags, " | CL_TARGET") \ - test_flag("Joined", flags, " | CL_JOINED") \ - test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \ - 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("Report", flags, " | CL_REPORT") - sub( "^0 \\| ", "", 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) -{ - return nth_arg(0, opt_args("Var", flags)) -} - -# Return true if the option described by FLAGS has a globally-visible state. -function global_state_p(flags) -{ - return (var_name(flags) != "" \ - || opt_args("Mask", flags) != "" \ - || opt_args("InverseMask", flags) != "") -} - -# Return true if the option described by FLAGS must have some state -# associated with it. -function needs_state_p(flags) -{ - return flag_set_p("Target", 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. -function static_var(name, flags) -{ - if (global_state_p(flags) || !needs_state_p(flags)) - return "" - gsub ("[^A-Za-z0-9]", "_", 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)) - return "int " - else if (flag_set_p("UInteger", flags)) - return "int " - else - return "const char *" -} - -# Given that an option has flags FLAGS, return an initializer for the -# "var_cond" and "var_value" fields of its cl_options[] entry. -function var_set(flags) -{ - s = nth_arg(1, opt_args("Var", flags)) - if (s != "") - return "CLVC_EQUAL, " s - s = opt_args("Mask", flags); - if (s != "") { - vn = var_name(flags); - if (vn) - return "CLVC_BIT_SET, OPTION_MASK_" s - else - return "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 - else - return "CLVC_BIT_CLEAR, MASK_" s - } - if (var_type(flags) == "const char *") - return "CLVC_STRING, 0" - return "CLVC_BOOLEAN, 0" -} - -# Given that an option called NAME has flags FLAGS, return an initializer -# for the "flag_var" field of its cl_options[] entry. -function var_ref(name, flags) -{ - name = var_name(flags) static_var(name, flags) - if (name != "") - return "&" name - if (opt_args("Mask", flags) != "") - return "&target_flags" - if (opt_args("InverseMask", flags) != "") - return "&target_flags" - return "0" -} +# Copyright (C) 2003,2004 Free Software Foundation, Inc. +# Contributed by Kelley Cook, June 2004. +# Original code from Neil Booth, May 2003. +# +# 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 +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Some common subroutines for use by opt[ch]-gen.awk. + +# Return nonzero if FLAGS contains a flag matching REGEX. +function flag_set_p(regex, flags) +{ + return (" " flags " ") ~ (" " regex " ") +} + +# Return STRING if FLAGS contains a flag matching regexp REGEX, +# otherwise return the empty string. +function test_flag(regex, flags, string) +{ + if (flag_set_p(regex, flags)) + return string + return "" +} + +# If FLAGS contains a "NAME(...argument...)" flag, return the value +# of the argument. Return the empty string otherwise. +function opt_args(name, flags) +{ + flags = " " flags + if (flags !~ " " name "\\(") + return "" + sub(".* " name "\\(", "", flags) + sub("\\).*", "", flags) + + return flags +} + +# Return the Nth comma-separated element of S. Return the empty string +# if S does not contain N elements. +function nth_arg(n, s) +{ + while (n-- > 0) { + if (s !~ ",") + return "" + sub("[^,]*, *", "", s) + } + sub(",.*", "", s) + return s +} + +# Return a bitmask of CL_* values for option flags FLAGS. +function switch_flags (flags) +{ + result = "0" + for (j = 0; j < n_langs; j++) { + regex = langs[j] + gsub ( "\\+", "\\+", regex ) + result = result test_flag(regex, flags, " | " macros[j]) + } + result = result \ + test_flag("Common", flags, " | CL_COMMON") \ + test_flag("Target", flags, " | CL_TARGET") \ + test_flag("Joined", flags, " | CL_JOINED") \ + test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \ + 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("Report", flags, " | CL_REPORT") + sub( "^0 \\| ", "", 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) +{ + return nth_arg(0, opt_args("Var", flags)) +} + +# Return true if the option described by FLAGS has a globally-visible state. +function global_state_p(flags) +{ + return (var_name(flags) != "" \ + || opt_args("Mask", flags) != "" \ + || opt_args("InverseMask", flags) != "") +} + +# Return true if the option described by FLAGS must have some state +# associated with it. +function needs_state_p(flags) +{ + return flag_set_p("Target", 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. +function static_var(name, flags) +{ + if (global_state_p(flags) || !needs_state_p(flags)) + return "" + gsub ("[^A-Za-z0-9]", "_", 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)) + return "int " + else if (flag_set_p("UInteger", flags)) + return "int " + else + return "const char *" +} + +# Given that an option has flags FLAGS, return an initializer for the +# "var_cond" and "var_value" fields of its cl_options[] entry. +function var_set(flags) +{ + s = nth_arg(1, opt_args("Var", flags)) + if (s != "") + return "CLVC_EQUAL, " s + s = opt_args("Mask", flags); + if (s != "") { + vn = var_name(flags); + if (vn) + return "CLVC_BIT_SET, OPTION_MASK_" s + else + return "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 + else + return "CLVC_BIT_CLEAR, MASK_" s + } + if (var_type(flags) == "const char *") + return "CLVC_STRING, 0" + return "CLVC_BOOLEAN, 0" +} + +# Given that an option called NAME has flags FLAGS, return an initializer +# for the "flag_var" field of its cl_options[] entry. +function var_ref(name, flags) +{ + name = var_name(flags) static_var(name, flags) + if (name != "") + return "&" name + if (opt_args("Mask", flags) != "") + return "&target_flags" + if (opt_args("InverseMask", flags) != "") + return "&target_flags" + return "0" +} diff --git a/support/cpp2/opt-gather.awk b/support/cpp2/opt-gather.awk index 87dd37ab..084362ec 100644 --- a/support/cpp2/opt-gather.awk +++ b/support/cpp2/opt-gather.awk @@ -1,54 +1,54 @@ -# Copyright (C) 2003,2004 Free Software Foundation, Inc. -# Contributed by Kelley Cook, June 2004. -# Original code from Neil Booth, May 2003. -# -# 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 -# Free Software Foundation; either version 2, or (at your option) any -# later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# This Awk script takes a list of *.opt files and combines them into -# a three-field sorted list suitable for input into opt[ch]-gen.awk. -# -# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile - -function sort(ARRAY, ELEMENTS) -{ - for (i = 2; i <= ELEMENTS; ++i) { - for (j = i; ARRAY[j-1] > ARRAY[j]; --j) { - temp = ARRAY[j] - ARRAY[j] = ARRAY[j-1] - ARRAY[j-1] = temp - } - } - return -} - -BEGIN { numrec = 0 } - -# Ignore comments and blank lines -/^[ \t]*(;|$)/ { flag = 0; next } -/^[^ \t]/ { if (flag == 0) { - record[++numrec] = $0 - flag = 1 } - else { - record[numrec] = record[numrec] SUBSEP $0 - } -} - -# Sort it and output it -END { - sort(record,numrec) - - for (i = 1; i <= numrec; i++) { - print record[i] } -} +# Copyright (C) 2003,2004 Free Software Foundation, Inc. +# Contributed by Kelley Cook, June 2004. +# Original code from Neil Booth, May 2003. +# +# 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 +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# This Awk script takes a list of *.opt files and combines them into +# a three-field sorted list suitable for input into opt[ch]-gen.awk. +# +# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile + +function sort(ARRAY, ELEMENTS) +{ + for (i = 2; i <= ELEMENTS; ++i) { + for (j = i; ARRAY[j-1] > ARRAY[j]; --j) { + temp = ARRAY[j] + ARRAY[j] = ARRAY[j-1] + ARRAY[j-1] = temp + } + } + return +} + +BEGIN { numrec = 0 } + +# Ignore comments and blank lines +/^[ \t]*(;|$)/ { flag = 0; next } +/^[^ \t]/ { if (flag == 0) { + record[++numrec] = $0 + flag = 1 } + else { + record[numrec] = record[numrec] SUBSEP $0 + } +} + +# Sort it and output it +END { + sort(record,numrec) + + for (i = 1; i <= numrec; i++) { + print record[i] } +} diff --git a/support/cpp2/optc-gen.awk b/support/cpp2/optc-gen.awk index 08232f37..065972b0 100644 --- a/support/cpp2/optc-gen.awk +++ b/support/cpp2/optc-gen.awk @@ -1,168 +1,168 @@ -# Copyright (C) 2003,2004 Free Software Foundation, Inc. -# Contributed by Kelley Cook, June 2004. -# Original code from Neil Booth, May 2003. -# -# 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 -# Free Software Foundation; either version 2, or (at your option) any -# later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# This Awk script reads in the option records generated from -# opt-gather.awk, combines the flags of duplicat options and generates a -# C file. -# -# This program uses functions from opt-functions.awk -# -# Usage: awk -f opt-functions.awk -f optc-gen.awk \ -# [-v header_name=header.h] < inputfile > options.c - -BEGIN { - n_opts = 0 - n_langs = 0 - quote = "\042" - comma = "," - FS=SUBSEP - # Default the name of header created from opth-gen.awk to options.h - if (header_name == "") header_name="options.h" -} - -# Collect the text and flags of each option into an array - { - if ($1 == "Language") { - langs[n_langs] = $2 - n_langs++; - } - else { - name = opt_args("Mask", $1) - if (name == "") { - opts[n_opts] = $1 - flags[n_opts] = $2 - help[n_opts] = $3 - n_opts++; - } - } - } - -# Dump that array of options into a C file. -END { -print "/* This file is auto-generated by opts.sh. */" -print "" -n_headers = split(header_name, headers, " ") -for (i = 1; i <= n_headers; i++) - print "#include " quote headers[i] quote -print "#include " quote "opts.h" quote -print "#include " quote "intl.h" quote -print "" - -for (i = 0; i < n_opts; i++) { - name = var_name(flags[i]); - if (name == "") - continue; - - if (flag_set_p("VarExists", flags[i])) - continue; - - init = opt_args("Init", flags[i]) - if (init != "") - init = " = " init; - else if (name in var_seen) - continue; - - print "/* Set by -" opts[i] "." - print " " help[i] " */" - print var_type(flags[i]) name init ";" - print "" - - var_seen[name] = 1; -} - -print "" -print "/* Local state variables. */" -for (i = 0; i < n_opts; i++) { - name = static_var(opts[i], flags[i]); - if (name != "") - print "static " var_type(flags[i]) name ";" -} -print "" - -print "const char * const lang_names[] =\n{" -for (i = 0; i < n_langs; i++) { - macros[i] = "CL_" langs[i] - gsub( "[^A-Za-z0-9_]", "X", macros[i] ) - s = substr(" ", length (macros[i])) - print " " quote langs[i] quote "," - } - -print " 0\n};\n" -print "const unsigned int cl_options_count = N_OPTS;\n" - -print "const struct cl_option cl_options[] =\n{" - -for (i = 0; i < n_opts; i++) - back_chain[i] = "N_OPTS"; - -for (i = 0; i < n_opts; i++) { - # Combine the flags of identical switches. Switches - # appear many times if they are handled by many front - # ends, for example. - while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { - flags[i + 1] = flags[i] " " flags[i + 1]; - i++; - } - - len = length (opts[i]); - enum = "OPT_" opts[i] - if (opts[i] == "finline-limit=") - enum = enum "eq" - gsub ("[^A-Za-z0-9]", "_", enum) - - # If this switch takes joined arguments, back-chain all - # subsequent switches to it for which it is a prefix. If - # a later switch S is a longer prefix of a switch T, T - # will be back-chained to S in a later iteration of this - # for() loop, which is what we want. - if (flag_set_p("Joined.*", flags[i])) { - for (j = i + 1; j < n_opts; j++) { - if (substr (opts[j], 1, len) != opts[i]) - break; - back_chain[j] = enum; - } - } - - s = substr(" ", length (opts[i])) - if (i + 1 == n_opts) - comma = "" - - if (help[i] == "") - hlp = "0" - else - hlp = quote help[i] quote; - - printf(" { %c-%s%c,\n %s,\n %s, %u,\n", - quote, opts[i], quote, hlp, back_chain[i], len) - condition = opt_args("Condition", flags[i]) - cl_flags = switch_flags(flags[i]) - if (condition != "") - printf("#if %s\n" \ - " %s,\n" \ - "#else\n" \ - " CL_DISABLED,\n" \ - "#endif\n", - condition, cl_flags, cl_flags) - else - printf(" %s,\n", cl_flags) - printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]), - var_set(flags[i]), comma) -} - -print "};" -} +# Copyright (C) 2003,2004 Free Software Foundation, Inc. +# Contributed by Kelley Cook, June 2004. +# Original code from Neil Booth, May 2003. +# +# 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 +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# This Awk script reads in the option records generated from +# opt-gather.awk, combines the flags of duplicat options and generates a +# C file. +# +# This program uses functions from opt-functions.awk +# +# Usage: awk -f opt-functions.awk -f optc-gen.awk \ +# [-v header_name=header.h] < inputfile > options.c + +BEGIN { + n_opts = 0 + n_langs = 0 + quote = "\042" + comma = "," + FS=SUBSEP + # Default the name of header created from opth-gen.awk to options.h + if (header_name == "") header_name="options.h" +} + +# Collect the text and flags of each option into an array + { + if ($1 == "Language") { + langs[n_langs] = $2 + n_langs++; + } + else { + name = opt_args("Mask", $1) + if (name == "") { + opts[n_opts] = $1 + flags[n_opts] = $2 + help[n_opts] = $3 + n_opts++; + } + } + } + +# Dump that array of options into a C file. +END { +print "/* This file is auto-generated by opts.sh. */" +print "" +n_headers = split(header_name, headers, " ") +for (i = 1; i <= n_headers; i++) + print "#include " quote headers[i] quote +print "#include " quote "opts.h" quote +print "#include " quote "intl.h" quote +print "" + +for (i = 0; i < n_opts; i++) { + name = var_name(flags[i]); + if (name == "") + continue; + + if (flag_set_p("VarExists", flags[i])) + continue; + + init = opt_args("Init", flags[i]) + if (init != "") + init = " = " init; + else if (name in var_seen) + continue; + + print "/* Set by -" opts[i] "." + print " " help[i] " */" + print var_type(flags[i]) name init ";" + print "" + + var_seen[name] = 1; +} + +print "" +print "/* Local state variables. */" +for (i = 0; i < n_opts; i++) { + name = static_var(opts[i], flags[i]); + if (name != "") + print "static " var_type(flags[i]) name ";" +} +print "" + +print "const char * const lang_names[] =\n{" +for (i = 0; i < n_langs; i++) { + macros[i] = "CL_" langs[i] + gsub( "[^A-Za-z0-9_]", "X", macros[i] ) + s = substr(" ", length (macros[i])) + print " " quote langs[i] quote "," + } + +print " 0\n};\n" +print "const unsigned int cl_options_count = N_OPTS;\n" + +print "const struct cl_option cl_options[] =\n{" + +for (i = 0; i < n_opts; i++) + back_chain[i] = "N_OPTS"; + +for (i = 0; i < n_opts; i++) { + # Combine the flags of identical switches. Switches + # appear many times if they are handled by many front + # ends, for example. + while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { + flags[i + 1] = flags[i] " " flags[i + 1]; + i++; + } + + len = length (opts[i]); + enum = "OPT_" opts[i] + if (opts[i] == "finline-limit=") + enum = enum "eq" + gsub ("[^A-Za-z0-9]", "_", enum) + + # If this switch takes joined arguments, back-chain all + # subsequent switches to it for which it is a prefix. If + # a later switch S is a longer prefix of a switch T, T + # will be back-chained to S in a later iteration of this + # for() loop, which is what we want. + if (flag_set_p("Joined.*", flags[i])) { + for (j = i + 1; j < n_opts; j++) { + if (substr (opts[j], 1, len) != opts[i]) + break; + back_chain[j] = enum; + } + } + + s = substr(" ", length (opts[i])) + if (i + 1 == n_opts) + comma = "" + + if (help[i] == "") + hlp = "0" + else + hlp = quote help[i] quote; + + printf(" { %c-%s%c,\n %s,\n %s, %u,\n", + quote, opts[i], quote, hlp, back_chain[i], len) + condition = opt_args("Condition", flags[i]) + cl_flags = switch_flags(flags[i]) + if (condition != "") + printf("#if %s\n" \ + " %s,\n" \ + "#else\n" \ + " CL_DISABLED,\n" \ + "#endif\n", + condition, cl_flags, cl_flags) + else + printf(" %s,\n", cl_flags) + printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]), + var_set(flags[i]), comma) +} + +print "};" +} diff --git a/support/cpp2/opth-gen.awk b/support/cpp2/opth-gen.awk index 09d1a9a0..a6537a1c 100644 --- a/support/cpp2/opth-gen.awk +++ b/support/cpp2/opth-gen.awk @@ -1,185 +1,185 @@ -# Copyright (C) 2003,2004 Free Software Foundation, Inc. -# Contributed by Kelley Cook, June 2004. -# Original code from Neil Booth, May 2003. -# -# 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 -# Free Software Foundation; either version 2, or (at your option) any -# later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# This Awk script reads in the option records generated from -# opt-gather.awk, combines the flags of duplicate options and generates a -# C header file. -# -# This program uses functions from opt-functions.awk -# Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h - -BEGIN { - n_opts = 0 - n_langs = 0 - n_extra_masks = 0 - quote = "\042" - comma = "," - FS=SUBSEP -} - -# Collect the text and flags of each option into an array - { - if ($1 == "Language") { - langs[n_langs] = $2 - n_langs++; - } - else { - name = opt_args("Mask", $1) - if (name == "") { - opts[n_opts] = $1 - flags[n_opts] = $2 - help[n_opts] = $3 - n_opts++; - } - else { - extra_masks[n_extra_masks++] = name - } - } - } - -# Dump out an enumeration into a .h file. -# Combine the flags of duplicate options. -END { -print "/* This file is auto-generated by opts.sh. */" -print "" -print "#ifndef OPTIONS_H" -print "#define OPTIONS_H" -print "" -print "extern int target_flags;" -print "" - -for (i = 0; i < n_opts; i++) { - name = var_name(flags[i]); - if (name == "") - continue; - - print "extern " var_type(flags[i]) name ";" -} -print "" - -for (i = 0; i < n_opts; i++) { - name = opt_args("Mask", flags[i]) - vname = var_name(flags[i]) - mask = "MASK_" - if (vname != "") { - mask = "OPTION_MASK_" - } - if (name != "" && !flag_set_p("MaskExists", flags[i])) - print "#define " mask name " (1 << " masknum[vname]++ ")" -} -for (i = 0; i < n_extra_masks; i++) { - print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")" -} - -for (var in masknum) { - if (masknum[var] > 31) { - if (var == "") - print "#error too many target masks" - else - print "#error too many masks for " var - } -} -print "" - -for (i = 0; i < n_opts; i++) { - name = opt_args("Mask", flags[i]) - vname = var_name(flags[i]) - macro = "OPTION_" - mask = "OPTION_MASK_" - if (vname == "") { - vname = "target_flags" - macro = "TARGET_" - mask = "MASK_" - } - if (name != "" && !flag_set_p("MaskExists", flags[i])) - print "#define " macro name \ - " ((" vname " & " mask name ") != 0)" -} -for (i = 0; i < n_extra_masks; i++) { - print "#define TARGET_" extra_masks[i] \ - " ((target_flags & MASK_" extra_masks[i] ") != 0)" -} -print "" - -for (i = 0; i < n_opts; i++) { - opt = opt_args("InverseMask", flags[i]) - if (opt ~ ",") - print "#define TARGET_" nth_arg(1, opt) \ - " ((target_flags & MASK_" nth_arg(0, opt) ") == 0)" -} -print "" - -for (i = 0; i < n_langs; i++) { - macros[i] = "CL_" langs[i] - gsub( "[^A-Za-z0-9_]", "X", macros[i] ) - s = substr(" ", length (macros[i])) - print "#define " macros[i] s " (1 << " i ")" - } - -print "" -print "enum opt_code" -print "{" - -for (i = 0; i < n_opts; i++) - back_chain[i] = "N_OPTS"; - -for (i = 0; i < n_opts; i++) { - # Combine the flags of identical switches. Switches - # appear many times if they are handled by many front - # ends, for example. - while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { - flags[i + 1] = flags[i] " " flags[i + 1]; - i++; - } - - len = length (opts[i]); - enum = "OPT_" opts[i] - if (opts[i] == "finline-limit=") - enum = enum "eq" - gsub ("[^A-Za-z0-9]", "_", enum) - - # If this switch takes joined arguments, back-chain all - # subsequent switches to it for which it is a prefix. If - # a later switch S is a longer prefix of a switch T, T - # will be back-chained to S in a later iteration of this - # for() loop, which is what we want. - if (flag_set_p("Joined.*", flags[i])) { - for (j = i + 1; j < n_opts; j++) { - if (substr (opts[j], 1, len) != opts[i]) - break; - back_chain[j] = enum; - } - } - - s = substr(" ", length (opts[i])) - if (i + 1 == n_opts) - comma = "" - - if (help[i] == "") - hlp = "0" - else - hlp = "N_(\"" help[i] "\")"; - - print " " enum "," s "/* -" opts[i] " */" -} - -print " N_OPTS" -print "};" -print "" -print "#endif /* OPTIONS_H */" -} +# Copyright (C) 2003,2004 Free Software Foundation, Inc. +# Contributed by Kelley Cook, June 2004. +# Original code from Neil Booth, May 2003. +# +# 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 +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# This Awk script reads in the option records generated from +# opt-gather.awk, combines the flags of duplicate options and generates a +# C header file. +# +# This program uses functions from opt-functions.awk +# Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h + +BEGIN { + n_opts = 0 + n_langs = 0 + n_extra_masks = 0 + quote = "\042" + comma = "," + FS=SUBSEP +} + +# Collect the text and flags of each option into an array + { + if ($1 == "Language") { + langs[n_langs] = $2 + n_langs++; + } + else { + name = opt_args("Mask", $1) + if (name == "") { + opts[n_opts] = $1 + flags[n_opts] = $2 + help[n_opts] = $3 + n_opts++; + } + else { + extra_masks[n_extra_masks++] = name + } + } + } + +# Dump out an enumeration into a .h file. +# Combine the flags of duplicate options. +END { +print "/* This file is auto-generated by opts.sh. */" +print "" +print "#ifndef OPTIONS_H" +print "#define OPTIONS_H" +print "" +print "extern int target_flags;" +print "" + +for (i = 0; i < n_opts; i++) { + name = var_name(flags[i]); + if (name == "") + continue; + + print "extern " var_type(flags[i]) name ";" +} +print "" + +for (i = 0; i < n_opts; i++) { + name = opt_args("Mask", flags[i]) + vname = var_name(flags[i]) + mask = "MASK_" + if (vname != "") { + mask = "OPTION_MASK_" + } + if (name != "" && !flag_set_p("MaskExists", flags[i])) + print "#define " mask name " (1 << " masknum[vname]++ ")" +} +for (i = 0; i < n_extra_masks; i++) { + print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")" +} + +for (var in masknum) { + if (masknum[var] > 31) { + if (var == "") + print "#error too many target masks" + else + print "#error too many masks for " var + } +} +print "" + +for (i = 0; i < n_opts; i++) { + name = opt_args("Mask", flags[i]) + vname = var_name(flags[i]) + macro = "OPTION_" + mask = "OPTION_MASK_" + if (vname == "") { + vname = "target_flags" + macro = "TARGET_" + mask = "MASK_" + } + if (name != "" && !flag_set_p("MaskExists", flags[i])) + print "#define " macro name \ + " ((" vname " & " mask name ") != 0)" +} +for (i = 0; i < n_extra_masks; i++) { + print "#define TARGET_" extra_masks[i] \ + " ((target_flags & MASK_" extra_masks[i] ") != 0)" +} +print "" + +for (i = 0; i < n_opts; i++) { + opt = opt_args("InverseMask", flags[i]) + if (opt ~ ",") + print "#define TARGET_" nth_arg(1, opt) \ + " ((target_flags & MASK_" nth_arg(0, opt) ") == 0)" +} +print "" + +for (i = 0; i < n_langs; i++) { + macros[i] = "CL_" langs[i] + gsub( "[^A-Za-z0-9_]", "X", macros[i] ) + s = substr(" ", length (macros[i])) + print "#define " macros[i] s " (1 << " i ")" + } + +print "" +print "enum opt_code" +print "{" + +for (i = 0; i < n_opts; i++) + back_chain[i] = "N_OPTS"; + +for (i = 0; i < n_opts; i++) { + # Combine the flags of identical switches. Switches + # appear many times if they are handled by many front + # ends, for example. + while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { + flags[i + 1] = flags[i] " " flags[i + 1]; + i++; + } + + len = length (opts[i]); + enum = "OPT_" opts[i] + if (opts[i] == "finline-limit=") + enum = enum "eq" + gsub ("[^A-Za-z0-9]", "_", enum) + + # If this switch takes joined arguments, back-chain all + # subsequent switches to it for which it is a prefix. If + # a later switch S is a longer prefix of a switch T, T + # will be back-chained to S in a later iteration of this + # for() loop, which is what we want. + if (flag_set_p("Joined.*", flags[i])) { + for (j = i + 1; j < n_opts; j++) { + if (substr (opts[j], 1, len) != opts[i]) + break; + back_chain[j] = enum; + } + } + + s = substr(" ", length (opts[i])) + if (i + 1 == n_opts) + comma = "" + + if (help[i] == "") + hlp = "0" + else + hlp = "N_(\"" help[i] "\")"; + + print " " enum "," s "/* -" opts[i] " */" +} + +print " N_OPTS" +print "};" +print "" +print "#endif /* OPTIONS_H */" +} -- 2.30.2