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