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
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
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/>. */
24 #include "coretypes.h"
27 #include "diagnostic-core.h"
30 /* An array containing the compiler parameters and their current
33 param_info
*compiler_params
;
35 /* The number of entries in the table. */
36 static size_t num_compiler_params
;
38 /* Add the N PARAMS to the current list of compiler parameters. */
41 add_params (const param_info params
[], size_t n
)
43 /* Allocate enough space for the new parameters. */
44 compiler_params
= XRESIZEVEC (param_info
, compiler_params
,
45 num_compiler_params
+ n
);
46 /* Copy them into the table. */
47 memcpy (compiler_params
+ num_compiler_params
,
49 n
* sizeof (param_info
));
50 /* Keep track of how many parameters we have. */
51 num_compiler_params
+= n
;
54 /* Set the value of the parameter given by NUM to VALUE. If
55 EXPLICIT_P, this is being set by the user; otherwise it is being
56 set implicitly by the compiler. */
59 set_param_value_internal (compiler_param num
, int value
,
62 size_t i
= (size_t) num
;
64 compiler_params
[i
].value
= value
;
66 compiler_params
[i
].set
= true;
69 /* Set the VALUE associated with the parameter given by NAME. */
72 set_param_value (const char *name
, int value
)
76 /* Make sure nobody tries to set a parameter to an invalid value. */
77 gcc_assert (value
!= INVALID_PARAM_VAL
);
79 /* Scan the parameter table to find a matching entry. */
80 for (i
= 0; i
< num_compiler_params
; ++i
)
81 if (strcmp (compiler_params
[i
].option
, name
) == 0)
83 if (value
< compiler_params
[i
].min_value
)
84 error ("minimum value of parameter %qs is %u",
85 compiler_params
[i
].option
,
86 compiler_params
[i
].min_value
);
87 else if (compiler_params
[i
].max_value
> compiler_params
[i
].min_value
88 && value
> compiler_params
[i
].max_value
)
89 error ("maximum value of parameter %qs is %u",
90 compiler_params
[i
].option
,
91 compiler_params
[i
].max_value
);
93 set_param_value_internal ((compiler_param
) i
, value
, true);
97 /* If we didn't find this parameter, issue an error message. */
98 error ("invalid parameter %qs", name
);
101 /* Set the value of the parameter given by NUM to VALUE, implicitly,
102 if it has not been set explicitly by the user. */
105 maybe_set_param_value (compiler_param num
, int value
)
107 if (!PARAM_SET_P (num
))
108 set_param_value_internal (num
, value
, false);
111 /* Set the default value of a parameter given by NUM to VALUE, before
112 option processing. */
115 set_default_param_value (compiler_param num
, int value
)
117 gcc_assert (!PARAM_SET_P (num
));
118 set_param_value_internal (num
, value
, false);
121 /* Return the current value of num_compiler_params, for the benefit of
122 plugins that use parameters as features. */
125 get_num_compiler_params (void)
127 return num_compiler_params
;