Ejemplo n.º 1
0
Archivo: loop.c Proyecto: Ced/openscop
/**
 * osl_loop_sread function:
 * this function reads a loop structure from a string complying to the
 * OpenScop textual format and returns a pointer to this loop structure.
 * The input parameter is updated to the position in the input string this
 * function reaches right after reading the comment structure.
 *
 * \param[in,out] input   The input string where to find an loop structure.
 *                        Updated to the position after what has been read.
 * \return                A pointer to the loop structure that has been read.
 */
osl_loop_p osl_loop_sread(char **input) {
  size_t i;
  int nb_loops;
  osl_loop_p head;
  osl_loop_p loop;

  if (input == NULL) {
    OSL_debug("no loop optional tag");
    return NULL;
  }

  // Find the number of names provided.
  nb_loops = osl_util_read_int(NULL, input);
  if(nb_loops == 0)
    return NULL;

  // Allocate the array of id and names.
  head = loop = osl_loop_malloc();

  while (nb_loops != 0) {

    loop->iter = osl_util_read_string(NULL, input);
    loop->nb_stmts = (size_t)osl_util_read_int(NULL, input);
    
    OSL_malloc(loop->stmt_ids, int *, loop->nb_stmts * sizeof(int));
    for (i = 0; i < loop->nb_stmts; i++)
      loop->stmt_ids[i] = osl_util_read_int(NULL, input);
  
    loop->private_vars = osl_util_read_line(NULL, input);
    if (!strcmp(loop->private_vars, "(null)")) {
      free(loop->private_vars);
      loop->private_vars=NULL;
    }

    loop->directive = osl_util_read_int(NULL, input);

    // special case for OSL_LOOP_DIRECTIVE_USER
    if (loop->directive & OSL_LOOP_DIRECTIVE_USER) {
      loop->user = osl_util_read_line(NULL, input);
      if (!strcmp(loop->user, "(null)")) {
        free(loop->user);
        loop->user=NULL;
      }
    }

    nb_loops--;
    if (nb_loops != 0) {
      loop->next = osl_loop_malloc ();
      loop = loop->next;
    }
  }

  return head;
}
Ejemplo n.º 2
0
/**
 * osl_dependence_psread function
 * Retrieve a osl_dependence_p list from the option tag in the scop.
 */
osl_dependence_p osl_dependence_psread(char **input, int precision) {
  osl_dependence_p first = NULL;
  osl_dependence_p currdep = NULL;

  if (*input == NULL) {
    OSL_debug("no dependence optional tag");
    return NULL;
  }

  int i;
  /* Get the number of dependences. */
  int nbdeps = osl_util_read_int(NULL, input);

  /* For each of them, read 1 and shift of the read size. */
  for (i = 0; i < nbdeps; i++) {
    osl_dependence_p adep = osl_dependence_read_one_dep(input, precision);
    if (first == NULL) {
      currdep = first = adep;
    } else {
      currdep->next = adep;
      currdep = currdep->next;
    }
  }

  return first;
}
Ejemplo n.º 3
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body 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 body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0) {
      body->iterators = osl_strings_sread(input);
    }
    else {
      body->iterators = osl_strings_malloc();
      OSL_malloc(body->iterators->string, char **, sizeof(char *));
      body->iterators->string[0] = NULL;
    }

    // Read the body:
    expression = osl_util_read_line(NULL, input);

    // Insert the body.
    body->expression = osl_strings_encapsulate(expression);
  }

  return body;
}
Ejemplo n.º 4
0
/**
 * osl_dependence_read_one_dep function:
 * Read one dependence from a string.
 */
static
osl_dependence_p osl_dependence_read_one_dep(char **input, int precision) {
  osl_dependence_p dep = osl_dependence_malloc();
  char *buffer;
  
  /* Dependence type */
  buffer = osl_util_read_string(NULL, input);
  if (! strcmp(buffer, "RAW"))
    dep->type = OSL_DEPENDENCE_RAW;
  else if (! strcmp(buffer, "RAR"))
    dep->type = OSL_DEPENDENCE_RAR;
  else if (! strcmp(buffer, "WAR"))
    dep->type = OSL_DEPENDENCE_WAR;
  else if (! strcmp(buffer, "WAW"))
    dep->type = OSL_DEPENDENCE_WAW;
  else if (! strcmp(buffer, "RAW_SCALPRIV"))
    dep->type = OSL_DEPENDENCE_RAW_SCALPRIV;
  free(buffer);

  /* # From source statement xxx */
  dep->label_source = osl_util_read_int(NULL, input);
  
  /* # To target statement xxx */
  dep->label_target = osl_util_read_int(NULL, input);

  /* # Depth */
  dep->depth = osl_util_read_int(NULL, input);

  /* # From source access ref */  
  dep->ref_source = osl_util_read_int(NULL, input);
  
  /* # To target access ref */
  dep->ref_target = osl_util_read_int(NULL, input);
  
  /* Read the osl_relation */
  dep->domain = osl_relation_psread(input, precision);
  
  return dep;
}
Ejemplo n.º 5
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body 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 body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0)
      body->iterators = osl_strings_sread(input);

    // Read the body:
    // - Skip blank/commented lines and spaces before the body.
    osl_util_sskip_blank_and_comments(input);
      
    // - Remove the comments after the body.
    expression = *input;
    while (*input && **input != '#' && **input != '\n')
      (*input)++;
    
    if (*input && **input == '#') {
      **input = '\0';
      while (**input != '\n')
        (*input)++;
    }
    else {
      if (*input && **input == '\n') {
        **input = '\0';
        (*input)++;
      }
    }

    // - Copy the body.
    body->expression = osl_strings_encapsulate(strdup(expression));
  }

  return body;
}
Ejemplo n.º 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;
}