2 /*+-----------------------------------------------------------------**
4 **-----------------------------------------------------------------**
6 **-----------------------------------------------------------------**
7 ** First version: 15/07/2011 **
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 *****************************************************************************/
66 #include <osl/extensions/textual.h>
67 #include <osl/extensions/comment.h>
68 #include <osl/extensions/null.h>
69 #include <osl/extensions/scatnames.h>
70 #include <osl/extensions/arrays.h>
71 #include <osl/extensions/coordinates.h>
72 #include <osl/extensions/clay.h>
73 #include <osl/extensions/dependence.h>
74 #include <osl/extensions/symbols.h>
75 #include <osl/extensions/irregular.h>
76 #include <osl/extensions/extbody.h>
77 #include <osl/extensions/loop.h>
78 #include <osl/extensions/pluto_unroll.h>
79 #include <osl/strings.h>
81 #include <osl/relation.h>
82 #include <osl/interface.h>
85 /*+***************************************************************************
86 * Structure display function *
87 *****************************************************************************/
91 * osl_interface_idump function:
92 * this function displays an osl_interface_t structure (*interface) into
93 * a file (file, possibly stdout) in a way that trends to be understandable.
94 * It includes an indentation level (level) in order to work with others
96 * \param file The file where the information has to be printed.
97 * \param interface The interface structure which has to be printed.
98 * \param level Number of spaces before printing, for each line.
100 void osl_interface_idump(FILE * file
, osl_interface_p interface
, int level
) {
103 // Go to the right level.
104 for (j
= 0; j
< level
; j
++)
105 fprintf(file
, "|\t");
107 if (interface
!= NULL
)
108 fprintf(file
, "+-- osl_interface_t: URI = %s\n", interface
->URI
);
110 fprintf(file
, "+-- NULL interface\n");
113 while (interface
!= NULL
) {
115 // Go to the right level.
116 for (j
= 0; j
< level
; j
++)
117 fprintf(file
, "|\t");
119 if (interface
->URI
!= NULL
)
120 fprintf(file
, "| osl_interface_t: URI = %s\n", interface
->URI
);
122 fprintf(file
, "| osl_interface_t: URI = (NULL)\n");
127 interface
= interface
->next
;
130 if (interface
!= NULL
) {
131 for (j
= 0; j
<= level
+ 1; j
++)
132 fprintf(file
, "|\t");
134 for (j
= 0; j
<= level
; j
++)
135 fprintf(file
, "|\t");
136 fprintf(file
, "V\n");
141 for (j
= 0; j
<= level
; j
++)
142 fprintf(file
, "|\t");
148 * osl_interface_dump function:
149 * this function prints the content of a osl_interface_t structure
150 * (*interface) into a file (file, possibly stdout).
151 * \param file File where informations are printed.
152 * \param interface The interface structure to print.
154 void osl_interface_dump(FILE * file
, osl_interface_p interface
) {
155 osl_interface_idump(file
, interface
, 0);
159 /*****************************************************************************
161 *****************************************************************************/
164 /*+***************************************************************************
165 * Memory allocation/deallocation function *
166 *****************************************************************************/
170 * osl_interface_add function:
171 * this function adds an interface node (it may be a list as well) to a
172 * list of interfaces provided as parameter (list). The new node
173 * is inserted at the end of the list.
174 * \param list The list of interfaces to add a node (NULL if empty).
175 * \param interface The interface to add to the list.
177 void osl_interface_add(osl_interface_p
* list
, osl_interface_p interface
) {
178 osl_interface_p tmp
= *list
, check_interface
;
180 if (interface
!= NULL
) {
181 // First, check that the interface list is OK.
182 check_interface
= interface
;
183 while (check_interface
!= NULL
) {
184 if (check_interface
->URI
== NULL
)
185 OSL_error("no URI in an interface to add to a list");
187 if (osl_interface_lookup(*list
, check_interface
->URI
) != NULL
)
188 OSL_error("only one interface with a given URI is allowed");
189 check_interface
= check_interface
->next
;
193 while (tmp
->next
!= NULL
)
195 tmp
->next
= interface
;
205 * osl_interface_malloc function:
206 * This function allocates the memory space for a osl_interface_t
207 * structure and sets its fields with default values. Then it returns a
208 * pointer to the allocated space.
209 * \return A pointer to an empty interface structure with fields set to
212 osl_interface_p
osl_interface_malloc() {
213 osl_interface_p interface
;
215 OSL_malloc(interface
, osl_interface_p
,
216 sizeof(osl_interface_t
));
217 interface
->URI
= NULL
;
218 interface
->idump
= NULL
;
219 interface
->sprint
= NULL
;
220 interface
->sread
= NULL
;
221 interface
->malloc
= NULL
;
222 interface
->free
= NULL
;
223 interface
->clone
= NULL
;
224 interface
->equal
= NULL
;
225 interface
->next
= NULL
;
232 * osl_interface_free function:
233 * this function frees the allocated memory for an osl_interface_t
234 * structure, and all the interfaces stored in the list.
235 * \param[in] interface The pointer to the interface we want to free.
237 void osl_interface_free(osl_interface_p interface
) {
241 while (interface
!= NULL
) {
242 tmp
= interface
->next
;
243 if (interface
->URI
!= NULL
)
244 free(interface
->URI
);
252 /*+***************************************************************************
253 * Processing functions *
254 *****************************************************************************/
258 * osl_interface_number function:
259 * this function returns the number of statements in the interface list
260 * provided as parameter.
261 * \param[in] interface The first element of the interface list.
262 * \return The number of statements in the interface list.
264 int osl_interface_number(osl_interface_p interface
) {
267 while (interface
!= NULL
) {
269 interface
= interface
->next
;
276 * osl_interface_nclone function:
277 * This function builds and returns a "hard copy" (not a pointer copy) of the
278 * n first elements of an osl_interface_t list.
279 * \param interface The pointer to the interface structure we want to clone.
280 * \param n The number of nodes we want to copy (-1 for infinity).
281 * \return The clone of the n first nodes of the interface list.
283 osl_interface_p
osl_interface_nclone(osl_interface_p interface
, int n
) {
284 osl_interface_p clone
= NULL
, new;
287 while ((interface
!= NULL
) && ((n
== -1) || (i
< n
))) {
288 new = osl_interface_malloc();
289 OSL_strdup(new->URI
, interface
->URI
);
290 new->idump
= interface
->idump
;
291 new->sprint
= interface
->sprint
;
292 new->sread
= interface
->sread
;
293 new->malloc
= interface
->malloc
;
294 new->free
= interface
->free
;
295 new->clone
= interface
->clone
;
296 new->equal
= interface
->equal
;
298 osl_interface_add(&clone
, new);
299 interface
= interface
->next
;
308 * osl_interface_clone function:
309 * This function builds and returns a "hard copy" (not a pointer copy) of an
310 * osl_interface_t data structure.
311 * \param interface The pointer to the interface structure we want to copy.
312 * \return A pointer to the copy of the interface structure.
314 osl_interface_p
osl_interface_clone(osl_interface_p interface
) {
316 return osl_interface_nclone(interface
, -1);
321 * osl_interface_equal function:
322 * this function returns true if the two interface structures are the same,
323 * (content-wise) false otherwise.
324 * \param interface1 The first interface structure.
325 * \param interface2 The second interface structure.
326 * \return 1 if interface1 and interface2 are the same, 0 otherwise.
328 int osl_interface_equal(osl_interface_p interface1
,
329 osl_interface_p interface2
) {
331 if (interface1
== interface2
)
334 if (((interface1
== NULL
) && (interface2
!= NULL
)) ||
335 ((interface1
!= NULL
) && (interface2
== NULL
)))
338 if (strcmp(interface1
->URI
, interface2
->URI
) ||
339 (interface1
->idump
!= interface2
->idump
) ||
340 (interface1
->sprint
!= interface2
->sprint
) ||
341 (interface1
->sread
!= interface2
->sread
) ||
342 (interface1
->malloc
!= interface2
->malloc
) ||
343 (interface1
->free
!= interface2
->free
) ||
344 (interface1
->clone
!= interface2
->clone
) ||
345 (interface1
->equal
!= interface2
->equal
))
353 * osl_interface_lookup function:
354 * this function returns the first interface with a given URI in the
355 * interface list provided as parameter and NULL if it doesn't find such
357 * \param list The interface list where to search a given interface URI.
358 * \param URI The URI of the interface we are looking for.
359 * \return The first interface of the requested URI in the list.
362 osl_interface_lookup(osl_interface_p list
, char * URI
) {
365 OSL_warning("lookup for a NULL URI");
368 while (list
!= NULL
) {
369 if ((list
->URI
!= NULL
) && (!strcmp(list
->URI
, URI
)))
381 * osl_interface_get_default_registry function:
382 * this function creates the list of known interfaces (of all generic types,
383 * including extensions) and returns it.
384 * \return The list of known interfaces.
386 osl_interface_p
osl_interface_get_default_registry() {
387 osl_interface_p registry
= NULL
;
390 osl_interface_add(®istry
, osl_strings_interface());
391 osl_interface_add(®istry
, osl_body_interface());
392 osl_interface_add(®istry
, osl_relation_interface());
395 osl_interface_add(®istry
, osl_textual_interface());
396 osl_interface_add(®istry
, osl_comment_interface());
397 osl_interface_add(®istry
, osl_null_interface());
398 osl_interface_add(®istry
, osl_scatnames_interface());
399 osl_interface_add(®istry
, osl_arrays_interface());
400 osl_interface_add(®istry
, osl_coordinates_interface());
401 osl_interface_add(®istry
, osl_clay_interface());
402 osl_interface_add(®istry
, osl_dependence_interface());
403 osl_interface_add(®istry
, osl_symbols_interface());
404 osl_interface_add(®istry
, osl_extbody_interface());
405 osl_interface_add(®istry
, osl_loop_interface());
406 osl_interface_add(®istry
, osl_pluto_unroll_interface());
407 //osl_interface_add(®istry, osl_irregular_interface());