Switch to Google coding style
[openscop.git] / source / scop.c
blobf8fb1eba4e42f2447a330cea9787f9b4956a8ec5
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
4 **-----------------------------------------------------------------**
5 ** scop.c **
6 **-----------------------------------------------------------------**
7 ** First version: 30/04/2008 **
8 **-----------------------------------------------------------------**
11 *****************************************************************************
12 * OpenScop: Structures and formats for polyhedral tools to talk together *
13 *****************************************************************************
14 * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15 * / / / // // // // / / / // // / / // / /|,_, *
16 * / / / // // // // / / / // // / / // / / / /\ *
17 * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18 * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19 * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20 * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21 * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22 * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23 * | I | | | | e | | | | | | | | | | | | | \ \ \ *
24 * | T | | | | | | | | | | | | | | | | | \ \ \ *
25 * | E | | | | | | | | | | | | | | | | | \ \ \ *
26 * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27 * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29 * *
30 * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31 * *
32 * (3-clause BSD license) *
33 * Redistribution and use in source and binary forms, with or without *
34 * modification, are permitted provided that the following conditions *
35 * are met: *
36 * *
37 * 1. Redistributions of source code must retain the above copyright notice, *
38 * this list of conditions and the following disclaimer. *
39 * 2. Redistributions in binary form must reproduce the above copyright *
40 * notice, this list of conditions and the following disclaimer in the *
41 * documentation and/or other materials provided with the distribution. *
42 * 3. The name of the author may not be used to endorse or promote products *
43 * derived from this software without specific prior written permission. *
44 * *
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
55 * *
56 * OpenScop Library, a library to manipulate OpenScop formats and data *
57 * structures. Written by: *
58 * Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59 * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr> *
60 * *
61 *****************************************************************************/
63 # include <stdlib.h>
64 # include <stdio.h>
65 # include <ctype.h>
66 # include <string.h>
67 # include <openscop/scop.h>
70 /*+***************************************************************************
71 * Structure display functions *
72 *****************************************************************************/
75 /**
76 * openscop_scop_print_structure function:
77 * this function displays an openscop_scop_t structure (*scop) into a
78 * file (file, possibly stdout) in a way that trends to be understandable. It
79 * includes an indentation level (level) in order to work with others
80 * print_structure functions.
81 * \param file The file where the information has to be printed.
82 * \param scop The scop structure whose information has to be printed.
83 * \param level Number of spaces before printing, for each line.
85 void openscop_scop_print_structure(FILE * file, openscop_scop_p scop,
86 int level) {
87 int j;
89 // Go to the right level.
90 for (j = 0; j < level; j++)
91 fprintf(file, "|\t");
93 if (scop != NULL) {
94 fprintf(file, "+-- openscop_scop_t\n");
96 // A blank line.
97 for (j = 0; j <= level+1; j++)
98 fprintf(file, "|\t");
99 fprintf(file, "\n");
101 // Print the language.
102 for (j = 0; j < level; j++)
103 fprintf(file, "|\t");
104 fprintf(file, "|\tLanguage: %s\n", scop->language);
106 // A blank line.
107 for (j = 0; j <= level+1; j++)
108 fprintf(file, "|\t");
109 fprintf(file, "\n");
111 // Print the context of the scop.
112 openscop_relation_print_structure(file, scop->context, level+1);
114 // Print the names.
115 openscop_names_print_structure(file, scop->names, level+1);
117 // Print the statements.
118 openscop_statement_print_structure(file, scop->statement, level+1);
120 // Print the extensions.
121 openscop_extension_print_structure(file, scop->extension, level+1);
123 // A blank line.
124 for (j = 0; j <= level+1; j++)
125 fprintf(file, "|\t");
126 fprintf(file, "\n");
128 else {
129 fprintf(file, "+-- NULL scop\n");
132 // The last line.
133 for (j = 0; j <= level; j++)
134 fprintf(file, "|\t");
135 fprintf(file, "\n");
140 * openscop_scop_print function:
141 * this function prints the content of an openscop_scop_t structure (*scop)
142 * into a file (file, possibly stdout).
143 * \param file The file where the information has to be printed.
144 * \param scop The scop structure whose information has to be printed.
146 void openscop_scop_print(FILE * file, openscop_scop_p scop) {
147 openscop_scop_print_structure(file, scop, 0);
152 * openscop_scop_name_limits function:
153 * this function finds the (maximum) number of various elements of a scop and
154 * return the values through parameters. To ensure the correctness of the
155 * results, an integrity check of the input scop should be run before calling
156 * this function.
157 * \param scop The scop to analyse.
158 * \parem nb_parameters The number of parameters in the scop (output).
159 * \parem nb_iterators The number of iterators in the scop (output).
160 * \parem nb_scattdims The number of scattdims in the scop (output).
161 * \parem nb_localdims The number of local dimensions in the scop (output).
162 * \parem nb_arrays The number of arrays in the scop (output).
164 static
165 void openscop_scop_name_limits(openscop_scop_p scop,
166 int * nb_parameters,
167 int * nb_iterators,
168 int * nb_scattdims,
169 int * nb_localdims,
170 int * nb_arrays) {
171 int i, k, tmp, coef, id;
172 openscop_statement_p statement;
173 openscop_relation_list_p list;
175 // * The number of parameters is collected from the context,
176 // - in matrix format we compute it from the context using #columns,
177 // - in relation format it corresponds to the #parameters field.
178 // * The numbers of local dimensions are collected from all relations
179 // in the corresponding field, it is 0 for matrix format.
180 *nb_parameters = 0;
181 *nb_localdims = 0;
182 if (scop->context != NULL) {
183 if (openscop_relation_is_matrix(scop->context)) {
184 *nb_parameters = scop->context->nb_columns - 2;
186 else {
187 *nb_parameters = scop->context->nb_parameters;
188 *nb_localdims = scop->context->nb_local_dims;
192 *nb_iterators = 0;
193 *nb_scattdims = 0;
194 *nb_arrays = 0;
195 statement = scop->statement;
196 while (statement != NULL) {
197 // * The number of iterators are defined by iteration domains,
198 // - in matrix format we compute it using #columns and #parameters,
199 // - in relation format it corresponds to the #output_dims.
200 if (statement->domain != NULL) {
201 if (openscop_relation_is_matrix(statement->domain)) {
202 tmp = statement->domain->nb_columns - *nb_parameters - 2;
203 if (tmp > *nb_iterators)
204 *nb_iterators = tmp;
206 else {
207 if (statement->domain->nb_output_dims > *nb_iterators)
208 *nb_iterators = statement->domain->nb_output_dims;
210 if (statement->domain->nb_local_dims > *nb_localdims)
211 *nb_localdims = statement->domain->nb_local_dims;
215 // * The number of scattdims are defined by scattering,
216 // - in matrix format it corresponds to the number of rows,
217 // - in relation format it corresponds to the #input_dims.
218 if (statement->scattering != NULL) {
219 if (openscop_relation_is_matrix(statement->scattering)) {
220 if (statement->domain->nb_rows > *nb_scattdims)
221 *nb_scattdims = statement->scattering->nb_rows;
223 else {
224 if (statement->scattering->nb_input_dims > *nb_scattdims)
225 *nb_scattdims = statement->scattering->nb_input_dims;
227 if (statement->scattering->nb_local_dims > *nb_localdims)
228 *nb_localdims = statement->scattering->nb_local_dims;
232 // * The number of arrays are defined by accesses,
233 // - in matrix format, array identifiers are m[0][0],
234 // - in relation format, array identifiers are
235 // m[i][#columns -1] / m[i][1], with i the (supposedly only) row
236 // where m[i][1] is not 0.
237 for (k = 0; k < 2; k++) {
238 if (k == 0)
239 list = statement->read;
240 else
241 list = statement->write;
243 while (list != NULL) {
244 if (list->elt != NULL) {
245 if (openscop_relation_is_matrix(list->elt)) {
246 if (SCOPINT_get_si(list->elt->m[0][0]) > *nb_arrays)
247 *nb_arrays = SCOPINT_get_si(list->elt->m[0][0]);
249 else {
250 for (i = 0; i < list->elt->nb_rows; i++) {
251 coef = SCOPINT_get_si(list->elt->m[i][1]);
252 if (coef != 0) {
253 id = SCOPINT_get_si(list->elt->m[0][list->elt->nb_columns-1]);
254 if (abs(id / coef) > *nb_arrays)
255 *nb_arrays = abs(id / coef);
259 if (statement->scattering->nb_local_dims > *nb_localdims)
260 *nb_localdims = statement->scattering->nb_local_dims;
264 list = list->next;
268 statement = statement->next;
274 * openscop_scop_full_names function:
275 * this function generates an openscop_names_p structure which contains
276 * enough names for the scop provided as parameter, for each kind of names.
277 * If the names contained in the input scop are not sufficient, this function
278 * generated the missing names.
279 * \param scop The scop we need a name for each element.
280 * \return A set of names for the scop.
282 static
283 openscop_names_p openscop_scop_full_names(openscop_scop_p scop) {
284 int nb_parameters;
285 int nb_iterators;
286 int nb_scattdims;
287 int nb_localdims;
288 int nb_arrays;
289 openscop_arrays_p arrays;
290 openscop_names_p names;
292 names = openscop_names_copy(scop->names);
294 // Extract array names information from extensions.
295 openscop_util_strings_free(names->arrays, names->nb_arrays);
296 arrays = (openscop_arrays_p)openscop_extension_lookup(scop->extension,
297 OPENSCOP_EXTENSION_ARRAYS);
298 names->arrays = openscop_arrays_generate_names(arrays,
299 &(names->nb_arrays));
301 // Complete names if necessary.
302 openscop_scop_name_limits(scop, &nb_parameters,
303 &nb_iterators,
304 &nb_scattdims,
305 &nb_localdims,
306 &nb_arrays);
308 openscop_util_strings_complete(&names->parameters, &names->nb_parameters,
309 "P_", nb_parameters);
311 openscop_util_strings_complete(&names->iterators, &names->nb_iterators,
312 "i_", nb_iterators);
314 openscop_util_strings_complete(&names->scattdims, &names->nb_scattdims,
315 "s_", nb_scattdims);
317 openscop_util_strings_complete(&names->localdims, &names->nb_localdims,
318 "l_", nb_localdims);
320 openscop_util_strings_complete(&names->arrays, &names->nb_arrays,
321 "A_", nb_arrays);
323 return names;
328 * openscop_scop_print_openscop function:
329 * this function prints the content of an openscop_scop_t structure (*scop)
330 * into a file (file, possibly stdout) in the OpenScop textual format.
331 * \param file The file where the information has to be printed.
332 * \param scop The scop structure whose information has to be printed.
334 void openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) {
335 openscop_names_p names;
336 int tmp_nb_iterators = 0;
337 char ** tmp_iterators = NULL;
339 if (openscop_scop_integrity_check(scop) == 0) {
340 fprintf(stderr, "[OpenScop] Error: OpenScop integrity check failed.\n");
341 exit(1);
344 // Build a name structure for pretty printing of relations.
345 names = openscop_scop_full_names(scop);
347 if (0) {
348 fprintf(file, "# \n");
349 fprintf(file, "# <| \n");
350 fprintf(file, "# A \n");
351 fprintf(file, "# /.\\ \n");
352 fprintf(file, "# <| [\"\"M# \n");
353 fprintf(file, "# A | # Clan McCloog Castle \n");
354 fprintf(file, "# /.\\ [\"\"M# [Generated by the OpenScop ");
355 fprintf(file, "Library %s %s bits]\n",OPENSCOP_RELEASE, OPENSCOP_VERSION);
356 fprintf(file, "# [\"\"M# | # U\"U#U \n");
357 fprintf(file, "# | # | # \\ .:/ \n");
358 fprintf(file, "# | # | #___| # \n");
359 fprintf(file, "# | \"--' .-\" \n");
360 fprintf(file, "# |\"-\"-\"-\"-\"-#-#-## \n");
361 fprintf(file, "# | # ## ###### \n");
362 fprintf(file, "# \\ .::::'/ \n");
363 fprintf(file, "# \\ ::::'/ \n");
364 fprintf(file, "# :8a| # # ## \n");
365 fprintf(file, "# ::88a ### \n");
366 fprintf(file, "# ::::888a 8a ##::. \n");
367 fprintf(file, "# ::::::888a88a[]:::: \n");
368 fprintf(file, "# :::::::::SUNDOGa8a::::. .. \n");
369 fprintf(file, "# :::::8::::888:Y8888:::::::::... \n");
370 fprintf(file, "#::':::88::::888::Y88a______________________________");
371 fprintf(file, "________________________\n");
372 fprintf(file, "#:: ::::88a::::88a:Y88a ");
373 fprintf(file, " __---__-- __\n");
374 fprintf(file, "#' .: ::Y88a:::::8a:Y88a ");
375 fprintf(file, "__----_-- -------_-__\n");
376 fprintf(file, "# :' ::::8P::::::::::88aa. _ _- -");
377 fprintf(file, "- --_ --- __ --- __--\n");
378 fprintf(file, "#.:: :::::::::::::::::::Y88as88a...s88aa.\n");
380 else {
381 fprintf(file, "# [File generated by the OpenScop Library %s %s bits]\n",
382 OPENSCOP_RELEASE,OPENSCOP_VERSION);
385 fprintf(file, "\nOpenScop\n\n");
386 fprintf(file, "# =============================================== Global\n");
387 fprintf(file, "# Language\n");
388 fprintf(file, "%s\n\n", scop->language);
390 fprintf(file, "# Context\n");
391 // Remove the iterators from the names structure to print comments, as
392 // this information is used to know the number of iterators.
393 // TODO: do this in openscop_relation_print_openscop
394 tmp_nb_iterators = names->nb_iterators;
395 tmp_iterators = names->iterators;
396 names->nb_iterators = 0;
397 names->iterators = NULL;
398 openscop_relation_print_openscop(file, scop->context,
399 OPENSCOP_TYPE_DOMAIN, names);
400 names->nb_iterators = tmp_nb_iterators;
401 names->iterators = tmp_iterators;
402 fprintf(file, "\n");
404 openscop_names_print_openscop(file, scop->names);
406 fprintf(file, "# Number of statements\n");
407 fprintf(file, "%d\n\n",openscop_statement_number(scop->statement));
409 openscop_statement_print_openscop(file, scop->statement, names);
411 if (scop->extension) {
412 fprintf(file, "# ==============================================="
413 " Extensions\n");
414 openscop_extension_print_openscop(file, scop->extension);
417 openscop_names_free(names);
421 /*****************************************************************************
422 * Reading function *
423 *****************************************************************************/
426 static
427 void openscop_scop_update_val(int * variable, int value) {
428 if ((*variable == OPENSCOP_UNDEFINED) || (*variable == value))
429 *variable = value;
430 else
431 fprintf(stderr, "[OpenScop] Warning: number of iterators and "
432 "parameters inconsistency.\n");
435 static
436 void openscop_scop_update_properties(openscop_relation_p relation,
437 int nb_output_dims, int nb_input_dims,
438 int nb_parameters) {
439 if (relation != NULL) {
440 openscop_scop_update_val(&(relation->nb_output_dims), nb_output_dims);
441 openscop_scop_update_val(&(relation->nb_input_dims), nb_input_dims);
442 openscop_scop_update_val(&(relation->nb_parameters), nb_parameters);
448 * openscop_scop_propagate_properties internal function:
449 * This function tries to propagate information in all relations through the
450 * whole openscop representation. For instance, the number of parameters can
451 * be found in the context as well as in any relation: if it is undefined in
452 * the relation, this function defines it, if it is different than the
453 * expected value, it reports an error. This function does the same for
454 * the number of output and input dimensions.
455 * \param scop The SCoP we want to propagate properties.
457 static
458 void openscop_scop_propagate_properties(openscop_scop_p scop) {
459 int i, nb_parameters;
460 openscop_statement_p statement;
461 openscop_relation_p relation;
462 openscop_relation_list_p list;
464 // Context part: get the number of parameters.
465 if ((scop->context != NULL) &&
466 (openscop_relation_is_matrix(scop->context))) {
467 nb_parameters = scop->context->nb_columns - 2;
468 openscop_scop_update_properties(scop->context, 0, 0, nb_parameters);
470 else {
471 return;
474 // For each statement:
475 statement = scop->statement;
476 while (statement != NULL) {
477 // - Domain part,
478 relation = statement->domain;
479 if (openscop_relation_is_matrix(relation)) {
480 while (relation != NULL) {
481 openscop_scop_update_properties(
482 relation, relation->nb_columns-nb_parameters-2, 0, nb_parameters);
483 relation = relation->next;
487 // - Scattering part,
488 relation = statement->scattering;
489 if (openscop_relation_is_matrix(relation)) {
490 while (relation != NULL) {
491 openscop_scop_update_properties(
492 relation, 0, relation->nb_columns-nb_parameters-2, nb_parameters);
493 relation = relation->next;
497 // - Access part.
498 for (i = 0; i < 2; i++) {
499 if (i == 0)
500 list = statement->read;
501 else
502 list = statement->write;
504 while (list != NULL) {
505 relation = list->elt;
506 if (openscop_relation_is_matrix(relation)) {
507 while (relation != NULL) {
508 openscop_scop_update_properties(
509 relation, 0, relation->nb_columns - nb_parameters - 2,
510 nb_parameters);
511 relation = relation->next;
515 list = list->next;
519 statement = statement->next;
525 * openscop_scop_read function:
526 * this function reads a scop structure from a file (possibly stdin)
527 * complying to the OpenScop textual format and returns a pointer to this
528 * scop structure. If some relation properties (number of input/output/local
529 * dimensions and number of parameters) are undefined, it will define them
530 * according to the available information.
531 * \param file The file where the scop has to be read.
532 * \return A pointer to the scop structure that has been read.
534 openscop_scop_p openscop_scop_read(FILE * file) {
535 openscop_scop_p scop = NULL;
536 openscop_statement_p stmt = NULL;
537 openscop_statement_p prev = NULL;
538 int nb_statements;
539 int max;
540 char ** tmp;
541 int i;
543 if (file == NULL)
544 return NULL;
546 scop = openscop_scop_malloc();
549 // I. CONTEXT PART
552 // Ensure the file is a .scop.
553 tmp = openscop_util_strings_read(file, &max);
554 if ((max == 0) || (strcmp(*tmp, "OpenScop"))) {
555 fprintf(stderr, "[OpenScop] Error: not an OpenScop file "
556 "(type \"%s\".\n", *tmp);
557 exit (1);
559 if (max > 1)
560 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
561 "(after file type).\n");
562 free(*tmp);
563 free(tmp);
565 // Read the language.
566 char ** language = openscop_util_strings_read(file, &max);
567 if (max == 0) {
568 fprintf(stderr, "[OpenScop] Error: no language (backend) specified.\n");
569 exit (1);
571 if (max > 1)
572 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
573 "(after language).\n");
574 scop->language = *language;
575 free(language);
577 // Read the context.
578 scop->context = openscop_relation_read(file);
579 scop->names = openscop_names_read(file);
582 // II. STATEMENT PART
585 // Read the number of statements.
586 nb_statements = openscop_util_read_int(file, NULL);
588 for (i = 0; i < nb_statements; ++i) {
589 // Read each statement.
590 stmt = openscop_statement_read(file);
591 if (scop->statement == NULL)
592 scop->statement = stmt;
593 else
594 prev->next = stmt;
595 prev = stmt;
599 // III. OPTION PART
602 // Read the remainder of the file, and store it in the extension field.
603 scop->extension = openscop_extension_read(file);
606 // VI. FINALIZE AND CHECK
608 openscop_scop_propagate_properties(scop);
610 if (!openscop_scop_integrity_check(scop))
611 fprintf(stderr, "[OpenScop] Warning: global integrity check failed.\n");
613 return scop;
617 /*+***************************************************************************
618 * Memory allocation/deallocation functions *
619 *****************************************************************************/
623 * openscop_scop_malloc function:
624 * this function allocates the memory space for a openscop_scop_t structure and
625 * sets its fields with default values. Then it returns a pointer to the
626 * allocated space.
627 * \return A pointer to an empty scop with fields set to default values.
629 openscop_scop_p openscop_scop_malloc() {
630 openscop_scop_p scop;
632 scop = (openscop_scop_p)malloc(sizeof(openscop_scop_t));
633 if (scop == NULL) {
634 fprintf(stderr, "[OpenScop] Memory Overflow.\n");
635 exit(1);
638 scop->version = 1;
639 scop->language = NULL;
640 scop->context = NULL;
641 scop->names = NULL;
642 scop->statement = NULL;
643 scop->extension = NULL;
644 scop->usr = NULL;
646 return scop;
651 * openscop_scop_free function:
652 * This function frees the allocated memory for a openscop_scop_t structure.
653 * \param scop The pointer to the scop we want to free.
655 void openscop_scop_free(openscop_scop_p scop) {
656 if (scop != NULL) {
657 if (scop->language != NULL)
658 free(scop->language);
660 openscop_relation_free(scop->context);
661 openscop_names_free(scop->names);
662 openscop_statement_free(scop->statement);
663 openscop_extension_free(scop->extension);
665 free(scop);
670 /*+***************************************************************************
671 * Processing functions *
672 *****************************************************************************/
676 * openscop_scop_copy function:
677 * This functions builds and returns a "hard copy" (not a pointer copy)
678 * of a openscop_statement_t data structure provided as parameter.
679 * Note that the usr field is not touched by this function.
680 * \param statement The pointer to the scop we want to copy.
681 * \return A pointer to the full copy of the scop provided as parameter.
683 openscop_scop_p openscop_scop_copy(openscop_scop_p scop) {
684 openscop_scop_p copy;
686 copy = openscop_scop_malloc();
687 copy->version = scop->version;
688 if (scop->language != NULL)
689 copy->language = strdup(scop->language);
690 copy->context = openscop_relation_copy(scop->context);
691 copy->names = openscop_names_copy(scop->names);
692 copy->statement = openscop_statement_copy(scop->statement);
693 copy->extension = openscop_extension_copy(scop->extension);
695 return copy;
700 * openscop_scop_equal function:
701 * this function returns true if the two scops are the same, false
702 * otherwise (the usr field is not tested).
703 * \param s1 The first scop.
704 * \param s2 The second scop.
705 * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise.
707 int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) {
708 if (s1->version != s2->version) {
709 fprintf(stderr, "[OpenScop] info: versions are not the same.\n");
710 //return 0;
713 if (strcmp(s1->language, s2->language) != 0) {
714 fprintf(stderr, "[OpenScop] info: languages are not the same.\n");
715 return 0;
718 if (!openscop_relation_equal(s1->context, s2->context)) {
719 fprintf(stderr, "[OpenScop] info: contexts are not the same.\n");
720 return 0;
723 if (!openscop_names_equal(s1->names, s2->names)) {
724 fprintf(stderr, "[OpenScop] info: names are not the same.\n");
725 return 0;
728 if (!openscop_statement_equal(s1->statement, s2->statement)) {
729 fprintf(stderr, "[OpenScop] info: statements are not the same.\n");
730 return 0;
733 if (!openscop_extension_equal(s1->extension, s2->extension)) {
734 fprintf(stderr, "[OpenScop] info: extensions are not the same.\n");
735 return 0;
738 return 1;
743 * openscop_scop_integrity_check function:
744 * This function checks that a scop is "well formed". It returns 0 if the
745 * check failed or 1 if no problem has been detected.
746 * \param scop The scop we want to check.
747 * \return 0 if the integrity check fails, 1 otherwise.
749 int openscop_scop_integrity_check(openscop_scop_p scop) {
750 int expected_nb_parameters;
751 int max_nb_parameters;
752 int max_nb_iterators;
753 int max_nb_scattdims;
754 int max_nb_localdims;
755 int max_nb_arrays;
757 // Check the language.
758 if ((scop->language != NULL) &&
759 (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") ||
760 !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml")))
761 fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!\n");
763 // Check the context.
764 if (openscop_relation_is_matrix(scop->context))
766 if (!openscop_relation_integrity_check(scop->context,
767 OPENSCOP_TYPE_CONTEXT,
768 OPENSCOP_UNDEFINED,
769 OPENSCOP_UNDEFINED,
770 OPENSCOP_UNDEFINED))
771 return 0;
773 // Get the number of parameters.
774 if (scop->context != NULL) {
775 if (openscop_relation_is_matrix(scop->context))
776 expected_nb_parameters = scop->context->nb_columns - 2;
777 else
778 expected_nb_parameters = scop->context->nb_parameters;
780 else
781 expected_nb_parameters = OPENSCOP_UNDEFINED;
783 if (!openscop_statement_integrity_check(scop->statement,
784 expected_nb_parameters))
785 return 0;
787 // Ensure we have enough names.
788 openscop_scop_name_limits(scop, &max_nb_parameters,
789 &max_nb_iterators,
790 &max_nb_scattdims,
791 &max_nb_localdims,
792 &max_nb_arrays);
794 return openscop_names_integrity_check(scop->names, expected_nb_parameters,
795 max_nb_iterators, max_nb_scattdims);