Initialize names in scop_malloc()
[openscop.git] / source / scop.c
blob2641ec6274b3ce1f674ade14dff4ab8c1c24e0fd
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
86 openscop_scop_print_structure(FILE * file, openscop_scop_p scop, int level)
88 int j;
90 // Go to the right level.
91 for (j = 0; j < level; j++)
92 fprintf(file, "|\t");
94 if (scop != NULL)
96 fprintf(file, "+-- openscop_scop_t\n");
98 // A blank line.
99 for (j = 0; j <= level+1; j++)
100 fprintf(file, "|\t");
101 fprintf(file, "\n");
103 // Print the language.
104 for (j = 0; j < level; j++)
105 fprintf(file, "|\t");
106 fprintf(file, "|\tLanguage: %s\n", scop->language);
108 // A blank line.
109 for (j = 0; j <= level+1; j++)
110 fprintf(file, "|\t");
111 fprintf(file, "\n");
113 // Print the context of the scop.
114 openscop_relation_print_structure(file, scop->context, level+1);
116 // Print the names.
117 openscop_names_print_structure(file, scop->names, level+1);
119 // Print the statements.
120 openscop_statement_print_structure(file, scop->statement, level+1);
122 // Print the extensions.
123 openscop_extension_print_structure(file, scop->extension, level+1);
125 // A blank line.
126 for (j = 0; j <= level+1; j++)
127 fprintf(file, "|\t");
128 fprintf(file, "\n");
130 else
132 fprintf(file, "+-- NULL scop\n");
135 // The last line.
136 for (j = 0; j <= level; j++)
137 fprintf(file, "|\t");
138 fprintf(file, "\n");
143 * openscop_scop_print function:
144 * this function prints the content of an openscop_scop_t structure (*scop)
145 * into a file (file, possibly stdout).
146 * \param file The file where the information has to be printed.
147 * \param scop The scop structure whose information has to be printed.
149 void
150 openscop_scop_print(FILE * file, openscop_scop_p scop)
152 openscop_scop_print_structure(file, scop, 0);
157 * openscop_scop_name_limits function:
158 * this function finds the (maximum) number of various elements of a scop and
159 * return the values through parameters. To ensure the correctness of the
160 * results, an integrity check of the input scop should be run before calling
161 * this function.
162 * \param scop The scop to analyse.
163 * \parem nb_parameters The number of parameters in the scop (output).
164 * \parem nb_iterators The number of iterators in the scop (output).
165 * \parem nb_scattdims The number of scattdims in the scop (output).
166 * \parem nb_localdims The number of local dimensions in the scop (output).
167 * \parem nb_arrays The number of arrays in the scop (output).
169 static
170 void
171 openscop_scop_name_limits(openscop_scop_p scop,
172 int * nb_parameters,
173 int * nb_iterators,
174 int * nb_scattdims,
175 int * nb_localdims,
176 int * nb_arrays)
178 int i, k, tmp, coef, id;
179 openscop_statement_p statement;
180 openscop_relation_list_p list;
182 // * The number of parameters is collected from the context,
183 // - in matrix format we compute it from the context using #columns,
184 // - in relation format it corresponds to the #parameters field.
185 // * The numbers of local dimensions are collected from all relations
186 // in the corresponding field, it is 0 for matrix format.
187 *nb_parameters = 0;
188 *nb_localdims = 0;
189 if (scop->context != NULL)
191 if (openscop_relation_is_matrix(scop->context))
193 *nb_parameters = scop->context->nb_columns - 2;
195 else
197 *nb_parameters = scop->context->nb_parameters;
198 *nb_localdims = scop->context->nb_local_dims;
202 *nb_iterators = 0;
203 *nb_scattdims = 0;
204 *nb_arrays = 0;
205 statement = scop->statement;
206 while (statement != NULL)
208 // * The number of iterators are defined by iteration domains,
209 // - in matrix format we compute it using #columns and #parameters,
210 // - in relation format it corresponds to the #output_dims.
211 if (statement->domain != NULL)
213 if (openscop_relation_is_matrix(statement->domain))
215 tmp = statement->domain->nb_columns - *nb_parameters - 2;
216 if (tmp > *nb_iterators)
217 *nb_iterators = tmp;
219 else
221 if (statement->domain->nb_output_dims > *nb_iterators)
222 *nb_iterators = statement->domain->nb_output_dims;
224 if (statement->domain->nb_local_dims > *nb_localdims)
225 *nb_localdims = statement->domain->nb_local_dims;
229 // * The number of scattdims are defined by scattering,
230 // - in matrix format it corresponds to the number of rows,
231 // - in relation format it corresponds to the #input_dims.
232 if (statement->scattering != NULL)
234 if (openscop_relation_is_matrix(statement->scattering))
236 if (statement->domain->nb_rows > *nb_scattdims)
237 *nb_scattdims = statement->scattering->nb_rows;
239 else
241 if (statement->scattering->nb_input_dims > *nb_scattdims)
242 *nb_scattdims = statement->scattering->nb_input_dims;
244 if (statement->scattering->nb_local_dims > *nb_localdims)
245 *nb_localdims = statement->scattering->nb_local_dims;
249 // * The number of arrays are defined by accesses,
250 // - in matrix format, array identifiers are m[0][0],
251 // - in relation format, array identifiers are
252 // m[i][#columns -1] / m[i][1], with i the (supposedly only) row
253 // where m[i][1] is not 0.
254 for (k = 0; k < 2; k++)
256 if (k == 0)
257 list = statement->read;
258 else
259 list = statement->write;
261 while (list != NULL)
263 if (list->elt != NULL)
265 if (openscop_relation_is_matrix(list->elt))
267 if (SCOPINT_get_si(list->elt->m[0][0]) > *nb_arrays)
268 *nb_arrays = SCOPINT_get_si(list->elt->m[0][0]);
270 else
272 for (i = 0; i < list->elt->nb_rows; i++)
274 coef = SCOPINT_get_si(list->elt->m[i][1]);
275 if (coef != 0)
277 id = SCOPINT_get_si(list->elt->m[0][list->elt->nb_columns-1]);
278 if (abs(id / coef) > *nb_arrays)
279 *nb_arrays = abs(id / coef);
283 if (statement->scattering->nb_local_dims > *nb_localdims)
284 *nb_localdims = statement->scattering->nb_local_dims;
288 list = list->next;
292 statement = statement->next;
298 * openscop_scop_full_names function:
299 * this function generates an openscop_names_p structure which contains
300 * enough names for the scop provided as parameter, for each kind of names.
301 * If the names contained in the input scop are not sufficient, this function
302 * generated the missing names.
303 * \param scop The scop we need a name for each element.
304 * \return A set of names for the scop.
306 static
307 openscop_names_p
308 openscop_scop_full_names(openscop_scop_p scop)
310 int nb_parameters;
311 int nb_iterators;
312 int nb_scattdims;
313 int nb_localdims;
314 int nb_arrays;
315 openscop_arrays_p arrays;
316 openscop_names_p names;
318 names = openscop_names_copy(scop->names);
320 // Extract array names information from extensions.
321 openscop_util_strings_free(names->arrays, names->nb_arrays);
322 arrays = (openscop_arrays_p)openscop_extension_lookup(scop->extension,
323 OPENSCOP_EXTENSION_ARRAYS);
324 names->arrays = openscop_arrays_generate_names(arrays,
325 &(names->nb_arrays));
327 // Complete names if necessary.
328 openscop_scop_name_limits(scop, &nb_parameters,
329 &nb_iterators,
330 &nb_scattdims,
331 &nb_localdims,
332 &nb_arrays);
334 openscop_util_strings_complete(&names->parameters, &names->nb_parameters,
335 "P_", nb_parameters);
337 openscop_util_strings_complete(&names->iterators, &names->nb_iterators,
338 "i_", nb_iterators);
340 openscop_util_strings_complete(&names->scattdims, &names->nb_scattdims,
341 "s_", nb_scattdims);
343 openscop_util_strings_complete(&names->localdims, &names->nb_localdims,
344 "l_", nb_localdims);
346 openscop_util_strings_complete(&names->arrays, &names->nb_arrays,
347 "A_", nb_arrays);
349 return names;
354 * openscop_scop_print_openscop function:
355 * this function prints the content of an openscop_scop_t structure (*scop)
356 * into a file (file, possibly stdout) in the OpenScop textual format.
357 * \param file The file where the information has to be printed.
358 * \param scop The scop structure whose information has to be printed.
360 void
361 openscop_scop_print_openscop(FILE * file, openscop_scop_p scop)
363 openscop_names_p names;
365 if (openscop_scop_integrity_check(scop) == 0)
367 fprintf(stderr, "[OpenScop] Error: OpenScop integrity check failed.\n");
368 exit(1);
371 // Build a name structure for pretty printing of relations.
372 names = openscop_scop_full_names(scop);
374 if (0)
376 fprintf(file, "# \n");
377 fprintf(file, "# <| \n");
378 fprintf(file, "# A \n");
379 fprintf(file, "# /.\\ \n");
380 fprintf(file, "# <| [\"\"M# \n");
381 fprintf(file, "# A | # Clan McCloog Castle \n");
382 fprintf(file, "# /.\\ [\"\"M# [Generated by the OpenScop ");
383 fprintf(file, "Library %s %s bits]\n",OPENSCOP_RELEASE, OPENSCOP_VERSION);
384 fprintf(file, "# [\"\"M# | # U\"U#U \n");
385 fprintf(file, "# | # | # \\ .:/ \n");
386 fprintf(file, "# | # | #___| # \n");
387 fprintf(file, "# | \"--' .-\" \n");
388 fprintf(file, "# |\"-\"-\"-\"-\"-#-#-## \n");
389 fprintf(file, "# | # ## ###### \n");
390 fprintf(file, "# \\ .::::'/ \n");
391 fprintf(file, "# \\ ::::'/ \n");
392 fprintf(file, "# :8a| # # ## \n");
393 fprintf(file, "# ::88a ### \n");
394 fprintf(file, "# ::::888a 8a ##::. \n");
395 fprintf(file, "# ::::::888a88a[]:::: \n");
396 fprintf(file, "# :::::::::SUNDOGa8a::::. .. \n");
397 fprintf(file, "# :::::8::::888:Y8888:::::::::... \n");
398 fprintf(file, "#::':::88::::888::Y88a______________________________");
399 fprintf(file, "________________________\n");
400 fprintf(file, "#:: ::::88a::::88a:Y88a ");
401 fprintf(file, " __---__-- __\n");
402 fprintf(file, "#' .: ::Y88a:::::8a:Y88a ");
403 fprintf(file, "__----_-- -------_-__\n");
404 fprintf(file, "# :' ::::8P::::::::::88aa. _ _- -");
405 fprintf(file, "- --_ --- __ --- __--\n");
406 fprintf(file, "#.:: :::::::::::::::::::Y88as88a...s88aa.\n");
408 else
410 fprintf(file, "# [File generated by the OpenScop Library %s %s bits]\n",
411 OPENSCOP_RELEASE,OPENSCOP_VERSION);
414 fprintf(file, "\nOpenScop\n\n");
415 fprintf(file, "# =============================================== Global\n");
416 fprintf(file, "# Language\n");
417 fprintf(file, "%s\n\n", scop->language);
419 fprintf(file, "# Context\n");
420 openscop_relation_print_openscop(file, scop->context,
421 OPENSCOP_TYPE_DOMAIN, names);
422 fprintf(file, "\n");
424 openscop_names_print_openscop(file, scop->names);
426 fprintf(file, "# Number of statements\n");
427 fprintf(file, "%d\n\n",openscop_statement_number(scop->statement));
429 openscop_statement_print_openscop(file, scop->statement, names);
431 if (scop->extension)
433 fprintf(file, "# ==============================================="
434 " Extensions\n");
435 openscop_extension_print_openscop(file, scop->extension);
438 openscop_names_free(names);
442 /*****************************************************************************
443 * Reading function *
444 *****************************************************************************/
447 static
448 void
449 openscop_scop_update_val(int * variable, int value)
451 if ((*variable == OPENSCOP_UNDEFINED) || (*variable == value))
452 *variable = value;
453 else
454 fprintf(stderr, "[OpenScop] Warning: number of iterators and "
455 "parameters inconsistency.\n");
458 static
459 void
460 openscop_scop_update_properties(openscop_relation_p relation,
461 int nb_output_dims, int nb_input_dims,
462 int nb_parameters)
464 if (relation != NULL)
466 openscop_scop_update_val(&(relation->nb_output_dims), nb_output_dims);
467 openscop_scop_update_val(&(relation->nb_input_dims), nb_input_dims);
468 openscop_scop_update_val(&(relation->nb_parameters), nb_parameters);
474 * openscop_scop_propagate_properties internal function:
475 * This function tries to propagate information in all relations through the
476 * whole openscop representation. For instance, the number of parameters can
477 * be found in the context as well as in any relation: if it is undefined in
478 * the relation, this function defines it, if it is different than the
479 * expected value, it reports an error. This function does the same for
480 * the number of output and input dimensions.
481 * \param scop The SCoP we want to propagate properties.
483 static
484 void
485 openscop_scop_propagate_properties(openscop_scop_p scop)
487 int i, nb_parameters;
488 openscop_statement_p statement;
489 openscop_relation_p relation;
490 openscop_relation_list_p list;
492 // Context part: get the number of parameters.
493 if ((scop->context != NULL) &&
494 (openscop_relation_is_matrix(scop->context)))
496 nb_parameters = scop->context->nb_columns - 2;
497 openscop_scop_update_properties(scop->context, 0, 0, nb_parameters);
499 else
500 return;
502 // For each statement:
503 statement = scop->statement;
504 while (statement != NULL)
506 // - Domain part,
507 relation = statement->domain;
508 if (openscop_relation_is_matrix(relation))
510 while (relation != NULL)
512 openscop_scop_update_properties(relation,
513 relation->nb_columns - nb_parameters - 2, 0, nb_parameters);
514 relation = relation->next;
518 // - Scattering part,
519 relation = statement->scattering;
520 if (openscop_relation_is_matrix(relation))
522 while (relation != NULL)
524 openscop_scop_update_properties(relation,
525 0, relation->nb_columns - nb_parameters - 2, nb_parameters);
526 relation = relation->next;
530 // - Access part.
531 for (i = 0; i < 2; i++)
533 if (i == 0)
534 list = statement->read;
535 else
536 list = statement->write;
538 while (list != NULL)
540 relation = list->elt;
541 if (openscop_relation_is_matrix(relation))
543 while (relation != NULL)
545 openscop_scop_update_properties(relation,
546 0, relation->nb_columns - nb_parameters - 2, nb_parameters);
547 relation = relation->next;
551 list = list->next;
555 statement = statement->next;
561 * openscop_scop_read function:
562 * this function reads a scop structure from a file (possibly stdin)
563 * complying to the OpenScop textual format and returns a pointer to this
564 * scop structure. If some relation properties (number of input/output/local
565 * dimensions and number of parameters) are undefined, it will define them
566 * according to the available information.
567 * \param file The file where the scop has to be read.
568 * \return A pointer to the scop structure that has been read.
570 openscop_scop_p
571 openscop_scop_read(FILE * file)
573 openscop_scop_p scop = NULL;
574 openscop_statement_p stmt = NULL;
575 openscop_statement_p prev = NULL;
576 int nb_statements;
577 int max;
578 char ** tmp;
579 int i;
581 if (file == NULL)
582 return NULL;
584 scop = openscop_scop_malloc();
587 // I. CONTEXT PART
590 // Ensure the file is a .scop.
591 tmp = openscop_util_strings_read(file, &max);
592 if ((max == 0) || (strcmp(*tmp, "OpenScop")))
594 fprintf(stderr, "[OpenScop] Error: not an OpenScop file "
595 "(type \"%s\".\n", *tmp);
596 exit (1);
598 if (max > 1)
599 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
600 "(after file type).\n");
601 free(*tmp);
602 free(tmp);
604 // Read the language.
605 char ** language = openscop_util_strings_read(file, &max);
606 if (max == 0)
608 fprintf(stderr, "[OpenScop] Error: no language (backend) specified.\n");
609 exit (1);
611 if (max > 1)
612 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
613 "(after language).\n");
614 scop->language = *language;
615 free(language);
617 // Read the context.
618 scop->context = openscop_relation_read(file);
619 scop->names = openscop_names_read(file);
622 // II. STATEMENT PART
625 // Read the number of statements.
626 nb_statements = openscop_util_read_int(file, NULL);
628 for (i = 0; i < nb_statements; ++i)
630 // Read each statement.
631 stmt = openscop_statement_read(file);
632 if (scop->statement == NULL)
633 scop->statement = stmt;
634 else
635 prev->next = stmt;
636 prev = stmt;
640 // III. OPTION PART
643 // Read the remainder of the file, and store it in the extension field.
644 scop->extension = openscop_extension_read(file);
647 // VI. FINALIZE AND CHECK
649 openscop_scop_propagate_properties(scop);
651 if (!openscop_scop_integrity_check(scop))
652 fprintf(stderr, "[OpenScop] Warning: global integrity check failed.\n");
654 return scop;
658 /*+***************************************************************************
659 * Memory allocation/deallocation functions *
660 *****************************************************************************/
664 * openscop_scop_malloc function:
665 * this function allocates the memory space for a openscop_scop_t structure and
666 * sets its fields with default values. Then it returns a pointer to the
667 * allocated space.
668 * \return A pointer to an empty scop with fields set to default values.
670 openscop_scop_p
671 openscop_scop_malloc()
673 openscop_scop_p scop;
675 scop = (openscop_scop_p)malloc(sizeof(openscop_scop_t));
676 if (scop == NULL)
678 fprintf(stderr, "[OpenScop] Memory Overflow.\n");
679 exit(1);
682 scop->version = 1;
683 scop->language = NULL;
684 scop->context = NULL;
685 scop->names = NULL;
686 scop->statement = NULL;
687 scop->extension = NULL;
688 scop->usr = NULL;
690 return scop;
695 * openscop_scop_free function:
696 * This function frees the allocated memory for a openscop_scop_t structure.
697 * \param scop The pointer to the scop we want to free.
699 void
700 openscop_scop_free(openscop_scop_p scop)
702 if (scop != NULL)
704 if (scop->language != NULL)
705 free(scop->language);
707 openscop_relation_free(scop->context);
708 openscop_names_free(scop->names);
709 openscop_statement_free(scop->statement);
710 openscop_extension_free(scop->extension);
712 free(scop);
717 /*+***************************************************************************
718 * Processing functions *
719 *****************************************************************************/
723 * openscop_scop_copy function:
724 * This functions builds and returns a "hard copy" (not a pointer copy)
725 * of a openscop_statement_t data structure provided as parameter.
726 * Note that the usr field is not touched by this function.
727 * \param statement The pointer to the scop we want to copy.
728 * \return A pointer to the full copy of the scop provided as parameter.
730 openscop_scop_p
731 openscop_scop_copy(openscop_scop_p scop)
733 openscop_scop_p copy;
735 copy = openscop_scop_malloc();
736 copy->version = scop->version;
737 if (scop->language != NULL)
738 copy->language = strdup(scop->language);
739 copy->context = openscop_relation_copy(scop->context);
740 copy->names = openscop_names_copy(scop->names);
741 copy->statement = openscop_statement_copy(scop->statement);
742 copy->extension = openscop_extension_copy(scop->extension);
744 return copy;
749 * openscop_scop_equal function:
750 * this function returns true if the two scops are the same, false
751 * otherwise (the usr field is not tested).
752 * \param s1 The first scop.
753 * \param s2 The second scop.
754 * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise.
757 openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2)
759 if (s1->version != s2->version)
761 fprintf(stderr, "[OpenScop] info: versions are not the same.\n");
762 //return 0;
765 if (strcmp(s1->language, s2->language) != 0)
767 fprintf(stderr, "[OpenScop] info: languages are not the same.\n");
768 return 0;
771 if (!openscop_relation_equal(s1->context, s2->context))
773 fprintf(stderr, "[OpenScop] info: contexts are not the same.\n");
774 return 0;
777 if (!openscop_names_equal(s1->names, s2->names))
779 fprintf(stderr, "[OpenScop] info: names are not the same.\n");
780 return 0;
783 if (!openscop_statement_equal(s1->statement, s2->statement))
785 fprintf(stderr, "[OpenScop] info: statements are not the same.\n");
786 return 0;
789 if (!openscop_extension_equal(s1->extension, s2->extension))
791 fprintf(stderr, "[OpenScop] info: extensions are not the same.\n");
792 return 0;
795 return 1;
802 * openscop_scop_integrity_check function:
803 * This function checks that a scop is "well formed". It returns 0 if the
804 * check failed or 1 if no problem has been detected.
805 * \param scop The scop we want to check.
806 * \return 0 if the integrity check fails, 1 otherwise.
809 openscop_scop_integrity_check(openscop_scop_p scop)
811 int expected_nb_parameters;
812 int max_nb_parameters;
813 int max_nb_iterators;
814 int max_nb_scattdims;
815 int max_nb_localdims;
816 int max_nb_arrays;
818 // Check the language.
819 if ((scop->language != NULL) &&
820 (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") ||
821 !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml")))
822 fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!\n");
824 // Check the context.
825 if (openscop_relation_is_matrix(scop->context))
827 if (!openscop_relation_integrity_check(scop->context,
828 OPENSCOP_TYPE_CONTEXT,
829 OPENSCOP_UNDEFINED,
830 OPENSCOP_UNDEFINED,
831 OPENSCOP_UNDEFINED))
832 return 0;
834 // Get the number of parameters.
835 if (scop->context != NULL)
837 if (openscop_relation_is_matrix(scop->context))
838 expected_nb_parameters = scop->context->nb_columns - 2;
839 else
840 expected_nb_parameters = scop->context->nb_parameters;
842 else
843 expected_nb_parameters = OPENSCOP_UNDEFINED;
845 if (!openscop_statement_integrity_check(scop->statement,
846 expected_nb_parameters))
847 return 0;
849 // Ensure we have enough names.
850 openscop_scop_name_limits(scop, &max_nb_parameters,
851 &max_nb_iterators,
852 &max_nb_scattdims,
853 &max_nb_localdims,
854 &max_nb_arrays);
856 return openscop_names_integrity_check(scop->names, expected_nb_parameters,
857 max_nb_iterators, max_nb_scattdims);