params.c revision 169689
152284Sobrien/* params.c - Run-time parameters.
290075Sobrien   Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
3117395Skan   Written by Mark Mitchell <mark@codesourcery.com>.
490075Sobrien
552284SobrienThis file is part of GCC.
6132718Skan
752284SobrienGCC is free software; you can redistribute it and/or modify it under
8132718Skanthe terms of the GNU General Public License as published by the Free
952284SobrienSoftware Foundation; either version 2, or (at your option) any later
1052284Sobrienversion.
1152284Sobrien
1252284SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
13132718SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or
1452284SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1552284Sobrienfor more details.
1652284Sobrien
1752284SobrienYou should have received a copy of the GNU General Public License
1852284Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
19132718SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20169689Skan02110-1301, USA.
21169689Skan
2252284Sobrien*/
23132718Skan
2452284Sobrien#include "config.h"
25132718Skan#include "system.h"
2690075Sobrien#include "coretypes.h"
2790075Sobrien#include "tm.h"
28132718Skan#include "params.h"
2990075Sobrien#include "toplev.h"
30132718Skan
31132718Skan/* An array containing the compiler parameters and their current
3290075Sobrien   values.  */
33132718Skan
3490075Sobrienparam_info *compiler_params;
3552284Sobrien
3690075Sobrien/* The number of entries in the table.  */
3790075Sobrien
38132718Skanstatic size_t num_compiler_params;
39132718Skan
4090075Sobrien/* Add the N PARAMS to the current list of compiler parameters.  */
4190075Sobrien
4290075Sobrienvoid
4352284Sobrienadd_params (const param_info params[], size_t n)
4452284Sobrien{
4552284Sobrien  /* Allocate enough space for the new parameters.  */
46132718Skan  compiler_params = xrealloc (compiler_params,
4752284Sobrien			      (num_compiler_params + n) * sizeof (param_info));
4890075Sobrien  /* Copy them into the table.  */
49132718Skan  memcpy (compiler_params + num_compiler_params,
50132718Skan	  params,
51132718Skan	  n * sizeof (param_info));
5252284Sobrien  /* Keep track of how many parameters we have.  */
5352284Sobrien  num_compiler_params += n;
5452284Sobrien}
5552284Sobrien
5652284Sobrien/* Set the VALUE associated with the parameter given by NAME.  */
5752284Sobrien
5852284Sobrienvoid
5952284Sobrienset_param_value (const char *name, int value)
6090075Sobrien{
6190075Sobrien  size_t i;
6290075Sobrien
6390075Sobrien  /* Make sure nobody tries to set a parameter to an invalid value.  */
6490075Sobrien  gcc_assert (value != INVALID_PARAM_VAL);
6590075Sobrien
6652284Sobrien  /* Scan the parameter table to find a matching entry.  */
67132718Skan  for (i = 0; i < num_compiler_params; ++i)
6890075Sobrien    if (strcmp (compiler_params[i].option, name) == 0)
6990075Sobrien      {
7090075Sobrien	if (value < compiler_params[i].min_value)
7190075Sobrien	  error ("minimum value of parameter %qs is %u",
7290075Sobrien		 compiler_params[i].option,
7390075Sobrien		 compiler_params[i].min_value);
7490075Sobrien	else if (compiler_params[i].max_value > compiler_params[i].min_value
7590075Sobrien		 && value > compiler_params[i].max_value)
76132718Skan	  error ("maximum value of parameter %qs is %u",
7752284Sobrien		 compiler_params[i].option,
78132718Skan		 compiler_params[i].max_value);
79132718Skan	else
80132718Skan	  compiler_params[i].value = value;
8152284Sobrien	return;
82132718Skan      }
83132718Skan
84132718Skan  /* If we didn't find this parameter, issue an error message.  */
85132718Skan  error ("invalid parameter %qs", name);
8652284Sobrien}
87132718Skan