예제 #1
0
파일: RIFG.cpp 프로젝트: Vladimir84/rcc
RIFG::NodeId 
RIFG::getEdgeSink(RIFG::EdgeId eid) const
{
  OA::OA_ptr<OA::DGraph::EdgeInterface> e = getEdge(eid);
  OA::OA_ptr<OA::DGraph::NodeInterface> n = e->getSink();
  return (getNodeId(n));
}
예제 #2
0
int main ( unsigned argc,  char * argv[] )
{
    string sInputFile, sOutputFile;
    ofstream outputFile;

    // for debugging only switch between persistentand "pointer" handles
    // (pointers are faster, persistent are easier to debug
    bool p_h=FALSE; 
    //    p_h = TRUE;

    // read in command line arguments
    // usage: CtoOA inputFile
    if(argc < 2) { usage(argv[0]); return 1; }
    sInputFile  = argv[1];
    //sOutputFile = argv[2];

    // load the Sage project, open the output file, and construct the
    // code generator (which outputs .oa notation to the file)
    SgProject * sageProject = frontend((int)argc, &argv[0]);
    //outputFile.open(sOutputFile.c_str());

    // debug output
    //AstPDFGeneration pdftest;
    //pdftest.generateInputFiles(sageProject);
    //AstDOTGeneration dottest;
    //dottest.generateInputFiles(sageProject);
    
    // Loop over every file.   BW 4/13/06
    int filenum = sageProject->numberOfFiles();
    for (int i = 0; i < filenum; ++i) 
    {

        SgFile &sageFile = sageProject->get_file(i);
        SgGlobal *root = sageFile.get_root();

        // Loop through every function in the file of this project.
        std::vector<SgNode*> nodeArray;
        OA::OA_ptr<SageIRInterface> irInterface; 
        irInterface = new SageIRInterface(sageProject, &nodeArray, p_h);
        OA::OA_ptr<SageIRProcIterator> procIter;
	// Do not process include files, e.g., iostream.h.
	bool excludeInputFiles = true;
        procIter = new SageIRProcIterator(sageProject, irInterface, excludeInputFiles);

        for (; procIter->isValid(); ++(*procIter) ) 
	{
            // output notation for this function
	    outputNotation(procIter->current(), irInterface, std::cout);
	}
    }     

    return 0;
}
예제 #3
0
//! Propagate a data-flow set from caller to callee
OA_ptr<DataFlow::DataFlowSet> 
ManagerICFGDep::callerToCallee(ProcHandle caller,
   OA_ptr<DataFlow::DataFlowSet> dfset, CallHandle call, ProcHandle callee)
{

    
    // new DepDFSet for this stmt
    OA_ptr<DepDFSet> stmtDepDFSet;
    stmtDepDFSet = new DepDFSet;


    //! ===========================================
    //! Iterate over assignment pairs of statement
    //! ===========================================

    OA::OA_ptr<OA::AssignPairIterator> aPairIter;
    aPairIter = mIR->getAssignPairIterator(call);

    for( ; aPairIter->isValid(); ++(*aPairIter)) {

        //! ======== Get the LHS (Defs) of Assignment ========
        OA::MemRefHandle memref = aPairIter->currentTarget();

        //! ======== Get the RHS (Uses) of Assignment ========
        OA::ExprHandle expr = aPairIter->currentSource();


        //! ========
        //! Get Defs
        //! ========
        OA_ptr<Alias::AliasTagSet> aSet = mAlias->getAliasTags(memref);
        OA::OA_ptr<OA::Alias::AliasTagIterator> deftagSetIter;
        deftagSetIter = aSet->getIterator();



        //! ================ Def tagIter =============
        for( deftagSetIter->reset() ; deftagSetIter->isValid();
             ++(*deftagSetIter) ) {


                 //! ============
                 //! Get Uses
                 //! ============

                 //! ======== Get ExprTree for RHS =========
                 OA_ptr<ExprTree> eTree = mIR->getExprTree(expr);

                 CollectMREVisitor evalVisitor;
                 eTree->acceptVisitor(evalVisitor);

                 //! ======= Collect all MREs from ExprTree =========
                 OA::set<OA_ptr<MemRefExpr> > mSet;
                 mSet = evalVisitor.getMemRef();

                 OA::OA_ptr<std::set<OA_ptr<MemRefExpr> > > mSetPtr;
                 mSetPtr = new std::set<OA_ptr<MemRefExpr> >(mSet);

                 OA_ptr<MemRefExprIterator> mreIter;
                 mreIter = new OA::MemRefExprIterator(mSetPtr);



                 //! ============ Use MREIter ==============
                 for( ; mreIter->isValid(); ++(*mreIter) ) {

                     OA::OA_ptr<OA::MemRefExpr> mre;
                     mre = mreIter->current();

                     //! === ignore AddressOf because it is not a Use ===
                     if(mre->isaAddressOf()) {
                        continue;
                     }

                     OA::OA_ptr<OA::Alias::AliasTagSet> mretagSet;
                     OA::OA_ptr<OA::Alias::AliasTagIterator> mretagSetIter;
                     mretagSet = mAlias->getAliasTags(mreIter->current());
                     mretagSetIter = mretagSet->getIterator();

                     //! =============== Use tagIter ==============
                     for( ; mretagSetIter->isValid(); ++(*mretagSetIter)) {

                         //! =============================================
                         //! Create ICFGDep Pair
                         //! =============================================

                         stmtDepDFSet->insertDep(mretagSetIter->current(),
                                                 deftagSetIter->current());



                     } // end mreTagSetIter

                 } // end mreIter

        } // end deftagIter


    } // end aPairIter


    //! =========================================
    //! map stmtDepDFSet to stmt in depResults
    //! =========================================
    mDep->mapCallToDeps(call, stmtDepDFSet);


    return dfset;

}
예제 #4
0
OA_ptr<DataFlow::DataFlowSet>
ManagerICFGDep::transfer(ProcHandle proc,
                         OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
{


    // new DepDFSet for this stmt
    OA_ptr<DepDFSet> stmtDepDFSet;
    stmtDepDFSet = new DepDFSet;


    //! ===========================================
    //! Iterate over assignment pairs of statement
    //! ===========================================

    OA::OA_ptr<OA::AssignPairIterator> aPairIter;
    aPairIter = mIR->getAssignPairIterator(stmt);

    for( ; aPairIter->isValid(); ++(*aPairIter)) {

        //! ======== Get the LHS (Defs) of Assignment ========
        OA::MemRefHandle memref = aPairIter->currentTarget();

        //! ======== Get the RHS (Uses) of Assignment ========
        OA::ExprHandle expr = aPairIter->currentSource();


        //! ========
        //! Get Defs
        //! ========
        OA_ptr<Alias::AliasTagSet> aSet = mAlias->getAliasTags(memref);
        OA::OA_ptr<OA::Alias::AliasTagIterator> deftagSetIter;
        deftagSetIter = aSet->getIterator();



        //! ================ Def tagIter =============
        for( deftagSetIter->reset() ; deftagSetIter->isValid();
             ++(*deftagSetIter) ) {

                 //! =====================================================
                 //! Store Must Defs
                 //!
                 //! Do it here, before going over Uses in RHS ExprHandle.
                 //! because we have pointer assignment statements p=>x
                 //! which is modelled as p=&x.  AddressOf is not a Use
                 //! and therefore we ignore &x for ICFGDep pairs but
                 //! def "p" is Must Def and we dont want to ignore it.
                 //! Thus, process MustDefs before accessing RHS.
                 //! =====================================================

                  if(aSet->isMust()) {
                     mDep->insertMustDefForStmt(stmt,deftagSetIter->current());
                     stmtDepDFSet->removeImplicitDep(deftagSetIter->current(),
                                                     deftagSetIter->current());
                  }

                 //! ============
                 //! Get Uses
                 //! ============

                 //! ======== Get ExprTree for RHS =========
                 OA_ptr<ExprTree> eTree = mIR->getExprTree(expr);

                 CollectMREVisitor evalVisitor;
                 eTree->acceptVisitor(evalVisitor);

                 //! ======= Collect all MREs from ExprTree =========
                 OA::set<OA_ptr<MemRefExpr> > mSet;
                 mSet = evalVisitor.getMemRef();

                 OA::OA_ptr<std::set<OA_ptr<MemRefExpr> > > mSetPtr;
                 mSetPtr = new std::set<OA_ptr<MemRefExpr> >(mSet);

                 OA_ptr<MemRefExprIterator> mreIter;
                 mreIter = new OA::MemRefExprIterator(mSetPtr);



                 //! ============ Use MREIter ==============
                 for( ; mreIter->isValid(); ++(*mreIter) ) {

                     OA::OA_ptr<OA::MemRefExpr> mre;
                     mre = mreIter->current();

                     //! === ignore AddressOf because it is not a Use ===
                     if(mre->isaAddressOf()) {
                        continue;
                     }


                     OA::OA_ptr<OA::Alias::AliasTagSet> mretagSet;
                     OA::OA_ptr<OA::Alias::AliasTagIterator> mretagSetIter;
                     mretagSet = mAlias->getAliasTags(mreIter->current());
                     mretagSetIter = mretagSet->getIterator();

                     //! =============== Use tagIter ==============
                     for( ; mretagSetIter->isValid(); ++(*mretagSetIter)) {

                         //! =============================================
                         //! Create ICFGDep Pair
                         //! =============================================

                         stmtDepDFSet->insertDep(mretagSetIter->current(),
                                                 deftagSetIter->current());

                     } // end mreTagSetIter

                 } // end mreIter

             } // end deftagIter

         } // end aPairIter


         //! =========================================
         //! map stmtDepDFSet to stmt in depResults
         //! =========================================
         mDep->mapStmtToDeps(stmt, stmtDepDFSet);


         return in;

}
예제 #5
0
//--------------------------------------------------------------------
void
ManagerCallGraphStandard::build_graph(OA_ptr<IRProcIterator> procIter)
{
  // Iterate over all the procedures in the program
  for ( procIter->reset(); procIter->isValid(); ++(*procIter)) { 
    
    // Create a node for this procedure
    ProcHandle currProc = procIter->current();
    SymHandle currProcSym = mIR->getSymHandle(currProc);
    if (debug) {
      std::cout << "currProc = " << mIR->toString(currProc);
      std::cout << ", currProcSym = " << mIR->toString(currProcSym) 
                << std::endl;
    }

    OA_ptr<Node> currProcNode 
      = mCallGraph->findOrAddNode(currProcSym);
    currProcNode->add_def(currProc); 

  if (debug) {
      std::cout << "After currProc = " << mIR->toString(currProc);
      std::cout << ", After currProcSym = " << mIR->toString(currProcSym)
                << std::endl;
    }

    
    // Iterate over the statements of this procedure
    OA_ptr<IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(currProc);
    // Iterate over the statements of this block adding procedure references
    for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
      StmtHandle stmt = stmtIterPtr->current();

      // Iterate over procedure calls of a statement
      OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
      
      if (debug) {
        if (callsiteItPtr->isValid()) {
          std::cout << "\n***\n  Call Statement:\n     <'";
          std::cout << mIR->toString(stmt) << "'>";
        }
      }
      for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
        CallHandle call = callsiteItPtr->current();

        if (debug) {
          std::cout << "\n        Call: ["
                    << mIR->toString(call) << "]";
        }
        // get the mre for the function call (eg. NamedRef('foo'))
        OA_ptr<MemRefExpr> callMRE = mIR->getCallMemRefExpr(call);

        // iterate over the may tags for this callMRE
        OA_ptr<Alias::AliasTagSet> aSet;
        aSet = mAlias->getAliasTags(callMRE);

        OA_ptr<Alias::AliasTagIterator> mayCallItPtr;
        mayCallItPtr = aSet->getIterator();

        for(; mayCallItPtr->isValid(); ++(*mayCallItPtr)) {
           AliasTag tag = mayCallItPtr->current();

           OA::OA_ptr<OA::MemRefExprIterator> mreIter;
           mreIter = mAlias->getMemRefExprIterator(tag);

           for(; mreIter->isValid(); ++(*mreIter)) {
               
                 OA_ptr<MemRefExpr> mre = mreIter->current();
                 
                 // right now we only handle named refs. Languages w/ anonymous
                 // functions will be UnnamedRefs. We'll need to fix this at
                 // some point in the future.
                 assert(mre->isaNamed());

                 SymHandle sym = mre.convert<OA::NamedRef>()->getSymHandle();
                 // Add a node (if nonexistent) and edge
                 OA_ptr<Node> node = mCallGraph->findOrAddNode(sym);
                 node->add_call(call);

                 if(debug)
                 {
                    std::cout << "ManagerCallGraphStandard currProcNode";
                    std::cout << currProcNode->getId();
                    std::cout << std::endl;
                 }

                 if(debug)
                 {
                    std::cout << "ManagerCallGraphStandard Node";
                    std::cout << node->getId();
                    std::cout << std::endl;
                }

                mCallGraph->connect(currProcNode, node, NORMAL_EDGE, call);
 
           }
           
        } // iterating over may locs for the callMRE

      } // iterating over calls of a statement

      if (debug) {
        callsiteItPtr->reset();
        if (callsiteItPtr->isValid()) {
          std::cout << "\n***\n";
        }
      }
    } // iterating over statements

  } // iterating over procedures

}