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