params.c revision 117395
190075Sobrien/* params.c - Run-time parameters.
290075Sobrien   Copyright (C) 2001 Free Software Foundation, Inc.
390075Sobrien   Written by Mark Mitchell <mark@codesourcery.com>.
490075Sobrien
590075SobrienThis file is part of GCC.
690075Sobrien
790075SobrienGCC is free software; you can redistribute it and/or modify it under
890075Sobrienthe terms of the GNU General Public License as published by the Free
990075SobrienSoftware Foundation; either version 2, or (at your option) any later
1090075Sobrienversion.
1190075Sobrien
1290075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1490075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1590075Sobrienfor more details.
1690075Sobrien
1790075SobrienYou should have received a copy of the GNU General Public License
1890075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
1990075SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
2090075Sobrien02111-1307, USA.
2190075Sobrien
2290075Sobrien*/
2390075Sobrien
2490075Sobrien#include "config.h"
2590075Sobrien#include "system.h"
2690075Sobrien#include "params.h"
2790075Sobrien#include "toplev.h"
2890075Sobrien
2990075Sobrien/* An array containing the compiler parameters and their current
3090075Sobrien   values.  */
3190075Sobrien
3290075Sobrienparam_info *compiler_params;
3390075Sobrien
3490075Sobrien/* The number of entries in the table.  */
3590075Sobrien
3690075Sobrienstatic size_t num_compiler_params;
3790075Sobrien
3890075Sobrien/* Add the N PARAMS to the current list of compiler parameters.  */
3990075Sobrien
40117395Skanvoid
4190075Sobrienadd_params (params, n)
4290075Sobrien     const param_info params[];
4390075Sobrien     size_t n;
4490075Sobrien{
4590075Sobrien  /* Allocate enough space for the new parameters.  */
46117395Skan  compiler_params =
47117395Skan    ((param_info *)
4890075Sobrien     xrealloc (compiler_params,
4990075Sobrien	       (num_compiler_params + n) * sizeof (param_info)));
5090075Sobrien  /* Copy them into the table.  */
5190075Sobrien  memcpy (compiler_params + num_compiler_params,
5290075Sobrien	  params,
5390075Sobrien	  n * sizeof (param_info));
5490075Sobrien  /* Keep track of how many parameters we have.  */
5590075Sobrien  num_compiler_params += n;
5690075Sobrien}
5790075Sobrien
5890075Sobrien/* Set the VALUE associated with the parameter given by NAME.  */
5990075Sobrien
6090075Sobrienvoid
6190075Sobrienset_param_value (name, value)
6290075Sobrien     const char *name;
6390075Sobrien     int value;
6490075Sobrien{
6590075Sobrien  size_t i;
6690075Sobrien
6790075Sobrien  /* Make sure nobody tries to set a parameter to an invalid value.  */
6890075Sobrien  if (value == INVALID_PARAM_VAL)
6990075Sobrien    abort ();
7090075Sobrien
7190075Sobrien  /* Scan the parameter table to find a matching entry.  */
7290075Sobrien  for (i = 0; i < num_compiler_params; ++i)
7390075Sobrien    if (strcmp (compiler_params[i].option, name) == 0)
7490075Sobrien      {
7590075Sobrien	compiler_params[i].value = value;
7690075Sobrien	return;
7790075Sobrien      }
7890075Sobrien
7990075Sobrien  /* If we didn't find this parameter, issue an error message.  */
8090075Sobrien  error ("invalid parameter `%s'", name);
8190075Sobrien}
82