示例#1
0
文件: loop.c 项目: Ced/openscop
/**
 * osl_loop_clone_one function:
 * this function builds and returns a "hard copy" (not a pointer copy) of
 * "one" (and not the whole list) osl_loop_t data structure.
 *
 * \param[in] loop  The pointer to the loop structure to clone.
 * \return          A pointer to the clone of the loop structure.
 */
osl_loop_p osl_loop_clone_one(osl_loop_p loop) {
  size_t i;
  osl_loop_p clone;

  if (loop == NULL)
    return NULL;

  clone = osl_loop_malloc();
  OSL_strdup(clone->iter, loop->iter);
  clone->nb_stmts = loop->nb_stmts;
  OSL_malloc(clone->stmt_ids, int *, loop->nb_stmts * sizeof(int));

  for (i = 0; i < loop->nb_stmts; i++) {
    clone->stmt_ids[i] = loop->stmt_ids[i];
  }

  clone->directive = loop->directive;

  if(loop->private_vars != NULL)
    OSL_strdup(clone->private_vars, loop->private_vars);

  if(loop->user != NULL)
    OSL_strdup(clone->user, loop->user);

  return clone;
}
示例#2
0
/**
 * osl_scop_clone function:
 * This functions builds and returns a "hard copy" (not a pointer copy)
 * of a osl_statement_t data structure provided as parameter.
 * Note that the usr field is not touched by this function.
 * \param scop The pointer to the scop we want to clone.
 * \return A pointer to the full clone of the scop provided as parameter.
 */
osl_scop_p osl_scop_clone(osl_scop_p scop) {
    osl_scop_p clone = NULL, node, previous = NULL;
    int first = 1;

    while (scop != NULL) {
        node                 = osl_scop_malloc();
        node->version        = scop->version;
        if (scop->language != NULL)
            OSL_strdup(node->language, scop->language);
        node->context        = osl_relation_clone(scop->context);
        node->parameters     = osl_generic_clone(scop->parameters);
        node->statement      = osl_statement_clone(scop->statement);
        node->registry       = osl_interface_clone(scop->registry);
        node->extension      = osl_generic_clone(scop->extension);

        if (first) {
            first = 0;
            clone = node;
            previous = node;
        }
        else {
            previous->next = node;
            previous = previous->next;
        }

        scop = scop->next;
    }

    return clone;
}
示例#3
0
/**
 * osl_textual_clone function:
 * this function builds and returns a "hard copy" (not a pointer copy) of an
 * osl_textual_t data structure.
 * \param[in] textual The pointer to the textual structure we want to clone.
 * \return A pointer to the clone of the textual structure.
 */
osl_textual_p osl_textual_clone(osl_textual_p textual) {
  osl_textual_p clone;

  if (textual == NULL)
    return NULL;

  clone = osl_textual_malloc();
  OSL_strdup(clone->textual, textual->textual);

  return clone;
}
示例#4
0
文件: strings.c 项目: Syllo/openscop
/**
 * osl_strings_sread function:
 * this function reads a strings structure from a string complying to the
 * OpenScop textual format and returns a pointer to this strings structure.
 * The input string should only contain the list of strings this function
 * has to read (comments at the end of the line are accepted). The input
 * parameter is updated to the position in the input string this function
 * reach right after reading the strings structure.
 * \param[in,out] input The input string where to find a strings structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the strings structure that has been read.
 */
osl_strings_p osl_strings_sread(char ** input) {
  char tmp[OSL_MAX_STRING];
  char * s;
  char ** string = NULL;
  int nb_strings;
  int i, count;
  osl_strings_p strings = NULL;

  // Skip blank/commented lines and spaces before the strings.
  osl_util_sskip_blank_and_comments(input);
  
  // Count the actual number of strings.
  nb_strings = 0;
  s = *input;
  while (1) {
    for (count = 0; *s && !isspace(*s) && *s != '#'; count++)
      s++;
    
    if (count != 0)
      nb_strings++;

    if ((!*s) || (*s == '#') || (*s == '\n'))
      break;
    else
      s++;
  }

  if (nb_strings > 0) {
    // Allocate the array of strings. Make it NULL-terminated.
    OSL_malloc(string, char **, sizeof(char *) * (nb_strings + 1));
    string[nb_strings] = NULL;

    // Read the desired number of strings.
    s = *input;
    for (i = 0; i < nb_strings; i++) {
      for (count = 0; *s && !isspace(*s) && *s != '#'; count++)
	tmp[count] = *(s++);
      tmp[count] = '\0';
      OSL_strdup(string[i], tmp);
      if (*s != '#')
	s++;
    }

    // Update the input pointer to the end of the strings structure.
    *input = s;

    // Build the strings structure
    strings = osl_strings_malloc();
    free(strings->string);
    strings->string = string;
  }
示例#5
0
/**
 * osl_body_interface function:
 * this function creates an interface structure corresponding to the body
 * structure and returns it).
 * \return An interface structure for the body structure.
 */
osl_interface_p osl_body_interface() {
  osl_interface_p interface = osl_interface_malloc();
  
  OSL_strdup(interface->URI, OSL_URI_BODY);
  interface->idump  = (osl_idump_f)osl_body_idump;
  interface->sprint = (osl_sprint_f)osl_body_sprint;
  interface->sread  = (osl_sread_f)osl_body_sread;
  interface->malloc = (osl_malloc_f)osl_body_malloc;
  interface->free   = (osl_free_f)osl_body_free;
  interface->clone  = (osl_clone_f)osl_body_clone;
  interface->equal  = (osl_equal_f)osl_body_equal;

  return interface;
}
示例#6
0
文件: loop.c 项目: Ced/openscop
/**
 * osl_loop_interface function:
 * this function creates an interface structure corresponding to the loop
 * extension and returns it.
 *
 * \return  An interface structure for the loop extension.
 */
osl_interface_p osl_loop_interface(void) {
  osl_interface_p interface = osl_interface_malloc();
  
  OSL_strdup(interface->URI, OSL_URI_LOOP);
  interface->idump  = (osl_idump_f)osl_loop_idump;
  interface->sprint = (osl_sprint_f)osl_loop_sprint;
  interface->sread  = (osl_sread_f)osl_loop_sread;
  interface->malloc = (osl_malloc_f)osl_loop_malloc;
  interface->free   = (osl_free_f)osl_loop_free;
  interface->clone  = (osl_clone_f)osl_loop_clone;
  interface->equal  = (osl_equal_f)osl_loop_equal;

  return interface;
}
示例#7
0
/**
 * osl_textual_sread function:
 * this function reads a textual structure from a string complying to the
 * OpenScop textual format and returns a pointer to this textual structure.
 * The string should contain only one textual format of a textual structure.
 * \param[in,out] extensions The input string where to find a textual struct.
 *                           Updated to the position after what has been read.
 * \return A pointer to the textual structure that has been read.
 */
osl_textual_p osl_textual_sread(char ** extensions) {
  osl_textual_p textual = NULL;

  if (*extensions != NULL) {
    textual = osl_textual_malloc();
    OSL_strdup(textual->textual, *extensions);
    
    // Update the input string pointer to the end of the string (since
    // everything has been read).
    *extensions = *extensions + strlen(*extensions);
  }

  return textual;
}
示例#8
0
/**
 * osl_scatnames_interface function:
 * this function creates an interface structure corresponding to the scatnames
 * extension and returns it).
 * \return An interface structure for the scatnames extension.
 */
osl_interface_p osl_scatnames_interface() {
  osl_interface_p interface = osl_interface_malloc();
  
  OSL_strdup(interface->URI, OSL_URI_SCATNAMES);
  interface->idump  = (osl_idump_f)osl_scatnames_idump;
  interface->sprint = (osl_sprint_f)osl_scatnames_sprint;
  interface->sread  = (osl_sread_f)osl_scatnames_sread;
  interface->malloc = (osl_malloc_f)osl_scatnames_malloc;
  interface->free   = (osl_free_f)osl_scatnames_free;
  interface->clone  = (osl_clone_f)osl_scatnames_clone;
  interface->equal  = (osl_equal_f)osl_scatnames_equal;

  return interface;
}
示例#9
0
/**
 * osl_textual_idump function:
 * this function displays an osl_textual_t structure (*textual) 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] textual The textual structure to be printed.
 * \param[in] level   Number of spaces before printing, for each line.
 */
void osl_textual_idump(FILE * file, osl_textual_p textual, int level) {
  int j;
  char * tmp;

  // Go to the right level.
  for (j = 0; j < level; j++)
    fprintf(file, "|\t");

  if (textual != NULL) {
    fprintf(file, "+-- osl_textual_t: ");
    
    // Display the textual message (without any carriage return).
    OSL_strdup(tmp, textual->textual);
    for (j = 0; j < (int)strlen(tmp); j++)
      if (tmp[j] == '\n')
	tmp[j] = ' ';

    if (strlen(tmp) > 40) {
      for (j = 0; j < 20; j++)
        fprintf(file, "%c", tmp[j]);
      fprintf(file, "   ...   ");
      for (j = (int)strlen(tmp) - 20; j < (int)strlen(tmp); j++)
        fprintf(file, "%c", tmp[j]);
      fprintf(file, "\n");
    }
    else {
      fprintf(file,"%s\n", tmp);
    }
    free(tmp);
  }
  else {
    fprintf(file, "+-- NULL textual\n");
  }

  // The last line.
  for (j = 0; j <= level; j++)
    fprintf(file, "|\t");
  fprintf(file, "\n");
}
示例#10
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, NULL, OSL_URI_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) {
            OSL_strdup(scop->language, 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;
}