/**
 * osl_coordinates_sprint function:
 * this function prints the content of an osl_coordinates_t structure
 * (*coordinates) into a string (returned) in the OpenScop textual format.
 * \param  coordinates The coordinates structure to be print.
 * \return A string containing the OpenScop dump of the coordinates structure.
 */
char * osl_coordinates_sprint(osl_coordinates_p coordinates) {
  int high_water_mark = OSL_MAX_STRING;
  char * string = NULL;
  char buffer[OSL_MAX_STRING];

  if (coordinates != NULL) {
    OSL_malloc(string, char *, high_water_mark * sizeof(char));
    string[0] = '\0';
   
    // Print the coordinates content.
    sprintf(buffer, "# File name\n%s\n", coordinates->name);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Starting line\n%d\n", coordinates->start);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Ending line\n%d\n", coordinates->end);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Indentation\n%d\n", coordinates->indent);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
  
    // Keep only the memory space we need.
    OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
  }
示例#2
0
/**
 * osl_arrays_sprint function:
 * this function prints the content of an osl_arrays_t structure
 * (*arrays) into a string (returned) in the OpenScop textual format.
 * \param[in] arrays The arrays structure to print.
 * \return A string containing the OpenScop dump of the arrays structure.
 */
char * osl_arrays_sprint(osl_arrays_p arrays) {
  int i;
  int high_water_mark = OSL_MAX_STRING;
  char * string = NULL;
  char buffer[OSL_MAX_STRING];

  if (arrays != NULL) {
    OSL_malloc(string, char *, high_water_mark * sizeof(char));
    string[0] = '\0';

    sprintf(buffer, "# Number of arrays\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "%d\n", arrays->nb_names);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    if (arrays->nb_names) {
      sprintf(buffer, "# Mapping array-identifiers/array-names\n");
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }
    for (i = 0; i < arrays->nb_names; i++) {
      sprintf(buffer, "%d %s\n", arrays->id[i], arrays->names[i]);
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }

    OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
  }
示例#3
0
文件: strings.c 项目: Syllo/openscop
/**
 * 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;
}
示例#4
0
/**
 * osl_extbody_sprint function:
 * this function prints the content of an osl_extbody_t structure
 * (*ebody) into a string (returned) in the OpenScop textual format.
 * \param[in] ebody The ebody structure to print.
 * \return A string containing the OpenScop dump of the ebodystructure.
 */
char * osl_extbody_sprint(osl_extbody_p ebody) {
  int i;
  int high_water_mark = OSL_MAX_STRING;
  char * string = NULL, * body_string = NULL;
  char buffer[OSL_MAX_STRING];

  if (ebody != NULL) {
    OSL_malloc(string, char *, high_water_mark * sizeof(char));
    string[0] = '\0';

    sprintf(buffer, "# Number of accesses\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "%d\n", ebody->nb_access);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    if (ebody->nb_access) {
      sprintf(buffer, "# Access coordinates (start/length)\n");
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }
    for (i = 0; i < ebody->nb_access; i++) {
      sprintf(buffer, "%d %d\n", ebody->start[i], ebody->length[i]);
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }

    body_string = osl_body_sprint(ebody->body);
    osl_util_safe_strcat(&string, body_string, &high_water_mark);
    free(body_string);
  }
示例#5
0
/**
 * osl_irregular_sprint function:
 * this function prints the content of an osl_irregular_t structure
 * (*irregular) into a string (returned) in the OpenScop textual format.
 * \param  irregular The irregular structure whose information has to be printed.
 * \return A string containing the OpenScop dump of the irregular structure.
 */
char * osl_irregular_sprint(osl_irregular_p irregular) {
  int high_water_mark = OSL_MAX_STRING,i,j;
  char * string = NULL;
  char * buffer;

  if (irregular != NULL) {
    OSL_malloc(string, char *, high_water_mark * sizeof(char));
    OSL_malloc(buffer, char *, OSL_MAX_STRING * sizeof(char));
    string[0] = '\0';
   
    // Print the begin tag.
    sprintf(buffer, OSL_TAG_IRREGULAR_START);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    // Print the content.
    sprintf(buffer, "\n%d\n", irregular->nb_statements);
    for(i=0; i<irregular->nb_statements; i++) {
      sprintf(buffer, "%s%d ", buffer, irregular->nb_predicates[i]);
      for(j=0; j<irregular->nb_predicates[i]; j++) {
        sprintf(buffer, "%s%d ", buffer, irregular->predicates[i][j]);
      }
      sprintf(buffer, "%s\n", buffer);
    }
    // Print the predicates.
    // controls:
    sprintf(buffer, "%s%d\n", buffer, irregular->nb_control);
    sprintf(buffer, "%s%d\n", buffer, irregular->nb_exit);
    for(i=0; i<irregular->nb_control; i++) {
      sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[i]);
      for(j=0; j<irregular->nb_iterators[i];j++)
        sprintf(buffer, "%s%s ", buffer, irregular->iterators[i][j]);
      sprintf(buffer, "%s\n%s\n", buffer, irregular->body[i]);
    }
    // exits: 
    for(i=0; i<irregular->nb_exit; i++) {
      sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[
                                        irregular->nb_control + i]);
      for(j=0; j<irregular->nb_iterators[irregular->nb_control + i];j++)
        sprintf(buffer, "%s%s ", buffer, irregular->iterators[
                                          irregular->nb_control+i][j]);
      sprintf(buffer, "%s\n%s\n", buffer, irregular->body[
                                          irregular->nb_control + i]);
    }

    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    // Print the end tag.
    sprintf(buffer, OSL_TAG_IRREGULAR_STOP"\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
  
    // Keep only the memory space we need.
    OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
    free(buffer);
  }
示例#6
0
文件: util.c 项目: tajkhan/clay
void static clay_util_name_sprint(char **dst, int *hwm, 
                                  int *print_plus, int val, char *name) {
  if (*print_plus)
    osl_util_safe_strcat(dst, " + ", hwm);
  else
    *print_plus = 1;

  char buffer[32];

  if (name == NULL) {
    snprintf(buffer, 32, "%d", val);
    osl_util_safe_strcat(dst, buffer, hwm);
  } else {
    if (val == 1) {
      osl_util_safe_strcat(dst, name, hwm);
    } else if (val == -1) {
      osl_util_safe_strcat(dst, "-", hwm);
      osl_util_safe_strcat(dst, name, hwm);
    } else {
      snprintf(buffer, 32, "%d*", val);
      osl_util_safe_strcat(dst, buffer, hwm);
      osl_util_safe_strcat(dst, name, hwm);
    }
  }
}
示例#7
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;
}
示例#8
0
文件: dependence.c 项目: ArtemL/GCC
/**
 * osl_dependence_sprint function:
 * Returns a string containing the dependence, formatted to fit the
 * .scop representation.
 */
char* osl_dependence_sprint(osl_dependence_p dependence) {
  
  osl_dependence_p tmp = dependence;
  int nb_deps;
  int buffer_size = 2048;
  char* buffer;
  char buff[2048];
  char* type;
  char* pbuffer;
  
  OSL_malloc(buffer, char*, buffer_size);
  buffer[0] = '\0';
  
  for (tmp = dependence, nb_deps = 0; tmp; tmp = tmp->next, ++nb_deps)
   ;
  snprintf(buff, OSL_MAX_STRING, "# Number of dependences\n%d\n", nb_deps);
  strcat(buffer, buff);
  
  if (nb_deps) {
    for (tmp = dependence, nb_deps = 1; tmp; tmp = tmp->next, ++nb_deps) {
      
      switch (tmp->type) {
        case OSL_UNDEFINED:
          type = "UNSET";
          break;
        case OSL_DEPENDENCE_RAW:
          type = "RAW #(flow)";
          break;
        case OSL_DEPENDENCE_WAR:
          type = "WAR #(anti)";
          break;
        case OSL_DEPENDENCE_WAW:
          type = "WAW #(output)";
          break;
        case OSL_DEPENDENCE_RAR:
          type = "RAR #(input)";
          break;
        case OSL_DEPENDENCE_RAW_SCALPRIV:
          type = "RAW_SCALPRIV #(scalar priv)";
          break;
        default:
          exit(1);
          break;
      }

      /* Output dependence information. */
      snprintf(buff, OSL_MAX_STRING, "# Description of dependence %d\n"
              "# type\n%s\n"
              "# From source statement id\n%d\n"
              "# To target statement id\n%d\n"
              "# Depth \n%d\n"
              "# From source access ref\n%d\n"
              "# To target access ref\n%d\n"
              "# Dependence domain\n",
              nb_deps, type,
              tmp->label_source,
              tmp->label_target,
              tmp->depth,
              tmp->ref_source,
              tmp->ref_target);

      osl_util_safe_strcat(&buffer, buff, &buffer_size);
      
      /* Output dependence domain. */
      pbuffer = osl_relation_sprint(tmp->domain);
      osl_util_safe_strcat(&buffer, pbuffer, &buffer_size);
      free(pbuffer);
    }
  }
  
  return buffer;
}
示例#9
0
文件: util.c 项目: tajkhan/clay
/**
 * clay_util_body_regenerate_access function:
 * Read the access array and re-generate the code in the body
 * \param[in] ebody     An extbody structure
 * \param[in] access    The relation to regenerate the code
 * \param[in] index     nth access (needed to access to the array start and 
 *                      length of the extbody structure)
 */
void clay_util_body_regenerate_access(osl_extbody_p ebody,
                                      osl_relation_p access,
                                      int index,
                                      osl_arrays_p arrays,
                                      osl_scatnames_p scatnames,
                                      osl_strings_p params) {

  if (!arrays || !scatnames || !params || access->nb_output_dims == 0 ||
      index >= ebody->nb_access)
    return;

  const int precision = access->precision;
  int i, j, k, row, val, print_plus;

  // check if there are no inequ
  for (i = 0 ; i < access->nb_rows ; i++) {
    if (!osl_int_zero(precision, access->m[i][0]))
      CLAY_error("I don't know how to regenerate access with inequalities");
  }

  // check identity matrix in output dims
  int n;
  for (j = 0 ; j < access->nb_output_dims ; j++) {
    n = 0;
    for (i = 0 ; i < access->nb_rows ; i++)
      if (!osl_int_zero(precision, access->m[i][j+1])) {
        if (n >= 1)
          CLAY_error("I don't know how to regenerate access with "
                     "dependences in output dims");
        n++;
      }
  }

  char *body = ebody->body->expression->string[0];
  int body_len = strlen(body);
  int start = ebody->start[index];
  int len = ebody->length[index];
  int is_zero; // if the line contains only zeros

  if (start >= body_len || start + len >= body_len || (start == -1 && len == -1))
    return;

  char *new_body;
  char end_body[OSL_MAX_STRING];
  int hwm = OSL_MAX_STRING;

  CLAY_malloc(new_body, char *, OSL_MAX_STRING * sizeof(char));

  // copy the beginning of the body
  if (start+1 >= OSL_MAX_STRING)
    CLAY_error("memcpy: please recompile osl with a higher OSL_MAX_STRING");
  memcpy(new_body, body, start);
  new_body[start] = '\0';

  // save the end in a buffer
  int sz = body_len - start - len;
  if (sz + 1 >= OSL_MAX_STRING)
    CLAY_error("memcpy: please recompile osl with a higher OSL_MAX_STRING");
  memcpy(end_body, body + start + len, sz);
  end_body[sz] = '\0';


  // copy access name string
  val = osl_relation_get_array_id(access);
  val = clay_util_arrays_search(arrays, val); // get the index in th array
  osl_util_safe_strcat(&new_body, arrays->names[val], &hwm);


  // generate each dims
  for (i = 1 ; i < access->nb_output_dims ; i++) {
    row = clay_util_relation_get_line(access, i);
    if (row == -1)
      continue;

    osl_util_safe_strcat(&new_body, "[", &hwm);

    is_zero = 1;
    print_plus = 0;
    k = 1 + access->nb_output_dims;

    // iterators
    for (j = 0 ; j < access->nb_input_dims ; j++, k++) {
      val = osl_int_get_si(precision, access->m[row][k]);
      if (val != 0) {
        clay_util_name_sprint(&new_body,
                              &hwm, 
                              &print_plus,
                              val,
                              scatnames->names->string[j*2+1]);
        is_zero = 0;
      }
    }

    // params
    for (j = 0 ; j < access->nb_parameters ; j++, k++) {
      val = osl_int_get_si(precision, access->m[row][k]);
      if (val != 0) {
        clay_util_name_sprint(&new_body,
                              &hwm, 
                              &print_plus,
                              val,
                              params->string[j]);
        is_zero = 0;
      }
    }

    // const
    val = osl_int_get_si(precision, access->m[row][k]);
    if (val != 0 || is_zero)
      clay_util_name_sprint(&new_body,
                            &hwm, 
                            &print_plus,
                            val,
                            NULL);

    osl_util_safe_strcat(&new_body, "]", &hwm);
  }

  // length of the generated access
  ebody->length[index] = strlen(new_body) - start;

  // concat the end
  osl_util_safe_strcat(&new_body, end_body, &hwm);

  // update ebody
  free(ebody->body->expression->string[0]);
  ebody->body->expression->string[0] = new_body;

  // shift the start
  int diff = ebody->length[index] - len;
  for (i = index+1 ; i < ebody->nb_access ; i++)
    if (ebody->start[i] != -1)
      ebody->start[i] += diff;
}
示例#10
0
文件: loop.c 项目: Ced/openscop
/**
 * osl_loop_sprint function:
 * this function prints the content of an osl_loop_t structure
 * (*loop) into a string (returned) in the OpenScop textual format.
 * \param[in] loop The loop structure to print.
 * \return         A string containing the OpenScop dump of the loop structure.
 */
char * osl_loop_sprint(osl_loop_p loop) {
  size_t i;
  int nloop = 0;
  size_t 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';

  sprintf(buffer, "# Number of loops\n%d\n",osl_loop_count(loop));
  osl_util_safe_strcat(&string, buffer, &high_water_mark);

  while (loop != NULL) {
    sprintf(buffer, "# ===========================================\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Loop number %d \n", ++nloop);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Iterator name\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
    sprintf(buffer, "%s\n", loop->iter);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Number of stmts\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
    sprintf(buffer, "%zu\n", loop->nb_stmts);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    if (loop->nb_stmts) {
      sprintf(buffer, "# Statement identifiers\n");
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }
    for (i = 0; i < loop->nb_stmts; i++) {
      sprintf(buffer, "%d\n", loop->stmt_ids[i]);
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }

    sprintf(buffer, "# Private variables\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
    sprintf(buffer, "%s\n", loop->private_vars);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    sprintf(buffer, "# Directive\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
    sprintf(buffer, "%d", loop->directive);
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    // special case for OSL_LOOP_DIRECTIVE_USER
    if (loop->directive & OSL_LOOP_DIRECTIVE_USER) {
      sprintf(buffer, " %s", loop->user);
      osl_util_safe_strcat(&string, buffer, &high_water_mark);
    }
    sprintf(buffer, "\n");
    osl_util_safe_strcat(&string, buffer, &high_water_mark);

    loop = loop->next;
  }

  OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
  return string;
}