void CudaOutliner::functionParameterHandling(ASTtools::VarSymSet_t& syms, // regular (shared) parameters MintHostSymToDevInitMap_t hostToDevVars, const ASTtools::VarSymSet_t& pdSyms, // those must use pointer dereference const ASTtools::VarSymSet_t& pSyms, // private variables, handles dead variables (neither livein nor liveout) std::set<SgInitializedName*> & readOnlyVars, std::set<SgInitializedName*> & liveOutVars, SgFunctionDeclaration* func) // the outlined function { //ASTtools::VarSymSet_t syms; //std::copy(syms1.begin(), syms1.end(), std::inserter(syms,syms.begin())); VarSymRemap_t sym_remap; // variable remapping for regular(shared) variables VarSymRemap_t private_remap; // variable remapping for private/firstprivate/reduction variables ROSE_ASSERT (func); SgFunctionParameterList* params = func->get_parameterList (); ROSE_ASSERT (params); SgFunctionDefinition* def = func->get_definition (); ROSE_ASSERT (def); SgBasicBlock* body = def->get_body (); ROSE_ASSERT (body); // Place in which to put new outlined variable symbols. SgScopeStatement* args_scope = isSgScopeStatement (body); ROSE_ASSERT (args_scope); // For each variable symbol, create an equivalent function parameter. // Also create unpacking and repacking statements. int counter=0; // SgInitializedName* parameter1=NULL; // the wrapper parameter SgVariableDeclaration* local_var_decl = NULL; // handle OpenMP private variables/ or those which are neither live-in or live-out handlePrivateVariables(pSyms, body, private_remap); // -------------------------------------------------- // for each parameters passed to the outlined function // They include parameters for regular shared variables and // also the shared copies for firstprivate and reduction variables for (ASTtools::VarSymSet_t::reverse_iterator i = syms.rbegin ();i != syms.rend (); ++i) { // Basic information about the variable to be passed into the outlined function // Variable symbol name const SgInitializedName* i_name = (*i)->get_declaration (); ROSE_ASSERT (i_name); string name_str = i_name->get_name ().str (); SgName p_sg_name ( name_str); //SgType* i_type = i_name->get_type (); bool readOnly = false; if (readOnlyVars.find(const_cast<SgInitializedName*> (i_name)) != readOnlyVars.end()) readOnly = true; // step 1. Create parameters and insert it into the parameter list. // ---------------------------------------- SgInitializedName* p_init_name = NULL; SgVariableSymbol* host_sym= const_cast<SgVariableSymbol*> (*i); if(hostToDevVars.find(host_sym) != hostToDevVars.end() ){ //these are vector variables SgInitializedName* dev_name = hostToDevVars[host_sym]; p_init_name = createInitName (dev_name->get_name(), dev_name->get_type(), func, def); ROSE_ASSERT (p_init_name); prependArg(func->get_parameterList (),p_init_name); } else{ //scalar values p_init_name = createOneFunctionParameter(i_name, readOnly, func); } // step 2. Create unpacking/unwrapping statements, also record variables to be replaced // ---------------------------------------- // bool isPointerDeref = false; if (Outliner::enable_classic) { // classic methods use parameters directly, no unpacking is needed if (!readOnly) //read only variable should not have local variable declaration, using parameter directly // taking advantage of the same parameter names for readOnly variables // Let postprocessing to patch up symbols for them { // non-readonly variables need to be mapped to their parameters with different names (p__) // remapVarSyms() will use pointer dereferencing for all of them by default in C, // this is enough to mimic the classic outlining work //handleSharedVariables(*i, p_init_name, args_scope, sym_remap); //handleSharedVariables(*i, body, sym_remap); //Didem: I comment out this part because it uses pointer deferencing for all non-readonly variables. //recordSymRemap(*i,p_init_name, args_scope, sym_remap); } } else { local_var_decl = NULL; //createUnpackDecl (p_init_name, counter, isPointerDeref, i_name , NULL, body); ROSE_ASSERT (local_var_decl); prependStatement (local_var_decl,body); // regular and shared variables used the first local declaration recordSymRemap (*i, local_var_decl, args_scope, sym_remap); // transfer the value for firstprivate variables. } // step 3. Create and insert companion re-pack statement in the end of the function body // If necessary // ---------------------------------------- SgInitializedName* local_var_init = NULL; if (local_var_decl != NULL ) local_var_init = local_var_decl->get_decl_item (SgName (name_str.c_str ())); if (!SageInterface::is_Fortran_language() && !Outliner::enable_classic) ROSE_ASSERT(local_var_init!=NULL); SgExprStatement* pack_stmt = createPackStmt (local_var_init); if (pack_stmt) appendStatement (pack_stmt,body); counter ++; } //end for // variable substitution SgBasicBlock* func_body = func->get_definition()->get_body(); remapVarSyms (sym_remap, pdSyms, private_remap , func_body); }
// schroder3 (2016-07-12): Returns the mangled stable/portable scope of the given statement. // FIXME: There are some places (see comment below) in the rose mangling which add the address // of the AST node to the mangled name. Due to this, this function currently does not return // a stable/portable mangled scope in all cases. string getScopeAsMangledStableString(SgLocatedNode* stmt) { SgNode* parent = stmt; // Go up in the AST and look for the closest scope of the given statement: while((parent = parent->get_parent())) { SgStatement* declScope = 0; // Look for a FunctionParameterList or a ScopeStatement: if(SgFunctionParameterList* functionParams = isSgFunctionParameterList(parent)) { // Special case: Function parameter: The scope is // the corresponding function definition/declaration: // Function declaration is enough, because we only need the function // name and types to create the mangled scope. declScope = isSgFunctionDeclaration(functionParams->get_parent()); ROSE_ASSERT(declScope); } else if(SgScopeStatement* scope = isSgScopeStatement(parent)) { declScope = scope; } if(declScope) { // Found the scope of the given statement. // In theory it should work by using // return mangleQualifiersToString(declScope); // but there are the following problems in functions that get called by mangleQualifiersToString(...): // 1) SgFunctionDeclaration::get_mangled_name() mangles every function with the name "main" (even // those that are not in the global scope) as // main_<address of the AST node> // . // 2) SgTemplateArgument::get_mangled_name(...) adds the address of a AST node to the mangled // name if the template argument is a type and it's parent is a SgTemplateInstantiationDecl. // Especially because of the address we can not use this as a portable scope representation. // // Workaround for 1): Replace the name of every function definition/declaration that has the name "main" and that // is a direct or indirect scope parent of declScope by a temporary name that is different from "main". // Then use mangleQualifiersToString(...) to mangle the scope. Finally, replace occurrences of the // temporary name in the mangled-scope by "main". // // Workaround for 2): Currently none. // Workaround for 1): string tempName = string("(]"); // Something that does not appear in a function or operator name. SgName tempSgName = SgName(tempName); SgName mainSgName = SgName("main"); vector<SgFunctionDeclaration*> main_func_decls; SgStatement* scopeParent = declScope; // Collect all functions that have "main" as their name and replace their name // by the temporary name: while((scopeParent = scopeParent->get_scope()) && !isSgGlobal(scopeParent)) { SgFunctionDefinition* funcDef = isSgFunctionDefinition(scopeParent); if(SgFunctionDeclaration* funcDecl = funcDef ? funcDef->get_declaration() :0) { if(funcDecl->get_name() == tempSgName) { // There is a function whose name contains tempName. The mangled scope // will probably be wrong: throw SPRAY::Exception("Found function whose name contains the reserved text \"" + tempName + "\". " "Mangling of scope is not possible."); } else if(funcDecl->get_name() == mainSgName) { main_func_decls.push_back(funcDecl); funcDecl->set_name(tempSgName); } } } // Create the mangled-scope: string mangled_scope; if(SgFunctionDeclaration* fundDecl = isSgFunctionDeclaration(declScope)) { // Special case: A function decl node is not a scope statement: mangled_scope = fundDecl->get_mangled_name(); } else if(SgScopeStatement* scope = isSgScopeStatement(declScope)) { mangled_scope = mangleQualifiersToString(scope); } else { ROSE_ASSERT(false); } // Replace occurrences of the temporary name in the mangled-scope // by "main" and restore the previous name ("main") of the functions: for(vector<SgFunctionDeclaration*>::const_iterator i = main_func_decls.begin(); i != main_func_decls.end(); ++i ) { (*i)->set_name(mainSgName); size_t start = mangled_scope.find(tempName); // TODO: Functions and local classes (and more?) are mangled as L0R, L1R, ... and not with their // scope. Because of that, there is no corresponding temporary name in // the mangled-scope sometimes: if(start != string::npos) { mangled_scope.replace(start, tempName.length(), string("main")); } } if(mangled_scope.find(tempName) != string::npos) { // There is a function whose name contains tempName. Because we abort above if there is such a function // this should not happen. ROSE_ASSERT(false); } return mangled_scope; } } return string(""); }
int main (int argc, char *argv[]) { vector<string> argvList(argv, argv+argc); //Processing debugging and annotation options // autopar_command_processing(argvList); argvList = commandline_processing (argvList); // enable parsing user-defined pragma if enable_diff is true // -rose:openmp:parse_only if (enable_diff) argvList.push_back("-rose:openmp:parse_only"); SgProject *project = frontend (argvList); ROSE_ASSERT (project != NULL); // register midend signal handling function if (KEEP_GOING_CAUGHT_MIDEND_SIGNAL) { std::cout << "[WARN] " << "Configured to keep going after catching a " << "signal in AutoPar" << std::endl; Rose::KeepGoing::setMidendErrorCode (project, 100); goto label_end; } // create a block to avoid jump crosses initialization of candidateFuncDefs etc. { std::vector<SgFunctionDefinition* > candidateFuncDefs; findCandidateFunctionDefinitions (project, candidateFuncDefs); normalizeLoops (candidateFuncDefs); //Prepare liveness analysis etc. //Too much output for analysis debugging info. //initialize_analysis (project,enable_debug); initialize_analysis (project, false); // This is a bit redundant with findCandidateFunctionDefinitions () // But we do need the per file control to decide if omp.h is needed for each file // // For each source file in the project SgFilePtrList & ptr_list = project->get_fileList(); for (SgFilePtrList::iterator iter = ptr_list.begin(); iter!=ptr_list.end(); iter++) { SgFile* sageFile = (*iter); SgSourceFile * sfile = isSgSourceFile(sageFile); ROSE_ASSERT(sfile); SgGlobal *root = sfile->get_globalScope(); Rose_STL_Container<SgNode*> defList = NodeQuery::querySubTree(sfile, V_SgFunctionDefinition); bool hasOpenMP= false; // flag to indicate if omp.h is needed in this file //For each function body in the scope //for (SgDeclarationStatementPtrList::iterator p = declList.begin(); p != declList.end(); ++p) for (Rose_STL_Container<SgNode*>::iterator p = defList.begin(); p != defList.end(); ++p) { // cout<<"\t loop at:"<< cur_loop->get_file_info()->get_line() <<endl; SgFunctionDefinition *defn = isSgFunctionDefinition(*p); ROSE_ASSERT (defn != NULL); SgFunctionDeclaration *func = defn->get_declaration(); ROSE_ASSERT (func != NULL); //ignore functions in system headers, Can keep them to test robustness if (defn->get_file_info()->get_filename()!=sageFile->get_file_info()->get_filename()) { continue; } SgBasicBlock *body = defn->get_body(); // For each loop Rose_STL_Container<SgNode*> loops = NodeQuery::querySubTree(defn,V_SgForStatement); if (loops.size()==0) { if (enable_debug) cout<<"\t skipped since no for loops are found in this function"<<endl; continue; } #if 0 // Moved to be executed before running liveness analysis. // normalize C99 style for (int i= x, ...) to C89 style: int i; (i=x, ...) // Liao, 10/22/2009. Thank Jeff Keasler for spotting this bug for (Rose_STL_Container<SgNode*>::iterator iter = loops.begin(); iter!= loops.end(); iter++ ) { SgForStatement* cur_loop = isSgForStatement(*iter); ROSE_ASSERT(cur_loop); SageInterface::normalizeForLoopInitDeclaration(cur_loop); } #endif // X. Replace operators with their equivalent counterparts defined // in "inline" annotations AstInterfaceImpl faImpl_1(body); CPPAstInterface fa_body(&faImpl_1); OperatorInlineRewrite()( fa_body, AstNodePtrImpl(body)); // Pass annotations to arrayInterface and use them to collect // alias info. function info etc. ArrayAnnotation* annot = ArrayAnnotation::get_inst(); ArrayInterface array_interface(*annot); array_interface.initialize(fa_body, AstNodePtrImpl(defn)); array_interface.observe(fa_body); //FR(06/07/2011): aliasinfo was not set which caused segfault LoopTransformInterface::set_aliasInfo(&array_interface); for (Rose_STL_Container<SgNode*>::iterator iter = loops.begin(); iter!= loops.end(); iter++ ) { SgNode* current_loop = *iter; if (enable_debug) { SgForStatement * fl = isSgForStatement(current_loop); cout<<"\t\t Considering loop at "<< fl->get_file_info()->get_line()<<endl; } //X. Parallelize loop one by one // getLoopInvariant() will actually check if the loop has canonical forms // which can be handled by dependence analysis SgInitializedName* invarname = getLoopInvariant(current_loop); if (invarname != NULL) { bool ret = ParallelizeOutermostLoop(current_loop, &array_interface, annot); if (ret) // if at least one loop is parallelized, we set hasOpenMP to be true for the entire file. hasOpenMP = true; } else // cannot grab loop index from a non-conforming loop, skip parallelization { if (enable_debug) cout<<"Skipping a non-canonical loop at line:"<<current_loop->get_file_info()->get_line()<<"..."<<endl; // We should not reset it to false. The last loop may not be parallelizable. But a previous one may be. //hasOpenMP = false; } }// end for loops } // end for-loop for declarations // insert omp.h if needed if (hasOpenMP && !enable_diff) { SageInterface::insertHeader("omp.h",PreprocessingInfo::after,false,root); if (enable_patch) generatePatchFile(sfile); } // compare user-defined and compiler-generated OmpAttributes if (enable_diff) diffUserDefinedAndCompilerGeneratedOpenMP(sfile); } //end for-loop of files #if 1 // undo loop normalization std::map <SgForStatement* , bool >::iterator iter = trans_records.forLoopInitNormalizationTable.begin(); for (; iter!= trans_records.forLoopInitNormalizationTable.end(); iter ++) { SgForStatement* for_loop = (*iter).first; unnormalizeForLoopInitDeclaration (for_loop); } #endif // Qing's loop normalization is not robust enough to pass all tests //AstTests::runAllTests(project); // clean up resources for analyses release_analysis(); } label_end: // Report errors if (keep_going) { std::vector<std::string> orig_rose_cmdline(argv, argv+argc); Rose::KeepGoing::generate_reports (project, orig_rose_cmdline); } //project->unparse(); return backend (project); }
int main(int argc,char ** argv) { SgProject *project = frontend(argc, argv); VisPromelaAST * debugPromelaAst=new VisPromelaAST(project); cout <<"reverting mpi"<<endl; revertMPIDefinitions(project); announceStep(1,0,"Identify modelchecking targets"); //! step1: Identify modelchecking targets PromelaMarker initialMarker; initialMarker.traverse(project, preorder); debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.inital_marking.dot"); // since the next step is creating a slice, we must identify all statements which are modelchekcing targets so that we have a valid slice SlicingInfo si=SlicingInfo(); // it might be better to use the AST-Attributes as a method for containing this information, but right now the pragma is sufficient si.setSliceTargetString(string("SPIN_TARGET")); si.traverse(project, preorder); announceStep(2,0,"Create abstractions using sdg and other means"); // create the sdg SystemDependenceGraph * sdg=new SystemDependenceGraph(); sdg->parseProject(project); //TODO: at this point one would implement abstractions, because they alter the code in such a way, that slicing might be able to remove additional statements, which otherwihse would not be removed announceStep(3,0,"Slice program to reduce state-space and\n\t eliminate dead code from abstractions"); //! Step2: Slice program to reduce towards abstraction and goal // create the set of nodes, that are in the slice, in terms of the sdg CreateSliceSet sliceSet(sdg,si.getSlicingTargets()); // using the set of statements that are within the slice construct an unnamed CreateSlice-class and slice the project CreateSlice(sliceSet.computeSliceSet()).traverse(project); // since now the ast is substantially different from the previouse version the sdg is not valid anymore delete(sdg); //DEVEL: output the sliced statement-graph debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.sliced.dot"); //DEVEL: run-ast-consistancy-test to enshure a valid ast AstTests::runAllTests(project); announceStep(4,1,"Perform sanity-check for non-transformable code like scanf and parameterinput argc and argv"); //TODO: implement the sanitiy-checks announceStep(4,2,"Identify Process and Thread functions and mark them as PROMELA-Procs"); // find process functions,like main and thread-functions. // For this version of the transformation only main is valid, // but later on threadfunctions might also work. Therefore the // a vector is used to store the main function vector<SgFunctionDefinition*> procFuncVec=findProcessFunctions(project); // mark those function declarations,definitions and main-basic block to enshure proper promela-output for (int i=0;i<procFuncVec.size();i++) { cout <<"\t*marking function for promela-output: "<<procFuncVec[i]->get_declaration()->get_name().getString()<<endl; // mark the function body for transformation markForPromelaTransformation(procFuncVec[i]); // force the first SgBasicBlock to be converted to promela!!!!! markForPromelaTransformation(procFuncVec[i]->get_body () ); //CI (04/16/2007): This is currently not necessary if (isSgFile(procFuncVec[i]->get_parent()->get_parent()->get_parent())) { cout <<"marking file"<<endl; markForPromelaTransformation(procFuncVec[i]->get_parent()->get_parent()->get_parent()); } } announceStep(4,3,"Identify functions using global variables and add them to the inlining list"); vector<SgVariableDeclaration *> globalVarDeclVec; vector<SgFunctionDefinition *> functionsToInline; std::map<SgNode*,bool> functionToInlineMap; //TODO: search in each functions for uses of a global variable, if the function contains a use, mark it and continue with the next function list<SgNode*> sgGlobalList=NodeQuery::querySubTree(project,V_SgGlobal); for (list<SgNode*>::iterator sgGlobalIt=sgGlobalList.begin();sgGlobalIt!=sgGlobalList.end();sgGlobalIt++) { // iterate over this scope without recursing and find all variabledeclarations ... SgDeclarationStatementPtrList globalDeclList=isSgGlobal(*sgGlobalIt)->get_declarations (); for (SgDeclarationStatementPtrList::iterator it=globalDeclList.begin();it!=globalDeclList.end();it++) { if (isSgVariableDeclaration(*it)) { cout <<"\t\t*found VarDecl:"<<(*it)->unparseToString()<<endl; //TODO: check if its from a header and if it is used.. globalVarDeclVec.push_back(isSgVariableDeclaration(*it)); } } } // remove MPI-Symbols form the globals vector<SgVariableDeclaration *> globalVarDeclVecTmp; for (int i=0;i<globalVarDeclVec.size();i++) { // if the current declaration is an mpi declaration, remove it from the global list (it is from a header, and will be directly supported in spin if (isNodeMPI(globalVarDeclVec[i])) { cout<<"\t\t* found an MPI-Var-Decl, ignoring"<<endl; } else { globalVarDeclVecTmp.push_back(globalVarDeclVec[i]); } } globalVarDeclVec=globalVarDeclVecTmp; // now that we have a list of all global declarations, find their uses list<SgNode*> functionList=NodeQuery::querySubTree(project,V_SgFunctionDefinition); for (list<SgNode*>::iterator fIt=functionList.begin();fIt!=functionList.end();fIt++) { //check if the function is main, .. kind of silly to inline main... if (isSgFunctionDefinition(*fIt)->get_declaration()->get_name().getString()=="main") continue; // search the function for globals list<SgNode*> sgVarRefList=NodeQuery::querySubTree(*fIt,V_SgVarRefExp); for (list<SgNode*>::iterator it=sgVarRefList.begin();sgVarRefList.end()!=it;it++) { // // get the declaration and then if the declaration is of global scope -> it is a global if (isSgFunctionParameterList(isSgVarRefExp(*it)->get_symbol () ->get_declaration ()->get_declaration())) continue; if (isSgVarRefExp(*it)->get_symbol () ->get_declaration ()->get_declaration()==NULL) // is an initialized name form the function.parameter.list continue; SgNode * tmp=(*it); while(!isSgStatement(tmp) && !isSgGlobal(tmp)) tmp=tmp->get_parent(); // cout <<"\t\tParentStmt: "<<tmp->unparseToString()<<endl; // cout <<"\t\tdebug:"<<(*it)->unparseToString()<<endl; // cout <<"\t\tclass:"<<isSgVarRefExp(*it)->get_symbol () ->get_declaration ()->get_declaration()->class_name()<<endl; SgVariableDeclaration *decl=isSgVariableDeclaration(isSgVarRefExp(*it)->get_symbol () ->get_declaration ()->get_declaration()); assert(decl!=NULL); // cout <<"\t\t*decl: "<<decl->unparseToString()<<endl; if (isSgGlobal(decl->get_parent())) // is a global scope -> global { // we have a global, add the function to the list and break functionsToInline.push_back(isSgFunctionDefinition(*fIt)); functionToInlineMap[isSgFunctionDefinition(*fIt)]=true; cout <<"\t\t*Found use of Global <"<<decl->get_definition()->get_vardefn ()->get_name ().getString()<<"> in "<<isSgFunctionDefinition(*fIt)->get_declaration()->get_name().getString()<<", -> added to inline list"<<endl; break; } } } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step4_3.dot"); announceStep(4,4,"Identify function called by proc-functions that contain modelchecking critical code"); // a function that contains modelchecking code is marked as a promela-target after PropagatePromelaTargetTraversal -> propagate promela-targets PropagatePromelaTargetTraversal().traverse(project); for (list<SgNode*>::iterator fIt=functionList.begin();fIt!=functionList.end();fIt++) { // if the definition has a promela and is not main //check if the function is main, .. kind of silly to inline main... if (isSgFunctionDefinition(*fIt)->get_declaration()->get_name().getString()=="main") continue; // add it to the list of inline targets.. if (!functionToInlineMap.count(isSgFunctionDefinition(*fIt)) || !functionToInlineMap[isSgFunctionDefinition(*fIt)]) { functionsToInline.push_back(isSgFunctionDefinition(*fIt)); functionToInlineMap[isSgFunctionDefinition(*fIt)]=true; cout <<"\t\t*"<<isSgFunctionDefinition(*fIt)->get_declaration()->get_name().getString()<<" contains a modelchecking target, -> added to inline list"<<endl; } else { cout <<"\t\t*"<<isSgFunctionDefinition(*fIt)->get_declaration()->get_name().getString()<<" contains a modelchecking target, but is already marked for inlining"<<endl; } } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step4_4.dot"); announceStep(4,5,"Inlining identifyed functions"); bool doneSomeInlineing=false; if (functionsToInline.size()) { // for all thread functions for (int procNr=0;procNr<procFuncVec.size();procNr++) { list<SgNode*> callSiteList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgFunctionCallExp); for (list<SgNode*>::iterator callSite=callSiteList.begin();callSite!=callSiteList.end();callSite++) { SgFunctionDefinition * def; // get the definition for that function if (isSgFunctionRefExp(isSgFunctionCallExp((*callSite))->get_function())) { // straight function call def=isSgFunctionRefExp(isSgFunctionCallExp((*callSite))->get_function())->get_symbol()->get_declaration()->get_definition(); } else { cerr <<"ERROR: could not identify function-definition"<<endl; assert(false); } if (functionToInlineMap[def]) { cout <<"\t\t*need to inline function >"<<def->get_declaration()->get_name().getString()<<"<"<<endl; bool inliningOK=false; inliningOK=doInline(isSgFunctionCallExp(*callSite)); assert(inliningOK==true); doneSomeInlineing|=true; } } } if (doneSomeInlineing) { cout <<"\t\t*Inlineing done->performing ast-consistancy-check"<<endl; // now we can remove the definion and declaration of the iline functions for (int fNr=0;fNr<functionsToInline.size();fNr++) { cout <<"\t\t* removing function declaration and definition of "<<functionsToInline[fNr]->get_declaration()->get_name().getString()<<endl; LowLevelRewrite::remove(isSgStatement(functionsToInline[fNr])); LowLevelRewrite::remove(isSgStatement(functionsToInline[fNr]->get_declaration())); } // AstTests::runAllTests(project); } } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step4_5.dot"); //this one failes.. AstTests::runAllTests(project); announceStep(4,6,"transform for loops to whjile loops"); for (int procNr=0;procNr<procFuncVec.size();procNr++) { changeForLoops(procFuncVec[procNr]); } announceStep(4,6,"MPI-Specific: Moving globals into main"); for(int i=0;i<globalVarDeclVec.size();i++) { bool used=false; // do a nast search if or not the globals are used (->rules aout includesd stuff) SgInitializedName * gIniName=globalVarDeclVec[globalVarDeclVec.size()-1-i]->get_definition()->get_vardefn (); list<SgNode*> varRefExpList=NodeQuery::querySubTree(procFuncVec[0],V_SgVarRefExp); for (list<SgNode*>::iterator it=varRefExpList.begin();it!=varRefExpList.end();it++) { // check if the initialized name is in the list... SgVarRefExp * exp=isSgVarRefExp(*it); SgInitializedName * iniName=exp->get_symbol ()->get_declaration () ; if (gIniName==iniName) { used=true; break; } } // and if not used->skip if (!used) continue; LowLevelRewrite::remove(isSgStatement(globalVarDeclVec[globalVarDeclVec.size()-1-i])); // is allwayzs main // add them in reverse order in case they depend on each other assert(procFuncVec.size()>0); assert(procFuncVec[0]->get_body ()); procFuncVec[0]->get_body ()->prepend_statement (globalVarDeclVec[globalVarDeclVec.size()-1-i]); // and remove it from the old localtion } announceStep(4,7,"Replacing do-while and for-loops which contain model-targets with while-loops"); //CI (4/19/2007): TODO for (int procNr=0;procNr<procFuncVec.size();procNr++) { list<SgNode*> loopsToReplace; list<SgNode*> tmpList; tmpList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgForStatement); loopsToReplace.insert(loopsToReplace.end(),tmpList.begin(),tmpList.end()); tmpList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgDoWhileStmt); loopsToReplace.insert(loopsToReplace.end(),tmpList.begin(),tmpList.end()); for (list<SgNode*>::iterator it=loopsToReplace.begin();it!=loopsToReplace.end();it++) { if (!toConvert(*it)) continue; //else if (isSgForStatement(*it)) forToWhileTransformation(isSgForStatement(*it)); if (isSgDoWhileStmt(*it)) doWhileToWhileTransformation(isSgDoWhileStmt(*it)); } } // since the inline does not preserve ast-attributes, we need to regenerate them prom the "copied" pragmas announceStep(4,8,"Re-Identify modelchecking targets"); PromelaMarker().traverse(project, preorder); debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step4_8.dot"); // from this point on, only work on the function of procFuncVec is necessary,since all necessary data has been inlined announceStep(4,9,"Identify sideffecting-conditionals and move them out of the control-statement, if the statement is transformed to promela"); // first update the modelchecking information PropagatePromelaTargetTraversal().traverse(project); list<SgNode*> conditinalControlStmts; for (int procNr=0;procNr<procFuncVec.size();procNr++) { list<SgNode*> tmpList; // IF tmpList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgIfStmt); conditinalControlStmts.insert(conditinalControlStmts.end(),tmpList.begin(),tmpList.end()); // WHILE tmpList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgWhileStmt); conditinalControlStmts.insert(conditinalControlStmts.end(),tmpList.begin(),tmpList.end()); // SWITCH tmpList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgSwitchStatement); conditinalControlStmts.insert(conditinalControlStmts.end(),tmpList.begin(),tmpList.end()); //make loop userfriendly: for (list<SgNode*>::iterator it=conditinalControlStmts.begin();it!=conditinalControlStmts.end();it++) { bool isWhile=false; // if the statement is not suppoesed to be unparsed to promela -> skip if (!toConvert(*it)) continue; SgStatement * conditional=NULL; if (isSgIfStmt(*it)) { conditional=isSgIfStmt(*it)->get_conditional (); } else if (isSgWhileStmt(*it)) { conditional=isSgWhileStmt(*it)->get_condition (); isWhile=true; } else if (isSgSwitchStatement(*it)) { conditional=isSgSwitchStatement(*it)->get_item_selector (); } // now that we have the SgStatement if (isSideEffektingStmt(conditional)) { cout <<"\t\t*need to move >"<<conditional->unparseToString()<<"< outside the control-structure"<<endl; if (isWhile) { // if the loop contains a continue, substitute those with the end-labl and a goto there, list<SgNode*> continueStmtList= NodeQuery::querySubTree(*it,V_SgContinueStmt); for (list<SgNode*>::iterator continueIt=continueStmtList.begin(); continueIt!=continueStmtList.end(); continueIt++) { // traverse from this one up to the next loop-parent SgNode * tmp=*continueIt; while(!isSgWhileStmt(tmp) && !isSgDoWhileStmt(tmp)&& !isSgForStatement(tmp)) tmp=tmp->get_parent(); // if the continue belongs to this while-loop if (tmp==*it) removeContinues(isSgWhileStmt(*it)); } } // generate a VariableDeclaration SgVariableDeclaration * tempVarDecl=new SgVariableDeclaration( Sg_File_Info::generateDefaultFileInfoForTransformationNode(), SgName("spinBoolTmp"), new SgTypeBool()); // get the expression form the statement assert(isSgExprStatement(conditional)!=NULL); SgExpression * condExpr=isSgExprStatement(conditional)->get_expression (); // generate a initial assignment using the existing stmt SgInitializer * initializer=new SgAssignInitializer( Sg_File_Info::generateDefaultFileInfoForTransformationNode(),condExpr); // attach initializer tempVarDecl->get_definition()->get_vardefn()->set_initializer (initializer); // create a sgvarRefExpr SgVarRefExp * ref=new SgVarRefExp (Sg_File_Info::generateDefaultFileInfoForTransformationNode(), new SgVariableSymbol (tempVarDecl->get_definition()->get_vardefn ())); // replace the original statement with a SgVarRefExpr isSgExprStatement(conditional)->set_expression(ref); ref->set_parent(conditional); // get the parent scope and set it for the variable SgNode * tmp=*it; while(!isSgScopeStatement(tmp)) tmp=tmp->get_parent(); tempVarDecl->get_definition()->get_vardefn()->set_scope(isSgScopeStatement(tmp)->get_scope()); // and prepend the declaration before the conditional LowLevelRewrite::insert(isSgStatement(*it),tempVarDecl,true); // and append it to the while-body, which will work together with the inliner.. if (isWhile) { ref=new SgVarRefExp (Sg_File_Info::generateDefaultFileInfoForTransformationNode(), new SgVariableSymbol (tempVarDecl->get_definition()->get_vardefn ())); // copy the other expression SgExpression *rhs=isSgExpression(SgTreeCopy().copyAst(condExpr)); SgAssignOp * assgnExpr=new SgAssignOp(Sg_File_Info::generateDefaultFileInfoForTransformationNode(),ref,rhs); //append at the end of the loop, too isSgWhileStmt(*it)->get_body ()->append_statement ( new SgExprStatement (Sg_File_Info::generateDefaultFileInfoForTransformationNode(),assgnExpr) ); // assgnExpr->set_parent(isSgWhileStmt(*it)->get_body ()); } } // else do nothing } } // * 3.3: find all variables in the function,give them a unique name and move them to the bgeinning of the function, this is allowed because this is for C only!!!. This would not work for classes which must be constructed announceStep(4,8,"find all variables assign unique name and transform them to \n\tmatch promelas 2-scope-convention"); string procName; vector<SgClassType *>classTypeList; // first rename all variables to have unique names... for (int procNr=0;procNr<procFuncVec.size();procNr++) { flattenScopes(isSgFunctionDefinition(procFuncVec[procNr])); } // output a marked ast debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.reduced.dot"); announceStep(4,9,"final propagation of promela-targets"); project->unparse(); PropagatePromelaTargetTraversal().traverse(project); debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.transformations.dot"); cout <<"-------------------------------------------------------------------------------"<<endl <<"\tFrom here on the C-Ast will be modified into a Promela/C-AST"<<endl <<"-------------------------------------------------------------------------------"<<endl; announceStep(6,1,"using the initial promela targets mark the ast"); // using the sdg traverse the project to unparse to promela // the important step is to identify staements which can not be transformed to // promela because of PROMELA restrictions and therfore must be kept in C // since we have done slicing this is only done for functioncalls and such stuff // find the model-intersting nodes` sdg=new SystemDependenceGraph(); sdg->parseProject(project); vector<SpinPStructContainer*> pStructContainerArray; for (int procNr=0;procNr<procFuncVec.size();procNr++) { // list<SgNode*> stmtList=NodeQuery::querySubTree(project,V_SgStatement); list<SgNode*> stmtList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgStatement); list<SgNode*> markedNodes; // find all nodes which have beem tagged for promela-transformation for (list<SgNode*>::iterator stmtIt=stmtList.begin();stmtIt!=stmtList.end();stmtIt++) { if (toConvert(*stmtIt)) { markedNodes.push_back(*stmtIt); } } // once these statements have been identified, track their dependencys cout <<"processing stmt's"<<endl; for (list<SgNode*>::iterator it=markedNodes.begin();it!=markedNodes.end();it++) { cout <<"*stmt marked: "<<(*it)->unparseToString()<<endl; if (isSgFunctionDefinition(*it)) continue; cout <<" control dependencys:"<<endl; DependenceNode* currDepNode=sdg->getNode(*it); set <SimpleDirectedGraphNode *> preds=currDepNode->getPredecessors(); // cout <<(*it)->unparseToString()<<" has "<<preds.size()<<" predecessors"<<endl; // process all predecessors... for (set < SimpleDirectedGraphNode * >::iterator i = preds.begin();i != preds.end(); i++) { DependenceNode *pred = dynamic_cast < DependenceNode * >(*i); // ok this node is what dependency? set < DependenceGraph::EdgeType > connectingSet=sdg->edgeType(pred,currDepNode); SgNode * predNode=getStatement(pred->getSgNode()); SgNode * parentPredNode=NULL; // since controlstatements like if and while have a statement as an expression in rose and since the expression has all the control dependencys track those, but mark the parent statement,too if (isSgWhileStmt(predNode->get_parent())) parentPredNode=predNode->get_parent(); else if (isSgIfStmt(predNode->get_parent())) parentPredNode=predNode->get_parent(); // if control, add to the transformation set if (connectingSet.count(DependenceGraph::CONTROL)) { cout <<"\tcontrol dependency"<<endl; if (toConvert(predNode)) { cout <<"\t>"<<predNode->unparseToString()<<"<already marked for conversion"<<endl; } else { markedNodes.push_back(pred->getSgNode()); cout <<"\tmark >"<<predNode->unparseToString()<<"< for conversion"<<endl; markForPromelaTransformation(predNode); if (parentPredNode!=NULL) markForPromelaTransformation(parentPredNode); } } else if (connectingSet.count(DependenceGraph::DATA)) { cout <<"data dependency presen, but not resolved!"<<endl; // this will be done by checkin all controll dependeny nodes and adding those to the promela state vector... } else { cout <<"ILLIGAL DEPENDENCY FOUND. Previouse transformations should have removed those!!!"<<endl; } } } } // now the ast is in its final marked for debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step6_1.dot"); announceStep(6,2,"Creating PStruct"); for (int procNr=0;procNr<procFuncVec.size();procNr++) { /* create astruct that contains the data that is stored in the state vector...*/ SpinPStructContainer * pStruct= new SpinPStructContainer( procFuncVec[procNr]->get_declaration()->get_name().getString() ); // add the struct to the AST-for fun->it will be hidden in the promela output pass LowLevelRewrite::insert( isSgStatement(procFuncVec[procNr]->get_parent()), pStruct->getStructSubTree(), true ); // put the struct in the vector for later use pStructContainerArray.push_back(pStruct); // register class type classTypeList.push_back(new SgClassType(pStruct->getStructSubTree())); } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step6_2.dot"); announceStep(5,0,"transform MPI-calls to SPIN-M-calls"); MPISpinReplacement MPIreplacer; for (int i=0;i<procFuncVec.size();i++) { //old: MPIreplacer.replaceIn(procFuncVec[i],pStructContainerArray[i]->getPStructVarDeclaration()); MPIreplacer.replaceIn(procFuncVec[i],pStructContainerArray[i]); } project->unparse(); debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step5.dot"); announceStep(6,3,"Identifying variables and putting them in the state-vector"); for (int procNr=0;procNr<procFuncVec.size();procNr++) { // traverse over each promela-procedure and track wich variables are use. //later add those to the state vector. the variables that need to be in // the state vector will be stored in an ast attribute attached to the // function-definition... // Create the container that will contain the variables for the "promela-export" CStateASTAttrib * c_stateAttr=new CStateASTAttrib(); // find all VariableDeclarations list<SgNode*> variableDeclarationList=NodeQuery::querySubTree(procFuncVec[procNr],V_SgVariableDeclaration); // this set will contain a variable declarations set<SgNode*> iniNameList; set<SgInitializedName *>cStateVariables; // the list in markedNodes contains all control nodes, // now traverse again and check variables for (list<SgNode*>::iterator it= variableDeclarationList.begin(); it!=variableDeclarationList.end(); it++) { // get the paren scope... SgNode * parentScopeTmp=*it; // get parents until we find the first scope while(!isSgScopeStatement(parentScopeTmp)) { parentScopeTmp=parentScopeTmp->get_parent(); } // tmp is now the next scope if (toConvert(parentScopeTmp)) { // parent scope will be transforemd to promela -> block might be split up // in mutliple c_blocks, and since varDecls don't carry accross c-blocks->statevec SgVariableDeclaration * decl=isSgVariableDeclaration(*it); // if the variable is promela-compatible and the parent scope is the scope form the procFuncVec -> no explicit state vector needed, can be keept in promela... // if (isPromelaCompatibleVariableType(decl)) // { // ok, mark the variable as unparsable to promela... // } // else // { // add it the the state=ast-trribute cStateVariables.insert(decl->get_definition()->get_vardefn ()); cout <<"converting "<<decl->get_definition()->get_vardefn ()->get_name ().getString()<<endl; markAsPromelaStateVar(decl); c_stateAttr->add(decl->get_definition()->get_vardefn () ); cout <<"\t\t*added "<< decl->get_definition()->get_vardefn ()->get_name ().getString()<<" to the state-vector"<<endl; // remove the old variable-declaration LowLevelRewrite::remove(isSgStatement(decl)); pStructContainerArray[procNr]->addVariable(decl); // } } else { // the block is PURE c-> no promelastate will pass across its borders // therefore all variable-declaration within can be keept as is... } /*CI (4/19/2007) not all variable-uses need to be inc-block style, determine that later c_stateAttr->add(isSgInitializedName(*setIt)); setStateVecVarAttrib(*setIt,new StateVecVarASTAttrib(true));*/ // now force all nodes that contain a variable that is declared using the c_state stmt to be converted to c!!!! markStatementsWithCStateVariables(procFuncVec[procNr],cStateVariables); } // attach the c-state-attribute to the function-defintion setCStateAttrib(procFuncVec[procNr],c_stateAttr); } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step6_3.dot"); announceStep(6,4,"inserting promela proctype variable to the proc-functions"); // * 3.4: insert the promela proctype variable to the proc-functions for (int i=0;i<procFuncVec.size();i++) { /* // create instance SgType * instanceType=classTypeList[i]; Sg_File_Info * instanceFI=Sg_File_Info::generateDefaultFileInfoForTransformationNode(); SgName instanceName=string("P")+(procFuncVec[i])->get_declaration()->get_name().getString()+"Instance"; SgStatement * instanceVarDecl=new SgVariableDeclaration(instanceFI,instanceName,instanceType); procFuncVec[i]->get_body()->prepend_statement (instanceVarDecl); */ procFuncVec[i]->get_body()->prepend_statement ( pStructContainerArray[i]->getPStructVarDeclaration() ); // fix scope pStructContainerArray[i]->getPStructVarDeclaration()->get_definition()->get_vardefn ()->set_scope(procFuncVec[i]->get_body()->get_scope()); procFuncVec[i]->get_body()->prepend_statement ( pStructContainerArray[i]->getPStructVarInstanziationDeclaration() ); pStructContainerArray[i]->getPStructVarInstanziationDeclaration()->get_definition()->get_vardefn ()->set_scope(procFuncVec[i]->get_body()->get_scope()); /* // creat ptr variable Sg_File_Info * initializerFI=Sg_File_Info::generateDefaultFileInfoForTransformationNode(); SgVarRefExp * varRef=new SgVarRefExp ( Sg_File_Info::generateDefaultFileInfoForTransformationNode(),new SgVariableSymbol (isSgVariableDeclaration(instanceVarDecl)->get_definition()->get_vardefn ())); SgAddressOfOp *aof=new SgAddressOfOp (Sg_File_Info::generateDefaultFileInfoForTransformationNode(),isSgExpression(varRef),instanceType); SgInitializer * ptrInitializer= new SgAssignInitializer(initializerFI,aof); */ /* Sg_File_Info * ptrFI=Sg_File_Info::generateDefaultFileInfoForTransformationNode(); // ptrFI->setCompilerGenerated(); // ptrFI->unsetOutputInCodeGeneration (); SgType * pointerType=new SgPointerType (instanceType); SgName ptrName=string("P")+(procFuncVec[i])->get_declaration()->get_name().getString(); SgStatement * ptrVarDecl=new SgVariableDeclaration(ptrFI,ptrName,pointerType); //SgStatement * ptrVarDecl=new SgVariableDeclaration(ptrFI,ptrName,pointerType,ptrInitializer); procFuncVec[i]->get_body()->prepend_statement (ptrVarDecl); procVariableList.push_back(isSgVariableDeclaration(ptrVarDecl));*/ // procVariableList.push_back(pStructContainerArray[i]->getPStructVarDeclaration()); } announceStep(6,5,"transform the use of variables in c_code-blocks to PROEMALs-callingconvetion"); for (int i=0;i<procFuncVec.size();i++) { refactorSgVarRefExpInCBlocks(procFuncVec[i],pStructContainerArray[i]->getPStructVarDeclaration()); } // since mpi-commands within promela will be transformned in by the promela-mpi-iunclude-> keep the in spin for the moment..., but a direct approach is also thinkable... { list<SgNode*> stmtList=NodeQuery::querySubTree(procFuncVec[0],V_SgStatement); // find all nodes which have beem tagged for promela-transformation for (list<SgNode*>::iterator stmtIt=stmtList.begin();stmtIt!=stmtList.end();stmtIt++) { if (isNodeMPI(*stmtIt) && !toConvert(*stmtIt)) { markForPromelaTransformation(*stmtIt); } } } debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.Step6_5.dot"); // *3.x finally remove return statements in all promela functions and replace them with a goto to the end of that function body announceStep(6,6,"remove all return-statements and replace with goto-statenents"); for (int i=0;i<procFuncVec.size();i++) { removeReturnStmts(procFuncVec[i]); } // 4.x mark AST for unparse, adding astattributes announceStep(6,7,"final PROMELA-attribute propagation"); MarkAST4Unparse finalMarker; finalMarker.traverse(project); // add mpi include and pp-directives if (MPIreplacer.getNrOfMPICalls()>0) { announceStep(6,8,"MPI-touchup. Add the SPIN-M #include mpi-spin.prom directive adn the active MPI_PROC"); cout <<"\t\t*found "<<MPIreplacer.getNrOfMPICalls()<<" MPI-calls"<<endl; SgGlobal * globalNode=NULL; SgNode * tmp=procFuncVec[0]; while(!isSgGlobal(tmp)) tmp=tmp->get_parent(); globalNode=isSgGlobal(tmp); if (globalNode->get_attachedPreprocessingInfoPtr ()==NULL) globalNode->set_attachedPreprocessingInfoPtr(new AttachedPreprocessingInfoType()); PreprocessingInfo * spinInclude=new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,string("#include \"mpi-spin.prom\""),"user-generated",0,0,0,PreprocessingInfo::before,false,false); globalNode->addToAttachedPreprocessingInfo(spinInclude); PreprocessingInfo * activeMPI_PROC=new PreprocessingInfo(PreprocessingInfo::CpreprocessorIncludeDeclaration,string("active MPI_PROC"),"user-generated",0,0,0,PreprocessingInfo::after,false,false); globalNode->addToAttachedPreprocessingInfo(activeMPI_PROC); } cout <<"*--------------------------------*\n\tstep 7->unparse\n*--------------------------------*"<<endl; announceStep(7,0,"unparsing mixed ast"); // output the dot-grpah AstDOTGeneration dotgen; dotgen.generateInputFiles(project,AstDOTGeneration::PREORDER); // set4: assert that the promela-part is valid // Step4: unparse project to C/Promela // Unparser_Opt options; // ofstream * out=new ofstream("main.pml"); // CToProMeLaUnparser unparser(out,string("main.pml"),options,0); // SgUnparse_Info info; // cout <<" Test of unparser. Filename is "<<unparser.getFileName()<<endl; debugPromelaAst->generate(string((*(project->get_fileList ()->begin()))->getFileName())+".SPIN.1.dot"); cout <<"unparing to C"<<endl; project->unparse(); for (int i=0;i<procFuncVec.size();i++) pStructContainerArray[i]->hideShugar(); cout << "unparsing to Promela"<<endl; unparsePromelaProject(project,NULL,NULL); //unnparser. // unparser.run_unparser(); // unparseProject(project); // unparser.unparseProject(project,info); return 0; }
int main(int argc, char *argv[]) { SgProject* proj = frontend(argc,argv); ROSE_ASSERT (proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string dotFileName1=fileName+"."+ mainDef->get_declaration()->get_name() +".dot"; cfgToDot(mainDef,dotFileName1); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); std::set<std::vector<string> > sssv; std::vector<string> sss; sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @8 :0"); sss.push_back("<SgExprStatement> @9 :0"); sss.push_back("<SgAssignOp> @9 :0"); sss.push_back("<SgVarRefExp> @9 :0"); sss.push_back("<SgAssignOp> @9 :1"); sss.push_back("<SgIntVal> @9 :0"); sss.push_back("<SgIntVal> @9 :1"); sss.push_back("<SgAssignOp> @9 :2"); sss.push_back("<SgExprStatement> @9 :1"); sss.push_back("<SgBasicBlock> @8 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @1 :0"); sss.push_back("<SgFunctionParameterList> @1 :0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @1 :1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @1 :2"); sss.push_back("<SgBasicBlock> @2 :0"); sss.push_back("<SgVariableDeclaration> @3 :0"); sss.push_back("<SgInitializedName> k :0"); sss.push_back("<SgAssignInitializer> @3 :0"); sss.push_back("<SgIntVal> @3 :0"); sss.push_back("<SgIntVal> @3 :1"); sss.push_back("<SgAssignInitializer> @3 :1"); sss.push_back("<SgInitializedName> k :1"); sss.push_back("<SgVariableDeclaration> @3 :1"); sss.push_back("<SgBasicBlock> @2 :1"); sss.push_back("<SgVariableDeclaration> @4 :0"); sss.push_back("<SgInitializedName> x :0"); sss.push_back("<SgAssignInitializer> @4 :0"); sss.push_back("<SgIntVal> @4 :0"); sss.push_back("<SgIntVal> @4 :1"); sss.push_back("<SgAssignInitializer> @4 :1"); sss.push_back("<SgInitializedName> x :1"); sss.push_back("<SgVariableDeclaration> @4 :1"); sss.push_back("<SgBasicBlock> @2 :2"); sss.push_back("<SgIfStmt> @5 :0"); sss.push_back("<SgExprStatement> @5 :0"); sss.push_back("<SgOrOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgAndOp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :0"); sss.push_back("<SgBoolValExp> @5 :1"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgAndOp> @5 :1"); sss.push_back("<SgAndOp> @5 :2"); sss.push_back("<SgOrOp> @5 :1"); sss.push_back("<SgOrOp> @5 :2"); sss.push_back("<SgExprStatement> @5 :1"); sss.push_back("<SgIfStmt> @5 :1"); sss.push_back("<SgBasicBlock> @5 :0"); sss.push_back("<SgExprStatement> @6 :0"); sss.push_back("<SgAssignOp> @6 :0"); sss.push_back("<SgVarRefExp> @6 :0"); sss.push_back("<SgAssignOp> @6 :1"); sss.push_back("<SgIntVal> @6 :0"); sss.push_back("<SgIntVal> @6 :1"); sss.push_back("<SgAssignOp> @6 :2"); sss.push_back("<SgExprStatement> @6 :1"); sss.push_back("<SgBasicBlock> @5 :1"); sss.push_back("<SgIfStmt> @5 :2"); sss.push_back("<SgBasicBlock> @2 :3"); sss.push_back("<SgReturnStmt> @11 :0"); sss.push_back("<SgIntVal> @11 :0"); sss.push_back("<SgIntVal> @11 :1"); sss.push_back("<SgReturnStmt> @11 :1"); sss.push_back("End(::main)<SgFunctionDefinition> @1 :3"); sssv.insert(sss); sss.clear(); vis->sssv = sssv; vis->constructPathAnalyzer(mg, true, 0, 0, true); std::cout << "finished" << std::endl; std::cout << " paths: " << vis->paths.size() << std::endl; delete vis; }
void process() { int i; for (i = 0; i < fdefList.size(); i++) { SgFunctionDefinition* fndef = fdefList.at(i); if (fndef == NULL) { return; } std::string functionName = fndef->get_declaration()->get_name().getString(); SgFunctionDeclaration *f = fndef->get_declaration(); if (!debugHooks) { SgNode *body = fndef->get_body(); // Move any preprocessing info before the function to a new // null statement preceding the function. AttachedPreprocessingInfoType save_buf; SageInterface::cutPreprocessingInfo(f, PreprocessingInfo::before, save_buf) ; if (save_buf.size()) { SgVariableDeclaration *dummy = SageBuilder::buildVariableDeclaration( "___htc_dummy_decl_for_preproc_info", SageBuilder::buildIntType(), 0, f->get_scope()); SageInterface::setExtern(dummy); SageInterface::insertStatementBefore(f, dummy); SageInterface::pastePreprocessingInfo( dummy, PreprocessingInfo::before, save_buf); } SageInterface::addTextForUnparser( f, "\n#if 0", AstUnparseAttribute::e_before); std::string CapFnName = Capitalize(functionName); std::string before_body = "\n#endif\n"; std::string macro_name = "HTC_KEEP_MODULE_" + Upper(functionName); before_body += "#ifdef " + macro_name + "\n"; before_body += "#include \"Ht.h\"\n"; before_body += "#include \"Pers" + CapFnName + ".h\"\n"; before_body += "#ifndef __htc_GW_write_addr\n"; before_body += "#define __htc_GW_write_addr(v,a) v.write_addr(a)\n"; before_body += "#endif\n"; before_body += "#ifndef __htc_GW_write_addr2\n"; before_body += "#define __htc_GW_write_addr2(v,a,b) v.write_addr(a,b)\n"; before_body += "#endif\n"; before_body += "void CPers" + CapFnName + "::Pers" + CapFnName + "()\n"; SageInterface::addTextForUnparser(body, before_body, AstUnparseAttribute::e_before); std::string after_body = "\n#endif /* " + macro_name + " */\n"; SageInterface::addTextForUnparser(body, after_body, AstUnparseAttribute::e_after); // Write the _src.cpp file generate_src_cpp_file(fndef, CapFnName, macro_name); } } for (i = 0; i < fdeclList.size(); i++) { SgFunctionDeclaration *fdecl = fdeclList.at(i); if (!debugHooks && fdecl && fdecl->get_definingDeclaration() != fdecl) { // Move any preprocessing info before the function to a new // null statement preceding the function. AttachedPreprocessingInfoType save_buf; SageInterface::cutPreprocessingInfo(fdecl, PreprocessingInfo::before, save_buf) ; if (save_buf.size()) { SgVariableDeclaration *dummy2 = SageBuilder::buildVariableDeclaration( "___htc_dummy_decl2_for_preproc_info", SageBuilder::buildIntType(), 0, fdecl->get_scope()); SageInterface::setExtern(dummy2); SageInterface::insertStatementBefore(fdecl, dummy2); SageInterface::pastePreprocessingInfo( dummy2, PreprocessingInfo::before, save_buf); } SageInterface::addTextForUnparser(fdecl, "\n/* ", AstUnparseAttribute::e_before); SageInterface::addTextForUnparser(fdecl, " */", AstUnparseAttribute::e_after); // comment out function prototypes // fdecl->setCompilerGenerated(); // fdecl->unsetOutputInCodeGeneration(); } } }
void ControlDependenceGraph::_buildInterprocedural() { // Go through the SGNODE dependence nodes and create the appropriate // call site nodes, entry nodes etc. SgFunctionDefinition *func = isSgFunctionDefinition(_head); ROSE_ASSERT(func != NULL); // First create the entry node for the procedure _interprocedural->procedureEntry.entry = new DependenceNode(DependenceNode::ENTRY, func->get_declaration()); DependenceNode *entry = createNode(_interprocedural->procedureEntry.entry); // Link the entry node up with all the nodes in the CDG which do not have // predecessors for (set < SimpleDirectedGraphNode * >::iterator i = _nodes.begin(); i != _nodes.end(); i++) { DependenceNode *node = dynamic_cast < DependenceNode * >(*i); if ((node->numPredecessors() == 0) && (node != entry)) { establishEdge(entry, node); } } // create a formal out return argument, control dependent on the entry // node string return_name = func->get_declaration()->get_name().str(); return_name = return_name + " return"; _interprocedural->procedureEntry.formal_return = new DependenceNode(DependenceNode::FORMALOUT, return_name); DependenceNode *formal_return = createNode(_interprocedural->procedureEntry.formal_return); establishEdge(entry, formal_return); // for each of the arguments in the function parameter list, add a // formal-in and formal-out node SgFunctionParameterList *paramlist = func->get_declaration()->get_parameterList(); SgInitializedNamePtrList params = paramlist->get_args(); for (SgInitializedNamePtrList::iterator i = params.begin(); i != params.end(); i++) { SgInitializedName *name = *i; DependenceNode *formal_in = new DependenceNode(DependenceNode::FORMALIN, name->get_name().str()); DependenceNode *formal_out = new DependenceNode(DependenceNode::FORMALOUT, name->get_name().str()); establishEdge(entry, createNode(formal_in)); establishEdge(entry, createNode(formal_out)); _interprocedural->procedureEntry.formal_in[name] = formal_in; _interprocedural->procedureEntry.formal_out[name] = formal_out; // To preserve the order of arguments, we insert them into arg_order _interprocedural->procedureEntry.arg_order.push_back(name); } // Now we go through each of the SgNodes in our CDG. If any of them // contain a function call, we want to build a call site node for them. map < SgNode *, DependenceNode * >::iterator sgnode_iterator; for (sgnode_iterator = _sgnode_map.begin(); sgnode_iterator != _sgnode_map.end(); sgnode_iterator++) { SgNode *currnode = sgnode_iterator->first; list < SgFunctionCallExp * >calls = InterproceduralInfo::extractFunctionCalls(currnode); if (calls.empty()) continue; for (list < SgFunctionCallExp * >::iterator i = calls.begin(); i != calls.end(); i++) { SgFunctionCallExp *call = *i; // This needs to be replaced with some call graph analysis SgFunctionRefExp *func = isSgFunctionRefExp(call->get_function()); ROSE_ASSERT(func != NULL); SgName func_name = func->get_symbol()->get_name(); InterproceduralInfo::CallSiteStructure callstructure; callstructure.callsite = new DependenceNode(DependenceNode::CALLSITE, call); // the call site is control dependent on the statement (i.e. for // the call site to happen, the statement must be executed) DependenceNode *callsite = createNode(callstructure.callsite); // addLink(callsite, getNode(currnode)); establishEdge(getNode(currnode), callsite); // create an actual out node for the return value, control // dependent on callsite string return_name = func_name.str(); return_name = return_name + " return"; callstructure.actual_return = new DependenceNode(DependenceNode::ACTUALOUT, return_name); DependenceNode *actual_return = createNode(callstructure.actual_return); establishEdge(callsite, actual_return); // For each argument in the function call, build an actual_in and // actual_out, control dependent on callsite SgExpressionPtrList args = call->get_args()->get_expressions(); for (SgExpressionPtrList::iterator j = args.begin(); j != args.end(); j++) { SgExpression *arg = *j; DependenceNode *actual_in = new DependenceNode(DependenceNode::ACTUALIN, arg); DependenceNode *actual_out = new DependenceNode(DependenceNode::ACTUALOUT, arg); establishEdge(callsite, createNode(actual_in)); establishEdge(callsite, createNode(actual_out)); callstructure.actual_in[arg] = actual_in; callstructure.actual_out[arg] = actual_out; // To preserve the order of expressions in the parameter list, // // we insert them into expr_order callstructure.expr_order.push_back(arg); } // add the callstructure to interprocedural info _interprocedural->callsite_map[call] = callstructure; } } }
int main(int argc, char *argv[]) { SgProject* proj = frontend(argc,argv); ROSE_ASSERT (proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string dotFileName1=fileName+"."+ mainDef->get_declaration()->get_name() +".dot"; cfgToDot(mainDef,dotFileName1); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); std::set<std::vector<string> > sssv; std::vector<string> sss; sss.push_back("Start(::main)<SgFunctionDefinition> @line=1 :idx=0"); sss.push_back("main_parameter_list_<SgFunctionParameterList> @line=1 :idx=0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @line=1 :idx=1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @line=1 :idx=2"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=0"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=0"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=1"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=1"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=0"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=0"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=1"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=1"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=2"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=1"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=1"); sss.push_back("End(::main)<SgFunctionDefinition> @line=1 :idx=3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @line=1 :idx=0"); sss.push_back("main_parameter_list_<SgFunctionParameterList> @line=1 :idx=0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @line=1 :idx=1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @line=1 :idx=2"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=0"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=0"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=1"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=1"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a5f8188<SgBasicBlock> @line=2 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=3"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=0"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=0"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=1"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=1"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=2"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=1"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=1"); sss.push_back("End(::main)<SgFunctionDefinition> @line=1 :idx=3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @line=1 :idx=0"); sss.push_back("main_parameter_list_<SgFunctionParameterList> @line=1 :idx=0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @line=1 :idx=1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @line=1 :idx=2"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=0"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=0"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=1"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=1"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=0"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=0"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=1"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=1"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a5f8300<SgBasicBlock> @line=4 :idx=0"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=3"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=2"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=1"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=1"); sss.push_back("End(::main)<SgFunctionDefinition> @line=1 :idx=3"); sssv.insert(sss); sss.clear(); sss.push_back("Start(::main)<SgFunctionDefinition> @line=1 :idx=0"); sss.push_back("main_parameter_list_<SgFunctionParameterList> @line=1 :idx=0"); sss.push_back("After parameters(::main)<SgFunctionDefinition> @line=1 :idx=1"); sss.push_back("After pre-initialization(::main)<SgFunctionDefinition> @line=1 :idx=2"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=0"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=0"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=2 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=2 :idx=1"); sss.push_back("initialized_name_i<SgInitializedName> i :idx=1"); sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=2 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a5f8188<SgBasicBlock> @line=2 :idx=0"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=3"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=0"); sss.push_back("var_ref_of_i<SgVarRefExp> @line=2 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=2 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=2 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=2 :idx=1"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=2"); sss.push_back("0x2b199a654010<SgForStatement> @line=2 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=0"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=0"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=0"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=0"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=4 :idx=1"); sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=4 :idx=1"); sss.push_back("initialized_name_j<SgInitializedName> j :idx=1"); sss.push_back("_variable_declaration_j<SgVariableDeclaration> @line=4 :idx=1"); sss.push_back("SgForInitStatement<SgForInitStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a5f8300<SgBasicBlock> @line=4 :idx=0"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=3"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=1"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=0"); sss.push_back("var_ref_of_j<SgVarRefExp> @line=4 :idx=0"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=1"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=0"); sss.push_back("integer_value_exp_1<SgIntVal> @line=4 :idx=1"); sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=4 :idx=2"); sss.push_back("SgExprStatement<SgExprStatement> @line=4 :idx=1"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=2"); sss.push_back("0x2b199a654178<SgForStatement> @line=4 :idx=4"); sss.push_back("0x2b199a5f8010<SgBasicBlock> @line=1 :idx=2"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=0"); sss.push_back("integer_value_exp_0<SgIntVal> @line=6 :idx=1"); sss.push_back("SgReturnStmt<SgReturnStmt> @line=6 :idx=1"); sss.push_back("End(::main)<SgFunctionDefinition> @line=1 :idx=3"); sssv.insert(sss); sss.clear(); vis->sssv = sssv; vis->constructPathAnalyzer(mg, true, 0, 0, true); ROSE_ASSERT(vis->sssv.size() == vis->paths.size()); std::cout << "finished" << std::endl; std::cout << " paths: " << vis->paths.size() << std::endl; delete vis; }
void RewriteFSM::visitSgFunctionDeclaration(SgFunctionDeclaration *FD) { SgFunctionDefinition *fdef = FD->get_definition(); if (!fdef) { return; } if (debugHooks) { std::cout << "Func decl: " << FD << " " << FD->get_name() << std::endl; } std::string modName = FD->get_name().getString(); HtdInfoAttribute *htd = getHtdInfoAttribute(fdef); bool isStreamingStencil = false; size_t pos = 0; if ((pos = modName.find(StencilStreamPrefix)) != std::string::npos && pos == 0) { isStreamingStencil = true; } #define hostEntryPrefix "__HTC_HOST_ENTRY_" bool isHostEntry = false; if ((pos = modName.find(hostEntryPrefix)) != std::string::npos && pos == 0) { isHostEntry = true; } // Emit a default, unnamed thread group. std::string modWidth = boost::to_upper_copy(modName) + "_HTID_W"; if (isStreamingStencil) { // The streaming version of a stencil must have width 0. htd->appendDefine(modWidth, "0"); } else if (isHostEntry) { htd->appendDefine(modWidth, "1"); } else if (htd->moduleWidth != -1) { htd->appendDefine(modWidth, boost::lexical_cast<std::string>(htd->moduleWidth)); } else { DefaultModuleWidthAttribute *dwAttr = getDefaultModuleWidthAttribute(SageInterface::getGlobalScope(fdef)); if (dwAttr) { htd->appendDefine(modWidth, boost::lexical_cast<std::string>(dwAttr->width)); } else { htd->appendDefine(modWidth, "5"); } } htd->appendModule(modName, "", modWidth); // For streaming stencils, ProcessStencils inserts a canned sequence, // so we bypass generating a normal FSM. if (isStreamingStencil) { return; } // // Create new case body blocks for each state. // The first executable statement starts the first state, and each // label starts a new state. // std::map<SgLabelStatement *, int> labelToState; std::map<int, std::string> stateToName; SgBasicBlock *funcBody = isSgBasicBlock(fdef->get_body()); SgStatementPtrList &stmts = funcBody->get_statements(); std::vector<SgStatement *>::iterator SI, SP; for (SI = stmts.begin(); SI != stmts.end(); ++SI) { if (!isSgDeclarationStatement(*SI)) { break; } } if (SI == stmts.end()) { return; } SP = SI; std::vector<SgBasicBlock *> newBlocks; SgBasicBlock *newbb = SageBuilder::buildBasicBlock(); newBlocks.push_back(newbb); stateToName[1] = "__START"; bool prevIsLabel = false; for (; SI != stmts.end(); ++SI) { SgStatement *stmt = *SI; SgLabelStatement *labstmt = isSgLabelStatement(stmt); if (labstmt) { if (!prevIsLabel) { newbb = SageBuilder::buildBasicBlock(); newBlocks.push_back(newbb); } int snum = newBlocks.size(); labelToState[labstmt] = snum; stateToName[snum] += "__" + labstmt->get_label().getString(); prevIsLabel = true; #if 1 // TODO: these labels can carry preproc infos-- but the unparser // doesn't output them if the label is not actually output. AttachedPreprocessingInfoType *comments = labstmt->getAttachedPreprocessingInfo(); if (comments && comments->size() > 0) { std::cerr << "DEVWARN: losing Preprocinfo on label" << std::endl; SageInterface::dumpPreprocInfo(labstmt); } #endif stmt->unsetOutputInCodeGeneration(); SageInterface::appendStatement(stmt, newbb); } else { prevIsLabel = false; SageInterface::appendStatement(stmt, newbb); } } stmts.erase(SP, stmts.end()); // Add module name to each state name and create enum decl. SgEnumDeclaration *enumDecl = SageBuilder::buildEnumDeclaration("states", fdef); for (int i = 1; i <= newBlocks.size(); i++) { stateToName[i] = modName + stateToName[i]; boost::to_upper(stateToName[i]); SgName nm(stateToName[i]); SgInitializedName *enumerator = SageBuilder::buildInitializedName(nm, SageBuilder::buildIntType(), SageBuilder::buildAssignInitializer(SageBuilder::buildIntVal(i))); enumerator->set_scope(funcBody); enumDecl->append_enumerator(enumerator); // Add the instruction to the htd info. htd->appendInst(nm.getString()); } SageInterface::prependStatement(enumDecl, funcBody); if (!debugHooks) { enumDecl->unsetOutputInCodeGeneration(); } SgGlobal *GS = SageInterface::getGlobalScope(FD); SgVariableDeclaration *declHtValid = HtDeclMgr::buildHtlVarDecl("PR_htValid", GS); SgVariableDeclaration *declHtInst = HtDeclMgr::buildHtlVarDecl("PR_htInst", GS); SgFunctionDeclaration *declHtContinue = HtDeclMgr::buildHtlFuncDecl("HtContinue", GS); SgFunctionDeclaration *declHtAssert = HtDeclMgr::buildHtlFuncDecl("HtAssert", GS); // // Create the finite state machine switch statement "switch (PR_htInst)", // and insert guard "if (PR_htValid)". // SgBasicBlock *newSwitchBody = SageBuilder::buildBasicBlock(); SgExpression *htInstExpr = SageBuilder::buildVarRefExp(declHtInst); SgSwitchStatement *newSwitch = SageBuilder::buildSwitchStatement(htInstExpr, newSwitchBody); SgExpression *htValidExpr = SageBuilder::buildVarRefExp(declHtValid); SgIfStmt *newIfStmt = SageBuilder::buildIfStmt(htValidExpr, SageBuilder::buildBasicBlock(newSwitch), 0); SageInterface::appendStatement(newIfStmt, funcBody); int casenum = 1; foreach (SgBasicBlock *newCaseBody, newBlocks) { SgExpression *caseExpr = SageBuilder::buildEnumVal_nfi(casenum, enumDecl, stateToName[casenum]); SgCaseOptionStmt *newCase = SageBuilder::buildCaseOptionStmt(caseExpr, newCaseBody); SageInterface::appendStatement(newCase, newSwitchBody); casenum++; }
// Main inliner code. Accepts a function call as a parameter, and inlines // only that single function call. Returns the inserted block // if inlining succeeded, and NULL otherwise. // The function call must be to a named function, static member // function, or non-virtual non-static member function, and the function // must be known (not through a function pointer or member function // pointer). Also, the body of the function must already be visible. // Recursive procedures are handled properly (when allowRecursion is set), by // inlining one copy of the procedure into itself. Any other restrictions on // what can be inlined are bugs in the inliner code. SgBasicBlock* doInline(SgFunctionCallExp* funcall, bool allowRecursion) { #if 0 // DQ (4/6/2015): Adding code to check for consitancy of checking the isTransformed flag. ROSE_ASSERT(funcall != NULL); ROSE_ASSERT(funcall->get_parent() != NULL); SgGlobal* globalScope = TransformationSupport::getGlobalScope(funcall); ROSE_ASSERT(globalScope != NULL); // checkTransformedFlagsVisitor(funcall->get_parent()); checkTransformedFlagsVisitor(globalScope); #endif SgExpression* funname = funcall->get_function(); SgExpression* funname2 = isSgFunctionRefExp(funname); SgDotExp* dotexp = isSgDotExp(funname); SgArrowExp* arrowexp = isSgArrowExp(funname); SgExpression* thisptr = 0; if (dotexp || arrowexp) { funname2 = isSgBinaryOp(funname)->get_rhs_operand(); if (dotexp) { SgExpression* lhs = dotexp->get_lhs_operand(); // FIXME -- patch this into p_lvalue bool is_lvalue = lhs->get_lvalue(); if (isSgInitializer(lhs)) is_lvalue = false; if (!is_lvalue) { SgAssignInitializer* ai = SageInterface::splitExpression(lhs); ROSE_ASSERT (isSgInitializer(ai->get_operand())); #if 1 printf ("ai = %p ai->isTransformation() = %s \n",ai,ai->isTransformation() ? "true" : "false"); #endif SgInitializedName* in = isSgInitializedName(ai->get_parent()); ROSE_ASSERT (in); removeRedundantCopyInConstruction(in); lhs = dotexp->get_lhs_operand(); // Should be a var ref now } thisptr = new SgAddressOfOp(SgNULL_FILE, lhs); } else if (arrowexp) { thisptr = arrowexp->get_lhs_operand(); } else { assert (false); } } if (!funname2) { // std::cout << "Inline failed: not a call to a named function" << std::endl; return NULL; // Probably a call through a fun ptr } SgFunctionSymbol* funsym = 0; if (isSgFunctionRefExp(funname2)) funsym = isSgFunctionRefExp(funname2)->get_symbol(); else if (isSgMemberFunctionRefExp(funname2)) funsym = isSgMemberFunctionRefExp(funname2)->get_symbol(); else assert (false); assert (funsym); if (isSgMemberFunctionSymbol(funsym) && isSgMemberFunctionSymbol(funsym)->get_declaration()->get_functionModifier().isVirtual()) { // std::cout << "Inline failed: cannot inline virtual member functions" << std::endl; return NULL; } SgFunctionDeclaration* fundecl = funsym->get_declaration(); fundecl = fundecl ? isSgFunctionDeclaration(fundecl->get_definingDeclaration()) : NULL; SgFunctionDefinition* fundef = fundecl ? fundecl->get_definition() : NULL; if (!fundef) { // std::cout << "Inline failed: no definition is visible" << std::endl; return NULL; // No definition of the function is visible } if (!allowRecursion) { SgNode* my_fundef = funcall; while (my_fundef && !isSgFunctionDefinition(my_fundef)) { // printf ("Before reset: my_fundef = %p = %s \n",my_fundef,my_fundef->class_name().c_str()); my_fundef = my_fundef->get_parent(); ROSE_ASSERT(my_fundef != NULL); // printf ("After reset: my_fundef = %p = %s \n",my_fundef,my_fundef->class_name().c_str()); } // printf ("After reset: my_fundef = %p = %s \n",my_fundef,my_fundef->class_name().c_str()); assert (isSgFunctionDefinition(my_fundef)); if (isSgFunctionDefinition(my_fundef) == fundef) { std::cout << "Inline failed: trying to inline a procedure into itself" << std::endl; return NULL; } } SgVariableDeclaration* thisdecl = 0; SgName thisname("this__"); thisname << ++gensym_counter; SgInitializedName* thisinitname = 0; if (isSgMemberFunctionSymbol(funsym) && !fundecl->get_declarationModifier().get_storageModifier().isStatic()) { assert (thisptr != NULL); SgType* thisptrtype = thisptr->get_type(); const SgSpecialFunctionModifier& specialMod = funsym->get_declaration()->get_specialFunctionModifier(); if (specialMod.isConstructor()) { SgFunctionType* ft = funsym->get_declaration()->get_type(); ROSE_ASSERT (ft); SgMemberFunctionType* mft = isSgMemberFunctionType(ft); ROSE_ASSERT (mft); SgType* ct = mft->get_class_type(); thisptrtype = new SgPointerType(ct); } SgConstVolatileModifier& thiscv = fundecl->get_declarationModifier().get_typeModifier().get_constVolatileModifier(); // if (thiscv.isConst() || thiscv.isVolatile()) { FIXME thisptrtype = new SgModifierType(thisptrtype); isSgModifierType(thisptrtype)->get_typeModifier().get_constVolatileModifier() = thiscv; // } // cout << thisptrtype->unparseToString() << " --- " << thiscv.isConst() << " " << thiscv.isVolatile() << endl; SgAssignInitializer* assignInitializer = new SgAssignInitializer(SgNULL_FILE, thisptr); assignInitializer->set_endOfConstruct(SgNULL_FILE); #if 1 printf ("before new SgVariableDeclaration(): assignInitializer = %p assignInitializer->isTransformation() = %s \n",assignInitializer,assignInitializer->isTransformation() ? "true" : "false"); #endif thisdecl = new SgVariableDeclaration(SgNULL_FILE, thisname, thisptrtype, assignInitializer); #if 1 printf ("(after new SgVariableDeclaration(): assignInitializer = %p assignInitializer->isTransformation() = %s \n",assignInitializer,assignInitializer->isTransformation() ? "true" : "false"); #endif thisdecl->set_endOfConstruct(SgNULL_FILE); thisdecl->get_definition()->set_endOfConstruct(SgNULL_FILE); thisdecl->set_definingDeclaration(thisdecl); thisinitname = (thisdecl->get_variables()).back(); //thisinitname = lastElementOfContainer(thisdecl->get_variables()); // thisinitname->set_endOfConstruct(SgNULL_FILE); assignInitializer->set_parent(thisinitname); markAsTransformation(assignInitializer); // printf ("Built new SgVariableDeclaration #1 = %p \n",thisdecl); // DQ (6/23/2006): New test ROSE_ASSERT(assignInitializer->get_parent() != NULL); } // Get the list of actual argument expressions from the function call, which we'll later use to initialize new local // variables in the inlined code. We need to detach the actual arguments from the AST here since we'll be reattaching // them below (otherwise we would violate the invariant that the AST is a tree). SgFunctionDefinition* targetFunction = PRE::getFunctionDefinition(funcall); SgExpressionPtrList funargs = funcall->get_args()->get_expressions(); funcall->get_args()->get_expressions().clear(); BOOST_FOREACH (SgExpression *actual, funargs) actual->set_parent(NULL); // Make a copy of the to-be-inlined function so we're not modifying and (re)inserting the original. SgBasicBlock* funbody_raw = fundef->get_body(); SgInitializedNamePtrList& params = fundecl->get_args(); std::vector<SgInitializedName*> inits; SgTreeCopy tc; SgFunctionDefinition* function_copy = isSgFunctionDefinition(fundef->copy(tc)); ROSE_ASSERT (function_copy); SgBasicBlock* funbody_copy = function_copy->get_body(); renameLabels(funbody_copy, targetFunction); ASSERT_require(funbody_raw->get_symbol_table()->size() == funbody_copy->get_symbol_table()->size()); // We don't need to keep the copied SgFunctionDefinition now that the labels in it have been moved to the target function // (having it in the memory pool confuses the AST tests), but we must not delete the formal argument list or the body // because we need them below. if (function_copy->get_declaration()) { ASSERT_require(function_copy->get_declaration()->get_parent() == function_copy); function_copy->get_declaration()->set_parent(NULL); function_copy->set_declaration(NULL); } if (function_copy->get_body()) { ASSERT_require(function_copy->get_body()->get_parent() == function_copy); function_copy->get_body()->set_parent(NULL); function_copy->set_body(NULL); } delete function_copy; function_copy = NULL; #if 0 SgPragma* pragmaBegin = new SgPragma("start_of_inline_function", SgNULL_FILE); SgPragmaDeclaration* pragmaBeginDecl = new SgPragmaDeclaration(SgNULL_FILE, pragmaBegin); pragmaBeginDecl->set_endOfConstruct(SgNULL_FILE); pragmaBegin->set_parent(pragmaBeginDecl); pragmaBeginDecl->set_definingDeclaration(pragmaBeginDecl); funbody_copy->prepend_statement(pragmaBeginDecl); pragmaBeginDecl->set_parent(funbody_copy); #endif // In the to-be-inserted function body, create new local variables with distinct non-conflicting names, one per formal // argument and having the same type as the formal argument. Initialize those new local variables with the actual // arguments. Also, build a paramMap that maps each formal argument (SgInitializedName) to its corresponding new local // variable (SgVariableSymbol). ReplaceParameterUseVisitor::paramMapType paramMap; SgInitializedNamePtrList::iterator formalIter = params.begin(); SgExpressionPtrList::iterator actualIter = funargs.begin(); for (size_t argNumber=0; formalIter != params.end() && actualIter != funargs.end(); ++argNumber, ++formalIter, ++actualIter) { SgInitializedName *formalArg = *formalIter; SgExpression *actualArg = *actualIter; // Build the new local variable. // FIXME[Robb P. Matzke 2014-12-12]: we need a better way to generate a non-conflicting local variable name SgAssignInitializer* initializer = new SgAssignInitializer(SgNULL_FILE, actualArg, formalArg->get_type()); ASSERT_not_null(initializer); initializer->set_endOfConstruct(SgNULL_FILE); #if 1 printf ("initializer = %p initializer->isTransformation() = %s \n",initializer,initializer->isTransformation() ? "true" : "false"); #endif SgName shadow_name(formalArg->get_name()); shadow_name << "__" << ++gensym_counter; SgVariableDeclaration* vardecl = new SgVariableDeclaration(SgNULL_FILE, shadow_name, formalArg->get_type(), initializer); vardecl->set_definingDeclaration(vardecl); vardecl->set_endOfConstruct(SgNULL_FILE); vardecl->get_definition()->set_endOfConstruct(SgNULL_FILE); vardecl->set_parent(funbody_copy); // Insert the new local variable into the (near) beginning of the to-be-inserted function body. We insert them in the // order their corresponding actuals/formals appear, although the C++ standard does not require this order of // evaluation. SgInitializedName* init = vardecl->get_variables().back(); inits.push_back(init); initializer->set_parent(init); init->set_scope(funbody_copy); funbody_copy->get_statements().insert(funbody_copy->get_statements().begin() + argNumber, vardecl); SgVariableSymbol* sym = new SgVariableSymbol(init); paramMap[formalArg] = sym; funbody_copy->insert_symbol(shadow_name, sym); sym->set_parent(funbody_copy->get_symbol_table()); } // Similarly for "this". We create a local variable in the to-be-inserted function body that will be initialized with the // caller's "this". if (thisdecl) { thisdecl->set_parent(funbody_copy); thisinitname->set_scope(funbody_copy); funbody_copy->get_statements().insert(funbody_copy->get_statements().begin(), thisdecl); SgVariableSymbol* thisSym = new SgVariableSymbol(thisinitname); funbody_copy->insert_symbol(thisname, thisSym); thisSym->set_parent(funbody_copy->get_symbol_table()); ReplaceThisWithRefVisitor(thisSym).traverse(funbody_copy, postorder); } ReplaceParameterUseVisitor(paramMap).traverse(funbody_copy, postorder); SgName end_of_inline_name = "rose_inline_end__"; end_of_inline_name << ++gensym_counter; SgLabelStatement* end_of_inline_label = new SgLabelStatement(SgNULL_FILE, end_of_inline_name); end_of_inline_label->set_endOfConstruct(SgNULL_FILE); #if 0 printf ("\n\nCalling AST copy mechanism on a SgBasicBlock \n"); // Need to set the parent of funbody_copy to avoid error. funbody_copy->set_parent(funbody_raw->get_parent()); printf ("This is a copy of funbody_raw = %p to build funbody_copy = %p \n",funbody_raw,funbody_copy); printf ("funbody_raw->get_statements().size() = %" PRIuPTR " \n",funbody_raw->get_statements().size()); printf ("funbody_copy->get_statements().size() = %" PRIuPTR " \n",funbody_copy->get_statements().size()); printf ("funbody_raw->get_symbol_table()->size() = %d \n",(int)funbody_raw->get_symbol_table()->size()); printf ("funbody_copy->get_symbol_table()->size() = %d \n",(int)funbody_copy->get_symbol_table()->size()); printf ("Output the symbol table for funbody_raw \n"); funbody_raw->get_symbol_table()->print("debugging copy problem"); // printf ("Output the symbol table for funbody_copy \n"); // funbody_copy->get_symbol_table()->print("debugging copy problem"); SgProject* project_copy = TransformationSupport::getProject(funbody_raw); ROSE_ASSERT(project_copy != NULL); const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 4000; generateAstGraph(project_copy,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH); #endif funbody_copy->append_statement(end_of_inline_label); end_of_inline_label->set_scope(targetFunction); SgLabelSymbol* end_of_inline_label_sym = new SgLabelSymbol(end_of_inline_label); end_of_inline_label_sym->set_parent(targetFunction->get_symbol_table()); targetFunction->get_symbol_table()->insert(end_of_inline_label->get_name(), end_of_inline_label_sym); // To ensure that there is some statement after the label SgExprStatement* dummyStatement = SageBuilder::buildExprStatement(SageBuilder::buildNullExpression()); dummyStatement->set_endOfConstruct(SgNULL_FILE); funbody_copy->append_statement(dummyStatement); dummyStatement->set_parent(funbody_copy); #if 0 SgPragma* pragmaEnd = new SgPragma("end_of_inline_function", SgNULL_FILE); SgPragmaDeclaration* pragmaEndDecl = new SgPragmaDeclaration(SgNULL_FILE, pragmaEnd); pragmaEndDecl->set_endOfConstruct(SgNULL_FILE); pragmaEnd->set_parent(pragmaEndDecl); pragmaEndDecl->set_definingDeclaration(pragmaEndDecl); funbody_copy->append_statement(pragmaEndDecl); pragmaEndDecl->set_parent(funbody_copy); #endif ChangeReturnsToGotosPrevisitor previsitor = ChangeReturnsToGotosPrevisitor(end_of_inline_label, funbody_copy); replaceExpressionWithStatement(funcall, &previsitor); // Make sure the AST is consistent. To save time, we'll just fix things that we know can go wrong. For instance, the // SgAsmExpression.p_lvalue data member is required to be true for certain operators and is set to false in other // situations. Since we've introduced new expressions into the AST we need to adjust their p_lvalue according to the // operators where they were inserted. markLhsValues(targetFunction); #ifdef NDEBUG AstTests::runAllTests(SageInterface::getProject()); #endif #if 0 // DQ (4/6/2015): Adding code to check for consitancy of checking the isTransformed flag. ROSE_ASSERT(funcall != NULL); ROSE_ASSERT(funcall->get_parent() != NULL); ROSE_ASSERT(globalScope != NULL); // checkTransformedFlagsVisitor(funcall->get_parent()); checkTransformedFlagsVisitor(globalScope); #endif // DQ (4/7/2015): This fixes something I was required to fix over the weekend and which is fixed more directly, I think. // Mark the things we insert as being transformations so they get inserted into the output by backend() markAsTransformation(funbody_copy); return funbody_copy; }
int main(int argc, char *argv[]) { ss << "#include \"SgGraphTemplate.h\"\n"; ss << "#include \"graphProcessing.h\"\n"; ss << "#include \"staticCFG.h\"\n"; ss << "using namespace std;\n"; ss << "using namespace boost;\n"; //ss << "set<vector<string> > sssv;\n"; //ss << "vector<string> sss;\n"; ss << "typedef myGraph CFGforT;\n"; SgProject* proj = frontend(argc,argv); ROSE_ASSERT (proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); // stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string Cfilename = fileName+"."+ mainDef->get_declaration()->get_name() +"test.C"; // cfgToDot(mainDef,dotFileName1); //cfg->buildFullCFG(); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); //vis->constructPathAnalyzer(mg, true, 0, 0, true); // std::cout << "took: " << timeDifference(t2, t1) << std::endl; //cfg.clearNodesAndEdges(); //std::cout << "finished" << std::endl; // std::cout << "tltnodes: " << vis->tltnodes << " paths: " << vis->paths << std::endl; // delete vis; //} ss << "class visitorTraversal : public SgGraphTraversal<CFGforT>\n"; ss << " {\n"; ss << " public:\n"; ss << " vector<string> sss;\n"; ss << " set<vector<string> > sssv;\n"; //vis->constructPathAnalyzer(mg, true, 0, 0, true); ss << " void analyzePath(std::vector<VertexID>& pth);\n"; ss << " SgIncidenceDirectedGraph* g;\n"; ss << " myGraph* orig;\n"; ss << " StaticCFG::CFG* cfg;\n"; ss << " std::vector<std::vector<string> > paths;\n"; ss << " };\n"; ss << "void visitorTraversal::analyzePath(std::vector<VertexID>& pathR) {\n"; ss << " std::vector<string> path;\n"; ss << " for (unsigned int j = 0; j < pathR.size(); j++) {\n"; ss << " SgGraphNode* R = getGraphNode[pathR[j]];\n"; ss << " CFGNode cf = cfg->toCFGNode(R);\n"; ss << " string str = cf.toString();"; ss << "str.erase(std::remove(str.begin(), str.end(), '\\n'), str.end());\n"; ss << " path.push_back(str);\n"; ss << " }\n"; ss << " paths.push_back(path);\n"; ss << " // ROSE_ASSERT(sssv.find(path) != sssv.end());\n"; ss << "}\n"; //ss << "set<vector<string> > sssv;\n"; ss << "int main(int argc, char *argv[]) {\n"; ss << "SgProject* proj = frontend(argc,argv);\n"; ss << "ROSE_ASSERT (proj != NULL);\n"; ss << "SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj);\n"; ss << "SgFunctionDefinition* mainDef = mainDefDecl->get_definition();\n"; ss << "visitorTraversal* vis = new visitorTraversal();\n"; ss << "StaticCFG::CFG cfg(mainDef);\n"; ss << "stringstream ss;\n"; ss << "string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString());\n"; ss << "string dotFileName1=fileName+\".\"+ mainDef->get_declaration()->get_name() +\".dot\";\n"; ss << "cfgToDot(mainDef,dotFileName1);\n"; ss << "SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph();\n"; ss << "g = cfg.getGraph();\n"; ss << "myGraph* mg = new myGraph();\n"; ss << "mg = instantiateGraph(g, cfg);\n"; //ss << "vis->tltnodes = 0;\n"; //ss << "vis->paths = 0;\n"; ss << "std::set<std::vector<string> > sssv;\n"; ss << "std::vector<string> sss;\n"; vis->constructPathAnalyzer(mg, true, 0, 0, true); ss << "vis->sssv = sssv;\n"; ss << "vis->constructPathAnalyzer(mg, true, 0, 0, true);\n"; ss << "ROSE_ASSERT(vis->sssv.size() == vis->paths.size());\n"; ss << "std::cout << \"finished\" << std::endl;\n"; ss << "std::cout << \" paths: \" << vis->paths.size() << std::endl;\n"; ss << "delete vis;\n"; ss << "}\n"; string sst = ss.str(); ofstream myfile; myfile.open(Cfilename.c_str()); myfile << sst; myfile.close(); delete vis; return 0; }
void testOneFunction( std::string funcParamName, vector<string> argvList, bool debug, int nrOfNodes, multimap <int, vector<string> > resultsIn, multimap <int, vector<string> > resultsOut) { cout << " \n\n------------------------------------------\nrunning (variable)... " << argvList[1] << endl; // Build the AST used by ROSE SgProject* project = frontend(argvList); // Call the Def-Use Analysis DFAnalysis* defuse = new DefUseAnalysis(project); int val = defuse->run(debug); if (debug) std::cerr << ">Analysis run is : " << (val ? "failure" : "success" ) << " " << val << std::endl; if (val==1) exit(1); if (debug==false) defuse->dfaToDOT(); LivenessAnalysis* liv = new LivenessAnalysis(debug,(DefUseAnalysis*)defuse); std::vector <FilteredCFGNode < IsDFAFilter > > dfaFunctions; NodeQuerySynthesizedAttributeType vars = NodeQuery::querySubTree(project, V_SgFunctionDefinition); NodeQuerySynthesizedAttributeType::const_iterator i = vars.begin(); bool abortme=false; int hitIn=0; int hitOut=0; for (; i!=vars.end();++i) { SgFunctionDefinition* func = isSgFunctionDefinition(*i); std::string name = func->class_name(); string funcName = func->get_declaration()->get_qualified_name().str(); if (debug) cerr << " .. running live analysis for func : " << funcName << endl; FilteredCFGNode <IsDFAFilter> rem_source = liv->run(func,abortme); if (abortme) break; if (funcName!=funcParamName) { if (debug) cerr << " .. skipping live analysis check for func : " << funcName << endl; continue; } if (rem_source.getNode()!=NULL) dfaFunctions.push_back(rem_source); NodeQuerySynthesizedAttributeType nodes = NodeQuery::querySubTree(func, V_SgNode); // Edg3 mistakenly adds SgType nodes to the AST; Edg4 adds some also, but fewer. So we just remove them all. They // make no difference in the variable-liveness analysis anyway. nodes.erase(std::remove_if(nodes.begin(), nodes.end(), is_type_node), nodes.end()); SgFunctionDeclaration* decl = isSgFunctionDeclaration(func->get_declaration()); ROSE_ASSERT(decl); Rose_STL_Container<SgInitializedName*> args = decl->get_parameterList()->get_args(); if (debug) cerr <<"Found args : " << args.size() << endl; Rose_STL_Container<SgInitializedName*>::const_iterator it = args.begin(); for (;it!=args.end();++it) { nodes.push_back(*it); } if((int)nodes.size()-1!=nrOfNodes) { cerr << "Error :: Number of nodes = " << nodes.size()-1 << " should be : " << nrOfNodes << endl; exit(1); } else { if (debug) cerr << "Investigating nodes : " << nodes.size() << endl; } NodeQuerySynthesizedAttributeType::const_iterator nodesIt = nodes.begin(); for (; nodesIt!=nodes.end();++nodesIt) { SgNode* node = *nodesIt; ROSE_ASSERT(node); int tableNr = defuse->getIntForSgNode(node); std::vector<SgInitializedName*> in = liv->getIn(node); std::vector<SgInitializedName*> out = liv->getOut(node); std::vector<string> inName; std::vector<string> outName; std::vector<SgInitializedName*>::const_iterator itv = in.begin(); for (;itv!=in.end();++itv) { SgInitializedName* init = *itv; string name = init->get_name(); inName.push_back(name); } itv = out.begin(); for (;itv!=out.end();++itv) { SgInitializedName* init = *itv; string name = init->get_name(); outName.push_back(name); } std::sort(inName.begin(), inName.end()); std::sort(outName.begin(), outName.end()); multimap <int, vector<string> >::const_iterator k =resultsIn.begin(); for (;k!=resultsIn.end();++k) { int resNr = k->first; vector<string> results = k->second; if (debug) cerr << " ... containing nodes : " << results.size() << " node: " << node->class_name() << " tableNr : " << tableNr << " resNr : " << resNr << endl; if (tableNr==resNr) { std::sort(results.begin(), results.end()); if (results==inName) { if (debug) cerr <<"Contents in IN vector is correct! " << endl; } else { if (debug) { cerr << " >>>>>>>>>> Problem with contents for IN ! " << endl; cerr << " >>>>>>>>>> RESULT ... " << endl; } std::vector<string>::const_iterator itv = inName.begin(); for (;itv!=inName.end();++itv) { string name = *itv; if (debug) cerr << name << " " ; } if (debug) { cerr << endl; cerr << " >>>>>>>>>> USER ... " << endl; } itv = results.begin(); for (;itv!=results.end();++itv) { string name = *itv; if (debug) cerr << name << " " ; } if (debug) { cerr << endl; } exit(1); } if (results.size()==in.size()) { hitIn++; } if (debug) cout << " nodeNr: " << tableNr << ". ResultSize IN should be:" << results.size() << " - resultSize is: " << in.size() << " foundMatches == : " << hitIn << "/" << resultsIn.size() << endl; } } k =resultsOut.begin(); for (;k!=resultsOut.end();++k) { int resNr = k->first; vector<string> results = k->second; // cerr << " ... containing nodes : " << results.size() << " tableNr : " << tableNr << // " resNr : " << resNr << endl; if (tableNr==resNr) { std::sort(results.begin(), results.end()); if (results==outName) { if (debug) cerr <<"Contents in OUT vector is correct! " << endl; } else { if (debug) { cerr << " >>>>>>>>>> Problem with contents for OUT ! " << endl; cerr << " >>>>>>>>>> RESULT ... " << endl; } std::vector<string>::const_iterator itv = outName.begin(); for (;itv!=outName.end();++itv) { string name = *itv; if (debug) cerr << name << " " ; } if (debug) { cerr << endl; cerr << " >>>>>>>>>> USER ... " << endl; } itv = results.begin(); for (;itv!=results.end();++itv) { string name = *itv; if (debug) cerr << name << " " ; } if (debug) cerr << endl; exit(1); } if (results.size()==out.size()) { hitOut++; } if (debug) cout << " nodeNr: " << tableNr << ". ResultSize OUT should be:" << results.size() << " - resultSize is: " << out.size() << " foundMatches == : " << hitOut << "/" << resultsOut.size() << endl; } } if (hitIn==0 && hitOut==0) { if (debug) cout << " nodeNr: " << tableNr << " IN: " << hitIn << "/" << resultsIn.size() << " Out:" << hitOut << "/" << resultsOut.size() << endl; } } if (hitIn!=(int)resultsIn.size() || hitOut!=(int)resultsOut.size()) { cout << " Error: No hit! ... DFA values of node " << nrOfNodes << " are not correct! " << endl; exit(1); } } if (debug) cerr << "Writing out to var.dot... " << endl; std::ofstream f2("var.dot"); dfaToDot(f2, string("var"), dfaFunctions, (DefUseAnalysis*)defuse, liv); f2.close(); if (abortme) { cerr<<"ABORTING ." << endl; ROSE_ASSERT(false); // exit(1); } // iterate again and write second var.dot file i = vars.begin(); abortme=false; std::vector <FilteredCFGNode < IsDFAFilter > > dfaFunctions2; for (; i!=vars.end();++i) { SgFunctionDefinition* func = isSgFunctionDefinition(*i); std::string name = func->class_name(); string funcName = func->get_declaration()->get_qualified_name().str(); if (debug) cerr << " .. running live analysis for func (fixupStatementsINOUT): " << funcName << endl; FilteredCFGNode <IsDFAFilter> rem_source = liv->run(func,abortme); liv->fixupStatementsINOUT(func); if (rem_source.getNode()!=NULL) dfaFunctions2.push_back(rem_source); } if (debug) cerr << "Writing out to varFix.dot... " << endl; std::ofstream f3("varFix.dot"); dfaToDot(f3, string("varFix"), dfaFunctions2, (DefUseAnalysis*)defuse, liv); f3.close(); if (debug) std::cout << "Analysis test is success." << std::endl; }
int main ( int argc, char * argv[] ) { //init_poet(); // initialize poet if (argc <= 1) { PrintUsage(argv[0]); return -1; } #ifdef USE_OMEGA std::stringstream buffer; buffer << argv[argc-1] << std::endl; DepStats.SetFileName(buffer.str()); #endif vector<string> argvList(argv, argv + argc); CmdOptions::GetInstance()->SetOptions(argvList); OperatorSideEffectAnnotation* funcAnnot=OperatorSideEffectAnnotation::get_inst(); funcAnnot->register_annot(); LoopTransformInterface::set_sideEffectInfo(funcAnnot); ReadAnnotation::get_inst()->read(); if (DebugAnnot()) { funcAnnot->Dump(); } AssumeNoAlias aliasInfo; LoopTransformInterface::set_aliasInfo(&aliasInfo); LoopTransformInterface::cmdline_configure(argvList); SgProject *sageProject = new SgProject ( argvList); FixFileInfo(sageProject); int filenum = sageProject->numberOfFiles(); for (int i = 0; i < filenum; ++i) { SgSourceFile* sageFile = isSgSourceFile(sageProject->get_fileList()[i]); ROSE_ASSERT(sageFile != NULL); std::string fname = sageFile->get_file_info()->get_raw_filename(); fname=fname.substr(fname.find_last_of('/')+1); AutoTuningInterface tuning(fname); LoopTransformInterface::set_tuningInterface(&tuning); SgGlobal *root = sageFile->get_globalScope(); ROSE_ASSERT(root != NULL); SgDeclarationStatementPtrList declList = root->get_declarations (); for (SgDeclarationStatementPtrList::iterator p = declList.begin(); p != declList.end(); ++p) { SgFunctionDeclaration *func = isSgFunctionDeclaration(*p); if (func == 0) continue; SgFunctionDefinition *defn = func->get_definition(); if (defn == 0) continue; SgBasicBlock *stmts = defn->get_body(); AstInterfaceImpl scope(stmts); LoopTransformInterface::TransformTraverse(scope,AstNodePtrImpl(stmts)); } tuning.GenOutput(); } unparseProject(sageProject); #ifdef USE_OMEGA DepStats.SetDepChoice(0x1 | 0x2 | 0x4); DepStats.PrintResults(); #endif return 0; }
int main(int argc, char *argv[]) { struct timeval t1, t2; SgProject* proj = frontend(argc,argv); ROSE_ASSERT (proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); //cfg.buildFullCFG(); stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string dotFileName1=fileName+"."+ mainDef->get_declaration()->get_name() +".dot"; cfgToDot(mainDef,dotFileName1); //cfg->buildFullCFG(); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); vis->orig = mg; vis->tltnodes = 0; vis->paths = 0; //vis->firstPrepGraph(constcfg); t1 = getCPUTime(); vis->constructPathAnalyzer(mg, true, 0, 0, true); t2 = getCPUTime(); std::cout << "took: " << timeDifference(t2, t1) << std::endl; //cfg.clearNodesAndEdges(); std::cout << "finished" << std::endl; std::cout << "tltnodes: " << vis->tltnodes << " paths: " << vis->paths << std::endl; StaticCFG::CFG* cfgs[vis->defs.size()]; SgIncidenceDirectedGraph* sgs[vis->defs.size()]; myGraph* mgs[vis->defs.size()]; visitorTraversal* visps[vis->defs.size()]; for (size_t i = 0; i < vis->defs.size(); i++) { ROSE_ASSERT(isSgFunctionDefinition(vis->defs[i])); cfgs[i] = new StaticCFG::CFG(isSgFunctionDefinition(vis->defs[i])); //ROSE_ASSERT(gpart != NULL); sgs[i] = new SgIncidenceDirectedGraph(); sgs[i] = cfgs[i]->getGraph(); ROSE_ASSERT(sgs[i] != NULL); mgs[i] = new myGraph(); mgs[i] = instantiateGraph(sgs[i], *cfgs[i]); ROSE_ASSERT(mgs[i] != NULL); visps[i] = new visitorTraversal(); visps[i]->orig = mgs[i]; visps[i]->tltnodes = 0; visps[i]->paths = 0; std::cout << "fun: " << vis->defstr[i] << std::endl; visps[i]->constructPathAnalyzer(mgs[i], true, 0, 0, true); std::cout << "paths: " << visps[i]->paths << std::endl; string dotFileName1=vis->defs[i]->get_declaration()->get_name() +".dot"; cfgToDot(vis->defs[i],dotFileName1); } delete vis; }
int main( int argc, char * argv[] ) { // Build the AST used by ROSE SgProject* project = frontend(argc,argv); ROSE_ASSERT(project != NULL); // Build a list of functions within the AST and find all access functions // (function name starts with "get_" or "set_") // Build list using a query of the whole AST Rose_STL_Container<SgNode*> functionDefinitionList = NodeQuery::querySubTree (project,V_SgFunctionDefinition); // Build list using nested Queries (operating on return result of previous query) // Rose_STL_Container<SgNode*> accessFunctionsList; // accessFunctionsList = NodeQuery::queryNodeList (functionDeclarationList,&querySolverAccessFunctions); // printFunctionDeclarationList(accessFunctionsList); // Alternative form of same query building the list using a query of the whole AST // accessFunctionsList = NodeQuery::querySubTree (project,&querySolverAccessFunctions); // printFunctionDeclarationList(accessFunctionsList); int counter = 0; for (Rose_STL_Container<SgNode*>::iterator i = functionDefinitionList.begin(); i != functionDefinitionList.end(); i++) { SgFunctionDefinition* fnc = isSgFunctionDefinition(*i); stringstream ss; SgFunctionDeclaration* functionDeclaration = fnc->get_declaration(); string fileName= functionDeclaration->get_name().str();//StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string dotFileName1; ss << fileName << "." << counter << ".dot"; counter++; dotFileName1 = ss.str(); //SgFunctionDefinition* fnc = functionDeclaration->get_definition(); if (fnc != NULL) { StaticCFG::CFG* cfg = new StaticCFG::CFG(fnc); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); visitorTraversal* vis = new visitorTraversal(); g = cfg->getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, (*cfg)); vis->tltnodes = 0; vis->paths = 0; std::cout << dotFileName1 << std::endl; cfgToDot(fnc,dotFileName1); //vis->firstPrepGraph(constcfg); //t1 = getCPUTime(); vis->constructPathAnalyzer(mg, true, 0, 0, true); //t2 = getCPUTim std::cout << "function: " << fileName << std::endl; std::cout << "paths: " << vis->paths << std::endl; delete vis; delete cfg; delete g; delete mg; //std::cout << "took: " << timeDifference(t2, t1) << std::endl; } } SgProject* proj = project; SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); if (mainDefDecl != NULL) { SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); //cfg.buildFullCFG(); stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string dotFileName1=fileName+"."+ mainDef->get_declaration()->get_name() +".dot"; cfgToDot(mainDef,dotFileName1); //cfg->buildFullCFG(); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); vis->tltnodes = 0; vis->paths = 0; //vis->firstPrepGraph(constcfg); vis->constructPathAnalyzer(mg, true, 0, 0, true); //std::cout << "took: " << timeDifference(t2, t1) << std::endl; //cfg.clearNodesAndEdges(); std::cout << "finished" << std::endl; std::cout << "tltnodes: " << vis->tltnodes << " paths: " << vis->paths << std::endl; //std::cout << "ipaths: " << ipaths << std::endl; delete vis; } // Another way to query for collections of IR nodes VariantVector vv1 = V_SgClassDefinition; std::cout << "Number of class definitions in the memory pool is: " << NodeQuery::queryMemoryPool(vv1).size() << std::endl; // Another way to query for collections of multiple IR nodes. // VariantVector(V_SgType) is internally expanded to all IR nodes derived from SgType. VariantVector vv2 = VariantVector(V_SgClassDefinition) + VariantVector(V_SgType); std::cout << "Number of class definitions AND types in the memory pool is: " << NodeQuery::queryMemoryPool(vv2).size() << std::endl; // Note: Show composition of AST queries return 0; }
int main (int argc, char *argv[]) { vector<string> argvList(argv, argv+argc); //Processing debugging and annotation options autopar_command_processing(argvList); // enable parsing user-defined pragma if enable_diff is true // -rose:openmp:parse_only if (enable_diff) argvList.push_back("-rose:openmp:parse_only"); SgProject *project = frontend (argvList); ROSE_ASSERT (project != NULL); #if 1 // This has to happen before analyses are called. // For each loop VariantVector vv (V_SgForStatement); Rose_STL_Container<SgNode*> loops = NodeQuery::queryMemoryPool(vv); // normalize C99 style for (int i= x, ...) to C89 style: int i; (i=x, ...) // Liao, 10/22/2009. Thank Jeff Keasler for spotting this bug for (Rose_STL_Container<SgNode*>::iterator iter = loops.begin(); iter!= loops.end(); iter++ ) { SgForStatement* cur_loop = isSgForStatement(*iter); ROSE_ASSERT(cur_loop); SageInterface::normalizeForLoopInitDeclaration(cur_loop); } #endif //Prepare liveness analysis etc. initialize_analysis (project,false); // For each source file in the project SgFilePtrList & ptr_list = project->get_fileList(); for (SgFilePtrList::iterator iter = ptr_list.begin(); iter!=ptr_list.end(); iter++) { SgFile* sageFile = (*iter); SgSourceFile * sfile = isSgSourceFile(sageFile); ROSE_ASSERT(sfile); SgGlobal *root = sfile->get_globalScope(); SgDeclarationStatementPtrList& declList = root->get_declarations (); bool hasOpenMP= false; // flag to indicate if omp.h is needed in this file //For each function body in the scope for (SgDeclarationStatementPtrList::iterator p = declList.begin(); p != declList.end(); ++p) { SgFunctionDeclaration *func = isSgFunctionDeclaration(*p); if (func == 0) continue; SgFunctionDefinition *defn = func->get_definition(); if (defn == 0) continue; //ignore functions in system headers, Can keep them to test robustness if (defn->get_file_info()->get_filename()!=sageFile->get_file_info()->get_filename()) continue; SgBasicBlock *body = defn->get_body(); // For each loop Rose_STL_Container<SgNode*> loops = NodeQuery::querySubTree(defn,V_SgForStatement); if (loops.size()==0) continue; #if 0 // Moved to be executed before running liveness analysis. // normalize C99 style for (int i= x, ...) to C89 style: int i; (i=x, ...) // Liao, 10/22/2009. Thank Jeff Keasler for spotting this bug for (Rose_STL_Container<SgNode*>::iterator iter = loops.begin(); iter!= loops.end(); iter++ ) { SgForStatement* cur_loop = isSgForStatement(*iter); ROSE_ASSERT(cur_loop); SageInterface::normalizeForLoopInitDeclaration(cur_loop); } #endif // X. Replace operators with their equivalent counterparts defined // in "inline" annotations AstInterfaceImpl faImpl_1(body); CPPAstInterface fa_body(&faImpl_1); OperatorInlineRewrite()( fa_body, AstNodePtrImpl(body)); // Pass annotations to arrayInterface and use them to collect // alias info. function info etc. ArrayAnnotation* annot = ArrayAnnotation::get_inst(); ArrayInterface array_interface(*annot); array_interface.initialize(fa_body, AstNodePtrImpl(defn)); array_interface.observe(fa_body); //FR(06/07/2011): aliasinfo was not set which caused segfault LoopTransformInterface::set_aliasInfo(&array_interface); // X. Loop normalization for all loops within body NormalizeForLoop(fa_body, AstNodePtrImpl(body)); for (Rose_STL_Container<SgNode*>::iterator iter = loops.begin(); iter!= loops.end(); iter++ ) { SgNode* current_loop = *iter; //X. Parallelize loop one by one // getLoopInvariant() will actually check if the loop has canonical forms // which can be handled by dependence analysis SgInitializedName* invarname = getLoopInvariant(current_loop); if (invarname != NULL) { hasOpenMP = ParallelizeOutermostLoop(current_loop, &array_interface, annot); } else // cannot grab loop index from a non-conforming loop, skip parallelization { if (enable_debug) cout<<"Skipping a non-canonical loop at line:"<<current_loop->get_file_info()->get_line()<<"..."<<endl; hasOpenMP = false; } }// end for loops } // end for-loop for declarations // insert omp.h if needed if (hasOpenMP && !enable_diff) { SageInterface::insertHeader("omp.h",PreprocessingInfo::after,false,root); if (enable_patch) generatePatchFile(sfile); } // compare user-defined and compiler-generated OmpAttributes if (enable_diff) diffUserDefinedAndCompilerGeneratedOpenMP(sfile); } //end for-loop of files // Qing's loop normalization is not robust enough to pass all tests //AstTests::runAllTests(project); release_analysis(); //project->unparse(); return backend (project); }