Ejemplo n.º 1
0
/**
 * osl_scop_free function:
 * This function frees the allocated memory for a osl_scop_t structure.
 * \param scop The pointer to the scop we want to free.
 */
void osl_scop_free(osl_scop_p scop) {
  osl_scop_p tmp;
  
  while (scop != NULL) {
    if (scop->language != NULL)
      free(scop->language);
    osl_generic_free(scop->parameters);
    osl_relation_free(scop->context);
    osl_statement_free(scop->statement);
    osl_interface_free(scop->registry);
    osl_generic_free(scop->extension);

    tmp = scop->next;
    free(scop);
    scop = tmp;
  }
}
Ejemplo n.º 2
0
Archivo: clay.c Proyecto: Ced/clay
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;

  // 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);
		candl_scop_usr_init(orig_scop);
	}
	#endif
  
  // Execute the script ...
  // do nothing if the scop is NULL
  if (scop != NULL) {
    // Read the script file
    if (!options->from_tag) {
      clay_parser_file(scop, options->script, options);
      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;
        clay_parser_string(scop, clay_tag->script, options);

        // remove the extension clay
        last->next = x->next;
        x->next = NULL;
        osl_generic_free(x);
      }
    }
  }

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

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

		candl_options_free(candl_opt);
		candl_violation_free(violation);
 		osl_dependence_free(dep);
		candl_scop_usr_cleanup(orig_scop);
		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) {
      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 (!options->keep_extbody)
        clay_util_scop_export_body(scop);

			osl_scop_print(stdout, scop);
		}
	}

  osl_scop_free(scop);
  clay_options_free(options);

  return 0;
}