The system is designed so that a subclass can add additional command line options to the ones defined in a superclass.
The Module::_command_line is an *OptionList which is a class that keeps track of the options for the module.
To add command line parsing to your module, add your options to the Module::_command_line in the initialize() routine.
Here is an example of code for initialize
// This will add a required field "file-name"
Module::initialize();
_command_line -> set_description("description of the pass");
_file = new OptionString("file-name",&_file_name );
Option *file_option = (new OptionList())->add(_file);
_command_line->add(file_option);
// This will add an optional "-verbose" switch
Module::initialize();
_command_line -> set_description("description of the pass");
_verbose = new OptionLiteral("-verbose");
OptionSelection *opt = new OptionSelection(true);
opt->add(_verbose);
_command_line->add(opt);
// This will add a required "-bigendian" or "-littleendian" switch
Module::initialize();
_command_line -> set_description("description of the pass");
_bigend = new OptionLiteral("-bigendian");
_littleend = new OptionLiteral("-littleendian");
OptionLoop *opt = new OptionSelection();
opt->add(_bitend);
opt->add(_littleend);
_command_line->add(opt);
// This will add optional "-keep" and "-verbose" switches
Module::initialize();
_command_line -> set_description("description of the pass");
_keep = new OptionLiteral("-keep");
_verbose = new OptionLiteral("-verbose");
OptionSelect *select_opt = new OptionSelection();
select_opt->add(_keep);
select_opt->add(_verbose);
OptionLoop *loop_opt = new OptionLoop(select_opt);
_command_line->add(loop_opt);
A convenient function to create an option tree that matches a literal followed by a string.
E.g. "-I /usr/include".
param prefix - the literal string. param argument - the name of the string argument. param storage - the location to store the string argument. param description - the description of this compound option.
A convenient function to create an option tree that matches any set of strings.
e.g. "filename1 filename2 filename3"
param argument - the name of the string argument. param storage - the location to store the string arguments. param description - the description of this compound option.
written by Dimitri van Heesch, © 1997-1999