// New version of command line processing using Sawyer library static std::vector<std::string> commandline_processing(std::vector< std::string > & argvList) { using namespace Sawyer::CommandLine; Parser p = CommandlineProcessing::createEmptyParserStage(purpose, description); p.doc("Synopsis", "@prop{programName} @v{switches} @v{files}..."); p.longPrefix("-"); // initialize generic Sawyer switches: assertion, logging, threads, etc. p.with(CommandlineProcessing::genericSwitches()); // initialize this tool's switches p.with(commandLineSwitches()); // --rose:help for more ROSE switches SwitchGroup tool("ROSE builtin switches"); bool showRoseHelp = false; tool.insert(Switch("rose:help") .longPrefix("-") .intrinsicValue(true, showRoseHelp) .doc("Show the old-style ROSE help.")); p.with(tool); std::vector<std::string> remainingArgs = p.parse(argvList).apply().unparsedArgs(true); // add back -annot file TODO: how about multiple appearances? for (size_t i=0; i<AutoParallelization::annot_filenames.size(); i++) { remainingArgs.push_back("-annot"); remainingArgs.push_back(AutoParallelization::annot_filenames[i]); } if (AutoParallelization::keep_going) remainingArgs.push_back("-rose:keep_going"); // AFTER parse the command-line, you can do this: if (showRoseHelp) SgFile::usage(0); // work with the parser of the ArrayAbstraction module //Read in annotation files after -annot CmdOptions::GetInstance()->SetOptions(remainingArgs); ArrayAnnotation* annot = ArrayAnnotation::get_inst(); annot->register_annot(); ReadAnnotation::get_inst()->read(); if (AutoParallelization::dump_annot_file) annot->Dump(); //Strip off custom options and their values to enable backend compiler CommandlineProcessing::removeArgsWithParameters(remainingArgs,"-annot"); #if 0 // DEBUGGING [Robb P Matzke 2016-09-27] std::cerr <<"These are the arguments after parsing with Sawyer:\n"; BOOST_FOREACH (const std::string &s, remainingArgs) std::cerr <<" \"" <<s <<"\"\n"; #endif return remainingArgs; }
// Modified from AutoParallelization project void UpcLibrary::processOptions(vector<string> &argvList){ if(CommandlineProcessing::isOption(argvList, "", "-debug", true)){ cout << "Enabling debugging..." << endl; debug = true; } if(CommandlineProcessing::isOption(argvList, "", "-phase2", true)){ cout << "Skipping Phase I..." << endl; phase2_only = true; } //Save -debugdep, -annot file .. etc, // used internally in ReadAnnotation and Loop transformation CmdOptions::GetInstance()->SetOptions(argvList); bool dumpAnnot = CommandlineProcessing::isOption(argvList,"","-dumpannot",true); //Read in annotation files after -annot ArrayAnnotation* annot = ArrayAnnotation::get_inst(); annot->register_annot(); ReadAnnotation::get_inst()->read(); if (dumpAnnot) annot->Dump(); //Strip off custom options and their values to enable backend compiler CommandlineProcessing::removeArgsWithParameters(argvList,"-annot"); // keep --help option after processing, let other modules respond also if ((CommandlineProcessing::isOption (argvList,"--help","",false)) || (CommandlineProcessing::isOption (argvList,"-help","",false))) { cout << "upctr-specific options" << endl; cout << "\t-debug print debug info" << endl; cout << "\t-phase2 run only phase II (dependence analysis)" << endl; cout << "\t-annot filename specify annotation file for semantics of abstractions" << endl; cout << "\t-dumpannot dump annotation file content" << endl; cout << "---------------------------------------------------------------" << endl; } }
//============================================================================== int main (int argc, char** argv) { // Build the AST used by ROSE vector <string> argvList (argv, argv + argc); if (CommandlineProcessing::isOption(argvList,"-help","", false)) { cout<<"---------------------Tool-Specific Help-----------------------------------"<<endl; cout<<"This is a source analysis to estimate FLOPS and Load/store bytes for loops in your C/C++ or Fortran code."<<endl; cout<<"Usage: "<<argvList[0]<<" -c ["<<report_option<<" result.txt] "<< "input.c"<<endl; cout<<endl; cout<<"The optional "<<report_option<<" option is provided for users to specify where to save the results"<<endl; cout<<"By default, the results will be saved into a file named report.txt"<<endl; cout<<"----------------------Generic Help for ROSE tools--------------------------"<<endl; } if (CommandlineProcessing::isOption(argvList,"-static-counting-only","", true)) { running_mode = e_static_counting; } if (CommandlineProcessing::isOption(argvList,"-debug","", true)) { debug = true; } else debug = false; if (CommandlineProcessing::isOptionWithParameter (argvList, report_option,"", report_filename,true)) { if (debug) cout<<"Using user specified file: "<<report_filename<<" for storing results."<<endl; } else { //report_filename="ai_tool_report.txt"; // this is set in src/ai_measurement.cpp already if (debug) cout<<"Using the default file:"<<report_filename<<" for storing results."<<endl; } //Save -debugdep, -annot file .. etc, // used internally in ReadAnnotation and Loop transformation CmdOptions::GetInstance()->SetOptions(argvList); bool dumpAnnot = CommandlineProcessing::isOption(argvList,"","-dumpannot",true); //Read in annotation files after -annot ArrayAnnotation* annot = ArrayAnnotation::get_inst(); annot->register_annot(); ReadAnnotation::get_inst()->read(); if (dumpAnnot) annot->Dump(); //Strip off custom options and their values to enable backend compiler CommandlineProcessing::removeArgsWithParameters(argvList,"-annot"); SgProject* project = frontend(argvList); // Insert your own manipulations of the AST here... SgFilePtrList file_ptr_list = project->get_fileList(); //visitorTraversal exampleTraversal; for (size_t i = 0; i<file_ptr_list.size(); i++) { SgFile* cur_file = file_ptr_list[i]; SgSourceFile* s_file = isSgSourceFile(cur_file); if (s_file != NULL) { // Preorder is not friendly for transformation //exampleTraversal.traverseWithinFile(s_file, postorder); Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(s_file,V_SgStatement); if (running_mode == e_analysis_and_instrument) // reverse of pre-order for transformation mode { for (Rose_STL_Container<SgNode *>::reverse_iterator i = nodeList.rbegin(); i != nodeList.rend(); i++) { SgStatement *stmt= isSgStatement(*i); processStatements (stmt); } } else if (running_mode == e_static_counting) // pre-order traverse for analysis only mode { for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++) { SgStatement *stmt= isSgStatement(*i); processStatements (stmt); } } else { cerr<<"Error. unrecognized execution mode:"<< running_mode<<endl; ROSE_ASSERT (false); } } // endif } // end for // Generate source code from AST and invoke your // desired backend compiler return backend(project); }
bool ArrayInterface :: may_alias(AstInterface& _fa, const AstNodePtr& r1, const AstNodePtr& r2) { CPPAstInterface& fa = static_cast<CPPAstInterface&>(_fa); AstNodePtr array1, array2; ArrayAnnotation* annot = ArrayAnnotation::get_inst(); bool elem1 = annot->is_access_array_elem( fa, r1, &array1) ; bool len1 = annot->is_access_array_length( fa, r1, &array1); bool elem2 = annot->is_access_array_elem( fa, r2, &array2); bool len2 = annot->is_access_array_length( fa, r2, &array2); if ( (elem1 && len2) || (len1 && elem2)) { return false; } else if ( (elem1 && elem2) || (len1 && len2)) { if (may_alias(fa, array1, array2)) { if (DebugAliasAnal()) std::cerr << "has alias between " << AstInterface::AstToString(r1) << " and " << AstInterface::AstToString(r2) << std::endl; return true; } } else if (elem1 || len1) { if (may_alias(fa, array1, r2)) { if (DebugAliasAnal()) std::cerr << "has alias between " << AstInterface::AstToString(r1) << " and " << AstInterface::AstToString(r2) << std::endl; return true; } } else if (elem2 || len2) { if (may_alias(fa, r1, array2)) { if (DebugAliasAnal()) std::cerr << "has alias between " << AstInterface::AstToString(r1) << " and " << AstInterface::AstToString(r2) << std::endl; return true; } } else { AstInterface::AstNodeList args; if (annot->is_array_construct_op( fa, r1, &args)) { for (AstInterface::AstNodeList::iterator p = args.begin(); p != args.end(); ++p) { AstNodePtr cur = *p; if (may_alias( fa, cur, r2)) { if (DebugAliasAnal()) std::cerr << "has alias between " << AstInterface::AstToString(r1) << " and " << AstInterface::AstToString(r2) << std::endl; return true; } } return false; } else if (annot->is_array_construct_op( fa, r2, &args)) { for (AstInterface::AstNodeList::iterator p = args.begin(); p != args.end(); ++p) { AstNodePtr cur = *p; if (may_alias( fa, cur, r1)) { if (DebugAliasAnal()) std::cerr << "has alias between " << AstInterface::AstToString(r1) << " and " << AstInterface::AstToString(r2) << std::endl; return true; } } return false; } return aliasCollect.may_alias( fa, r1, r2); } return false; }