OSDN Git Service

moxie EH fixes
[pf3gnuchains/gcc-fork.git] / gcc / params.c
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>.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
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"
28 #include "toplev.h"
29
30 /* An array containing the compiler parameters and their current
31    values.  */
32
33 param_info *compiler_params;
34
35 /* The number of entries in the table.  */
36 static size_t num_compiler_params;
37
38 /* Whether the parameters have all been initialized and had their
39    default values determined.  */
40 static bool params_finished;
41
42 /* Add the N PARAMS to the current list of compiler parameters.  */
43
44 void
45 add_params (const param_info params[], size_t n)
46 {
47   gcc_assert (!params_finished);
48
49   /* Allocate enough space for the new parameters.  */
50   compiler_params = XRESIZEVEC (param_info, compiler_params,
51                                 num_compiler_params + n);
52   /* Copy them into the table.  */
53   memcpy (compiler_params + num_compiler_params,
54           params,
55           n * sizeof (param_info));
56   /* Keep track of how many parameters we have.  */
57   num_compiler_params += n;
58 }
59
60 /* Note that all parameters have been added and all default values
61    set.  */
62
63 void
64 finish_params (void)
65 {
66   params_finished = true;
67 }
68
69 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
70    PARAMS_SET.  If EXPLICIT_P, this is being set by the user;
71    otherwise it is being set implicitly by the compiler.  */
72
73 static void
74 set_param_value_internal (compiler_param num, int value,
75                           int *params, int *params_set,
76                           bool explicit_p)
77 {
78   size_t i = (size_t) num;
79
80   gcc_assert (params_finished);
81
82   params[i] = value;
83   if (explicit_p)
84     params_set[i] = true;
85 }
86
87 /* Set the VALUE associated with the parameter given by NAME in PARAMS
88    and PARAMS_SET.  */
89
90 void
91 set_param_value (const char *name, int value,
92                  int *params, int *params_set)
93 {
94   size_t i;
95
96   /* Make sure nobody tries to set a parameter to an invalid value.  */
97   gcc_assert (value != INVALID_PARAM_VAL);
98
99   /* Scan the parameter table to find a matching entry.  */
100   for (i = 0; i < num_compiler_params; ++i)
101     if (strcmp (compiler_params[i].option, name) == 0)
102       {
103         if (value < compiler_params[i].min_value)
104           error ("minimum value of parameter %qs is %u",
105                  compiler_params[i].option,
106                  compiler_params[i].min_value);
107         else if (compiler_params[i].max_value > compiler_params[i].min_value
108                  && value > compiler_params[i].max_value)
109           error ("maximum value of parameter %qs is %u",
110                  compiler_params[i].option,
111                  compiler_params[i].max_value);
112         else
113           set_param_value_internal ((compiler_param) i, value,
114                                     params, params_set, true);
115         return;
116       }
117
118   /* If we didn't find this parameter, issue an error message.  */
119   error ("invalid parameter %qs", name);
120 }
121
122 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
123    PARAMS_SET, implicitly, if it has not been set explicitly by the
124    user.  */
125
126 void
127 maybe_set_param_value (compiler_param num, int value,
128                        int *params, int *params_set)
129 {
130   if (!params_set[(int) num])
131     set_param_value_internal (num, value, params, params_set, false);
132 }
133
134 /* Set the default value of a parameter given by NUM to VALUE, before
135    option processing.  */
136
137 void
138 set_default_param_value (compiler_param num, int value)
139 {
140   gcc_assert (!params_finished);
141
142   compiler_params[(int) num].default_value = value;
143 }
144
145 /* Return the default value of parameter NUM.  */
146
147 int
148 default_param_value (compiler_param num)
149 {
150   return compiler_params[(int) num].default_value;
151 }
152
153 /* Initialize an array PARAMS with default values of the
154    parameters.  */
155
156 void
157 init_param_values (int *params)
158 {
159   size_t i;
160
161   gcc_assert (params_finished);
162
163   for (i = 0; i < num_compiler_params; i++)
164     params[i] = compiler_params[i].default_value;
165 }
166
167 /* Return the current value of num_compiler_params, for the benefit of
168    plugins that use parameters as features.  */
169
170 size_t
171 get_num_compiler_params (void)
172 {
173   return num_compiler_params;
174 }