/** * @brief Aggregate two osl_generic together (cloning the necessary structures). * The parameters are not modified. If two generics are found, only one is kept (like a union). * * @param gen1 A pointer to the first osl_generic. * @param gen2 A pointer to the first osl_generic. * * @return The aggregation of two osl_generic. */ struct osl_generic * substrate_osl_generic_fusion( struct osl_generic * gen1, struct osl_generic * gen2) { struct osl_generic * res = NULL, *tmp1 = NULL, *tmp2 = NULL; struct osl_generic * new_generic = NULL; tmp1 = gen1; while(tmp1 != NULL) { tmp2 = substrate_osl_generic_lookup(gen2, tmp1->interface->URI); if(tmp2 == NULL) { osl_generic_add(&res, substrate_osl_generic_nclone(tmp1,1)); } else if(osl_generic_equal(tmp1, tmp2)) { if(strcmp(tmp1->interface->URI,"body") == 0) { new_generic = osl_generic_malloc(); new_generic->interface = osl_body_interface(); new_generic->next = NULL; new_generic->data = substrate_osl_body_fusion(tmp1->data,tmp2->data); osl_generic_add(&res, new_generic); } else { osl_generic_add(&res, substrate_osl_generic_nclone(tmp1,1)); } } else { if(strcmp(tmp1->interface->URI,"body") == 0) { new_generic = osl_generic_malloc(); new_generic->interface = osl_body_interface(); new_generic->next = NULL; new_generic->data = substrate_osl_body_fusion(tmp1->data,tmp2->data); osl_generic_add(&res, new_generic); } else { OSL_warning("Can't fusion the generic structures : don't know how."); fprintf(stderr,"URI : %s\n", tmp1->interface->URI); } } tmp1 = tmp1->next; } return res; }
/** * osl_scop_pread function ("precision read"): * this function reads a list of scop structures from a file (possibly stdin) * complying to the OpenScop textual format and returns a pointer to this * scop list. If some relation properties (number of input/output/local * dimensions and number of parameters) are undefined, it will define them * according to the available information. * \param[in] file The file where the scop has to be read. * \param[in] registry The list of known interfaces (others are ignored). * \param[in] precision The precision of the relation elements. * \return A pointer to the scop structure that has been read. */ osl_scop_p osl_scop_pread(FILE * file, osl_interface_p registry, int precision) { osl_scop_p list = NULL, current = NULL, scop; osl_statement_p stmt = NULL; osl_statement_p prev = NULL; osl_strings_p language; int nb_statements; char * tmp; int first = 1; int i; if (file == NULL) return NULL; while(1) { // // I. START TAG // tmp = osl_util_read_uptotag(file, OSL_TAG_START_SCOP); if (tmp == NULL) { OSL_debug("no more scop in the file"); break; } else { free(tmp); } scop = osl_scop_malloc(); scop->registry = osl_interface_clone(registry); // // II. CONTEXT PART // // Read the language. language = osl_strings_read(file); if (osl_strings_size(language) == 0) OSL_error("no language (backend) specified"); if (osl_strings_size(language) > 1) OSL_warning("uninterpreted information (after language)"); if (language != NULL) { scop->language = strdup(language->string[0]); osl_strings_free(language); } // Read the context domain. scop->context = osl_relation_pread(file, precision); // Read the parameters. if (osl_util_read_int(file, NULL) > 0) scop->parameters = osl_generic_read_one(file, scop->registry); // // III. STATEMENT PART // // Read the number of statements. nb_statements = osl_util_read_int(file, NULL); for (i = 0; i < nb_statements; i++) { // Read each statement. stmt = osl_statement_pread(file, scop->registry, precision); if (scop->statement == NULL) scop->statement = stmt; else prev->next = stmt; prev = stmt; } // // IV. EXTENSION PART (TO THE END TAG) // // Read up the end tag (if any), and store extensions. scop->extension = osl_generic_read(file, scop->registry); // Add the new scop to the list. if (first) { list = scop; first = 0; } else { current->next = scop; } current = scop; } if (!osl_scop_integrity_check(list)) OSL_warning("scop integrity check failed"); return list; }
/** * osl_scop_print function: * this function prints the content of an osl_scop_t structure (*scop) * into a file (file, possibly stdout) in the OpenScop textual format. * \param file The file where the information has to be printed. * \param scop The scop structure whose information has to be printed. */ void osl_scop_print(FILE * file, osl_scop_p scop) { int parameters_backedup = 0; int arrays_backedup = 0; osl_strings_p parameters_backup = NULL; osl_strings_p arrays_backup = NULL; osl_names_p names; osl_arrays_p arrays; if (scop == NULL) { fprintf(file, "# NULL scop\n"); return; } else { fprintf(file, "# [File generated by the OpenScop Library %s]\n", OSL_RELEASE); } if (osl_scop_integrity_check(scop) == 0) OSL_warning("OpenScop integrity check failed. Something may go wrong."); // Generate the names for the various dimensions. names = osl_scop_names(scop); while (scop != NULL) { // If possible, replace parameter names with scop parameter names. if (osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS)) { parameters_backedup = 1; parameters_backup = names->parameters; names->parameters = scop->parameters->data; } // If possible, replace array names with arrays extension names. arrays = osl_generic_lookup(scop->extension, OSL_URI_ARRAYS); if (arrays != NULL) { arrays_backedup = 1; arrays_backup = names->arrays; names->arrays = osl_arrays_to_strings(arrays); } fprintf(file, "\n"OSL_TAG_START_SCOP"\n\n"); fprintf(file, "# =============================================== " "Global\n"); fprintf(file, "# Language\n"); fprintf(file, "%s\n\n", scop->language); fprintf(file, "# Context\n"); osl_relation_pprint(file, scop->context, names); fprintf(file, "\n"); osl_util_print_provided(file, osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS), "Parameters are"); osl_generic_print(file, scop->parameters); fprintf(file, "\n# Number of statements\n"); fprintf(file, "%d\n\n",osl_statement_number(scop->statement)); osl_statement_pprint(file, scop->statement, names); if (scop->extension) { fprintf(file, "# =============================================== " "Extensions\n"); osl_generic_print(file, scop->extension); } fprintf(file, "\n"OSL_TAG_END_SCOP"\n\n"); // If necessary, switch back parameter names. if (parameters_backedup) { parameters_backedup = 0; names->parameters = parameters_backup; } // If necessary, switch back array names. if (arrays_backedup) { arrays_backedup = 0; osl_strings_free(names->arrays); names->arrays = arrays_backup; } scop = scop->next; } osl_names_free(names); }