Beispiel #1
0
/**
 * 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;
}
Beispiel #2
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;
}