OSDN Git Service

Oops - forgot to include ChangeLog entry for m32r patch
[pf3gnuchains/gcc-fork.git] / gcc / opt-functions.awk
1 #  Copyright (C) 2003,2004 Free Software Foundation, Inc.
2 #  Contributed by Kelley Cook, June 2004.
3 #  Original code from Neil Booth, May 2003.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
8 # later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # Some common subroutines for use by opt[ch]-gen.awk.
20
21 # If FLAGS contains a "NAME(...argument...)" flag, return the value
22 # of the argument.  Return the empty string otherwise.
23 function opt_args(name, flags)
24 {
25         flags = " " flags
26         if (flags !~ " " name "\\(")
27                 return ""
28         sub(".* " name "\\(", "", flags)
29         sub("\\).*", "", flags)
30
31         return flags
32 }
33
34 # Return the Nth comma-separated element of S.  Return the empty string
35 # if S does not contain N elements.
36 function nth_arg(n, s)
37 {
38         while (n-- > 0) {
39                 if (s !~ ",")
40                         return ""
41                 sub("[^,]*, *", "", s)
42         }
43         sub(",.*", "", s)
44         return s
45 }
46
47 # Return a bitmask of CL_* values for option flags FLAGS.
48 function switch_flags (flags)
49 {
50         flags = " " flags " "
51         result = "0"
52         for (j = 0; j < n_langs; j++) {
53                 regex = " " langs[j] " "
54                 gsub ( "\\+", "\\+", regex )
55                 if (flags ~ regex)
56                         result = result " | " macros[j]
57         }
58         if (flags ~ " Common ") result = result " | CL_COMMON"
59         if (flags ~ " Target ") result = result " | CL_TARGET"
60         if (flags ~ " Joined ") result = result " | CL_JOINED"
61         if (flags ~ " JoinedOrMissing ") \
62             result = result " | CL_JOINED | CL_MISSING_OK"
63         if (flags ~ " Separate ") result = result " | CL_SEPARATE"
64         if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
65         if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
66         if (flags ~ " Undocumented ") result = result " | CL_UNDOCUMENTED"
67         if (flags ~ " Report ") result = result " | CL_REPORT"
68         sub( "^0 \\| ", "", result )
69         return result
70 }
71
72 # If FLAGS includes a Var flag, return the name of the variable it specifies.
73 # Return the empty string otherwise.
74 function var_name(flags)
75 {
76         return nth_arg(0, opt_args("Var", flags))
77 }
78
79 # Given that an option has flags FLAGS, return an initializer for the
80 # "var_cond" and "var_value" fields of its cl_options[] entry.
81 function var_set(flags)
82 {
83         s = nth_arg(1, opt_args("Var", flags))
84         if (s != "")
85                 return "CLVC_EQUAL, " s
86         s = opt_args("Mask", flags);
87         if (s != "")
88                 return "CLVC_BIT_SET, MASK_" s
89         s = nth_arg(0, opt_args("InverseMask", flags));
90         if (s != "")
91                 return "CLVC_BIT_CLEAR, MASK_" s
92         return "CLVC_BOOLEAN, 0"
93 }
94
95 # Given that an option has flags FLAGS, return an initializer for the
96 # "flag_var" field of its cl_options[] entry.
97 function var_ref(flags)
98 {
99         name = var_name(flags)
100         if (name != "")
101                 return "&" name
102         if (opt_args("Mask", flags) != "")
103                 return "&target_flags"
104         if (opt_args("InverseMask", flags) != "")
105                 return "&target_flags"
106         return "0"
107 }