From Craig Silverstein: rework option handling to make it easier to

add a new option.
This commit is contained in:
Ian Lance Taylor 2008-03-04 23:10:38 +00:00
parent 3954eb47e1
commit ee1fe73e11
8 changed files with 1197 additions and 1679 deletions

View File

@ -112,7 +112,7 @@ Output_compressed_section::set_final_data_size()
this->write_to_postprocessing_buffer();
bool success = false;
if (this->options_->zlib_compress_debug_sections())
if (strcmp(this->options_->compress_debug_sections(), "zlib") == 0)
success = zlib_compress(uncompressed_data, uncompressed_size,
&this->data_, &compressed_size);
if (success)

View File

@ -36,6 +36,25 @@ const int DEBUG_SCRIPT = 2;
const int DEBUG_ALL = DEBUG_TASK | DEBUG_SCRIPT;
// Convert a debug string to the appropriate enum.
inline int
debug_string_to_enum(const char* arg)
{
static const struct { const char* name; int value; }
debug_options[] =
{
{ "task", DEBUG_TASK },
{ "script", DEBUG_SCRIPT },
{ "all", DEBUG_ALL }
};
int retval = 0;
for (size_t i = 0; i < sizeof(debug_options) / sizeof(*debug_options); ++i)
if (strstr(arg, debug_options[i].name))
retval |= debug_options[i].value;
return retval;
}
// Print a debug message if TYPE is enabled. This is a macro so that
// we only evaluate the arguments if necessary.

View File

@ -612,7 +612,7 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
{
Output_section* os;
if ((flags & elfcpp::SHF_ALLOC) == 0
&& this->options_.compress_debug_sections()
&& strcmp(this->options_.compress_debug_sections(), "none") != 0
&& is_compressible_debug_section(name))
os = new Output_compressed_section(&this->options_, name, type, flags);
else

View File

@ -149,7 +149,7 @@ main(int argc, char** argv)
// Handle the command line options.
Command_line command_line;
command_line.process(argc - 1, argv + 1);
command_line.process(argc - 1, const_cast<const char**>(argv + 1));
long start_time = 0;
if (command_line.options().stats())

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@
#include "gold.h"
#include "debug.h"
#include "options.h"
#include "target.h"
#include "target-select.h"
@ -41,8 +42,9 @@ Parameters::set_options(const General_options* options)
{
gold_assert(!this->options_valid());
this->options_ = options;
// For speed, we make our own copy of the debug variable.
this->debug_ = this->options().debug();
// For speed, we convert the options() debug var from a string to an
// enum (from debug.h).
this->debug_ = debug_string_to_enum(this->options().debug());
}
void

View File

@ -2131,7 +2131,7 @@ script_parse_option(void* closurev, const char* option, size_t length)
else
{
bool past_a_double_dash_option = false;
char* mutable_option = strndup(option, length);
const char* mutable_option = strndup(option, length);
gold_assert(mutable_option != NULL);
closure->command_line()->process_one_option(1, &mutable_option, 0,
&past_a_double_dash_option);