From a18a72068ee5a30103bca9b2093812ffb1b11f84 Mon Sep 17 00:00:00 2001 From: Cedric Bastoul Date: Mon, 18 Jul 2011 11:45:02 +0200 Subject: [PATCH] Addition of a next field to the scop structure --- doc/openscop.texi | 43 +++-- include/Makefile.am | 3 +- include/openscop/scop.h.in | 17 +- include/openscop/scop_list.h | 124 ------------ source/Makefile.am | 1 - source/scop.c | 438 +++++++++++++++++++++++-------------------- source/scop_list.c | 327 -------------------------------- tests/openscop_test.c | 2 +- tests/test_scop_list.scop | 70 +++++++ 9 files changed, 339 insertions(+), 686 deletions(-) delete mode 100644 include/openscop/scop_list.h delete mode 100644 source/scop_list.c create mode 100644 tests/test_scop_list.scop diff --git a/doc/openscop.texi b/doc/openscop.texi index 2d59cd5..0ca8745 100644 --- a/doc/openscop.texi +++ b/doc/openscop.texi @@ -1961,9 +1961,9 @@ typedef struct openscop_statement * openscop_statement_p; @end group @end example -@noindent The @code{openscop_statement_t} structure represents a @code{NULL} -terminated linked list of statements. Each node contains the useful -information for a given statement to process it within a polyhedral +@noindent The @code{openscop_statement_t} structure represents a node +in a @code{NULL}-terminated linked list of statements. Each node contains the +useful information for a given statement to process it within a polyhedral framework. The order in the list may matter for naming conventions (e.g. "S1" for the first statement in the list). The iteration domain and the scattering are represented using an @code{openscop_relation_p} @@ -2004,14 +2004,14 @@ typedef struct openscop_extension_id * openscop_extension_id_p; @end group @end example -@noindent The @code{openscop_extension_id_t} structure stores the +@noindent The @code{openscop_extension_id_t} structure represents a +node in a @code{NULL}-terminated list of extension ids. Each node stores the @emph{identity} of an extension, i.e., its unique name (@code{URI}) and the function pointers to all the base functions it has to provide. Extension providers will find information relative to those functions in the OpenScop Library description (@pxref{Base Functions}) and the section dedicated to writing extensions -(@pxref{Extension Development}). The @code{openscop_extension_id_t} -structure is a node in a NULL-terminated list of extension ids. +(@pxref{Extension Development}). @node openscop_extension_t @subsubsection openscop_extension_t @@ -2028,12 +2028,12 @@ typedef struct openscop_extension * openscop_extension_p; @end group @end example -@noindent The @code{openscop_extension_t} structure stores an extension to the core -OpenScop representation. It is a node of a @code{NULL}-terminated linked list of -extensions. The @code{id} field gives the identity of what is pointed by the -@code{extension} field. An OpenScop implementation is not required to support -any extension. It must warn the user that a given identity is not -supported and ignore it during the processing. +@noindent The @code{openscop_extension_t} structure represents a node in a +@code{NULL}-terminated list of extensions. It stores an extension to the core +OpenScop representation. The @code{id} field gives the identity of what is +pointed by the @code{extension} field. An OpenScop implementation is not +required to support any extension. It must warn the user that a given identity +is not supported and ignore it during the processing. @node openscop_scop_t @subsubsection openscop_scop_t @@ -2049,16 +2049,18 @@ struct openscop_scop @{ openscop_extension_id_p registry; /* List of registered extensions */ openscop_extension_p extension; /* Extension list */ void * usr; /* A user-defined field */ + struct openscop_scop * next; /* Next scop in the list */ @}; typedef struct openscop_scop openscop_scop_t; typedef struct openscop_scop * openscop_scop_p; @end group @end example -@noindent @code{openscop_scop_t} stores the useful informations of a static -control part of a program to process it within a polyhedral framework. -To prepare OpenScop specification evolution, the @code{version} field -tells the version of the data structure. It should be set to 1 for +@noindent @code{openscop_scop_t} represents a node in a +@code{NULL}-terminated list of scops. It stores the useful informations +of a static control part of a program to process it within a polyhedral +framework. To prepare OpenScop specification evolution, the @code{version} +field tells the version of the data structure. It should be set to 1 for now (and hopefully a very, very, long time). It contains the informations about the context: the target language in the @code{language} field, the constraints on the @@ -2881,15 +2883,16 @@ important data structure (e.g., @code{struct foo}) has its own header file (@code{include/openscop/foo.h}) where lies the definition of the data structure, the two typedefs for the data structure (one for the structure, @code{openscop_foo_t}, and one for a pointer -to the structure, @code{openscop_foo_p}) and the prototypes of the various -functions related to this data structure (all named using the -prefix "@code{openscop_foo_"}. The source code of the functions is provided in a +to the structure, @code{openscop_foo_p}), the prototypes of the various +functions related to this data structure, all named using the +prefix "@code{openscop_foo_}". The source code of the functions is provided in a separated C file (@code{source/foo.c}). Utility functions independent from the main data structures may be placed in separate source files (e.g., definition in @code{include/openscop/util.h} and code in @code{source/util.c}). Tool-wide preprocessor directives are -placed in @code{include/openscop/macros.h}. +placed in @code{include/openscop/macros.h}, macros are prefixed with +"@code{OPENSCOP_}". The core code itself has to be written according to the Google C++ Coding Style: @url{http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml} (for diff --git a/include/Makefile.am b/include/Makefile.am index 9f7eeb5..23064fc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -94,5 +94,4 @@ pkginclude_HEADERS = \ openscop/names.h \ openscop/strings.h \ openscop/util.h \ - openscop/scop.h \ - openscop/scop_list.h + openscop/scop.h diff --git a/include/openscop/scop.h.in b/include/openscop/scop.h.in index f0356d8..0616ab5 100644 --- a/include/openscop/scop.h.in +++ b/include/openscop/scop.h.in @@ -103,13 +103,13 @@ 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 *) when - * the type field is OPENSCOP_TYPE_STRING or a generic pointer to anything - * else (void *) when the type field is OPENSCOP_TYPE_GENERIC. The OpenScop - * library does not touch AT ALL generic information: printing, copy etc. must - * be done externally. + * The scop_t structure stores a list of scops. Each node 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 *) when the type field is OPENSCOP_TYPE_STRING or a generic pointer + * to anything else (void *) when the type field is OPENSCOP_TYPE_GENERIC. + * 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 */ @@ -122,6 +122,7 @@ struct openscop_scop { openscop_extension_p extension; /**< Extension list */ void * usr; /**< A user-defined field, not touched AT ALL by the OpenScop Library */ + struct openscop_scop * next; /**< Next statement in the linked list */ }; typedef struct openscop_scop openscop_scop_t; typedef struct openscop_scop * openscop_scop_p; @@ -154,6 +155,8 @@ void openscop_scop_free(openscop_scop_p); openscop_scop_p openscop_scop_clone(openscop_scop_p); int openscop_scop_equal(openscop_scop_p, openscop_scop_p); int openscop_scop_integrity_check(openscop_scop_p); +void openscop_scop_register_extension(openscop_scop_p, + openscop_extension_id_p); # if defined(__cplusplus) diff --git a/include/openscop/scop_list.h b/include/openscop/scop_list.h deleted file mode 100644 index 56eca3c..0000000 --- a/include/openscop/scop_list.h +++ /dev/null @@ -1,124 +0,0 @@ - - /*+-----------------------------------------------------------------** - ** OpenScop Library ** - **-----------------------------------------------------------------** - ** scop_list.h ** - **-----------------------------------------------------------------** - ** First version: 14/07/2011 ** - **-----------------------------------------------------------------** - - - ***************************************************************************** - * OpenScop: Structures and formats for polyhedral tools to talk together * - ***************************************************************************** - * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, * - * / / / // // // // / / / // // / / // / /|,_, * - * / / / // // // // / / / // // / / // / / / /\ * - * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ * - * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ * - * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ * - * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ * - * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ * - * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ * - * | I | | | | e | | | | | | | | | | | | | \ \ \ * - * | T | | | | | | | | | | | | | | | | | \ \ \ * - * | E | | | | | | | | | | | | | | | | | \ \ \ * - * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ * - * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / * - * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' * - * * - * Copyright (C) 2008 University Paris-Sud 11 and INRIA * - * * - * (3-clause BSD license) * - * Redistribution and use in source and binary forms, with or without * - * modification, are permitted provided that the following conditions * - * are met: * - * * - * 1. Redistributions of source code must retain the above copyright notice, * - * this list of conditions and the following disclaimer. * - * 2. Redistributions in binary form must reproduce the above copyright * - * notice, this list of conditions and the following disclaimer in the * - * documentation and/or other materials provided with the distribution. * - * 3. The name of the author may not be used to endorse or promote products * - * derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * * - * OpenScop Library, a library to manipulate OpenScop formats and data * - * structures. Written by: * - * Cedric Bastoul and * - * Louis-Noel Pouchet * - * * - *****************************************************************************/ - - -#ifndef OPENSCOP_SCOP_LIST_H -# define OPENSCOP_SCOP_LIST_H - -# include -# include -# include - - -# if defined(__cplusplus) -extern "C" - { -# endif - - -/** - * The openscop_scop_list_t structure describes a (NULL-terminated - * linked) list of scops. - */ -struct openscop_scop_list { - openscop_scop_p elt; /**< An element of the list. */ - struct openscop_scop_list * next; /**< Pointer to the next element - of the list.*/ -}; -typedef struct openscop_scop_list openscop_scop_list_t; -typedef struct openscop_scop_list * openscop_scop_list_p; - - -/*+*************************************************************************** - * Structure display function * - *****************************************************************************/ -void openscop_scop_list_idump(FILE *, openscop_scop_list_p, int); -void openscop_scop_list_dump(FILE *, openscop_scop_list_p); -void openscop_scop_list_print(FILE *, openscop_scop_list_p); - - -/***************************************************************************** - * Reading function * - *****************************************************************************/ -openscop_scop_list_p openscop_scop_list_read(FILE *); - - -/*+*************************************************************************** - * Memory allocation/deallocation function * - *****************************************************************************/ -openscop_scop_list_p openscop_scop_list_malloc(); -void openscop_scop_list_free(openscop_scop_list_p); - - -/*+*************************************************************************** - * Processing functions * - *****************************************************************************/ -openscop_scop_list_p openscop_scop_list_clone(openscop_scop_list_p); -int openscop_scop_list_equal(openscop_scop_list_p, - openscop_scop_list_p); -int openscop_scop_list_integrity_check(openscop_scop_list_p); - - -# if defined(__cplusplus) - } -# endif -#endif /* define OPENSCOP_SCOP_LIST_H */ diff --git a/source/Makefile.am b/source/Makefile.am index ddb642a..b8046ff 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -84,7 +84,6 @@ lib_LTLIBRARIES = libopenscop.la libopenscop_la_SOURCES = \ scop.c \ - scop_list.c \ statement.c \ extensions/textual.c \ extensions/comment.c \ diff --git a/source/scop.c b/source/scop.c index b06a522..f8d1326 100644 --- a/source/scop.c +++ b/source/scop.c @@ -83,14 +83,26 @@ * \param level Number of spaces before printing, for each line. */ void openscop_scop_idump(FILE * file, openscop_scop_p scop, int level) { - int j; + int j, first = 1; // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); - if (scop != NULL) { + if (scop != NULL) fprintf(file, "+-- openscop_scop_t\n"); + else + fprintf(file, "+-- NULL scop\n"); + + while (scop != NULL) { + if (!first) { + // Go to the right level. + for (j = 0; j < level; j++) + fprintf(file, "|\t"); + fprintf(file, "| openscop_scop_t\n"); + } + else + first = 0; // A blank line. for (j = 0; j <= level+1; j++) @@ -135,13 +147,19 @@ void openscop_scop_idump(FILE * file, openscop_scop_p scop, int level) { // Print the extensions. openscop_extension_idump(file, scop->extension, level+1); + scop = scop->next; + // A blank line. for (j = 0; j <= level+1; j++) fprintf(file, "|\t"); fprintf(file, "\n"); - } - else { - fprintf(file, "+-- NULL scop\n"); + + // Next line. + if (scop != NULL) { + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "V\n"); + } } // The last line. @@ -305,72 +323,43 @@ void openscop_scop_print(FILE * file, openscop_scop_p scop) { fprintf(file, "# NULL scop\n"); return; } - - if (openscop_scop_integrity_check(scop) == 0) - OPENSCOP_warning("OpenScop integrity check failed. " - "Something may go wrong"); - - if (0) { - fprintf(file, "# \n"); - fprintf(file, "# <| \n"); - fprintf(file, "# A \n"); - fprintf(file, "# /.\\ \n"); - fprintf(file, "# <| [\"\"M# \n"); - fprintf(file, "# A | # Clan McCloog Castle \n"); - fprintf(file, "# /.\\ [\"\"M# [Generated by the OpenScop "); - fprintf(file, "Library %s %s bits]\n",OPENSCOP_RELEASE, OPENSCOP_VERSION); - fprintf(file, "# [\"\"M# | # U\"U#U \n"); - fprintf(file, "# | # | # \\ .:/ \n"); - fprintf(file, "# | # | #___| # \n"); - fprintf(file, "# | \"--' .-\" \n"); - fprintf(file, "# |\"-\"-\"-\"-\"-#-#-## \n"); - fprintf(file, "# | # ## ###### \n"); - fprintf(file, "# \\ .::::'/ \n"); - fprintf(file, "# \\ ::::'/ \n"); - fprintf(file, "# :8a| # # ## \n"); - fprintf(file, "# ::88a ### \n"); - fprintf(file, "# ::::888a 8a ##::. \n"); - fprintf(file, "# ::::::888a88a[]:::: \n"); - fprintf(file, "# :::::::::SUNDOGa8a::::. .. \n"); - fprintf(file, "# :::::8::::888:Y8888:::::::::... \n"); - fprintf(file, "#::':::88::::888::Y88a______________________________"); - fprintf(file, "________________________\n"); - fprintf(file, "#:: ::::88a::::88a:Y88a "); - fprintf(file, " __---__-- __\n"); - fprintf(file, "#' .: ::Y88a:::::8a:Y88a "); - fprintf(file, "__----_-- -------_-__\n"); - fprintf(file, "# :' ::::8P::::::::::88aa. _ _- -"); - fprintf(file, "- --_ --- __ --- __--\n"); - fprintf(file, "#.:: :::::::::::::::::::Y88as88a...s88aa.\n"); - } else { fprintf(file, "# [File generated by the OpenScop Library %s %s bits]\n", OPENSCOP_RELEASE,OPENSCOP_VERSION); } - fprintf(file, "\n"OPENSCOP_TAG_START_SCOP"\n\n"); - fprintf(file, "# =============================================== Global\n"); - fprintf(file, "# Language\n"); - fprintf(file, "%s\n\n", scop->language); - - fprintf(file, "# Context\n"); - openscop_relation_print(file, scop->context, NULL); - fprintf(file, "\n"); + if (openscop_scop_integrity_check(scop) == 0) + OPENSCOP_warning("OpenScop integrity check failed. " + "Something may go wrong."); + + while (scop != NULL) { + fprintf(file, "\n"OPENSCOP_TAG_START_SCOP"\n\n"); + fprintf(file, "# =============================================== " + "Global\n"); + fprintf(file, "# Language\n"); + fprintf(file, "%s\n\n", scop->language); + + fprintf(file, "# Context\n"); + openscop_relation_print(file, scop->context, NULL); + fprintf(file, "\n"); - openscop_strings_print(file, (char **)scop->parameters, 1, - (scop->parameter_type == OPENSCOP_TYPE_STRING), "Parameters"); + openscop_strings_print(file, (char **)scop->parameters, 1, + (scop->parameter_type == OPENSCOP_TYPE_STRING), "Parameters"); - fprintf(file, "# Number of statements\n"); - fprintf(file, "%d\n\n",openscop_statement_number(scop->statement)); + fprintf(file, "# Number of statements\n"); + fprintf(file, "%d\n\n",openscop_statement_number(scop->statement)); - openscop_statement_print(file, scop->statement, NULL); + openscop_statement_print(file, scop->statement, NULL); - if (scop->extension) { - fprintf(file, "# ===============================================" - " Extensions\n"); - openscop_extension_print(file, scop->extension); + if (scop->extension) { + fprintf(file, "# =============================================== " + "Extensions\n"); + openscop_extension_print(file, scop->extension); + } + fprintf(file, "\n"OPENSCOP_TAG_END_SCOP"\n\n"); + + scop = scop->next; } - fprintf(file, "\n"OPENSCOP_TAG_END_SCOP"\n\n"); } @@ -381,93 +370,106 @@ void openscop_scop_print(FILE * file, openscop_scop_p scop) { /** * openscop_scop_read function: - * this function reads a scop structure from a file (possibly stdin) + * 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 structure. If some relation properties (number of input/output/local + * 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 file The file where the scop has to be read. * \return A pointer to the scop structure that has been read. */ openscop_scop_p openscop_scop_read(FILE * file) { - openscop_scop_p scop = NULL; + openscop_scop_p list = NULL, current = NULL, scop; openscop_statement_p stmt = NULL; openscop_statement_p prev = NULL; int nb_statements, nb_parameters; char * tmp, ** language; + int first = 1; int i; if (file == NULL) return NULL; - // - // I. START TAG - // - tmp = openscop_util_read_uptotag(file, OPENSCOP_TAG_START_SCOP); - free(tmp); - if (feof(file)) { - OPENSCOP_info("no more scop in the file"); - return NULL; - } + while(1) { + // + // I. START TAG + // + tmp = openscop_util_read_uptotag(file, OPENSCOP_TAG_START_SCOP); + free(tmp); + if (feof(file)) { + OPENSCOP_info("no more scop in the file"); + break; + } - scop = openscop_scop_malloc(); - - // - // II. CONTEXT PART - // - - // Read the language. - language = openscop_strings_read(file); - if (openscop_strings_size(language) == 0) - OPENSCOP_error("no language (backend) specified"); - - if (openscop_strings_size(language) > 1) - OPENSCOP_warning("uninterpreted information (after language)"); - - scop->language = *language; - free(language); - - // Read the context domain. - scop->context = openscop_relation_read(file); - - // Read the parameters. - scop->parameter_type = OPENSCOP_TYPE_STRING; - if (openscop_util_read_int(file, NULL) > 0) { - scop->parameters = (void **)openscop_strings_read(file); - nb_parameters = openscop_strings_size((char **)scop->parameters); - if ((scop->context != NULL) && - (nb_parameters != scop->context->nb_parameters)) - OPENSCOP_warning("bad number of parameters"); - } + scop = openscop_scop_malloc(); - // - // III. STATEMENT PART - // + // + // II. CONTEXT PART + // - // Read the number of statements. - nb_statements = openscop_util_read_int(file, NULL); + // Read the language. + language = openscop_strings_read(file); + if (openscop_strings_size(language) == 0) + OPENSCOP_error("no language (backend) specified"); - for (i = 0; i < nb_statements; i++) { - // Read each statement. - stmt = openscop_statement_read(file); - if (scop->statement == NULL) - scop->statement = stmt; - else - prev->next = stmt; - prev = stmt; - } + if (openscop_strings_size(language) > 1) + OPENSCOP_warning("uninterpreted information (after language)"); + + scop->language = *language; + free(language); + + // Read the context domain. + scop->context = openscop_relation_read(file); + + // Read the parameters. + scop->parameter_type = OPENSCOP_TYPE_STRING; + if (openscop_util_read_int(file, NULL) > 0) { + scop->parameters = (void **)openscop_strings_read(file); + nb_parameters = openscop_strings_size((char **)scop->parameters); + if ((scop->context != NULL) && + (nb_parameters != scop->context->nb_parameters)) + OPENSCOP_warning("bad number of parameters"); + } + + // + // III. STATEMENT PART + // + + // Read the number of statements. + nb_statements = openscop_util_read_int(file, NULL); + + for (i = 0; i < nb_statements; i++) { + // Read each statement. + stmt = openscop_statement_read(file); + if (scop->statement == NULL) + scop->statement = stmt; + else + prev->next = stmt; + prev = stmt; + } - // - // IV. EXTENSION PART (TO THE END TAG) - // + // + // IV. EXTENSION PART (TO THE END TAG) + // - // Read up the end tag (if any), and store extensions in the extension field. - scop->extension = openscop_extension_read(file, scop->registry); + // Read up the end tag (if any), and store extensions in the extension field. + scop->extension = openscop_extension_read(file, scop->registry); + + // Add the new scop to the list. + if (first) { + list = scop; + first = 0; + } + else { + current->next = scop; + } + current = scop; + } - if (!openscop_scop_integrity_check(scop)) + if (!openscop_scop_integrity_check(list)) OPENSCOP_warning("scop integrity check failed"); - return scop; + return list; } @@ -512,7 +514,8 @@ openscop_scop_p openscop_scop_malloc() { scop->statement = NULL; scop->registry = NULL; scop->extension = NULL; - scop->usr = NULL; + scop->usr = NULL; + scop->next = NULL; openscop_scop_register_default_extensions(scop); return scop; @@ -525,17 +528,21 @@ openscop_scop_p openscop_scop_malloc() { * \param scop The pointer to the scop we want to free. */ void openscop_scop_free(openscop_scop_p scop) { - if (scop != NULL) { + openscop_scop_p tmp; + + while (scop != NULL) { if (scop->language != NULL) free(scop->language); - - openscop_strings_free((char **)scop->parameters); + if (scop->parameter_type == OPENSCOP_TYPE_STRING) + openscop_strings_free((char **)scop->parameters); openscop_relation_free(scop->context); openscop_statement_free(scop->statement); openscop_extension_id_free(scop->registry); openscop_extension_free(scop->extension); + tmp = scop->next; free(scop); + scop = tmp; } } @@ -550,27 +557,41 @@ void openscop_scop_free(openscop_scop_p scop) { * This functions builds and returns a "hard copy" (not a pointer copy) * of a openscop_statement_t data structure provided as parameter. * Note that the usr field is not touched by this function. - * \param statement The pointer to the scop we want to copy. - * \return A pointer to the full copy of the scop provided as parameter. + * \param statement The pointer to the scop we want to clone. + * \return A pointer to the full clone of the scop provided as parameter. */ openscop_scop_p openscop_scop_clone(openscop_scop_p scop) { - openscop_scop_p copy = NULL; + openscop_scop_p clone = NULL, node, previous = NULL; + int first = 1; - if (scop != NULL) { - copy = openscop_scop_malloc(); - copy->version = scop->version; + while (scop != NULL) { + node = openscop_scop_malloc(); + node->version = scop->version; if (scop->language != NULL) - copy->language = strdup(scop->language); - copy->context = openscop_relation_clone(scop->context); - copy->parameter_type = scop->parameter_type; - copy->parameters = (void **)openscop_strings_clone( + node->language = strdup(scop->language); + node->context = openscop_relation_clone(scop->context); + node->parameter_type = scop->parameter_type; + if (node->parameter_type == OPENSCOP_TYPE_STRING) + node->parameters = (void **)openscop_strings_clone( (char **)scop->parameters); - copy->statement = openscop_statement_clone(scop->statement); - copy->registry = openscop_extension_id_clone(scop->registry); - copy->extension = openscop_extension_clone(scop->extension); + node->statement = openscop_statement_clone(scop->statement); + node->registry = openscop_extension_id_clone(scop->registry); + node->extension = openscop_extension_clone(scop->extension); + + if (first) { + first = 0; + clone = node; + previous = node; + } + else { + previous->next = node; + previous = previous->next; + } + + scop = scop->next; } - return copy; + return clone; } @@ -583,52 +604,59 @@ openscop_scop_p openscop_scop_clone(openscop_scop_p scop) { * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise. */ int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) { - - if (s1 == s2) - return 1; - if (s1->version != s2->version) { - OPENSCOP_info("versions are not the same"); - return 0; - } - - if (strcmp(s1->language, s2->language) != 0) { - OPENSCOP_info("languages are not the same"); - return 0; - } + while ((s1 != NULL) && (s2 != NULL)) { + if (s1 == s2) + return 1; - if (!openscop_relation_equal(s1->context, s2->context)) { - OPENSCOP_info("contexts are not the same"); - return 0; - } - - if (s1->parameter_type != s2->parameter_type) { - OPENSCOP_info("parameter types are not the same"); - return 0; - } + if (s1->version != s2->version) { + OPENSCOP_info("versions are not the same"); + return 0; + } - if ((s1->parameter_type == OPENSCOP_TYPE_STRING) && - (!openscop_strings_equal((char **)s1->parameters, - (char **)s2->parameters))) { - OPENSCOP_info("parameters are not the same"); - return 0; - } - - if (!openscop_statement_equal(s1->statement, s2->statement)) { - OPENSCOP_info("statements are not the same"); - return 0; + if (strcmp(s1->language, s2->language) != 0) { + OPENSCOP_info("languages are not the same"); + return 0; + } + + if (!openscop_relation_equal(s1->context, s2->context)) { + OPENSCOP_info("contexts are not the same"); + return 0; + } + + if (s1->parameter_type != s2->parameter_type) { + OPENSCOP_info("parameter types are not the same"); + return 0; + } + + if ((s1->parameter_type == OPENSCOP_TYPE_STRING) && + (!openscop_strings_equal((char **)s1->parameters, + (char **)s2->parameters))) { + OPENSCOP_info("parameters are not the same"); + return 0; + } + + if (!openscop_statement_equal(s1->statement, s2->statement)) { + OPENSCOP_info("statements are not the same"); + return 0; + } + + if (!openscop_extension_id_equal(s1->registry, s2->registry)) { + OPENSCOP_info("registries are not the same"); + return 0; + } + + if (!openscop_extension_equal(s1->extension, s2->extension)) { + OPENSCOP_info("extensions are not the same"); + return 0; + } + + s1 = s1->next; + s2 = s2->next; } - if (!openscop_extension_id_equal(s1->registry, s2->registry)) { - OPENSCOP_info("registries are not the same"); + if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL))) return 0; - } - - if (!openscop_extension_equal(s1->extension, s2->extension)) { - OPENSCOP_info("extensions are not the same"); - return 0; - } - return 1; } @@ -644,32 +672,34 @@ 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; - if (scop == NULL) - return 1; - // Check the language. - if ((scop->language != NULL) && - (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") || - !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml"))) - fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!?!\n"); - - // Check the context. - if (!openscop_relation_integrity_check(scop->context, - OPENSCOP_TYPE_CONTEXT, - OPENSCOP_UNDEFINED, - OPENSCOP_UNDEFINED, - OPENSCOP_UNDEFINED)) - return 0; + while (scop != NULL) { + // Check the language. + if ((scop->language != NULL) && + (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") || + !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml"))) + fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!?!\n"); + + // Check the context. + if (!openscop_relation_integrity_check(scop->context, + OPENSCOP_TYPE_CONTEXT, + OPENSCOP_UNDEFINED, + OPENSCOP_UNDEFINED, + OPENSCOP_UNDEFINED)) + return 0; + + // Get the number of parameters. + if (scop->context != NULL) + expected_nb_parameters = scop->context->nb_parameters; + else + expected_nb_parameters = OPENSCOP_UNDEFINED; - // Get the number of parameters. - if (scop->context != NULL) - expected_nb_parameters = scop->context->nb_parameters; - else - expected_nb_parameters = OPENSCOP_UNDEFINED; + if (!openscop_statement_integrity_check(scop->statement, + expected_nb_parameters)) + return 0; - if (!openscop_statement_integrity_check(scop->statement, - expected_nb_parameters)) - return 0; + scop = scop->next; + } return 1; } diff --git a/source/scop_list.c b/source/scop_list.c deleted file mode 100644 index 521408e..0000000 --- a/source/scop_list.c +++ /dev/null @@ -1,327 +0,0 @@ - - /*+-----------------------------------------------------------------** - ** OpenScop Library ** - **-----------------------------------------------------------------** - ** scop_list.c ** - **-----------------------------------------------------------------** - ** First version: 14/07/2011 ** - **-----------------------------------------------------------------** - - - ***************************************************************************** - * OpenScop: Structures and formats for polyhedral tools to talk together * - ***************************************************************************** - * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, * - * / / / // // // // / / / // // / / // / /|,_, * - * / / / // // // // / / / // // / / // / / / /\ * - * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ * - * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ * - * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ * - * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ * - * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ * - * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ * - * | I | | | | e | | | | | | | | | | | | | \ \ \ * - * | T | | | | | | | | | | | | | | | | | \ \ \ * - * | E | | | | | | | | | | | | | | | | | \ \ \ * - * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ * - * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / * - * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' * - * * - * Copyright (C) 2008 University Paris-Sud 11 and INRIA * - * * - * (3-clause BSD license) * - * Redistribution and use in source and binary forms, with or without * - * modification, are permitted provided that the following conditions * - * are met: * - * * - * 1. Redistributions of source code must retain the above copyright notice, * - * this list of conditions and the following disclaimer. * - * 2. Redistributions in binary form must reproduce the above copyright * - * notice, this list of conditions and the following disclaimer in the * - * documentation and/or other materials provided with the distribution. * - * 3. The name of the author may not be used to endorse or promote products * - * derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * * - * OpenScop Library, a library to manipulate OpenScop formats and data * - * structures. Written by: * - * Cedric Bastoul and * - * Louis-Noel Pouchet * - * * - *****************************************************************************/ - - -# include -# include -# include - - -/*+*************************************************************************** - * Structure display function * - *****************************************************************************/ - - -/** - * openscop_scop_list_idump function: - * this function displays a openscop_scop_list_t structure (*list) into a - * file (file, possibly stdout) in a way that trends to be understandable. - * It includes an indentation level (level) in order to work with others - * print_structure functions. - * \param[in] file File where informations are printed. - * \param[in] list The scop_list whose information has to be printed. - * \param[in] level Number of spaces before printing, for each line. - */ -void openscop_scop_list_idump(FILE * file, - openscop_scop_list_p list, - int level) { - int j, first = 1; - - // Go to the right level. - for (j = 0; j < level; j++) - fprintf(file, "|\t"); - - if (list != NULL) - fprintf(file, "+-- openscop_scop_list_t\n"); - else - fprintf(file, "+-- NULL scop list\n"); - - while (list != NULL) { - if (!first) { - // Go to the right level. - for (j = 0; j < level; j++) - fprintf(file, "|\t"); - fprintf(file, "| openscop_scop_list_t\n"); - } - else - first = 0; - - // A blank line. - for (j = 0; j <= level+1; j++) - fprintf(file, "|\t"); - fprintf(file, "\n"); - - // Print a relation. - openscop_scop_idump(file, list->elt, level+1); - - list = list->next; - - // Next line. - if (list != NULL) { - for (j = 0; j <= level; j++) - fprintf(file, "|\t"); - fprintf(file, "V\n"); - } - } - - // The last line. - for (j = 0; j <= level; j++) - fprintf(file, "|\t"); - fprintf(file, "\n"); -} - - -/** - * openscop_scop_list_dump function: - * this function prints the content of a openscop_scop_list_t structure - * (*scop_list) into a file (file, possibly stdout). - * \param[in] file File where informations are printed. - * \param[in] list The scop_list whose information have to be printed. - */ -void openscop_scop_list_dump(FILE * file, openscop_scop_list_p list) { - openscop_scop_list_idump(file, list, 0); -} - - -/** - * openscop_scop_list_print function: - * this function prints the content of an openscop_scop_list_t structure - * (*list) into a file (file, possibly stdout) in the OpenScop format. - * \param[in] file File where informations are printed. - * \param[in] list The list whose information has to be printed. - */ -void openscop_scop_list_print(FILE * file, openscop_scop_list_p list) { - - if (list == NULL) { - fprintf(file,"# NULL scop list\n"); - } - else { - while(list != NULL) { - openscop_scop_print(file, list->elt); - fprintf(file, "\n"); - list = list->next; - } - } -} - - -/***************************************************************************** - * Reading function * - *****************************************************************************/ - - -/** - * openscop_scop_list_read function: - * this function reads a scop list into a file (foo, posibly stdin) and - * returns a pointer this list. - * \param[in] file The input stream. - * \return A pointer to the scop list structure that has been read. - */ -openscop_scop_list_p openscop_scop_list_read(FILE * file) { - openscop_scop_p scop; - openscop_scop_list_p list = NULL, current = NULL, node; - int first = 1; - - while ((scop = openscop_scop_read(file)) != NULL) { - node = openscop_scop_list_malloc(); - node->elt = scop; - if (first) { - list = node; - first = 0; - } - else { - current->next = node; - } - current = node; - } - - return list; -} - - -/*+*************************************************************************** - * Memory allocation/deallocation function * - *****************************************************************************/ - - -/** - * openscop_scop_list_malloc function: - * this function allocates the memory space for a openscop_scop_list_t - * structure and sets its fields with default values. Then it returns a - * pointer to the allocated space. - * \return A pointer to an empty scop list with fields set to default values. - */ -openscop_scop_list_p openscop_scop_list_malloc() { - openscop_scop_list_p list; - - OPENSCOP_malloc(list, openscop_scop_list_p, sizeof(openscop_scop_list_t)); - list->elt = NULL; - list->next = NULL; - - return list; -} - - -/** - * openscop_scop_list_free function: - * this function frees the allocated memory for a openscop_scop_list_t - * structure. - * \param[in,out] list The pointer to the scop_list we want to free. - */ -void openscop_scop_list_free(openscop_scop_list_p list) { - openscop_scop_list_p tmp; - - if (list == NULL) - return; - - while (list != NULL) { - if (list->elt != NULL) - openscop_scop_free(list->elt); - tmp = list->next; - free(list); - list = tmp; - } -} - - -/*+*************************************************************************** - * Processing functions * - *****************************************************************************/ - - -/** - * openscop_scop_list_clone function: - * this function builds and returns a "hard copy" (not a pointer copy) of an - * openscop_scop_list_t data structure (the full union of scop_list). - * \param[in] list The pointer to the scop list we want to clone. - * \return A pointer to the clone of the scop list. - */ -openscop_scop_list_p openscop_scop_list_clone(openscop_scop_list_p list) { - openscop_scop_list_p clone = NULL, node, previous = NULL; - int first = 1; - - while (list != NULL) { - node = openscop_scop_list_malloc(); - node->elt = openscop_scop_clone(list->elt); - - if (first) { - first = 0; - clone = node; - previous = node; - } - else { - previous->next = node; - previous = previous->next; - } - - list = list->next; - } - - return clone; -} - - -/** - * openscop_scop_list_equal function: - * this function returns true if the two scop lists provided as parameters - * are the same, false otherwise. - * \param[in] l1 The first list. - * \param[in] l2 The second list. - * \return 1 if l1 and l2 are the same (content-wise), 0 otherwise. - */ -int openscop_scop_list_equal(openscop_scop_list_p l1, openscop_scop_list_p l2) { - while ((l1 != NULL) && (l2 != NULL)) { - if (l1 == l2) - return 1; - - if (!openscop_scop_equal(l1->elt, l2->elt)) - return 0; - - l1 = l1->next; - l2 = l2->next; - } - - if (((l1 == NULL) && (l2 != NULL)) || ((l1 != NULL) && (l2 == NULL))) - return 0; - - return 1; -} - - -/** - * openscop_scop_list_integrity_check function: - * this function checks that a scop list is "well formed" according to - * OpenScop specifications. It returns 0 if the check failed or 1 if no - * problem has been detected. - * \param[in] list The scop_list we want to check. - * \return 0 if the integrity check fails, 1 otherwise. - */ -int openscop_scop_list_integrity_check(openscop_scop_list_p list) { - - while (list != NULL) { - if (openscop_scop_integrity_check(list->elt) == 0) - return 0; - - list = list->next; - } - return 1; -} diff --git a/tests/openscop_test.c b/tests/openscop_test.c index 9612922..777834a 100644 --- a/tests/openscop_test.c +++ b/tests/openscop_test.c @@ -68,7 +68,7 @@ #include #include -#define FORK // Comment that if you want only one process +//#define FORK // Comment that if you want only one process // (best for debugging with valgrind but bad // for make check since any error will // stop the job). diff --git a/tests/test_scop_list.scop b/tests/test_scop_list.scop new file mode 100644 index 0000000..d24e74f --- /dev/null +++ b/tests/test_scop_list.scop @@ -0,0 +1,70 @@ + + +# =============================================== Global +# Language +C + +# Context +CONTEXT +0 2 0 0 0 0 + +# Parameter names are not provided +0 + +# One statement +1 + +# =============================================== Statement 1 +# Number of relations describing the statement +0 + +# ---------------------------------------------- 1.1 Domain +# NULL Domain + +# ---------------------------------------------- 1.2 Scattering +# NULL Scattering + +# ---------------------------------------------- 1.3 Access +# NULL Access + +# ---------------------------------------------- 1.4 Body +# Statement body is not provided +0 + + + + + +# =============================================== Global +# Language +C + +# Context +CONTEXT +0 2 0 0 0 0 + +# Parameter names are not provided +0 + +# One statement +1 + +# =============================================== Statement 1 +# Number of relations describing the statement +0 + +# ---------------------------------------------- 1.1 Domain +# NULL Domain + +# ---------------------------------------------- 1.2 Scattering +# NULL Scattering + +# ---------------------------------------------- 1.3 Access +# NULL Access + +# ---------------------------------------------- 1.4 Body +# Statement body is not provided +0 + + + -- 2.11.4.GIT