void RemoveUnsupportedStatements::do_procedure_definition(ProcedureDefinition* p)
{
  procDef = p ;
  assert(procDef != NULL) ;

  OutputInformation("Remove Unsupported statements begins") ;

  CForStatement* innermost = InnermostLoop(procDef) ;
  if (innermost == NULL)
  {
    OutputInformation("Remove Unsupported statements ends") ;
    return ;
  }

  StatementList* parentList = 
    dynamic_cast<StatementList*>(innermost->get_parent()) ;
  CForStatement* outerLoops = 
    dynamic_cast<CForStatement*>(innermost->get_parent()) ;
  CForStatement* outermostLoop = innermost ;
  while (parentList == NULL && outerLoops != NULL)
  {
    parentList = dynamic_cast<StatementList*>(outerLoops->get_parent()) ;
    outermostLoop = outerLoops ;
    outerLoops = dynamic_cast<CForStatement*>(outerLoops->get_parent()) ;
  }
  assert(parentList != NULL) ;
  assert(outermostLoop != NULL) ;

  int position = DeterminePosition(parentList, outermostLoop) ;
  assert(position >= 0) ;
  
  for (int i = 0 ; i < position ; ++i)
  {
    StatementList* blankList = create_statement_list(theEnv) ;
    Statement* toReplace = parentList->get_statement(i) ;
    parentList->replace(toReplace, blankList) ;
    // Will this delete kill me?
    //delete toReplace ;
  }
  
  for (int i = position + 1 ; i < parentList->get_statement_count() ; ++i)
  {
    StatementList* blankList = create_statement_list(theEnv) ;
    Statement* toReplace = parentList->get_statement(i) ;
    parentList->replace(toReplace, blankList) ;
    // Will this delete kill me?... yep!  or not...
    //delete toReplace ;
  }
  
  OutputInformation("Remove Unsupported statments ends") ;
}
Esempio n. 2
0
//------------------------------------------------------------------------------
int ClimateFile::GetColumnData(char* FileName,char* FieldName,double* vect,int* cant)
{
  int pos=DeterminePosition(FileName,FieldName);
  if(pos==0)
  {
    return -2;
  }
  FILE *pFile=0;
  pFile = fopen (FileName,"r");
  if (pFile==0)
  {
     fclose(pFile);
     return -1; // problema al abrir el archivo
  }
  fclose(pFile);
  ifstream in(FileName);
  string linea;
  vector<string> v;
  string buffer;
  char* pEnd=0;
  int i,j=0,ContCol=0;
  getline(in,linea,'\n');
  int cantidad=0;
  for(i=1;!in.eof();i++)
  {
      getline(in,linea,'\n');
      stringstream aStream;
      aStream << linea;
      ContCol=0;
      vect[i-1]=0.0;
      while(!aStream.eof())
      {
         ContCol++;
         j++;
         buffer="";
         aStream >> buffer;
         v.push_back(buffer);
         if(ContCol==pos)
         {
           vect[i-1]=strtod(v[j-1].c_str(),&pEnd);
           cantidad++;
         }
      }
  }
  in.close();
  *cant=cantidad;
  return 0;
}
void CombineSummationPass::do_procedure_definition(ProcedureDefinition* p)
{
  procDef = p ;
  assert(procDef != NULL) ;

  OutputInformation("Combine summation pass begins") ;

  StatementList* innermost = InnermostList(procDef) ;
  assert(innermost != NULL) ;

  bool change = false ;
  do
  {
    // Find the first summation
    StoreVariableStatement* firstStatement = NULL ;
    StoreVariableStatement* secondStatement = NULL ;
    change = false ;
    int i ;
    int firstStatementPosition = -1 ;
    i = 0 ;
    while (i < innermost->get_statement_count())
    {
      StoreVariableStatement* currentStoreVariable =
	dynamic_cast<StoreVariableStatement*>(innermost->get_statement(i)) ;
      if (currentStoreVariable != NULL && IsSummation(currentStoreVariable))
      {
	firstStatement = currentStoreVariable ;
	firstStatementPosition = i ;
	break ;
      }
	++i ;
    }
    
    if (firstStatement != NULL)
    {
      VariableSymbol* firstDest = firstStatement->get_destination() ;
      for (int j = i+1 ; j < innermost->get_statement_count() ; ++j)
      {
	StoreVariableStatement* nextStoreVar = 
	  dynamic_cast<StoreVariableStatement*>(innermost->get_statement(j));
	if (nextStoreVar != NULL && IsSummation(nextStoreVar, firstDest))
	{
	  secondStatement = nextStoreVar ;
	  break ;
	}
	if (IsDefinition(innermost->get_statement(j), firstDest) ||
	    HasUses(innermost->get_statement(j), firstDest))
	{
	  break ;
	}						
      }
    }
    if (secondStatement != NULL)
    {
      // Go through each of the variables used in the first statement and
      //  make sure there are no definitions to any of them.
      //  I only have to worry about variables and not array accesses because
      //  we don't allow them to read and write to array values.
      int originalPosition = DeterminePosition(innermost, firstStatement) ;
      assert(originalPosition >= 0) ;
      list<VariableSymbol*> usedVars = 
	AllUsedVariablesBut(firstStatement, firstStatement->get_destination());
      bool goodPath = true ;
      for (int j = originalPosition ; 
	   j < innermost->get_statement_count() && 
	     innermost->get_statement(j) != secondStatement ; 
	   ++j)
      {
	list<VariableSymbol*>::iterator usedIter = usedVars.begin() ;
	while (usedIter != usedVars.end())
	{
	  if (IsOutputVariable((*usedIter), innermost->get_statement(j)))
	  {
	    goodPath = false ;
	    break ;
	  }
	  ++usedIter ;
	}
	if (!goodPath) 
	{
	  break ;
	}
      }
      if (!goodPath)
      {
	continue ;
      }
      // Actually do the combining here
      change = true ;
      Expression* remains = RemoveValue(firstStatement) ;
      Expression* secondRemains = RemoveValue(secondStatement) ;
      // Create two binary expressions
      BinaryExpression* remainsSum = 
	create_binary_expression(theEnv,
				 remains->get_result_type(),
				 LString("add"),
				 remains,
				 secondRemains) ;
      LoadVariableExpression* loadDest = 
	create_load_variable_expression(theEnv,
	    secondStatement->get_destination()->get_type()->get_base_type(),
					secondStatement->get_destination()) ;
      BinaryExpression* finalSum =
	create_binary_expression(theEnv,
				 remainsSum->get_result_type(),
				 LString("add"),
				 remainsSum,
				 loadDest) ;

      secondStatement->set_value(finalSum) ;
      // Delete?
      innermost->remove_statement(firstStatementPosition) ;
    }
     
  } while (change == true) ;  

  OutputInformation("Combine summation pass ends") ;
}