AST_Graph::nodePartOfGraph::result_type AST_Graph::nodePartOfGraph::operator()(pair<SgNode*,std::string>& x) { result_type functionalReturn; functionalReturn.addToGraph = true; functionalReturn.DOTOptions = ""; functionalReturn.DOTLabel = ""; SgLocatedNode* locatedNode = isSgLocatedNode(x.first); if(locatedNode!=NULL) { Sg_File_Info* fileInfo = locatedNode->get_file_info(); std::string filename(Rose::utility_stripPathFromFileName(fileInfo->get_filename())); if (filename.find("rose_edg_required_macros_and_functions.h") != std::string::npos) { functionalReturn.addToGraph = false; } if (fileInfo->isCompilerGenerated()==true) { // std::cout << "Is compiler generated\n"; functionalReturn.addToGraph = false; } } return functionalReturn; }
void StaticConstructorTraversal::visit(SgNode *n) { // Get declared variables SgInitializedName *vName = isSgInitializedName(n); if (vName && !isAcreIgnore(vName->get_declaration())) { Sg_File_Info *fInfo = vName->get_file_info(); SgScopeStatement *scope = vName->get_scope(); // Find global variables (variables in namespaces count, e.g. std) if (!fInfo->isCompilerGenerated() && (isSgGlobal(scope) || isSgNamespaceDefinitionStatement(scope))) { // Walk typedefs until reach pointer to base type SgTypedefType *tdType = isSgTypedefType(vName->get_type()); while (tdType && isSgTypedefType(tdType->get_base_type())) tdType = isSgTypedefType(tdType->get_base_type()); // Determine if type is a class (i.e. type with a constructor) SgClassType *cType = isSgClassType(vName->get_type()); if (tdType) cType = isSgClassType(tdType->get_base_type()); // Output location of globals with a static constructor if (cType) { *out << "Static Constructor Violation: " << fInfo->get_filename() << " @ " << fInfo->get_line() << "\n"; } } } }
/** Show an error message about a node. */ static void emit_node_mesg(SgNode *node, const std::string &mesg="") { Sg_File_Info *loc = isSgLocatedNode(node) ? isSgLocatedNode(node)->get_startOfConstruct() : NULL; std::string filename = loc ? loc->get_filenameString() : "__UNKNOWN_FILE__"; int lno = loc ? loc->get_line() : 0; int cno = loc ? loc->get_col() : 0; std::cerr <<filename <<":" <<lno <<"." <<cno <<": " <<(mesg.empty() ? "error" : mesg) <<"\n"; }
DOTInheritedAttribute AstDOTGeneration::evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia) { // I think this may no longer be required, but I will leave it in place for now visitedNodes.insert(node); // printf ("AstDOTGeneration::evaluateInheritedAttribute(): node = %s \n",node->class_name().c_str()); // We might not want to increment the trace position information for // the IR nodes from rose_edg_required_macros_and_functions.h // ia.tdbuTracePos = tdbuTrace++; // ia.tdTracePos = tdTrace++; // DQ (5/3/2006) // We put macros and functions required for GNU compatability in the file: // rose_edg_required_macros_and_functions.h // and we want to avoid generating nodes for these within visualizations of the AST. // Once EDG supports these functions (we have collected the onese missed by EDG here) // this file will not be required. We could filter on declaration first to avoid // lots of string comparision. Or use a static pointer to save the first fileInfo // from "rose_edg_required_macros_and_functions.h" and then use the // Sg_File_Info::sameFile() function (this reduces to an integer comparision internally). Sg_File_Info* fileInfo = node->get_file_info(); if (fileInfo != NULL) { // Build factored versions of the rather numerous tests (we are now not // able to rely on short-circuit evaluation which makes the code easier // to debug using valgrind). bool isCompilerGeneratedOrPartOfTransformation = fileInfo->isCompilerGenerated(); // DQ (5/3/2006): All constructs from the rose_edg_required_macros_and_functions.h // file are marked as compiler generated. These are declarations required for GNU // compatability and we would like to have them be ignored because they should be // considered builtin and not explicitly represented. In a sense this file is special. // Not that if we traverse the AST without constraint then we traverse these IR nodes. if (isCompilerGeneratedOrPartOfTransformation == true) { std::string targetFileName = "rose_edg_required_macros_and_functions.h"; std::string rawFileName = node->get_file_info()->get_raw_filename(); std::string filenameWithoutPath = StringUtility::stripPathFromFileName(rawFileName); if (filenameWithoutPath == targetFileName) ia.skipSubTree = true; } } // We might not want to increment the trace position information for // the IR nodes from rose_edg_required_macros_and_functions.h if (ia.skipSubTree == false) { ia.tdbuTracePos = tdbuTrace++; ia.tdTracePos = tdTrace++; } return ia; }
std::ostream &operator<<(std::ostream &os, SgNode *node) { os << node->class_name(); if (SgLocatedNode *ln = isSgLocatedNode(node)) { Sg_File_Info *fi = ln->get_file_info(); os << "(" << fi->get_filename() << ":" << fi->get_line() << ":" << fi->get_col() << ") "; } os << node->unparseToCompleteString(); return os; }
// debugging function of a node location string printPosition(SgNode *node) { ostringstream out; out << "("; Sg_File_Info *startinf = node->get_startOfConstruct(); Sg_File_Info *endinf = node->get_endOfConstruct(); if(startinf) out << startinf->get_filename() << ":" << startinf->get_line(); if( endinf) { out << "- " << startinf->get_filename() << ":" << startinf->get_line(); } out << ") "; return out.str(); }
SgStatement* returnFirstOrLastStatementFromCurrentFile ( SgStatement* target, const SgStatementPtrList & statementList, bool findFirstStatement ) { // printf ("Inside of returnFirstOrLastStatement \n"); // Find the first statement from the current file being processed SgStatement* statement = NULL; if (findFirstStatement) { SgStatementPtrList::const_iterator statementIterator = statementList.begin(); while (statementIterator != statementList.end()) { statement = *statementIterator; ROSE_ASSERT (statement != NULL); Sg_File_Info* fileInfo = statement->get_file_info(); ROSE_ASSERT (fileInfo != NULL); string filename = fileInfo->get_filename(); if (filename == ROSE::getFileNameByTraversalBackToFileNode(target)) { // printf ("Found the first statement in this file = %s \n",filename.c_str()); // printf ("First statement = %s \n",statement->unparseToCompleteString().c_str()); break; } statementIterator++; } } else { SgStatementPtrList::const_reverse_iterator statementIterator = statementList.rbegin(); while (statementIterator != statementList.rend()) { statement = *statementIterator; ROSE_ASSERT (statement != NULL); Sg_File_Info* fileInfo = statement->get_file_info(); ROSE_ASSERT (fileInfo != NULL); string filename = fileInfo->get_filename(); if (filename == ROSE::getFileNameByTraversalBackToFileNode(target)) { // printf ("Found the last statement in this file = %s \n",filename.c_str()); // printf ("First statement = %s \n",statement->unparseToCompleteString().c_str()); break; } statementIterator++; } } ROSE_ASSERT (statement != NULL); return statement; }
int main(int argc, char * argv[]) { SgProject* project = frontend(argc,argv); std::ofstream report_file; report_file.open(((*project)[0]->getFileName() + ".report").c_str()); if (report_file.is_open()) { PolyhedralModelisation poly_model; poly_model.traverse(project); std::set<PolyhedralElement *> collection; poly_model.collectPolyhedralElement(collection, true, false, true, true, false); // default arguments... std::set<PolyhedralElement *>::iterator it; for (it = collection.begin(); it != collection.end(); it++) { const PolyhedralControl * control = dynamic_cast<const PolyhedralControl *>(*it); if (control == NULL) continue; SgFunctionDefinition * func_def = isSgFunctionDefinition(control->associated_node); if (func_def == NULL) continue; SgFunctionDeclaration * func_decl = isSgFunctionDeclaration(func_def->get_declaration()); if (func_decl == NULL) continue; if (!func_decl->get_functionModifier().isCudaKernel()) continue; Sg_File_Info * fi = func_def->get_startOfConstruct(); report_file << "Found: " << func_decl->get_name() << " at " << fi->get_filenameString() << ":" << fi->get_line() << std::endl; report_file << "\tStructure:" << std::endl; (*it)->print(report_file, "\t\t"); report_file << std::endl; report_file << "\tAccesses:" << std::endl; std::set<Access *> accesses; (*it)->collectAccess(accesses); std::set<Access *>::iterator it_access; for (it_access = accesses.begin(); it_access != accesses.end(); it_access++) { (*it_access)->print(report_file, "\t\t"); } report_file << std::endl; report_file << std::endl; } } else std::cerr << "Cannot open " << (*project)[0]->getFileName() << ".report to save the analysis report..." << std::endl; return 0; }
//The argument to the function is filterOnNodes::result_type filterOnNodes::operator()(filterOnNodes::argument_type x) const { AST_Graph::FunctionalReturnType returnValue; //Determine if the node is to be added to the graph. true=yes returnValue.addToGraph = true; //set colors etc. for the graph Node returnValue.DOTOptions = "shape=polygon,regular=0,URL=\"\\N\",tooltip=\"more info at\\N\",sides=4,peripheries=1,color=\"Blue\",fillcolor=green,fontname=\"7x13bold\",fontcolor=black,style=filled"; if( isSgProject(x.first) != NULL ) returnValue.DOTOptions = "shape=ellipse,regular=0,URL=\"\\N\",tooltip=\"more info at\\N\",sides=4,peripheries=1,color=\"Blue\",fillcolor=yellow,fontname=\"7x13bold\",fontcolor=black,style=filled"; //Filter out SgSymbols from the graph if ( isSgSymbol(x.first) != NULL ) returnValue.addToGraph = false; if ( isSgType(x.first) != NULL ) returnValue.addToGraph = false; //Filter out compiler generated nodes SgLocatedNode* locatedNode = isSgLocatedNode(x.first); if ( locatedNode != NULL ) { Sg_File_Info* fileInfo = locatedNode->get_file_info(); std::string filename(Rose::utility_stripPathFromFileName(fileInfo->get_filename())); if (filename.find("rose_edg_macros_and_functions_required_for_gnu.h") != std::string::npos) { returnValue.addToGraph = false; } if (fileInfo->isCompilerGenerated()==true) { // std::cout << "Is compiler generated\n"; returnValue.addToGraph = false; } } return returnValue; }
void RoseFileComboBox::setProject(SgProject * proj) { clear(); //delete all combobox entries project=proj; if(project==NULL) return; //Add Entries to the combobox for(int i=0; i < project->numberOfFiles(); i++) { Sg_File_Info * fi = (*project)[i]->get_file_info(); QFileInfo qFi; QVariant fileId (fi->get_file_id()); qFi.setFile(fi->get_filenameString().c_str()); if(dispOnlyFilename) addItem(qFi.fileName(),-1); else addItem(qFi.filePath(),-1); std::map< int, std::string > map = fi->get_fileidtoname_map(); typedef std::map<int,std::string>::iterator MapIter; for( MapIter iter = map.begin(); iter != map.end(); ++iter ) { qFi.setFile( iter->second.c_str()); QString dispString; if(dispOnlyFilename) dispString=qFi.fileName(); else dispString=qFi.filePath(); addItem(QString(" ")+dispString,iter->first); } } }
void createMap::printNodeToTokenMap() { #ifndef USE_ROSE #ifndef ROSE_SKIP_COMPILATION_OF_WAVE // If we are using ROSE to compile ROSE source code then the Wave support is not present. std::cout << "BEGIN printing node to token map" << std::endl; std::cout << "SIZE: " << nodeToTokenMap.size() << std::endl; for(map<SgNode*,std::pair<int,int> >::iterator map_it = nodeToTokenMap.begin(); map_it != nodeToTokenMap.end(); ++map_it ){ Sg_File_Info* fileInfo = map_it->first->get_file_info(); token_type currentBeginToken = tokenStream[map_it->second.first]; token_type currentEndToken = tokenStream[map_it->second.second]; string nodeFilename = fileInfo->get_filenameString(); int nodeLine = fileInfo->get_line(); int nodeColumn = fileInfo->get_col(); std::cout << "Position of node is filename " << nodeFilename << " line " << nodeLine << " column " << nodeColumn << std::endl; string beginTokenFilename = currentBeginToken.get_position().get_file().c_str(); int beginTokenLine = currentBeginToken.get_position().get_line(); int beginTokenColumn = currentBeginToken.get_position().get_column(); std::cout << "Begin position of token is filename " << beginTokenFilename << " line " << beginTokenLine << " column " << beginTokenColumn << std::endl; string endTokenFilename = currentEndToken.get_position().get_file().c_str(); int endTokenLine = currentEndToken.get_position().get_line(); int endTokenColumn = currentEndToken.get_position().get_column(); std::cout << "End position of token is filename " << endTokenFilename << " line " << endTokenLine << " column " << endTokenColumn << std::endl; std::cout << std::endl; }; std::cout << "END printing node to token map" << std::endl; #endif #endif }
void loopTraversal::visit(SgNode *node) { Sg_File_Info *info = NULL; SgNode *parent = NULL; info = node->get_file_info(); /* Find code fragment for bottlenecks type 'loop' in C */ if ((isSgForStatement(node)) && (info->get_line() == globals.linenumber)) { /* Found a C loop on the exact line number */ printf("found a loop on (%s:%d) looking for the parent loop\n", info->get_filename(), info->get_line()); parent = node->get_parent(); info = parent->get_file_info(); /* It is a basic block. Who is this basic block's parent? */ if (NULL != isSgBasicBlock(parent)) { parent = parent->get_parent(); } /* Is it a for/do/while? */ if (isSgForStatement(parent)) { /* The parent is a loop */ printf("parent loop found on (%s:%d)\n", info->get_filename(), info->get_line()); /* Do the interchange */ rc = loopInterchange(isSgForStatement(parent), 2, 1); } } }
FindSmallestStatementsInh FindSmallestStatements::evaluateInheritedAttribute(SgNode* n, FindSmallestStatementsInh inheritedAttribute) { //If the node should be consired as a topmost node if(inheritedAttribute.inSubtreeOfStatement == false && isSgLocatedNode(n)) { Sg_File_Info* thisNodePos = n->get_file_info(); #if 0 std::string pos; thisNodePos->display(pos); std::cerr << "************************\n"; std::cerr << "NodePosDisp " << n->class_name() << pos << std::endl; std::cerr << "************************\n"; #endif //If positions are the same add to list of statements switch(n->variantT()) { case V_SgExprStatement: std::cout << "Skipping this node" << std::endl; break; default: { if( macroCallInfo->get_file_id() == thisNodePos->get_file_id() && macroCallInfo->get_line() == thisNodePos->get_line() && macroCallInfo->get_col() == thisNodePos->get_col() ) { if( find_all == false ) inheritedAttribute.inSubtreeOfStatement = true; matchingCalls.push_back(n); } break; } } } return inheritedAttribute; }
static void RegisterItem(SgFunctionDeclaration *funcDecl, SgBasicBlock *funcBody, SgStatement *stmt, const char *registerFuncName, SgType *varType, SgVariableDeclaration *var, bool beforeStmt) { Sg_File_Info *fileInfo ; if (!isSgForStatement(stmt)) { fileInfo = stmt->get_file_info() ; } else { fileInfo = (beforeStmt ? stmt->get_startOfConstruct() : stmt->get_endOfConstruct()) ; } SgFunctionCallExp *registerCall = buildFunctionCallExp( SgName(registerFuncName), varType, buildExprListExp( buildStringVal(fileInfo->get_filenameString()), buildStringVal(funcDecl->get_name().str()), buildIntVal(fileInfo->get_line()) ), funcBody ) ; SgExprStatement *varAssign = buildExprStatement(buildAssignOp(buildVarRefExp(var), registerCall)) ; SgExpression *varEqualZero = buildEqualityOp(buildVarRefExp(var), buildIntVal(0)) ; SgIfStmt *statement = buildIfStmt( varEqualZero, varAssign, NULL ) ; stmt->get_scope()->insert_statement(stmt, statement, beforeStmt) ; return ; }
string AstPDFGeneration_private::get_bookmark_name(SgNode* node) { string nodefilename="--not initialized--"; string bookmarktext; { ostringstream ss; ss << node->sage_class_name() << " "; SgLocatedNode* sgLocNode = dynamic_cast<SgLocatedNode*> (node); if(sgLocNode) { Sg_File_Info* fi = sgLocNode->get_file_info(); if(fi) { // ss << "(" << fi->get_line() << "," << fi->get_col() << ") in \"" << fi->get_filename() << "\""; // nodefilename=string(fi->get_filename()); #if 1 // if (fi->isCompilerGenerated()) // ss << " compilerGenerated "; if (fi->isTransformation()) ss << " transformation " ; if (fi->isOutputInCodeGeneration()) ss<< " unparsable "; ss << "(" << fi->get_line() << "," << fi->get_col() << ") in \"" << fi->get_filename() << "\""; #endif nodefilename=string(fi->get_filename()); } else { ss << "(BUG)"; } } else { ss << ""; // provide no explicit info about the lack of file_info } bookmarktext=ss.str(); } return bookmarktext; }
/* recommenderTraversal::visit */ void recommenderTraversal::visit(SgNode *node) { Sg_File_Info *info = NULL; SgFunctionDefinition *function = NULL; SgForStatement *c_loop = NULL; SgNode *grandparent = NULL; SgNode *parent = NULL; int node_found = 0; info = node->get_file_info(); /* Find code fragment for bottlenecks type 'loop' in C */ if ((isSgForStatement(node)) && (info->get_line() == fragment->line) && (PERFEXPERT_HOTSPOT_LOOP == fragment->type)) { /* Found a C loop on the exact line number */ OUTPUT_VERBOSE((8, " [loop] %s (line %d)", _GREEN((char *)"found"), info->get_line())); /* Extract the loop fragment */ if (PERFEXPERT_SUCCESS != output_fragment(node, info, fragment)) { OUTPUT(("%s", _ERROR((char *)"extracting fragment"))); rc = PERFEXPERT_ERROR; return; } /* Save the fragment path and filename */ PERFEXPERT_ALLOC(char, fragment->fragment_file, (strlen(globals.workdir) + strlen(FRAGMENTS_DIR) + strlen(fragment->file) + 15)); sprintf(fragment->fragment_file, "%s/%s/%s_%d", globals.workdir, FRAGMENTS_DIR, fragment->file, fragment->line); /* What is the loop detph and who is parent node */ if (2 <= fragment->depth) { parent = node->get_parent(); /* It is a basic block. Who is this basic block's parent? */ if (NULL != isSgBasicBlock(parent)) { parent = parent->get_parent(); } /* Is it a for/do/while? */ if (isSgForStatement(parent)) { info = parent->get_file_info(); fragment->outer_loop_line = info->get_line(); /* The parent is a loop */ OUTPUT_VERBOSE((8, " [parent loop] %s (line %d)", _GREEN((char *)"found"), fragment->outer_loop_line)); /* Extract the parent loop fragment */ if (PERFEXPERT_SUCCESS != output_fragment(parent, info, fragment)) { OUTPUT(("%s", _ERROR((char *)"extracting fragment"))); rc = PERFEXPERT_ERROR; return; } /* Save the fragment path and filename */ PERFEXPERT_ALLOC(char, fragment->outer_loop_fragment_file, (strlen(globals.workdir) + strlen(FRAGMENTS_DIR) + strlen(fragment->file) + 15)); sprintf(fragment->outer_loop_fragment_file, "%s/%s/%s_%d", globals.workdir, FRAGMENTS_DIR, fragment->file, fragment->outer_loop_line); /* What is the loop detph and who is the grandparent node */ if (3 <= fragment->depth) { grandparent = parent->get_parent(); /* It is a basic block. Who is this basic block's parent? */ if (NULL != isSgBasicBlock(grandparent)) { grandparent = grandparent->get_parent(); } /* Is it a for/do/while? */ if (isSgForStatement(grandparent)) { info = grandparent->get_file_info(); fragment->outer_outer_loop_line = info->get_line(); /* The grandparent is a loop */ OUTPUT_VERBOSE((8, " [grandparent loop] %s (line %d)", _GREEN((char *)"found"), fragment->outer_outer_loop_line)); /* Extract the parent loop fragment */ if (PERFEXPERT_SUCCESS != output_fragment(grandparent, info, fragment)) { OUTPUT(("%s", _ERROR((char *)"extracting fragment"))); rc = PERFEXPERT_ERROR; return; } /* Save the fragment path and filename */ PERFEXPERT_ALLOC(char, fragment->outer_outer_loop_fragment_file, (strlen(globals.workdir) + strlen(FRAGMENTS_DIR) + strlen(fragment->file) + 15)); sprintf(fragment->outer_outer_loop_fragment_file, "%s/%s/%s_%d", globals.workdir, FRAGMENTS_DIR, fragment->file, fragment->outer_outer_loop_line); } } }
void AstPDFGeneration_private::edit_page(size_t pageNumber, SgNode* node, PDFInheritedAttribute inheritedValue) { // JW (added by DQ 7/23/2004): Adds address of each IR node to the top of the page HPDF_Page_SetRGBFill(currentPage, 1, 0, 0); // DQ (1/20/2006): Modified for 64 bit machines // ostringstream _ss; _ss << "0x" << std::hex << (int)node; ostringstream _ss; _ss << "pointer:" << std::hex << node; HPDF_Page_ShowTextNextLine(currentPage, _ss.str().c_str()); // Liao, 2/11/2009, move some essential information from bookmark into the page also // since some deep levels of bookmarks cannot display long lines properly by acrobat reader HPDF_Page_ShowTextNextLine(currentPage, node->sage_class_name()); SgLocatedNode* sgLocNode = dynamic_cast<SgLocatedNode*> (node); if(sgLocNode) { Sg_File_Info* fi = sgLocNode->get_file_info(); ostringstream temp; temp<<fi->get_filename()<<" "<<fi->get_line()<<":"<<fi->get_col(); if(fi) HPDF_Page_ShowTextNextLine(currentPage,temp.str().c_str()); if (fi->isTransformation()) HPDF_Page_ShowTextNextLine(currentPage,"IsTransformation:1"); else HPDF_Page_ShowTextNextLine(currentPage,"IsTransformation:0"); if (fi->isOutputInCodeGeneration()) HPDF_Page_ShowTextNextLine(currentPage,"IsOutputInCodeGeneration:1"); else HPDF_Page_ShowTextNextLine(currentPage,"IsOutputInCodeGeneration:0"); } if (isSgDeclarationStatement(node)) { HPDF_Page_ShowTextNextLine(currentPage, ("Declaration mangled name: " + isSgDeclarationStatement(node)->get_mangled_name().getString()).c_str()); #if 0 // not necessary, p_name field gives the similar information if (isSgDeclarationStatement(node)->hasAssociatedSymbol()) { SgSymbol *symbol = isSgDeclarationStatement(node)->get_symbol_from_symbol_table (); if (symbol) HPDF_Page_ShowTextNextLine(currentPage, ("Symbol name: " + symbol->get_name().getString()).c_str()); } #endif } // JW hack to show expression types if (isSgExpression(node)) HPDF_Page_ShowTextNextLine(currentPage, ("Expression type: " + isSgExpression(node)->get_type()->unparseToString()).c_str()); HPDF_Page_SetRGBFill(currentPage, 0, 1, 0); if (inheritedValue.parentPage==NULL) { HPDF_Page_ShowTextNextLine(currentPage, ""); HPDF_Page_ShowTextNextLine(currentPage, " root node"); } else { HPDF_Page_ShowTextNextLine(currentPage, ""); HPDF_Page_ShowTextNextLine(currentPage, " "); create_textlink("Click here to go to the parent node", inheritedValue.parentPage, 9); } HPDF_Page_ShowTextNextLine(currentPage, ""); HPDF_Page_ShowTextNextLine(currentPage, ""); // generate RTI information for SgNode { RTIReturnType rti=node->roseRTI(); for(RTIReturnType::iterator i=rti.begin(); i<rti.end(); i++) { if (strlen(i->type) >= 7 && strncmp(i->type, "static ", 7) == 0) { continue; // Skip static members } HPDF_Page_SetRGBFill(currentPage, 0.5, 0, 0.1); HPDF_Page_ShowTextNextLine(currentPage, i->type); HPDF_Page_ShowText(currentPage, " "); HPDF_Page_SetRGBFill(currentPage, 0.0, 0.5, 0.5); HPDF_Page_ShowText(currentPage, i->name); HPDF_Page_ShowText(currentPage, " : "); HPDF_Page_SetRGBFill(currentPage, 0.0, 0.0, 0.0); string value=i->value; if (value.size() >= 80) { // HPDF doesn't like strings > 64k, and we probably shouldn't be trying to print them anyway; this trims things to a reasonable length value = "<too long>: " + value.substr(0, 80); } if (value.size() >= 80) { value = "<too long>: " + value.substr(0, 80); } AstNodeVisitMapping::MappingType::iterator mapit; // ensure that mapping value exists (otherwise it would be added to the map) // and decide whether to create a link to a page (representing a node) or not mapit=addrPageMapping.find(value); if (mapit!=addrPageMapping.end()) { size_t destPageNum = mapit->second; ROSE_ASSERT (destPageNum < pageDests.size()); create_textlink(value.c_str(), pageDests[destPageNum] /* targetpage */); } else { HPDF_Page_ShowText(currentPage,value.c_str()); } } } // generate AstAttribute information { // printf ("In AstPDFGeneration_private::edit_page(): using new attribute interface \n"); // if (node->get_attribute() != NULL) #if 0 if (node->getAttribute() != NULL) { AstAttributeMechanism::AttributeIdentifiers aidents = node->attribute().getAttributeIdentifiers(); PDF_continue_text(pdfFile, ""); // next line PDF_setrgbcolor(pdfFile, 0.0, 0.2, 0.7); PDF_continue_text(pdfFile, "AstAttributes:"); // next line for (AstAttributeMechanism::AttributeIdentifiers::iterator it = aidents.begin(); it != aidents.end(); it++) { PDF_continue_text(pdfFile, ""); // next line PDF_setrgbcolor(pdfFile, 0.0, 0.2, 0.7); PDF_show(pdfFile,((*it)+": ").c_str()); PDF_setrgbcolor(pdfFile, 0.0, 0.0, 0.0); // float textxpos=PDF_get_value(pdfFile,"textx",0.0); // float textypos=PDF_get_value(pdfFile,"texty",0.0); string attributeValue = (node->attribute()[*it])->toString(); // split string into different substrings separated by newlines string substring=""; int oldpos=0; int newpos; do { newpos=attributeValue.find('\n', oldpos); substring=attributeValue.substr(oldpos,newpos-oldpos); if(oldpos==0) PDF_show(pdfFile, substring.append(" ").c_str()); else PDF_continue_text(pdfFile, substring.c_str()); oldpos = newpos+1; // go to next '\n' and skip it } // DQ (8/9/2005): Suggested fix from Rich (fixes infinite loop where AST Attributes are attached) // while( newpos < (int) attributeValue.size()); while( newpos < (int) attributeValue.size() && newpos >= 0 ); // PDF_show_boxed(pdfFile, attributeValue.c_str(), textxpos, textypos, 0, 0, "left", ""); } } #else // DQ (4/10/2006): New AstAttribute Interface (but access the AstAttributeMechanism directly // since "getAttributeIdentifiers()" is not in the interface implemented at the IR nodes). if (node->get_attributeMechanism() != NULL) { AstAttributeMechanism::AttributeIdentifiers aidents = node->get_attributeMechanism()->getAttributeIdentifiers(); HPDF_Page_ShowTextNextLine(currentPage, ""); // next line HPDF_Page_SetRGBFill(currentPage, 0.0, 0.2, 0.7); HPDF_Page_ShowTextNextLine(currentPage, "AstAttributes:"); // next line for (AstAttributeMechanism::AttributeIdentifiers::iterator it = aidents.begin(); it != aidents.end(); it++) { HPDF_Page_ShowTextNextLine(currentPage, ""); // next line HPDF_Page_SetRGBFill(currentPage, 0.0, 0.2, 0.7); HPDF_Page_ShowText(currentPage,((*it)+": ").c_str()); HPDF_Page_SetRGBFill(currentPage, 0.0, 0.0, 0.0); // float textxpos=PDF_get_value(pdfFile,"textx",0.0); // float textypos=PDF_get_value(pdfFile,"texty",0.0); // string attributeValue = (node->attribute()[*it])->toString(); string attributeValue = node->getAttribute(*it)->toString(); // split string into different substrings separated by newlines string substring=""; int oldpos=0; int newpos; do { newpos=attributeValue.find('\n', oldpos); substring=attributeValue.substr(oldpos,newpos-oldpos); if(oldpos==0) HPDF_Page_ShowText(currentPage, substring.append(" ").c_str()); else HPDF_Page_ShowTextNextLine(currentPage, substring.c_str()); oldpos = newpos+1; // go to next '\n' and skip it } // DQ (8/9/2005): Suggested fix from Rich (fixes infinite loop where AST Attributes are attached) // while( newpos < (int) attributeValue.size()); while( newpos < (int) attributeValue.size() && newpos >= 0 ); // PDF_show_boxed(pdfFile, attributeValue.c_str(), textxpos, textypos, 0, 0, "left", ""); } } // end if #endif } }
static std::string sourcePositionInformation (SgNode* node) { // DQ (8/31/2013): Adding source position information for DOT output. string ss; SgLocatedNode* locatedNode = isSgLocatedNode(node); if (locatedNode != NULL) { Sg_File_Info* fileInfo = locatedNode->get_file_info(); if (fileInfo != NULL) { bool hasSpecialMode = false; if (fileInfo->isCompilerGenerated() == true) { ss += "compiler generated\\n"; hasSpecialMode = true; } else { if (fileInfo->isFrontendSpecific() == true) { ss += "front-end specific\\n"; hasSpecialMode = true; } else { if (fileInfo->isTransformation() == true) { ss += "is part of transformation\\n"; hasSpecialMode = true; } else { // ss += "???\\n"; } } } if (hasSpecialMode == true) { if (fileInfo->isOutputInCodeGeneration() == true) { ss += "IS output in generated code\\n"; } else { ss += "is NOT output in generated code\\n"; } } else { // DQ (9/1/2013): Name a few cases were we want to output the end of the IR node construct's source position range. // bool outputEndOfConstruct = (isSgAggregateInitializer(node) != NULL || isSgScopeStatement(node) != NULL); bool outputEndOfConstruct = true; // (isSgAggregateInitializer(node) != NULL || isSgStatement(node) != NULL); if (outputEndOfConstruct == true) { // Output the end of the range represented by the IR node's source position. ss += generateFileLineColumnString(locatedNode->get_startOfConstruct()); ss += generateFileLineColumnString(locatedNode->get_endOfConstruct()); } else { // For an SgStatement this is the startOfConstruct, but for an SgExpression this is the operator position (or sometimes equal to the startOfConstruct). ss += generateFileLineColumnString(fileInfo); } } } else { ss += "no source position available\\n"; } } else { // DQ (9/1/2013): We could handle the source position of some other IR nodes (e.g. output name of the file for SgFile). SgFile* file = isSgFile(node); if (file != NULL) { ROSE_ASSERT(file->get_file_info() != NULL); ss += generateFileLineColumnString(file->get_file_info()); } } return ss; }
void InsertFortranContainsStatement::visit ( SgNode* node ) { // DQ (10/3/2008): This bug in OFP is now fixed so no fixup is required. printf ("Error: fixup of contains statement no longer required. \n"); ROSE_ASSERT(false); // DQ (11/24/2007): Output the current IR node for debugging the traversal of the Fortran AST. ROSE_ASSERT(node != NULL); #if 0 Sg_File_Info* fileInfo = node->get_file_info(); printf ("node = %s fileInfo = %p \n",node->class_name().c_str(),fileInfo); if (fileInfo != NULL) { bool isCompilerGenerated = fileInfo->isCompilerGenerated(); std::string filename = fileInfo->get_filenameString(); int line_number = fileInfo->get_line(); int column_number = fileInfo->get_line(); printf ("--- isCompilerGenerated = %s position = %d:%d filename = %s \n",isCompilerGenerated ? "true" : "false",line_number,column_number,filename.c_str()); } #endif SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(node); // This is for handling where CONTAINS is required in a function if (functionDefinition != NULL) { SgBasicBlock* block = functionDefinition->get_body(); SgStatementPtrList & statementList = block->get_statements(); SgStatementPtrList::iterator i = statementList.begin(); bool firstFunctionDeclaration = false; bool functionDeclarationSeen = false; while (i != statementList.end() && firstFunctionDeclaration == false) { SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(*i); // DQ (1/20/2008): Note that entry statements should not cause introduction of a contains statement! if (isSgEntryStatement(functionDeclaration) != NULL) functionDeclaration = NULL; if (functionDeclaration != NULL) { firstFunctionDeclaration = functionDeclarationSeen == false; functionDeclarationSeen = true; if (firstFunctionDeclaration == true) { // Insert a CONTAINS statement. // printf ("Building a contains statement (in function) \n"); SgContainsStatement* containsStatement = new SgContainsStatement(); SageInterface::setSourcePosition(containsStatement); containsStatement->set_definingDeclaration(containsStatement); block->get_statements().insert(i,containsStatement); containsStatement->set_parent(block); ROSE_ASSERT(containsStatement->get_parent() != NULL); } } i++; } } #if 0 // OFP now has better support for the CONTAINS statement so this code is not longer required. // The use of CONTAINS in modules appears to be handled by OFP, so no fixup is required. SgClassDefinition* classDefinition = isSgClassDefinition(node); // This is for handling where CONTAINS is required in a module if (classDefinition != NULL) { SgDeclarationStatementPtrList & statementList = classDefinition->get_members(); SgDeclarationStatementPtrList::iterator i = statementList.begin(); bool firstFunctionDeclaration = false; bool functionDeclarationSeen = false; while (i != statementList.end() && firstFunctionDeclaration == false) { printf ("InsertFortranContainsStatement: *i in statementList in module = %p = %s \n",*i,(*i)->class_name().c_str()); SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(*i); if (functionDeclaration != NULL) { firstFunctionDeclaration = functionDeclarationSeen == false; functionDeclarationSeen = true; if (firstFunctionDeclaration == true) { // Insert a CONTAINS statement. // printf ("Building a contains statement (in module) \n"); SgContainsStatement* containsStatement = new SgContainsStatement(); SageInterface::setSourcePosition(containsStatement); containsStatement->set_definingDeclaration(containsStatement); // This insert function does not set the parent (unlike for SgBasicBlock) classDefinition->get_members().insert(i,containsStatement); containsStatement->set_parent(classDefinition); ROSE_ASSERT(containsStatement->get_parent() != NULL); } } i++; } } #endif }
void AstTextAttributesHandling::visit(SgNode* node) { ROSE_ASSERT (node != NULL); #if 0 printf ("In AstTextAttributesHandling::visit(%p): node = %s \n",node,node->sage_class_name()); #endif // DQ (2/20/2007): Don't add attributes to expliclt share IR nodes (from the AST merge). These IR nodes are // explicitly marked as shared and a different from SgType IR nodes which can be shared have not Sg_File_Info // object and so cannot be explicitly makred when they are shared. bool markedAsShared = false; Sg_File_Info* fileInfo = node->get_file_info(); if (fileInfo != NULL && fileInfo->isShared() == true) markedAsShared = true; // Only apply this test to IR nodes that are not marked as shared (sharedIR nodes would fail the test by design) // if (!dynamic_cast<SgType*>(node) || !dynamic_cast<SgTypedefSeq*>(node)) if ( (!dynamic_cast<SgType*>(node) || !dynamic_cast<SgTypedefSeq*>(node)) && (markedAsShared == false) ) { switch(mode) { case M_set: { // DQ (1/2/2006): Use the new attribute interface // printf ("In AstTextAttributesHandling::visit() set: using new attribute interface \n"); // DQ (4/10/2006): We only test this on statements (since not all IR nodes have the attribute mechanism defined) // SgStatement* statement = dynamic_cast<SgStatement*>(node); // if (statement != NULL) node->addNewAttribute("test1", new AstTextAttribute("value1") ); node->addNewAttribute("test2", new AstTextAttribute("value2: newline follows here:\nThis is the 2nd line of value 2.\nThis is the 3rd line of value 2.") ); node->addNewAttribute("test3", new AstTextAttribute("value3") ); #if UNPARSE_SOURCE_TEST if (dynamic_cast<SgStatement*>(node)) { node->addNewAttribute("source", new AstTextAttribute( node->unparseToString() ) ); // node->addNewAttribute("source", new AstTextAttribute( "node->unparseToString()" ) ); } else { node->addNewAttribute("source", new AstTextAttribute("-- undefined --") ); } #endif break; } case M_remove: { // DQ (1/2/2006): Use the new attribute interface // printf ("In AstTextAttributesHandling::visit() remove: using new attribute interface \n"); // DQ (4/10/2006): We only test this on statements (since not allIR nodes have the attribute mechanism defined) // SgStatement* statement = dynamic_cast<SgStatement*>(node); // if (statement != NULL) node->removeAttribute("test1"); node->removeAttribute("test2"); node->removeAttribute("test3"); #if UNPARSE_SOURCE_TEST node->removeAttribute("source"); #endif break; } default: cerr << "error: undefined mode in AstTextAttributesHandling." << endl; // DQ (9/5/2006): Added assertion to make default case fail! ROSE_ASSERT(false); } } }
void MarkLhsValues::visit(SgNode* node) { // DQ (1/19/2008): Fixup the get_lvalue() member function which is common on expressions. // printf ("In TestLValueExpressions::visit(): node = %s \n",node->class_name().c_str()); ROSE_ASSERT(node != NULL); #if 0 Sg_File_Info* fileInfo = node->get_file_info(); printf ("In MarkLhsValues::visit(): node = %s fileInfo = %p \n",node->class_name().c_str(),fileInfo); if (fileInfo != NULL) { bool isCompilerGenerated = fileInfo->isCompilerGenerated(); std::string filename = fileInfo->get_filenameString(); int line_number = fileInfo->get_line(); int column_number = fileInfo->get_line(); printf ("--- isCompilerGenerated = %s position = %d:%d filename = %s \n",isCompilerGenerated ? "true" : "false",line_number,column_number,filename.c_str()); } #endif // This function most often sets the SgVarRefExp which appears as an lhs operand in a limited set of binary operators. SgExpression* expression = isSgExpression(node); if (expression != NULL) { #if 0 printf ("MarkLhsValues::visit(): calling expression->get_lvalue() on expression = %p = %s \n",expression,expression->class_name().c_str()); #endif SgBinaryOp* binaryOperator = isSgBinaryOp(expression); if (binaryOperator != NULL) { switch (expression->variantT()) { // IR nodes that have an l-value (required by C/C++/Fortran standard) case V_SgAssignOp: case V_SgAndAssignOp: case V_SgDivAssignOp: case V_SgIorAssignOp: case V_SgLshiftAssignOp: case V_SgMinusAssignOp: case V_SgModAssignOp: case V_SgMultAssignOp: case V_SgPlusAssignOp: case V_SgRshiftAssignOp: case V_SgXorAssignOp: { SgExpression* lhs = binaryOperator->get_lhs_operand(); ROSE_ASSERT(lhs != NULL); SgExpression* rhs = binaryOperator->get_rhs_operand(); ROSE_ASSERT(rhs != NULL); // This is violated by the ROSE/tests/nonsmoke/functional/roseTests/astInliningTests/pass16.C test code! // ROSE_ASSERT(lhs->get_lvalue() == true); // This is a value that I know has to be set, the AST generation in EDG/Sage and OFP/Sage // sets this properly, but some transformations of the AST do not, so we fix it up here. lhs->set_lvalue(true); rhs->set_lvalue(false); break; } // These cases are less clear so don't explicitly mark it as an l-value! case V_SgDotExp: case V_SgArrowExp: { SgExpression* lhs = binaryOperator->get_lhs_operand(); ROSE_ASSERT(lhs != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES printf ("L-value test for SgBinaryOp = %s: not clear how to assert value -- lhs->get_lvalue() = %s \n",binaryOperator->class_name().c_str(),lhs->get_lvalue() ? "true" : "false"); #endif // ROSE_ASSERT(lhs->get_lvalue() == true); break; } // DQ (10/9/2008): For the Fortran user defined operator, the lhs is not an L-value. // This represents my understanding, because assignment is explicitly handled separately. case V_SgUserDefinedBinaryOp: { SgExpression* lhs = binaryOperator->get_lhs_operand(); ROSE_ASSERT(lhs != NULL); SgExpression* rhs = binaryOperator->get_rhs_operand(); ROSE_ASSERT(rhs != NULL); // This is a value that I know has to be set, the AST generation in EDG/Sage and OFP/Sage // sets this properly, but some transformations of the AST do not, so we fix it up here. lhs->set_lvalue(false); rhs->set_lvalue(false); break; } default: { // Make sure that the lhs is not an L-value SgExpression* lhs = binaryOperator->get_lhs_operand(); ROSE_ASSERT(lhs != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES if (lhs->get_lvalue() == true) { printf ("Error for lhs = %p = %s = %s in binary expression = %s \n", lhs,lhs->class_name().c_str(),SageInterface::get_name(lhs).c_str(),expression->class_name().c_str()); binaryOperator->get_startOfConstruct()->display("Error for lhs: lhs->get_lvalue() == true: debug"); } #endif // ROSE_ASSERT(lhs->get_lvalue() == false); } } //SgExpression* rhs = binaryOperator->get_rhs_operand(); // Liao 3/14/2011. This function is called by builders for binary expressions. // These builders can accept empty right hand operands. // ROSE_ASSERT(rhs != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES if (rhs != NULL) if (rhs->get_lvalue() == true) { printf ("Error for rhs = %p = %s = %s in binary expression = %s \n", rhs,rhs->class_name().c_str(),SageInterface::get_name(rhs).c_str(),expression->class_name().c_str()); binaryOperator->get_startOfConstruct()->display("Error for rhs: rhs->get_lvalue() == true: debug"); } #endif // ROSE_ASSERT(rhs->get_lvalue() == false); } SgUnaryOp* unaryOperator = isSgUnaryOp(expression); if (unaryOperator != NULL) { switch (expression->variantT()) { // IR nodes that should have a valid lvalue // What about SgAddressOfOp? case V_SgAddressOfOp: break; // JJW 1/31/2008 case V_SgMinusMinusOp: case V_SgPlusPlusOp: { SgExpression* operand = unaryOperator->get_operand(); ROSE_ASSERT(operand != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES // if (operand->get_lvalue() == true) if (operand->get_lvalue() == false) { printf ("Error for operand = %p = %s = %s in unary expression (SgMinusMinusOp or SgPlusPlusOp) = %s \n", operand,operand->class_name().c_str(),SageInterface::get_name(operand).c_str(),expression->class_name().c_str()); unaryOperator->get_startOfConstruct()->display("Error for operand: operand->get_lvalue() == true: debug"); } #endif // ROSE_ASSERT(operand->get_lvalue() == false); operand->set_lvalue(true); // ROSE_ASSERT(operand->get_lvalue() == true); break; } case V_SgThrowOp: { #if WARN_ABOUT_ATYPICAL_LVALUES // Note that the gnu " __throw_exception_again;" can cause a SgThrowOp to now have an operand! SgExpression* operand = unaryOperator->get_operand(); if (operand == NULL) { printf ("Warning: operand == NULL in SgUnaryOp = %s (likely caused by __throw_exception_again) \n",expression->class_name().c_str()); // unaryOperator->get_startOfConstruct()->display("Error: operand == NULL in SgUnaryOp: debug"); } #endif // ROSE_ASSERT(operand != NULL); break; } // DQ (10/9/2008): For the Fortran user defined operator, the operand is not an L-value. // This represents my understanding, because assignment is explicitly handled separately. case V_SgUserDefinedUnaryOp: { SgExpression* operand = unaryOperator->get_operand(); ROSE_ASSERT(operand != NULL); operand->set_lvalue(false); } // Added to address problem on Qing's machine using g++ 4.0.2 case V_SgNotOp: // These are where some error occur. I want to isolate then so that I know the current status of where lvalues are not marked correctly! case V_SgPointerDerefExp: case V_SgCastExp: case V_SgMinusOp: case V_SgBitComplementOp: // case V_SgPlusOp: { SgExpression* operand = unaryOperator->get_operand(); ROSE_ASSERT(operand != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES // Most of the time this is false, we only want to know when it is true if (operand->get_lvalue() == true) { printf ("L-value test for SgUnaryOp = %s: not clear how to assert value -- operand->get_lvalue() = %s \n",unaryOperator->class_name().c_str(),operand->get_lvalue() ? "true" : "false"); // unaryOperator->get_startOfConstruct()->display("L-value test for SgUnaryOp: operand->get_lvalue() == true: debug"); } #endif // ROSE_ASSERT(operand->get_lvalue() == false); break; } default: { SgExpression* operand = unaryOperator->get_operand(); ROSE_ASSERT(operand != NULL); #if WARN_ABOUT_ATYPICAL_LVALUES if (operand->get_lvalue() == true) { printf ("Error for operand = %p = %s = %s in unary expression = %s \n", operand,operand->class_name().c_str(),SageInterface::get_name(operand).c_str(),expression->class_name().c_str()); unaryOperator->get_startOfConstruct()->display("Error for operand: operand->get_lvalue() == true: debug"); } #endif // DQ (10/9/2008): What is the date and author for this comment? Is it fixed now? Was it made into a test code? // Note that this fails for line 206 of file: include/g++_HEADERS/hdrs1/ext/mt_allocator.h ROSE_ASSERT(operand->get_lvalue() == false); } } } } }
InheritedAttribute visitorTraversal::evaluateInheritedAttribute(SgNode* n, InheritedAttribute inheritedAttribute) { Sg_File_Info* s = n->get_startOfConstruct(); Sg_File_Info* e = n->get_endOfConstruct(); Sg_File_Info* f = n->get_file_info(); for(int x=0; x < inheritedAttribute.depth; ++x) { printf(" "); } if(s != NULL && e != NULL && !isSgLabelStatement(n)) { printf ("%s (%d, %d, %d)->(%d, %d): %s",n->sage_class_name(),s->get_file_id()+1,s->get_raw_line(),s->get_raw_col(),e->get_raw_line(),e->get_raw_col(), verbose ? n->unparseToString().c_str() : "" ); if(isSgAsmDwarfConstruct(n)) { printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str()); } SgExprStatement * exprStmt = isSgExprStatement(n); if(exprStmt != NULL) { printf(" [expr type: %s]", exprStmt->get_expression()->sage_class_name()); SgFunctionCallExp * fcall = isSgFunctionCallExp(exprStmt->get_expression()); if(fcall != NULL) { SgExpression * funcExpr = fcall->get_function(); if(funcExpr != NULL) { printf(" [function expr: %s]", funcExpr->class_name().c_str()); } SgFunctionDeclaration * fdecl = fcall->getAssociatedFunctionDeclaration(); if(fdecl != NULL) { printf(" [called function: %s]", fdecl->get_name().str()); } } } if(isSgFunctionDeclaration(n)) { printf(" [declares function: %s]", isSgFunctionDeclaration(n)->get_name().str()); } SgStatement * sgStmt = isSgStatement(n); if(sgStmt != NULL) { printf(" [scope: %s, %p]", sgStmt->get_scope()->sage_class_name(), sgStmt->get_scope()); } //SgLabelStatement * lblStmt = isSgLabelStatement(n); //if(lblStmt != NULL) { // SgStatement * lblStmt2 = lblStmt->get_statement(); //} } else if (f != NULL) { SgInitializedName * iname = isSgInitializedName(n); if(iname != NULL) { SgType* inameType = iname->get_type(); printf("%s (%d, %d, %d): %s [type: %s", n->sage_class_name(),f->get_file_id()+1,f->get_raw_line(),f->get_raw_col(),n->unparseToString().c_str(),inameType->class_name().c_str()); SgDeclarationStatement * ds = isSgDeclarationStatement(iname->get_parent()); if(ds != NULL) { if(ds->get_declarationModifier().get_storageModifier().isStatic()) { printf(" static"); } } SgArrayType * art = isSgArrayType(iname->get_type()); if(art != NULL) { printf(" %d", art->get_rank()); } printf("]"); if(isSgAsmDwarfConstruct(n)) { printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str()); } } else { printf("%s (%d, %d, %d): %s", n->sage_class_name(),f->get_file_id()+1,f->get_raw_line(),f->get_raw_col(), verbose ? n->unparseToString().c_str() : ""); } } else { printf("%s : %s", n->sage_class_name(), verbose ? n->unparseToString().c_str() : ""); if(isSgAsmDwarfConstruct(n)) { printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str()); } } printf(" succ# %lu", n->get_numberOfTraversalSuccessors()); printf("\n"); return InheritedAttribute(inheritedAttribute.depth+1); }
static void CreateLoopProbe(SgFunctionDeclaration *funcDecl, SgBasicBlock *funcBody, SgStatement *stmt, int *loopCount) { SgExpression *lb ; SgExpression *ub ; SgExpression *step ; bool isCanonicalFor = SageInterface::isCanonicalForLoop(stmt, NULL, &lb, &ub, &step) ; /* generate loop segment, and iteration information if requested */ if (countIters && !isCanonicalFor) { Sg_File_Info *fileInfo = stmt->get_startOfConstruct() ; printf("Non-canonical loop in %s:::%s at line %d\n", fileInfo->get_filenameString().c_str(), funcDecl->get_name().str(), fileInfo->get_line()) ; } else { SgExpression *its = NULL ; if (countIters && isCanonicalFor) { bool isDecreasing = false ; bool adjustBound = false ; SgExpression *high ; SgExpression *max ; SgExpression *minuend ; SgExpression *subtrahend ; SgExpression *tmp ; SgForStatement* fs = isSgForStatement(stmt) ; ROSE_ASSERT(fs) ; SgBinaryOp* test = isSgBinaryOp(fs->get_test_expr()); ROSE_ASSERT(test) ; switch (test->variantT()) { case V_SgLessOrEqualOp: adjustBound = true ; case V_SgLessThanOp: break; case V_SgGreaterOrEqualOp: adjustBound = true ; case V_SgGreaterThanOp: // tmp = lb ; // lb = ub ; // ub = tmp ; isDecreasing = true ; break; // case V_SgNotEqualOp: // Do we really want to allow this != operator ? // break; default: /* do nothing */ ; } if (adjustBound) { high = buildAddOp(SageInterface::copyExpression(ub), buildIntVal(isDecreasing ? -1 : 1)) ; } else { high = SageInterface::copyExpression(ub) ; } /* if step != const 1, we need to adjust high */ if (!(isSgIntVal(step) && (isSgIntVal(step)->get_value() == 1))) { max = buildAddOp(high, buildSubtractOp(SageInterface::copyExpression(step), buildIntVal(1))) ; } else { max = high ; } minuend = max ; subtrahend = SageInterface::copyExpression(lb) ; #if 0 if (isDecreasing) { SgExpression *tmp ; tmp = minuend ; minuend = subtrahend ; subtrahend = tmp ; } #endif /* The control logic is purely to clean up the output, since */ /* the compiler can do a fine job of folding integer constansts */ its = buildDivideOp(buildSubtractOp(minuend, subtrahend), SageInterface::copyExpression(step)) ; #if 0 if (!(isSgIntVal(step) && (isSgIntVal(step)->get_value() == 1))) { its = buildDivideOp(buildSubtractOp(minuend, subtrahend), SageInterface::copyExpression(step)) ; } else { if (!(isSgIntVal(subtrahend) && (isSgIntVal(subtrahend)->get_value() == 0))) { its = buildSubtractOp(minuend, subtrahend) ; } else { its = minuend ; } } #endif } /* start loop code fragment */ SgVariableDeclaration *loopDecl = ET_BuildDecl(funcBody, "ET_loop", *loopCount, ETtype, true) ; RegisterItem(funcDecl, funcBody, stmt, "ET_RegisterLoop", ETtype, loopDecl, true) ; HandleItem(funcBody, stmt, "ET_PushLoopSeqId", buildVarRefExp(loopDecl), true) ; /* end loop code fragment */ HandleItem(funcBody, stmt, "ET_PopLoopSeqId", its, false) ; ++(*loopCount) ; } }
void PreAndPostOrderTraversal::preOrderVisit(SgNode* n) { SgFunctionDeclaration * dec = isSgFunctionDeclaration(n); if (dec != NULL) { cout << "Found function declaration " << dec->get_name().getString(); Sg_File_Info * start = dec->get_startOfConstruct(); Sg_File_Info * end = dec->get_endOfConstruct(); if(start->isCompilerGenerated()) { cout << ", which is compiler-generated" << endl; } else { cout << " in file " << start->get_raw_filename() << ", " << start->get_file_id() << " from line " << start->get_line() << ", col " << start->get_col() << " to line " << end->get_line() << ", col " << end->get_col() << endl; } SgFunctionType * type = dec->get_type(); SgType * retType = type->get_return_type(); cout << "Return type: " << retType->unparseToString() << endl; SgFunctionParameterList * params = dec->get_parameterList(); SgInitializedNamePtrList & ptrList = params->get_args(); if(!ptrList.empty()) { cout << "Parameter types: "; for(SgInitializedNamePtrList::iterator j = ptrList.begin(); j != ptrList.end(); j++) { SgType * pType = (*j)->get_type(); cout << pType->unparseToString() << " "; } cout << endl; } cout << "Linkage: " << dec->get_linkage() << endl; cout << endl; } SgFunctionDefinition * def = isSgFunctionDefinition(n); if (def != NULL) { cout << "Found function definition " << def->get_declaration()->get_name().getString(); Sg_File_Info * start = def->get_startOfConstruct(); Sg_File_Info * end = def->get_endOfConstruct(); if(start->isCompilerGenerated()) { cout << ", which is compiler-generated" << endl; } else { cout << " in file " << start->get_raw_filename() << " from line " << start->get_line() << ", col " << start->get_col() << " to line " << end->get_line() << ", col " << end->get_col() << endl; SgBasicBlock * body = def->get_body(); Sg_File_Info * bodyStart = body->get_startOfConstruct(); Sg_File_Info * bodyEnd = body->get_endOfConstruct(); cout << "Function body from line " << bodyStart->get_line() << ", col " << bodyStart->get_col() << " to line " << bodyEnd->get_line() << ", col " << bodyEnd->get_col() << endl; } cout << endl; } }
void mergeStaticASTFileInformation(vector<AstFileSpecificInfo*> & AstFileInfoArray) { // Take care of merging the function type table first. vector<SgFunctionTypeTable*> functionTableArray; for (size_t i = 0; i < AstFileInfoArray.size(); ++i) { functionTableArray.push_back(AstFileInfoArray[i]->functionTable); } // Merge the function tables from each AST. SgFunctionTypeTable* globalFunctionTypeTable = mergeFunctionTypeSymbolTables (functionTableArray); ROSE_ASSERT(globalFunctionTypeTable != NULL); map<int,std::string> mergedFileidtoname_map; map<std::string,int> mergedNametofileid_map; map<int,int> mergedFileidtoid_map; // Now merge the file name maps (static information in Sg_File_Info). // int maxFilenameIndex = 0; // int minFilenameIndex = 100000000; for (size_t index = 0; index < AstFileInfoArray.size(); index++) { map<int,std::string> & fileidtoname_map = AstFileInfoArray[index]->fileidtoname_map; // Build a new map of all the possible file names for (std::map<int,std::string>::iterator i = fileidtoname_map.begin(); i != fileidtoname_map.end(); i++) { // printf ("id = %d name = %s \n",i->first,i->second.c_str()); if (mergedNametofileid_map.count(i->second) == 0) { int returnValue = (int)mergedNametofileid_map.size(); #if 0 printf ("Adding new name to merged maps id = %d name = %s will use new id = %d \n",i->first,i->second.c_str(),returnValue); #endif mergedNametofileid_map[i->second] = returnValue; mergedFileidtoname_map[returnValue] = i->second; // We still need the mapping of old ids to new ids for each AST file. mergedFileidtoid_map [i->first] = returnValue; } } #if 0 printf ("Resetting memory pool entries (%d,%d) \n",AstFileInfoArray[index]->baseOfASTFileInfo,AstFileInfoArray[index]->boundOfASTFileInfo); #endif // Now iterate over the memory pool of Sg_File _Info objects so that we can reset the file ids. for (int i = AstFileInfoArray[index]->baseOfASTFileInfo; i < AstFileInfoArray[index]->boundOfASTFileInfo; i++) { // Set each id to the new id as specified in mergedFileidtoid_map // printf ("Accessing the %d = %lu entry of the Sg_File_Info memory pool. \n",i,(unsigned long) i); // printf ("Memory pool size = %lu \n",AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(V_Sg_File_Info)); // Compute the postion of the indexed Sg_File_Info object in the memory pool. unsigned long localIndex = i; unsigned long positionInPool = localIndex % Sg_File_Info_CLASS_ALLOCATION_POOL_SIZE ; unsigned long memoryBlock = (localIndex - positionInPool) / Sg_File_Info_CLASS_ALLOCATION_POOL_SIZE; Sg_File_Info* fileInfo = &(((Sg_File_Info*)(Sg_File_Info_Memory_Block_List[memoryBlock]))[positionInPool]); // $CLASSNAME* $CLASSNAME_getPointerFromGlobalIndex ( unsigned long globalIndex ) // Sg_File_Info* fileInfo = Sg_File_Info_getPointerFromGlobalIndex((unsigned long) i + 1); ROSE_ASSERT(fileInfo != NULL); int oldFileId = fileInfo->get_file_id(); int newFileId = mergedFileidtoid_map[oldFileId]; // Only reset those file ids that are associated with valid file names. // Values less than zero indicate file name classifications. if (oldFileId >= 0 && oldFileId != newFileId) { #if 0 printf ("Accessing the %d Exchanging old file id = %d for new file id = %d \n",i,oldFileId,newFileId); #endif fileInfo->set_file_id ( newFileId ); } } } // Now reset the static maps to use the new mapping. Sg_File_Info::get_nametofileid_map() = mergedNametofileid_map; Sg_File_Info::get_fileidtoname_map() = mergedFileidtoname_map; // DQ (6/21/2010): Fixup the support for builtin types stored as static data in the SgType derived classes. // FixupbuiltinTypes(AST_FILE_IO::getAst(i),AST_FILE_IO::getAst(i)); printf ("In mergeStaticASTFileInformation: SgTypeUnsignedInt::p_builtin_type = %p \n",SgTypeUnsignedInt::createType()); // Note that GNU g++ 4.2.x allows us to reference "index" out of scope! // printf ("maxFilenameIndex = %d minFilenameIndex = %d \n",maxFilenameIndex,minFilenameIndex); }