OpenScop  0.9.0
interface.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** interface.c **
6  **-----------------------------------------------------------------**
7  ** First version: 15/07/2011 **
8  **-----------------------------------------------------------------**
9 
10 
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  *****************************************************************************/
62 
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <string.h>
66 #include <osl/extensions/textual.h>
67 #include <osl/extensions/comment.h>
68 #include <osl/extensions/null.h>
70 #include <osl/extensions/arrays.h>
72 #include <osl/extensions/clay.h>
74 #include <osl/extensions/symbols.h>
76 #include <osl/extensions/extbody.h>
77 #include <osl/extensions/loop.h>
79 #include <osl/strings.h>
80 #include <osl/body.h>
81 #include <osl/relation.h>
82 #include <osl/interface.h>
83 
84 
85 /*+***************************************************************************
86  * Structure display function *
87  *****************************************************************************/
88 
89 
100 void osl_interface_idump(FILE * file, osl_interface_p interface, int level) {
101  int j, first = 1;
102 
103  // Go to the right level.
104  for (j = 0; j < level; j++)
105  fprintf(file, "|\t");
106 
107  if (interface != NULL)
108  fprintf(file, "+-- osl_interface_t: URI = %s\n", interface->URI);
109  else
110  fprintf(file, "+-- NULL interface\n");
111 
112 
113  while (interface != NULL) {
114  if (!first) {
115  // Go to the right level.
116  for (j = 0; j < level; j++)
117  fprintf(file, "|\t");
118 
119  if (interface->URI != NULL)
120  fprintf(file, "| osl_interface_t: URI = %s\n", interface->URI);
121  else
122  fprintf(file, "| osl_interface_t: URI = (NULL)\n");
123  }
124  else
125  first = 0;
126 
127  interface = interface->next;
128 
129  // Next line.
130  if (interface != NULL) {
131  for (j = 0; j <= level + 1; j++)
132  fprintf(file, "|\t");
133  fprintf(file, "\n");
134  for (j = 0; j <= level; j++)
135  fprintf(file, "|\t");
136  fprintf(file, "V\n");
137  }
138  }
139 
140  // The last line.
141  for (j = 0; j <= level; j++)
142  fprintf(file, "|\t");
143  fprintf(file, "\n");
144 }
145 
146 
154 void osl_interface_dump(FILE * file, osl_interface_p interface) {
155  osl_interface_idump(file, interface, 0);
156 }
157 
158 
159 /*****************************************************************************
160  * Reading function *
161  *****************************************************************************/
162 
163 
164 /*+***************************************************************************
165  * Memory allocation/deallocation function *
166  *****************************************************************************/
167 
168 
178  osl_interface_p tmp = *list, check_interface;
179 
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");
186 
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;
190  }
191 
192  if (*list != NULL) {
193  while (tmp->next != NULL)
194  tmp = tmp->next;
195  tmp->next = interface;
196  }
197  else {
198  *list = interface;
199  }
200  }
201 }
202 
203 
213  osl_interface_p interface;
214 
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;
226 
227  return interface;
228 }
229 
230 
238  osl_interface_p tmp;
239  int i = 0;
240 
241  while (interface != NULL) {
242  tmp = interface->next;
243  if (interface->URI != NULL)
244  free(interface->URI);
245  free(interface);
246  interface = tmp;
247  i++;
248  }
249 }
250 
251 
252 /*+***************************************************************************
253  * Processing functions *
254  *****************************************************************************/
255 
256 
265  int number = 0;
266 
267  while (interface != NULL) {
268  number++;
269  interface = interface->next;
270  }
271  return number;
272 }
273 
274 
284  osl_interface_p clone = NULL, new;
285  int i = 0;
286 
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;
297 
298  osl_interface_add(&clone, new);
299  interface = interface->next;
300  i++;
301  }
302 
303  return clone;
304 }
305 
306 
315 
316  return osl_interface_nclone(interface, -1);
317 }
318 
319 
329  osl_interface_p interface2) {
330 
331  if (interface1 == interface2)
332  return 1;
333 
334  if (((interface1 == NULL) && (interface2 != NULL)) ||
335  ((interface1 != NULL) && (interface2 == NULL)))
336  return 0;
337 
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))
346  return 0;
347 
348  return 1;
349 }
350 
351 
363 
364  if (URI == NULL) {
365  OSL_warning("lookup for a NULL URI");
366  }
367  else {
368  while (list != NULL) {
369  if ((list->URI != NULL) && (!strcmp(list->URI, URI)))
370  return list;
371 
372  list = list->next;
373  }
374  }
375 
376  return NULL;
377 }
378 
379 
387  osl_interface_p registry = NULL;
388 
389  // Internal generics
393 
394  // Extensions
407  //osl_interface_add(&registry, osl_irregular_interface());
408 
409  return registry;
410 }
411 
412 
413 
osl_interface_p osl_comment_interface()
Definition: comment.c:297
osl_interface_p osl_clay_interface()
Definition: clay.c:302
int osl_interface_equal(osl_interface_p interface1, osl_interface_p interface2)
Definition: interface.c:328
osl_interface_p osl_symbols_interface()
Definition: symbols.c:551
osl_interface_p osl_interface_nclone(osl_interface_p interface, int n)
Definition: interface.c:283
void osl_interface_free(osl_interface_p interface)
Definition: interface.c:237
osl_equal_f equal
Definition: interface.h:97
osl_interface_p osl_dependence_interface()
Definition: dependence.c:641
osl_interface_p osl_interface_malloc()
Definition: interface.c:212
osl_interface_p osl_interface_clone(osl_interface_p interface)
Definition: interface.c:314
osl_malloc_f malloc
Definition: interface.h:94
osl_interface_p osl_textual_interface()
Definition: textual.c:321
osl_interface_p osl_interface_lookup(osl_interface_p list, char *URI)
Definition: interface.c:362
osl_interface_p osl_body_interface()
Definition: body.c:390
void osl_interface_idump(FILE *file, osl_interface_p interface, int level)
Definition: interface.c:100
osl_interface_p osl_scatnames_interface()
Definition: scatnames.c:269
void osl_interface_add(osl_interface_p *list, osl_interface_p interface)
Definition: interface.c:177
int osl_interface_number(osl_interface_p interface)
Definition: interface.c:264
osl_interface_p osl_arrays_interface()
Definition: arrays.c:459
void osl_interface_dump(FILE *file, osl_interface_p interface)
Definition: interface.c:154
osl_idump_f idump
Definition: interface.h:91
osl_interface_p osl_null_interface()
Definition: null.c:256
osl_interface_p osl_strings_interface()
Definition: strings.c:450
char * URI
Definition: interface.h:90
osl_interface_p osl_pluto_unroll_interface()
Definition: pluto_unroll.c:409
osl_sread_f sread
Definition: interface.h:93
osl_interface_p osl_extbody_interface()
Definition: extbody.c:363
osl_clone_f clone
Definition: interface.h:96
osl_free_f free
Definition: interface.h:95
osl_interface_p osl_interface_get_default_registry()
Definition: interface.c:386
struct osl_interface * next
Definition: interface.h:98
osl_interface_p osl_coordinates_interface()
Definition: coordinates.c:356
osl_interface_p osl_loop_interface()
Definition: loop.c:547
osl_interface_p osl_relation_interface()
Definition: relation.c:3000
osl_sprint_f sprint
Definition: interface.h:92