Beispiel #1
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;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
        std::string filename;

        SgProject *project = frontend(argc, argv);
        std::vector<InterproceduralInfo*> ip;
#ifdef NEWDU
        // Create the global def-use analysis
        DFAnalysis *defUseAnalysis=new DefUseAnalysis(project);
        if (defUseAnalysis->run(false)==1)
        {
                std::cerr<<"testSDG:: DFAnalysis failed!  -- (defUseAnalysis->run(false)==0"<<endl;
                exit(0);
        }
#endif
        string outputFileName=(*(*project->get_fileList()).begin())->get_sourceFileNameWithoutPath ();


        SystemDependenceGraph *sdg = new SystemDependenceGraph;
        // for all function-declarations in the AST
        list < SgNode * >functionDeclarations = NodeQuery::querySubTree(project, V_SgFunctionDeclaration);

        for (list < SgNode * >::iterator i = functionDeclarations.begin(); i != functionDeclarations.end(); i++)
        {
                ControlDependenceGraph *cdg;
                DataDependenceGraph *ddg;
        //      FunctionDependenceGraph * pdg;
                InterproceduralInfo *ipi;

                SgFunctionDeclaration *fDec = isSgFunctionDeclaration(*i);

                ROSE_ASSERT(fDec != NULL);

                // CI (01/08/2007): A missing function definition is an indicator to a 
                // 
                // 
                // librarycall. 
                // * An other possibility would be a programmer-mistake, which we
                // don't treat at this point.  // I assume librarycall
                if (fDec->get_definition() == NULL)
                {
//                      if (fDec->get_file_info()->isCompilerGenerated()) continue;
                        // treat librarycall -> iterprocedualInfo must be created...
                        // make all call-parameters used and create a function stub for
                        // the graph
                        ipi=new InterproceduralInfo(fDec);
                        ipi->addExitNode(fDec);
                        sdg->addInterproceduralInformation(ipi);
                        if (sdg->isKnownLibraryFunction(fDec))
                        {
                                sdg->createConnectionsForLibaryFunction(fDec);
                        }
                        else
                        {
                                sdg->createSafeConfiguration(fDec);
                        }
                        ip.push_back(ipi);

                        // This is somewhat a waste of memory and a more efficient approach might generate this when needed, but at the momenent everything is created...
                }
                else
                {
                        // get the control depenence for this function
                        ipi=new InterproceduralInfo(fDec);

                        ROSE_ASSERT(ipi != NULL);

                        // get control dependence for this function defintion
                        cdg = new ControlDependenceGraph(fDec->get_definition(), ipi);
                        cdg->computeInterproceduralInformation(ipi);

                        // get the data dependence for this function
                        #ifdef NEWDU
                        ddg = new DataDependenceGraph(fDec->get_definition(), defUseAnalysis,ipi);
                        #else
                        ddg = new DataDependenceGraph(fDec->get_definition(), ipi);
                        #endif
                        
                        sdg->addFunction(cdg,ddg);
                        sdg->addInterproceduralInformation(ipi);
                        ip.push_back(ipi);
                }   
                // else if (fD->get_definition() == NULL)

        }
        // now all function-declarations have been process as well have all function-definitions
        filename = (outputFileName) + ".no_ii.sdg.dot";
        sdg->writeDot((char *)filename.c_str());
        
        // perform interproceduralAnalysys
        sdg->performInterproceduralAnalysis();

        filename = (outputFileName)+".deadEnds.sdg.dot";
        sdg->writeDot((char *)filename.c_str());                        
        sdg->cleanUp();
        filename = (outputFileName)+".final.sdg.dot";
        sdg->writeDot((char *)filename.c_str());                        
}
Beispiel #3
0
/*
 * Add calls to register and unregister expressions/arrays with the memory
 * management wrapper.
 */
bool RegisterPointers::addRegUnregCalls()
{
	string msg;

	if(definedInSystemHeader)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " is in system headers";
		WARNING(TOOL, msg);
		return false;
	}

	if(compilerGenerated)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " is compiler-generated";
		WARNING(TOOL, msg);
		return false;
	}

	if(addrUsedInIO)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " has its address taken in "
				+ "a function known to not require registering/unregistering";
		WARNING(TOOL, msg);
		return false;
	}

	//Add register/unregister calls
	SgStatement* prevStmt = NULL;
	SgExprStatement* funcCall = NULL;
	SgType* type = NULL;
	SgExpression* expr = NULL;

	if(isGlobal)
	{
		type = varName->get_type();
		SgName name = varName->get_name();
		int numVals = 1;

		if(isSgPointerType(type))
			return false;	//If its a pointer, it points to a static array, dynamic array, or scalar
							//which has its address taken (all of which have already been registered)

		SgFunctionDeclaration* main = findMain(getScope(varName));
		ROSE_ASSERT(main);
		expr = buildVarRefExp(name, varName->get_scope());
		if(isSgArrayType(type))
			numVals = getArrayElementCount(isSgArrayType(type));
		else
			expr = buildAddressOfOp(expr);

		funcCall = MMCallBuilder::buildRegisterPointerCall(expr, buildUnsignedIntVal(numVals),
				main->get_definition());
		insertStatement(getFirstStatement(main->get_definition()), funcCall);//, false, true);
		funcCall = MMCallBuilder::buildUnregisterPointerCall(expr, main->get_definition());
		instrumentEndOfFunction(main, funcCall);
	}
	else if(expression) //Address-of expressions
	{
		prevStmt = getEnclosingStatement(expression);
		funcCall = MMCallBuilder::buildRegisterPointerCall(expression, buildUnsignedIntVal(1),
				getScope(expression));
		insertStatement(prevStmt, funcCall);
		funcCall = MMCallBuilder::buildUnregisterPointerCall(expression, getScope(expression));
		instrumentEndOfFunction(getEnclosingFunctionDeclaration(prevStmt), funcCall);
	}
	else //Array types
	{
		SgVarRefExp* varRef = buildVarRefExp(varName, getScope(varName));

		int numVals = getArrayElementCount(isSgArrayType(varName->get_type()));
		funcCall = MMCallBuilder::buildRegisterPointerCall(varRef, buildUnsignedIntVal(numVals),
				varName->get_scope());
		insertStatement(varName->get_declaration(), funcCall, false, true);
		varRef = buildVarRefExp(varName, getScope(varName));
		funcCall = MMCallBuilder::buildUnregisterPointerCall(varRef, varName->get_scope());
		instrumentEndOfFunction(getEnclosingFunctionDeclaration(varName), funcCall);
	}

	return true;
}
Beispiel #4
0
void SystemDependenceGraph::build()
{
    boost::unordered_map<CFGVertex, Vertex> cfgVerticesToSdgVertices;
    boost::unordered_map<SgNode*, Vertex>   astNodesToSdgVertices;

    //map<SgFunctionCallExp*, vector<SDGNode*> > funcCallToArgs;

    vector<CallSiteInfo> functionCalls;


    map<SgNode*, vector<Vertex> > actualInParameters;
    map<SgNode*, vector<Vertex> > actualOutParameters;

    map<SgNode*, Vertex> formalInParameters;
    map<SgNode*, Vertex> formalOutParameters;

    vector<SgFunctionDefinition*> funcDefs = 
        SageInterface::querySubTree<SgFunctionDefinition>(project_, V_SgFunctionDefinition);
    foreach (SgFunctionDefinition* funcDef, funcDefs)
    {
        SgFunctionDeclaration* funcDecl = funcDef->get_declaration();

        CFG* cfg = new CFG(funcDef, cfgNodefilter_);
        functionsToCFGs_[funcDecl] = cfg;

        // For each function, build an entry node for it.
        SDGNode* entry = new SDGNode(SDGNode::Entry);
        entry->astNode = funcDef;
        //entry->funcDef = funcDef;
        Vertex entryVertex = addVertex(entry);
        functionsToEntries_[funcDecl] = entryVertex;

        // Add all out formal parameters to SDG.
        const SgInitializedNamePtrList& formalArgs = funcDecl->get_args();
        foreach (SgInitializedName* initName, formalArgs)
        {
            // If the parameter is passed by reference, create a formal-out node.
            if (isParaPassedByRef(initName->get_type()))
            {
                SDGNode* formalOutNode = new SDGNode(SDGNode::FormalOut);
                formalOutNode->astNode = initName;
                Vertex formalOutVertex = addVertex(formalOutNode);
                formalOutParameters[initName] = formalOutVertex;

                // Add a CD edge from call node to this formal-out node.
                addTrueCDEdge(entryVertex, formalOutVertex);
            }
        }

        // A vertex representing the returned value.
        Vertex returnVertex;

        // If the function returns something, build a formal-out node.
        if (!isSgTypeVoid(funcDecl->get_type()->get_return_type()))
        {
            SDGNode* formalOutNode = new SDGNode(SDGNode::FormalOut);
            // Assign the function declaration to the AST node of this vertex to make
            // it possible to classify this node into the subgraph of this function.
            formalOutNode->astNode = funcDecl;
            returnVertex = addVertex(formalOutNode);
            formalOutParameters[funcDecl] = returnVertex;

            // Add a CD edge from call node to this formal-out node.
            addTrueCDEdge(entryVertex, returnVertex);
        }

        // Add all CFG vertices to SDG.
        foreach (CFGVertex cfgVertex, boost::vertices(*cfg))
        {
            if (cfgVertex == cfg->getEntry() || cfgVertex == cfg->getExit())
                continue;

            SgNode* astNode = (*cfg)[cfgVertex]->getNode();

            // If this node is an initialized name and it is a parameter, make it 
            // as a formal in node.
            SgInitializedName* initName = isSgInitializedName(astNode);
            if (initName && isSgFunctionParameterList(initName->get_parent()))
            {
                SDGNode* formalInNode = new SDGNode(SDGNode::FormalIn);
                formalInNode->astNode = initName;
                Vertex formalInVertex = addVertex(formalInNode);
                formalInParameters[initName] = formalInVertex;

                cfgVerticesToSdgVertices[cfgVertex] = formalInVertex;
                astNodesToSdgVertices[astNode] = formalInVertex;

                // Add a CD edge from call node to this formal-in node.
                addTrueCDEdge(entryVertex, formalInVertex);
                continue;
            }

            // Add a new node to SDG.
            SDGNode* newSdgNode = new SDGNode(SDGNode::ASTNode);
            //newSdgNode->cfgNode = (*cfg)[cfgVertex];
            newSdgNode->astNode = astNode;
            Vertex sdgVertex = addVertex(newSdgNode);

            cfgVerticesToSdgVertices[cfgVertex] = sdgVertex;
            astNodesToSdgVertices[astNode] = sdgVertex;


            // Connect a vertex containing the return statement to the formal-out return vertex.
            if (isSgReturnStmt(astNode)
                    || isSgReturnStmt(astNode->get_parent()))
            {
                SDGEdge* newEdge = new SDGEdge(SDGEdge::DataDependence);
                addEdge(sdgVertex, returnVertex, newEdge);                
            }

            // If this CFG node contains a function call expression, extract its all parameters
            // and make them as actual-in nodes.

            if (SgFunctionCallExp* funcCallExpr = isSgFunctionCallExp(astNode))
            {
                CallSiteInfo callInfo;
                callInfo.funcCall = funcCallExpr;
                callInfo.vertex = sdgVertex;

                // Change the node type.
                newSdgNode->type = SDGNode::FunctionCall;
                vector<SDGNode*> argsNodes;

                // Get the associated function declaration.
                SgFunctionDeclaration* funcDecl = funcCallExpr->getAssociatedFunctionDeclaration();
                
                if (funcDecl == NULL) 
                    continue;
                    
                ROSE_ASSERT(funcDecl);
                const SgInitializedNamePtrList& formalArgs = funcDecl->get_args();

                SgExprListExp* args = funcCallExpr->get_args();
                const SgExpressionPtrList& actualArgs = args->get_expressions();
                
                if (formalArgs.size() != actualArgs.size())
                {
                    cout << "The following function has variadic arguments:\n";
                    cout << funcDecl->get_file_info()->get_filename() << endl;
                    cout << funcDecl->get_name() << formalArgs.size() << " " << actualArgs.size() << endl;
                    continue;
                }

                for (int i = 0, s = actualArgs.size(); i < s; ++i)
                {
                    // Make sure that this parameter node is added to SDG then we
                    // change its node type from normal AST node to a ActualIn arg.
                    ROSE_ASSERT(astNodesToSdgVertices.count(actualArgs[i]));

                    Vertex paraInVertex = astNodesToSdgVertices.at(actualArgs[i]);
                    SDGNode* paraInNode = (*this)[paraInVertex]; 
                    paraInNode->type = SDGNode::ActualIn;

                    actualInParameters[formalArgs[i]].push_back(paraInVertex);
                    callInfo.inPara.push_back(paraInVertex);

                    // Add a CD edge from call node to this actual-in node.
                    addTrueCDEdge(sdgVertex, paraInVertex);

                    // If the parameter is passed by reference, create a parameter-out node.
                    if (isParaPassedByRef(formalArgs[i]->get_type()))
                    {
                        SDGNode* paraOutNode = new SDGNode(SDGNode::ActualOut);
                        paraOutNode->astNode = actualArgs[i];
                        //argsNodes.push_back(paraInNode);

                        // Add an actual-out parameter node.
                        Vertex paraOutVertex = addVertex(paraOutNode);
                        actualOutParameters[formalArgs[i]].push_back(paraOutVertex);
                        callInfo.outPara.push_back(paraOutVertex);

                        // Add a CD edge from call node to this actual-out node.
                        addTrueCDEdge(sdgVertex, paraOutVertex);
                    }
                }

                if (!isSgTypeVoid(funcDecl->get_type()->get_return_type())) 
                {
                    // If this function returns a value, create a actual-out vertex.
                    SDGNode* paraOutNode = new SDGNode(SDGNode::ActualOut);
                    paraOutNode->astNode = funcCallExpr;

                    // Add an actual-out parameter node.
                    Vertex paraOutVertex = addVertex(paraOutNode);
                    actualOutParameters[funcDecl].push_back(paraOutVertex);
                    callInfo.outPara.push_back(paraOutVertex);
                    callInfo.isVoid = false;
                    callInfo.returned = paraOutVertex;

                    // Add a CD edge from call node to this actual-out node.
                    addTrueCDEdge(sdgVertex, paraOutVertex);
                }

                functionCalls.push_back(callInfo);
                //funcCallToArgs[funcCallExpr] = argsNodes;
            }
        }

        // Add control dependence edges.
        addControlDependenceEdges(cfgVerticesToSdgVertices, *cfg, entryVertex);
    }
SgName
Unparser_Nameq::lookup_generated_qualified_name ( SgNode* referencedNode )
   {
  // These are all of the types of IR nodes that can reference anything that is qualified.
  // It is a longer list than I expected (or designed for initially), but still not unreasonable.

     SgName nameQualifier;

     if (referencedNode == NULL)
        {
       // DQ (6/25/2011): This is the case of the using the unparseToString() function.  Our more sophisticated name 
       // qualification support is not possible to support in this case (because we don;'t have the scope from which 
       // to compute the qualified name) and so a fully qualified name is generated by default.

       // printf ("Note that info.set_reference_node_for_qualification(SgNode*) should have been called before calling this function. \n");
       // DQ (6/23/2011): This test fails this assertion: tests/roseTests/programAnalysisTests/testCallGraphAnalysis/test3.C
       // but allow it to pass as a test.
       // printf ("WARNING: referencedNode in Unparser_Nameq::lookup_generated_qualified_name() should be a valid pointer! \n");
#if 0
       // DQ (3/5/2012): Uncommenting this for debugging.
          printf ("WARNING: referencedNode in Unparser_Nameq::lookup_generated_qualified_name() should be a valid pointer! \n");
#endif
          return nameQualifier;
        }
     ROSE_ASSERT(referencedNode != NULL);

#if 0
     printf ("In Unparser_Nameq::lookup_generated_qualified_name(): referencedNode = %p = %s \n",referencedNode,referencedNode->class_name().c_str());
#endif
     switch (referencedNode->variantT())
        {
          case V_SgInitializedName:
             {
               SgInitializedName* initializedName = isSgInitializedName(referencedNode);
               nameQualifier = initializedName->get_qualified_name_prefix_for_type();
               break;
             }

       // DQ (12/29/2011): Added cases for new template IR nodes.
          case V_SgTemplateFunctionDeclaration:
          case V_SgTemplateMemberFunctionDeclaration:

          case V_SgFunctionDeclaration:
          case V_SgMemberFunctionDeclaration:
          case V_SgTemplateInstantiationFunctionDecl:
          case V_SgTemplateInstantiationMemberFunctionDecl:
             {
               SgFunctionDeclaration* node = isSgFunctionDeclaration(referencedNode);
               nameQualifier = node->get_qualified_name_prefix_for_return_type();
               break;
             }

          case V_SgTypedefDeclaration:
             {
               SgTypedefDeclaration* node = isSgTypedefDeclaration(referencedNode);
               nameQualifier = node->get_qualified_name_prefix_for_base_type();
               break;
             }

          case V_SgTemplateArgument:
             {
#if 0
            // DQ (5/4/2013): This was previously disabled, maybe because the SgTemplateArgument is shared between too many declarations (in different scopes).
               printf ("WARNING: lookup of qualifier prefix from SgTemplateArgument was previously disabled \n");
#endif
               SgTemplateArgument* node = isSgTemplateArgument(referencedNode);
               nameQualifier = node->get_qualified_name_prefix_for_type();
               break;
             }

       // DQ (7/13/2013): I think we need this here, but wait until we generate the error to drive it to be introduced.
       // Also this does not permit handling of multiple types requiring different name qualification (same as for throw support).
       // DQ (7/12/2013): Added support to type trait builtin functions 
          case V_SgTypeTraitBuiltinOperator:

       // DQ (8/19/2013): Added support for constructor initializers that might have an associated 
       // qualified name string associated with the templated class or instantiated template class.
          case V_SgConstructorInitializer:

          case V_SgTypeIdOp:
          case V_SgSizeOfOp:
          case V_SgNewExp:
          case V_SgCastExp:
             {
            // SgCastExp* node = isSgCastExp(referencedNode);
               SgExpression* node = isSgExpression(referencedNode);
               nameQualifier = node->get_qualified_name_prefix_for_referenced_type();
               break;
             }

          case V_SgClassType:
             {
            // These can appear in throw expression lists...ignore for now...
            // SgType* node = isSgType(referencedNode);
            // nameQualifier = node->get_qualified_name_prefix_for_type();
            // printf ("WARNING: Note that qualified types in throw expression lists are not yet supported... \n");
               break;
             }

          case V_SgFunctionType:
             {
            // These can appear in typedefs of function pointers...ignore for now...
            // SgType* node = isSgType(referencedNode);
            // nameQualifier = node->get_qualified_name_prefix_for_type();
            // printf ("WARNING: Note that qualified types in function pointer typedefs are not yet supported... \n");
               break;
             }

          case V_SgTypedefType:
             {
            // These can appear in typedef types...ignore for now...
            // SgType* node = isSgType(referencedNode);
            // nameQualifier = node->get_qualified_name_prefix_for_type();
            // printf ("WARNING: Note that qualified types in typedef types are not yet supported... \n");
               break;
             }
#if 0
          case V_:
             {
               * node = is (referencedNode);
               nameQualifier = node->get_qualified_name_prefix_for_type();
               break;
             }
#endif
          default:
             {
               printf ("In Unparser_Nameq::lookup_generated_qualified_name(): Sorry not implemented case of name qualification for info.get_reference_node_for_qualification() = %s \n",referencedNode->class_name().c_str());
               ROSE_ASSERT(false);
             }
        }

     return nameQualifier;
   }
Beispiel #6
0
//! search for all possible (virtual) function calls 
vector<SgMemberFunctionDeclaration*> 
Classhierarchy::searchMemberFunctionCalls(SgMemberFunctionDeclaration* mfCall)
{
        vector<SgMemberFunctionDeclaration*> retvec;
        property_map< dbgType, boost::vertex_classhierarchy_t>::type chMap = boost::get( boost::vertex_classhierarchy, *this );

        SgClassDefinition *classDef  = mfCall->get_scope();
        SgName                                           classname = classDef->get_qualified_name(); // MANGLE
        string                                           cnamestr  = classname.str();
        graph_traits< dbgType >::vertex_iterator vi,vend;
        dbgVertex vdesc = *vi;
        bool foundVertex = false;
        tie(vi,vend) = vertices( *this );
        for(; vi!=vend; vi++) {
                //cerr << " BCH v i"<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl;
                if( get(vertex_dbg_data, *this, *vi).get_typeName() == cnamestr ) {
                        //cerr << " SMF srch "<< cnamestr <<" vi "<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl;
                        vdesc = *vi;
                        foundVertex = true;
                        break;
                }
        }
        if(!foundVertex) { cerr << " SMF srch "<< cnamestr <<" vi "<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl; }
        assert( foundVertex );

        set<dbgVertex> treeset;
        treeset.insert( vdesc );

        // first find "highest" class in CH that still provides this MF
        dbgVertex vhighest = vdesc; // first assume its the current one
        graph_traits<dbgType>::out_edge_iterator oi,oend;
        tie(oi,oend) = out_edges( vdesc, *this);
        for(; oi!=oend; oi++) {
                //cerr << " SMF inherits from "<< get(vertex_index,*this,target(*oi,*this))<< " i1" << get(vertex_index1, *this, target(*oi,*this))<<","<< get(vertex_name, *this, target(*oi,*this)) << endl;
                
                // does any of the base classes implement the member function?
                bool noParentImpl = true; 
                
                // check if this base class also implements MF
                for(set<SgNode*>::iterator chd= chMap[target(*oi,*this)].inherited.begin(); 
                                chd!= chMap[target(*oi,*this)].inherited.end(); chd++) {
                        SgFunctionDeclaration *inhFunc = isSgFunctionDeclaration( *chd );
                        bool virt = false;
                        //cerr << "  TOPO v srch1" << endl;
                        if(inhFunc->isVirtual()) virt = true;
                        if( (virt) && (compareFunctionDeclarations(inhFunc,mfCall)) ) {
                                // remeber for traversal
                                treeset.insert( target(*oi, *this) );
                                noParentImpl = false;
                        }
                }
                if(noParentImpl) {
                        // we found it
                        vhighest = target(*oi, *this);
                        break;
                }
        }
        //cerr << " SMF high "<< cnamestr <<" vi "<< get(vertex_index,*this,vhighest)<< " i1" << get(vertex_index1, *this, vhighest)<<","<< get(vertex_name, *this, vhighest) << endl; 

        // now traverse class hierachy downwards, for all children that implement this function, add to set
        set<dbgVertex> tovisit;
        set<dbgVertex> visited;
        tovisit.insert( vhighest );
        //hier weiter
        while( tovisit.size() > 0 ) {
                dbgVertex currVert = *(tovisit.begin());
                tovisit.erase( currVert );
                visited.insert( currVert );
        //cerr << " SMF visi "<< get(vertex_index,*this,currVert)<< " i1" << get(vertex_index1, *this, currVert)<<","<< get(vertex_name, *this, currVert) << endl; 
                for(set<SgNode*>::iterator chd= chMap[currVert].defined.begin(); chd!= chMap[currVert].defined.end(); chd++) {
                        SgMemberFunctionDeclaration*inhFunc = isSgMemberFunctionDeclaration( *chd );
                        if(compareFunctionDeclarations(inhFunc,mfCall)) {
                                retvec.push_back( inhFunc );
                        }
                }
                graph_traits<dbgType>::in_edge_iterator ii,iend;
                tie(ii,iend) = in_edges( currVert, *this);
                for(; ii!=iend; ii++) {
                        dbgVertex child = source(*ii, *this);
                        // only insert of not already visited
                        set<dbgVertex>::iterator found = visited.find( child );
                        if(found == visited.end()) 
                                tovisit.insert( child );
                }
        }

        //retvec.push_back( mfCall );
        return retvec;
}
Beispiel #7
0
SgFunctionDeclaration * CudaOutliner::generateFunction ( SgBasicBlock* s,
                                                         const string& func_name_str,
                                                         ASTtools::VarSymSet_t& syms,
							 MintHostSymToDevInitMap_t hostToDevVars,
							 const ASTtools::VarSymSet_t& pdSyms,
                                                         const ASTtools::VarSymSet_t& psyms,
                                                         SgScopeStatement* scope)
{
  //Create a function named 'func_name_str', with a parameter list from 'syms'                                                             
  //pdSyms specifies symbols which must use pointer dereferencing if replaced during outlining,  
  //only used when -rose:outline:temp_variable is used                                                                                     
  //psyms are the symbols for OpenMP private variables, or dead variables (not live-in, not live-out)    

  ROSE_ASSERT ( s && scope);
  ROSE_ASSERT(isSgGlobal(scope));

  // step 1: perform necessary liveness and side effect analysis, if requested.     
  // ---------------------------------------------------------                                                                           
  std::set< SgInitializedName *> liveIns, liveOuts;
  // Collect read-only variables of the outlining target                                                                                
  std::set<SgInitializedName*> readOnlyVars;
  if (Outliner::temp_variable||Outliner::enable_classic)
    {
      SgStatement* firstStmt = (s->get_statements())[0];
      if (isSgForStatement(firstStmt)&& Outliner::enable_liveness)
        {
          LivenessAnalysis * liv = SageInterface::call_liveness_analysis (SageInterface::getProject());
	  SageInterface::getLiveVariables(liv, isSgForStatement(firstStmt), liveIns, liveOuts);
        }
      SageInterface::collectReadOnlyVariables(s,readOnlyVars);
      if (0)//Outliner::enable_debug)
        {
          cout<<"  INFO:Mint: CudaOutliner::generateFunction()---Found "<<readOnlyVars.size()<<" read only variables..:";
          for (std::set<SgInitializedName*>::const_iterator iter = readOnlyVars.begin();
               iter!=readOnlyVars.end(); iter++)
            cout<<" "<<(*iter)->get_name().getString()<<" ";
          cout<<endl;
          cout<<"CudaOutliner::generateFunction() -----Found "<<liveOuts.size()<<" live out variables..:";
          for (std::set<SgInitializedName*>::const_iterator iter = liveOuts.begin();
               iter!=liveOuts.end(); iter++)
            cout<<" "<<(*iter)->get_name().getString()<<" ";
          cout<<endl;
        }
    }
    //step 2. Create function skeleton, 'func'.             
    // -----------------------------------------                
  SgName func_name (func_name_str);
  SgFunctionParameterList *parameterList = buildFunctionParameterList();
  
  SgType* func_Type = SgTypeVoid::createType ();
  SgFunctionDeclaration* func = createFuncSkeleton (func_name, func_Type ,parameterList, scope);

  //adds __global__ keyword 
  func->get_functionModifier().setCudaKernel();
 
  ROSE_ASSERT (func);

  // Liao, 4/15/2009 , enforce C-bindings  for C++ outlined code 
  // enable C code to call this outlined function                                                                                
  // Only apply to C++ , pure C has trouble in recognizing extern "C"                                                    
  // Another way is to attach the function with preprocessing info:                                                     
  // #if __cplusplus                                                                                                           
  // extern "C"                                                                                                              
  // #endif                                                                                                                                
  // We don't choose it since the language linkage information is not explicit in AST                                                           
  if ( SageInterface::is_Cxx_language() || is_mixed_C_and_Cxx_language() \
       || is_mixed_Fortran_and_Cxx_language() || is_mixed_Fortran_and_C_and_Cxx_language() )
    {
      // Make function 'extern "C"'                                                                                                                                         
      func->get_declarationModifier().get_storageModifier().setExtern();
      func->set_linkage ("C");
    }

  //step 3. Create the function body                                                                                       
  // -----------------------------------------                                                                                              
  // Generate the function body by deep-copying 's'.                                                                                       
              
  SgBasicBlock* func_body = func->get_definition()->get_body();
  ROSE_ASSERT (func_body != NULL);

  // This does a copy of the statements in "s" to the function body of the outlined function.                                             
  ROSE_ASSERT(func_body->get_statements().empty() == true);

  // This calls AST copy on each statement in the SgBasicBlock, but not on the block, so the                                          
  // symbol table is setup by AST copy mechanism and it is  setup properly
  SageInterface::moveStatementsBetweenBlocks (s, func_body);

  if (Outliner::useNewFile)
    ASTtools::setSourcePositionAtRootAndAllChildrenAsTransformation(func_body);

  //step 4: variable handling, including:                                                                                                  
  // -----------------------------------------                                                                                             
  //   create parameters of the outlined functions                                                                                        
  //   add statements to unwrap the parameters if wrapping is requested
  //   add repacking statements if necessary                                                                                               
  //   replace variables to access to parameters, directly or indirectly                                                                  
  //   do not wrap parameters 
  Outliner::enable_classic = true;

  functionParameterHandling(syms, hostToDevVars, pdSyms, psyms, readOnlyVars, liveOuts, func);
  ROSE_ASSERT (func != NULL);
  
  // Retest this...  // Copied the similar fix from the rose outliner                        
  //     Liao 2/6/2013. It is essential to rebuild function type after the parameter list is finalized.
  //     The original function type was build using empty parameter list.
  SgType* stale_func_type = func->get_type();
  func->set_type(buildFunctionType(func->get_type()->get_return_type(), buildFunctionParameterTypeList(func->get_parameterList())));
  SgFunctionDeclaration* non_def_func = isSgFunctionDeclaration(func->get_firstNondefiningDeclaration ()) ;
  ROSE_ASSERT (non_def_func != NULL);
  ROSE_ASSERT (stale_func_type == non_def_func->get_type());
  non_def_func->set_type(func->get_type());

  ROSE_ASSERT(func->get_definition()->get_body()->get_parent() == func->get_definition());

  ROSE_ASSERT(scope->lookup_function_symbol(func->get_name()));

  return func;
}  
Beispiel #8
0
// 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;
   }
Beispiel #9
0
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;
}
Beispiel #10
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;
}
Beispiel #11
0
void
ProcTraversal::visit(SgNode *node) {
    if (isSgFunctionDeclaration(node)) {
        SgFunctionDeclaration *decl = isSgFunctionDeclaration(node);
        if (decl->get_definition() != NULL) {
            /* collect statistics */
            //AstNumberOfNodesStatistics anons;
            //anons.traverse(decl, postorder);
            //original_ast_nodes += anons.get_numberofnodes();
            //original_ast_statements += anons.get_numberofstatements();

            /* do the real work */
            Procedure *proc = new Procedure();
            proc->procnum = procnum++;
            proc->decl = decl;
            proc->funcsym
                = isSgFunctionSymbol(decl->get_symbol_from_symbol_table());
            if (proc->funcsym == NULL)
            {
#if 0
                std::cout
                        << std::endl
                        << "*** NULL function symbol for declaration "
                        << decl->unparseToString()
                        << std::endl
                        << "symbol: "
                        << (void *) decl->get_symbol_from_symbol_table()
                        << (decl->get_symbol_from_symbol_table() != NULL ?
                            decl->get_symbol_from_symbol_table()->class_name()
                            : "")
                        << std::endl
                        << "first nondef decl: "
                        << (void *) decl->get_firstNondefiningDeclaration()
                        << " sym: "
                        << (decl->get_firstNondefiningDeclaration() != NULL ?
                            (void *) decl->get_firstNondefiningDeclaration()
                            ->get_symbol_from_symbol_table()
                            : (void *) NULL)
                        << std::endl;
#endif
                if (decl->get_firstNondefiningDeclaration() != NULL)
                {
                    proc->funcsym = isSgFunctionSymbol(decl
                                                       ->get_firstNondefiningDeclaration()
                                                       ->get_symbol_from_symbol_table());
                }
            }
            assert(proc->funcsym != NULL);
            // GB (2008-05-14): We need two parameter lists: One for the names of the
            // variables inside the function definition, which is
            // decl->get_parameterList(), and one that contains any default arguments
            // the function might have. The default arguments are supposedly
            // associated with the first nondefining declaration.
            proc->params = decl->get_parameterList();
            SgDeclarationStatement *fndstmt = decl->get_firstNondefiningDeclaration();
            SgFunctionDeclaration *fnd = isSgFunctionDeclaration(fndstmt);
            if (fnd != NULL && fnd != decl)
                proc->default_params = fnd->get_parameterList();
            else
                proc->default_params = proc->params;

            SgMemberFunctionDeclaration *mdecl
                = isSgMemberFunctionDeclaration(decl);
            if (mdecl) {
                proc->class_type = isSgClassDefinition(mdecl->get_scope());
                std::string name = proc->class_type->get_mangled_name().str();
                name += "::";
                name += decl->get_name().str();
                std::string mname = proc->class_type->get_mangled_name().str();
                mname += "::";
                mname += decl->get_mangled_name().str();
                proc->memberf_name = name;
                proc->mangled_memberf_name = mname;
                proc->name = decl->get_name().str();
                proc->mangled_name = decl->get_mangled_name().str();
                // GB (2008-05-26): Computing a single this symbol for each
                // procedure. Thus, this symbol can also be compared by pointer
                // equality (as is the case for all other symbols). While we're at it,
                // we also build a VarRefExp for this which can be used everywhere the
                // this pointer occurs.
                proc->this_type = Ir::createPointerType(
                                      proc->class_type->get_declaration()->get_type());
                proc->this_sym = Ir::createVariableSymbol("this", proc->this_type);
                proc->this_exp = Ir::createVarRefExp(proc->this_sym);
            } else {
                proc->name = decl->get_name().str();
                proc->mangled_name = decl->get_mangled_name().str();
                proc->class_type = NULL;
                proc->memberf_name = proc->mangled_memberf_name = "";
                proc->this_type = NULL;
                proc->this_sym = NULL;
                proc->this_exp = NULL;
                // GB (2008-07-01): Better resolution of calls to static functions.
                // This only makes sense for non-member functions.
                SgStorageModifier &sm =
                    (fnd != NULL ? fnd : decl)->get_declarationModifier().get_storageModifier();
                proc->isStatic = sm.isStatic();
                // Note that we query the first nondefining declaration for the
                // static modifier, but we save the file of the *defining*
                // declaration. This is because the first declaration might be in
                // some header file, but for call resolution, the actual source
                // file with the definition is relevant.
                // Trace back to the enclosing file node. The definition might be
                // included in foo.c from bar.c, in which case the Sg_File_Info
                // would refer to bar.c; but for function call resolution, foo.c is
                // the relevant file.
                SgNode *p = decl->get_parent();
                while (p != NULL && !isSgFile(p))
                    p = p->get_parent();
                proc->containingFile = isSgFile(p);
            }
            proc_map.insert(std::make_pair(proc->name, proc));
            mangled_proc_map.insert(std::make_pair(proc->mangled_name, proc));
            std::vector<SgVariableSymbol* >* arglist
                = new std::vector<SgVariableSymbol* >();
            SgVariableSymbol *this_var = NULL, *this_temp_var = NULL;
            if (mdecl
                    || decl->get_parameterList() != NULL
                    && !decl->get_parameterList()->get_args().empty()) {
                proc->arg_block
                    = new BasicBlock(node_id, INNER, proc->procnum);
                if (mdecl) {
                    // GB (2008-05-26): We now compute the this pointer right at the
                    // beginning of building the procedure.
                    // this_var = Ir::createVariableSymbol("this", this_type);
                    this_var = proc->this_sym;
                    // std::string varname
                    //   = std::string("$") + proc->name + "$this";
                    // this_temp_var = Ir::createVariableSymbol(varname, proc->this_type);
                    this_temp_var = global_this_variable_symbol;
                    ParamAssignment* paramAssignment
                        = Ir::createParamAssignment(this_var, this_temp_var);
                    proc->arg_block->statements.push_back(paramAssignment);
                    arglist->push_back(this_var);
                    if (proc->name.find('~') != std::string::npos) {
                        arglist->push_back(this_temp_var);
                    }
                }
                SgInitializedNamePtrList params
                    = proc->params->get_args();
                SgInitializedNamePtrList::const_iterator i;
#if 0
                int parnum = 0;
                for (i = params.begin(); i != params.end(); ++i) {
                    SgVariableSymbol *i_var = Ir::createVariableSymbol(*i);
                    std::stringstream varname;
                    // varname << "$" << proc->name << "$arg_" << parnum++;
                    SgVariableSymbol* var =
                        Ir::createVariableSymbol(varname.str(),(*i)->get_type());
                    proc->arg_block->statements.push_back(Ir::createParamAssignment(i_var, var));
                    arglist->push_back(i_var);
                }
#else
                // GB (2008-06-23): Trying to replace all procedure-specific argument
                // variables by a global list of argument variables. This means that at
                // this point, we do not necessarily need to build a complete list but
                // only add to the CFG's argument list if it is not long enough.
                size_t func_params = params.size();
                size_t global_args = global_argument_variable_symbols.size();
                std::stringstream varname;
                while (global_args < func_params)
                {
                    varname.str("");
                    varname << "$tmpvar$arg_" << global_args++;
                    SgVariableSymbol *var
                        = Ir::createVariableSymbol(varname.str(),
                                                   global_unknown_type);
                    program->global_map[varname.str()]
                        = std::make_pair(var, var->get_declaration());
                    global_argument_variable_symbols.push_back(var);
                }
                // now create the param assignments
                size_t j = 0;
                for (i = params.begin(); i != params.end(); ++i)
                {
                    SgVariableSymbol *i_var = Ir::createVariableSymbol(params[j]);
                    SgVariableSymbol *var = global_argument_variable_symbols[j];
                    j++;
                    proc->arg_block->statements.push_back(
                        Ir::createParamAssignment(i_var, var));
                    arglist->push_back(i_var);
                }
#if 0
                // replace the arglist allocated above by the new one; this must be
                // fixed for this pointers!
                delete arglist;
                arglist = &global_argument_variable_symbols;
#endif
#endif
            } else {
                proc->arg_block = NULL;
            }
            /* If this is a constructor, call default constructors
             * of all base classes. If base class constructors are
             * called manually, these calls will be removed later. */
            if (mdecl
                    && strcmp(mdecl->get_name().str(),
                              proc->class_type->get_declaration()->get_name().str()) == 0
                    && proc->class_type != NULL) {
                SgBaseClassPtrList::iterator base;
                for (base = proc->class_type->get_inheritances().begin();
                        base != proc->class_type->get_inheritances().end();
                        ++base) {
                    SgClassDeclaration* baseclass = (*base)->get_base_class();
                    SgVariableSymbol *lhs
                        = Ir::createVariableSymbol("$tmpvar$" + baseclass->get_name(),
                                                   baseclass->get_type());
                    program->global_map["$tmpvar$" + baseclass->get_name()]
                        = std::make_pair(lhs, lhs->get_declaration());
                    SgMemberFunctionDeclaration* fd=get_default_constructor(baseclass);
                    assert(fd);
                    SgType* basetype=baseclass->get_type();
                    assert(basetype);
                    SgConstructorInitializer *sci
                        = Ir::createConstructorInitializer(fd,basetype);
                    ArgumentAssignment* a
                        = Ir::createArgumentAssignment(lhs, sci);
                    proc->arg_block->statements.push_back(a);

                    // std::string this_called_varname
                    //   = std::string("$") + baseclass->get_name() + "$this";
                    SgVariableSymbol *this_called_var
                    // = Ir::createVariableSymbol(this_called_varname,
                    //                            baseclass->get_type());
                        = global_this_variable_symbol;
                    ReturnAssignment* this_ass
                        = Ir::createReturnAssignment(this_var, this_called_var);
                    proc->arg_block->statements.push_back(this_ass);
                }
            }
            if (mdecl && mdecl->get_CtorInitializerList() != NULL
                    && !mdecl->get_CtorInitializerList()->get_ctors().empty()) {
                SgInitializedNamePtrList cis
                    = mdecl->get_CtorInitializerList()->get_ctors();
                SgInitializedNamePtrList::const_iterator i;
                if (proc->arg_block == NULL) {
                    proc->arg_block = new BasicBlock(node_id, INNER, proc->procnum);
                }
                for (i = cis.begin(); i != cis.end(); ++i) {
                    SgVariableSymbol* lhs = Ir::createVariableSymbol(*i);
                    SgAssignInitializer *ai
                        = isSgAssignInitializer((*i)->get_initializer());
                    SgConstructorInitializer *ci
                        = isSgConstructorInitializer((*i)->get_initializer());
                    /* TODO: other types of initializers */
                    if (ai) {
                        SgClassDeclaration *class_decl
                            = proc->class_type->get_declaration();
                        // GB (2008-05-26): We now compute the this pointer right at the
                        // beginning of building the procedure.
                        // SgVarRefExp* this_ref
                        //   = Ir::createVarRefExp("this",
                        //                         Ir::createPointerType(class_decl->get_type()));
                        SgVarRefExp* this_ref = proc->this_exp;
                        SgArrowExp* arrowExp
                            = Ir::createArrowExp(this_ref,Ir::createVarRefExp(lhs));
                        // GB (2008-03-17): We need to handle function calls in
                        // initializers. In order to be able to build an argument
                        // assignment, we need to know the function's return variable, so
                        // the expression labeler must be called on it. The expression
                        // number is irrelevant, however, as it does not appear in the
                        // return variable.
                        if (isSgFunctionCallExp(ai->get_operand_i())) {
#if 0
                            ExprLabeler el(0 /*expnum*/);
                            el.traverse(ai->get_operand_i(), preorder);
                            // expnum = el.get_expnum();
#endif
                            // GB (2008-06-25): There is now a single global return
                            // variable. This may or may not mean that we can simply ignore
                            // the code above. I don't quite understand why this labeling
                            // couldn't be done later on, and where its result was used.
                        }
                        ArgumentAssignment* argumentAssignment
                            = Ir::createArgumentAssignment(arrowExp,ai->get_operand_i());
                        proc->arg_block->statements.push_back(argumentAssignment);
                    } else if (ci) {
                        /* if this is a call to a base class's
                         * constructor, remove the call we generated
                         * before */
                        SgStatement* this_a = NULL;
                        SgClassDeclaration* cd = ci->get_class_decl();
                        std::deque<SgStatement *>::iterator i;
                        for (i = proc->arg_block->statements.begin();
                                i != proc->arg_block->statements.end();
                                ++i) {
                            ArgumentAssignment* a
                                = dynamic_cast<ArgumentAssignment *>(*i);
                            if (a && isSgConstructorInitializer(a->get_rhs())) {
                                SgConstructorInitializer* c
                                    = isSgConstructorInitializer(a->get_rhs());
                                std::string c_decl_name = c->get_class_decl()->get_name().str();
                                std::string cd_name = cd->get_name().str();
                                // if (c->get_class_decl()->get_name() == cd->get_name()) {
                                if (c_decl_name == cd_name) {
#if 0
                                    // erase the following assignment
                                    // of the this pointer as well
                                    this_a = *proc->arg_block->statements.erase(i+1);
                                    proc->arg_block->statements.erase(i);
#endif
                                    // GB (2008-03-28): That's an interesting piece of code, but
                                    // it might be very mean to iterators. At least it is hard to
                                    // see whether it is correct. So let's try it like this:
                                    // erase i; we get an iterator back, which refers to the next
                                    // element. Save that element as this_a, and then erase.
                                    std::deque<SgStatement *>::iterator this_pos;
                                    this_pos = proc->arg_block->statements.erase(i);
                                    this_a = *this_pos;
                                    proc->arg_block->statements.erase(this_pos);
                                    // Good. Looks like this fixed a very obscure bug.
                                    break;
                                }
                            }
                        }
                        /* now add the initialization */
                        proc->arg_block->statements.push_back(Ir::createArgumentAssignment(lhs, ci));
                        if (this_a != NULL)
                            proc->arg_block->statements.push_back(this_a);
                    }
                }
            }
            proc->entry = new CallBlock(node_id++, START, proc->procnum,
                                        new std::vector<SgVariableSymbol *>(*arglist),
                                        (proc->memberf_name != ""
                                         ? proc->memberf_name
                                         : proc->name));
            proc->exit = new CallBlock(node_id++, END, proc->procnum,
                                       new std::vector<SgVariableSymbol *>(*arglist),
                                       (proc->memberf_name != ""
                                        ? proc->memberf_name
                                        : proc->name));
            proc->entry->partner = proc->exit;
            proc->exit->partner = proc->entry;
            proc->entry->call_target = Ir::createFunctionRefExp(proc->funcsym);
            proc->exit->call_target = Ir::createFunctionRefExp(proc->funcsym);
            /* In constructors, insert an assignment $A$this = this
             * at the end to make sure that the 'this' pointer can be
             * passed back to the calling function uncobbled. */
            proc->this_assignment = NULL;
            if (mdecl) {
                SgMemberFunctionDeclaration* cmdecl
                    = isSgMemberFunctionDeclaration(mdecl->get_firstNondefiningDeclaration());
                // if (cmdecl && cmdecl->get_specialFunctionModifier().isConstructor()) {
                proc->this_assignment
                    = new BasicBlock(node_id++, INNER, proc->procnum);
                ReturnAssignment* returnAssignment
                    = Ir::createReturnAssignment(this_temp_var, this_var);
                proc->this_assignment->statements.push_back(returnAssignment);
                add_link(proc->this_assignment, proc->exit, NORMAL_EDGE);
                // }
            }
            std::stringstream varname;
            // varname << "$" << proc->name << "$return";
            // proc->returnvar = Ir::createVariableSymbol(varname.str(),
            //                                            decl->get_type()->get_return_type());
            proc->returnvar = global_return_variable_symbol;
            procedures->push_back(proc);
            if(getPrintCollectedFunctionNames()) {
                std::cout << (proc->memberf_name != ""
                              ? proc->memberf_name
                              : proc->name)
                          << " " /*<< proc->decl << std::endl*/;
            }
            if (proc->arg_block != NULL)
            {
                proc->arg_block->call_target
                    = Ir::createFunctionRefExp(proc->funcsym);
            }
            // delete arglist;
        }
    }
}
SgFunctionSymbol*
SimpleInstrumentation::buildNewFunctionDeclaration ( SgStatement* statementLocation, SgFunctionType* previousFunctionType )
   {
  // *****************************************************
  // Create the functionDeclaration
  // *****************************************************

  // Must mark the newly built node to be a part of a transformation so that it will be unparsed!
     Sg_File_Info * file_info = new Sg_File_Info();
     ROSE_ASSERT(file_info != NULL);
     file_info->set_isPartOfTransformation(true);

     SgName function_name = "contest_call";
     ROSE_ASSERT(previousFunctionType != NULL);
     SgFunctionDeclaration* functionDeclaration = new SgFunctionDeclaration(file_info, function_name, previousFunctionType);
     ROSE_ASSERT(functionDeclaration != NULL);
     ROSE_ASSERT(functionDeclaration->get_parameterList() != NULL);

  // ********************************************************************
  // Create the InitializedName for a parameter within the parameter list
  // ********************************************************************
     SgTypePtrList & argList = previousFunctionType->get_arguments();
     SgTypePtrList::iterator i = argList.begin();
     while ( i != argList.end() )
        {
          SgName var_name = "";
          SgInitializer* var_initializer = NULL;
          SgInitializedName *var_init_name = new SgInitializedName(var_name, *i, var_initializer, NULL);
          functionDeclaration->get_parameterList()->append_arg(var_init_name);
          i++;
        }

  // Add any additional function arguments here! Make sure that the function type is consistant.

  // Get the scope
     SgScopeStatement* scope = statementLocation->get_scope();

  // Set the parent node in the AST (this could be done by the AstPostProcessing
     functionDeclaration->set_parent(scope);

  // Set the scope explicitly (since it could be different from the parent?)
     functionDeclaration->set_scope(scope);

  // If it is not a forward declaration then the unparser will skip the ";" at the end (need to fix this better)
     functionDeclaration->setForward();
     ROSE_ASSERT(functionDeclaration->isForward() == true);

  // Mark function as extern "C"
     functionDeclaration->get_declarationModifier().get_storageModifier().setExtern();
     functionDeclaration->set_linkage("C");  // This mechanism could be improved!

     bool inFront = true;
     SgGlobal* globalScope = TransformationSupport::getGlobalScope(statementLocation);
     SgFunctionDeclaration* functionDeclarationInGlobalScope = 
          TransformationSupport::getFunctionDeclaration(statementLocation);
     ROSE_ASSERT(globalScope != NULL);
     ROSE_ASSERT(functionDeclarationInGlobalScope != NULL);
     globalScope->insert_statement(functionDeclarationInGlobalScope,functionDeclaration,inFront);

     SgFunctionSymbol* functionSymbol = new SgFunctionSymbol(functionDeclaration);
     ROSE_ASSERT(functionSymbol != NULL);
     ROSE_ASSERT(functionSymbol->get_type() != NULL);

     return functionSymbol;
   }
void SimpleInstrumentation::visit ( SgNode* astNode )
   {
     switch(astNode->variantT()) 
        {
          case V_SgFunctionCallExp:
             {
               SgFunctionCallExp *functionCallExp = isSgFunctionCallExp(astNode);
               SgExpression *function = functionCallExp->get_function();
               ROSE_ASSERT(function);
               switch (function->variantT())
                  {
                    case V_SgFunctionRefExp:
                       {
                         SgFunctionRefExp *functionRefExp = isSgFunctionRefExp(function);
                         SgFunctionSymbol *symbol = functionRefExp->get_symbol();
                         ROSE_ASSERT(symbol != NULL);
                         SgFunctionDeclaration *functionDeclaration = symbol->get_declaration();
                         ROSE_ASSERT(functionDeclaration != NULL);
                         if (symbol == functionSymbol)
                            {
                           // Now we know that we have found the correct function call 
                           // (even in the presence of overloading or other forms of hidding)
                           // Now fixup the symbol and type of the SgFunctionRefExp object to 
                           // reflect the new function to be called (after this we still have to 
                           // fixup the argument list in the SgFunctionCallExp.

                           // We only want to build the decalration once (and insert it into the global scope)
                           // after that we save the symbol and reuse it.
                              if (newFunctionSymbol == NULL)
                                 {
                                   SgFunctionType* originalFunctionType = isSgFunctionType(functionSymbol->get_type());
                                   ROSE_ASSERT(originalFunctionType != NULL);
                                   newFunctionSymbol = buildNewFunctionDeclaration (TransformationSupport::getStatement(astNode),originalFunctionType);
                                 }

                              ROSE_ASSERT(newFunctionSymbol != NULL);
                              ROSE_ASSERT(newFunctionSymbol->get_type() != NULL);

                              functionRefExp->set_symbol(newFunctionSymbol);
                            }

                         break;
                       }
                    default:
                         cerr<<"warning: unrecognized variant: "<<function->class_name();
                  }
               break;
             }

          case V_SgFunctionDeclaration:
             {
               SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(astNode);
               string functionName = functionDeclaration->get_name().str();
               if (functionName == "send")
                  {
                    SgFunctionType *functionType = functionDeclaration->get_type();
                    ROSE_ASSERT(functionType != NULL);
                    bool foundFunction = false;
                    if (functionType->get_return_type()->unparseToString() == "ssize_t")
                       {
                         SgTypePtrList & argumentList = functionType->get_arguments();
                         SgTypePtrList::iterator i = argumentList.begin();
                         if ( (*i++)->unparseToString() == "int" )
                              if ( (*i++)->unparseToString() == "const void *" )
                                   if ( (*i++)->unparseToString() == "size_t" )
                                        if ( (*i++)->unparseToString() == "int" )
                                             foundFunction = true;
                       }

                    if (foundFunction == true)
                       {
                      // Now get the sysmbol using functionType
                         SgScopeStatement *scope = functionDeclaration->get_scope();
                         ROSE_ASSERT(scope != NULL);
                         functionSymbol = scope->lookup_function_symbol (functionName,functionType);
                       }
                  }
               break;
             }
          default:
             {
            // No other special cases
             }
        }
   }
Beispiel #14
0
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;
}
Beispiel #15
0
int main( int argc, char * argv[] )
{
// Option to linearize the array.
  Rose_STL_Container<std::string> localCopy_argv = CommandlineProcessing::generateArgListFromArgcArgv(argc, argv);
  int newArgc;
  char** newArgv = NULL;
  vector<string> argList = localCopy_argv;
  if (CommandlineProcessing::isOption(argList,"-f2c:","linearize",true) == true)
  {
    isLinearlizeArray = true;
  }
  CommandlineProcessing::generateArgcArgvFromList(argList,newArgc, newArgv);
// Build the AST used by ROSE
  SgProject* project = frontend(newArgc,newArgv);
  AstTests::runAllTests(project);   

  if (SgProject::get_verbose() > 2)
    generateAstGraph(project,8000,"_orig");
  
  // Traversal with Memory Pool to search for variableDeclaration
  variableDeclTraversal translateVariableDeclaration;
  traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
  for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
  {
    /*
       For the Fortran AST, a single variableDeclaration can be shared by multiple variables.
       This violated the normalization rules for C unparser.  Therefore, we have to transform it.
    */
    SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
    ROSE_ASSERT(variableDeclaration);
    if((variableDeclaration->get_variables()).size() != 1)
    {
      updateVariableDeclarationList(variableDeclaration);
      statementList.push_back(variableDeclaration);
      removeList.push_back(variableDeclaration);
    }
  }

  // reset the vector that collects all variable declaration. We need to walk through memory pool again to find types
  
  variableDeclList.clear();
  traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
  for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
  {
    SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
    ROSE_ASSERT(variableDeclaration);
    SgInitializedNamePtrList initializedNameList = variableDeclaration->get_variables();
    for(SgInitializedNamePtrList::iterator i=initializedNameList.begin(); i!=initializedNameList.end();++i)
    {
      SgInitializedName* initiallizedName = isSgInitializedName(*i);
      SgType* baseType = initiallizedName->get_type();
      if(baseType->variantT() == V_SgArrayType)
      {
        SgArrayType* arrayBase = isSgArrayType(baseType);
        // At this moment, we are still working on the Fortran-stype AST.  Therefore, there is no nested types for multi-dim array.
        if(arrayBase->findBaseType()->variantT() == V_SgTypeString)
        {
          arrayBase->reset_base_type(translateType(arrayBase->findBaseType()));
          arrayBase->set_rank(arrayBase->get_rank()+1);
        }
      }
      else
      {
        initiallizedName->set_type(translateType(baseType));
      }
    }
  }

  // replace the AttributeSpecificationStatement 
  Rose_STL_Container<SgNode*> AttributeSpecificationStatement = NodeQuery::querySubTree (project,V_SgAttributeSpecificationStatement);
  for (Rose_STL_Container<SgNode*>::iterator i = AttributeSpecificationStatement.begin(); i != AttributeSpecificationStatement.end(); i++)
  {
    SgAttributeSpecificationStatement* attributeSpecificationStatement = isSgAttributeSpecificationStatement(*i);
    ROSE_ASSERT(attributeSpecificationStatement);
    translateAttributeSpecificationStatement(attributeSpecificationStatement);
    statementList.push_back(attributeSpecificationStatement);
    removeList.push_back(attributeSpecificationStatement);
  }

  // replace the parameter reference
  parameterTraversal translateParameterRef;
  traverseMemoryPoolVisitorPattern(translateParameterRef);
  for(vector<SgVarRefExp*>::iterator i=parameterRefList.begin(); i!=parameterRefList.end(); ++i)
  {
    SgVarRefExp* parameterRef = isSgVarRefExp(*i);
    if(parameterSymbolList.find(parameterRef->get_symbol()) != parameterSymbolList.end())
    {
      SgExpression* newExpr = isSgExpression(deepCopy(parameterSymbolList.find(parameterRef->get_symbol())->second));
      ROSE_ASSERT(newExpr);
      newExpr->set_parent(parameterRef->get_parent());
      replaceExpression(parameterRef,
                        newExpr,
                        false);
    }
  }

  /*
     Parameters will be replaced by #define, all the declarations should be removed
  */
  for(map<SgVariableSymbol*,SgExpression*>::iterator i=parameterSymbolList.begin();i!=parameterSymbolList.end();++i)
  {
    SgVariableSymbol* symbol = i->first;
    SgInitializedName* initializedName = symbol->get_declaration();
    SgVariableDeclaration* decl = isSgVariableDeclaration(initializedName->get_parent());
    statementList.push_back(decl);
    removeList.push_back(decl);
  }


  // Traversal with Memory Pool to search for arrayType
  arrayTypeTraversal translateArrayType;
  traverseMemoryPoolVisitorPattern(translateArrayType);
  for(vector<SgArrayType*>::iterator i=arrayTypeList.begin(); i!=arrayTypeList.end(); ++i)
  {
    if(isLinearlizeArray)
    {
      linearizeArrayDeclaration(*i);
    }
    else
    {
      translateArrayDeclaration(*i);
    }
  }

  // Traversal with Memory Pool to search for pntrArrRefExp
  pntrArrRefTraversal translatePntrArrRefExp;
  traverseMemoryPoolVisitorPattern(translatePntrArrRefExp);
  for(vector<SgPntrArrRefExp*>::iterator i=pntrArrRefList.begin(); i!=pntrArrRefList.end(); ++i)
  {
    if(isLinearlizeArray)
    {
      linearizeArraySubscript(*i);
    }
    else
    {
      translateArraySubscript(*i);
    }
  }


  Rose_STL_Container<SgNode*> functionList = NodeQuery::querySubTree (project,V_SgFunctionDeclaration);
  for (Rose_STL_Container<SgNode*>::iterator i = functionList.begin(); i != functionList.end(); i++)
  {
    if((isSgProcedureHeaderStatement(*i) != NULL) ||
       (isSgProgramHeaderStatement(*i) != NULL)){
      SgFunctionDeclaration* functionBody = isSgFunctionDeclaration(*i);
      bool hasReturnVal = false;
      if(isSgProcedureHeaderStatement(functionBody))
      {
        hasReturnVal = isSgProcedureHeaderStatement(functionBody)->isFunction();
      }
      fixFortranSymbolTable(functionBody->get_definition(),hasReturnVal);
    }
  } 

  // Traversal with Memory Pool to search for equivalenceStatement
  equivalencelTraversal translateEquivalenceStmt;
  traverseMemoryPoolVisitorPattern(translateEquivalenceStmt);
  for(vector<SgEquivalenceStatement*>::iterator i=equivalenceList.begin(); i!=equivalenceList.end(); ++i)
  {
    SgEquivalenceStatement* equivalenceStatement = isSgEquivalenceStatement(*i);
    ROSE_ASSERT(equivalenceStatement);
    translateEquivalenceStatement(equivalenceStatement);
    statementList.push_back(equivalenceStatement);
    removeList.push_back(equivalenceStatement);
  }



  // Simple traversal, bottom-up, to translate the rest
  f2cTraversal f2c;
  f2c.traverseInputFiles(project,postorder);

  // removing all the unsed statement from AST
  for(vector<SgStatement*>::iterator i=statementList.begin(); i!=statementList.end(); ++i)
  {
    removeStatement(*i);
    (*i)->set_parent(NULL);
  }
      
  // deepDelete the removed nodes 
  for(vector<SgNode*>::iterator i=removeList.begin(); i!=removeList.end(); ++i)
  {
    deepDelete(*i);
  }
      
/*
  1. There should be no Fortran-specific AST nodes in the whole
     AST graph after the translation. 
  
  TODO: make sure translator generating clean AST 
*/
    //generateDOT(*project);
  if (SgProject::get_verbose() > 2)
    generateAstGraph(project,8000);
  return backend(project);
}
Beispiel #16
0
int main(int argc, char *argv[])
{
	std::string filename;

    SgProject *project = frontend(argc, argv);
#ifdef NEWDU
    EDefUse *edu=new EDefUse(project);
		// Create the global def-use analysis
		if (edu->run(false)==0)
		{
			std::cerr<<"DFAnalysis failed!"<<endl;
		}
#endif
		std::vector<InterproceduralInfo*> ip;

 // list < SgNode * >functionDeclarations = NodeQuery::querySubTree(project, V_SgFunctionDeclaration);
    NodeQuerySynthesizedAttributeType functionDeclarations = NodeQuery::querySubTree(project, V_SgFunctionDeclaration);

 // for (list < SgNode * >::iterator i = functionDeclarations.begin(); i != functionDeclarations.end(); i++)
    for (NodeQuerySynthesizedAttributeType::iterator i = functionDeclarations.begin(); i != functionDeclarations.end(); i++)
    {
        DataDependenceGraph *ddg;
        InterproceduralInfo *ipi;

        SgFunctionDeclaration *fD = isSgFunctionDeclaration(*i);

        // SGFunctionDefinition * fDef;
        ROSE_ASSERT(fD != NULL);

        // CI (01/08/2007): A missing function definition is an indicator to a 
        // 
        // 
        // librarycall. 
        // * An other possibility would be a programmer-mistake, which we
        // don't treat at this point.  // I assume librarycall
        if (fD->get_definition() == NULL)
        {
        }
        else
        {
            // get the control depenence for this function
						ipi=new InterproceduralInfo(fD);

            ROSE_ASSERT(ipi != NULL);

            // get the data dependence for this function
#ifdef NEWDU
            ddg = new DataDependenceGraph(fD->get_definition(),edu);
#else
            ddg = new DataDependenceGraph(fD->get_definition());
#endif
						//printf("DDG for %s:\n", fD->get_name().str());
						
// Liao, Feb. 7/2008,
//strip off absolute path to avoid polluting the source tree with generated .dot files
            //filename = (fD->get_definition()->get_file_info()->get_filenameString ()) 
            filename = StringUtility::stripPathFromFileName((fD->get_definition()->get_file_info()->get_filenameString ()))
         + "." + (fD->get_name().getString()) + ".ddg.dot";
            ddg->writeDot((char *)filename.c_str());

        }   
    }
		return 0;
}
Beispiel #17
0
  void instr(SgProject* project, Rose_STL_Container<SgType*> types)
  {
    SgGlobal* global = SI::getFirstGlobalScope(project);
    std::string prefix("rtc_ti_"); //struct prefix
    std::string ti_type_str("struct rtc_typeinfo*");
    SgType* ti_type = SB::buildOpaqueType(ti_type_str,global);

    //Insert declarations from the typechecking library.

    //void minalloc_check(unsigned long long addr)
    SgFunctionDeclaration* minalloc_check_decl = SB::buildNondefiningFunctionDeclaration(
          SgName("minalloc_check"),
          SgTypeVoid::createType(),
          SB::buildFunctionParameterList(
            SB::buildInitializedName("addr",SB::buildUnsignedLongLongType())),
          global,NULL);
    SI::prependStatement(minalloc_check_decl,global);

    //void typetracker_add(unsigned long long addr, struct rtc_typeinfo* ti);
    SgFunctionDeclaration* typetracker_add_decl = SB::buildNondefiningFunctionDeclaration(
          SgName("typetracker_add"),
          SgTypeVoid::createType(),
          SB::buildFunctionParameterList(
            SB::buildInitializedName("addr",SB::buildUnsignedLongLongType()),
            SB::buildInitializedName("ti",ti_type)),
          global,NULL);
    SI::prependStatement(typetracker_add_decl,global);

    //void setBaseType(rtc_typeinfo* ti, rtc_typeinfo* base)
    SgFunctionDeclaration* setBaseType_decl = SB::buildNondefiningFunctionDeclaration(
          SgName("setBaseType"),
          SgTypeVoid::createType(),
          SB::buildFunctionParameterList(
            SB::buildInitializedName("ti",ti_type),
            SB::buildInitializedName("base",ti_type)),
          global,NULL);
    SI::prependStatement(setBaseType_decl,global);

    //struct rtc_typeinfo* ti_init(const char* a, size_t sz, int c)
    SgFunctionDeclaration* ti_init_decl = SB::buildNondefiningFunctionDeclaration(
                                            SgName("ti_init"),
                                            ti_type,
                                            SB::buildFunctionParameterList(
//    SB::buildInitializedName("a",SB::buildPointerType(SB::buildConstType(SB::buildCharType()))),
                                                SB::buildInitializedName("a",SB::buildPointerType(SB::buildCharType())),
//    SB::buildInitializedName("sz", SB::buildOpaqueType("size_t",global)),
                                                SB::buildInitializedName("sz", SB::buildLongLongType()),
                                                SB::buildInitializedName("c", SB::buildIntType())),
                                            global,NULL);
    SI::prependStatement(ti_init_decl,global);

    //void traverseAndPrint()
    SgFunctionDeclaration* traverseAndPrint_decl = SB::buildNondefiningFunctionDeclaration(
          SgName("traverseAndPrint"),SgTypeVoid::createType(),SB::buildFunctionParameterList(),global,NULL);
    SI::prependStatement(traverseAndPrint_decl,global);

    //non-defining declaration of rtc_init_typeinfo
    SgName init_name("rtc_init_typeinfo");
    SgFunctionDeclaration* init_nondef = SB::buildNondefiningFunctionDeclaration(init_name,SgTypeVoid::createType(),SB::buildFunctionParameterList(),global,NULL);
    SI::prependStatement(init_nondef,global);

    //call to rtc_init_typeinfo placed in main function.
    SgFunctionDeclaration* maindecl = SI::findMain(project);
    SgExprStatement* initcall = SB::buildFunctionCallStmt(init_name,SgTypeVoid::createType(),NULL,maindecl->get_definition());
    maindecl->get_definition()->prepend_statement(initcall);

    //defining declaration of rtc_init_typeinfo
    SgFunctionDeclaration* init_definingDecl = new SgFunctionDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),init_name,init_nondef->get_type(),NULL);
    init_definingDecl->set_firstNondefiningDeclaration(init_nondef);
    SgFunctionDefinition* init_definition = new SgFunctionDefinition(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),init_definingDecl,SB::buildBasicBlock());
    init_definingDecl->set_definition(init_definition);
    SI::appendStatement(init_definingDecl,global);

    std::vector<std::string> lst;
    for(unsigned int index = 0; index < types.size(); index++)
    {
      SgType* ptr = types[index];

      ptr = ptr->stripTypedefsAndModifiers();
      if(!shouldInstrumentType(ptr))
        continue;
      std::string nameStr = prefix + Util::getNameForType(ptr).getString();
      if(!contains(lst,nameStr))
      {
        SgVariableDeclaration* decl = SB::buildVariableDeclaration(nameStr,ti_type,NULL,global);
        SI::prependStatement(decl,global);
        lst.push_back(nameStr);
      }
    }

    for(unsigned int index = 0; index < types.size(); index++)
    {
      SgType* ptr = types[index];
      ptr = ptr->stripTypedefsAndModifiers();
      if(!shouldInstrumentType(ptr))
        continue;
      std::string typeNameStr = Util::getNameForType(ptr).getString();
      std::string structNameStr = prefix + Util::getNameForType(ptr).getString();

      if(contains(lst,structNameStr))
      {
        SgExpression* lhs;
        SgExpression* rhs;

        //In case of an anonymous struct or union, we create a local, named version of the declaration so we can know its size.
        SgClassDeclaration* altDecl = NULL;
        if(isSgNamedType(ptr) && isSgClassDeclaration(isSgNamedType(ptr)->get_declaration()) && isSgClassDeclaration(isSgNamedType(ptr)->get_declaration())->get_isUnNamed())
        {
          SgClassDeclaration* originalDecl = isSgClassDeclaration(isSgNamedType(ptr)->get_declaration()->get_definingDeclaration());
          SgName altDecl_name(typeNameStr + "_def");
          altDecl = new SgClassDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),altDecl_name,originalDecl->get_class_type());

          SgClassDefinition* altDecl_definition = SB::buildClassDefinition(altDecl);

          SgDeclarationStatementPtrList originalMembers = originalDecl->get_definition()->get_members();
          for(SgDeclarationStatementPtrList::iterator it = originalMembers.begin(); it != originalMembers.end(); it++)
          {
            SgDeclarationStatement* member = *it;
            SgDeclarationStatement* membercpy = isSgDeclarationStatement(SI::copyStatement(member));
            altDecl_definition->append_member(membercpy);
          }


          SgClassDeclaration* altDecl_nondef = new SgClassDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),altDecl_name,originalDecl->get_class_type());

          altDecl_nondef->set_scope(global);
          altDecl->set_scope(global);

          altDecl->set_firstNondefiningDeclaration(altDecl_nondef);
          altDecl_nondef->set_firstNondefiningDeclaration(altDecl_nondef);
          altDecl->set_definingDeclaration(altDecl);
          altDecl_nondef->set_definingDeclaration(altDecl);


          SgClassType* altDecl_ct = SgClassType::createType(altDecl_nondef);
          altDecl->set_type(altDecl_ct);
          altDecl_nondef->set_type(altDecl_ct);

          altDecl->set_isUnNamed(false);
          altDecl_nondef->set_isUnNamed(false);

          altDecl_nondef->set_forward(true);

          SgSymbol* sym = new SgClassSymbol(altDecl_nondef);
          global->insert_symbol(altDecl_name, sym);

          altDecl->set_linkage("C");
          altDecl_nondef->set_linkage("C");

          ROSE_ASSERT(sym && sym->get_symbol_basis() == altDecl_nondef);
          ROSE_ASSERT(altDecl->get_definingDeclaration() == altDecl);
          ROSE_ASSERT(altDecl->get_firstNondefiningDeclaration() == altDecl_nondef);
          ROSE_ASSERT(altDecl->search_for_symbol_from_symbol_table() == sym);
          ROSE_ASSERT(altDecl->get_definition() == altDecl_definition);
          ROSE_ASSERT(altDecl->get_scope() == global && altDecl->get_scope() == altDecl_nondef->get_scope());
          ROSE_ASSERT(altDecl_ct->get_declaration() == altDecl_nondef);

          //For some reason, this is not working...

          //global->append_statement(altDecl);
          //global->prepend_statement(altDecl_nondef);

          //SI::setOneSourcePositionForTransformation(altDecl);
          //SI::setOneSourcePositionForTransformation(altDecl_nondef);
        }

        SgType* baseType;
        if(isSgPointerType(ptr))
          baseType = ptr->dereference();
        else
          baseType = ptr->findBaseType();

        baseType = baseType->stripTypedefsAndModifiers();
        if(baseType == NULL || baseType == ptr)
        {
          //In this case, there is no base type.
          rhs = SB::buildFunctionCallExp(SgName("ti_init"),SgTypeVoid::createType(),SB::buildExprListExp(
                                           SB::buildStringVal(ptr->unparseToString()),
                                           ((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)),
                                           SB::buildIntVal(getClassification(ptr))
                                         ),init_definition);
        }
        else
        {
          //The type has a base type.
          std::string baseStructNameStr = prefix + Util::getNameForType(baseType).getString();
          rhs = SB::buildFunctionCallExp(SgName("ti_init"),ti_type,SB::buildExprListExp(
                                           SB::buildStringVal(ptr->unparseToString()),
                                           ((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)),
                                           SB::buildIntVal(getClassification(ptr))
                                         ),init_definition);

          SgExprStatement* set_BT = SB::buildFunctionCallStmt(SgName("setBaseType"),ti_type,SB::buildExprListExp(
                                      SB::buildVarRefExp(structNameStr),
                                      SB::buildVarRefExp(baseStructNameStr)),
                                    init_definition);
          init_definition->append_statement(set_BT);
        }
        lhs = SB::buildVarRefExp(structNameStr);


        SgExprStatement* assignstmt = SB::buildAssignStatement(lhs,rhs);
        init_definition->prepend_statement(assignstmt);
        std::remove(lst.begin(),lst.end(),structNameStr);

      }



    }
  }
Beispiel #18
0
    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();
            }
        }

    }
Beispiel #19
0
//! init virtual fucntion inheritance
void Classhierarchy::inheritVirtualFunctions()
{
        // prepare LUT for multiple declarations
        //map<SgNode *, set<SgNode *> > multDec;
                
        property_map< dbgType, boost::vertex_classhierarchy_t>::type chMap = boost::get( boost::vertex_classhierarchy, *this );
        graph_traits< dbgType >::vertex_iterator vi,vend;
        tie(vi,vend) = vertices( *this );
        //graph_traits< dbgType >::vertex_descriptor par=*vi, succ=*vi;

        // output info
        for(; vi!=vend; vi++) {
                //cerr << " BCH v i"<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl;
                for( set<SgNode*>::iterator chd= chMap[*vi].defined.begin(); chd!= chMap[*vi].defined.end(); chd++) {
                        SgFunctionDeclaration *funcDec = isSgFunctionDeclaration( *chd );
                        //cerr << " BCH chd " << funcDec->get_mangled_name().str()<< endl; // debug
                        //cerr << " BCH chd " << funcDec->get_mangled_name().str()<< " "<< (int)funcDec->get_type() << endl; // debug
                }
        }

        // search for multiple declarations
        tie(vi,vend) = vertices( *this );
        for(; vi!=vend; vi++) {
                for(set<SgNode*>::iterator chd= chMap[*vi].defined.begin(); chd!= chMap[*vi].defined.end(); chd++) {
                        SgFunctionDeclaration *funcDec = isSgFunctionDeclaration( *chd );
                        bool found = true;
                        while(found) {
                                found = false;
                                for(set<SgNode*>::iterator chdComp = chMap[*vi].defined.begin(); 
                                                (chdComp!= chMap[*vi].defined.end())&&(!found); ) {
                                        SgFunctionDeclaration *compDec = isSgFunctionDeclaration( *chdComp );
                                        if(chdComp != chd) {
                                                //if( compDec->get_type() == funcDec->get_type() ) { // ??? TODO fix type comparison?
                                                if(compareFunctionDeclarations(compDec, funcDec)) {
                                                        //cerr << " BCH REM " << funcDec->get_mangled_name().str()<< " " << compDec->get_mangled_name().str() << endl; // debug
                                                        chMap[*vi].multDeclarations[ funcDec ].insert( compDec );
                                                        found = true;
                                                        chMap[*vi].defined.erase( chdComp ); // should return new iterator in newer STL standard??
                                                        //chVertexData::iterator chdComp2 = (chMap[*vi]).erase( chdComp );
                                                        //chdComp = chdComp2;
                //cerr << " BCH removing i"<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl;
                                                }
                                        }
                                        if(!found) chdComp++;
                                }
                        } // found
                        
                }
                //if( get( vertex_dbg_data,  *this , *vi).get_id() == edges[i].get_sourceId() ) {
                //par = *vi;
                //parFound = true;
                //}
        }


        //typedef std::deque< boostVert > container;
        //cerr << " TOPO START " << endl;
        std::deque< dbgVertex > torder;
        try {
                boost::topological_sort(*this, std::back_inserter(torder));
        } catch(boost::not_a_dag) {
                cerr << "CH -  BOOST ERROR: NOT A DAG!!!!!??? " << endl;
                assert( false );
                return;
        }
        //cerr << " TOPO END " << endl;

        //cerr << " -- " << endl; // debug
        
        for( std::deque< dbgVertex >::iterator vi=torder.begin(); vi!=torder.end(); vi++) {
                dbgVertex srcVert = *vi; // current vertex in the topo order
                //cerr << "XTOPO v i"<< get(vertex_index,*this,*vi)<< " i1" << get(vertex_index1, *this, *vi)<<","<< get(vertex_name, *this, *vi) << endl;

                for(set<SgNode*>::iterator chd= chMap[srcVert].defined.begin(); chd!= chMap[srcVert].defined.end(); chd++) {
                        SgFunctionDeclaration *defMF = isSgFunctionDeclaration( *chd );
                        
                        bool erased = true;
                        while(erased) {
                                erased = false;
                                for(set<SgNode*>::iterator inhd= chMap[srcVert].inherited.begin(); 
                                                inhd!= chMap[srcVert].inherited.end() && (!erased); ) {
                                        SgFunctionDeclaration *inhMF = isSgFunctionDeclaration( *inhd );
                                        if(compareFunctionDeclarations(defMF, inhMF)) {
                                                // own function overrides, so delete old one
                                                chMap[srcVert].inherited.erase( *inhd );
                                                erased = true;
                //cerr << "  TOPO MF:"<< defMF->get_mangled_name().str()<< " overrides MF:"<< inhMF->get_mangled_name().str() << endl; // debug
                                        }
                                        if(!erased) inhd++;
                                }
                        }
                        
                }               
                // add to inherited functions
                for(set<SgNode*>::iterator chd= chMap[srcVert].defined.begin(); chd!= chMap[srcVert].defined.end(); chd++) {
                        chMap[srcVert].inherited.insert( *chd );
                }

                // inherit own methods to child classes
                graph_traits<dbgType>::in_edge_iterator ii,iend;
                tie(ii,iend) = in_edges(*vi, *this);
                for(; ii!=iend; ii++) {
                        //dbgVertex srcVert = source(*ii,*this);
                        // methods inherited from this class to the other one
                        dbgVertex child = source(*ii, *this);
                //cerr << " T inherits to "<< get(vertex_index,*this,child)<< " i1" << get(vertex_index1, *this, child)<<","<< get(vertex_name, *this, child) << endl;
                        //for(set<SgNode*>::iterator chd= chMap[srcVert].defined.begin(); chd!= chMap[srcVert].defined.end(); chd++) {
                        for(set<SgNode*>::iterator chd= chMap[srcVert].inherited.begin(); chd!= chMap[srcVert].inherited.end(); chd++) {
                                SgFunctionDeclaration *inhFunc = isSgFunctionDeclaration( *chd );
                                bool virt = false;
                //cerr << "  TOPO v srch1" << endl;
                                if(inhFunc->isVirtual()) virt = true;
                                // also check multiple declarations
                //cerr << "  TOPO v srch2" << endl;
                                if(!virt) {
                                        for(set<SgNode *>::iterator si=chMap[srcVert].multDeclarations[inhFunc].begin(); 
                                                        si != chMap[srcVert].multDeclarations[inhFunc].end(); si++) {
                                                SgFunctionDeclaration *inhDup = isSgFunctionDeclaration( *si );
                                                if(inhDup->isVirtual()) virt = true;
                //cerr << "  TOPO v srch "<< inhDup->get_mangled_name().str() << endl; // debug
                                        }
                                }
                                        // TODO check virtual inheritance? other declarations?
                                if(virt) {
                                        //cerr << " VIRT " << inhFunc->get_mangled_name().str() << endl; // debug
                                        // and now... ??
                                }
                                chMap[child].inherited.insert( inhFunc );
                        }
                        //cerr << " BOOST v <<< " << get(vertex_index1, *this, boost::target(*ii,*this) )<<","<< get(vertex_name, *this, boost::target(*ii,*this) ) << endl; // debug
                }

        }

        // add own methods to all inherited ones
        for( std::deque< dbgVertex >::iterator vi=torder.begin(); vi!=torder.end(); vi++) {
        }

}
int main(int argc, char** argv) {

  std::string binaryFilename = (argc >= 1 ? argv[argc-1]   : "" );
  std::vector<std::string> newArgv(argv,argv+argc);
  newArgv.push_back("-rose:output");
  newArgv.push_back(binaryFilename+"-binarySemantics.C");

  SgProject* proj = frontend(newArgv);
  
  ROSE_ASSERT (proj);
  SgSourceFile* newFile = isSgSourceFile(proj->get_fileList().front());
  ROSE_ASSERT(newFile != NULL);
  SgGlobal* g = newFile->get_globalScope();
  ROSE_ASSERT (g);

  //I am doing some experimental work to enable functions in the C representation
  //Set this flag to true in order to enable that work
  bool enable_functions = true;
  //Jeremiah did some work to enable a simplification and normalization of the 
  //C representation. Enable this work by setting this flag to true.
  bool enable_normalizations = false;

  vector<SgNode*> asmFiles = NodeQuery::querySubTree(proj, V_SgAsmGenericFile);
  ROSE_ASSERT (asmFiles.size() == 1);



  if( enable_functions == false)
  {
    //Representation of C normalizations withotu functions
    SgFunctionDeclaration* decl = buildDefiningFunctionDeclaration("run", SgTypeVoid::createType(), buildFunctionParameterList(), g);
    appendStatement(decl, g);
    SgBasicBlock* body = decl->get_definition()->get_body();
    //  ROSE_ASSERT(isSgAsmFile(asmFiles[0]));
    //  X86CTranslationPolicy policy(newFile, isSgAsmFile(asmFiles[0]));
    X86CTranslationPolicy policy(newFile, isSgAsmGenericFile(asmFiles[0]));
    ROSE_ASSERT( isSgAsmGenericFile(asmFiles[0]) != NULL);

    policy.switchBody = buildBasicBlock();
    removeDeadStores(policy.switchBody,policy);

    SgSwitchStatement* sw = buildSwitchStatement(buildVarRefExp(policy.ipSym), policy.switchBody);
    ROSE_ASSERT(isSgBasicBlock(sw->get_body()));

    SgWhileStmt* whileStmt = buildWhileStmt(buildBoolValExp(true), sw);

    appendStatement(whileStmt, body);
    policy.whileBody = sw;

    X86InstructionSemantics<X86CTranslationPolicy, WordWithExpression> t(policy);
    //AS FIXME: This query gets noting in the form in the repository. Doing this hack since we only 
    //have one binary file anyways.
    //vector<SgNode*> instructions = NodeQuery::querySubTree(asmFiles[0], V_SgAsmX86Instruction);
    vector<SgNode*> instructions = NodeQuery::querySubTree(proj, V_SgAsmX86Instruction);

    std::cout << "Instruction\n";
    for (size_t i = 0; i < instructions.size(); ++i) {
      SgAsmX86Instruction* insn = isSgAsmX86Instruction(instructions[i]);
      ROSE_ASSERT (insn);
      try {
          t.processInstruction(insn);
      } catch (const X86InstructionSemantics<X86CTranslationPolicy, WordWithExpression>::Exception &e) {
          std::cout <<e.mesg <<": " <<unparseInstructionWithAddress(e.insn) <<"\n";
      }
    }


    if ( enable_normalizations == true )
    {
      //Enable normalizations of C representation
      //This is done heuristically where some steps
      //are repeated. It is not clear which order is 
      //the best
      {
        plugInAllConstVarDefs(policy.switchBody,policy) ;
        simplifyAllExpressions(policy.switchBody);
        removeIfConstants(policy.switchBody);
        removeDeadStores(policy.switchBody,policy);
        removeUnusedVariables(policy.switchBody);
      }
      {
        plugInAllConstVarDefs(policy.switchBody,policy) ;
        simplifyAllExpressions(policy.switchBody);
        removeIfConstants(policy.switchBody);
        removeDeadStores(policy.switchBody,policy);
      }
      removeUnusedVariables(policy.switchBody);
    }

  
  }else{ //Experimental changes to introduce functions into the C representation


    //When trying to add function I get that symbols are not defined

    //Iterate over the functions separately
    vector<SgNode*> asmFunctions = NodeQuery::querySubTree(proj, V_SgAsmFunction);

    for(size_t j = 0; j < asmFunctions.size(); j++ )
    {
      SgAsmFunction* binFunc = isSgAsmFunction( asmFunctions[j] );

      // Some functions (probably just one) are generated to hold basic blocks that could not
      // be assigned to a particular function. This happens when the Disassembler is overzealous
      // and the Partitioner cannot statically determine where the block belongs.  The name of
      // one such function is "***uncategorized blocks***".  [matzke 2010-06-29]
      if ((binFunc->get_reason() & SgAsmFunction::FUNC_LEFTOVERS))
        continue;

      //Some functions may be unnamed so we need to generate a name for those
      std::string funcName;
      if (binFunc->get_name().size()==0) {
	char addr_str[64];
	sprintf(addr_str, "0x%"PRIx64, binFunc->get_statementList()[0]->get_address());
	funcName = std::string("my_") + addr_str;;
      } else {
	funcName = "my" + binFunc->get_name();
      }

      //Functions can have illegal characters in their name. Need to replace those characters
      for ( int i = 0 ; i < funcName.size(); i++ )
      {
	char& currentCharacter = funcName.at(i);
	if ( currentCharacter == '.' )
	  currentCharacter = '_';
      }


      SgFunctionDeclaration* decl = buildDefiningFunctionDeclaration(funcName, SgTypeVoid::createType(), buildFunctionParameterList(), g);

      appendStatement(decl, g);
      SgBasicBlock* body = decl->get_definition()->get_body();
      X86CTranslationPolicy policy(newFile, isSgAsmGenericFile(asmFiles[0]));
      ROSE_ASSERT( isSgAsmGenericFile(asmFiles[0]) != NULL);
      policy.switchBody = buildBasicBlock();
      SgSwitchStatement* sw = buildSwitchStatement(buildVarRefExp(policy.ipSym), policy.switchBody);
      SgWhileStmt* whileStmt = buildWhileStmt(buildBoolValExp(true), sw);
      appendStatement(whileStmt, body);
      policy.whileBody = sw;
      X86InstructionSemantics<X86CTranslationPolicy, WordWithExpression> t(policy);
      vector<SgNode*> instructions = NodeQuery::querySubTree(binFunc, V_SgAsmX86Instruction);

      for (size_t i = 0; i < instructions.size(); ++i) {
        SgAsmX86Instruction* insn = isSgAsmX86Instruction(instructions[i]);
	if( insn->get_kind() == x86_nop )
	  continue;
        ROSE_ASSERT (insn);
        try {
            t.processInstruction(insn);
        } catch (const X86InstructionSemantics<X86CTranslationPolicy, WordWithExpression>::Exception &e) {
            std::cout <<e.mesg <<": " <<unparseInstructionWithAddress(e.insn) <<"\n";
        }
      }

    }

    //addDirectJumpsToSwitchCases(policy);


  }

  proj->get_fileList().erase(proj->get_fileList().end() - 1); // Remove binary file before calling backend

//  AstTests::runAllTests(proj);

  //Compile the resulting project

  return backend(proj);
}
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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=0");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=0");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=1");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=1");
sss.push_back("0x2b916c912478<SgBasicBlock> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=6 :idx=0");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=1");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=1");
sss.push_back("var_ref_of_j<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=2");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=6 :idx=1");
sss.push_back("0x2b916c912478<SgBasicBlock> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=1");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=1");
sss.push_back("0x2b916c9125f0<SgBasicBlock> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=9 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=9 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=9 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=9 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=9 :idx=1");
sss.push_back("0x2b916c9125f0<SgBasicBlock> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<SgForStatement> @line=4 :idx=4");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=3");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=0");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=0");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=1");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=1");
sss.push_back("0x2b916c912478<SgBasicBlock> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=6 :idx=0");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=1");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=1");
sss.push_back("var_ref_of_j<SgVarRefExp> @line=6 :idx=0");
sss.push_back("SgAddOp_undef_name<SgAddOp> @line=6 :idx=2");
sss.push_back("SgAssignOp_undef_name<SgAssignOp> @line=6 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=6 :idx=1");
sss.push_back("0x2b916c912478<SgBasicBlock> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=1");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<SgForStatement> @line=4 :idx=4");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=3");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=0");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=0");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=1");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=1");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=1");
sss.push_back("0x2b916c9125f0<SgBasicBlock> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=9 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=9 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=9 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=9 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=9 :idx=1");
sss.push_back("0x2b916c9125f0<SgBasicBlock> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<SgForStatement> @line=4 :idx=4");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=3");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=0");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=0");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=5 :idx=0");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=5 :idx=1");
sss.push_back("SgModOp_undef_name<SgModOp> @line=5 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=5 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=5 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=1");
sss.push_back("0x2b916cb41010<SgIfStmt> @line=5 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=0");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=0");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=0");
sss.push_back("var_ref_of_k<SgVarRefExp> @line=8 :idx=0");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=8 :idx=1");
sss.push_back("SgSubtractOp_undef_name<SgSubtractOp> @line=8 :idx=2");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=1");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=8 :idx=1");
sss.push_back("SgEqualityOp_undef_name<SgEqualityOp> @line=8 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=1");
sss.push_back("0x2b916cb41180<SgIfStmt> @line=8 :idx=2");
sss.push_back("0x2b916c912300<SgBasicBlock> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<SgForStatement> @line=4 :idx=4");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=3");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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("0x2b916c912010<SgBasicBlock> @line=1 :idx=0");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=0");
sss.push_back("initialized_name_k<SgInitializedName> k :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_k<SgInitializedName> k :idx=1");
sss.push_back("_variable_declaration_k<SgVariableDeclaration> @line=2 :idx=1");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=0");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=0");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=0");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=0");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=3 :idx=1");
sss.push_back("SgAssignInitializer_undef_name<SgAssignInitializer> @line=3 :idx=1");
sss.push_back("initialized_name_i<SgInitializedName> i :idx=1");
sss.push_back("_variable_declaration_i<SgVariableDeclaration> @line=3 :idx=1");
sss.push_back("SgForInitStatement<SgForInitStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=0");
sss.push_back("0x2b916cac7178<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("0x2b916cac7178<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_2<SgIntVal> @line=4 :idx=0");
sss.push_back("integer_value_exp_2<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("0x2b916cac7178<SgForStatement> @line=4 :idx=2");
sss.push_back("0x2b916cac7178<SgForStatement> @line=4 :idx=4");
sss.push_back("0x2b916c912188<SgBasicBlock> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=3");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgPlusPlusOp_undef_name<SgPlusPlusOp> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=1");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=0");
sss.push_back("var_ref_of_i<SgVarRefExp> @line=3 :idx=0");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=1");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=0");
sss.push_back("integer_value_exp_2<SgIntVal> @line=3 :idx=1");
sss.push_back("SgLessThanOp_undef_name<SgLessThanOp> @line=3 :idx=2");
sss.push_back("SgExprStatement<SgExprStatement> @line=3 :idx=1");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=2");
sss.push_back("0x2b916cac7010<SgForStatement> @line=3 :idx=4");
sss.push_back("0x2b916c912010<SgBasicBlock> @line=1 :idx=2");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=0");
sss.push_back("integer_value_exp_0<SgIntVal> @line=13 :idx=1");
sss.push_back("SgReturnStmt<SgReturnStmt> @line=13 :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;
}
int main(int argc, char *argv[])
{
	std::string filename;

	SgProject *project = frontend(argc, argv);
	std::vector<InterproceduralInfo*> ip;
#ifdef NEWDU
	// Create the global def-use analysis
	DFAnalysis *defUseAnalysis=new DefUseAnalysis(project);
	if (defUseAnalysis->run(false)==0)
	{
		std::cerr<<"DFAnalysis failed!"<<endl;
	}
#endif
 string outputFileName=project->get_fileList().front()->get_sourceFileNameWithoutPath ();                                                                                                
 


	SystemDependenceGraph *sdg = new SystemDependenceGraph;
	// for all function-declarations in the AST
	NodeQuerySynthesizedAttributeType functionDeclarations = NodeQuery::querySubTree(project, V_SgFunctionDeclaration);

	for (NodeQuerySynthesizedAttributeType::iterator i = functionDeclarations.begin(); i != functionDeclarations.end(); i++)
	{
		ControlDependenceGraph *cdg;
		DataDependenceGraph *ddg;
	//	FunctionDependenceGraph * pdg;
		InterproceduralInfo *ipi;

		SgFunctionDeclaration *fDec = isSgFunctionDeclaration(*i);

		ROSE_ASSERT(fDec != NULL);

		// CI (01/08/2007): A missing function definition is an indicator to a 
		// 
		// 
		// librarycall. 
		// * An other possibility would be a programmer-mistake, which we
		// don't treat at this point.  // I assume librarycall
		if (fDec->get_definition() == NULL)
		{
//			if (fDec->get_file_info()->isCompilerGenerated()) continue;
			// treat librarycall -> iterprocedualInfo must be created...
			// make all call-parameters used and create a function stub for
			// the graph
			ipi=new InterproceduralInfo(fDec);
			ipi->addExitNode(fDec);
			sdg->addInterproceduralInformation(ipi);
			if (sdg->isKnownLibraryFunction(fDec))
			{
				sdg->createConnectionsForLibaryFunction(fDec);
			}
			else
			{
				sdg->createSafeConfiguration(fDec);
			}
			ip.push_back(ipi);

			// This is somewhat a waste of memory and a more efficient approach might generate this when needed, but at the momenent everything is created...
		}
		else
		{
			// get the control depenence for this function
			ipi=new InterproceduralInfo(fDec);

			ROSE_ASSERT(ipi != NULL);

			// get control dependence for this function defintion
			cdg = new ControlDependenceGraph(fDec->get_definition(), ipi);
			cdg->computeInterproceduralInformation(ipi);

			// get the data dependence for this function
			#ifdef NEWDU
			ddg = new DataDependenceGraph(fDec->get_definition(), defUseAnalysis,ipi);
			#else
			ddg = new DataDependenceGraph(fDec->get_definition(), ipi);
			#endif
			
			sdg->addFunction(cdg,ddg);
			sdg->addInterproceduralInformation(ipi);
			ip.push_back(ipi);
		}   
		// else if (fD->get_definition() == NULL)

	}
	// now all function-declarations have been process as well have all function-definitions
	filename = (outputFileName) + ".no_ii.sdg.dot";
	sdg->writeDot((char *)filename.c_str());
	
	// perform interproceduralAnalysys
	sdg->performInterproceduralAnalysis();

	filename = (outputFileName)+".deadEnds.sdg.dot";
	sdg->writeDot((char *)filename.c_str());			
	sdg->cleanUp();
	filename = (outputFileName)+".final.sdg.dot";
	sdg->writeDot((char *)filename.c_str());			
	

	//get SlicingInfo
	SlicingInfo si;
	si.traverse(project, preorder);

	set < SgNode * >totalSlicingSet;
	NodeQuerySynthesizedAttributeType targetList = si.getSlicingTargets();
	if (targetList.size()==0)
	{
		cout <<"no slicing targes, exiting"<<endl;
	}
	else
	{
		CreateSliceSet sliceSet(sdg,targetList);
		for (NodeQuerySynthesizedAttributeType::iterator i = targetList.begin(); i != targetList.end(); i++)
		{
			cout <<"slicing for \""<<(*i)->unparseToString()<<"\""<<endl;
			set < SgNode * >currentSlicingSet, tmp;
			currentSlicingSet=sliceSet.computeSliceSet(dynamic_cast<SgNode*>(*i));
			set_union(totalSlicingSet.begin(), totalSlicingSet.end(),
					currentSlicingSet.begin(), currentSlicingSet.end(),
					inserter(tmp, tmp.begin()));
			totalSlicingSet.swap(tmp);
		}
	}
	filename = (outputFileName)+".sliced.sdg.dot";
	sdg->writeDot((char *)filename.c_str());			
}
Beispiel #23
0
int main(int argc,char** argv) {
	SgProject* proj = frontend(argc,argv);
	fixAllPrefixPostfix(proj);
	initializeScopeInformation(proj);	
	SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj);

	SgFunctionDefinition* mainDef = mainDecl->get_definition();
	
	//SageInterface::rebuildSymbolTable(mainDef);
	StaticCFG::CFG cfg(mainDef);
	SgIncidenceDirectedGraph *g = cfg.getGraph();
	PathCollector* pathCollector = new PathCollector(g,&cfg);	

	std::vector<SgNode*> scopeNodes = NodeQuery::querySubTree(mainDef,V_SgScopeStatement);
	
	std::vector<SgGraphNode*> visited;
	std::vector<SgNode*> nodes = NodeQuery::querySubTree(mainDef,V_SgWhileStmt);
	std::vector<SgNode*>::iterator node = nodes.begin();
	for (; node != nodes.end(); node++) {
	SgScopeStatement* scopeOfWhile = SageInterface::getEnclosingScope(*node);
	SgStatementPtrList statementsInScope = scopeOfWhile->getStatementList();
	SgStatementPtrList::iterator statPtr = statementsInScope.begin();
	std::set<SgPragmaDeclaration*> prdecls;

	for (; statPtr!=statementsInScope.end();statPtr++) {
		if (isSgPragmaDeclaration(*statPtr)) {
			prdecls.insert(isSgPragmaDeclaration(*statPtr));
		}
	}
	//SgExprStatement* boundingConditionStatement = isSgExprStatement(isSgWhileStmt(*node)->get_condition()); 	
	//SgExpression* boundingCondition = boundingConditionStatement->get_expression();
	SgStatement* body = (isSgWhileStmt(*node)->get_body());
	std::vector<std::vector<SgGraphNode*> > paths = pathCollector->getPaths();

	
	std::cout << getPrelude() << std::endl;

		

	SgGraphNode* whileStart = cfg.cfgForBeginning(isSgWhileStmt(*node));		
	SgGraphNode* whileEnd = cfg.cfgForEnd(isSgWhileStmt(*node));
	collectPaths(whileStart,whileEnd, pathCollector);
	SgGraphNode* whileOut = getWhileEndNode(isSgWhileStmt(*node),pathCollector);
	SgGraphNode* bodyStart = cfg.cfgForBeginning(isSgWhileStmt(*node)->get_body());
	SgGraphNode* bodyEnd = cfg.cfgForEnd(isSgWhileStmt(*node)->get_body());

        pathCollector->clearPaths();
	
	collectPaths(bodyStart,whileOut,pathCollector);	
	paths.clear();
	paths = pathCollector->getPaths();
	std::vector<std::vector<SgGraphNode*> >::iterator i  = paths.begin();
	std::set<SgVariableSymbol*> vars = getVars(pathCollector);
	std::string vardecls;
	std::string initrule;
	std::vector<std::string> rules= getRules(*node,pathCollector, vars, vardecls,initrule);
	std::cout << vardecls << std::endl;
	for (int i = 0; i < rules.size(); i++) {
		std::cout << rules[i] << std::endl;
	}
	std::set<SgPragmaDeclaration*>::iterator pr = prdecls.begin();
	for (; pr != prdecls.end(); pr++) {
		std::set<std::string> variables;
		std::vector<std::string> s_expressions;
		std::string prag_str = get_pragma_string(*pr);
		bool initPrag;
		/*std::string rhs =*/ translateToS_Expr(prag_str,variables,s_expressions,initPrag);
		if (s_expressions.size() > 0) {
		std::string queryResult;
		if (initPrag) {
			queryResult = assumptionPragma(s_expressions,initrule);
		}
		else {
			queryResult = queryPragma(s_expressions,initrule);
		}	
		std::cout << queryResult << std::endl;
		}
	}
	}
	backend(proj);
	return 0;
	}
Beispiel #24
0
//searches for locations where types may be connected through assignment, passing as argument and returns
//then passes the associated node along with the expression to link variables.
int Analysis::variableSetAnalysis(SgProject* project, SgType* matchType, bool base){
  RoseAst wholeAST(project);
  list<SgVariableDeclaration*> listOfGlobalVars = SgNodeHelper::listOfGlobalVars(project);
  if(listOfGlobalVars.size() > 0){
    for(auto varDec : listOfGlobalVars){
      SgInitializedName* initName = SgNodeHelper::getInitializedNameOfVariableDeclaration(varDec);
      if(!initName) continue;
      SgInitializer* init = initName->get_initializer();
      if(!init) continue;
      SgType* keyType = initName->get_type();
      if(!checkMatch(base, keyType, matchType)) continue;
      addToMap(varDec, varDec);  
      if(!isArrayPointerType(keyType)) continue;
      SgExpression* exp = init;
      linkVariables(varDec, keyType, exp);
    }
  }
  list<SgFunctionDefinition*> listOfFunctionDefinitions = SgNodeHelper::listOfFunctionDefinitions(project);
  for(auto funDef : listOfFunctionDefinitions){  
    SgInitializedNamePtrList& initNameList = SgNodeHelper::getFunctionDefinitionFormalParameterList(funDef);
    SgFunctionDeclaration* funDec = funDef->get_declaration();
    if(checkMatch(base, funDec->get_type()->get_return_type(), matchType)) addToMap(funDec, funDec);
    for(auto init : initNameList) if(checkMatch(base, init->get_type(), matchType)) addToMap(init, init);
    RoseAst ast(funDef);
    for(RoseAst::iterator i = ast.begin(); i!=ast.end(); i++){
      SgNode* key = nullptr;
      SgType* keyType = nullptr;
      SgExpression* exp = nullptr;
      if(SgAssignOp* assignOp = isSgAssignOp(*i)){
        SgExpression* lhs = assignOp->get_lhs_operand();
        if(SgVarRefExp* varRef = isSgVarRefExp(lhs)){
          keyType = varRef->get_type();
          if(!isArrayPointerType(keyType)) continue;    
          SgVariableSymbol* varSym = varRef->get_symbol();
	  key = varSym->get_declaration()->get_declaration();
        }
        exp = assignOp->get_rhs_operand();
      }
      else if(SgVariableDeclaration* varDec = isSgVariableDeclaration(*i)){
        SgInitializedName* initName = SgNodeHelper::getInitializedNameOfVariableDeclaration(varDec);
        if(!initName) continue;
        if(checkMatch(base, matchType, initName->get_type())) addToMap(varDec, varDec);
        SgInitializer* init = initName->get_initializer();
        if(!init) continue;
        keyType = initName->get_type();
        if(!isArrayPointerType(keyType)) continue;
        key = initName->get_declaration();
        exp = init;
      }
      else if(SgFunctionCallExp* callExp = isSgFunctionCallExp(*i)){
        SgFunctionDefinition* funDef = SgNodeHelper::determineFunctionDefinition(callExp);
        if(!funDef) continue;
        SgInitializedNamePtrList& initNameList = SgNodeHelper::getFunctionDefinitionFormalParameterList(funDef);
        SgExpressionPtrList& expList = callExp->get_args()->get_expressions();
        auto initIter = initNameList.begin();
        auto expIter  = expList.begin(); 
        while(initIter != initNameList.end()){
          if(isArrayPointerType((*initIter)->get_type())){
            if(checkMatch(base, matchType, (*initIter)->get_type())) linkVariables((*initIter), (*initIter)->get_type(), (*expIter));
          }
          ++initIter;
          ++expIter;
        }
      }
      else if(SgReturnStmt* ret = isSgReturnStmt(*i)){
        exp = ret->get_expression();
        keyType = exp->get_type();
        if(!isArrayPointerType(keyType)) continue;
        key = funDec;
         
      }
      if(!checkMatch(base, keyType, matchType)) continue;
      if(key && keyType && exp) linkVariables(key, keyType, exp);
    }
  }
  for(auto i = setMap.begin(); i != setMap.end(); ++i){
    bool intersect = false;
    set<SgNode*>* found = nullptr;
    for(auto j = listSets.begin(); j != listSets.end(); ++j){
      intersect = setIntersect(*j, i->second);
      if((*j)->count(i->first)) intersect = true;
      if(found != nullptr && intersect){ 
        inPlaceUnion(found, i->second);
        inPlaceUnion(found, *j);
        (found)->insert(i->first);
        j = listSets.erase(j);
        ++j;
      }
      else if(intersect){
        inPlaceUnion(*j, i->second);
        (*j)->insert(i->first);
        found = *j;
      }
    }
    if(!intersect){
      set<SgNode*>* copy = copySet(i->second);
      copy->insert(i->first);
      listSets.push_back(copy);
    }
  }
  return 0;
}
Beispiel #25
0
  NodeQuerySynthesizedAttributeType
NodeQuery::querySolverVariableTypes (SgNode * astNode)
{
  ROSE_ASSERT (astNode != NULL);
  NodeQuerySynthesizedAttributeType returnNodeList;
  /*
     SgVariableDeclaration* sageVariableDeclaration = isSgVariableDeclaration(astNode);

     if(sageVariableDeclaration != NULL)
     {
     SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables();


     printf ("\nHere is a function declaration :Line = %d Columns = %d \n", ROSE:: getLineNumber (isSgLocatedNode(astNode) ), ROSE:: getColumnNumber ( isSgLocatedNode(astNode) ));
     cout << "The filename is:" << ROSE::getFileName(isSgLocatedNode(astNode)) << endl;


     typedef SgInitializedNamePtrList::iterator LI;

     for ( LI i = sageInitializedNameList.begin(); i != sageInitializedNameList.end(); ++i) {
     SgType* sageElementType = i->get_type();
     ROSE_ASSERT( sageElementType != NULL);

     cout << "The class name is: " << sageElementType->sage_class_name() << endl;
     returnNodeList.push_back( sageElementType );

     }
     cout << endl << "End printout of this Initialized Name list" << endl;


     }

   */
  // SgVarRefExp *sageVarRefExp = isSgVarRefExp (astNode);

  switch (astNode->variantT ())
  {

    case V_SgVariableDeclaration:
      {
        SgVariableDeclaration *sageVariableDeclaration =
          isSgVariableDeclaration (astNode);
        ROSE_ASSERT (sageVariableDeclaration != NULL);

        SgInitializedNamePtrList sageInitializedNameList =
          sageVariableDeclaration->get_variables ();

#if DEBUG_NODEQUERY
        printf ("\nIn filename: %s ",
            ROSE::getFileName (isSgLocatedNode (astNode)));
        printf ("\nHere is a variable :Line = %d Columns = %d \n",
            ROSE::getLineNumber (isSgLocatedNode (astNode)),
            ROSE::getColumnNumber (isSgLocatedNode (astNode)));
        //cout << "The typename of the variable is: " << typeName << endl;
#endif

        typedef SgInitializedNamePtrList::iterator variableIterator;
        SgType *typeNode;

        for (variableIterator variableListElement =
            sageInitializedNameList.begin ();
            variableListElement != sageInitializedNameList.end ();
            ++variableListElement)
        {
          SgInitializedName* elmVar = *variableListElement;

          ROSE_ASSERT (elmVar != NULL);
          typeNode = elmVar->get_type ();
          ROSE_ASSERT (typeNode != NULL);
          returnNodeList.push_back (typeNode);
        }
        break;
      }                         /* End case V_SgVariableDeclaration */

    case V_SgFunctionDeclaration:
    case V_SgMemberFunctionDeclaration:
      {
        SgFunctionDeclaration * sageFunctionDeclaration =
          isSgFunctionDeclaration (astNode);
        ROSE_ASSERT (sageFunctionDeclaration != NULL);

        SgInitializedNamePtrList sageInitializedNameList =
          sageFunctionDeclaration->get_args ();
        SgType *typeNode;

        typedef SgInitializedNamePtrList::iterator variableIterator;

        for (variableIterator variableListElement =
            sageInitializedNameList.begin ();
            variableListElement != sageInitializedNameList.end ();
            ++variableListElement)
        {
          SgInitializedName* elmVar = *variableListElement;

          ROSE_ASSERT (elmVar != NULL);
          typeNode = elmVar->get_type ();
          ROSE_ASSERT (typeNode != NULL);
          returnNodeList.push_back (typeNode);

        }

        break;
      }

    default:
      {
        // DQ (8/20/2005): Added default to avoid compiler warnings about unrepresented cases
      }
  }                             /* End switch case astNode */



  return returnNodeList;
}                               /* End function querySolverType() */
DetectMacroExpansionsToBeUnparsedAsAstTransformationsSynthesizedAttribute 
DetectMacroExpansionsToBeUnparsedAsAstTransformations::evaluateSynthesizedAttribute ( 
   SgNode* n, 
   DetectMacroExpansionsToBeUnparsedAsAstTransformationsInheritedAttribute inheritedAttribute, 
   SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     DetectMacroExpansionsToBeUnparsedAsAstTransformationsSynthesizedAttribute returnAttribute(n);

#if 0
     printf ("In (Detect Transformations in Macro Expansions) evaluateSynthesizedAttribute(): n = %s n->get_containsTransformation() = %s \n",n->class_name().c_str(),n->get_containsTransformation() ? "true" : "false");
#endif

  // DQ (11/8/2015): This has to be moved to after the tokenStreamSequenceMap has been setup since we need that to determine if 
  // IR nodes have a token mapping or not (subparts of macros expansions will not and we need this infor to recognize parts of 
  // the AST that are associated with macro expansions.
  // DQ (11/8/2015): If this has been marked as containing a transformation then check if there is token info for each of the children.
  // If there is not token info for each of the children then this currentStatement (e.g. n) must be marked as a transformation.
  // This case happens when a transformation is done to a child of a statement that is part of a macro.  In this case the parent will
  // have token information which is the macro call, but since there is a transformation, we have to unparse the fully expanded form 
  // of the macro (from the AST), so the whole subtree must be unparsed.  NOTE: this case might be more complex if multiple statements
  // are associated with a macro (so that there is not a single root of the subtree.  I need to build an example of this to better 
  // understand if there is a problem and if so just what would be the best solution.  It will b at least an iterative refinement of
  // this specific problem.  See tests/roseTests/astInterfaceTests/inputmoveDeclarationToInnermostScope_test2015_135.C for an example
  // of this problem.
     if (n->get_containsTransformation() == true)
        {
#if 0
          printf ("Found case of statement marked as containing a transforamtion \n");
#endif
          SgStatement* currentStatement = isSgStatement(n);
#if 0
          if (currentStatement != NULL)
             {
            // printf ("currentStatement = %p = %s \n",currentStatement,currentStatement->class_name().c_str());
               printf ("currentStatement = %s \n",currentStatement->class_name().c_str());
               printf ("   --- currentStatement->isTransformation()    = %s \n",currentStatement->isTransformation() ? "true" : "false");
             }
#endif
       // We have to test for a macro exapansion (will only work on statement level grainularity where parent statement has child statements).
          bool all_children_have_token_info = true;
          for (size_t i = 0; i < synthesizedAttributeList.size(); i++)
             {
               SgStatement* statement = isSgStatement(synthesizedAttributeList[i].node);
               if (statement != NULL)
                  {
#if 0
                 // printf ("(child) statement = %p = %s \n",statement,statement->class_name().c_str());
                    printf ("(child) statement = %s \n",statement->class_name().c_str());
                    printf ("   --- statement->isTransformation()           = %s \n",statement->isTransformation() ? "true" : "false");
                    printf ("   --- statement->get_containsTransformation() = %s \n",statement->get_containsTransformation() ? "true" : "false");
#endif
                 // DQ (11/8/2015): We might need to also check the surrounding white space as well (except that I think this is set later).
                    if (tokenStreamSequenceMap.find(statement) != tokenStreamSequenceMap.end())
                       {
                      // If we have a token mapping then we don't have to do anything.
                         TokenStreamSequenceToNodeMapping* mapping = tokenStreamSequenceMap[statement];
                         ROSE_ASSERT(mapping != NULL);
                       }
                      else
                       {
#if 0
                      // printf ("Parent statement = %p = %s No token stream information found for child statement = %p = %s \n",
                      //      currentStatement,currentStatement->class_name().c_str(),statement,statement->class_name().c_str());
                         printf ("Parent statement = %s No token stream information found for child statement = %s \n",
                              currentStatement->class_name().c_str(),statement->class_name().c_str());
                         printf ("   --- at line: %d \n",statement->get_file_info()->get_line());

                      // When this is a function declaration, try to understand more about it.
                         SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(statement);
                         if (functionDeclaration != NULL)
                            {
                              printf ("   --- functionDeclaration name = %s \n",functionDeclaration->get_name().str());
                            }
#endif
                         all_children_have_token_info = false;
                       }
                  }
             }

          if (currentStatement != NULL && all_children_have_token_info == false)
             {
#if 0
            // printf ("*** Found case of statement marked as containing a transforamtion, but all children without token info (detected a macro expansion): currentStatement = %p = %s \n",currentStatement,currentStatement->class_name().c_str());
               printf ("*** Found case of statement marked as containing a transforamtion, but all children without token info (detected a macro expansion): currentStatement = %s \n",currentStatement->class_name().c_str());
#endif

            // DQ (11/9/2015): Added support for specific scopes where we don't want them the be 
            // unparsed from the token stream when children of them are transformed.
            // DQ (11/8/2015): I think that this should not apply to a SgBasicBlock (for example see 
            // tests/roseTests/astInterfaceTests/inputmoveDeclarationToInnermostScope_test2015_94.C).
            // The reason is that a block is not the same sort for compound statement as a SgForStatement.
            // if (isSgBasicBlock(currentStatement) == NULL)
               bool current_statement_is_allowed_to_have_statements_with_unmapped_token_sequences = 
                    ( (isSgGlobal(currentStatement) != NULL)          || 
                      (isSgBasicBlock(currentStatement) != NULL)      ||
                   // (isSgEnumDefinition(currentStatement) != NULL)  ||
                      (isSgClassDefinition(currentStatement) != NULL) );

               if (current_statement_is_allowed_to_have_statements_with_unmapped_token_sequences == false)
                  {
                 // Mark as a transformation instead of containing a transformation.
                    currentStatement->setTransformation();

                 // We also need to mark this too!
                    currentStatement->setOutputInCodeGeneration();

                 // And reset this to NOT contain a transformation.
                    currentStatement->set_containsTransformation(false);
#if 0
                    printf ("Exiting as a test! \n");
                    ROSE_ASSERT(false);
#endif
                  }
                 else
                  {
#if 0
                 // printf ("This currentStatement = %p = %s is allowed to have a child without a token sequence mapping \n",currentStatement,currentStatement->class_name().c_str());
                    printf ("This currentStatement = %s is allowed to have a child without a token sequence mapping \n",currentStatement->class_name().c_str());
#endif
                  }
             }
#if 0
       // Debugging code.
          if (isSgForStatement(n) != NULL)
             {
               printf ("Exiting as a test! \n");
               ROSE_ASSERT(false);
             }
#endif
        }

     return returnAttribute;
   }
Beispiel #27
0
DOTSynthesizedAttribute
AstDOTGeneration::evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l)
   {
     SubTreeSynthesizedAttributes::iterator iter;
     ROSE_ASSERT(node);

  // printf ("AstDOTGeneration::evaluateSynthesizedAttribute(): node = %s \n",node->class_name().c_str());

  // DQ (5/3/2006): Skip this IR node if it is specified as such in the inherited attribute
     if (ia.skipSubTree == true)
        {
       // I am unclear if I should return NULL or node as a parameter to DOTSynthesizedAttribute
       // Figured this out: if we return a valid pointer then we get a node in the DOT graph 
       // (with just the pointer value as a label), where as if we return a DOTSynthesizedAttribute 
       // with a NUL pointer then the node will NOT appear in the DOT graph.
       // return DOTSynthesizedAttribute(node);
          return DOTSynthesizedAttribute(NULL);
        }

     string nodeoption;
     if(AstTests::isProblematic(node))
        {
       // cout << "problematic node found." << endl;
          nodeoption="color=\"orange\" ";
        }
     string nodelabel=string("\\n")+node->class_name();

  // DQ (1/24/2009): Added support for output of isForward flag in the dot graph.
     SgDeclarationStatement* genericDeclaration = isSgDeclarationStatement(node);
     if (genericDeclaration != NULL)
        {
       // At the moment the mnemonic name is stored, but it could be computed in the 
       // future from the kind and the tostring() function.
          string name = (genericDeclaration->isForward() == true) ? "isForward" : "!isForward";
          ROSE_ASSERT(name.empty() == false);

       // DQ (3/20/2011): Added class names to the generated dot file graphs of the AST.
          SgClassDeclaration* classDeclaration = isSgClassDeclaration(genericDeclaration);
          if (classDeclaration != NULL)
             {
               nodelabel += string("\\n") + classDeclaration->get_name();
             }

       // DQ (3/20/2011): Added function names to the generated dot file graphs of the AST.
          SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(genericDeclaration);
          if (functionDeclaration != NULL)
             {
               nodelabel += string("\\n") + functionDeclaration->get_name();
             }

       // DQ (2/29/2012): Added typedef names to the generated dot file graphs of the AST.
          SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(genericDeclaration);
          if (typedefDeclaration != NULL)
             {
               nodelabel += string("\\n") + typedefDeclaration->get_name();
             }

          nodelabel += string("\\n") + name;
        }

  // DQ (4/6/2011): Added support for output of the name for SgInitializedName IR nodes.
     SgInitializedName* initializedName = isSgInitializedName(node);
     if (initializedName != NULL)
        {
          nodelabel += string("\\n") + initializedName->get_name();
        }

  // DQ (4/6/2011): Added support for output of the name for SgInitializedName IR nodes.
     SgIntVal* intValue = isSgIntVal(node);
     if (intValue != NULL)
        {
          nodelabel += string("\\n value = ") + StringUtility::numberToString(intValue->get_value());
        }

  // DQ (4/6/2011): Added support for output of the name for SgInitializedName IR nodes.
     SgVarRefExp* varRefExp = isSgVarRefExp(node);
     if (varRefExp != NULL)
        {
          SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
          ROSE_ASSERT(variableSymbol != NULL);
          string name = variableSymbol->get_name();
          nodelabel += string("\\n name = ") + name;
        }

  // DQ (1/19/2009): Added support for output of what specific instrcution this is in the dot graph.
     SgAsmInstruction* genericInstruction = isSgAsmInstruction(node);
     if (genericInstruction != NULL)
        {
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
       // At the moment the mnemonic name is stored, but it could be computed in the 
       // future from the kind and the tostring() function.
#if 1
          string unparsedInstruction = unparseInstruction(genericInstruction);
          string addressString       = StringUtility::numberToString( (void*) genericInstruction->get_address() );
       // string name = genericInstruction->get_mnemonic();
          string name = unparsedInstruction + "\\n address: " + addressString;
#else
          string name = unparsedInstruction + "\\n" + addressString;
#endif
          ROSE_ASSERT(name.empty() == false);

          nodelabel += string("\\n") + name;
#else
          printf ("Warning: In AstDOTGeneration.C ROSE_BUILD_BINARY_ANALYSIS_SUPPORT is not defined \n");
#endif
        }

     SgAsmExpression* genericExpression = isSgAsmExpression(node);
     if (genericExpression != NULL)
        {
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
          string name = unparseExpression(genericExpression, NULL, NULL);
          ROSE_ASSERT(name.empty() == false);
          nodelabel += string("\\n") + name;
#else
          printf ("Warning: In AstDOTGeneration.C ROSE_BUILD_BINARY_ANALYSIS_SUPPORT is not defined \n");
#endif
        }

  // DQ (10/29/2008): Added some support for additional output of internal names for specific IR nodes.
  // In generall there are long list of these IR nodes in the binary and this helps make some sense of 
  // the lists (sections, symbols, etc.).
     SgAsmExecutableFileFormat* binaryFileFormatNode = isSgAsmExecutableFileFormat(node);
     if (binaryFileFormatNode != NULL)
        {
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
       // The case of binary file format IR nodes can be especially confusing so we want the 
       // default to output some more specific information for some IR nodes (e.g. sections).
          string name;

          SgAsmGenericSection* genericSection = isSgAsmGenericSection(node);
          if (genericSection != NULL)
             {
               SgAsmGenericString* genericString = genericSection->get_name();
               ROSE_ASSERT(genericString != NULL);

               name = genericString->get_string();
             }

          SgAsmGenericSymbol* genericSymbol = isSgAsmGenericSymbol(node);
          if (genericSymbol != NULL)
             {
               SgAsmGenericString* genericString = genericSymbol->get_name();
               ROSE_ASSERT(genericString != NULL);

               name = genericString->get_string();

               if (name.empty() == true)
                    name = "no_name_for_symbol";
             }

          SgAsmGenericDLL* genericDLL = isSgAsmGenericDLL(node);
          if (genericDLL != NULL)
             {
               SgAsmGenericString* genericString = genericDLL->get_name();
               ROSE_ASSERT(genericString != NULL);

               name = genericString->get_string();
             }

          SgAsmPEImportItem* peImportItem = isSgAsmPEImportItem(node);
          if (peImportItem != NULL)
             {
               SgAsmGenericString* genericString = peImportItem->get_name();
               ROSE_ASSERT(genericString != NULL);

               name = genericString->get_string();
             }

          SgAsmDwarfLine* asmDwarfLine = isSgAsmDwarfLine(node);
          if (asmDwarfLine != NULL)
             {
               char buffer[100];

            // It does not work to embed the "\n" into the single sprintf parameter.
            // sprintf(buffer," Addr: 0x%08"PRIx64" \n line: %d col: %d ",asmDwarfLine->get_address(),asmDwarfLine->get_line(),asmDwarfLine->get_column());

               sprintf(buffer,"Addr: 0x%08"PRIx64,asmDwarfLine->get_address());
               name = buffer;
               sprintf(buffer,"line: %d col: %d",asmDwarfLine->get_line(),asmDwarfLine->get_column());
               name += string("\\n") + buffer;
             }

          SgAsmDwarfConstruct* asmDwarfConstruct = isSgAsmDwarfConstruct(node);
          if (asmDwarfConstruct != NULL)
             {
               name = asmDwarfConstruct->get_name();
             }

#if 0
       // This might not be the best way to implement this, since we want to detect common base classes of IR nodes.
          switch (node->variantT())
             {
               case V_SgAsmElfSection:
                  {
                    SgAsmElfSection* n = isSgAsmElfSection(node);
                    name = n->get_name();
                    break;
                  }

               default:
                  {
                 // No additional information is suggested for the default case!
                  }
             }
#endif

          if (name.empty() == false)
               nodelabel += string("\\n") + name;
#else
          printf ("Warning: In AstDOTGeneration.C ROSE_BUILD_BINARY_ANALYSIS_SUPPORT is not defined \n");
#endif
        }

  // DQ (11/29/2008): Output the directives in the label of the IR node.
     SgC_PreprocessorDirectiveStatement* preprocessorDirective = isSgC_PreprocessorDirectiveStatement(node);
     if (preprocessorDirective != NULL)
        {
          string s = preprocessorDirective->get_directiveString();

       // Change any double quotes to single quotes so that DOT will not misunderstand the generated lables.
          while (s.find("\"") != string::npos)
             {
               s.replace(s.find("\""),1,"\'");
             }

          if (s.empty() == false)
               nodelabel += string("\\n") + s;
        }

     nodelabel += additionalNodeInfo(node);

  // DQ (11/1/2003) added mechanism to add additional options (to add color, etc.)
  // nodeoption += additionalNodeOptions(node);
     string additionalOptions = additionalNodeOptions(node);
  // printf ("nodeoption = %s size() = %ld \n",nodeoption.c_str(),nodeoption.size());
  // printf ("additionalOptions = %s size() = %ld \n",additionalOptions.c_str(),additionalOptions.size());

     string x;
     string y;
     x += additionalOptions;

     nodeoption += additionalOptions;

     DOTSynthesizedAttribute d(0);

  // DQ (7/27/2008): Added mechanism to support pruning of AST
     bool commentoutNode = commentOutNodeInGraph(node);
     if (commentoutNode == true)
        {
       // DQ (11/10/2008): Fixed to only output message when (verbose_level > 0); command-line option.
       // DQ (7/27/2008): For now just return to test this mechanism, then we want to add comment "//" propoerly to generated DOT file.
          if (SgProject::get_verbose() > 0)
             {
               printf ("Skipping the use of this IR node in the DOT Graph \n");
             }
        }
       else
        {

// **************************

     switch(traversal)
        {
          case TOPDOWNBOTTOMUP:
               dotrep.addNode(node,dotrep.traceFormat(ia.tdbuTracePos,tdbuTrace)+nodelabel,nodeoption);
               break;
          case PREORDER:
          case TOPDOWN:
               dotrep.addNode(node,dotrep.traceFormat(ia.tdTracePos)+nodelabel,nodeoption);
               break;
          case POSTORDER:
          case BOTTOMUP:
               dotrep.addNode(node,dotrep.traceFormat(buTrace)+nodelabel,nodeoption);
               break;
          default:
               assert(false);
        }
  
     ++tdbuTrace;
     ++buTrace;

  // add edges or null values
     int testnum=0;
     for (iter = l.begin(); iter != l.end(); iter++)
        {
          string edgelabel = string(node->get_traversalSuccessorNamesContainer()[testnum]);
          string toErasePrefix = "p_";

          if (AstTests::isPrefix(toErasePrefix,edgelabel))
             {
               edgelabel.erase(0, toErasePrefix.size());
             }

          if ( iter->node == NULL)
             {
            // SgNode* snode=node->get_traversalSuccessorContainer()[testnum];
               AstSuccessorsSelectors::SuccessorsContainer c;
               AstSuccessorsSelectors::selectDefaultSuccessors(node,c);
               SgNode* snode=c[testnum];

            // isDefault shows that the default constructor for synth attribute was used
               if (l[testnum].isDefault() && snode && (visitedNodes.find(snode) != visitedNodes.end()) )
                  {
                 // handle bugs in SAGE
                    dotrep.addEdge(node,edgelabel,snode,"dir=forward arrowhead=\"odot\" color=red ");
                  }
                 else
                  {
                    if (snode == NULL)
                       {
                         dotrep.addNullValue(node,"",edgelabel,"");
                       }
                  }
             }
            else
             {
            // DQ (3/5/2007) added mechanism to add additional options (to add color, etc.)
               string edgeoption = additionalEdgeOptions(node,iter->node,edgelabel);

               switch(traversal)
                  {
                    case TOPDOWNBOTTOMUP:
                         dotrep.addEdge(node,edgelabel,(*iter).node,edgeoption + "dir=both");
                         break;
                    case PREORDER:
                    case TOPDOWN:
                         dotrep.addEdge(node,edgelabel,(*iter).node,edgeoption + "dir=forward");
                         break;
                    case POSTORDER:
                    case BOTTOMUP:
                         dotrep.addEdge(node,edgelabel,(*iter).node,edgeoption + "dir=back");
                         break;
                    default:
                         assert(false);
                  }
             }

          testnum++;
        }

// **************************
        }



  // DQ (7/4/2008): Support for edges specified in AST attributes
     AstAttributeMechanism* astAttributeContainer = node->get_attributeMechanism();
     if (astAttributeContainer != NULL)
        {
       // Loop over all the attributes at this IR node
          for (AstAttributeMechanism::iterator i = astAttributeContainer->begin(); i != astAttributeContainer->end(); i++)
             {
            // std::string name = i->first;
               AstAttribute* attribute = i->second;
               ROSE_ASSERT(attribute != NULL);

            // This can return a non-empty list in user-defined attributes (derived from AstAttribute).
            // printf ("Calling attribute->additionalNodeInfo() \n");
               std::vector<AstAttribute::AttributeNodeInfo> nodeList = attribute->additionalNodeInfo();
            // printf ("nodeList.size() = %lu \n",nodeList.size());

               for (std::vector<AstAttribute::AttributeNodeInfo>::iterator i_node = nodeList.begin(); i_node != nodeList.end(); i_node++)
                  {
                    SgNode* nodePtr   = i_node->nodePtr;
                    string nodelabel  = i_node->label;
                    string nodeoption = i_node->options;
                 // printf ("In AstDOTGeneration::evaluateSynthesizedAttribute(): Adding a node nodelabel = %s nodeoption = %s \n",nodelabel.c_str(),nodeoption.c_str());
                 // dotrep.addNode(NULL,dotrep.traceFormat(ia.tdTracePos)+nodelabel,nodeoption);
                    dotrep.addNode( nodePtr, dotrep.traceFormat(ia.tdTracePos) + nodelabel, nodeoption );
                  }

            // printf ("Calling attribute->additionalEdgeInfo() \n");
               std::vector<AstAttribute::AttributeEdgeInfo> edgeList = attribute->additionalEdgeInfo();
            // printf ("edgeList.size() = %lu \n",edgeList.size());
               for (std::vector<AstAttribute::AttributeEdgeInfo>::iterator i_edge = edgeList.begin(); i_edge != edgeList.end(); i_edge++)
                  {
                    string edgelabel  = i_edge->label;
                    string edgeoption = i_edge->options;
                 // printf ("In AstDOTGeneration::evaluateSynthesizedAttribute(): Adding an edge from i_edge->fromNode = %p to i_edge->toNode = %p edgelabel = %s edgeoption = %s \n",i_edge->fromNode,i_edge->toNode,edgelabel.c_str(),edgeoption.c_str());
                    dotrep.addEdge(i_edge->fromNode,edgelabel,i_edge->toNode,edgeoption + "dir=forward");
                  }
             }
        }



     switch(node->variantT())
        {
       // DQ (9/1/2008): Added case for output of SgProject rooted DOT file.
       // This allows source code and binary files to be combined into the same DOT file.
          case V_SgProject: 
             {
               SgProject* project = dynamic_cast<SgProject*>(node);
               ROSE_ASSERT(project != NULL);

               string generatedProjectName = SageInterface::generateProjectName( project );
            // printf ("generatedProjectName (from SgProject) = %s \n",generatedProjectName.c_str());
               if (generatedProjectName.length() > 40)
                  {
                 // printf ("Warning: generatedProjectName (from SgProject) = %s \n",generatedProjectName.c_str());
                    generatedProjectName = "aggregatedFileNameTooLong";
                    printf ("Proposed (generated) filename is too long, shortened to: %s \n",generatedProjectName.c_str());
                  }

               string filename = string("./") + generatedProjectName + ".dot";

            // printf ("generated filename for dot file (from SgProject) = %s \n",filename.c_str());
               if ( SgProject::get_verbose() >= 1 )
                    printf ("Output the DOT graph from the SgProject IR node (filename = %s) \n",filename.c_str());

               dotrep.writeToFileAsGraph(filename);
               break;
             }

       // case V_SgFile: 
          case V_SgSourceFile: 
          case V_SgBinaryComposite: 
             {
               SgFile* file = dynamic_cast<SgFile*>(node);
               ROSE_ASSERT(file != NULL);

               string original_filename = file->getFileName();

            // DQ (7/4/2008): Fix filenamePostfix to go before the "."
            // string filename = string("./") + ROSE::stripPathFromFileName(original_filename) + "."+filenamePostfix+"dot";
               string filename = string("./") + ROSE::stripPathFromFileName(original_filename) + filenamePostfix + ".dot";

            // printf ("generated filename for dot file (from SgSourceFile or SgBinaryComposite) = %s file->get_parent() = %p \n",filename.c_str(),file->get_parent());

            // printf ("file->get_parent() = %p \n",file->get_parent());
            // cout << "generating DOT file (from SgSourceFile or SgBinaryComposite): " << filename2 << " ... ";

            // DQ (9/1/2008): this effects the output of DOT files when multiple files are specified 
            // on the command line.  A SgProject is still built even when a single file is specificed 
            // on the command line, however there are cases where a SgFile can be built without a 
            // SgProject and this case allows those SgFile rooted subtrees to be output as DOT files.
            // If there is a SgProject then output the dot file from there, else output as a SgFile.
               if (file->get_parent() == NULL)
                  {
                 // If there is no SgProject then output the file now!
                    if ( SgProject::get_verbose() >= 1 )
                         printf ("Output the DOT graph from the SgFile IR node (no SgProject available) \n");

                    dotrep.writeToFileAsGraph(filename);
                  }
                 else
                  {
                 // There is a SgProject IR node, but if we will be traversing it we want to output the 
                 // graph then (so that the graph will include the SgProject IR nodes and connect multiple 
                 // files (SgSourceFile or SgBinaryComposite IR nodes).
                    if ( visitedNodes.find(file->get_parent()) == visitedNodes.end() )
                       {
                      // This SgProject node was not input as part of the traversal, 
                      // so we will not be traversing the SgProject IR nodes and we 
                      // have to output the graph now!

                         if ( SgProject::get_verbose() >= 1 )
                              printf ("Output the DOT graph from the SgFile IR node (SgProject was not traversed) \n");

                         dotrep.writeToFileAsGraph(filename);
                       }
                      else
                       {
                         if ( SgProject::get_verbose() >= 1 )
                              printf ("Skip the output of the DOT graph from the SgFile IR node (SgProject will be traversed) \n");
                       }
                  }
               
            // cout << "done." << endl;
               break;
             }

       // DQ (7/23/2005): Implemented default case to avoid g++ warnings 
       // about enum values not handled by this switch
          default: 
             {
            // nothing to do here
               break;
             }
        }

     d.node = node;
     return d;
   }
Beispiel #28
0
ATerm convertNodeToAterm(SgNode* n) 
   {
     if (n == NULL)
        {
#if 0
          printf ("convertNodeToAterm(): n = %p = %s \n",n,"NULL");
#endif
          return ATmake("NULL");
        }

     ROSE_ASSERT(n != NULL);
#if 0
     printf ("convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif

     ATerm term;
     switch (n->variantT())
        {
       // case V_SgFile:
          case V_SgSourceFile:
            // Special case needed to include file name
            // term = ATmake("File(<str>, <term>)", isSgFile(n)->getFileName(), convertNodeToAterm(isSgFile(n)->get_root()));
               term = ATmake("File(<str>, <term>)", isSgSourceFile(n)->getFileName().c_str(), convertNodeToAterm(isSgSourceFile(n)->get_globalScope()));
               break;

          case V_SgPlusPlusOp:
          case V_SgMinusMinusOp:
            // Special cases needed to include prefix/postfix status
               term = ATmake("<appl(<appl>, <term>)>",
                  getShortVariantName((VariantT)(n->variantT())).c_str(),
                  (isSgUnaryOp(n)->get_mode() == SgUnaryOp::prefix ? "Prefix" :
                   isSgUnaryOp(n)->get_mode() == SgUnaryOp::postfix ? "Postfix" :
                   "Unknown"),
                   convertNodeToAterm(isSgUnaryOp(n)->get_operand()));
               break;

          case V_SgExpressionRoot:
            // Special case to remove this node
               term = convertNodeToAterm(isSgExpressionRoot(n)->get_operand());
               break;

    case V_SgCastExp:
    // Special case needed to include type
    term = ATmake("Cast(<term>, <term>)>",
	    convertNodeToAterm(isSgUnaryOp(n)->get_operand()),
	    convertNodeToAterm(isSgCastExp(n)->get_type()));
    break;

    case V_SgVarRefExp:
    // Special case needed to include id
    term = ATmake("Var(<str>)", 
		  uniqueId(isSgVarRefExp(n)->get_symbol()->get_declaration()).c_str());
    break;

    case V_SgFunctionRefExp:
    // Special case needed to include id
    term = ATmake(
                  "Func(<str>)", 
                  uniqueId(isSgFunctionRefExp(n)->get_symbol()->get_declaration()).c_str());
    break;

    case V_SgIntVal:
    // Special case needed to include value
    term = ATmake("IntC(<int>)", isSgIntVal(n)->get_value());
    break;

    case V_SgUnsignedIntVal:
    term = ATmake("UnsignedIntC(<int>)", isSgUnsignedIntVal(n)->get_value());
    break;

    case V_SgUnsignedLongVal: {
      ostringstream s;
      s << isSgUnsignedLongVal(n)->get_value();
      term = ATmake("UnsignedLongC(<str>)", s.str().c_str());
    }
    break;

    case V_SgUnsignedLongLongIntVal: {
      ostringstream s;
      s << isSgUnsignedLongLongIntVal(n)->get_value();
      term = ATmake("UnsignedLongLongC(<str>)", s.str().c_str());
    }
    break;

    case V_SgDoubleVal:
    term = ATmake("DoubleC(<real>)", isSgDoubleVal(n)->get_value());
    break;

          case V_SgInitializedName:
             {
            // Works around double initname problem
               SgInitializer* initializer = isSgInitializedName(n)->get_initializer();
               const SgName& name = isSgInitializedName(n)->get_name();
               SgType* type = isSgInitializedName(n)->get_type();

               ROSE_ASSERT(type != NULL);
#if 0
               printf ("convertNodeToAterm(): case V_SgInitializedName: name = %s initializer = %p type = %p = %s \n",name.str(),initializer,type,type->class_name().c_str());
#endif
            // Works around fact that ... is not really an initname and shouldn't be a type either
               if (isSgTypeEllipse(type))
                  {
                    term = ATmake("Ellipses");
                  }
                 else
                  {
                    std::string uniqueIdString = uniqueId(n);
#if 0
                    printf ("uniqueIdString = %s \n",uniqueIdString.c_str());
                    printf ("Calling generate ATerm for SgInitializedName->get_name() name = %s \n",name.str());
                    ATerm name_aterm = ATmake("Name(<str>)",name.str());
                 // ATerm name_aterm = ATmake(name.str());
                    printf ("Calling convertNodeToAterm(type) \n");
                    ATerm type_aterm = convertNodeToAterm(type);
                    printf ("Calling convertNodeToAterm(initializer) \n");
#endif
                    ATerm initializer_aterm = convertNodeToAterm(initializer);
#if 0
                    printf ("Calling ATmake() \n");
#endif
#if 1
                    term = ATmake("InitName(<str>, <term>, <term>) {[id, <str>]}", 
                                    (name.str() ? name.str() : ""), 
                                    convertNodeToAterm(type), 
                                    convertNodeToAterm(initializer),
                                    uniqueId(n).c_str());
                                 // uniqueIdString.c_str());
#else
                    term = ATmake("InitName(<term>,<term>)",
                                  //(name.str() ? name.str() : ""), 
                                  // name_aterm,
                                    type_aterm, 
                                    initializer_aterm
                                 // uniqueId(n).c_str());
                                 // uniqueIdString.c_str());
                                    );
#endif
#if 0
                    printf ("Calling ATsetAnnotation() \n");
#endif
                    term = ATsetAnnotation(term, ATmake("id"), ATmake("<str>", uniqueId(n).c_str()));
#if 0
                    printf ("DONE: Calling ATsetAnnotation() \n");
#endif
                  }

               break;
             }

    case V_SgFunctionDeclaration: {
      // Special case needed to include name
      SgFunctionDeclaration* fd = isSgFunctionDeclaration(n);
      term = ATmake("Function(<str>, <term>, <term>, <term>)", 
		    fd->get_name().str(), 
		    convertNodeToAterm(fd->get_orig_return_type()),
		    convertSgNodeRangeToAterm(fd->get_args().begin(),
					      fd->get_args().end()),
		    convertNodeToAterm(fd->get_definition()));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgClassDeclaration: {
      // Special case needed to distinguish forward/full definitions and to
      // include class name
      SgClassDeclaration* decl = isSgClassDeclaration(n);
      assert (decl);
      SgName sname = decl->get_name();
      const char* name = sname.str();
      // Suggestion: have a field named local_definition in each class
      // declaration that is 0 whenever the current declaration doesn't
      // have a definition attached, even if there is another declaration
      // which does have a definition attached.
      SgClassDefinition* defn = decl->get_definition();
      // cout << "defn = 0x" << hex << defn << endl << dec;
      if (decl->isForward())
	defn = 0;
      if (defn)
	term = ATmake("Class(<str>, <term>)", 
		      (name ? name : ""), // Will be simpler when SgName
		      // becomes string
		      convertNodeToAterm(defn));
      else
	term = ATmake("ClassFwd(<str>)", (name ? name : ""));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgEnumDeclaration: {
      // Special case to include enum name and enumerator names which are not
      // traversal children
      SgName sname = isSgEnumDeclaration(n)->get_name();
      const char* name = sname.str();
      const SgInitializedNamePtrList& enumerators = 
	isSgEnumDeclaration(n)->get_enumerators();
      term = ATmake("Enum(<str>, <term>)",
		    (name ? name : "{anonymous}"), 
		    convertSgNodeRangeToAterm(enumerators.begin(),
					      enumerators.end()));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgPointerType: {
      // Special case because types can't be traversed yet
      SgType* type = isSgPointerType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Pointer(<term>)", t);
    }
    break;

    case V_SgReferenceType: {
      // Special case because types can't be traversed yet
      SgType* type = isSgReferenceType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Reference(<term>)", t);
    }
    break;

    case V_SgModifierType: {
      // Special case for type traversal and to prettify modifier names
      SgType* type = isSgModifierType(n)->get_base_type();
      SgTypeModifier& modifier = isSgModifierType(n)->get_typeModifier();
      SgConstVolatileModifier& cvmod = modifier.get_constVolatileModifier();
      term = convertNodeToAterm(type);
      if (cvmod.isConst())
	term = ATmake("Const(<term>)", term);
      if (cvmod.isVolatile())
	term = ATmake("Volatile(<term>)", term);
    }
    break;

    case V_SgArrayType: {
      // Special case because types can't be traversed yet, and to get length
      SgType* type = isSgArrayType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Array(<term>, <term>)", t, (isSgArrayType(n)->get_index() ? convertNodeToAterm((n->get_traversalSuccessorContainer())[4]) : ATmake("<str>", "NULL")));
      assert (term);
    }
    break;

    case V_SgFunctionType: {
      // Special case to allow argument list to be traversed
      SgFunctionType* ft = isSgFunctionType(n);
      ATerm ret = convertNodeToAterm(ft->get_return_type());
      ATerm args_list = convertSgNodeRangeToAterm(ft->get_arguments().begin(),
						  ft->get_arguments().end());
      term = ATmake("FunctionType(<term>, <term>)", ret, args_list);
    }
    break;

    case V_SgEnumType:
    case V_SgClassType: 
    case V_SgTypedefType: {
      // Special cases to optionally put in type definition instead of
      // reference
      SgNamedType* nt = isSgNamedType(n);
      assert (nt);
      SgName sname = nt->get_name();
   // char* name = sname.str();
      SgDeclarationStatement* decl = nt->get_declaration();
      assert (decl);
      SgClassDefinition* defn = isSgClassDeclaration(decl) ?
				isSgClassDeclaration(decl)->get_definition() :
				0;
      term = ATmake("Type(<term>)",
		    (nt->get_autonomous_declaration() || !defn ? 
                     ATmake("id(<str>)", uniqueId(decl).c_str()) :
		     convertNodeToAterm(nt->get_declaration())));
    }
    break;

    case V_SgLabelStatement: {
      // Special case to put in label id
      const char* name = isSgLabelStatement(n)->get_name().str();
      term = ATmake("Label(<str>)", (name ? name : ""));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgGotoStatement: {
      // Special case to put in label id
      term = ATmake("Goto(<str>)", 
                    uniqueId(isSgGotoStatement(n)->get_label()).c_str());
    }
    break;

    case V_SgTypedefDeclaration: {
      // Special case to put in typedef name
      const SgName& name = isSgTypedefDeclaration(n)->get_name();
      SgType* type = isSgTypedefDeclaration(n)->get_base_type();
      term = ATmake("Typedef(<str>, <term>)", (name.str() ? name.str() : ""), 
		      convertNodeToAterm(type));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgTemplateDeclaration: {
      // Traversal doesn't work for these
      SgTemplateDeclaration* td = isSgTemplateDeclaration(n);
      ROSE_ASSERT (td);
   // SgTemplateParameterPtrListPtr paramsPtr = td->get_templateParameters();
   // SgTemplateParameterPtrList & paramsPtr = td->get_templateParameters();
   // SgTemplateParameterPtrList params =	paramsPtr ? *paramsPtr : SgTemplateParameterPtrList();
      SgTemplateParameterPtrList & params =	td->get_templateParameters();
      string templateKindString;
      switch (td->get_template_kind()) {
	case SgTemplateDeclaration::e_template_none:
	  templateKindString = "None"; break;
	case SgTemplateDeclaration::e_template_class:
	  templateKindString = "Class"; break;
	case SgTemplateDeclaration::e_template_m_class:
	  templateKindString = "MemberClass"; break;
	case SgTemplateDeclaration::e_template_function:
	  templateKindString = "Function"; break;
	case SgTemplateDeclaration::e_template_m_function:
	  templateKindString = "MemberFunction"; break;
	case SgTemplateDeclaration::e_template_m_data:
	  templateKindString = "MemberData"; break;
	default: templateKindString = "Unknown"; break;
      }
      term = ATmake("TemplateDeclaration(<appl>, <str>, <term>, <str>)",
		    templateKindString.c_str(),
		    td->get_name().str(),
		    convertSgNodeRangeToAterm(params.begin(), params.end()),
		    td->get_string().str());
    }
    break;

    case V_SgTemplateInstantiationDecl: {
      // Traversal doesn't work for these
      SgTemplateInstantiationDecl* td = isSgTemplateInstantiationDecl(n);
      ROSE_ASSERT (td);
   // SgTemplateArgumentPtrListPtr argsPtr = td->get_templateArguments();
   // SgTemplateArgumentPtrList args = argsPtr ? *argsPtr : SgTemplateArgumentPtrList();
      SgTemplateArgumentPtrList & args = td->get_templateArguments();
      term = ATmake("TemplateInstantiationDecl(<str>, <term>)", td->get_templateDeclaration()->get_name().str(), convertSgNodeRangeToAterm(args.begin(), args.end()));
    }
    break;

    case V_SgTemplateParameter: {
      // Traversal doesn't work for these
      SgTemplateParameter* tp = isSgTemplateParameter(n);
      ROSE_ASSERT (tp);
      switch (tp->get_parameterType()) {
	case SgTemplateParameter::parameter_undefined: {
	  term = ATmake("Undefined");
	}
	break;

	case SgTemplateParameter::type_parameter: {
	  term = ATmake("Type(<term>)",
			convertNodeToAterm(tp->get_defaultTypeParameter()));
	}
	break;

	case SgTemplateParameter::nontype_parameter: {
	  term = ATmake("Nontype(<term>, <term>)",
			convertNodeToAterm(tp->get_type()),
			convertNodeToAterm(tp->get_defaultExpressionParameter()));
	}
	break;

	case SgTemplateParameter::template_parameter: {
	  term = ATmake("Template");
	}
	break;

	default: term = ATmake("Unknown"); break;
      }
    }
    break;

    case V_SgTemplateArgument: {
      // Traversal doesn't work for these
      SgTemplateArgument* ta = isSgTemplateArgument(n);
      ROSE_ASSERT (ta);
      switch (ta->get_argumentType()) {
	case SgTemplateArgument::argument_undefined:
	  term = ATmake("Undefined");
	  break;
	case SgTemplateArgument::type_argument:
	  term = ATmake("Type(<term>)", 
			convertNodeToAterm(ta->get_type()));
	  break;
	case SgTemplateArgument::nontype_argument:
	  term = ATmake("Nontype(<term>)", 
			convertNodeToAterm(ta->get_expression()));
	  break;
	// case SgTemplateArgument::template_argument:
	  // term = ATmake("Template");
	  // break;
	default: term = ATmake("Unknown"); break;
      }
    }
    break;

    default: {
      bool isContainer = 
	(AstTests::numSuccContainers(n) == 1) ||
	(!isSgType(n) && (n->get_traversalSuccessorContainer().size() == 0));
      term = ATmake((isContainer ? "<appl(<term>)>" : "<appl(<list>)>"), 
                    getShortVariantName((VariantT)(n->variantT())).c_str(),
                    (isSgType(n) ? ATmake("[]") : getTraversalChildrenAsAterm(n)));
               // Special case for types is because of traversal problems
    }
    break;
  }

#if 0
     printf ("Base of switch statement in convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif
     assert (term);

     term = ATsetAnnotation(term, ATmake("ptr"), pointerAsAterm(n));

#if 1
     if (n->get_file_info() != NULL)
        {
          term = ATsetAnnotation(term, ATmake("location"),convertFileInfoToAterm(n->get_file_info()));
        }

     if (isSgExpression(n))
        term = ATsetAnnotation(term, ATmake("type"), convertNodeToAterm(isSgExpression(n)->get_type()));
#endif

#if 0
     printf ("Leaving convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif
#if 0
     printf ("--- n->class_name() = %s ATwriteToString(term) = %s \n",n->class_name().c_str(),ATwriteToString(term));
#endif

  // cout << n->sage_class_name() << " -> " << ATwriteToString(term) << endl;
     return term;
   }
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
FixupAstSymbolTablesToSupportAliasedSymbols::visit ( SgNode* node )
   {
  // DQ (11/24/2007): Output the current IR node for debugging the traversal of the Fortran AST.
#if ALIAS_SYMBOL_DEBUGGING
     printf ("In FixupAstSymbolTablesToSupportAliasedSymbols::visit() (preorder AST traversal) node = %p = %s \n",node,node->class_name().c_str());
#endif

#if 0
  // DQ (7/23/2011): New support for linking namespaces sharing the same name (mangled name).
  // std::map<SgName,std::vector<SgNamespaceDefinition*> > namespaceMap;
     SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(node);
     if (namespaceDefinition != NULL)
        {
       // DQ (7/23/2011): Assemble namespaces with the same name into vectors defined in the map 
       // accessed using the name of the namespace as a key.

#error "DEAD CODE"

          SgName name = namespaceDefinition->get_namespaceDeclaration()->get_name();
#if ALIAS_SYMBOL_DEBUGGING
          printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: namespace definition found for name = %s #symbols = %d \n",name.str(),namespaceDefinition->get_symbol_table()->size());
#endif
       // It is important to use mangled names to define unique names when namespaces are nested.
          SgName mangledNamespaceName = namespaceDefinition->get_namespaceDeclaration()->get_mangled_name();
#if ALIAS_SYMBOL_DEBUGGING
          printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: namespace definition associated mangled name = %s \n",mangledNamespaceName.str());
#endif
       // DQ (7/23/2011): Fixup the name we use as a key in the map to relect that some namespaces don't have a name.
          if (name == "")
             {
            // Modify the mangled name to reflect the unnamed namespace...

#if ALIAS_SYMBOL_DEBUGGING
               printf ("Warning in FixupAstSymbolTablesToSupportAliasedSymbols::visit(): Unnamed namespaces shuld be mangled to reflect the lack of a name \n");
#endif
               mangledNamespaceName += "_unnamed_namespace";
             }

#if ALIAS_SYMBOL_DEBUGGING
          printf ("namespace definition associated mangled name = %s \n",mangledNamespaceName.str());
#endif
#if ALIAS_SYMBOL_DEBUGGING
          printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: associated mangled name = %s namespaceMap size = %" PRIuPTR " \n",mangledNamespaceName.str(),namespaceMap.size());
#endif
          std::map<SgName,std::vector<SgNamespaceDefinitionStatement*> >::iterator i = namespaceMap.find(mangledNamespaceName);
          if (i != namespaceMap.end())
             {
               std::vector<SgNamespaceDefinitionStatement*> & namespaceVector = i->second;
#if ALIAS_SYMBOL_DEBUGGING
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: (found an entry): Namespace vector size = %" PRIuPTR " \n",namespaceVector.size());
#endif
            // Testing each entry...
               for (size_t j = 0; j < namespaceVector.size(); j++)
                  {
                    ROSE_ASSERT(namespaceVector[j] != NULL);
                    SgName existingNamespaceName = namespaceVector[j]->get_namespaceDeclaration()->get_name();
#if ALIAS_SYMBOL_DEBUGGING
                    printf ("Existing namespace (SgNamespaceDefinitionStatement) %p = %s \n",namespaceVector[j],existingNamespaceName.str());
#endif
                    if (j > 0)
                       {
                         ROSE_ASSERT(namespaceVector[j]->get_previousNamespaceDefinition() != NULL);
                       }

                    if (namespaceVector.size() > 1 && j < namespaceVector.size() - 2)
                       {
                         ROSE_ASSERT(namespaceVector[j]->get_nextNamespaceDefinition() != NULL);
                       }
                  }

#error "DEAD CODE"

               size_t namespaceListSize = namespaceVector.size();
               if (namespaceListSize > 0)
                  {
                    size_t lastNamespaceIndex = namespaceListSize - 1;

                 // DQ (5/9/2013): Before setting these, I think they should be unset (to NULL values).
                 // ROSE_ASSERT(namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() == NULL);
                 // ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() == NULL);
                 // ROSE_ASSERT(namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() == NULL);
                    ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() != NULL);

                 // namespaceVector[lastNamespaceIndex]->set_nextNamespaceDefinition(namespaceDefinition);
#if 1
                    printf ("namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() = %p \n",namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition());
#endif
                    if (namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() == NULL)
                       {
                         namespaceVector[lastNamespaceIndex]->set_nextNamespaceDefinition(namespaceDefinition);
                       }
                      else
                       {
                      // DQ (5/9/2013): If this is already set then make sure it was set to the correct value.
                         ROSE_ASSERT(namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() == namespaceDefinition);
                       }

#error "DEAD CODE"

                 // DQ (5/9/2013): If this is already set then make sure it was set to the correct value.
                 // namespaceDefinition->set_previousNamespaceDefinition(namespaceVector[lastNamespaceIndex]);
                    ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() != NULL);
                    ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() == namespaceVector[lastNamespaceIndex]);

                 // DQ (5/9/2013): I think I can assert this.
                    ROSE_ASSERT(namespaceVector[lastNamespaceIndex]->get_namespaceDeclaration()->get_name() == namespaceDefinition->get_namespaceDeclaration()->get_name());
                    ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() != NULL);
#if 1
                    printf ("namespaceDefinition = %p namespaceDefinition->get_nextNamespaceDefinition() = %p \n",namespaceDefinition,namespaceDefinition->get_nextNamespaceDefinition());
#endif
                 // ROSE_ASSERT(namespaceDefinition->get_nextNamespaceDefinition()     == NULL);
                 // ROSE_ASSERT(namespaceVector[lastNamespaceIndex]->get_nextNamespaceDefinition() == NULL);
                  }

            // Add the namespace matching a previous name to the list.
               namespaceVector.push_back(namespaceDefinition);

#error "DEAD CODE"

            // Setup scopes as sources and distinations of alias symbols.
               SgNamespaceDefinitionStatement* referencedScope = namespaceDefinition->get_previousNamespaceDefinition();
               ROSE_ASSERT(referencedScope != NULL);
               SgNamespaceDefinitionStatement* currentScope = namespaceDefinition;
               ROSE_ASSERT(currentScope != NULL);

#if ALIAS_SYMBOL_DEBUGGING
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: Suppress injection of symbols from one namespace to the other for each reintrant namespace \n");
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: referencedScope #symbols = %d currentScope #symbols = %d \n",referencedScope->get_symbol_table()->size(),currentScope->get_symbol_table()->size());
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: referencedScope = %p currentScope = %p \n",referencedScope,currentScope);
#endif
#if 1
            // Generate the alias symbols from the referencedScope and inject into the currentScope.
               injectSymbolsFromReferencedScopeIntoCurrentScope(referencedScope,currentScope,SgAccessModifier::e_default);
#endif
             }
            else
             {
#if ALIAS_SYMBOL_DEBUGGING
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols: (entry NOT found): Insert namespace %p for name = %s into the namespaceMap \n",namespaceDefinition,mangledNamespaceName.str());
#endif
               std::vector<SgNamespaceDefinitionStatement*> list(1);
               ROSE_ASSERT(list.size() == 1);

#error "DEAD CODE"

               list[0] = namespaceDefinition;
#if 0
            // DQ (3/11/2012): New code, but maybe we should instead put the implicit "std" namespace into the global scope more directly.
               if (mangledNamespaceName == "std" && false)
                  {
                 // This case has to be handled special since the implicit "std" namespace primary declaration was 
                 // constructed but not added to the global scope.  But maybe it should be.
                  }
                 else
                  {
                 // DQ (7/24/2011): get_nextNamespaceDefinition() == NULL is false in the case of the AST copy tests 
                 // (see tests/nonsmoke/functional/CompileTests/copyAST_tests/copytest2007_30.C). Only  get_nextNamespaceDefinition() 
                 // appears to sometimes be non-null, so we reset them both to NULL just to make sure.
                    namespaceDefinition->set_nextNamespaceDefinition(NULL);
                    namespaceDefinition->set_previousNamespaceDefinition(NULL);

                    ROSE_ASSERT(namespaceDefinition->get_nextNamespaceDefinition()     == NULL);
                    ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() == NULL);
                  }
#else
            // DQ (7/24/2011): get_nextNamespaceDefinition() == NULL is false in the case of the AST copy tests 
            // (see tests/nonsmoke/functional/CompileTests/copyAST_tests/copytest2007_30.C). Only  get_nextNamespaceDefinition() 
            // appears to sometimes be non-null, so we reset them both to NULL just to make sure.
               namespaceDefinition->set_nextNamespaceDefinition(NULL);
               namespaceDefinition->set_previousNamespaceDefinition(NULL);

               ROSE_ASSERT(namespaceDefinition->get_nextNamespaceDefinition()     == NULL);
               ROSE_ASSERT(namespaceDefinition->get_previousNamespaceDefinition() == NULL);
#endif
               namespaceMap.insert(std::pair<SgName,std::vector<SgNamespaceDefinitionStatement*> >(mangledNamespaceName,list));

#error "DEAD CODE"

#if ALIAS_SYMBOL_DEBUGGING
               printf ("namespaceMap.size() = %" PRIuPTR " \n",namespaceMap.size());
#endif
             }
        }

#error "DEAD CODE"

#else
  // DQ (5/23/2013): Commented out since we now have a newer and better namespace support for symbol handling.
  // printf ("NOTE:: COMMENTED OUT old support for namespace declarations in FixupAstSymbolTablesToSupportAliasedSymbols traversal \n");
#endif

     SgUseStatement* useDeclaration = isSgUseStatement(node);
     if (useDeclaration != NULL)
        {
       // This must be done in the Fortran AST construction since aliased symbols must be inserted
       // before they are looked up as part of name resolution of variable, functions, and types.
       // For C++ we can be more flexible and support the construction of symbol aliases within 
       // post-processing.
        }

  // DQ (4/14/2010): Added this C++ specific support.
  // In the future we may want to support the injection of alias symbols for C++ "using" directives and "using" declarations.
     SgUsingDeclarationStatement* usingDeclarationStatement = isSgUsingDeclarationStatement(node);
     if (usingDeclarationStatement != NULL)
        {
#if ALIAS_SYMBOL_DEBUGGING
          printf ("Found the SgUsingDeclarationStatement \n");
#endif
          SgScopeStatement* currentScope = usingDeclarationStatement->get_scope();
          ROSE_ASSERT(currentScope != NULL);

          SgDeclarationStatement* declaration     = usingDeclarationStatement->get_declaration();
          SgInitializedName*      initializedName = usingDeclarationStatement->get_initializedName();

       // Only one of these can be non-null.
          ROSE_ASSERT(initializedName != NULL || declaration != NULL);
          ROSE_ASSERT( (initializedName != NULL && declaration != NULL) == false);

          if (declaration != NULL)
             {
#if ALIAS_SYMBOL_DEBUGGING
               printf ("In FixupAstSymbolTablesToSupportAliasedSymbols::visit(): declaration = %p = %s \n",declaration,declaration->class_name().c_str());
#endif
             }
            else
             {
               if (initializedName != NULL)
                  {
#if ALIAS_SYMBOL_DEBUGGING
                    printf ("In FixupAstSymbolTablesToSupportAliasedSymbols::visit(): initializedName = %s \n",initializedName->get_name().str());
#endif
                  }
                 else
                  {
                    printf ("Error: both declaration and initializedName in SgUsingDeclarationStatement are NULL \n");
                    ROSE_ASSERT(false);
                  }
             }

#if 0
          printf ("Exiting at the base of FixupAstSymbolTablesToSupportAliasedSymbols::visit() \n");
          ROSE_ASSERT(false);
#endif
        }

     SgUsingDirectiveStatement* usingDirectiveStatement = isSgUsingDirectiveStatement(node);
     if (usingDirectiveStatement != NULL)
        {
#if ALIAS_SYMBOL_DEBUGGING
          printf ("Found the SgUsingDirectiveStatement \n");
#endif
          SgNamespaceDeclarationStatement* namespaceDeclaration = usingDirectiveStatement->get_namespaceDeclaration();
          ROSE_ASSERT(namespaceDeclaration != NULL);

          SgScopeStatement* currentScope    = usingDirectiveStatement->get_scope();

       // To be more specific this is really a SgNamespaceDefinitionStatement
          SgScopeStatement* referencedScope = namespaceDeclaration->get_definition();

          if (referencedScope == NULL)
             {
            // DQ (5/21/2010): Handle case of using "std" (predefined namespace in C++), but it not having been explicitly defined (see test2005_57.C).
               if (namespaceDeclaration->get_name() != "std")
                  {
                    printf ("ERROR: namespaceDeclaration has no valid definition \n");
                    namespaceDeclaration->get_startOfConstruct()->display("ERROR: namespaceDeclaration has no valid definition");

                 // DQ (5/20/2010): Added assertion to trap this case.
                    printf ("Exiting because referencedScope could not be identified.\n");
                    ROSE_ASSERT(false);
                  }
             }

       // Note that "std", as a predefined namespace, can have a null definition, so we can't 
       // insist that we inject all symbols in namespaces that we can't see explicitly.
          if (referencedScope != NULL)
             {
               ROSE_ASSERT(referencedScope != NULL);
               ROSE_ASSERT(currentScope != NULL);
#if 0
               printf ("Calling injectSymbolsFromReferencedScopeIntoCurrentScope() for usingDirectiveStatement = %p = %s \n",node,node->class_name().c_str());
#endif
               injectSymbolsFromReferencedScopeIntoCurrentScope(referencedScope,currentScope,usingDirectiveStatement,SgAccessModifier::e_default);
             }

#if 0
          printf ("Exiting at the base of FixupAstSymbolTablesToSupportAliasedSymbols::visit() \n");
          ROSE_ASSERT(false);
#endif
        }

  // DQ (5/6/2011): Added support to build SgAliasSymbols in derived class scopes that reference the symbols of the base classes associated with protected and public declarations.
     SgClassDefinition* classDefinition = isSgClassDefinition(node);
     if (classDefinition != NULL)
        {
       // Handle any derived classes.
          SgBaseClassPtrList & baseClassList = classDefinition->get_inheritances();
          SgBaseClassPtrList::iterator i = baseClassList.begin();
          for ( ; i != baseClassList.end(); ++i)
             {
            // Check each base class.
               SgBaseClass* baseClass = *i;
               ROSE_ASSERT(baseClass != NULL);

               /* skip processing for SgExpBaseClasses (which don't have to define p_base_class) */
               if (baseClass->variantT() == V_SgExpBaseClass) {
                   continue;
               }

            // printf ("baseClass->get_baseClassModifier().displayString()                      = %s \n",baseClass->get_baseClassModifier().displayString().c_str());
            // printf ("baseClass->get_baseClassModifier().get_accessModifier().displayString() = %s \n",baseClass->get_baseClassModifier().get_accessModifier().displayString().c_str());

            // if (baseClass->get_modifier() == SgBaseClass::e_virtual)
               if (baseClass->get_baseClassModifier().get_modifier() == SgBaseClassModifier::e_virtual)
                  {
                 // Not clear if virtual as a modifier effects the handling of alias symbols.
                 // printf ("Not clear if virtual as a modifier effects the handling of alias symbols. \n");
                  }

            // DQ (6/22/2011): Define the access level for alias symbol's declarations to be included.
               SgAccessModifier::access_modifier_enum accessLevel = baseClass->get_baseClassModifier().get_accessModifier().get_modifier();

               SgClassDeclaration* tmpClassDeclaration    = baseClass->get_base_class();
               ROSE_ASSERT(tmpClassDeclaration != NULL);
#if 0
            // ROSE_ASSERT(tmpClassDeclaration->get_definingDeclaration() != NULL);
               SgClassDeclaration* targetClassDeclaration = isSgClassDeclaration(tmpClassDeclaration->get_definingDeclaration());
               ROSE_ASSERT(targetClassDeclaration != NULL);
               SgScopeStatement*   referencedScope  = targetClassDeclaration->get_definition();
            // We need this function to restrict it's injection of symbol to just those that are associated with public and protected declarations.
               injectSymbolsFromReferencedScopeIntoCurrentScope(referencedScope,classDefinition,accessLevel);
#else
            // DQ (2/25/2012) We only want to inject the symbol where we have identified the defining scope.
               if (tmpClassDeclaration->get_definingDeclaration() != NULL)
                  {
                    SgClassDeclaration* targetClassDeclaration = isSgClassDeclaration(tmpClassDeclaration->get_definingDeclaration());
                    ROSE_ASSERT(targetClassDeclaration != NULL);
                    SgScopeStatement*   referencedScope  = targetClassDeclaration->get_definition();
#if 0
                    printf ("Calling injectSymbolsFromReferencedScopeIntoCurrentScope() for classDefinition = %p = %s baseClass = %p accessLevel = %d \n",
                         node,node->class_name().c_str(),baseClass,accessLevel);
#endif
                 // DQ (7/12/2014): Use the SgBaseClass as the causal node that has triggered the insertion of the SgAliasSymbols.
                 // We need this function to restrict it's injection of symbol to just those that are associated with public and protected declarations.
                    injectSymbolsFromReferencedScopeIntoCurrentScope(referencedScope,classDefinition,baseClass,accessLevel);
                  }
                 else
                  {
                 // DQ (2/25/2012): Print a warning message when this happens (so far only test2012_08.C).
                    if (SgProject::get_verbose() > 0)
                       {
                         mprintf ("WARNING: In FixupAstSymbolTablesToSupportAliasedSymbols::visit(): Not really clear how to handle this case where tmpClassDeclaration->get_definingDeclaration() == NULL! \n");
                       }
                  }
#endif
             }
        }


     SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(node);
     if (functionDeclaration != NULL)
        {
#if ALIAS_SYMBOL_DEBUGGING
          printf ("Found a the SgFunctionDeclaration \n");
#endif
       // SgScopeStatement*  functionScope   = functionDeclaration->get_scope();
          SgScopeStatement*  currentScope    = isSgScopeStatement(functionDeclaration->get_parent());
          SgClassDefinition* classDefinition = isSgClassDefinition(currentScope);

          if (classDefinition != NULL)
             {
            // This is a function declared in a class definition, test of friend (forget why it is important to test for isOperator().
               if (functionDeclaration->get_declarationModifier().isFriend() == true || functionDeclaration->get_specialFunctionModifier().isOperator() == true)
                  {
                 // printf ("Process all friend function with a SgAliasSymbol to where they are declared in another scope (usually global scope) \n");
#if 0
                    SgName name = functionDeclaration->get_name();

                    SgSymbol* symbol = functionDeclaration->search_for_symbol_from_symbol_table();
                    ROSE_ASSERT ( symbol != NULL );

                    SgAliasSymbol* aliasSymbol = new SgAliasSymbol (symbol);

                 // Use the current name and the alias to the symbol
                    currentScope->insert_symbol(name,aliasSymbol);
#endif
#if 0
                    printf ("Error: friend functions not processed yet! \n");
                    ROSE_ASSERT(false);
#endif
                  }
             }
        }

#if ALIAS_SYMBOL_DEBUGGING
     printf ("Leaving FixupAstSymbolTablesToSupportAliasedSymbols::visit() (preorder AST traversal) node = %p = %s \n",node,node->class_name().c_str());
#endif
   }