/**
 * osl_scatnames_clone function:
 * This function builds and returns a "hard copy" (not a pointer copy) of an
 * osl_scatnames_t data structure.
 * \param[in] scatnames The pointer to the scatnames structure to clone.
 * \return A pointer to the clone of the scatnames structure.
 */
osl_scatnames_p osl_scatnames_clone(osl_scatnames_p scatnames) {
  osl_scatnames_p clone;

  if (scatnames == NULL)
    return NULL;

  clone = osl_scatnames_malloc();
  clone->names = osl_strings_clone(scatnames->names);

  return clone;
}
Beispiel #2
0
Datei: scop.c Projekt: imenf/clan
/**
 * clan_scop_generate_scatnames function:
 * this function generates a scatnames extension for the scop passed as
 * an argument. Since Clan use a "2d+1" scattering strategy, the
 * scattering dimension names are generated by reusing the original
 * iterator names of the deepest statement and by inserting between those
 * names some beta vector elements (the Xth beta element is called bX).
 * \param[in,out] scop The scop to add a scatnames extension to.
 */
void clan_scop_generate_scatnames(osl_scop_p scop) {
  osl_statement_p current, deepest;
  osl_scatnames_p scatnames;
  osl_strings_p iterators = NULL;
  osl_strings_p names = NULL;
  osl_generic_p extension;
  osl_body_p body = NULL;
  char buffer[CLAN_MAX_STRING];
  int max_depth = -1;
  int i;

  // Find the deepest statement to reuse its original iterators.
  current = scop->statement;
  while (current != NULL) {
    if (current->domain->nb_output_dims > max_depth) {
      max_depth = current->domain->nb_output_dims;
      deepest = current;
      body = (osl_body_p)osl_generic_lookup(deepest->extension, OSL_URI_BODY);
      if (body)
        iterators = body->iterators;
    }
    current = current->next;
  }

  // It there are no scattering dimension, do nothing.
  if (max_depth <= 0)
    return;

  // Create the NULL-terminated list of scattering dimension names.
  names = osl_strings_malloc();
  for (i = 0; i < max_depth; i++) {
    sprintf(buffer, "b%d", i);
    osl_strings_add(names, buffer);
    osl_strings_add(names, iterators->string[i]);
  }
  sprintf(buffer, "b%d", max_depth);
  osl_strings_add(names, buffer);

  // Build the scatnames extension.
  scatnames = osl_scatnames_malloc();
  scatnames->names = names;

  // Build the generic extension and insert it to the extension list.
  extension = osl_generic_malloc();
  extension->interface = osl_scatnames_interface();
  extension->data = scatnames;
  osl_generic_add(&scop->extension, extension);
}
/**
 * osl_scatnames_sread function:
 * this function reads a scatnames structure from a string complying to the
 * OpenScop textual format and returns a pointer to this scatnames structure.
 * The input parameter is updated to the position in the input string this
 * function reach right after reading the scatnames structure. If there
 * is nothing to read, the function returns NULL.
 * \param[in,out] input The input string where to find a scatnames.
 *                      Updated to the position after what has been read.
 * \return A pointer to the scatnames structure that has been read.
 */
osl_scatnames_p osl_scatnames_sread(char ** input) {
  osl_scatnames_p scatnames = NULL;
  osl_strings_p names = NULL;

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

  // Build the scatnames structure
  names = osl_strings_sread(input);
  if (names != NULL) {
    scatnames = osl_scatnames_malloc();
    scatnames->names = names;
  }

  return scatnames;
}