Exemplo n.º 1
0
Arquivo: loop.c Projeto: 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;
}
Exemplo n.º 2
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;
}