190075Sobrien/* params.c - Run-time parameters. 2169689Skan Copyright (C) 2001, 2003, 2004, 2005 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 19169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 20169689Skan02110-1301, USA. 2190075Sobrien 2290075Sobrien*/ 2390075Sobrien 2490075Sobrien#include "config.h" 2590075Sobrien#include "system.h" 26132718Skan#include "coretypes.h" 27132718Skan#include "tm.h" 2890075Sobrien#include "params.h" 2990075Sobrien#include "toplev.h" 3090075Sobrien 3190075Sobrien/* An array containing the compiler parameters and their current 3290075Sobrien values. */ 3390075Sobrien 3490075Sobrienparam_info *compiler_params; 3590075Sobrien 3690075Sobrien/* The number of entries in the table. */ 3790075Sobrien 3890075Sobrienstatic size_t num_compiler_params; 3990075Sobrien 4090075Sobrien/* Add the N PARAMS to the current list of compiler parameters. */ 4190075Sobrien 42117395Skanvoid 43132718Skanadd_params (const param_info params[], size_t n) 4490075Sobrien{ 4590075Sobrien /* Allocate enough space for the new parameters. */ 46132718Skan compiler_params = xrealloc (compiler_params, 47132718Skan (num_compiler_params + n) * sizeof (param_info)); 4890075Sobrien /* Copy them into the table. */ 4990075Sobrien memcpy (compiler_params + num_compiler_params, 5090075Sobrien params, 5190075Sobrien n * sizeof (param_info)); 5290075Sobrien /* Keep track of how many parameters we have. */ 5390075Sobrien num_compiler_params += n; 5490075Sobrien} 5590075Sobrien 5690075Sobrien/* Set the VALUE associated with the parameter given by NAME. */ 5790075Sobrien 5890075Sobrienvoid 59132718Skanset_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. */ 64169689Skan gcc_assert (value != INVALID_PARAM_VAL); 6590075Sobrien 6690075Sobrien /* Scan the parameter table to find a matching entry. */ 6790075Sobrien for (i = 0; i < num_compiler_params; ++i) 6890075Sobrien if (strcmp (compiler_params[i].option, name) == 0) 6990075Sobrien { 70169689Skan if (value < compiler_params[i].min_value) 71169689Skan error ("minimum value of parameter %qs is %u", 72169689Skan compiler_params[i].option, 73169689Skan compiler_params[i].min_value); 74169689Skan else if (compiler_params[i].max_value > compiler_params[i].min_value 75169689Skan && value > compiler_params[i].max_value) 76169689Skan error ("maximum value of parameter %qs is %u", 77169689Skan compiler_params[i].option, 78169689Skan compiler_params[i].max_value); 79169689Skan else 80169689Skan compiler_params[i].value = value; 8190075Sobrien return; 8290075Sobrien } 8390075Sobrien 8490075Sobrien /* If we didn't find this parameter, issue an error message. */ 85169689Skan error ("invalid parameter %qs", name); 8690075Sobrien} 87