comparison gcc/params.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* params.c - Run-time parameters. 1 /* params.c - Run-time parameters.
2 Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010 2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 Written by Mark Mitchell <mark@codesourcery.com>. 3 Written by Mark Mitchell <mark@codesourcery.com>.
5 4
6 This file is part of GCC. 5 This file is part of GCC.
7 6
8 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
20 <http://www.gnu.org/licenses/>. */ 19 <http://www.gnu.org/licenses/>. */
21 20
22 #include "config.h" 21 #include "config.h"
23 #include "system.h" 22 #include "system.h"
24 #include "coretypes.h" 23 #include "coretypes.h"
25 #include "tm.h" 24 #include "common/common-target.h"
26 #include "params.h" 25 #include "params.h"
26 #include "params-enum.h"
27 #include "diagnostic-core.h" 27 #include "diagnostic-core.h"
28 #include "spellcheck.h"
28 29
29 /* An array containing the compiler parameters and their current 30 /* An array containing the compiler parameters and their current
30 values. */ 31 values. */
31 32
32 param_info *compiler_params; 33 param_info *compiler_params;
35 static size_t num_compiler_params; 36 static size_t num_compiler_params;
36 37
37 /* Whether the parameters have all been initialized and had their 38 /* Whether the parameters have all been initialized and had their
38 default values determined. */ 39 default values determined. */
39 static bool params_finished; 40 static bool params_finished;
41
42 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX)
43 #define DEFPARAMENUM5(ENUM, OPTION, HELP, DEFAULT, V0, V1, V2, V3, V4) \
44 static const char *values_ ## ENUM [] = { #V0, #V1, #V2, #V3, #V4, NULL };
45 #include "params.def"
46 #undef DEFPARAMENUM5
47 #undef DEFPARAM
48
49 static const param_info lang_independent_params[] = {
50 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
51 { OPTION, DEFAULT, MIN, MAX, HELP, NULL },
52 #define DEFPARAMENUM5(ENUM, OPTION, HELP, DEFAULT, \
53 V0, V1, V2, V3, V4) \
54 { OPTION, (int)ENUM ## _KIND_ ## DEFAULT, 0, 4, HELP, values_ ## ENUM },
55 #include "params.def"
56 #undef DEFPARAM
57 #undef DEFPARAMENUM5
58 { NULL, 0, 0, 0, NULL, NULL }
59 };
40 60
41 /* Add the N PARAMS to the current list of compiler parameters. */ 61 /* Add the N PARAMS to the current list of compiler parameters. */
42 62
43 void 63 void
44 add_params (const param_info params[], size_t n) 64 add_params (const param_info params[], size_t n)
54 n * sizeof (param_info)); 74 n * sizeof (param_info));
55 /* Keep track of how many parameters we have. */ 75 /* Keep track of how many parameters we have. */
56 num_compiler_params += n; 76 num_compiler_params += n;
57 } 77 }
58 78
79 /* Add all parameters and default values that can be set in both the
80 driver and the compiler proper. */
81
82 void
83 global_init_params (void)
84 {
85 gcc_assert (!params_finished);
86
87 add_params (lang_independent_params, LAST_PARAM);
88 targetm_common.option_default_params ();
89 }
90
59 /* Note that all parameters have been added and all default values 91 /* Note that all parameters have been added and all default values
60 set. */ 92 set. */
61 93
62 void 94 void
63 finish_params (void) 95 finish_params (void)
64 { 96 {
65 params_finished = true; 97 params_finished = true;
98 }
99
100 /* Reset all state within params.c so that we can rerun the compiler
101 within the same process. For use by toplev::finalize. */
102
103 void
104 params_c_finalize (void)
105 {
106 XDELETEVEC (compiler_params);
107 compiler_params = NULL;
108 num_compiler_params = 0;
109 params_finished = false;
66 } 110 }
67 111
68 /* Set the value of the parameter given by NUM to VALUE in PARAMS and 112 /* 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; 113 PARAMS_SET. If EXPLICIT_P, this is being set by the user;
70 otherwise it is being set implicitly by the compiler. */ 114 otherwise it is being set implicitly by the compiler. */
81 params[i] = value; 125 params[i] = value;
82 if (explicit_p) 126 if (explicit_p)
83 params_set[i] = true; 127 params_set[i] = true;
84 } 128 }
85 129
130 /* Return true if it can find the matching entry for NAME in the parameter
131 table, and assign the entry index to INDEX. Return false otherwise. */
132
133 bool
134 find_param (const char *name, enum compiler_param *index)
135 {
136 for (size_t i = 0; i < num_compiler_params; ++i)
137 if (strcmp (compiler_params[i].option, name) == 0)
138 {
139 *index = (enum compiler_param) i;
140 return true;
141 }
142
143 return false;
144 }
145
146 /* Look for the closest match for NAME in the parameter table, returning it
147 if it is a reasonable suggestion for a misspelling. Return NULL
148 otherwise. */
149
150 const char *
151 find_param_fuzzy (const char *name)
152 {
153 best_match <const char *, const char *> bm (name);
154 for (size_t i = 0; i < num_compiler_params; ++i)
155 bm.consider (compiler_params[i].option);
156 return bm.get_best_meaningful_candidate ();
157 }
158
159 /* Return true if param with entry index INDEX should be defined using strings.
160 If so, return the value corresponding to VALUE_NAME in *VALUE_P. */
161
162 bool
163 param_string_value_p (enum compiler_param index, const char *value_name,
164 int *value_p)
165 {
166 param_info *entry = &compiler_params[(int) index];
167 if (entry->value_names == NULL)
168 return false;
169
170 *value_p = -1;
171
172 for (int i = 0; entry->value_names[i] != NULL; ++i)
173 if (strcmp (entry->value_names[i], value_name) == 0)
174 {
175 *value_p = i;
176 return true;
177 }
178
179 return true;
180 }
181
86 /* Set the VALUE associated with the parameter given by NAME in PARAMS 182 /* Set the VALUE associated with the parameter given by NAME in PARAMS
87 and PARAMS_SET. */ 183 and PARAMS_SET. */
88 184
89 void 185 void
90 set_param_value (const char *name, int value, 186 set_param_value (const char *name, int value,
93 size_t i; 189 size_t i;
94 190
95 /* Make sure nobody tries to set a parameter to an invalid value. */ 191 /* Make sure nobody tries to set a parameter to an invalid value. */
96 gcc_assert (value != INVALID_PARAM_VAL); 192 gcc_assert (value != INVALID_PARAM_VAL);
97 193
98 /* Scan the parameter table to find a matching entry. */ 194 enum compiler_param index;
99 for (i = 0; i < num_compiler_params; ++i) 195 if (!find_param (name, &index))
100 if (strcmp (compiler_params[i].option, name) == 0) 196 {
101 { 197 /* If we didn't find this parameter, issue an error message. */
102 if (value < compiler_params[i].min_value) 198 error ("invalid parameter %qs", name);
103 error ("minimum value of parameter %qs is %u", 199 return;
104 compiler_params[i].option, 200 }
105 compiler_params[i].min_value); 201 i = (size_t)index;
106 else if (compiler_params[i].max_value > compiler_params[i].min_value 202
107 && value > compiler_params[i].max_value) 203 if (value < compiler_params[i].min_value)
108 error ("maximum value of parameter %qs is %u", 204 error ("minimum value of parameter %qs is %u",
109 compiler_params[i].option, 205 compiler_params[i].option,
110 compiler_params[i].max_value); 206 compiler_params[i].min_value);
111 else 207 else if (compiler_params[i].max_value > compiler_params[i].min_value
112 set_param_value_internal ((compiler_param) i, value, 208 && value > compiler_params[i].max_value)
113 params, params_set, true); 209 error ("maximum value of parameter %qs is %u",
114 return; 210 compiler_params[i].option,
115 } 211 compiler_params[i].max_value);
116 212 else
117 /* If we didn't find this parameter, issue an error message. */ 213 set_param_value_internal ((compiler_param) i, value,
118 error ("invalid parameter %qs", name); 214 params, params_set, true);
119 } 215 }
120 216
121 /* Set the value of the parameter given by NUM to VALUE in PARAMS and 217 /* 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 218 PARAMS_SET, implicitly, if it has not been set explicitly by the
123 user. */ 219 user. */