2 /*+-----------------------------------------------------------------**
4 **-----------------------------------------------------------------**
6 **-----------------------------------------------------------------**
7 ** First version: 08/10/2010 **
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 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
30 * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
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 *
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. *
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. *
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> *
61 *****************************************************************************/
68 # include <openscop/relation_list.h>
71 /*+***************************************************************************
72 * Structure display function *
73 *****************************************************************************/
77 * openscop_relation_list_print_structure function:
78 * Displays a openscop_relation_list_t structure (a list of relations) into a
79 * file (file, possibly stdout). See openscop_relation_print_structure for
81 * \param file File where informations are printed.
82 * \param l The list of relations whose information have to be printed.
83 * \param level Number of spaces before printing, for each line.
86 openscop_relation_list_print_structure(FILE * file
, openscop_relation_list_p l
,
91 // Go to the right level.
92 for (j
= 0; j
< level
; j
++)
96 fprintf(file
, "+-- openscop_relation_list_t\n");
98 fprintf(file
, "+-- NULL relation list\n");
104 // Go to the right level.
105 for (j
= 0; j
< level
; j
++)
106 fprintf(file
, "|\t");
107 fprintf(file
, "| openscop_relation_list_t\n");
113 for (j
= 0; j
<= level
+1; j
++)
114 fprintf(file
, "|\t");
118 openscop_relation_print_structure(file
, l
->elt
, level
+1);
125 for (j
= 0; j
<= level
; j
++)
126 fprintf(file
, "|\t");
127 fprintf(file
, "V\n");
132 for (j
= 0; j
<= level
; j
++)
133 fprintf(file
, "|\t");
139 * openscop_relation_list_print function:
140 * This function prints the content of a openscop_relation_list_t into
141 * a file (file, possibly stdout).
142 * \param file File where informations are printed.
143 * \param list The relation whose information have to be printed.
146 openscop_relation_list_print(FILE * file
, openscop_relation_list_p list
)
148 openscop_relation_list_print_structure(file
, list
, 0);
153 * openscop_relation_list_print_openscop function:
154 * This function prints the content of a openscop_relation_list_t structure
155 * into a file (file, possibly stdout) in the OpenScop format.
156 * \param file File where informations are printed.
157 * \param list The relation list whose information have to be printed.
158 * \param type Semantic about this relation (domain, access...).
159 * \param nb_iterators The number of iterators for the considered statement.
160 * \param iterators An array containing iterator names for the statement.
161 * \param nb_parameters The number of parameters in the SCoP.
162 * \param parameters An array containing all parameters names.
163 * \param nb_arrays The number of arrays accessed in the SCoP.
164 * \param arrays An array containing all accessed array names.
167 openscop_relation_list_print_openscop(FILE * file
,
168 openscop_relation_list_p list
,
170 int nb_iterators
, char ** iterators
,
171 int nb_parameters
, char ** parameters
,
172 int nb_arrays
, char ** arrays
)
175 openscop_relation_list_p head
= list
;
177 // Count the number of elements in the list.
178 for (i
= 0; list
; list
= list
->next
, i
++)
183 fprintf(file
,"# List of %d elements\n%d\n", i
, i
);
185 fprintf(file
,"# List of %d element \n%d\n", i
, i
);
187 // Print each element of the relation list.
191 fprintf(file
, "# List element No.%d\n", i
);
192 openscop_relation_print_openscop(file
, head
->elt
, type
,
193 nb_iterators
, iterators
,
194 nb_parameters
, parameters
,
202 /*****************************************************************************
204 *****************************************************************************/
208 * openscop_relation_list_read function:
209 * This function reads a list of relations into a file (foo,
210 * posibly stdin) and returns a pointer this relation list.
211 * \param file The input stream.
212 * \return A pointer to the relation list structure that has been read.
214 openscop_relation_list_p
215 openscop_relation_list_read(FILE* file
)
217 char s
[OPENSCOP_MAX_STRING
];
219 openscop_relation_list_p list
;
220 openscop_relation_list_p res
;
223 // Skip blank/commented lines.
224 while (fgets(s
, OPENSCOP_MAX_STRING
, file
) == 0 || s
[0] == '#' ||
228 // Read the number of relations to read.
229 sscanf(s
, "%d", &nb_mat
);
231 // Allocate the header of the list and start reading each element.
232 res
= list
= openscop_relation_list_malloc();
233 for (i
= 0; i
< nb_mat
; ++i
)
235 list
->elt
= openscop_relation_read(file
);
237 list
->next
= openscop_relation_list_malloc();
245 /*+***************************************************************************
246 * Memory allocation/deallocation function *
247 *****************************************************************************/
251 * openscop_relation_list_malloc function:
252 * This function allocates the memory space for a openscop_relation_list_t
253 * structure and sets its fields with default values. Then it returns
254 * a pointer to the allocated space.
255 * \return A pointer to an empty relation list with fields set to default
258 openscop_relation_list_p
259 openscop_relation_list_malloc()
261 openscop_relation_list_p res
=
262 (openscop_relation_list_p
) malloc(sizeof(openscop_relation_list_t
));
266 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
279 * openscop_relation_list_free function:
280 * This function frees the allocated memory for a openscop_relation_list_t
281 * structure, and all the relations stored in the list.
282 * \param list The pointer to the relation list we want to free.
285 openscop_relation_list_free(openscop_relation_list_p list
)
287 openscop_relation_list_p tmp
;
295 openscop_relation_free(list
->elt
);
303 /*+***************************************************************************
304 * Processing functions *
305 *****************************************************************************/
309 * openscop_relation_list_node function:
310 * This function builds an openscop_relation_list_t node and sets its
311 * relation element as a copy of the one provided as parameter.
312 * \param relation The pointer to the relation to copy/paste in a list node.
313 * \return A pointer to a relation list node containing a copy of "relation".
315 openscop_relation_list_p
316 openscop_relation_list_node(openscop_relation_p relation
)
318 openscop_relation_list_p
new;
320 new = openscop_relation_list_malloc();
321 new->elt
= openscop_relation_copy(relation
);
328 * openscop_relation_list_copy function:
329 * This functions builds and returns a quasi-"hard copy" (not a pointer copy)
330 * of a openscop_relation_list_t data structure provided as parameter.
331 * \param list The pointer to the relation list we want to copy.
332 * \return A pointer to the full copy of the relation list in parameter.
334 openscop_relation_list_p
335 openscop_relation_list_copy(openscop_relation_list_p list
)
338 openscop_relation_list_p copy
= NULL
, node
, previous
= NULL
;
342 node
= openscop_relation_list_malloc();
343 node
->elt
= openscop_relation_copy(list
->elt
);
353 previous
->next
= node
;
354 previous
= previous
->next
;
365 * openscop_relation_list_concat function:
366 * this function builds a new relation list as the concatenation of the
367 * two lists sent as parameters.
368 * \param l1 The first relation list.
369 * \param l2 The second relation list.
370 * \return A pointer to the relation list resulting from the concatenation of
373 openscop_relation_list_p
374 openscop_relation_list_concat(openscop_relation_list_p l1
,
375 openscop_relation_list_p l2
)
377 openscop_relation_list_p
new, end
;
380 return openscop_relation_list_copy(l2
);
383 return openscop_relation_list_copy(l1
);
385 new = openscop_relation_list_copy(l1
);
387 while (end
->next
!= NULL
)
389 end
->next
= openscop_relation_list_copy(l2
);
396 * openscop_relation_list_equal function:
397 * This function returns true if the two relation lists are the same, false
399 * \param l1 The first relation list.
400 * \param l2 The second relation list.
401 * \return 1 if l1 and l2 are the same (content-wise), 0 otherwise.
404 openscop_relation_list_equal(openscop_relation_list_p l1
,
405 openscop_relation_list_p l2
)
407 while ((l1
!= NULL
) && (l2
!= NULL
))
409 if (!openscop_relation_equal(l1
->elt
, l2
->elt
))
416 if (((l1
== NULL
) && (l2
!= NULL
)) || ((l1
!= NULL
) && (l2
== NULL
)))
424 * openscop_relation_integrity_check function:
425 * This function checks that a list of relation is "well formed" according to
426 * some expected properties (setting an expected value to OPENSCOP_UNDEFINED
427 * means that we do not expect a specific value) and what the relations are
428 * supposed to represent (all relations of a list are supposed to have the
429 * same semantics). It returns 0 if the check failed or 1 if no problem has
431 * \param list The relation list we want to check.
432 * \param type Semantics about this relation (domain, access...).
433 * \param expected_nb_output_dims Expected number of output dimensions.
434 * \param expected_nb_input_dims Expected number of input dimensions.
435 * \param expected_nb_parameters Expected number of parameters.
436 * \return 0 if the integrity check fails, 1 otherwise.
439 openscop_relation_list_integrity_check(openscop_relation_list_p list
,
441 int expected_nb_output_dims
,
442 int expected_nb_input_dims
,
443 int expected_nb_parameters
)
447 if (!openscop_relation_integrity_check(list
->elt
,
449 expected_nb_output_dims
,
450 expected_nb_input_dims
,
451 expected_nb_parameters
))