]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/params.c
2009-12-01 Grigori Fursin <grigori.fursin@inria.fr>
[thirdparty/gcc.git] / gcc / params.c
CommitLineData
9a33a2e8 1/* params.c - Run-time parameters.
cfaf579d 2 Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
9a33a2e8 4 Written by Mark Mitchell <mark@codesourcery.com>.
5
f12b58b3 6This file is part of GCC.
9a33a2e8 7
f12b58b3 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
8c4c00c1 10Software Foundation; either version 3, or (at your option) any later
f12b58b3 11version.
9a33a2e8 12
f12b58b3 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.
9a33a2e8 17
18You should have received a copy of the GNU General Public License
8c4c00c1 19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
9a33a2e8 21
22#include "config.h"
23#include "system.h"
805e22b2 24#include "coretypes.h"
25#include "tm.h"
9a33a2e8 26#include "params.h"
27#include "toplev.h"
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. */
9a33a2e8 35static size_t num_compiler_params;
36
37/* Add the N PARAMS to the current list of compiler parameters. */
38
195731ad 39void
1a97be37 40add_params (const param_info params[], size_t n)
9a33a2e8 41{
42 /* Allocate enough space for the new parameters. */
4077bf7a 43 compiler_params = XRESIZEVEC (param_info, compiler_params,
44 num_compiler_params + n);
9a33a2e8 45 /* Copy them into the table. */
46 memcpy (compiler_params + num_compiler_params,
47 params,
48 n * sizeof (param_info));
49 /* Keep track of how many parameters we have. */
50 num_compiler_params += n;
51}
52
53/* Set the VALUE associated with the parameter given by NAME. */
54
55void
1a97be37 56set_param_value (const char *name, int value)
9a33a2e8 57{
58 size_t i;
59
60 /* Make sure nobody tries to set a parameter to an invalid value. */
876760f6 61 gcc_assert (value != INVALID_PARAM_VAL);
9a33a2e8 62
63 /* Scan the parameter table to find a matching entry. */
64 for (i = 0; i < num_compiler_params; ++i)
65 if (strcmp (compiler_params[i].option, name) == 0)
66 {
1d8a53f4 67 if (value < compiler_params[i].min_value)
68 error ("minimum value of parameter %qs is %u",
69 compiler_params[i].option,
70 compiler_params[i].min_value);
71 else if (compiler_params[i].max_value > compiler_params[i].min_value
72 && value > compiler_params[i].max_value)
73 error ("maximum value of parameter %qs is %u",
74 compiler_params[i].option,
75 compiler_params[i].max_value);
76 else
07804af5 77 {
78 compiler_params[i].value = value;
79 compiler_params[i].set = true;
80 }
9a33a2e8 81 return;
82 }
83
84 /* If we didn't find this parameter, issue an error message. */
eb586f2c 85 error ("invalid parameter %qs", name);
9a33a2e8 86}
c9036234 87
88/* Return the current value of num_compiler_params, for the benefit of
89 plugins that use parameters as features. */
90
91size_t
92get_num_compiler_params (void)
93{
94 return num_compiler_params;
95}