Exemple #1
0
/**
 * clay_util_scop_export_body function:
 * Convert each extbody to a body structure
 * \param[in] scop
 */
void clay_util_scop_export_body(osl_scop_p scop) {
  if (scop == NULL)
    return;

  osl_statement_p stmt = scop->statement;
  osl_extbody_p ebody = NULL;
  osl_body_p body = NULL;
  osl_generic_p gen = NULL;

  while (stmt) {
    ebody = osl_generic_lookup(stmt->extension, OSL_URI_EXTBODY);
    if (ebody!=NULL) {

      body = osl_generic_lookup(stmt->extension, OSL_URI_BODY);
      if (body) {
        osl_generic_remove(&stmt->extension, OSL_URI_BODY);
      }
      body = osl_body_clone(ebody->body);
      gen = osl_generic_shell(body, osl_body_interface());
      osl_generic_add(&stmt->extension, gen);
      osl_generic_remove(&stmt->extension, OSL_URI_EXTBODY);
      ebody=NULL;
      body=NULL;
    }
    stmt = stmt->next;
  }
}
Exemple #2
0
/**
 * clay_util_foreach_access function:
 * Execute func on each access which corresponds to access_name
 * \param[in,out] scop
 * \param[in] beta
 * \param[in] access_name      The id to search
 * \param[in] func             The function to execute for each access
 *                             The function takes an osl_relation_list_p in 
 *                             parameter (the elt can be modified) and must 
 *                             return a define error or CLAY_SUCCESS
 * \param[in] args             args of `func'
 * \param[in] regenerate_body  If 1: after each call to func, 
 *                             clay_util_body_regenerate_access is also called
 * \return                     Return a define error or CLAY_SUCCESS
 */
int clay_util_foreach_access(osl_scop_p scop,
                             clay_array_p beta,
                             unsigned int access_name,
                             int (*func)(osl_relation_list_p, void*),
                             void *args,
                             int regenerate_body) {

  osl_statement_p stmt = scop->statement;
  osl_relation_list_p access;
  osl_relation_p a;
  osl_extbody_p ebody = NULL;
  osl_body_p body = NULL;
  osl_generic_p gen= NULL;
  int count_access;
  int found = 0;
  int ret;

  // TODO : global vars ?
  osl_arrays_p arrays;
  osl_scatnames_p scatnames;
  osl_strings_p params;
  arrays = osl_generic_lookup(scop->extension, OSL_URI_ARRAYS);
  scatnames = osl_generic_lookup(scop->extension, OSL_URI_SCATNAMES);
  params = osl_generic_lookup(scop->parameters, OSL_URI_STRINGS);

  if (!arrays || !scatnames || !params)
    CLAY_warning("no arrays or scatnames extension");

  stmt = clay_beta_find(scop->statement, beta);
  if (!stmt)
    return CLAY_ERROR_BETA_NOT_FOUND;

  // for each access in the beta, we search the access_name
  while (stmt != NULL) {
    if (clay_beta_check(stmt, beta)) {
      access = stmt->access;
      count_access = 0;

      while (access) {
        a = access->elt;

        if (osl_relation_get_array_id(a) == access_name) {
          found = 1;

          ebody = osl_generic_lookup(stmt->extension, OSL_URI_EXTBODY);
          if (ebody==NULL) {
            CLAY_error("extbody uri not found on this statement");
            fprintf(stderr, "%s\n",
              ebody->body->expression->string[0]);
          }

          // call the function
          ret = (*func)(access, args);
          if (ret != CLAY_SUCCESS) {
            fprintf(stderr, "%s\n",
              ebody->body->expression->string[0]);
            return ret;
          }

          // re-generate the body
          if (regenerate_body) {
            clay_util_body_regenerate_access(
                ebody,
                access->elt,
                count_access,
                arrays,
                scatnames,
                params);


            //synchronize extbody with body
            body = osl_generic_lookup(stmt->extension, OSL_URI_BODY);
            if (body) {
              osl_generic_remove(&stmt->extension, OSL_URI_BODY);
              body = osl_body_clone(ebody->body);
              gen = osl_generic_shell(body, osl_body_interface());
              osl_generic_add(&stmt->extension, gen);
            }
          }
        }

        ebody = NULL;
        body  = NULL;
        access = access->next;
        count_access++;
      }
    }
    stmt = stmt->next;
  }

  if (!found)
   fprintf(stderr,"[Clay] Warning: access number %d not found\n", access_name);

  return CLAY_SUCCESS;
}
Exemple #3
0
int main(int argc, char * argv[]) {

  osl_scop_p scop = NULL;
  osl_generic_p x, last;
  osl_clay_p clay_tag;
  clay_options_p options;
  int parsing_result = 0;

  // Read command line parameters
  options = clay_options_read(argc, argv);
  if (options->print_infos) {
    clay_options_free(options);
    exit(0);
  }

  // Open the scop file
  #ifdef CLAN_LINKED
  if (options->readc) {
    clan_options_p clan_opt = clan_options_malloc();
		clan_opt->precision = OSL_PRECISION_MP;
		clan_opt->name = options->input_name;
		clan_opt->extbody = 1;
    scop = clan_scop_extract(options->input, clan_opt);
    //clan_options_free(clan_opt); // bug, the name is also freed
    free(clan_opt);
    fclose(options->input);
  }
  else
  #endif
  {
    scop = osl_scop_read(options->input);
    if (options->input != stdin)
      fclose(options->input);
  }

  if (options->normalize) {
    clay_beta_normalize(scop);
  }

#if defined(CANDL_LINKED)
  osl_scop_p orig_scop = NULL;
  if (!options->nocandl && scop != NULL) {
          orig_scop = osl_scop_clone(scop);
  }
#endif
  
  // Execute the script ...
  // do nothing if the scop is NULL
  if (scop != NULL) {
    // Read the script file
    if (!options->from_tag) {
      parsing_result = clay_parser_file(scop, options->script, options);
      if (parsing_result != 0) {
        fprintf(stderr, "[Clay] %s\n", clay_get_error_message());
      }
      fclose(options->script);
    
    // Read the script from the extension clay
    } else {
      // equivalent to osl_generic_lookup, but we need the last extension
      // to remove the clay extension in the list
      x = scop->extension;
      last = NULL;
      while (x != NULL) {
        if (osl_generic_has_URI(x, OSL_URI_CLAY))
          break;
        last = x;
        x = x->next;
      }
     
      if (x != NULL) {
        // parse the clay string
        clay_tag = x->data;
        parsing_result = clay_parser_string(scop, clay_tag->script, options);
        if (parsing_result != 0) {
          fprintf(stderr, "[Clay] %s\n", clay_get_error_message());
        }

        // remove the extension clay
        osl_generic_remove(&scop->extension, OSL_URI_CLAY);
      }
    }
  }

#ifdef CANDL_LINKED
  int is_violated = 0;
  // Check dependencies
  if (!options->nocandl && scop != NULL && parsing_result == 0) {
    candl_options_p candl_opt = candl_options_malloc();
    if (options->candl_fullcheck)
      candl_opt->fullcheck = 1;
    candl_scop_usr_init(orig_scop);
    candl_violation_p violation = 
        candl_violation(orig_scop, scop, 0, candl_opt);

    is_violated = (violation != NULL);
    if (is_violated) {
      candl_violation_pprint(stdout, violation);
      if (options->candl_structure)
        candl_violation_dump(stdout, violation);
    }

    candl_scop_usr_cleanup(orig_scop);
    candl_options_free(candl_opt);
    candl_violation_free(violation);
    osl_scop_free(orig_scop);
  }

  if (!is_violated) // print the scop or the .c file by cloog
#endif
	
	{
    #ifdef CLOOG_LINKED
		if (options->printc && scop != NULL && parsing_result == 0) {
      clay_util_scop_export_body(scop);

			CloogState *state = cloog_state_malloc();
			CloogOptions *cloogoptions = cloog_options_malloc(state);
			cloogoptions->openscop = 1;
			CloogInput *clooginput = cloog_input_from_osl_scop(cloogoptions->state, 
                                                         scop);
			cloog_options_copy_from_osl_scop(scop, cloogoptions);
			CloogProgram *program = cloog_program_alloc(clooginput->context, 
					                            clooginput->ud, cloogoptions);
			free(clooginput);
			cloog_program_generate(program, cloogoptions);
			
			cloog_program_pprint(stdout, program, cloogoptions);
			cloog_program_free(program);
			cloogoptions->scop = NULL; // don't free the scop
			cloog_options_free(cloogoptions);
			cloog_state_free(state);
		}
		else
		#endif
		{
                  if (parsing_result == 0) {
      if (!options->keep_extbody)
        clay_util_scop_export_body(scop);

			osl_scop_print(stdout, scop);
                  }
		}
	}

  osl_scop_free(scop);
  clay_options_free(options);

  return parsing_result;
}