Exemple #1
0
void ProjectManager::storeProjectState()
{
    QSettings s;

    s.remove("LoadedProjects");


    s.beginGroup("LoadedProjects");

    s.beginWriteArray("Projects");

    for(int p=0; p<rootNode->childrenCount(); p++)
    {
        ProjectNode * projNode =  dynamic_cast<ProjectNode*>(rootNode->child(p));

        s.setArrayIndex(p);
        s.setValue("Name",projNode->getName());

        SgProject * sgProj =  projNode->getSgProject();

        s.beginWriteArray("files");
        for(int i=0; i < sgProj->numberOfFiles(); i++)
        {
            QString name = (*sgProj)[i]->getFileName().c_str();
            s.setArrayIndex(i);
            s.setValue("name",name);
        }
        s.endArray();
    }

    s.endArray(); //Projects


    s.endGroup();
}
Exemple #2
0
int main(int argc, char ** argv) {
  std::vector<std::string> args(argv, argv + argc);

#if defined(TILEK_ACCELERATOR)
#  if defined(TILEK_TARGET_OPENCL)
  args.push_back("-DSKIP_OPENCL_SPECIFIC_DEFINITION");
#  endif
#endif

  SgProject * project = new SgProject(args);
  assert(project->numberOfFiles() == 1);

  SgSourceFile * source_file = isSgSourceFile(project->get_fileList()[0]);
  assert(source_file != NULL);

  std::string filename = source_file->get_sourceFileNameWithoutPath();
  std::string basename = filename.substr(0, filename.find_last_of('.'));

  KLT::DLX::Compiler< ::DLX::TileK::language_t, ::KLT::TileK::Generator> compiler(project, KLT_PATH, TILEK_PATH, basename);

//  MFB::api_t * api = compiler.getDriver().getAPI();
//  dump_api(api);

  compiler.compile(project);

  project->unparse();

  return 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;
}
Exemple #4
0
int
main ( int argc,  char * argv[] )
   {

     if (argc <= 1) {
         PrintUsage(argv[0]);
         return -1;
     }

     SgProject sageProject ( (int)argc,argv);

     SageInterface::changeAllBodiesToBlocks(&sageProject);

    CmdOptions::GetInstance()->SetOptions(argc, argv);

   int filenum = sageProject.numberOfFiles();
   for (int i = 0; i < filenum; ++i) {
      SgSourceFile* sageFile = isSgSourceFile(sageProject.get_fileList()[i]);
      ROSE_ASSERT(sageFile != NULL);

      TestCFGWrap::AnalysisDomain t = UseOA(argc, argv)? TestCFGWrap::OA : TestCFGWrap::ROSE;
      string filename = sageFile->getFileName();

#if 0 // Test harness uses stdout rather than a temporary file
      string txtname = filename.substr(filename.rfind('/')+1) + ".outx"; 
      TestCFGWrap_Text txtop(t,txtname);
#else
      TestCFGWrap_Stdout txtop(t);
#endif
      //string dotname = string(strrchr(sageFile.getFileName(),'/')+1) + ".dot";
      string dotname = filename.substr(filename.rfind('/')+1) + ".dot";
      TestCFGWrap_DOT dotop(t);
     SgGlobal *root = sageFile->get_globalScope();
     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;
          SgNode* stmts = defn;
          if (GenerateDOT(argc, argv)) {
             dotop(stmts, dotname);
          }
          else {
             txtop(stmts);
          }
     }
   }

  return 0;
}
int
main ( int argc,  char * argv[] )
   {

     if (argc <= 1) {
         PrintUsage(argv[0]);
         return -1;
     }

     SgProject sageProject ( (int)argc,argv);
     SageInterface::changeAllBodiesToBlocks(&sageProject);
    CmdOptions::GetInstance()->SetOptions(argc, argv);


   int filenum = sageProject.numberOfFiles();
   for (int i = 0; i < filenum; ++i) {
     SgSourceFile* sageFile = isSgSourceFile(sageProject.get_fileList()[i]);
     ROSE_ASSERT(sageFile != NULL);
     SgGlobal *root = sageFile->get_globalScope();
     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);
          AstInterface fa(&scope);
          StmtVarAliasCollect alias;
          alias(fa, AstNodePtrImpl(defn));
          if (GenerateDOT(argc, argv)) {
             string name = string(strrchr(sageFile->getFileName().c_str(),'/')+1) + ".dot";
             TestDUWrap_DOT op(alias);
             op(fa, defn, name);
          }
          else {
             string name = string(strrchr(sageFile->getFileName().c_str(),'/')+1) + ".outx";
#if 0   // Test harness uses stdout now rather than a temporary file [Robb P. Matzke 2013-02-25]
             TestDUWrap_Text op(alias,name);
#else
             TestDUWrap_Stdout op(alias);
#endif
             op(fa, defn);
          }
     }
   }

  return 0;
}
int
main ( int argc,  char * argv[] )
   {
int a;
     if (argc <= 1) {
         PrintUsage(argv[0]);
         return -1;
     }
	DEBUG_ICFG = 1;
	DEBUG_STMT = 0;

    SgProject sageProject ( argc,argv);
    SageInterface::changeAllBodiesToBlocks(&sageProject);
    CmdOptions::GetInstance()->SetOptions(argc, argv);


  // TestPtrAnal op;
  //
   ptr_Anal_ICFG_Creator op;
   int filenum = sageProject.numberOfFiles();
   for (int i = 0; i < filenum; ++i) {
     SgFile &sageFile = sageProject.get_file(i);
     SgGlobal *root = sageFile.get_root();
     AstInterfaceImpl scope(root);
     AstInterface fa(&scope);
     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;
          op(fa, defn);
     }
   }
   op.draw("out.jpg");
  return 0;
}
Exemple #7
0
int
main ( int argc,  char * argv[] )
   {

     if (argc <= 1) {
         PrintUsage(argv[0]);
         return -1;
     }

    SgProject sageProject ( argc,argv);
    SageInterface::changeAllLoopBodiesToBlocks(&sageProject);
    CmdOptions::GetInstance()->SetOptions(argc, argv);


   TestPtrAnal op;
   int filenum = sageProject.numberOfFiles();
   for (int i = 0; i < filenum; ++i) {

     SgSourceFile* sageFile = isSgSourceFile(sageProject.get_fileList()[i]);
     ROSE_ASSERT(sageFile != NULL);
     SgGlobal *root = sageFile->get_globalScope();

     AstInterfaceImpl scope(root);
     AstInterface fa(&scope);
     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;
          op(fa, defn);
     }
   }
  return 0;
}
Exemple #8
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);

  ArrayAnnotation* array_annot = ArrayAnnotation::get_inst();
  array_annot->register_annot();

  //OperatorSideEffectAnnotation* funcAnnot=OperatorSideEffectAnnotation::get_inst();
  //funcAnnot->register_annot();
  LoopTransformInterface::set_sideEffectInfo(array_annot);

  ArrayInterface anal(*array_annot);
  LoopTransformInterface::set_arrayInfo(&anal);

  ReadAnnotation::get_inst()->read();
  if (DebugAnnot()) {
   // funcAnnot->Dump();
    array_annot->Dump();
  }

  AssumeNoAlias aliasInfo;
  LoopTransformInterface::set_aliasInfo(&aliasInfo);

  LoopTransformInterface::cmdline_configure(argvList);

  SgProject *sageProject = new SgProject ( argvList);
  FixFileInfo(sageProject);

  // DQ (11/19/2013): Added AST consistency tests.
     AstTests::runAllTests(sageProject);

  int filenum = sageProject->numberOfFiles();
  for (int i = 0; i < filenum; ++i) {

  // DQ (11/19/2013): Added AST consistency tests.
     AstTests::runAllTests(sageProject);

    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 ();

 // DQ (11/19/2013): Added AST consistency tests.
    AstTests::runAllTests(sageProject);

    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);

   // DQ (11/19/2013): Added AST consistency tests.
      AstTests::runAllTests(sageProject);

   // DQ (11/19/2013): Added AST consistency tests.
      AstTests::runAllTests(sageProject);

      LoopTransformInterface::TransformTraverse(scope,AstNodePtrImpl(stmts));

#if 0
   // DQ (11/19/2013): Added AST consistency tests (this fails).
      AstTests::runAllTests(sageProject);
#endif
    }
    tuning.GenOutput();

#if 0
  // DQ (11/19/2013): Added AST consistency tests (this fails).
     AstTests::runAllTests(sageProject);
#endif
  }

//   if (CmdOptions::GetInstance()->HasOption("-fd")) {
//       simpleIndexFiniteDifferencing(sageProject);
//   }
//   if (CmdOptions::GetInstance()->HasOption("-pre")) {
//       partialRedundancyElimination(sageProject);
//   }

#if 0
  // DQ (11/19/2013): Added AST consistency tests (this fails).
     AstTests::runAllTests(sageProject);
#endif

     unparseProject(sageProject);
   //backend(sageProject);

#ifdef USE_OMEGA
     DepStats.SetDepChoice(0x1 | 0x2 | 0x4);
     DepStats.PrintResults();
#endif

  return 0;
}
Exemple #9
0
int main( int argc, char * argv[] ) 
   {

     std::vector<std::string> newArgv(argv,argv+argc);
     newArgv.push_back("-rose:wave");

     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include/g++_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include/gcc_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include-staging/g++_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include-staging/gcc_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/usr/include/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/tests/CompileTest/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<builtin>");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<built-in>");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<builltin>");


  // Build the AST used by ROSE
     SgProject* project = frontend(newArgv);
     ROSE_ASSERT(project != NULL);


  // Run internal consistency tests on AST
     AstTests::runAllTests(project);


     // Assume that there is only one file
     std::string filename;
     for(int i = 0 ; i < project->numberOfFiles(); i++)
     {
       SgSourceFile* file = isSgSourceFile(&project->get_file(i));
       if( file != NULL)
         filename = file->getFileName();

     };

     ROSE_ASSERT(filename != "");

     filename+=".out";
     filename = StringUtility::stripPathFromFileName(filename);


     //Output the macro diretives to the file
     ofstream myfile;
     myfile.open (filename.c_str());

     ROSE_ASSERT(myfile.is_open());
     std::cout << "Outputing to the file " << filename << std::endl;



     backend(project);
     print_out_all_macros(myfile, project);
  // Insert your own manipulation of the AST here...

  // Generate source code from AST and call the vendor's compiler
     return backend(project);
   }
Exemple #10
0
int
main(int argc, char** argv)
   {
     ios::sync_with_stdio();                            // Syncs C++ and C I/O subsystems!
     rose::Diagnostics::initialize();                   // because librose doesn't initialize itself until frontend()

     Settings settings;
     std::vector<std::string> roseArgs = parseCommandLine(argc, argv, settings).unreachedArgs();
     roseArgs.insert(roseArgs.begin(), std::string(argv[0])); // not sure why frontend needs this, but it does.
     SgProject* project = frontend(roseArgs);
     ROSE_ASSERT (project != NULL);

  // Internal AST consistancy tests.
     AstTests::runAllTests(project);

     ROSE_ASSERT(project->numberOfFiles() == 2);

     int numberOfNodesInFile_0 = project->get_fileList()[0]->numberOfNodesInSubtree();
     int numberOfNodesInFile_1 = project->get_fileList()[1]->numberOfNodesInSubtree();

     printf ("numberOfNodesInFile_0 = %d \n",numberOfNodesInFile_0);
     printf ("numberOfNodesInFile_1 = %d \n",numberOfNodesInFile_1);

     if (settings.useOldImplementation) {
#if 0
         diff(project->get_fileList()[0],project->get_fileList()[1]);
#else

         vector< vector< SgNode* > > traversalTraceList = generateTraversalTraceList (project->get_fileList()[0],
                                                                                      project->get_fileList()[1],
                                                                                      /* minDepth = 0 */ 0,
                                                                                      /* infinite maxDepth */ -1 );
         printf ("Calling sequenceAlignment()... traversalTraceList.size() = %zu \n",traversalTraceList.size());
         sequenceAlignment  ( traversalTraceList );
         printf ("Done with call to sequenceAlignment() \n");
#endif

         // This method simply prints the edits as a side effect and doesn't return anything useful.
         Sawyer::Stopwatch tedLocalTimer;
         tree_edit_distance (project->get_fileList()[0],project->get_fileList()[1]);
         std::cout <<"local implementation of tree edit distance took " <<tedLocalTimer <<" seconds\n";
     }

     // This stuff uses the new edit distance analysis in librose
     std::cout <<"Using TreeEditDistance from librose:\n";
     EditDistance::TreeEditDistance::Analysis analysis;
     Sawyer::Stopwatch tedRoseTimer;
     analysis.compute(project->get_fileList()[0], project->get_fileList()[1],  // the subtrees to compare
                      project->get_fileList()[0], project->get_fileList()[1]); // their file restrictions
     std::cout <<"librose implementation of tree edit distance took " <<tedRoseTimer <<" seconds\n";
     EditDistance::TreeEditDistance::Edits edits = analysis.edits();
     std::cout <<"  Nodes in source tree: " <<analysis.sourceTreeNodes().size() <<"\n"
               <<"  Nodes in target tree: " <<analysis.targetTreeNodes().size() <<"\n"
               <<"  Number of edits:      " <<edits.size() <<"\n"
               <<"  Total cost of edits:  " <<analysis.cost() <<"\n"
               <<"  Relative cost:        " <<analysis.relativeCost() <<"\n"
               <<"  Individual edits:\n";
     BOOST_FOREACH (const EditDistance::TreeEditDistance::Edit &edit, edits)
         std::cout <<"    " <<edit <<"\n";
     std::ofstream graphViz("output-rose.dot");
     analysis.emitGraphViz(graphViz);
     std::cout <<"librose implementation of tree edit distance + output took " <<tedRoseTimer <<" seconds\n";
   }
Exemple #11
0
int
main(int argc, char** argv)
   {
     ios::sync_with_stdio();     // Syncs C++ and C I/O subsystems!
	 std::string idaPath = IDA_PRO_PATH;
	 if(idaPath == "")
     {
	   std::cerr << "Error: It is required to configure ROSE with IDA Pro \n";
	   exit(1);
	 }

    std::list<string> tsvDirectories; 


    path dir_path(argv[1]); 
    
    find_tsv_directories(dir_path, tsvDirectories);


    std::cout << "We have " << tsvDirectories.size() << " files " << std::endl;


    for(std::list<string>::iterator iItr = tsvDirectories.begin();
        iItr != tsvDirectories.end(); ++iItr)
    {

      std::string filename = *iItr;
      std::cout << "now doing " << filename << std::endl;
      std::vector<char*> newArgs;
      newArgs.push_back(strdup("-rose:read_executable_file_format_only"));
      newArgs.push_back(strdup(filename.c_str()));


      //for(int i =0; i < argc ; ++i)
      //  newArgs.push_back(strdup(argv[i]));

      SgProject* project = frontend( newArgs.size(), &newArgs[0] );

      ROSE_ASSERT (project != NULL);
      std::cout << "A" << std::endl;

      //Files will only exist for executables
      for(int i =0; i < project->numberOfFiles(); ++i)
      {
        SgFile* file = (*project)[i];
        std::cout << "B" << std::endl;

        if( isSgBinaryComposite(file) ){
          std::string filename = file->getFileName(); 

          std::cout << "B " << filename << std::endl;
          boost::filesystem::path path(filename);
          path = boost::filesystem::system_complete(path);
          std::string directory      = path.directory_string();
          std::string filenameString = path.root_name();


          std::string s = filename;
          string s_filename = StringUtility::stripPathFromFileName(s);
          string s_path     = StringUtility::getPathFromFileName(s);

          string s_nosuffix = s_filename.substr(0,s_filename.find_first_of(".") );
          printf ("s = %s s_filename = %s \n",s.c_str(),s_filename.c_str());
          printf ("s = %s s_path     = %s \n",s.c_str(),s_path.c_str());
          printf ("s = %s s_nosuffix = %s \n",s.c_str(),s_nosuffix.c_str());

          {
            //Need to create .idb first since that is the only way
            //to enable IDA analysis of the binaries

            ostringstream ostr;
            ostr << idaPath+"/idal";
            ostr << " -B ";
            ostr << filename.c_str();
            ostr << " -o"+s_path+"/"+s_nosuffix+".idb";

            std::cout << ostr.str() << std::endl;
            system(ostr.str().c_str());
          }

          {
            //Create .sql


            ostringstream ostr;
            ostr << idaPath+"/idal ";
            ostr << " -OIDAPython:" + idaPath + "/ida2sql.py ";
            ostr << s_path+"/"+s_nosuffix+".idb";
            //ostr << " -o"+filename+".sql";
            std::cout << ostr.str() << std::endl;
            system(ostr.str().c_str());

          }

          {
            //create -tsv directory which is the supported format in ROSE
            ostringstream ostr;
            ostr << " mv " + s_path+"/"+s_nosuffix+ ".sql " + filename + ".sql; "; 
            ostr << " cd " + s_path+";";
            ostr << " tclsh ";
            ostr << ROSE_COMPILE_TREE_PATH;
            ostr << "/projects/AstEquivalence/split-into-tables.tcl " + s_filename + ".sql;";
            std::cout << ostr.str() << std::endl;
            system(ostr.str().c_str());


          }


        }


      }

      DeleteSgTree(project);
    }

     return 1;
   }
int main( int argc, char * argv[] ) {
    
    if(argc < 3){
        Usage(argc, argv);
    }
    
    char * roseTraceFile = argv[1];
    FILE * roseTraceFilePtr;
    
    if(!(roseTraceFilePtr = fopen(roseTraceFile, "rb"))){
        fprintf(stderr, "\n Failed to read TraceFile %s",roseTraceFile);
        exit(-1);
    }

    FILE * roseProjectDBFilePtr;
    const char * roseProjectDBFile = argv[2];
    // Open the DB file... Don't need lock for reading.
    if(!(roseProjectDBFilePtr = fopen(roseProjectDBFile, "r"))){
        fprintf(stderr, "\n Failed to read roseDBFile %s", roseProjectDBFile);
        exit(-1);
    }
    
    char fileName[PATH_MAX];
    // Read DB file and assign file Ids
    while(fgets(fileName, PATH_MAX, roseProjectDBFilePtr)){
        // kill \n
        fileName[strlen(fileName)-1] = '\0';
        idToFile.push_back(string(fileName));
    }
    fclose(roseProjectDBFilePtr);
    
    
    
    // Read all trace records from the trace
    uint64_t traceId;
    boost::unordered_map<uint64_t, SgNode*>::iterator it;
    std::set<uint64_t> fileSet;
    
    vector<uint64_t> traceRecordVector;
    
    
    while(fread(&traceId, sizeof(uint64_t), 1, roseTraceFilePtr)){
        uint32_t fileId = traceId >> 32;
        if (fileId > idToFile.size()) {
            cout<<"\n"<< std::hex << traceId << " MISSING FILE!!!! id" << std::hex << fileId;
            traceRecordVector.push_back(NULL);
        } else {
            // If we have not seen this file, add it to teh set of files we want to open
            if(fileSet.find(fileId) == fileSet.end()){
                fileSet.insert(fileId);
            }
            traceRecordVector.push_back(traceId);
        }
    }
    fclose(roseTraceFilePtr);
    
    // Now build AST for each file in the set.
    
    
    for(std::set<uint64_t>::iterator it = fileSet.begin(), e = fileSet.end(); it != e; it++) {
        // prepare args.
        
        uint32_t fileId = *it;
        int numArgs = argc - 2 + 1; // -2 becoz we remove the trace and DB file. +1 because we add the source file.
        char * arguments[numArgs];
        for(int i = 3 ; i < numArgs - 1; i++){
            arguments[i] = argv[i];
        }
        arguments[0] = argv[0];
        arguments[numArgs-1] = (char *) idToFile[fileId].c_str();
        
        // Generate the ROSE AST.
        SgProject* project = frontend(numArgs, arguments);
        // AST consistency tests (optional for users, but this enforces more of our tests)
        AstTests::runAllTests(project);
        
        // Build node to trace id map.
        for(int i = 0 ; i < project->numberOfFiles(); i++) {
            SgFile & file = project->get_file(i);
            IdToNodeMapper mapper(&file, string(roseProjectDBFile));
        }
    }
    
    // Now, print the mapping from trace id to its SgNode
    
    for( vector<uint64_t>::iterator it = traceRecordVector.begin(), e = traceRecordVector.end(); it != e; it++){
        uint64_t traceId = *it;
        uint32_t fileId = traceId >> 32;
        SgNode * curSgNode = idToNodeMap[traceId];
        if(idToNodeMap.find(traceId) != idToNodeMap.end())
            cout <<"\n" << std::hex << traceId << idToFile[fileId] << ":" << std::hex << curSgNode << ":" << curSgNode->class_name();
        else
            cout <<"\n" << std::hex << traceId << "HAS NO MAPPING!!!";
    }
    
    return 0;
    
}
Exemple #13
0
int main(int argc, char** argv)
   {
  // DQ (9/1/2006): Introduce tracking of performance of ROSE at the top most level.
     TimingPerformance timer_main ("Compass performance (main): time (sec) = ",true);

     std::ios::sync_with_stdio();     // Syncs C++ and C I/O subsystems!

     if (SgProject::get_verbose() > 0)
          printf ("In compassMain.C: main() \n");

     Rose_STL_Container<std::string> commandLineArray = CommandlineProcessing::generateArgListFromArgcArgv (argc,argv);

     Compass::commandLineProcessing(commandLineArray);

  // Read the Compass parameter file (contains input data for all checkers)
  // This has been moved ahead of the parsing of the AST so that it is more 
  // obvious when it is a problem.
     Compass::Parameters params(Compass::findParameterFile());

#ifdef ROSE_MPI
     // Initialize MPI if needed...
     // need to do this to make test cases pass with MPI. 
     /* setup MPI */
     MPI_Init(&argc, &argv);
     MPI_Comm_rank(MPI_COMM_WORLD, &Compass::my_rank);
     MPI_Comm_size(MPI_COMM_WORLD, &Compass::processes);
#endif

  // Use a modified commandline that inserts specific additional options
  // to the ROSE frontend to make use with Compass more appropriate.
  // SgProject* project = frontend(argc,argv);
     SgProject* project = frontend(commandLineArray);


#ifdef HAVE_SQLITE3

     std::vector<bool> was_modified;

     //Determine if any file has been modified since the last run. If so, rerun
     //the compass checkers. The first run will always run the compass checkers.
     for (int i = 0; i < project->numberOfFiles(); ++i)
     {
       // In each file find all declarations in global scope
       SgSourceFile* sageFile = isSgSourceFile(project->get_fileList()[i]);
       std::string filename   = sageFile->getFileName();

       struct stat file_info;
       
       if ( stat(filename.c_str(), &file_info) != 0 )
         {
           std::cerr << "Error: Can not determine last modification time of file " << filename 
                     << std::endl;
       }else{

         std::string last_modified = boost::lexical_cast<std::string>(file_info.st_mtime);
         try {

           /* Read in from database here */
           sqlite3x::sqlite3_command cmd(Compass::con, "SELECT last_modified from file_last_modified where filename=\""+filename+ "\"" );

           sqlite3x::sqlite3_reader r = cmd.executereader();


           while (r.read()) {
             std::string last_modified_in_db = r.getstring(0);
             was_modified.push_back( (last_modified_in_db == last_modified) ? false : true );

           }

         } catch (std::exception& e) {std::cerr << "Exception: " << e.what() << std::endl;}

         //Update last modified time in database
         try{
           sqlite3x::sqlite3_command cmd(Compass::con,"DELETE from file_last_modified where filename=\""+filename+ "\"");
           cmd.executenonquery();
         } catch (std::exception& e) {std::cerr << "Exception: " << e.what() << std::endl;}

         try{
           sqlite3x::sqlite3_command cmd(Compass::con,"INSERT into file_last_modified(filename, last_modified) VALUES(?,?)");
           cmd.bind(1,filename);
           cmd.bind(2,last_modified);

           cmd.executenonquery();
         } catch (std::exception& e) {std::cerr << "Exception: " << e.what() << std::endl;}

                  
       };


     }

     //Continue processign iff at least one file was modified
     if( ( find(was_modified.begin(), was_modified.end(), true) != was_modified.end() )
         ||  (was_modified.size() == 0) )
     {
       //Delete violation entries that correspond to this file
       for (int i = 0; i < project->numberOfFiles(); ++i)
       {
         // In each file find all declarations in global scope
         SgSourceFile* sageFile = isSgSourceFile(project->get_fileList()[i]);
         std::string filename   = sageFile->getFileName();
         try{
           sqlite3x::sqlite3_command cmd(Compass::con,"DELETE from violations where filename=\""+filename+ "\"");
           cmd.executenonquery();
         } catch (std::exception& e) {std::cerr << "Exception: " << e.what() << std::endl;}


       }
       //continue processing
     }else
       exit(0);




#endif


#if 0
     project->display("In Compass");
#endif

     std::vector<const Compass::Checker*> traversals;

#ifdef USE_QROSE
  // This is part of incomplete GUI interface for Compass using QRose from Imperial.

  // Both of these output object work, but one is more useful for QRose.
     QRoseOutputObject* output = new QRoseOutputObject();
#endif

     Compass::PrintingOutputObject output(std::cerr);
     
        {
       // Make this in a nested scope so that we can time the buildCheckers function
          TimingPerformance timer_build ("Compass performance (build checkers and run prerequisites): time (sec) = ",false);

          buildCheckers(traversals,params,output, project);
          for ( std::vector<const Compass::Checker*>::iterator itr = traversals.begin(); itr != traversals.end(); itr++ ) {
            ROSE_ASSERT (*itr);
            Compass::runPrereqs(*itr, project);
          }
        }

     TimingPerformance timer_checkers ("Compass performance (checkers only): time (sec) = ",false);

     std::vector<std::pair<std::string, std::string> > errors;
     for ( std::vector<const Compass::Checker*>::iterator itr = traversals.begin(); itr != traversals.end(); itr++ )
        {
          if ( (*itr) != NULL )
             {
               if (Compass::verboseSetting >= 0)
                    printf ("Running checker %s \n",(*itr)->checkerName.c_str());

               try
                  {
                    int spaceAvailable = 40;
                    std::string name = (*itr)->checkerName + ":";
                    int n = spaceAvailable - name.length();
                    //Liao, 4/3/2008, bug 82, negative value
                    if (n<0) n=0;
                    std::string spaces(n,' ');
                    TimingPerformance timer (name + spaces + " time (sec) = ",false);
                    (*itr)->run(params, &output);
                  }
               catch (const std::exception& e)
                  {
                    std::cerr << "error running checker : " << (*itr)->checkerName << " - reason: " << e.what() << std::endl;
                    errors.push_back(std::make_pair((*itr)->checkerName, e.what()));
                  }
             } // if( (*itr) != NULL )
            else
             {
               std::cerr << "Error: Traversal failed to initialize" << std::endl;
               return 1;
             } // else
        } // for()

  // Support for ToolGear
     if (Compass::UseToolGear == true)
        {
          Compass::outputTgui( Compass::tguiXML, traversals, &output );
        }

#ifdef HAVE_SQLITE3
     if (Compass::UseDbOutput == true)
        {
          Compass::outputDb( Compass::outputDbName, traversals, &output );
        }
#endif

  // Output errors specific to any checkers that didn't initialize properly
     if (!errors.empty())
        {
          std::cerr << "The following checkers failed due to internal errors:" << std::endl;
          std::vector<std::pair<std::string, std::string> >::iterator e_itr;
          for (e_itr = errors.begin(); e_itr != errors.end(); ++e_itr)
             {
               std::cerr << e_itr->first << ": " << e_itr->second << std::endl;
             }
        }

  // Just set the project, the report will be generated upon calling the destructor for "timer"
     timer_main.set_project(project);

#ifdef ROSE_MPI
  MPI_Finalize();
#endif
#if 1  // Liao, 2/26/2009, add this backend support to be more friendly to build systems
       // 
     return backend(project);
#else     
     return 0;
#endif     
   }
Exemple #14
0
void
TransformationSupport::getTransformationOptions ( SgNode* astNode, list<OptionDeclaration> & generatedList, string identifingTypeName )
   {
  // This function searches for variables of type ScopeBasedTransformationOptimization.  Variables
  // of type ScopeBasedTransformationOptimization are used to communicate optimizations from the
  // application to the preprocessor. If called from a project or file object it traverses down to
  // the global scope of the file and searches only the global scope, if called from and other
  // location within the AST it searches the current scope and then traverses the parent nodes to
  // find all enclosing scopes until in reaches the global scope.  At each scope it searches for
  // variables of type ScopeBasedTransformationOptimization.

  // printf ("######################### START OF TRANSFORMATION OPTION QUERY ######################## \n");

     ROSE_ASSERT (astNode != NULL);
     ROSE_ASSERT (identifingTypeName.c_str() != NULL);

#if 0
     printf ("In getTransformationOptions(): astNode->sage_class_name() = %s generatedList.size() = %d \n",
          astNode->sage_class_name(),generatedList.size());
     SgLocatedNode* locatedNode = isSgLocatedNode(astNode);
     if (locatedNode != NULL)
        {
          printf ("          locatedNode->get_file_info()->get_filename() = %s \n",locatedNode->get_file_info()->get_filename());
          printf ("          locatedNode->get_file_info()->get_line() = %d \n",locatedNode->get_file_info()->get_line());
        }
#endif

     switch (astNode->variant())
        {
          case ProjectTag:
             {
               SgProject* project = isSgProject(astNode);
               ROSE_ASSERT (project != NULL);

           //! Loop through all the files in the project and call the mainTransform function for each file
               int i = 0;
               for (i=0; i < project->numberOfFiles(); i++)
                  {
                    SgFile* file = &(project->get_file(i));

                 // printf ("Calling Query::traverse(SgFile,QueryFunctionType,QueryAssemblyFunctionType) \n");
                    getTransformationOptions ( file, generatedList, identifingTypeName );
                  }
               break;
             }

          case SourceFileTag:
             {
               SgSourceFile* file = isSgSourceFile(astNode);
               ROSE_ASSERT (file != NULL);
               SgGlobal* globalScope = file->get_globalScope();
               ROSE_ASSERT (globalScope != NULL);
               ROSE_ASSERT (isSgGlobal(globalScope) != NULL);
               getTransformationOptions ( globalScope, generatedList, identifingTypeName );
               break;
             }

       // Global Scope
          case GLOBAL_STMT:
             {
               SgGlobal* globalScope = isSgGlobal(astNode);
               ROSE_ASSERT (globalScope != NULL);

               SgSymbolTable* symbolTable = globalScope->get_symbol_table();
               ROSE_ASSERT (symbolTable != NULL);
               getTransformationOptions ( symbolTable, generatedList, identifingTypeName );

            // printf ("Processed global scope, exiting .. \n");
            // ROSE_ABORT();
               break;
             }

          case SymbolTableTag:
             {
            // List the variable in each scope
            // printf ("List all the variables in this symbol table! \n");
               SgSymbolTable* symbolTable = isSgSymbolTable(astNode);
               ROSE_ASSERT (symbolTable != NULL);

               bool foundTransformationOptimizationSpecifier = false;

            // printf ("Now print out the information in the symbol table for this scope: \n");
            // symbolTable->print();

#if 0
            // I don't know when a SymbolTable is given a name!
               printf ("SymbolTable has a name = %s \n",
                    (symbolTable->get_no_name()) ? "NO: it has no name" : "YES: it does have a name");
               if (!symbolTable->get_no_name())
                    printf ("SymbolTable name = %s \n",symbolTable->get_name().str());
                 else
                    ROSE_ASSERT (symbolTable->get_name().str() == NULL);
#endif

               if (symbolTable->get_table() != NULL)
                  {
                    SgSymbolTable::hash_iterator i = symbolTable->get_table()->begin();
                    int counter = 0;
                    while (i != symbolTable->get_table()->end())
                       {
                         ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );

                      // printf ("Initial info: number: %d pair.first (SgName) = %s pair.second (SgSymbol) sage_class_name() = %s \n",
                      //      counter,(*i).first.str(),(*i).second->sage_class_name());

                         SgSymbol* symbol = isSgSymbol((*i).second);
                         ROSE_ASSERT ( symbol != NULL );
                         SgType* type = symbol->get_type();
                         ROSE_ASSERT ( type != NULL );

                         SgNamedType* namedType = isSgNamedType(type);
                         string typeName;
                         if (namedType != NULL)
                            {
                              SgName n = namedType->get_name();
                              typeName = namedType->get_name().str();
                           // char* nameString = namedType->get_name().str();
                           // printf ("Type is: (named type) = %s \n",nameString);
                              ROSE_ASSERT (identifingTypeName.c_str() != NULL);
                           // ROSE_ASSERT (typeName != NULL);
                           // printf ("In getTransformationOptions(): typeName = %s identifingTypeName = %s \n",typeName.c_str(),identifingTypeName.c_str());
                           // if ( (typeName != NULL) && ( typeName == identifingTypeName) )
                              if ( typeName == identifingTypeName )
                                 {
                                // Now look at the parameter list to the constructor and save the
                                // values into the list.

                                // printf ("Now save the constructor arguments! \n");

                                   SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);

                                   if ( variableSymbol != NULL )
                                      {
                                        SgInitializedName* initializedNameDeclaration = variableSymbol->get_declaration();
                                        ROSE_ASSERT (initializedNameDeclaration != NULL);

                                        SgDeclarationStatement* declarationStatement = initializedNameDeclaration->get_declaration();
                                        ROSE_ASSERT (declarationStatement != NULL);

                                        SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(declarationStatement);
                                        ROSE_ASSERT (variableDeclaration != NULL);

                                        getTransformationOptionsFromVariableDeclarationConstructorArguments(variableDeclaration,generatedList);

                                        foundTransformationOptimizationSpecifier = true;

                                     // printf ("Exiting after saving the constructor arguments! \n");
                                     // ROSE_ABORT();
                                      }
                                     else
                                      {
#if 0
                                        printf ("Not a SgVariableSymbol: symbol->sage_class_name() = %s \n",
                                             symbol->sage_class_name());
#endif
                                      }
                                 }
                                else
                                 {
#if 0
                                   printf ("typeName != identifingTypeName : symbol->sage_class_name() = %s \n",
                                        symbol->sage_class_name());
#endif
#if 0
                                // I don't think this should ever be NULL (but it is sometimes)
                                   if (typeName != NULL)
                                        printf ("typeName == NULL \n");
#endif
                                 }
                            }
                           else
                            {
                              typeName = (char *)type->sage_class_name();
                            }

                      // printf ("In while loop at the base: counter = %d \n",counter);
                         i++;
                         counter++;
                       }
                  }
                 else
                  {
                 // printf ("Pointer to symbol table is NULL \n");
                  }

            // printf ("foundTransformationOptimizationSpecifier = %s \n",foundTransformationOptimizationSpecifier ? "true" : "false");

            // SgSymbolTable objects don't have a parent node (specifically they lack a get_parent
            // member function in the interface)!
               break;
             }

          case BASIC_BLOCK_STMT:
             {
            // List the variable in each scope
            // printf ("List all the variables in this scope! \n");
               SgBasicBlock* basicBlock = isSgBasicBlock(astNode);
               ROSE_ASSERT (basicBlock != NULL);

               SgSymbolTable* symbolTable = basicBlock->get_symbol_table();
               ROSE_ASSERT (symbolTable != NULL);
               getTransformationOptions ( symbolTable, generatedList, identifingTypeName );

            // Next go (fall through this case) to the default case so that we traverse the parent
            // of the SgBasicBlock.
            // break;
             }

          default:
            // Most cases will be the default (this is by design)
            // printf ("default in switch found in globalQueryGetListOperandStringFunction() (sage_class_name = %s) \n",astNode->sage_class_name());

            // Need to recursively backtrack through the parents until we reach the SgGlobal (global scope)
               SgStatement* statement = isSgStatement(astNode);
               if (statement != NULL)
                  {
                    SgNode* parentNode = statement->get_parent();
                    ROSE_ASSERT (parentNode != NULL);
//                  printf ("parent = %p parentNode->sage_class_name() = %s \n",parentNode,parentNode->sage_class_name());
                    SgStatement* parentStatement = isSgStatement(parentNode);
                    if (parentStatement == NULL)
                       {
                         printf ("parentStatement == NULL: statement (%p) is a %s \n",statement,statement->sage_class_name());
                         printf ("parentStatement == NULL: statement->get_file_info()->get_filename() = %s \n",statement->get_file_info()->get_filename());
                         printf ("parentStatement == NULL: statement->get_file_info()->get_line() = %d \n",statement->get_file_info()->get_line());
                       }
                    ROSE_ASSERT (parentStatement != NULL);

                 // Call this function recursively (directly rather than through the query mechanism)
                    getTransformationOptions ( parentStatement, generatedList, identifingTypeName );
                  }
                 else
                  {
                 // printf ("astNode is not a SgStatement! \n");
                  }

               break;
        }

#if 0
     printf ("At BASE of getTransformationOptions(): astNode->sage_class_name() = %s size of generatedList = %d \n",
          astNode->sage_class_name(),generatedList.size());
#endif

  // printf ("######################### END OF TRANSFORMATION OPTION QUERY ######################## \n");
   }
Exemple #15
0
int main( int argc, char * argv[] )
   {

     {
       std::vector<std::string> newArgv(argv,argv+argc);
       newArgv.push_back("-rose:skip_rose");
       SgProject* project = frontend(newArgv);
       backend(project);

     }
     std::vector<std::string> newArgv(argv,argv+argc);
     newArgv.push_back("-rose:wave");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include/g++_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include/gcc_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include-staging/g++_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/include-staging/gcc_HEADERS/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/usr/include/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("/tests/CompileTest/");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<builtin>");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<built-in>");
     newArgv.push_back("-rose:excludePath");
     newArgv.push_back("<builltin>");



  // Build the AST used by ROSE
     SgProject* project = frontend(newArgv);
     ROSE_ASSERT(project != NULL);

  // Build a list of functions within the AST
     AnalyzeMacroCalls* macroCalls = new AnalyzeMacroCalls(project, false, std::cerr);

  // Assume that there is only one file
     std::string filename;
     for(int i = 0 ; i < project->numberOfFiles(); i++)
     {
       SgSourceFile* file = isSgSourceFile(&project->get_file(i));
       if( file != NULL)
         filename = file->getFileName();

     };

     ROSE_ASSERT(filename != "");

     filename+=".out";
     filename = StringUtility::stripPathFromFileName(filename);

     ofstream myfile;
     myfile.open (filename.c_str());

     ROSE_ASSERT(myfile.is_open());
     std::cout << "Outputing to the file " << filename << std::endl;


     macroCalls->print_out_all_macros(myfile);
     //     return backend(project);
     myfile.close();

   }
Exemple #16
0
Rose_STL_Container<SgNode*> NodeQuery::generateListOfTypes ( SgNode* astNode )
{
  // Insert your own manipulation of the AST here...
#if 0
  printf ("\n\n");
  printf ("************************** \n");
  printf ("Generate list of types ... \n");
#endif

  Rose_STL_Container<SgNode*> nodeList;

  // if (isSgProject(astNode) != NULL || (isSgFile(astNode) != NULL && SgProject::numberOfFiles() == 1) )
  // if (isSgProject(astNode) != NULL)
  bool useMemoryPool = (isSgProject(astNode) != NULL);
  if (useMemoryPool == false)
  {
    // Check if this is a SgFile or SgGlobal where there is only a single SgFile in the SgProject!
    if (isSgFile(astNode) != NULL || isSgGlobal(astNode) != NULL)
    {
   // DQ (1/25/2011): We want to be able to use this functionality, it is not depreicated...
   // printf ("This is not a SgProject, but it is a SgFile or SgGlobal so check if this is an only file before using the memory pool! \n");
      SgProject* project = TransformationSupport::getProject(astNode);

      // 2nd chance to reset useMemoryPool and provide an optimized query for types!
      useMemoryPool = (project->numberOfFiles() == 1);
    }
  }

  if (useMemoryPool == true)
  {
    // Then just query the memory pool and provide a much faster query.
    // printf ("Using memory pool access to type information ... \n");

    TypeQueryDummyFunctionalTest funcTest;

    // Build the list of all IR node variants that are derived from SgType (including SgType)
    VariantVector ir_nodes (V_SgType);

    // Execute the query on each separate memory pool for the list of IR node variants

    // DQ (3/14/2007): The NodeQuery::queryMemoryPool() function assumes that the function return type is a std::list
    // so try to use the AstQueryNamespace::queryMemoryPool() function directly.
    // nodeList = NodeQuery::queryMemoryPool(funcTest,&ir_nodes);
    // AstQueryNamespace::queryMemoryPool(funcTest,nodeList,&ir_nodes);

    // DQ (2/16/2007): This is Andreas's fix for the performance problem represented by the previous 
    // implementat which built and returns STL lists by value with only a single IR node in the list.
    AstQueryNamespace::queryMemoryPool(std::bind2nd(funcTest,&nodeList),&ir_nodes); 
  }
  else
  {
    // This operation is expensive and not always accurate (though only vacuious destructors might be missing).
    // As a result we would like to depricate its use in ROSE (at least for V_SgType \n");
#if 0
    printf ("The use of this mechanism to get type information on arbitrary subtrees is depricated! (subtree at %p = %s) \n",astNode,astNode->class_name().c_str());
#endif

    // Get the types from the specified subtree
#if 1
 // DQ (1/13/2011): This will only get a subset of types.
    nodeList = NodeQuery::querySubTree (astNode,V_SgType);
#else
 // DQ (1/13/2011): But I don't think this is the correct approach...
    AstQueryNamespace::QueryDepth defineQueryType = AstQueryNamespace::ExtractTypes;
    nodeList = NodeQuery::querySubTree (astNode,V_SgType,defineQueryType);
#endif

#if 0
    printf ("/* AST Test: nodeList.size() = %zu */ \n",nodeList.size());
    printNodeList(nodeList);
    printf ("*** Sorted list *** \n");
#endif

    // DQ (9/25/2007): These operations don't exist for a std::vector and were used with we used std::list.
    // nodeList.sort();
    // nodeList.unique();
#if 0
    printf ("Skipping use of std::list<>::sort() and std::list<>::unique() now that we are using std::vector! (Is this a problem for NodeQuery::generateListOfTypes()?) \n");
#endif
  }

#if 0
  printNodeList(nodeList);
  printf ("DONE: Generate list of types ... \n");
  printf ("************************** \n\n\n");
#endif

  return nodeList;
}
int main( int argc, char * argv[] ) {
    
    if(argc < 4){
        Usage(argc, argv);
    }
    
    int numTraces = 0;
    
    try
    {
        numTraces = boost::lexical_cast<int>(argv[1]); 
    }
    catch(...) {
        Usage(argc, argv);
    }
    
    
    FILE * roseTraceFilePtrs[numTraces];
    char * roseTraceFiles[numTraces];
    FILE * roseProjectDBFilePtr;
    const char * roseProjectDBFile;

    
    for(int i = 0 ; i < numTraces; i++) {
        roseTraceFiles[i] = argv[i+2];
        if(!(roseTraceFilePtrs[i] = fopen(roseTraceFiles[i], "rb"))){
            fprintf(stderr, "\n Failed to read TraceFile %s",roseTraceFiles[i]);
            exit(-1);
        }
    }
    
    // patch argv
    for(int i = numTraces + 2 ; i < argc; i++){
        argv[i - 1 - numTraces] = argv[i];
    }
    int patchedArgc = argc - (numTraces + 1);
    
    
    // Generate the ROSE AST.
    
    SgProject* project = frontend(patchedArgc ,argv);
    // AST consistency tests (optional for users, but this enforces more of our tests)
    AstTests::runAllTests(project);
    
    
    // Open the DB file... DOn't need lock for reading.
    roseProjectDBFile = project->get_projectSpecificDatabaseFile().c_str();
    if(!(roseProjectDBFilePtr = fopen(roseProjectDBFile, "r"))){
        fprintf(stderr, "\n Failed to read roseDBFile %s", roseProjectDBFile);
        exit(-1);
    }
    
    char fileName[PATH_MAX];
    // Read DB file and assign file Ids
    while(fgets(fileName, PATH_MAX, roseProjectDBFilePtr)){
        // kill \n
        fileName[strlen(fileName)-1] = '\0';
        idToFile.push_back(string(fileName));
    }
    fclose(roseProjectDBFilePtr);
    
    // Build node to trace id map.
    for(int i = 0 ; i < project->numberOfFiles(); i++) {
        SgFile & file = project->get_file(i);
        IdToNodeMapper mapper(&file, project->get_projectSpecificDatabaseFile());
    }
    
    // Read all trace records from all traces
    uint64_t traceId;
    boost::unordered_map<uint64_t, SgNode*>::iterator it;
    
    vector<SgNode *> traceRecordVector[numTraces];
    
    for(int curTraceNo = 0 ; curTraceNo < numTraces ; curTraceNo++) {
        while(fread(&traceId, sizeof(uint64_t), 1, roseTraceFilePtrs[curTraceNo])){
            uint32_t fileId = traceId >> 32;
            uint32_t nodeId = (traceId & 0xffffffff);
            
            if (fileId > idToFile.size()) {
                cout<<"\n"<< std::hex << traceId << " MISSING FILE!!!! id" << std::hex << fileId;
                traceRecordVector[curTraceNo].push_back(NULL);
            } else {
                it = idToNodeMap.find(traceId);
                if(it == idToNodeMap.end()){
                    cout<<"\n"<< std::hex << traceId << " can't map back!!!" << std::hex << fileId << std::hex << nodeId;
                    traceRecordVector[curTraceNo].push_back(NULL);
                } else {
                    cout<<"\n"<< std::hex << traceId << ":"<< idToFile[fileId] << ":" << std::hex << (*it).second << ":" << ((*it).second)->class_name();
                    traceRecordVector[curTraceNo].push_back((*it).second);
                }
            }
        }
        fclose(roseTraceFilePtrs[curTraceNo]);
    }
    
    
    // Now, compare traces till they start to diverge and populate them in a vector so that one can iterate over them.
    
    vector<SgNode *> commonPrefix;
    uint64_t minTraceSize = -1;
    uint64_t maxTraceSize = 0;

    for( int i = 0 ; i < numTraces; i++){
        if( traceRecordVector[i].size() < minTraceSize) {
            minTraceSize = traceRecordVector[i].size();
        }
        if( traceRecordVector[i].size() > maxTraceSize) {
            maxTraceSize = traceRecordVector[i].size();
        }
    }

    uint64_t commonPrefixLength = 0;
    for( ; commonPrefixLength < minTraceSize; commonPrefixLength++){
        SgNode * curSgNode = traceRecordVector[0][commonPrefixLength];
        for(int traceNo = 1 ; traceNo < numTraces ; traceNo++){
            if(traceRecordVector[traceNo][commonPrefixLength] != curSgNode){
                // Paths diverged
                cout<<"\n Paths diverge, common prefix length = " << commonPrefixLength;
                goto DONE;
            }
        }
        commonPrefix.push_back(curSgNode);
    }
    
    if(maxTraceSize == minTraceSize)
        cout<<"\n Paths match perfectly, length = " << commonPrefixLength;

    
DONE:
    // Print the common prefix nodes
    cout<<"\n Common prefix is:";
    for( uint64_t i = 0; i < commonPrefixLength ; i++){
        SgNode * node = commonPrefix[i];
        cout<<"\n"<< std::hex << node << ":" << node->class_name();
    }
    return 0;
    
}
Exemple #18
0
string globalUnparseToString ( SgNode* astNode, SgUnparse_Info* inputUnparseInfoPointer )
{
  // This global function permits any SgNode (including it's subtree) to be turned into a string

  // DQ (3/2/2006): Let's make sure we have a valid IR node!
     ROSE_ASSERT(astNode != NULL);

     string returnString;

  // all options are now defined to be false. When these options can be passed in
  // from the prompt, these options will be set accordingly.
     bool _auto                         = false;
     bool linefile                      = false;
     bool useOverloadedOperators        = false;
     bool num                           = false;

  // It is an error to have this always turned off (e.g. pointer = this; will not unparse correctly)
     bool _this                         = true;

     bool caststring                    = false;
     bool _debug                        = false;
     bool _class                        = false;
     bool _forced_transformation_format = false;
     bool _unparse_includes             = false;

  // printf ("In globalUnparseToString(): astNode->sage_class_name() = %s \n",astNode->sage_class_name());

     Unparser_Opt roseOptions( _auto,
                               linefile,
                               useOverloadedOperators,
                               num,
                               _this,
                               caststring,
                               _debug,
                               _class,
                               _forced_transformation_format,
                               _unparse_includes );

     int lineNumber = 0;  // Zero indicates that ALL lines should be unparsed

     // Initialize the Unparser using a special string stream inplace of the usual file stream 
     ostringstream outputString;

     SgLocatedNode* locatedNode = isSgLocatedNode(astNode);
     string fileNameOfStatementsToUnparse;
     if (locatedNode == NULL)
        {
       // printf ("WARNING: applying AST -> string for non expression/statement AST objects \n");
          fileNameOfStatementsToUnparse = "defaultFileNameInGlobalUnparseToString";
        }
       else
        {
          ROSE_ASSERT (locatedNode != NULL);

       // DQ (5/31/2005): Get the filename from a traversal back through the parents to the SgFile
       // fileNameOfStatementsToUnparse = locatedNode->getFileName();
       // fileNameOfStatementsToUnparse = rose::getFileNameByTraversalBackToFileNode(locatedNode);
          if (locatedNode->get_parent() == NULL)
             {
            // DQ (7/29/2005):
            // Allow this function to be called with disconnected AST fragments not connected to 
            // a previously generated AST.  This happens in Qing's interface where AST fragements 
            // are built and meant to be unparsed.  Only the parent of the root of the AST 
            // fragement is expected to be NULL.
               fileNameOfStatementsToUnparse = locatedNode->getFileName();
             }
            else
             {
               fileNameOfStatementsToUnparse = rose::getFileNameByTraversalBackToFileNode(locatedNode);
             }
          
        }
     ROSE_ASSERT (fileNameOfStatementsToUnparse.size() > 0);

     Unparser roseUnparser ( &outputString, fileNameOfStatementsToUnparse, roseOptions, lineNumber );

  // Information that is passed down through the tree (inherited attribute)
  // Use the input SgUnparse_Info object if it is available.
     SgUnparse_Info* inheritedAttributeInfoPointer = NULL;
     if (inputUnparseInfoPointer != NULL)
        {
       // printf ("Using the input inputUnparseInfoPointer object \n");

       // Use the user provided SgUnparse_Info object
          inheritedAttributeInfoPointer = inputUnparseInfoPointer;
        }
       else
        {
       // DEFINE DEFAULT BEHAVIOUR FOR THE CASE WHEN NO inputUnparseInfoPointer (== NULL) IS 
       // PASSED AS ARGUMENT TO THE FUNCTION
       // printf ("Building a new Unparse_Info object \n");

       // If no input parameter has been specified then allocate one
       // inheritedAttributeInfoPointer = new SgUnparse_Info (NO_UNPARSE_INFO);
          inheritedAttributeInfoPointer = new SgUnparse_Info();
          ROSE_ASSERT (inheritedAttributeInfoPointer != NULL);

       // MS: 09/30/2003: comments de-activated in unparsing
          ROSE_ASSERT (inheritedAttributeInfoPointer->SkipComments() == false);

       // Skip all comments in unparsing
          inheritedAttributeInfoPointer->set_SkipComments();
          ROSE_ASSERT (inheritedAttributeInfoPointer->SkipComments() == true);
       // Skip all whitespace in unparsing (removed in generated string)
          inheritedAttributeInfoPointer->set_SkipWhitespaces();
          ROSE_ASSERT (inheritedAttributeInfoPointer->SkipWhitespaces() == true);

       // Skip all directives (macros are already substituted by the front-end, so this has no effect on those)
          inheritedAttributeInfoPointer->set_SkipCPPDirectives();
          ROSE_ASSERT (inheritedAttributeInfoPointer->SkipCPPDirectives() == true);
        }

     ROSE_ASSERT (inheritedAttributeInfoPointer != NULL);
     SgUnparse_Info & inheritedAttributeInfo = *inheritedAttributeInfoPointer;

  // Turn ON the error checking which triggers an error if the default SgUnparse_Info constructor is called
  // SgUnparse_Info::forceDefaultConstructorToTriggerError = true;

#if 1
  // DQ (10/19/2004): Cleaned up this code, remove this dead code after we are sure that this worked properly
  // Actually, this code is required to be this way, since after this branch the current function returns and
  // some data must be cleaned up differently!  So put this back and leave it this way, and remove the
  // "Implementation Note".

  // Both SgProject and SgFile are handled via recursive calls
     if ( (isSgProject(astNode) != NULL) || (isSgFile(astNode) != NULL) )
        {
       // printf ("Implementation Note: Put these cases (unparsing the SgProject and SgFile into the cases for nodes derived from SgSupport below! \n");

       // Handle recursive call for SgProject
          if (isSgProject(astNode) != NULL)
             {
               SgProject* project = isSgProject(astNode);
               ROSE_ASSERT(project != NULL);
               for (int i = 0; i < project->numberOfFiles(); i++)
                  {
                    SgFile* file = &(project->get_file(i));
                    ROSE_ASSERT(file != NULL);
                    string unparsedFileString = globalUnparseToString(file,inputUnparseInfoPointer);
                    string prefixString       = string("/* TOP:")      + string(rose::getFileName(file)) + string(" */ \n");
                    string suffixString       = string("\n/* BOTTOM:") + string(rose::getFileName(file)) + string(" */ \n\n");
                    returnString += prefixString + unparsedFileString + suffixString;
                  }
             }

       // Handle recursive call for SgFile
          if (isSgFile(astNode) != NULL)
             {
               SgFile* file = isSgFile(astNode);
               ROSE_ASSERT(file != NULL);
               SgGlobal* globalScope = file->get_root();
               ROSE_ASSERT(globalScope != NULL);
               returnString = globalUnparseToString(globalScope,inputUnparseInfoPointer);
             }
        }
       else
#endif
        {
       // DQ (1/12/2003): Only now try to trap use of SgUnparse_Info default constructor
       // Turn ON the error checking which triggers an error if the default SgUnparse_Info constructor is called
          SgUnparse_Info::set_forceDefaultConstructorToTriggerError(true);

          if (isSgStatement(astNode) != NULL)
             {
               SgStatement* stmt = isSgStatement(astNode);
               roseUnparser.unparseStatement ( stmt, inheritedAttributeInfo );
             }

          if (isSgExpression(astNode) != NULL)
             {
               SgExpression* expr = isSgExpression(astNode);
               roseUnparser.unparseExpression ( expr, inheritedAttributeInfo );
             }

          if (isSgType(astNode) != NULL)
             {
               SgType* type = isSgType(astNode);
               roseUnparser.unparseType ( type, inheritedAttributeInfo );
             }

          if (isSgSymbol(astNode) != NULL)
             {
               SgSymbol* symbol = isSgSymbol(astNode);
               roseUnparser.unparseSymbol ( symbol, inheritedAttributeInfo );
             }

          if (isSgSupport(astNode) != NULL)
             {
            // Handle different specific cases derived from SgSupport 
            // (e.g. template parameters and template arguments).
               switch (astNode->variantT())
                  {
#if 0
                    case V_SgProject:
                       {
                         SgProject* project = isSgProject(astNode);
                         ROSE_ASSERT(project != NULL);
                         for (int i = 0; i < project->numberOfFiles(); i++)
                            {
                              SgFile* file = &(project->get_file(i));
                              ROSE_ASSERT(file != NULL);
                              string unparsedFileString = globalUnparseToString(file,inputUnparseInfoPointer);
                              string prefixString       = string("/* TOP:")      + string(rose::getFileName(file)) + string(" */ \n");
                              string suffixString       = string("\n/* BOTTOM:") + string(rose::getFileName(file)) + string(" */ \n\n");
                              returnString += prefixString + unparsedFileString + suffixString;
                            }
                         break;
                       }
                    case V_SgFile:
                       {
                         SgFile* file = isSgFile(astNode);
                         ROSE_ASSERT(file != NULL);
                         SgGlobal* globalScope = file->get_root();
                         ROSE_ASSERT(globalScope != NULL);
                         returnString = globalUnparseToString(globalScope,inputUnparseInfoPointer);
                         break;
                       }
#endif
                    case V_SgTemplateParameter:
                       {
                         SgTemplateParameter* templateParameter = isSgTemplateParameter(astNode);
                         roseUnparser.unparseTemplateParameter(templateParameter,inheritedAttributeInfo);
                         break;
                       }
                    case V_SgTemplateArgument:
                       {
                         SgTemplateArgument* templateArgument = isSgTemplateArgument(astNode);
                         roseUnparser.unparseTemplateArgument(templateArgument,inheritedAttributeInfo);
                         break;
                       }
                    case V_SgInitializedName:
                       {
                      // QY: not sure how to implement this
                      // DQ (7/23/2004): This should unparse as a declaration 
                      // (type and name with initializer).
                         break;
                       }

                    case V_Sg_File_Info:
                       {
                      // DQ (5/11/2006): Not sure how or if we shoul implement this
                         break;
                       }

                 // Perhaps the support for SgFile and SgProject shoud be moved to this location?
                    default:
                         printf ("Error: default reached in node derived from SgSupport astNode = %s \n",astNode->sage_class_name());
                         ROSE_ABORT();
                }
             }

       // Turn OFF the error checking which triggers an if the default SgUnparse_Info constructor is called
          SgUnparse_Info::set_forceDefaultConstructorToTriggerError(false);

       // MS: following is the rewritten code of the above outcommented 
       //     code to support ostringstream instead of ostrstream.
          returnString = outputString.str();

       // Call function to tighten up the code to make it more dense
          if (inheritedAttributeInfo.SkipWhitespaces() == true)
             {
               returnString = roseUnparser.removeUnwantedWhiteSpace ( returnString );
             }

       // delete the allocated SgUnparse_Info object
          if (inputUnparseInfoPointer == NULL)
               delete inheritedAttributeInfoPointer;
        }

     return returnString;
   }
int
main ( int argc,  char * argv[] )
{
  // Initialize and check compatibility. See rose::initialize
  ROSE_INITIALIZE;

  if (argc <= 1) {
      PrintUsage(argv[0]);
      return -1;
  }
  vector<string> argvList(argv, argv + argc);
  CmdOptions::GetInstance()->SetOptions(argvList);
  AssumeNoAlias aliasInfo;
  LoopTransformInterface::cmdline_configure(argvList);
  LoopTransformInterface::set_aliasInfo(&aliasInfo);

#ifdef USE_OMEGA
  DepStats.SetFileName(buffer.str());
#endif

  OperatorSideEffectAnnotation *funcInfo = 
         OperatorSideEffectAnnotation::get_inst();
  funcInfo->register_annot();
  ReadAnnotation::get_inst()->read();
  if (DebugAnnot())
     funcInfo->Dump();
  LoopTransformInterface::set_sideEffectInfo(funcInfo);
  SgProject *project = new SgProject ( argvList);

   int filenum = project->numberOfFiles();
   for (int i = 0; i < filenum; ++i) {
  // SgFile &sageFile = sageProject->get_file(i);
  // SgGlobal *root = sageFile.get_root();
     SgSourceFile* file = isSgSourceFile(project->get_fileList()[i]);
     SgGlobal *root = file->get_globalScope();
     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 faImpl = AstInterfaceImpl(stmts);
          LoopTransformInterface::TransformTraverse(faImpl, AstNodePtrImpl(stmts));

       // JJW 10-29-2007 Adjust for iterator invalidation and possible changes to declList
          p = std::find(declList.begin(), declList.end(), func);
          assert (p != declList.end());
     }
   }

   if (CmdOptions::GetInstance()->HasOption("-fd")) {
       simpleIndexFiniteDifferencing(project);
   }

   if (CmdOptions::GetInstance()->HasOption("-pre")) {
       PRE::partialRedundancyElimination(project);
   }
#ifdef USE_OMEGA
     DepStats.SetDepChoice(0x1 | 0x2 | 0x4);
     DepStats.PrintResults();
#endif
  //Qing's loop transformations are not robust enough to pass all tests.
   //AstTests::runAllTests(sageProject);
   unparseProject(project);
   if (GenerateObj())
      return project->compileOutput();
   return 0;
}
int
main ( int argc, char * argv[] )
   {
  // DQ (2/26/2010): Use the last name as the output file name for the generated AST (written back out).
     ROSE_ASSERT(argc > 1);
     if (argc <= 1)
        {
          printf ("Error: This AST file reader requires the name of a binary AST file AND the output filename for the merged binary AST file. \n");
          ROSE_ASSERT(false);
        }

#if 0
  // DQ (2/23/2010): This can't be called since it will generate a SgFunctionTypeTable and the memory pools must be empty.
     printf ("Before reading AST files: SgNode::get_globalFunctionTypeTable() = %p \n",SgNode::get_globalFunctionTypeTable());
  // ROSE_ASSERT(isSgFunctionTypeTable(SgNode::get_globalFunctionTypeTable()) != NULL);
#endif

  // Internal debugging support (e.g. new and delete operators).
  // ROSE_DEBUG = 2;

     int numFiles = argc - 2;
     vector<std::string> fileNames;
     for (int i= 0; i < numFiles; ++i)
        {
       // Detect options starting with "-"; not allowed.
          if (argv[i+1][0] == '-')
             {
               printf ("Skipping %s \n",argv[i+1]);

               printf ("Error can't handle common ROSE options on command line! \n");
               ROSE_ASSERT(false);
             }

          fileNames.push_back(argv[i+1]);
        }

     string outputFileName = argv[argc-1];
     printf ("Number of file = %zu Output filename = %s \n",fileNames.size(),outputFileName.c_str());

  // Reset numFiles to only count valid input files.
  // numFiles = fileNames.size();

#if 0
     printf ("Exiting after test of output name specification. \n");
     ROSE_ASSERT(false);
#endif

#if 0
     cout << "################ In astFileRead.C ############## " << endl;
     cout << "#  Going to read " << numFiles << " files  " << endl;
     cout << "################################################ " << endl;
#endif

  // We should be built into a data structure to hold this sepeaate file by file AST information.
  // Static data structures in ROSE that require special handling when reading more than one AST from a file.
     vector<SgFunctionTypeTable*> functionTableArray;
  // vector<map<int, std::string> > fileidtoname_mapArray;
  // vector<map<std::string, int> > nametofileid_mapArray;

  // This uses the new data structure to hold all the required information for each 
  // AST file so that we can do a merge of the static information of the AST.
     vector<AstFileSpecificInfo*> AstFileInfoArray;

     size_t currentNumberOfNodes  = 0;
     size_t previousNumberOfNodes = 0;

  // DQ (6/5/2010): Trigger debugging output!
  // ROSE_DEBUG = 2;
  // SgProject::set_verbose(3);

  // cout  << endl << "Here we call the AST_FILE_IO :: readASTFromFile ..." << endl;
     SgProject* tmp_previous_globalProject = NULL;
     for (int i= 0; i < numFiles; ++i)
        {
       // cout  << "Here we will read .... " << fileNames[i] << endl;
          AST_FILE_IO :: readASTFromFile ( fileNames[i] + ".binary" );
       // cout  << "Here we just read .... " << fileNames[i] << endl;

          AstData* tmp_ast = AST_FILE_IO::getAst(i);
          SgProject* tmp_globalProject = tmp_ast->getRootOfAst();
          ROSE_ASSERT(tmp_globalProject->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
          if (tmp_previous_globalProject != NULL)
             {
               ROSE_ASSERT(tmp_previous_globalProject->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
             }
          tmp_previous_globalProject = tmp_globalProject;
          

          currentNumberOfNodes = Sg_File_Info::numberOfNodes();

       // printf ("SgProject* tmp_globalProject = %p \n",tmp_globalProject);
          printf ("file #%5d = %20s AST size = %12zu IR nodes  memory usage = %12zu bytes  Sg_File_Info::numberOfNodes() = %12zu \n",i,fileNames[i].c_str(),numberOfNodes(),memoryUsage(),currentNumberOfNodes);

       // TestFreepointerInMemoryPool::test();

#if 0
       // DQ (2/24/2010): This is a significant bottleneck to the performance on large codes since it is n^2 in the size of the AST.
          AstTests::runAllTests(ast->getRootOfAst());
#endif
#if 0
          printf ("In loop reading AST files: SgNode::get_globalFunctionTypeTable() = %p \n",SgNode::get_globalFunctionTypeTable());
          printf ("file #%d AST Sg_File_Info::numberOfNodes() = %d \n",i,currentNumberOfNodes);
#endif
       // Some of this information has to be setup after we call AST_FILE_IO::setStaticDataOfAst() for each AST.
       // AstFileSpecificInfo* astFileSpecificInformation = new AstFileSpecificInfo(SgNode::get_globalFunctionTypeTable(),previousNumberOfNodes,currentNumberOfNodes,Sg_File_Info::get_fileidtoname_map(),Sg_File_Info::get_nametofileid_map());
          AstFileSpecificInfo* astFileSpecificInformation = new AstFileSpecificInfo(previousNumberOfNodes,currentNumberOfNodes-1);
          ROSE_ASSERT(astFileSpecificInformation != NULL);  
          AstFileInfoArray.push_back(astFileSpecificInformation);

       // Track the positions of the base and bound of the Sg_File_Info list in the memory pool.
          previousNumberOfNodes = currentNumberOfNodes;

       // printf ("At base of loop over the input files... i = %d \n",i);
        }
#if 1
     cout  << endl << "AST_FILE_IO :: readASTFromFile done ... " << endl;
#endif

  // SgFunctionTypeTable* globalFunctionTypeTable = NULL;
     SgProject*           globalProject                 = NULL;

     ROSE_ASSERT(AstFileInfoArray.size() == (size_t)numFiles);

  // DQ (6/5/2010): Trigger debugging output!
  // ROSE_DEBUG = 2;

     AstData* ast = NULL;
     for (int i= 0; i < numFiles; ++i)
        {
#if 0
          printf ("Processing file #%d \n",i);
#endif
          ast = AST_FILE_IO::getAst(i);
#if 0
       // DQ (6/6/2010): Turned off to limit output in debugging...
       // DQ (6/5/2010): Unclear if I can use this test here!
          printf ("Running AstTests::runAllTests() BEFORE calling AST_FILE_IO::setStaticDataOfAst(ast)\n");
          AstTests::runAllTests(ast->getRootOfAst());
          printf ("DONE: Running AstTests::runAllTests() BEFORE calling AST_FILE_IO::setStaticDataOfAst(ast)\n");
#endif

       // This sets static data to be consistant within each AST, but not across the single merged AST (from multiple files).
          AST_FILE_IO::setStaticDataOfAst(ast);

       // TestFreepointerInMemoryPool::test();

#if 0
          printf ("In loop reading AST files: SgNode::get_globalFunctionTypeTable() = %p \n",SgNode::get_globalFunctionTypeTable());
          printf ("In loop reading AST files: Sg_File_Info::get_fileidtoname_map() = %p size() = %zu \n",&Sg_File_Info::get_fileidtoname_map(),Sg_File_Info::get_fileidtoname_map().size());
          printf ("In loop reading AST files: Sg_File_Info::get_nametofileid_map() = %p size() = %zu \n",&Sg_File_Info::get_nametofileid_map(),Sg_File_Info::get_nametofileid_map().size());
          printf ("Sg_File_Info::numberOfNodes() = %d \n",Sg_File_Info::numberOfNodes());
#endif
          ROSE_ASSERT(Sg_File_Info::get_fileidtoname_map().size() == Sg_File_Info::get_nametofileid_map().size());

       // We need to make a second call to fixup the information in the AstFileSpecificInfo objects once we have called AST_FILE_IO::setStaticDataOfAst() for each AST.
          AstFileInfoArray[i]->fixupAstFileSpecificInfo(SgNode::get_globalFunctionTypeTable(),Sg_File_Info::get_fileidtoname_map(),Sg_File_Info::get_nametofileid_map());

       // printf ("DONE with call to AstFileInfoArray[%d]->fixupAstFileSpecificInfo() \n",i);

       // Save references to all the function type tables.
          functionTableArray.push_back(SgNode::get_globalFunctionTypeTable());

       // Save copies of all the filename maps (copies because they are not implemented via a static pointer).
       // fileidtoname_mapArray.push_back(Sg_File_Info::get_fileidtoname_map());
       // nametofileid_mapArray.push_back(Sg_File_Info::get_nametofileid_map());

       // testAST(ast->getRootOfAst());


       // DQ (6/21/2010): Fixup the support for builtin types stored as static data in the SgType derived classes.
       // FixupbuiltinTypes(AST_FILE_IO::getAst(i),AST_FILE_IO::getAst(i));
       // printf ("In loop reading AST files: SgTypeUnsignedInt::p_builtin_type = %p \n",SgTypeUnsignedInt::createType());

#if 0
       // TestFreepointerInMemoryPool::test();

          printf ("Call to AstTests::runAllTests() ast->getRootOfAst() = %p = %s \n",ast->getRootOfAst(),ast->getRootOfAst()->class_name().c_str());
          SgProject* temp_project = ast->getRootOfAst();
       // ROSE_ASSERT(temp_project->numberOfFiles() == 1);
          ROSE_ASSERT(temp_project->numberOfDirectories() == 0);
          SgFile* temp_file = (*temp_project)[0];
          printf ("temp_file->get_filename() = %s \n",temp_file->getFileName().c_str());

       // DQ (6/5/2010): Turn on to support debugging...
       // DQ (2/24/2010): This is a significant bottleneck to the performance on large codes since it is n^2 in the size of the AST.
       // AstTests::runAllTests(ast->getRootOfAst());

          printf ("DONE with call to AstTests::runAllTests() \n");
#endif
#if 0
       // To read and merge the separate AST files, we don't have to call the backend.
          backend(ast->getRootOfAst());
#endif

       // printf ("globalProject = %p \n",globalProject);

          if (globalProject == NULL)
             {
               globalProject = ast->getRootOfAst();
               ROSE_ASSERT(globalProject->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
             }
            else
             {
               SgProject* localProject = ast->getRootOfAst();
               SgFile*    localFile    = (*localProject)[0];

            // DQ (3/1/2010): Merged files that are reread will have more than one SgFile object.
            // ROSE_ASSERT(localProject->numberOfFiles() == 1);

            // Add the file to the global project. This also sets the parent of the input file. Is this a side-effect that we want?
               globalProject->set_file(*localFile);
#if 0
               printf ("globalProject = %p numberOfFiles() = %d \n",globalProject,globalProject->numberOfFiles());
#endif
               ROSE_ASSERT(globalProject->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
//             delete localProject;
             }
        }

     printf ("Size of AST = %zu (globalProject = %p)\n",numberOfNodes(),globalProject);

#if 0
     for (int i= 0; i < numFiles; ++i)
        {
          AstFileInfoArray[i]->display("static AST file information");
        }
#endif

#if 0
  // DQ (3/7/2010): It may be that we have to process the merged static data before we can expect 
  // to pass this test.
  // DQ (2/24/2010): Better to run this once at the end to avoid a significant bottleneck to the 
  // performance on large codes (it is n^2 in the size of the AST if run for each file separately).
     //AstTests::runAllTests(ast->getRootOfAst());
#endif

  // Merge the function tables from each AST.
  // SgFunctionTypeTable* globalFunctionTypeTable = mergeFunctionTypeSymbolTables (functionTableArray);
  // ROSE_ASSERT(globalFunctionTypeTable != NULL);

  // It is required to merge the static information in the AST, to get a valid AST, even if no other merging is done.
     printf ("\n\nCalling mergeStaticASTFileInformation() \n");
     mergeStaticASTFileInformation(AstFileInfoArray);
     printf ("Size of AST (after merge of static data) = %zu \n",numberOfNodes());

  // DQ (7/10/2010): This is now called from within the AST merge mechanism.
  // printf ("Normalize the SgTypedefSeq IR nodes to be consistant across the union of ASTs. \n");
  // normalizeTypedefSequenceLists();
  // printf ("DONE: Normalize the SgTypedefSeq IR nodes to be consistant across the union of ASTs. \n");

#if 1
  // DQ (6/7/2010): Now call the AST merge that will detect redundant (or repeated) parts 
  // of the AST and force sharing of these pieces and delete the redundany copies.
     printf ("\n\nCalling AstMergeSupport() \n");
  // int mergeErrorCode = AstMergeSupport(globalProject);
  // bool skipFrontendSpecificIRnodes = true;
  // SgProject::set_verbose(3);
     bool skipFrontendSpecificIRnodes = false;
     mergeAST(globalProject,skipFrontendSpecificIRnodes);
  // ROSE_ASSERT(mergeErrorCode == 0);
  // SgProject::set_verbose(0);
#else
     printf ("Skipping call to mergeAST() \n");
#endif

     printf ("Size of AST (after final merge to eliminate redundancy) = %zu \n",numberOfNodes());

#if 1
  // DQ (2/24/2010): Better to run this once at the end to avoid a significant bottleneck to the 
  // performance on large codes (it is n^2 in the size of the AST if run for each file separately).
  // AstTests::runAllTests(ast->getRootOfAst());
     printf ("\n\nRunning AST consistancy tests on merged AST \n");
     AstTests::runAllTests(globalProject);
     printf ("DONE: Running AST consistancy tests on merged AST \n");
#endif

#if 0
  // Output an example of the value of p_freepointer.
     printf ("AST_FILE_IO::areFreepointersContainingGlobalIndices() = %s \n",AST_FILE_IO::areFreepointersContainingGlobalIndices() ? "true" : "false");
     printf ("BEFORE resetValidAstAfterWriting(): globalProject = %p globalProject->get_freepointer() = %p \n",globalProject,globalProject->get_freepointer());
  // AST_FILE_IO :: resetValidAstAfterWriting();
     printf ("AFTER resetValidAstAfterWriting(): globalProject = %p globalProject->get_freepointer() = %p \n",globalProject,globalProject->get_freepointer());

  // Initialization for file I/O.
  // AST_FILE_IO::clearAllMemoryPools();
#endif

  // DQ (6/6/2010): New test that detects fundamental problem. The extention of the memory pools triggered by
  // reading in a second file causes the SgProject IR node from the reading of the first file to be set to
  // the next node to be used (the SgProject for the second file.  It is not reset when reading the 
  // second file's SgProject and so remains.  
  //    1) Why do we have to extend the memory pool? Wouldn't this happen naturally via the new operator?
  //       ANSWER: We need to compute the address of future IR nodes from the global index numbers. So
  //               they all need to be pre-allocated!!!
     ROSE_ASSERT(globalProject->get_freepointer() == AST_FileIO::IS_VALID_POINTER());

  // Custom test of AST (for problems that appears to be specific to writing out the merged AST).
  // testAST(globalProject);

#if 1
  // Output an optional graph of the AST (just the tree, when active). Note that we need to multiple file version 
  // of this with includes so that we can present a single SgProject rooted AST with multiple SgFile objects.
  // generateDOT ( *globalProject );
     printf ("\n\nGenerating a dot file of the AST (could be very large) \n");
     generateDOT_withIncludes ( *globalProject, "aggregatedAST.dot" );
     printf ("DONE: Generating a dot file of the AST \n");
#endif

#if 1
  // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
     const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
     generateAstGraph(globalProject,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
#endif

#if 1
  // DQ (2/26/2010): Output an example of the value of p_freepointer for debugging.
  // printf ("globalProject->get_freepointer()  = %p \n",globalProject->get_freepointer());
  // printf ("AST_FILE_IO::vectorOfASTs.size() = %zu \n",AST_FILE_IO::vectorOfASTs.size());
  // AST_FILE_IO::display("Before writing the merged AST (before resetValidAstAfterWriting())");
  // string mergedFileName = "mergedFile.C";

     string mergedFileName = outputFileName;
     printf ("mergedFileName = %s numberOfNodes() = %zu \n",(mergedFileName + ".binary").c_str(),numberOfNodes());

     printf ("Calling AST_FILE_IO::reset() \n");
     AST_FILE_IO::reset();

  // printf ("Calling AST_FILE_IO::resetValidAstAfterWriting() \n");
  // AST_FILE_IO::resetValidAstAfterWriting();
  // AST_FILE_IO::display("Before writing the merged AST");

  // Now write out the merged AST.
     printf ("Calling AST_FILE_IO::startUp()... \n");
     AST_FILE_IO::startUp(globalProject);

     printf ("Writing the AST to disk... \n");
     AST_FILE_IO::writeASTToFile ( mergedFileName + ".binary" );
#endif

  // printf ("Before processing via DOT: globalProject = %p numberOfFiles() = %d \n",globalProject,globalProject->numberOfFiles());

#if 0
  // Output an optional graph of the AST (just the tree, when active). Note that we need to multiple file version 
  // of this with includes so that we can present a single SgProject rooted AST with multiple SgFile objects.
  // generateDOT ( *globalProject );
     generateDOT_withIncludes ( *globalProject, "aggregatedAST.dot" );
#endif

#if 0
  // Output an optional graph of the AST (the whole graph, of bounded complexity, when active)
     const int MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH = 8000;
     generateAstGraph(globalProject,MAX_NUMBER_OF_IR_NODES_TO_GRAPH_FOR_WHOLE_GRAPH);
#endif

     printf ("Program Terminated Normally! \n");

     return 0;
   }