From c3adcf4382398f753dc294540ab3eee7adafa4e6 Mon Sep 17 00:00:00 2001 From: Cedric Bastoul Date: Sun, 10 Jul 2011 21:20:10 +0200 Subject: [PATCH] Remove names_t and replace with parameter list only --- include/openscop/scop.h.in | 14 +++-- source/body.c | 67 +++++++++-------------- source/scop.c | 117 ++++++++++++++++++++++------------------ source/util.c | 4 +- tests/polynom.scop | 10 ---- tests/test_empty_statement.scop | 6 --- tests/test_just_access.scop | 6 --- tests/test_just_body.scop | 6 --- tests/test_just_domain.scop | 6 --- tests/test_just_scattering.scop | 6 --- tests/test_matmult.scop | 8 --- tests/test_no_statement.scop | 6 --- 12 files changed, 102 insertions(+), 154 deletions(-) diff --git a/include/openscop/scop.h.in b/include/openscop/scop.h.in index 5d82c05..5acd510 100644 --- a/include/openscop/scop.h.in +++ b/include/openscop/scop.h.in @@ -95,16 +95,22 @@ extern "C" /** * The scop_t structure stores the useful information of a static * control part of a program to process it within a polyhedral framework. + * Parameter information may be strings of characters (char *) or a generic + * pointer to anything else (void *). The OpenScop library does not touch AT + * ALL generic information: printing, copy etc. must be done externally. */ struct openscop_scop { int version; /**< Version of the data structure */ char * language; /**< Target language (backend) */ - openscop_relation_p context; /**< Constraints on the SCoP parameters */ - openscop_names_p names; /**< Various names for code generation */ + openscop_relation_p context; /**< Constraints on the SCoP parameters */ + int parameter_type; /**< OPENSCOP_TYPE_GENERIC if parameters are + generic (void*), OPENSCOP_TYPE_STRING if + they are strings (castable to char*) */ + void ** parameter; /**< Array of parameters */ openscop_statement_p statement; /**< Statement list of the SCoP */ - openscop_extension_p extension; /**< Extension list. */ + openscop_extension_p extension; /**< Extension list */ void * usr; /**< A user-defined field, not touched - AT ALL by the OpenScop Library. */ + AT ALL by the OpenScop Library */ }; typedef struct openscop_scop openscop_scop_t; typedef struct openscop_scop * openscop_scop_p; diff --git a/source/body.c b/source/body.c index f9b773a..0652716 100644 --- a/source/body.c +++ b/source/body.c @@ -92,48 +92,36 @@ void openscop_body_idump(FILE * file, openscop_body_p body, int level) { if (body != NULL) { fprintf(file, "+-- openscop_body_t\n"); - } - else { - fprintf(file, "+-- NULL body\n"); - } - - // A blank line. - for (j = 0; j <= level+1; j++) - fprintf(file, "|\t"); - fprintf(file, "\n"); - - if (body->type == OPENSCOP_TYPE_STRING) { - // Print the original iterator names. - for (i = 0; i <= level; i++) - fprintf(file, "|\t"); - if (body->nb_iterators > 0) { - fprintf(file, "+-- Original iterator strings:"); - for (i = 0; i < body->nb_iterators; i++) - fprintf(file, " %s", (char *)body->iterator[i]); - fprintf(file, "\n"); - } - else - fprintf(file, "+-- No original iterator string\n"); // A blank line. - for (i = 0; i <= level+1; i++) + for (j = 0; j <= level+1; j++) fprintf(file, "|\t"); fprintf(file, "\n"); - // Print the original body expression. - for (i = 0; i <= level; i++) - fprintf(file, "|\t"); - if (body->expression != NULL) - fprintf(file, "+-- Original expression: %s\n", (char *)body->expression); - else - fprintf(file, "+-- No original body expression\n"); + if (body->type == OPENSCOP_TYPE_STRING) { + // Print the original iterator names. + openscop_util_strings_idump(file, (char **)body->iterator, + body->nb_iterators, level, + "original iterator strings"); + + // Print the original body expression. + for (i = 0; i <= level; i++) + fprintf(file, "|\t"); + if (body->expression != NULL) + fprintf(file, "+-- Original expression: %s\n", (char *)body->expression); + else + fprintf(file, "+-- No original body expression\n"); + } + else { + for (i = 0; i <= level; i++) + fprintf(file, "|\t"); + fprintf(file, "+-- Non textual information\n"); + } } else { - for (i = 0; i <= level; i++) - fprintf(file, "|\t"); - fprintf(file, "+-- Non textual information\n"); + fprintf(file, "+-- NULL body\n"); } - + // The last line. for (j = 0; j <= level+1; j++) fprintf(file, "|\t"); @@ -204,11 +192,11 @@ openscop_body_p openscop_body_read(FILE * file, int nb_iterators) { int nb_strings; if (file) { - body = openscop_body_malloc(); - body->type = OPENSCOP_TYPE_STRING; - // Read the body information, if any. if (openscop_util_read_int(file, NULL) > 0) { + body = openscop_body_malloc(); + body->type = OPENSCOP_TYPE_STRING; + // Read the original iterator names. if (nb_iterators > 0) { body->iterator = (void *)openscop_util_strings_read(file, &nb_strings); @@ -232,11 +220,6 @@ openscop_body_p openscop_body_read(FILE * file, int nb_iterators) { // - Copy the body. body->expression = strdup(start); } - else { - body->nb_iterators = 0; - body->iterator = NULL; - body->expression = NULL; - } } return body; diff --git a/source/scop.c b/source/scop.c index 05d6c9a..66ba432 100644 --- a/source/scop.c +++ b/source/scop.c @@ -97,6 +97,16 @@ void openscop_scop_idump(FILE * file, openscop_scop_p scop, int level) { fprintf(file, "|\t"); fprintf(file, "\n"); + // Print the version. + for (j = 0; j < level; j++) + fprintf(file, "|\t"); + fprintf(file, "|\tVersion: %d\n", scop->version); + + // A blank line. + for (j = 0; j <= level+1; j++) + fprintf(file, "|\t"); + fprintf(file, "\n"); + // Print the language. for (j = 0; j < level; j++) fprintf(file, "|\t"); @@ -110,8 +120,12 @@ void openscop_scop_idump(FILE * file, openscop_scop_p scop, int level) { // Print the context of the scop. openscop_relation_idump(file, scop->context, level+1); - // Print the names. - openscop_names_idump(file, scop->names, level+1); + // Print the parameters. + openscop_util_strings_idump(file, + (scop->parameter_type == OPENSCOP_TYPE_STRING) ? + (char **)scop->parameter : NULL, + (scop->context != NULL) ? scop->context->nb_parameters : 0, + level, "parameters"); // Print the statements. openscop_statement_idump(file, scop->statement, level+1); @@ -147,6 +161,7 @@ void openscop_scop_dump(FILE * file, openscop_scop_p scop) { } +#if 0 /** * openscop_scop_name_limits function: * this function finds the (maximum) number of various elements of a scop and @@ -273,7 +288,7 @@ openscop_names_p openscop_scop_full_names(openscop_scop_p scop) { return names; } - +#endif /** * openscop_scop_print function: @@ -283,18 +298,12 @@ openscop_names_p openscop_scop_full_names(openscop_scop_p scop) { * \param scop The scop structure whose information has to be printed. */ void openscop_scop_print(FILE * file, openscop_scop_p scop) { - openscop_names_p names; - int tmp_nb_iterators = 0; - char ** tmp_iterators = NULL; if (openscop_scop_integrity_check(scop) == 0) { fprintf(stderr, "[OpenScop] Warning: OpenScop integrity check failed. " " Something may go wrong.\n"); } - // Build a name structure for pretty printing of relations. - names = openscop_scop_full_names(scop); - if (0) { fprintf(file, "# \n"); fprintf(file, "# <| \n"); @@ -339,32 +348,25 @@ void openscop_scop_print(FILE * file, openscop_scop_p scop) { fprintf(file, "%s\n\n", scop->language); fprintf(file, "# Context\n"); - // Remove the iterators from the names structure to print comments, as - // this information is used to know the number of iterators. - // TODO: do this in openscop_relation_print_openscop - tmp_nb_iterators = names->nb_iterators; - tmp_iterators = names->iterators; - names->nb_iterators = 0; - names->iterators = NULL; - openscop_relation_print(file, scop->context, names); - names->nb_iterators = tmp_nb_iterators; - names->iterators = tmp_iterators; + openscop_relation_print(file, scop->context, NULL); fprintf(file, "\n"); - openscop_names_print(file, scop->names); + openscop_util_strings_print(file, + (char **)scop->parameter, + (scop->context != NULL) ? scop->context->nb_parameters : 0, + (scop->parameter_type == OPENSCOP_TYPE_STRING), + "Parameters"); fprintf(file, "# Number of statements\n"); fprintf(file, "%d\n\n",openscop_statement_number(scop->statement)); - openscop_statement_print(file, scop->statement, names); - + openscop_statement_print(file, scop->statement, NULL); + if (scop->extension) { fprintf(file, "# ===============================================" " Extensions\n"); openscop_extension_print(file, scop->extension); } - - openscop_names_free(names); } @@ -387,7 +389,7 @@ openscop_scop_p openscop_scop_read(FILE * file) { openscop_scop_p scop = NULL; openscop_statement_p stmt = NULL; openscop_statement_p prev = NULL; - int nb_statements; + int nb_statements, nb_parameters; int max; char ** tmp; int i; @@ -428,7 +430,15 @@ openscop_scop_p openscop_scop_read(FILE * file) { // Read the context. scop->context = openscop_relation_read(file); - scop->names = openscop_names_read(file); + + // Read the parameters. + scop->parameter_type = OPENSCOP_TYPE_STRING; + if (openscop_util_read_int(file, NULL) > 0) { + scop->parameter = (void**)openscop_util_strings_read(file, &nb_parameters); + if ((scop->context != NULL) && + (nb_parameters != scop->context->nb_parameters)) + fprintf(stderr, "[OpenScop] Warning: bad number of parameters.\n"); + } // // II. STATEMENT PART @@ -458,7 +468,7 @@ openscop_scop_p openscop_scop_read(FILE * file) { // VI. FINALIZE AND CHECK // if (!openscop_scop_integrity_check(scop)) - fprintf(stderr, "[OpenScop] Warning: global integrity check failed.\n"); + fprintf(stderr, "[OpenScop] Warning: scop integrity check failed.\n"); return scop; } @@ -485,13 +495,14 @@ openscop_scop_p openscop_scop_malloc() { exit(1); } - scop->version = 1; - scop->language = NULL; - scop->context = NULL; - scop->names = NULL; - scop->statement = NULL; - scop->extension = NULL; - scop->usr = NULL; + scop->version = 1; + scop->language = NULL; + scop->context = NULL; + scop->parameter_type = OPENSCOP_UNDEFINED; + scop->parameter = NULL; + scop->statement = NULL; + scop->extension = NULL; + scop->usr = NULL; return scop; } @@ -507,8 +518,10 @@ void openscop_scop_free(openscop_scop_p scop) { if (scop->language != NULL) free(scop->language); + openscop_util_strings_free( + (char **)scop->parameter, + (scop->context != NULL) ? scop->context->nb_parameters : 0); openscop_relation_free(scop->context); - openscop_names_free(scop->names); openscop_statement_free(scop->statement); openscop_extension_free(scop->extension); @@ -538,7 +551,10 @@ openscop_scop_p openscop_scop_copy(openscop_scop_p scop) { if (scop->language != NULL) copy->language = strdup(scop->language); copy->context = openscop_relation_copy(scop->context); - copy->names = openscop_names_copy(scop->names); + copy->parameter_type = scop->parameter_type; + copy->parameter = (void **)openscop_util_strings_copy( + (char **)scop->parameter, + (scop->context != NULL) ? scop->context->nb_parameters : 0); copy->statement = openscop_statement_copy(scop->statement); copy->extension = openscop_extension_copy(scop->extension); @@ -574,8 +590,18 @@ int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) { return 0; } - if (!openscop_names_equal(s1->names, s2->names)) { - fprintf(stderr, "[OpenScop] info: names are not the same.\n"); + if (s1->parameter_type != s2->parameter_type) { + fprintf(stderr, "[OpenScop] info: parameter types are not the same.\n"); + return 0; + } + + if ((s1->parameter_type == OPENSCOP_TYPE_STRING) && + (!openscop_util_strings_equal( + (char **)s1->parameter, + (s1->context != NULL) ? s1->context->nb_parameters : 0, + (char **)s2->parameter, + (s2->context != NULL) ? s2->context->nb_parameters : 0))) { + fprintf(stderr, "[OpenScop] info: parameters are not the same.\n"); return 0; } @@ -602,11 +628,6 @@ int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) { */ int openscop_scop_integrity_check(openscop_scop_p scop) { int expected_nb_parameters; - int max_nb_parameters; - int max_nb_iterators; - int max_nb_scattdims; - int max_nb_localdims; - int max_nb_arrays; // Check the language. if ((scop->language != NULL) && @@ -632,13 +653,5 @@ int openscop_scop_integrity_check(openscop_scop_p scop) { expected_nb_parameters)) return 0; - // Ensure we have enough names. - openscop_scop_name_limits(scop, &max_nb_parameters, - &max_nb_iterators, - &max_nb_scattdims, - &max_nb_localdims, - &max_nb_arrays); - - return openscop_names_integrity_check(scop->names, expected_nb_parameters, - max_nb_iterators, max_nb_scattdims); + return 1; } diff --git a/source/util.c b/source/util.c index de5866a..179a98a 100644 --- a/source/util.c +++ b/source/util.c @@ -93,7 +93,7 @@ void openscop_util_strings_idump(FILE * file, // Print the original parameter names. for (i = 0; i <= level; i++) fprintf(file, "|\t"); - if (nb_strings > 0) { + if ((strings != NULL) && (nb_strings > 0)) { fprintf(file, "+-- %s:", title); for (i = 0; i < nb_strings; i++) fprintf(file, " %s", strings[i]); @@ -125,7 +125,7 @@ void openscop_util_strings_print(FILE * file, char * title) { int i; - if ((print != 0) && (nb_strings > 0)) { + if ((print != 0) && (strings != NULL) && (nb_strings > 0)) { fprintf(file, "# %s are provided\n", title); fprintf(file, "1\n"); fprintf(file, "# %s\n", title); diff --git a/tests/polynom.scop b/tests/polynom.scop index 0448d70..622108a 100644 --- a/tests/polynom.scop +++ b/tests/polynom.scop @@ -42,16 +42,6 @@ CONTEXT # Parameter names N -# Iterator names are provided -1 -# Iterator names -i j - -# Scattering dimension names are provided -1 -# Scattering dimension names -c0 c1 c2 c3 c4 - # Number of statements 1 diff --git a/tests/test_empty_statement.scop b/tests/test_empty_statement.scop index 4b135ee..32a07e9 100644 --- a/tests/test_empty_statement.scop +++ b/tests/test_empty_statement.scop @@ -11,12 +11,6 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # One statement 1 diff --git a/tests/test_just_access.scop b/tests/test_just_access.scop index 8d9f60a..9ee5197 100644 --- a/tests/test_just_access.scop +++ b/tests/test_just_access.scop @@ -11,12 +11,6 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # One statement 1 diff --git a/tests/test_just_body.scop b/tests/test_just_body.scop index 6c6c1ec..98c8f93 100644 --- a/tests/test_just_body.scop +++ b/tests/test_just_body.scop @@ -11,12 +11,6 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # One statement 1 diff --git a/tests/test_just_domain.scop b/tests/test_just_domain.scop index 9183c01..4ecc51e 100644 --- a/tests/test_just_domain.scop +++ b/tests/test_just_domain.scop @@ -11,12 +11,6 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # One statement 1 diff --git a/tests/test_just_scattering.scop b/tests/test_just_scattering.scop index 3947edc..21340eb 100644 --- a/tests/test_just_scattering.scop +++ b/tests/test_just_scattering.scop @@ -11,12 +11,6 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # One statement 1 diff --git a/tests/test_matmult.scop b/tests/test_matmult.scop index 211dca3..4fb62ba 100644 --- a/tests/test_matmult.scop +++ b/tests/test_matmult.scop @@ -16,14 +16,6 @@ CONTEXT # Parameter names N -# Iterator names are provided -1 -# Iterator names -a b c - -# Scattering dimension names are not provided -0 - # Number of statements 2 diff --git a/tests/test_no_statement.scop b/tests/test_no_statement.scop index 4b86589..45d799a 100644 --- a/tests/test_no_statement.scop +++ b/tests/test_no_statement.scop @@ -11,11 +11,5 @@ CONTEXT # Parameter names are not provided 0 -# Iterator names are not provided -0 - -# Scattering dimension names are not provided -0 - # No statement 0 -- 2.11.4.GIT