2011-04-29 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / params.c
blob95af6cec0ed73105566947137c8980d30ed6c34b
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>.
6 This file is part of GCC.
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.
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.
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/>. */
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"
29 /* An array containing the compiler parameters and their current
30 values. */
32 param_info *compiler_params;
34 /* The number of entries in the table. */
35 static size_t num_compiler_params;
37 /* Whether the parameters have all been initialized and had their
38 default values determined. */
39 static bool params_finished;
41 /* Add the N PARAMS to the current list of compiler parameters. */
43 void
44 add_params (const param_info params[], size_t n)
46 gcc_assert (!params_finished);
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;
59 /* Note that all parameters have been added and all default values
60 set. */
62 void
63 finish_params (void)
65 params_finished = true;
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. */
72 static void
73 set_param_value_internal (compiler_param num, int value,
74 int *params, int *params_set,
75 bool explicit_p)
77 size_t i = (size_t) num;
79 gcc_assert (params_finished);
81 params[i] = value;
82 if (explicit_p)
83 params_set[i] = true;
86 /* Set the VALUE associated with the parameter given by NAME in PARAMS
87 and PARAMS_SET. */
89 void
90 set_param_value (const char *name, int value,
91 int *params, int *params_set)
93 size_t i;
95 /* Make sure nobody tries to set a parameter to an invalid value. */
96 gcc_assert (value != INVALID_PARAM_VAL);
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)
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;
117 /* If we didn't find this parameter, issue an error message. */
118 error ("invalid parameter %qs", name);
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. */
125 void
126 maybe_set_param_value (compiler_param num, int value,
127 int *params, int *params_set)
129 if (!params_set[(int) num])
130 set_param_value_internal (num, value, params, params_set, false);
133 /* Set the default value of a parameter given by NUM to VALUE, before
134 option processing. */
136 void
137 set_default_param_value (compiler_param num, int value)
139 gcc_assert (!params_finished);
141 compiler_params[(int) num].default_value = value;
144 /* Return the default value of parameter NUM. */
147 default_param_value (compiler_param num)
149 return compiler_params[(int) num].default_value;
152 /* Initialize an array PARAMS with default values of the
153 parameters. */
155 void
156 init_param_values (int *params)
158 size_t i;
160 gcc_assert (params_finished);
162 for (i = 0; i < num_compiler_params; i++)
163 params[i] = compiler_params[i].default_value;
166 /* Return the current value of num_compiler_params, for the benefit of
167 plugins that use parameters as features. */
169 size_t
170 get_num_compiler_params (void)
172 return num_compiler_params;