Exemple #1
0
SgName
mangleFunctionName (const SgName& n, const SgName& ret_type_name )
  {
    string s_mangled = mangleFunctionNameToString (n.getString (),
                                                   ret_type_name.str ());
    SgName n_mangled (s_mangled.c_str ());
    return n_mangled;
  }
SgName
mangleTemplate (const SgName& templ_name,
                const SgTemplateArgumentPtrList& templ_args,
                const SgScopeStatement* scope)
   {
     string mangled_name = mangleTemplateToString(templ_name.getString(),templ_args,scope);
  // printf ("In mangleTemplate(): mangled_name = %s \n",mangled_name.c_str());
     return SgName (mangled_name.c_str());
   }
Exemple #3
0
ScopExtractor::ScopExtractor(SgProject* project, PolyRoseOptions& polyopts)
{
  //   this->project = project;
  this->polyoptions = polyopts;
  isVerbose = ! polyopts.getQuiet();
  if (isVerbose)
    std::cout << "[PolyOpt] Using generic scop extractor" << std::endl;

  SgFilePtrList& file_list = project->get_fileList();
  SgFilePtrList::const_iterator file_iter;
  // Iterate on all files of the project.
  for (file_iter = file_list.begin(); file_iter != file_list.end(); file_iter++)
    {
      SgSourceFile* file = isSgSourceFile(*file_iter);
      if (polyoptions.getScVerboseLevel())
	cout << "[Extr] File: " << file->getFileName() << endl;
      SgNodePtrList funcDefnList =
	NodeQuery::querySubTree(file, V_SgFunctionDefinition);
      SgNodePtrList::const_iterator iter;
      // Iterate on all function defined in a file.
      for (iter = funcDefnList.begin(); iter != funcDefnList.end(); ++iter)
	{
	  SgFunctionDefinition *fun = isSgFunctionDefinition(*iter);
	  if (!fun)
	    {
	      cout << "[Extr] Warning: Expected SgFunctionDefinition in " <<
		file->getFileName() << endl;
	      continue; // with the next function definition
	    }
	  SgName name = fun->get_declaration()->get_name();
	  if (polyoptions.getScVerboseLevel())
	    cout << "[Extr] Function: " << name.getString() << endl;
	  SgBasicBlock* body = fun->get_body();

	  // Ensure the function is a candidate (no (unsafe) function
	  // calls).
	  if (assertFunctionIsCandidate(project, body))
	    {
	      // Proceed recursively, bottom up.
	      inspectBottomUpFunctionBody(project, body);
	    }
	}
    }
  if (isVerbose)
    std::cout << "[ScopExtraction] Generic: done" << std::endl;
}
Exemple #4
0
Fichier : DCL.C Projet : 8l/rose
/**
 * Do not reuse variable names in subscopes
 */
bool DCL01_C( const SgNode *node ) {
	const SgInitializedName *varInitName = isSgInitializedName(node);
	if (!varInitName)
		return false;
	const SgName varName = varInitName->get_name();
	const SgScopeStatement *varScope = varInitName->get_scope();
	assert(varScope);
	while(!isSgGlobal(varScope)) {
		varScope = varScope->get_scope();
		if(varScope->symbol_exists(varName)) {
			print_error(node, "DCL01-C", ("Do not reuse variable names in subscopes: " + varName.getString()).c_str(), true);
			return true;
		}
	}

	return false;
}
Exemple #5
0
/**
 * Create scops for a sub-tree.
 *
 */
void
ScopExtractor::extractScops(SgNode* root)
{
  if (isVerbose)
    std::cout << "[PolyOpt] Using generic scop extractor" << std::endl;

  SgNodePtrList funcDefnList =
    NodeQuery::querySubTree(root, V_SgFunctionDefinition);
  SgNodePtrList::const_iterator iter;
  // Iterate on all functions defined in a sub-tree.
  for (iter = funcDefnList.begin(); iter != funcDefnList.end(); ++iter)
    {
      SgFunctionDefinition *fun = isSgFunctionDefinition(*iter);
      if (!fun)
	{
	  cout << "[Extr] Warning: Expected SgFunctionDefinition" << endl;
	  continue; // with the next function definition
	}
      SgName name = fun->get_declaration()->get_name();
      if (polyoptions.getScVerboseLevel())
	cout << "[Extr] Function: " << name.getString() << endl;
      SgBasicBlock* body = fun->get_body();

      // Ensure the function is a candidate (no (unsafe) function
      // calls).
      if (assertFunctionIsCandidate(NULL, body))
	{
	  // Proceed recursively, bottom up.
	  inspectBottomUpFunctionBody(NULL, body);
	}
    }

  // If no function is defined in the subtree, simply process it
  // as-is.
  if (funcDefnList.size() == 0)
    if (assertFunctionIsCandidate(NULL, root))
      // Proceed recursively, bottom up.
      inspectBottomUpFunctionBody(NULL, root);

  if (isVerbose)
    std::cout << "[ScopExtraction] Generic: done" << std::endl;
}
SgName
joinMangledQualifiers (const SgName& base, const SgName& name)
   {
#if 0
  // DQ (8/25/2006): This is debugging code required to find a problem that 
  // results in a 480,000,000 character string used of a mangled name prefix 
  // within the boost_tests/test_boost_phoenix_v2.C
     printf ("base.getString ().size() = %ld name.getString ().size() = %ld \n",base.getString().size(),name.getString().size());

     const int MODERATE_SIZE = 1000;
     if (base.getString().size() > MODERATE_SIZE)
          printf ("base.getString() = %s \n",base.getString().c_str());

     const int MAX_SIZE = 10000;
     ROSE_ASSERT(base.getString().size() < MAX_SIZE);
     ROSE_ASSERT(name.getString().size() < MAX_SIZE);
#endif

     string mangled_name = joinMangledQualifiersToString (base.getString (),name.getString ());
     return SgName (mangled_name.c_str ());
   }
Exemple #7
0
void
Unparse_Java::unparseEnumType(SgEnumType* type, SgUnparse_Info& info)
   {
     SgEnumType* enum_type = isSgEnumType(type);
     ROSE_ASSERT(enum_type);

     if (info.isTypeSecondPart() == false)
        {
          SgEnumDeclaration *edecl = isSgEnumDeclaration(enum_type->get_declaration());
          SgClassDefinition *cdefn = NULL;
          SgNamespaceDefinitionStatement* namespaceDefn = NULL;

          ROSE_ASSERT(edecl != NULL);

       // Build reference to any possible enclosing scope represented by a SgClassDefinition or SgNamespaceDefinition
       // to be used check if name qualification is required.
          unp->u_exprStmt->initializeDeclarationsFromParent ( edecl, cdefn, namespaceDefn );

          if (info.isTypeFirstPart() == true && info.SkipEnumDefinition() == false)
             {
               unp->u_exprStmt->unparseAttachedPreprocessingInfo(edecl, info, PreprocessingInfo::before);
             }

          curprint ( "enum ");

          SgNamedType *ptype = NULL;
          if (cdefn != NULL)
             {
               ptype = isSgNamedType(cdefn->get_declaration()->get_type());
             }

          if (SageInterface::is_C_language() == true || SageInterface::is_C99_language() == true)
             {
               curprint ( enum_type->get_name().getString() + " ");
             }
            else
             {
            // DQ (7/20/2011): Test compilation without the generateNameQualifier() functions.
            // The C++ support is more complex and can require qualified names!
            // SgName nameQualifier = unp->u_name->generateNameQualifier( edecl , info );
               SgName nameQualifier;

            // printf ("nameQualifier (from unp->u_name->generateNameQualifier function) = %s \n",nameQualifier.str());
            // curprint ( "\n/* nameQualifier (from unp->u_name->generateNameQualifier function) = " + nameQualifier + " */ \n ";
               curprint ( nameQualifier.str());
               SgName nm = enum_type->get_name();

               if (nm.getString() != "")
                  {
                 // printf ("Output qualifier of current types to the name = %s \n",nm.str());
                    curprint ( nm.getString() + " ");
                  }
             }
        }

     if (info.isTypeFirstPart() == true)
        {
      // info.display("info before constructing ninfo");
         SgUnparse_Info ninfo(info);

      // don't skip the semicolon in the output of the statement in the class definition
         ninfo.unset_SkipSemiColon();

         ninfo.set_isUnsetAccess();

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

         if ( info.SkipEnumDefinition() == false)
            {
              SgUnparse_Info ninfo(info);
              ninfo.set_inEnumDecl();
              SgInitializer *tmp_init = NULL;
              SgName tmp_name;

              SgEnumDeclaration *enum_stmt = isSgEnumDeclaration(enum_type->get_declaration());
              ROSE_ASSERT(enum_stmt != NULL);

           // This permits support of the empty enum case! "enum x{};"
              curprint ( "{");

              SgInitializedNamePtrList::iterator p = enum_stmt->get_enumerators().begin();
              if (p != enum_stmt->get_enumerators().end())
                 {
                // curprint ( "{";
                   while (1)
                      {
                        unp->u_exprStmt->unparseAttachedPreprocessingInfo(*p, info, PreprocessingInfo::before);
                        tmp_name=(*p)->get_name();
                        tmp_init=(*p)->get_initializer();
                        curprint ( tmp_name.str());
                        if(tmp_init)
                           {
                             curprint ( "=");
                             unp->u_exprStmt->unparseExpression(tmp_init, ninfo);
                           }
                        p++;
                        if (p != enum_stmt->get_enumerators().end())
                           {
                             curprint ( ",");
                           }
                          else
                             break;
                       }
                 // curprint ( "}";
                  }

            // Putting the "inside" info right here is just a wild guess as to where it might really belong.
               unp->u_exprStmt->unparseAttachedPreprocessingInfo(enum_stmt, info, PreprocessingInfo::inside);

               curprint ( "}");

               unp->u_exprStmt->unparseAttachedPreprocessingInfo(enum_stmt, info, PreprocessingInfo::after);
             }
        }
   }
Exemple #8
0
/*
 * returns string of functions name 
 */
string MigrationOutliner::getFunctionName(SgFunctionDeclaration *func){
        const SgName name = func->get_name();
        return name.getString();
}//end getFunctionName
Exemple #9
0
std::string initializeVariable(SgInitializedName* initName) {
	//if array type we need to get the index expression
	std::string index_expression_string;
	std::stringstream nameStringStream;
	SgName initNameName = initName->get_qualified_name();
	SgSymbol* initNameSym = initName->search_for_symbol_from_symbol_table();
	if (variablesOfNameX.find(initNameName.getString()) == variablesOfNameX.end()) {
		nameStringStream << initNameName.getString() << "_0";
		variablesOfNameX[initNameName.getString()] = 1;
	}
	else {
		int occurrence = variablesOfNameX[initNameName.getString()];
		nameStringStream << initNameName.getString() << "_" << occurrence;
		variablesOfNameX[initNameName.getString()] = occurrence+1;
	}
	SymbolToZ3[initNameSym] = nameStringStream.str();
	SymbolToInstances[initNameSym] = 0;
	SgType* initNameType = initName->get_type();
	std::string typeZ3;
	if (initNameType->isIntegerType()) {
		typeZ3 = "Int";
	}
	else if (initNameType->isFloatType()) {
		typeZ3 = "Real";
	}
	else if (isSgArrayType(initNameType)) {
		SgArrayType* arrTyp = isSgArrayType(initNameType);
		ROSE_ASSERT(arrTyp != NULL);
		SgType* underlying_type = arrTyp->get_base_type();
		std::string array_typeZ3;
		if (underlying_type->isIntegerType()) {
			array_typeZ3 = "Int";
		}
		else if (underlying_type->isFloatType()) {
			array_typeZ3 = "Real";
		}
		else {
			std::cout << "unknown underlying type of array!" << std::endl;
			std::cout << underlying_type->class_name() << std::endl;
			ROSE_ASSERT(false);
		}
		SgExpression* ind = arrTyp->get_index();
		std::stringstream arrStr;
		index_expression_string = getSgExpressionString(ind);
		typeZ3 = "(Array Int " + array_typeZ3 + ")";
	}
	else if (isSgClassType(initNameType)) {
		
		std::cout << "structs are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgPointerType(initNameType)) {
		std::cout << "pointers are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgEnumType(initNameType)) {
		SgEnumType* et = isSgEnumType(initNameType);
		SgEnumDeclaration* enum_d = isSgEnumDeclaration(et->getAssociatedDeclaration());
		getSgDeclarationStatement(enum_d);	
		typeZ3 = et->get_name().getString(); 
	}
	else {
		std::cout << "unknown type: " << initNameType->class_name() << std::endl;
		ROSE_ASSERT(false);
	}		
	std::string name = nameStringStream.str() + "_0";
	std::stringstream streamZ3;
	if (isSgArrayType(initNameType)) {
	streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	streamZ3 << "\n(declare-fun " << name << "_len () Int)";
	streamZ3 << "\n(assert (= " << name << "_len " << index_expression_string << "))"; 	
	#ifdef ARRAY_TEST
	std::cout << "arrStream: " << streamZ3.str() << std::endl;
	#endif

	}
	else if (isSgEnumType(initNameType)) {
		streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	}
	else {
	streamZ3 << "(declare-fun " << name << " () " << typeZ3 << ")";
	}
	return streamZ3.str();
}