Пример #1
0
// This function is not used, but is useful for 
// generating the list of all global variables
Rose_STL_Container<SgInitializedName*>
buildListOfGlobalVariables ( SgProject* project )
   {
  // This function builds a list of global variables (from a SgProject).

     Rose_STL_Container<SgInitializedName*> globalVariableList;

     const SgFilePtrList& fileList = project->get_fileList();
     SgFilePtrList::const_iterator file = fileList.begin();

  // Loop over the files in the project (multiple files exist 
  // when multiple source files are placed on the command line).
     while(file != fileList.end())
        {
          Rose_STL_Container<SgInitializedName*> fileGlobalVariableList = buildListOfGlobalVariables(isSgSourceFile(*file));

       // DQ (9/26/2007): Moved from std::list to std::vector
       // globalVariableList.merge(fileGlobalVariableList);
          globalVariableList.insert(globalVariableList.begin(),fileGlobalVariableList.begin(),fileGlobalVariableList.end());

          file++;
        }

     return globalVariableList;
   }
Пример #2
0
void
instantiateTemplates ( SgProject* project )
   {
  // DQ (7/12/2005): Introduce tracking of performance of ROSE.
     TimingPerformance timer ("AST Object Code Generation (instantiateTemplates): time (sec) = ");

  // DQ (9/6/2005): I think these operations have been superseded
  // by the AST post processing mechanism which is more complete.
     printf ("In instantiateTemplates(): I think this may be dead code! \n");
     ROSE_ASSERT(false);

  // After compilation we can start the process of template instantiation
  //    1) Compiling to object files (building *.ti files)
  //         a) build *.ti files (call instantiateTemplates() function)
  //    2) Linking
  //         a) call prelink utility
  //              * builds instantiation information (*.ii files)
  //              * calls compilation step to force instantiation (using info in *.ii files)
  //              * calls prelink utility iteratively
  //         b) call g++ to do final linking with all templates resolved

     ROSE_ASSERT (project != NULL);
  // printf ("In instantiateTemplates(project = %p) \n",project);

#if 1
  // ***********************
  // Calling prelink utility
  // ***********************
  // printf ("Calling prelink utility ... \n");

     Rose_STL_Container<string> sourceFilenameList = project->get_sourceFileNameList();

     ROSE_ASSERT (sourceFilenameList.size() <= 1);
     if ( project->get_prelink() == false )
        {
          Rose_STL_Container<string> objectFilenameList = project->get_objectFileNameList();

          string prelinkOptions = "-v -d9 -i ";
          string objectFiles;
          Rose_STL_Container<string> argList;
          if ( (sourceFilenameList.size() == 1) && (objectFilenameList.size() == 0) )
             {
               printf ("Handling (debugging) single file case of template instantiation \n");

               Rose_STL_Container<string>::iterator fileIndex = sourceFilenameList.begin();
               ROSE_ASSERT (sourceFilenameList.size() == 1);
               string filenameWithPath = *fileIndex;
               string filename         = Rose::utility_stripPathFromFileName(filenameWithPath.c_str());

               int filenameLength = filename.length();
               printf ("In instantiateTemplates(): filename = %s \n",filename.c_str());

            // This would not handle a foo.cpp file name (with ".cpp" as a suffix), I think
               string nameWithoutSuffix = filename.substr(0,filenameLength-2);
#if 0
               objectFiles = nameWithoutSuffix + ".o";
#else
            // Make the prelink phase operate on a rose_<file name>.o file and fix 
            // the object file name generated by the vendor compiler (to generate 
            // the same file name).
               objectFiles = string("rose_") + nameWithoutSuffix + ".o";
#endif
               printf ("In instantiateTemplates(): objectFiles = %s \n",objectFiles.c_str());

            // DQ (9/25/2007): This is the first element to be put into the list, so we can use push_back() inplace of push_front().
            // argList.push_front(objectFiles);
               argList.push_back(objectFiles);
             }
            else
             {
            // linking only (this processing is different than that of a single file)
            // Debug the single file case before addressing multiple files required 
            // for link only processing.

               printf ("Linking only, template instantiation stil being debugged (similar to single file case) \n");
            // ROSE_ASSERT (false);

               objectFiles = CommandlineProcessing::generateStringFromArgList(project->get_objectFileNameList());
               argList = project->get_objectFileNameList();
             }

       // DQ (1/13/2005):
       // We could check to make sure there are valid *.ti (template instantiation files) associated with the objectFiles
       // if not then calling "edg_prelink" will cause an error.  But it is not required!  It is not an error for edg_prelink
       // to not find a corresponding *.ti file for each object file!
       // printf ("Check for corresponding template instantiation files: objectFiles = %s \n",objectFiles.c_str());

       // Build the command line to execute the edg_prelink utility 
       // (user's path must include location of edg_prelink utility).
          string prelinkCommandLine = "edg_prelink " + prelinkOptions + objectFiles;

#if 0
          printf ("\n\n");
          printf ("######################################### \n");
          printf ("######################################### \n");
          printf ("######################################### \n");
          printf ("prelinkCommandLine = %s \n",prelinkCommandLine.c_str());
          printf ("######################################### \n");
          printf ("######################################### \n");
          printf ("######################################### \n");
          printf ("\n\n");

          printf ("Print out rose_test2005_74.C (before prelink) \n");
          system("cat /home/dquinlan2/ROSE/LINUX-3.3.2/developersScratchSpace/Dan/rose_test2005_74.C");
#endif

          int argc    = 0;
          char** argv = NULL;

       // Add the commandline parameters as separate strings (in reverse order)
       // argList.push_front(" -i ");
       // argList.push_front(" -d9 ");
       // argList.push_front(" -a 0 ");

       // DQ (9/25/2007): Move from std::list to std::vector.
       // argList.push_front(" -v ");
          argList.insert(argList.begin()," -v ");

       // Separate list out into form traditional argc and argv form parameters
          CommandlineProcessing::generateArgcArgvFromList (argList,argc,argv);

          printf ("Calling generateArgcArgvFromList: argc = %d compressed argList = %s \n",
               argc,CommandlineProcessing::generateStringFromArgList(argList).c_str());

       // Declaration of prelink_main() function
          int prelink_main(int argc, char *argv[]);

          printf ("############### Before call to prelink_main ... ################ \n");

       // Use original interface (from when it was a command line utility!
          prelink_main(argc,argv);

          printf ("############### After call to prelink_main ... ################ \n");
       // ROSE_ASSERT(false);
        }
       else
        {
       // printf ("############### Prelink option specified (exited compilation!) ################ \n");
        }

  // printf ("Print out rose_test2004_18.C (after prelink) \n");
  // system("cat /home/dquinlan2/ROSE/LINUX-3.3.2/dqDevelopmentDirectory/rose_test2004_18.C");

#else
     printf ("Skipping calls to iterative prelink utility ... \n");
#endif

#if 0
     printf ("Exiting after handling newly instantiated code! \n");
     ROSE_ASSERT (false);
#endif
   }