OSDN Git Service

PR c++/45399
[pf3gnuchains/gcc-fork.git] / gcc / params.c
1 /* params.c - Run-time parameters.
2    Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4    Written by Mark Mitchell <mark@codesourcery.com>.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "params.h"
27 #include "diagnostic-core.h"
28
29 /* An array containing the compiler parameters and their current
30    values.  */
31
32 param_info *compiler_params;
33
34 /* The number of entries in the table.  */
35 static size_t num_compiler_params;
36
37 /* Whether the parameters have all been initialized and had their
38    default values determined.  */
39 static bool params_finished;
40
41 /* Add the N PARAMS to the current list of compiler parameters.  */
42
43 void
44 add_params (const param_info params[], size_t n)
45 {
46   gcc_assert (!params_finished);
47
48   /* Allocate enough space for the new parameters.  */
49   compiler_params = XRESIZEVEC (param_info, compiler_params,
50                                 num_compiler_params + n);
51   /* Copy them into the table.  */
52   memcpy (compiler_params + num_compiler_params,
53           params,
54           n * sizeof (param_info));
55   /* Keep track of how many parameters we have.  */
56   num_compiler_params += n;
57 }
58
59 /* Note that all parameters have been added and all default values
60    set.  */
61
62 void
63 finish_params (void)
64 {
65   params_finished = true;
66 }
67
68 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
69    PARAMS_SET.  If EXPLICIT_P, this is being set by the user;
70    otherwise it is being set implicitly by the compiler.  */
71
72 static void
73 set_param_value_internal (compiler_param num, int value,
74                           int *params, int *params_set,
75                           bool explicit_p)
76 {
77   size_t i = (size_t) num;
78
79   gcc_assert (params_finished);
80
81   params[i] = value;
82   if (explicit_p)
83     params_set[i] = true;
84 }
85
86 /* Set the VALUE associated with the parameter given by NAME in PARAMS
87    and PARAMS_SET.  */
88
89 void
90 set_param_value (const char *name, int value,
91                  int *params, int *params_set)
92 {
93   size_t i;
94
95   /* Make sure nobody tries to set a parameter to an invalid value.  */
96   gcc_assert (value != INVALID_PARAM_VAL);
97
98   /* Scan the parameter table to find a matching entry.  */
99   for (i = 0; i < num_compiler_params; ++i)
100     if (strcmp (compiler_params[i].option, name) == 0)
101       {
102         if (value < compiler_params[i].min_value)
103           error ("minimum value of parameter %qs is %u",
104                  compiler_params[i].option,
105                  compiler_params[i].min_value);
106         else if (compiler_params[i].max_value > compiler_params[i].min_value
107                  && value > compiler_params[i].max_value)
108           error ("maximum value of parameter %qs is %u",
109                  compiler_params[i].option,
110                  compiler_params[i].max_value);
111         else
112           set_param_value_internal ((compiler_param) i, value,
113                                     params, params_set, true);
114         return;
115       }
116
117   /* If we didn't find this parameter, issue an error message.  */
118   error ("invalid parameter %qs", name);
119 }
120
121 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
122    PARAMS_SET, implicitly, if it has not been set explicitly by the
123    user.  */
124
125 void
126 maybe_set_param_value (compiler_param num, int value,
127                        int *params, int *params_set)
128 {
129   if (!params_set[(int) num])
130     set_param_value_internal (num, value, params, params_set, false);
131 }
132
133 /* Set the default value of a parameter given by NUM to VALUE, before
134    option processing.  */
135
136 void
137 set_default_param_value (compiler_param num, int value)
138 {
139   gcc_assert (!params_finished);
140
141   compiler_params[(int) num].default_value = value;
142 }
143
144 /* Return the default value of parameter NUM.  */
145
146 int
147 default_param_value (compiler_param num)
148 {
149   return compiler_params[(int) num].default_value;
150 }
151
152 /* Initialize an array PARAMS with default values of the
153    parameters.  */
154
155 void
156 init_param_values (int *params)
157 {
158   size_t i;
159
160   gcc_assert (params_finished);
161
162   for (i = 0; i < num_compiler_params; i++)
163     params[i] = compiler_params[i].default_value;
164 }
165
166 /* Return the current value of num_compiler_params, for the benefit of
167    plugins that use parameters as features.  */
168
169 size_t
170 get_num_compiler_params (void)
171 {
172   return num_compiler_params;
173 }