Rename string and _structure printing functions
[openscop.git] / source / scop.c
blob8b13aed3c13936cb8205a92ba401c33009a5e093
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_idump 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_idump(FILE * file, openscop_scop_p scop, int level) {
86 int j;
88 // Go to the right level.
89 for (j = 0; j < level; j++)
90 fprintf(file, "|\t");
92 if (scop != NULL) {
93 fprintf(file, "+-- openscop_scop_t\n");
95 // A blank line.
96 for (j = 0; j <= level+1; j++)
97 fprintf(file, "|\t");
98 fprintf(file, "\n");
100 // Print the language.
101 for (j = 0; j < level; j++)
102 fprintf(file, "|\t");
103 fprintf(file, "|\tLanguage: %s\n", scop->language);
105 // A blank line.
106 for (j = 0; j <= level+1; j++)
107 fprintf(file, "|\t");
108 fprintf(file, "\n");
110 // Print the context of the scop.
111 openscop_relation_idump(file, scop->context, level+1);
113 // Print the names.
114 openscop_names_idump(file, scop->names, level+1);
116 // Print the statements.
117 openscop_statement_idump(file, scop->statement, level+1);
119 // Print the extensions.
120 openscop_extension_idump(file, scop->extension, level+1);
122 // A blank line.
123 for (j = 0; j <= level+1; j++)
124 fprintf(file, "|\t");
125 fprintf(file, "\n");
127 else {
128 fprintf(file, "+-- NULL scop\n");
131 // The last line.
132 for (j = 0; j <= level; j++)
133 fprintf(file, "|\t");
134 fprintf(file, "\n");
139 * openscop_scop_dump function:
140 * this function prints the content of an openscop_scop_t structure (*scop)
141 * into a file (file, possibly stdout).
142 * \param file The file where the information has to be printed.
143 * \param scop The scop structure whose information has to be printed.
145 void openscop_scop_dump(FILE * file, openscop_scop_p scop) {
146 openscop_scop_idump(file, scop, 0);
151 * openscop_scop_name_limits function:
152 * this function finds the (maximum) number of various elements of a scop and
153 * return the values through parameters. To ensure the correctness of the
154 * results, an integrity check of the input scop should be run before calling
155 * this function.
156 * \param scop The scop to analyse.
157 * \parem nb_parameters The number of parameters in the scop (output).
158 * \parem nb_iterators The number of iterators in the scop (output).
159 * \parem nb_scattdims The number of scattdims in the scop (output).
160 * \parem nb_localdims The number of local dimensions in the scop (output).
161 * \parem nb_arrays The number of arrays in the scop (output).
163 static
164 void openscop_scop_name_limits(openscop_scop_p scop,
165 int * nb_parameters,
166 int * nb_iterators,
167 int * nb_scattdims,
168 int * nb_localdims,
169 int * nb_arrays) {
170 int k, tmp, array_id;
171 openscop_statement_p statement;
172 openscop_relation_list_p list;
174 // * The number of parameters is collected from the context,
175 // - in matrix format we compute it from the context using #columns,
176 // - in relation format it corresponds to the #parameters field.
177 // * The numbers of local dimensions are collected from all relations
178 // in the corresponding field, it is 0 for matrix format.
179 *nb_parameters = 0;
180 *nb_localdims = 0;
181 if (scop->context != NULL) {
182 if (openscop_relation_is_matrix(scop->context)) {
183 *nb_parameters = scop->context->nb_columns - 2;
185 else {
186 *nb_parameters = scop->context->nb_parameters;
187 *nb_localdims = scop->context->nb_local_dims;
191 *nb_iterators = 0;
192 *nb_scattdims = 0;
193 *nb_arrays = 0;
194 statement = scop->statement;
195 while (statement != NULL) {
196 // * The number of iterators are defined by iteration domains,
197 // - in matrix format we compute it using #columns and #parameters,
198 // - in relation format it corresponds to the #output_dims.
199 if (statement->domain != NULL) {
200 if (openscop_relation_is_matrix(statement->domain)) {
201 tmp = statement->domain->nb_columns - *nb_parameters - 2;
202 if (tmp > *nb_iterators)
203 *nb_iterators = tmp;
205 else {
206 if (statement->domain->nb_output_dims > *nb_iterators)
207 *nb_iterators = statement->domain->nb_output_dims;
209 if (statement->domain->nb_local_dims > *nb_localdims)
210 *nb_localdims = statement->domain->nb_local_dims;
214 // * The number of scattdims are defined by scattering,
215 // - in matrix format it corresponds to the number of rows,
216 // - in relation format it corresponds to the #input_dims.
217 if (statement->scattering != NULL) {
218 if (openscop_relation_is_matrix(statement->scattering)) {
219 if (statement->domain->nb_rows > *nb_scattdims)
220 *nb_scattdims = statement->scattering->nb_rows;
222 else {
223 if (statement->scattering->nb_input_dims > *nb_scattdims)
224 *nb_scattdims = statement->scattering->nb_input_dims;
226 if (statement->scattering->nb_local_dims > *nb_localdims)
227 *nb_localdims = statement->scattering->nb_local_dims;
231 // * The number of arrays are defined by accesses,
232 for (k = 0; k < 2; k++) {
233 if (k == 0)
234 list = statement->read;
235 else
236 list = statement->write;
238 while (list != NULL) {
239 array_id = openscop_relation_get_array_id(list->elt);
240 if (array_id > *nb_arrays)
241 *nb_arrays = array_id;
243 list = list->next;
247 statement = statement->next;
253 * openscop_scop_full_names function:
254 * this function generates an openscop_names_p structure which contains
255 * enough names for the scop provided as parameter, for each kind of names.
256 * If the names contained in the input scop are not sufficient, this function
257 * generated the missing names.
258 * \param scop The scop we need a name for each element.
259 * \return A set of names for the scop.
261 static
262 openscop_names_p openscop_scop_full_names(openscop_scop_p scop) {
263 int nb_parameters;
264 int nb_iterators;
265 int nb_scattdims;
266 int nb_localdims;
267 int nb_arrays;
268 openscop_arrays_p arrays;
269 openscop_names_p names;
271 names = openscop_names_copy(scop->names);
273 // Extract array names information from extensions.
274 openscop_util_strings_free(names->arrays, names->nb_arrays);
275 arrays = (openscop_arrays_p)openscop_extension_lookup(scop->extension,
276 OPENSCOP_EXTENSION_ARRAYS);
277 names->arrays = openscop_arrays_generate_names(arrays,
278 &(names->nb_arrays));
280 // Complete names if necessary.
281 openscop_scop_name_limits(scop, &nb_parameters,
282 &nb_iterators,
283 &nb_scattdims,
284 &nb_localdims,
285 &nb_arrays);
287 openscop_util_strings_complete(&names->parameters, &names->nb_parameters,
288 "P_", nb_parameters);
290 openscop_util_strings_complete(&names->iterators, &names->nb_iterators,
291 "i_", nb_iterators);
293 openscop_util_strings_complete(&names->scattdims, &names->nb_scattdims,
294 "s_", nb_scattdims);
296 openscop_util_strings_complete(&names->localdims, &names->nb_localdims,
297 "l_", nb_localdims);
299 openscop_util_strings_complete(&names->arrays, &names->nb_arrays,
300 "A_", nb_arrays);
302 return names;
307 * openscop_scop_print function:
308 * this function prints the content of an openscop_scop_t structure (*scop)
309 * into a file (file, possibly stdout) in the OpenScop textual format.
310 * \param file The file where the information has to be printed.
311 * \param scop The scop structure whose information has to be printed.
313 void openscop_scop_print(FILE * file, openscop_scop_p scop) {
314 openscop_names_p names;
315 int tmp_nb_iterators = 0;
316 char ** tmp_iterators = NULL;
318 if (openscop_scop_integrity_check(scop) == 0) {
319 fprintf(stderr, "[OpenScop] Warning: OpenScop integrity check failed. "
320 " Something may go wrong\n");
323 // Build a name structure for pretty printing of relations.
324 names = openscop_scop_full_names(scop);
326 if (0) {
327 fprintf(file, "# \n");
328 fprintf(file, "# <| \n");
329 fprintf(file, "# A \n");
330 fprintf(file, "# /.\\ \n");
331 fprintf(file, "# <| [\"\"M# \n");
332 fprintf(file, "# A | # Clan McCloog Castle \n");
333 fprintf(file, "# /.\\ [\"\"M# [Generated by the OpenScop ");
334 fprintf(file, "Library %s %s bits]\n",OPENSCOP_RELEASE, OPENSCOP_VERSION);
335 fprintf(file, "# [\"\"M# | # U\"U#U \n");
336 fprintf(file, "# | # | # \\ .:/ \n");
337 fprintf(file, "# | # | #___| # \n");
338 fprintf(file, "# | \"--' .-\" \n");
339 fprintf(file, "# |\"-\"-\"-\"-\"-#-#-## \n");
340 fprintf(file, "# | # ## ###### \n");
341 fprintf(file, "# \\ .::::'/ \n");
342 fprintf(file, "# \\ ::::'/ \n");
343 fprintf(file, "# :8a| # # ## \n");
344 fprintf(file, "# ::88a ### \n");
345 fprintf(file, "# ::::888a 8a ##::. \n");
346 fprintf(file, "# ::::::888a88a[]:::: \n");
347 fprintf(file, "# :::::::::SUNDOGa8a::::. .. \n");
348 fprintf(file, "# :::::8::::888:Y8888:::::::::... \n");
349 fprintf(file, "#::':::88::::888::Y88a______________________________");
350 fprintf(file, "________________________\n");
351 fprintf(file, "#:: ::::88a::::88a:Y88a ");
352 fprintf(file, " __---__-- __\n");
353 fprintf(file, "#' .: ::Y88a:::::8a:Y88a ");
354 fprintf(file, "__----_-- -------_-__\n");
355 fprintf(file, "# :' ::::8P::::::::::88aa. _ _- -");
356 fprintf(file, "- --_ --- __ --- __--\n");
357 fprintf(file, "#.:: :::::::::::::::::::Y88as88a...s88aa.\n");
359 else {
360 fprintf(file, "# [File generated by the OpenScop Library %s %s bits]\n",
361 OPENSCOP_RELEASE,OPENSCOP_VERSION);
364 fprintf(file, "\nOpenScop\n\n");
365 fprintf(file, "# =============================================== Global\n");
366 fprintf(file, "# Language\n");
367 fprintf(file, "%s\n\n", scop->language);
369 fprintf(file, "# Context\n");
370 // Remove the iterators from the names structure to print comments, as
371 // this information is used to know the number of iterators.
372 // TODO: do this in openscop_relation_print_openscop
373 tmp_nb_iterators = names->nb_iterators;
374 tmp_iterators = names->iterators;
375 names->nb_iterators = 0;
376 names->iterators = NULL;
377 openscop_relation_print(file, scop->context, names);
378 names->nb_iterators = tmp_nb_iterators;
379 names->iterators = tmp_iterators;
380 fprintf(file, "\n");
382 openscop_names_print(file, scop->names);
384 fprintf(file, "# Number of statements\n");
385 fprintf(file, "%d\n\n",openscop_statement_number(scop->statement));
387 openscop_statement_print(file, scop->statement, names);
389 if (scop->extension) {
390 fprintf(file, "# ==============================================="
391 " Extensions\n");
392 openscop_extension_print(file, scop->extension);
395 openscop_names_free(names);
399 /*****************************************************************************
400 * Reading function *
401 *****************************************************************************/
404 static
405 void openscop_scop_update_val(int * variable, int value) {
406 if ((*variable == OPENSCOP_UNDEFINED) || (*variable == value))
407 *variable = value;
408 else
409 fprintf(stderr, "[OpenScop] Warning: number of iterators and "
410 "parameters inconsistency.\n");
413 static
414 void openscop_scop_update_properties(openscop_relation_p relation,
415 int nb_output_dims, int nb_input_dims,
416 int nb_parameters) {
417 if (relation != NULL) {
418 openscop_scop_update_val(&(relation->nb_output_dims), nb_output_dims);
419 openscop_scop_update_val(&(relation->nb_input_dims), nb_input_dims);
420 openscop_scop_update_val(&(relation->nb_parameters), nb_parameters);
426 * openscop_scop_propagate_properties internal function:
427 * This function tries to propagate information in all relations through the
428 * whole openscop representation. For instance, the number of parameters can
429 * be found in the context as well as in any relation: if it is undefined in
430 * the relation, this function defines it, if it is different than the
431 * expected value, it reports an error. This function does the same for
432 * the number of output and input dimensions.
433 * \param scop The SCoP we want to propagate properties.
435 static
436 void openscop_scop_propagate_properties(openscop_scop_p scop) {
437 int i, nb_parameters;
438 openscop_statement_p statement;
439 openscop_relation_p relation;
440 openscop_relation_list_p list;
442 // Context part: get the number of parameters.
443 if ((scop->context != NULL) &&
444 (openscop_relation_is_matrix(scop->context))) {
445 nb_parameters = scop->context->nb_columns - 2;
446 openscop_scop_update_properties(scop->context, 0, 0, nb_parameters);
448 else {
449 return;
452 // For each statement:
453 statement = scop->statement;
454 while (statement != NULL) {
455 // - Domain part,
456 relation = statement->domain;
457 if (openscop_relation_is_matrix(relation)) {
458 while (relation != NULL) {
459 openscop_scop_update_properties(
460 relation, relation->nb_columns-nb_parameters-2, 0, nb_parameters);
461 relation = relation->next;
465 // - Scattering part,
466 relation = statement->scattering;
467 if (openscop_relation_is_matrix(relation)) {
468 while (relation != NULL) {
469 openscop_scop_update_properties(
470 relation, 0, relation->nb_columns-nb_parameters-2, nb_parameters);
471 relation = relation->next;
475 // - Access part.
476 for (i = 0; i < 2; i++) {
477 if (i == 0)
478 list = statement->read;
479 else
480 list = statement->write;
482 while (list != NULL) {
483 relation = list->elt;
484 if (openscop_relation_is_matrix(relation)) {
485 while (relation != NULL) {
486 openscop_scop_update_properties(
487 relation, 0, relation->nb_columns - nb_parameters - 2,
488 nb_parameters);
489 relation = relation->next;
493 list = list->next;
497 statement = statement->next;
503 * openscop_scop_read function:
504 * this function reads a scop structure from a file (possibly stdin)
505 * complying to the OpenScop textual format and returns a pointer to this
506 * scop structure. If some relation properties (number of input/output/local
507 * dimensions and number of parameters) are undefined, it will define them
508 * according to the available information.
509 * \param file The file where the scop has to be read.
510 * \return A pointer to the scop structure that has been read.
512 openscop_scop_p openscop_scop_read(FILE * file) {
513 openscop_scop_p scop = NULL;
514 openscop_statement_p stmt = NULL;
515 openscop_statement_p prev = NULL;
516 int nb_statements;
517 int nb_parameters;
518 int max;
519 char ** tmp;
520 int i;
522 if (file == NULL)
523 return NULL;
525 scop = openscop_scop_malloc();
528 // I. CONTEXT PART
531 // Ensure the file is a .scop.
532 tmp = openscop_util_strings_read(file, &max);
533 if ((max == 0) || (strcmp(*tmp, "OpenScop"))) {
534 fprintf(stderr, "[OpenScop] Error: not an OpenScop file "
535 "(type \"%s\".\n", *tmp);
536 exit (1);
538 if (max > 1)
539 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
540 "(after file type).\n");
541 free(*tmp);
542 free(tmp);
544 // Read the language.
545 char ** language = openscop_util_strings_read(file, &max);
546 if (max == 0) {
547 fprintf(stderr, "[OpenScop] Error: no language (backend) specified.\n");
548 exit (1);
550 if (max > 1)
551 fprintf(stderr, "[OpenScop] Warning: uninterpreted information "
552 "(after language).\n");
553 scop->language = *language;
554 free(language);
556 // Read the context.
557 scop->context = openscop_relation_read(file);
558 scop->names = openscop_names_read(file);
559 if (scop->context != NULL) {
560 if (openscop_relation_is_matrix(scop->context))
561 nb_parameters = scop->context->nb_columns - 2;
562 else
563 nb_parameters = scop->context->nb_parameters;
565 else {
566 nb_parameters = OPENSCOP_UNDEFINED;
570 // II. STATEMENT PART
573 // Read the number of statements.
574 nb_statements = openscop_util_read_int(file, NULL);
576 for (i = 0; i < nb_statements; ++i) {
577 // Read each statement.
578 stmt = openscop_statement_read(file, nb_parameters);
579 if (scop->statement == NULL)
580 scop->statement = stmt;
581 else
582 prev->next = stmt;
583 prev = stmt;
587 // III. OPTION PART
590 // Read the remainder of the file, and store it in the extension field.
591 scop->extension = openscop_extension_read(file);
594 // VI. FINALIZE AND CHECK
596 openscop_scop_propagate_properties(scop);
598 if (!openscop_scop_integrity_check(scop))
599 fprintf(stderr, "[OpenScop] Warning: global integrity check failed.\n");
601 return scop;
605 /*+***************************************************************************
606 * Memory allocation/deallocation functions *
607 *****************************************************************************/
611 * openscop_scop_malloc function:
612 * this function allocates the memory space for a openscop_scop_t structure and
613 * sets its fields with default values. Then it returns a pointer to the
614 * allocated space.
615 * \return A pointer to an empty scop with fields set to default values.
617 openscop_scop_p openscop_scop_malloc() {
618 openscop_scop_p scop;
620 scop = (openscop_scop_p)malloc(sizeof(openscop_scop_t));
621 if (scop == NULL) {
622 fprintf(stderr, "[OpenScop] Memory Overflow.\n");
623 exit(1);
626 scop->version = 1;
627 scop->language = NULL;
628 scop->context = NULL;
629 scop->names = NULL;
630 scop->statement = NULL;
631 scop->extension = NULL;
632 scop->usr = NULL;
634 return scop;
639 * openscop_scop_free function:
640 * This function frees the allocated memory for a openscop_scop_t structure.
641 * \param scop The pointer to the scop we want to free.
643 void openscop_scop_free(openscop_scop_p scop) {
644 if (scop != NULL) {
645 if (scop->language != NULL)
646 free(scop->language);
648 openscop_relation_free(scop->context);
649 openscop_names_free(scop->names);
650 openscop_statement_free(scop->statement);
651 openscop_extension_free(scop->extension);
653 free(scop);
658 /*+***************************************************************************
659 * Processing functions *
660 *****************************************************************************/
664 * openscop_scop_copy function:
665 * This functions builds and returns a "hard copy" (not a pointer copy)
666 * of a openscop_statement_t data structure provided as parameter.
667 * Note that the usr field is not touched by this function.
668 * \param statement The pointer to the scop we want to copy.
669 * \return A pointer to the full copy of the scop provided as parameter.
671 openscop_scop_p openscop_scop_copy(openscop_scop_p scop) {
672 openscop_scop_p copy;
674 copy = openscop_scop_malloc();
675 copy->version = scop->version;
676 if (scop->language != NULL)
677 copy->language = strdup(scop->language);
678 copy->context = openscop_relation_copy(scop->context);
679 copy->names = openscop_names_copy(scop->names);
680 copy->statement = openscop_statement_copy(scop->statement);
681 copy->extension = openscop_extension_copy(scop->extension);
683 return copy;
688 * openscop_scop_equal function:
689 * this function returns true if the two scops are the same, false
690 * otherwise (the usr field is not tested).
691 * \param s1 The first scop.
692 * \param s2 The second scop.
693 * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise.
695 int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) {
697 if (s1 == s2)
698 return 1;
700 if (s1->version != s2->version) {
701 fprintf(stderr, "[OpenScop] info: versions are not the same.\n");
702 return 0;
705 if (strcmp(s1->language, s2->language) != 0) {
706 fprintf(stderr, "[OpenScop] info: languages are not the same.\n");
707 return 0;
710 if (!openscop_relation_equal(s1->context, s2->context)) {
711 fprintf(stderr, "[OpenScop] info: contexts are not the same.\n");
712 return 0;
715 if (!openscop_names_equal(s1->names, s2->names)) {
716 fprintf(stderr, "[OpenScop] info: names are not the same.\n");
717 return 0;
720 if (!openscop_statement_equal(s1->statement, s2->statement)) {
721 fprintf(stderr, "[OpenScop] info: statements are not the same.\n");
722 return 0;
725 if (!openscop_extension_equal(s1->extension, s2->extension)) {
726 fprintf(stderr, "[OpenScop] info: extensions are not the same.\n");
727 return 0;
730 return 1;
735 * openscop_scop_integrity_check function:
736 * This function checks that a scop is "well formed". It returns 0 if the
737 * check failed or 1 if no problem has been detected.
738 * \param scop The scop we want to check.
739 * \return 0 if the integrity check fails, 1 otherwise.
741 int openscop_scop_integrity_check(openscop_scop_p scop) {
742 int expected_nb_parameters;
743 int max_nb_parameters;
744 int max_nb_iterators;
745 int max_nb_scattdims;
746 int max_nb_localdims;
747 int max_nb_arrays;
749 // Check the language.
750 if ((scop->language != NULL) &&
751 (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") ||
752 !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml")))
753 fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!\n");
755 // Check the context.
756 if (!openscop_relation_integrity_check(scop->context,
757 OPENSCOP_TYPE_CONTEXT,
758 OPENSCOP_UNDEFINED,
759 OPENSCOP_UNDEFINED,
760 OPENSCOP_UNDEFINED))
761 return 0;
763 // Get the number of parameters.
764 if (scop->context != NULL) {
765 if (openscop_relation_is_matrix(scop->context))
766 expected_nb_parameters = scop->context->nb_columns - 2;
767 else
768 expected_nb_parameters = scop->context->nb_parameters;
770 else
771 expected_nb_parameters = OPENSCOP_UNDEFINED;
773 if (!openscop_statement_integrity_check(scop->statement,
774 expected_nb_parameters))
775 return 0;
777 // Ensure we have enough names.
778 openscop_scop_name_limits(scop, &max_nb_parameters,
779 &max_nb_iterators,
780 &max_nb_scattdims,
781 &max_nb_localdims,
782 &max_nb_arrays);
784 return openscop_names_integrity_check(scop->names, expected_nb_parameters,
785 max_nb_iterators, max_nb_scattdims);