Esempio n. 1
0
scoplib_statement_p ScopLib::initializeStatement(ScopStmt *stmt) {
  scoplib_statement_p Stmt = scoplib_statement_malloc();

  // Domain & Schedule
  Stmt->domain = scoplib_matrix_list_malloc();
  Stmt->domain->elt = domainToMatrix(stmt->getDomain());
  Stmt->schedule = scatteringToMatrix(stmt->getScattering());

  // Statement name
  std::string entryName;
  raw_string_ostream OS(entryName);
  WriteAsOperand(OS, stmt->getBasicBlock(), false);
  entryName = OS.str();
  Stmt->body = (char*)malloc(sizeof(char) * (entryName.size() + 1));
  strcpy(Stmt->body, entryName.c_str());

  // Iterator names
  Stmt->nb_iterators = stmt->getNumIterators();
  Stmt->iterators = (char**) malloc(sizeof(char*) * Stmt->nb_iterators);

  for (int i = 0; i < Stmt->nb_iterators; ++i) {
    Stmt->iterators[i] = (char*) malloc(sizeof(char*) * 20);
    sprintf(Stmt->iterators[i], "i_%d", i);
  }

  // Memory Accesses
  Stmt->read = createAccessMatrix(stmt, true);
  Stmt->write = createAccessMatrix(stmt, false);

  return Stmt;
}
Esempio n. 2
0
/**
 * scoplib_scop_dup function:
 * This function returns a fresh identical (non shadow) copy of the
 * input scop.
 * \param scop   The scop whose information have to be printed.
 **
 */
scoplib_scop_p
scoplib_scop_dup(scoplib_scop_p scop)
{
  int i;
  scoplib_statement_p stm;
  scoplib_statement_p tmp = NULL;
  
  scoplib_symbol_p tmpsymbol = NULL;
  scoplib_symbol_p symbol;
  
  scoplib_scop_p ret = scoplib_scop_malloc();
  ret->context = scoplib_matrix_copy(scop->context);
  ret->nb_parameters = scop->nb_parameters;
  ret->parameters = (char**) malloc(sizeof(char*) * ret->nb_parameters);
  for (i = 0; i < ret->nb_parameters; ++i)
    ret->parameters[i] = strdup(scop->parameters[i]);
  ret->nb_arrays = scop->nb_arrays;
  ret->arrays = (char**) malloc(sizeof(char*) * ret->nb_arrays);
  for (i = 0; i < ret->nb_arrays; ++i)
    ret->arrays[i] = strdup(scop->arrays[i]);

  for (stm = scop->statement; stm; stm = stm->next)
    {
      scoplib_statement_p newstm = scoplib_statement_malloc();
      newstm->domain = scoplib_matrix_list_malloc();
      newstm->domain->elt = scoplib_matrix_copy(stm->domain->elt);
      newstm->schedule = scoplib_matrix_copy(stm->schedule);
      newstm->read = scoplib_matrix_copy(stm->read);
      newstm->write = scoplib_matrix_copy(stm->write);
      newstm->nb_iterators = stm->nb_iterators;
      newstm->iterators = (char**) malloc(sizeof(char*) * newstm->nb_iterators);
      for (i = 0; i < newstm->nb_iterators; ++i)
	newstm->iterators[i] = strdup(stm->iterators[i]);
      newstm->body = strdup (stm->body);
      if (ret->statement == NULL)
	ret->statement = tmp = newstm;
      else
	{
	  tmp->next = newstm;
	  tmp = tmp->next;
	}
    }
 
 for(symbol = scop->symbol_table;symbol;symbol = symbol->next) {
    
    scoplib_symbol_p newsymbol = scoplib_symbol_malloc();
    newsymbol->identifier = strdup(symbol->identifier);
    newsymbol->type       = symbol->type;
    
    if(ret->symbol_table == NULL )
      ret->symbol_table = tmpsymbol = newsymbol;
    else {
      tmpsymbol->next = newsymbol;
      tmpsymbol = tmpsymbol->next;
    } 
 }   
    
  if (scop->optiontags)
    ret->optiontags = strdup(scop->optiontags);
  ret->usr = scop->usr;

  return ret;
}