Beispiel #1
0
/**
 * osl_strings_sprint function:
 * this function prints the content of an osl_strings_t structure
 * (*strings) into a string (returned) in the OpenScop textual format.
 * \param[in] strings The strings structure which has to be printed.
 * \return A string containing the OpenScop dump of the strings structure.
 */
char * osl_strings_sprint(osl_strings_p strings) {
  size_t i;
  int high_water_mark = OSL_MAX_STRING;
  char * string = NULL;
  char buffer[OSL_MAX_STRING];

  OSL_malloc(string, char *, high_water_mark * sizeof(char));
  string[0] = '\0';
   
  if (strings != NULL) {
    for (i = 0; i < osl_strings_size(strings); i++) {
      sprintf(buffer, "%s", strings->string[i]);
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
      if (i < osl_strings_size(strings) - 1)
        osl_util_safe_strcat(&string, " ", &high_water_mark);
    }
    sprintf(buffer, "\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
  }
  else {
    sprintf(buffer, "# NULL strings\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
  }

  return string;
}
Beispiel #2
0
/**
 * @brief Fusion two osl_body into a third one.
 * The two osl_body must have the same iterators or the program will fail.
 *
 * @param body1 The first osl_body.
 * @param body2 The second osl_body.
 *
 * @return An osl_body with the same iteratar as the parameters, but with
 * their "code" fusionned.
 */
struct osl_body * substrate_osl_body_fusion(
        struct osl_body * body1,
        struct osl_body * body2)
{
    struct osl_body * res = NULL;
    size_t body1_size = 0, body2_size = 0;

    body1_size = osl_strings_size(body1->iterators);
    body2_size = osl_strings_size(body2->iterators);

    res = osl_body_malloc();
    if((osl_strings_equal(body1->iterators, body2->iterators)) || (body1_size==0) || (body2_size==0))
    {
        res->iterators = osl_strings_clone(body1->iterators);
        substrate_osl_strings_concat(
                &res->expression,
                body1->expression,
                body2->expression);
    }
    else
    {
        //TODO Maybe fuse when iterators don't match ? (I'm not really sure).
        OSL_error("Can't fusion body");
    }

    return res;
}
Beispiel #3
0
/**
 * osl_body_print_scoplib function:
 * this function prints the content of an osl_body_t structure
 * (*body) into a file (file, possibly stdout) in the SCoPLib format.
 * \param[in] file  File where informations are printed.
 * \param[in] body  The body whose information has to be printed.
 */
void osl_body_print_scoplib(FILE * file, osl_body_p body) {
  int nb_iterators;

  if (body != NULL) {
    nb_iterators = osl_strings_size(body->iterators);

    if (nb_iterators > 0) {
      fprintf(file, "# List of original iterators\n");
      osl_strings_print(file, body->iterators);
    } else {
      fprintf(file, "fakeiter\n");
    }

    fprintf(file, "# Statement body expression\n");
    osl_strings_print(file, body->expression);
  }
  else {
    fprintf(file, "# NULL statement body\n");
  }
}
Beispiel #4
0
/**
 * osl_strings_idump function:
 * this function displays an array of strings into a file (file, possibly
 * stdout) in a way that trends to be understandable. It includes an
 * indentation level (level) in order to work with others
 * idump functions.
 * \param[in] file    The file where the information has to be printed.
 * \param[in] strings The array of strings that has to be printed.
 * \param[in] level   Number of spaces before printing, for each line.
 */
void osl_strings_idump(FILE * file, osl_strings_p strings, int level) {
  int i, nb_strings;
  
  for (i = 0; i < level; i++)
    fprintf(file, "|\t");
  
  if (strings != NULL) {
    nb_strings = osl_strings_size(strings);
    fprintf(file, "+-- osl_strings_t:");
    for (i = 0; i < nb_strings; i++)
      fprintf(file, " %s", strings->string[i]);
    fprintf(file, "\n");
  }
  else
    fprintf(file, "+-- NULL strings\n");

  // A blank line.
  for (i = 0; i <= level; i++)
    fprintf(file, "|\t");
  fprintf(file, "\n");
}
Beispiel #5
0
/**
 * osl_body_sprint function:
 * this function prints the content of an osl_body_t structure
 * (*body) into a string (returned) in the OpenScop textual format.
 * \param[in] body The body structure which has to be printed.
 * \return A string containing the OpenScop dump of the body structure.
 */
char * osl_body_sprint(osl_body_p body) {
  int nb_iterators;
  int high_water_mark = OSL_MAX_STRING;
  char * string = NULL;
  char buffer[OSL_MAX_STRING];
  char * iterators, * expression;

  OSL_malloc(string, char *, high_water_mark * sizeof(char));
  string[0] = '\0';
  
  if (body != NULL) {
    nb_iterators = osl_strings_size(body->iterators);
    sprintf(buffer, "# Number of original iterators\n%d\n", nb_iterators);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    if (nb_iterators > 0) {
      sprintf(buffer, "# List of original iterators\n");
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
      iterators = osl_strings_sprint(body->iterators);
      osl_util_safe_strcat(&string, iterators, &high_water_mark);
      free(iterators);
    }

    sprintf(buffer, "# Statement body expression\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
    expression = osl_strings_sprint(body->expression);
    osl_util_safe_strcat(&string, expression, &high_water_mark);
    free(expression);
  }
  else {
    sprintf(buffer, "# NULL body\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
  }

  return string;
}
Beispiel #6
0
/**
 * osl_scop_pread function ("precision read"):
 * this function reads a list of scop structures from a file (possibly stdin)
 * complying to the OpenScop textual format and returns a pointer to this
 * scop list. If some relation properties (number of input/output/local
 * dimensions and number of parameters) are undefined, it will define them
 * according to the available information. 
 * \param[in] file      The file where the scop has to be read.
 * \param[in] registry  The list of known interfaces (others are ignored).
 * \param[in] precision The precision of the relation elements.
 * \return A pointer to the scop structure that has been read.
 */
osl_scop_p osl_scop_pread(FILE * file, osl_interface_p registry,
                          int precision) {
  osl_scop_p list = NULL, current = NULL, scop;
  osl_statement_p stmt = NULL;
  osl_statement_p prev = NULL;
  osl_strings_p language;
  int nb_statements;
  char * tmp;
  int first = 1;
  int i;

  if (file == NULL)
    return NULL;

  while(1) {
    //
    // I. START TAG
    //
    tmp = osl_util_read_uptotag(file, OSL_TAG_START_SCOP);
    if (tmp == NULL) {
      OSL_debug("no more scop in the file");
      break;
    }
    else {
      free(tmp);
    }

    scop = osl_scop_malloc();
    scop->registry = osl_interface_clone(registry);

    //
    // II. CONTEXT PART
    //

    // Read the language.
    language = osl_strings_read(file);
    if (osl_strings_size(language) == 0)
      OSL_error("no language (backend) specified");

    if (osl_strings_size(language) > 1)
      OSL_warning("uninterpreted information (after language)");

    if (language != NULL) {
      scop->language = strdup(language->string[0]);
      osl_strings_free(language);
    }

    // Read the context domain.
    scop->context = osl_relation_pread(file, precision);

    // Read the parameters.
    if (osl_util_read_int(file, NULL) > 0)
      scop->parameters = osl_generic_read_one(file, scop->registry);

    //
    // III. STATEMENT PART
    //

    // Read the number of statements.
    nb_statements = osl_util_read_int(file, NULL);

    for (i = 0; i < nb_statements; i++) {
      // Read each statement.
      stmt = osl_statement_pread(file, scop->registry, precision);
      if (scop->statement == NULL)
        scop->statement = stmt;
      else
        prev->next = stmt;
      prev = stmt;
    }

    //
    // IV. EXTENSION PART (TO THE END TAG)
    //

    // Read up the end tag (if any), and store extensions.
    scop->extension = osl_generic_read(file, scop->registry);

    // Add the new scop to the list.
    if (first) {
      list = scop;
      first = 0;
    }
    else {
      current->next = scop;
    }
    current = scop;    
  }
  
  if (!osl_scop_integrity_check(list))
    OSL_warning("scop integrity check failed");

  return list;
}