ROSE Compiler Framework/How to add a ROSE commandline option
Often a feature added into ROSE comes with a set of command line options. These options can enable and customize the feature.
For example, the OpenMP support in ROSE is disabled by default. A special option is need to enable it. Also, the support can be as little as simply parsing the OpenMP directive or as complex as translating into multithreaded code.
This HOWTO quickly go through key steps to add options.
internal flags
editOptions need to be stored somewhere. There are several choices for the storage,
- as a data member of SgProject , if the optiona is applicable to all files associated with a SgProject
- as a data member of SgFile, if the option is applicable to a single source file, or
- a member variable in a namespace you define, if the option is for some transformation or analysis.
If the option can be as specific as per file, it is recommended to add a new data member to SgFile to save the option value.
For example, here is a command line option to turn on the UPC language support:
ROSE/src/ROSETTA/src/support.C // add a date member for SgFile
// Liao (6/6/2008): Support for UPC model of C , 6/19/2008: add support for static threads compilation File.setDataPrototype ( "bool", "UPC_only", "= false", NO_CONSTRUCTOR_PARAMETER, BUILD_ACCESS_FUNCTIONS, NO_TRAVERSAL, NO_DELETE);
ROSETTA process this information to automatically generate a member and the corresponding member access functions (set/get_member()).
process the option
editCommand line options should be handled within src/frontend/SageIII/sage_support/cmdline.cpp .
File level options are handled by void SgFile::processRoseCommandLineOptions ( vector<string> & argv )
Example code for processing the -rose:openmp option
set_openmp(false); ROSE_ASSERT (get_openmp() == false); ... if ( CommandlineProcessing::isOption(argv,"-rose:","(OpenMP|openmp)",true) == true ) { if ( SgProject::get_verbose() >= 1 ) printf ("OpenMP option specified \n"); set_openmp(true); //side effect for enabling OpenMP, define the macro as required argv.push_back("-D_OPENMP"); }
ROSE commandline options should be removed after being processed, to avoid confusing the backend compiler
SgFile::stripRoseCommandLineOptions ( vector<string>& argv ) should have the code to strip off the option.
use the option
editIn your code, you can use the automatically generated access functions to set/retrieve the stored option values.
For example
if (sourceFile->get_openmp()) //... do something here ....
document the option
editAny option should be explained by the online help output.
Please add brief help text for your option in void SgFile::usage ( int status ) of ./src/frontend/SageIII/sage_support/cmdline.cpp: