2 /*+-----------------------------------------------------------------**
4 **-----------------------------------------------------------------**
5 ** extensions/irregular.c **
6 **-----------------------------------------------------------------**
7 ** First version: 07/12/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 *****************************************************************************/
67 #include <osl/macros.h>
69 #include <osl/strings.h>
70 #include <osl/interface.h>
71 #include <osl/extensions/irregular.h>
74 /*+***************************************************************************
75 * Structure display function *
76 *****************************************************************************/
80 * osl_irregular_idump function:
81 * this function displays an osl_irregular_t structure (*irregular) into a
82 * file (file, possibly stdout) in a way that trends to be understandable. It
83 * includes an indentation level (level) in order to work with others
85 * \param file The file where the information has to be printed.
86 * \param irregular The irregular structure whose information has to be printed.
87 * \param level Number of spaces before printing, for each line.
89 void osl_irregular_idump(FILE * file
, osl_irregular_p irregular
, int level
) {
92 // Go to the right level.
93 for (j
= 0; j
< level
; j
++)
96 if (irregular
!= NULL
)
97 fprintf(file
, "+-- osl_irregular_t\n");
99 fprintf(file
, "+-- NULL irregular\n");
101 if (irregular
!= NULL
) {
102 // Go to the right level.
103 for(j
= 0; j
<= level
; j
++)
104 fprintf(file
, "|\t");
106 // Display the irregular contents.
109 for (i
= 0; i
< irregular
->nb_statements
; i
++) {
110 fprintf(file
, "statement%d's predicats : ", i
);
111 for(j
= 0; j
< irregular
->nb_predicates
[i
]; j
++)
112 fprintf(file
, "%d ", irregular
->predicates
[i
][j
]);
117 for (i
= 0; i
< irregular
->nb_control
; i
++) {
118 fprintf(file
, "predicat%d's\niterators : ", i
);
119 for(j
= 0; j
< irregular
->nb_iterators
[i
]; j
++)
120 fprintf(file
, "%s ", irregular
->iterators
[i
][j
]);
121 fprintf(file
, "\ncontrol body: %s\n", irregular
->body
[i
]);
124 for(i
= irregular
->nb_control
;
125 i
< irregular
->nb_control
+ irregular
->nb_exit
; i
++) {
126 fprintf(file
, "predicat%d's\niterators : ", i
);
127 for(j
= 0; j
< irregular
->nb_iterators
[i
]; j
++)
128 fprintf(file
, "%s ", irregular
->iterators
[i
][j
]);
129 fprintf(file
, "\nexit body: %s\n", irregular
->body
[i
]);
134 for (j
= 0; j
<= level
; j
++)
135 fprintf(file
, "|\t");
141 * osl_irregular_dump function:
142 * this function prints the content of an osl_irregular_t structure
143 * (*irregular) into a file (file, possibly stdout).
144 * \param file The file where the information has to be printed.
145 * \param irregular The irregular structure whose information has to be printed.
147 void osl_irregular_dump(FILE * file
, osl_irregular_p irregular
) {
148 osl_irregular_idump(file
, irregular
, 0);
153 * osl_irregular_sprint function:
154 * this function prints the content of an osl_irregular_t structure
155 * (*irregular) into a string (returned) in the OpenScop textual format.
156 * \param irregular The irregular structure whose information has to be printed.
157 * \return A string containing the OpenScop dump of the irregular structure.
159 char * osl_irregular_sprint(osl_irregular_p irregular
) {
160 int high_water_mark
= OSL_MAX_STRING
,i
,j
;
161 char * string
= NULL
;
164 if (irregular
!= NULL
) {
165 OSL_malloc(string
, char *, high_water_mark
* sizeof(char));
166 OSL_malloc(buffer
, char *, OSL_MAX_STRING
* sizeof(char));
169 // Print the begin tag.
170 sprintf(buffer
, OSL_TAG_IRREGULAR_START
);
171 osl_util_safe_strcat(&string
, buffer
, &high_water_mark
);
173 // Print the content.
174 sprintf(buffer
, "\n%d\n", irregular
->nb_statements
);
175 for(i
=0; i
<irregular
->nb_statements
; i
++) {
176 sprintf(buffer
, "%s%d ", buffer
, irregular
->nb_predicates
[i
]);
177 for(j
=0; j
<irregular
->nb_predicates
[i
]; j
++) {
178 sprintf(buffer
, "%s%d ", buffer
, irregular
->predicates
[i
][j
]);
180 sprintf(buffer
, "%s\n", buffer
);
182 // Print the predicates.
184 sprintf(buffer
, "%s%d\n", buffer
, irregular
->nb_control
);
185 sprintf(buffer
, "%s%d\n", buffer
, irregular
->nb_exit
);
186 for(i
=0; i
<irregular
->nb_control
; i
++) {
187 sprintf(buffer
, "%s%d ", buffer
, irregular
->nb_iterators
[i
]);
188 for(j
=0; j
<irregular
->nb_iterators
[i
];j
++)
189 sprintf(buffer
, "%s%s ", buffer
, irregular
->iterators
[i
][j
]);
190 sprintf(buffer
, "%s\n%s\n", buffer
, irregular
->body
[i
]);
193 for(i
=0; i
<irregular
->nb_exit
; i
++) {
194 sprintf(buffer
, "%s%d ", buffer
, irregular
->nb_iterators
[
195 irregular
->nb_control
+ i
]);
196 for(j
=0; j
<irregular
->nb_iterators
[irregular
->nb_control
+ i
];j
++)
197 sprintf(buffer
, "%s%s ", buffer
, irregular
->iterators
[
198 irregular
->nb_control
+i
][j
]);
199 sprintf(buffer
, "%s\n%s\n", buffer
, irregular
->body
[
200 irregular
->nb_control
+ i
]);
203 osl_util_safe_strcat(&string
, buffer
, &high_water_mark
);
205 // Print the end tag.
206 sprintf(buffer
, OSL_TAG_IRREGULAR_STOP
"\n");
207 osl_util_safe_strcat(&string
, buffer
, &high_water_mark
);
209 // Keep only the memory space we need.
210 OSL_realloc(string
, char *, (strlen(string
) + 1) * sizeof(char));
218 /*****************************************************************************
220 *****************************************************************************/
223 * osl_irregular_sread function:
224 * this function reads a irregular structure from a string complying to the
225 * OpenScop textual format and returns a pointer to this irregular structure.
226 * The string should contain only one textual format of a irregular structure.
227 * \param extensions The input string where to find a irregular structure.
228 * \return A pointer to the irregular structure that has been read.
230 osl_irregular_p
osl_irregular_sread(char ** extensions_fixme
) {
233 osl_irregular_p irregular
;
235 // FIXME: this is a quick and dirty thing to accept char ** instead
236 // of char * in the parameter: really do it and update the
237 // pointer to after what has been read.
238 content
= *extensions_fixme
;
240 if (content
== NULL
) {
241 OSL_debug("no irregular optional tag");
245 if (strlen(content
) > OSL_MAX_STRING
)
246 OSL_error("irregular too long");
248 irregular
= osl_irregular_malloc();
251 tok
= strtok(content
," \n");
252 irregular
->nb_statements
= atoi(tok
);
253 OSL_malloc(irregular
->predicates
, int **,
254 sizeof(int*) * irregular
->nb_statements
);
255 OSL_malloc(irregular
->nb_predicates
, int *,
256 sizeof(int) * irregular
->nb_statements
);
259 for(i
= 0; i
< irregular
->nb_statements
; i
++) {
261 tok
= strtok(NULL
," \n");
262 irregular
->nb_predicates
[i
] = atoi(tok
);
263 OSL_malloc(irregular
->predicates
[i
], int *,
264 sizeof(int) * irregular
->nb_predicates
[i
]);
265 for(j
= 0; j
< irregular
->nb_predicates
[i
]; j
++){
266 tok
= strtok(NULL
, " \n");
267 irregular
->predicates
[i
][j
] = atoi(tok
);
271 // control and exits :
272 tok
= strtok(NULL
, " \n");
273 irregular
->nb_control
=atoi(tok
);
274 tok
= strtok(NULL
, " \n");
275 irregular
->nb_exit
= atoi(tok
);
277 int nb_predicates
= irregular
->nb_control
+ irregular
->nb_exit
;
279 OSL_malloc(irregular
->iterators
, char ***,
280 sizeof(char **) * nb_predicates
);
281 OSL_malloc(irregular
->nb_iterators
, int *, sizeof(int) * nb_predicates
);
282 OSL_malloc(irregular
->body
, char **, sizeof(char *) * nb_predicates
);
284 for(i
= 0; i
< nb_predicates
; i
++) {
285 // Get number of iterators
286 tok
= strtok(NULL
, " \n");
287 irregular
->nb_iterators
[i
] = atoi(tok
);
288 OSL_malloc(irregular
->iterators
[i
], char **,
289 sizeof(char *) * irregular
->nb_iterators
[i
]);
292 for(j
= 0; j
< irregular
->nb_iterators
[i
]; j
++)
293 OSL_strdup(irregular
->iterators
[i
][j
], strtok(NULL
, " \n"));
294 // Get predicat string
295 OSL_strdup(irregular
->body
[i
], strtok(NULL
, "\n"));
302 /*+***************************************************************************
303 * Memory allocation/deallocation function *
304 *****************************************************************************/
308 * osl_irregular_malloc function:
309 * This function allocates the memory space for an osl_irregular_t
310 * structure and sets its fields with default values. Then it returns a
311 * pointer to the allocated space.
312 * \return A pointer to an empty irregular structure with fields set to
315 osl_irregular_p
osl_irregular_malloc() {
316 osl_irregular_p irregular
;
318 OSL_malloc(irregular
, osl_irregular_p
,
319 sizeof(osl_irregular_t
));
320 irregular
->nb_statements
= 0;
321 irregular
->predicates
= NULL
;
322 irregular
->nb_predicates
= NULL
;
323 irregular
->nb_control
= 0;
324 irregular
->nb_exit
= 0;
325 irregular
->nb_iterators
= NULL
;
326 irregular
->iterators
= NULL
;
327 irregular
->body
= NULL
;
334 * osl_irregular_free function:
335 * This function frees the allocated memory for an osl_irregular_t
337 * \param irregular The pointer to the irregular structure we want to free.
339 void osl_irregular_free(osl_irregular_p irregular
) {
340 int i
, j
, nb_predicates
;
342 if (irregular
!= NULL
) {
343 for(i
= 0; i
< irregular
->nb_statements
; i
++)
344 free(irregular
->predicates
[i
]);
346 if(irregular
->predicates
!= NULL
)
347 free(irregular
->predicates
);
349 nb_predicates
= irregular
->nb_control
+ irregular
->nb_exit
;
350 for(i
= 0; i
< nb_predicates
; i
++) {
351 for(j
= 0; j
< irregular
->nb_iterators
[i
]; j
++)
352 free(irregular
->iterators
[i
][j
]);
353 free(irregular
->iterators
[i
]);
354 free(irregular
->body
[i
]);
356 if(irregular
->iterators
!= NULL
)
357 free(irregular
->iterators
);
358 if(irregular
->nb_iterators
!= NULL
)
359 free(irregular
->nb_iterators
);
360 if(irregular
->body
!= NULL
)
361 free(irregular
->body
);
362 if(irregular
->nb_predicates
!= NULL
)
363 free(irregular
->nb_predicates
);
369 /*+***************************************************************************
370 * Processing functions *
371 *****************************************************************************/
375 * osl_irregular_clone function:
376 * This function builds and returns a "hard copy" (not a pointer copy) of an
377 * osl_irregular_t data structure.
378 * \param irregular The pointer to the irregular structure we want to copy.
379 * \return A pointer to the copy of the irregular structure.
381 osl_irregular_p
osl_irregular_clone(osl_irregular_p irregular
) {
383 osl_irregular_p copy
;
385 if (irregular
== NULL
)
388 copy
= osl_irregular_malloc();
389 copy
->nb_statements
= irregular
->nb_statements
;
390 copy
->nb_predicates
= (int *)malloc(sizeof(int)*copy
->nb_statements
);
391 if (copy
->nb_predicates
== NULL
)
393 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
396 copy
->predicates
= (int **)malloc(sizeof(int*)*copy
->nb_statements
);
397 if (copy
->predicates
== NULL
)
399 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
402 for(i
=0; i
<copy
->nb_statements
; i
++)
404 copy
->nb_predicates
[i
]=irregular
->nb_predicates
[i
];
405 copy
->predicates
[i
] = (int *)malloc(sizeof(int)*copy
->nb_predicates
[i
]);
406 if (copy
->predicates
[i
] == NULL
)
408 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
411 for(j
=0; j
<copy
->nb_predicates
[i
]; j
++)
412 copy
->predicates
[i
][j
] = irregular
->predicates
[i
][j
];
415 copy
->nb_control
= irregular
->nb_control
;
416 copy
->nb_exit
= irregular
->nb_exit
;
417 int nb_predicates
= irregular
->nb_control
+ irregular
->nb_exit
;
418 copy
->nb_iterators
= (int *)malloc(sizeof(int)*nb_predicates
);
419 if (copy
->nb_iterators
== NULL
)
421 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
424 copy
->iterators
= (char ***)malloc(sizeof(char**)*nb_predicates
);
425 if (copy
->iterators
== NULL
)
427 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
430 copy
->body
= (char **)malloc(sizeof(char*)*nb_predicates
);
431 if (copy
->body
== NULL
)
433 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
436 for(i
=0; i
<nb_predicates
; i
++)
438 copy
->nb_iterators
[i
] = irregular
->nb_iterators
[i
];
439 copy
->iterators
[i
] = (char**)malloc(sizeof(char*)*copy
->nb_iterators
[i
]);
440 if (copy
->iterators
[i
] == NULL
)
442 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
445 for(j
=0;j
<copy
->nb_iterators
[i
];j
++)
446 OSL_strdup(copy
->iterators
[i
][j
], irregular
->iterators
[i
][j
]);
447 OSL_strdup(copy
->iterators
[i
][j
], irregular
->body
[i
]);
455 * osl_irregular_equal function:
456 * this function returns true if the two irregular structures are the same
457 * (content-wise), false otherwise. This functions considers two irregular
458 * \param c1 The first irregular structure.
459 * \param c2 The second irregular structure.
460 * \return 1 if c1 and c2 are the same (content-wise), 0 otherwise.
463 osl_irregular_equal(osl_irregular_p c1
, osl_irregular_p c2
)
469 if (((c1
== NULL
) && (c2
!= NULL
)) || ((c1
!= NULL
) && (c2
== NULL
)))
472 if(c1
->nb_statements
!= c2
->nb_statements
||
473 c1
->nb_control
!= c2
->nb_control
||
474 c1
->nb_exit
!= c2
->nb_exit
)
477 while(bool == 0 && i
< c1
->nb_statements
)
479 bool = c1
->nb_predicates
[i
] != c2
->nb_predicates
[i
] ? 1 : 0;
486 while(bool == 0 && i
< c1
->nb_control
+ c1
->nb_exit
)
488 bool += c1
->nb_iterators
[i
] != c2
->nb_iterators
[i
] ? 1 : 0;
489 bool += strcmp(c1
->body
[i
],c2
->body
[i
]);
491 while(bool == 0 && j
< c1
->nb_iterators
[i
])
493 bool += strcmp(c1
->iterators
[i
][j
],c2
->iterators
[i
][j
]);
503 osl_irregular_p
osl_irregular_add_control(
504 osl_irregular_p irregular
,
510 osl_irregular_p result
=osl_irregular_malloc();
512 result
->nb_control
= irregular
->nb_control
+ 1;
513 result
->nb_exit
= irregular
->nb_exit
;
514 result
->nb_statements
= irregular
->nb_statements
;
515 int nb_predicates
= result
->nb_control
+ result
->nb_exit
;
517 result
->iterators
= (char***)malloc(sizeof(char**)*nb_predicates
);
518 result
->nb_iterators
= (int*)malloc(sizeof(int)*nb_predicates
);
519 result
->body
= (char**)malloc(sizeof(char*)*nb_predicates
);
520 if (result
->iterators
== NULL
||
521 result
->nb_iterators
== NULL
||
522 result
->body
== NULL
)
524 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
528 for(i
=0; i
<irregular
->nb_control
; i
++)
530 result
->nb_iterators
[i
] = irregular
->nb_iterators
[i
];
531 OSL_strdup(result
->body
[i
], irregular
->body
[i
]);
532 result
->iterators
[i
] = (char**)malloc(sizeof(char*) *
533 irregular
->nb_iterators
[i
]);
534 if (result
->iterators
[i
] == NULL
)
536 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
539 for(j
=0; j
<irregular
->nb_iterators
[i
];j
++)
540 OSL_strdup(result
->iterators
[i
][j
], irregular
->iterators
[i
][j
]);
543 result
->iterators
[irregular
->nb_control
] = (char**)malloc(sizeof(char*)*nb_iterators
);
544 if (result
->iterators
[irregular
->nb_control
] == NULL
)
546 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
549 for(i
=0; i
<nb_iterators
; i
++)
550 OSL_strdup(result
->iterators
[irregular
->nb_control
][i
], iterators
[i
]);
551 result
->nb_iterators
[irregular
->nb_control
] = nb_iterators
;
552 OSL_strdup(result
->body
[irregular
->nb_control
], body
);
554 for(i
=result
->nb_control
; i
<nb_predicates
; i
++)
556 result
->nb_iterators
[i
] = irregular
->nb_iterators
[i
-1];
557 OSL_strdup(result
->body
[i
], irregular
->body
[i
-1]);
558 result
->iterators
[i
] = (char**)malloc(sizeof(char*) *
559 irregular
->nb_iterators
[i
-1]);
560 if (result
->iterators
[i
] == NULL
)
562 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
565 for(j
=0; j
<irregular
->nb_iterators
[i
-1];j
++)
566 OSL_strdup(result
->iterators
[i
][j
], irregular
->iterators
[i
-1][j
]);
569 result
->nb_predicates
= (int*)malloc(sizeof(int)*irregular
->nb_statements
);
570 result
->predicates
= (int**)malloc(sizeof(int*)*irregular
->nb_statements
);
571 if (result
->nb_predicates
== NULL
|| result
->predicates
== NULL
)
573 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
576 for(i
=0; i
<irregular
->nb_statements
; i
++)
578 result
->predicates
[i
] = (int*)malloc(sizeof(int)*irregular
->nb_predicates
[i
]);
579 if (result
->predicates
[i
] == NULL
)
581 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
584 result
->nb_predicates
[i
] = irregular
->nb_predicates
[i
];
585 for(j
=0; j
<irregular
->nb_predicates
[i
]; j
++)
586 result
->predicates
[i
][j
]=irregular
->predicates
[i
][j
];
592 osl_irregular_p
osl_irregular_add_exit(
593 osl_irregular_p irregular
,
599 osl_irregular_p result
=osl_irregular_malloc();
601 result
->nb_control
= irregular
->nb_control
;
602 result
->nb_exit
= irregular
->nb_exit
+ 1;
603 result
->nb_statements
= irregular
->nb_statements
;
604 int nb_predicates
= result
->nb_control
+ result
->nb_exit
;
606 result
->iterators
= (char***)malloc(sizeof(char**)*nb_predicates
);
607 result
->nb_iterators
= (int*)malloc(sizeof(int)*nb_predicates
);
608 result
->body
= (char**)malloc(sizeof(char*)*nb_predicates
);
609 if (result
->iterators
== NULL
||
610 result
->nb_iterators
== NULL
||
611 result
->body
== NULL
)
613 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
616 //copy controls and exits
617 for(i
=0; i
<nb_predicates
- 1; i
++)
619 result
->nb_iterators
[i
] = irregular
->nb_iterators
[i
];
620 OSL_strdup(result
->body
[i
], irregular
->body
[i
]);
621 result
->iterators
[i
] = (char**)malloc(sizeof(char*) *
622 irregular
->nb_iterators
[i
]);
623 if (result
->iterators
[i
] == NULL
)
625 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
628 for(j
=0; j
<irregular
->nb_iterators
[i
];j
++)
629 OSL_strdup(result
->iterators
[i
][j
], irregular
->iterators
[i
][j
]);
632 result
->iterators
[nb_predicates
-1] = (char**)malloc(sizeof(char*)*nb_iterators
);
633 if (result
->iterators
[nb_predicates
-1] == NULL
)
635 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
639 for(i
=0; i
<nb_iterators
; i
++)
640 OSL_strdup(result
->iterators
[nb_predicates
-1][i
], iterators
[i
]);
641 result
->nb_iterators
[nb_predicates
-1] = nb_iterators
;
642 OSL_strdup(result
->body
[nb_predicates
-1], body
);
644 result
->nb_predicates
= (int*)malloc(sizeof(int)*irregular
->nb_statements
);
645 result
->predicates
= (int**)malloc(sizeof(int*)*irregular
->nb_statements
);
646 if (result
->nb_predicates
== NULL
|| result
->predicates
== NULL
)
648 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
651 for(i
=0; i
<irregular
->nb_statements
; i
++)
653 result
->predicates
[i
] = (int*)malloc(sizeof(int)*irregular
->nb_predicates
[i
]);
654 if (result
->predicates
[i
] == NULL
)
656 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
659 result
->nb_predicates
[i
] = irregular
->nb_predicates
[i
];
660 for(j
=0; j
<irregular
->nb_predicates
[i
]; j
++)
661 result
->predicates
[i
][j
]=irregular
->predicates
[i
][j
];
667 osl_irregular_p
osl_irregular_add_predicates(
668 osl_irregular_p irregular
,
670 int nb_add_predicates
)
673 osl_irregular_p result
=osl_irregular_malloc();
675 result
->nb_control
= irregular
->nb_control
;
676 result
->nb_exit
= irregular
->nb_exit
;
677 result
->nb_statements
= irregular
->nb_statements
+1;
678 int nb_predicates
= result
->nb_control
+ result
->nb_exit
;
680 result
->iterators
= (char***)malloc(sizeof(char**)*nb_predicates
);
681 result
->nb_iterators
= (int*)malloc(sizeof(int)*nb_predicates
);
682 result
->body
= (char**)malloc(sizeof(char*)*nb_predicates
);
683 if (result
->iterators
== NULL
||
684 result
->nb_iterators
== NULL
||
685 result
->body
== NULL
)
687 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
690 //copy controls and exits
691 for(i
=0; i
<nb_predicates
; i
++)
693 result
->nb_iterators
[i
] = irregular
->nb_iterators
[i
];
694 OSL_strdup(result
->body
[i
], irregular
->body
[i
]);
695 result
->iterators
[i
] = (char**)malloc(sizeof(char*) *
696 irregular
->nb_iterators
[i
]);
697 if (result
->iterators
[i
] == NULL
)
699 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
702 for(j
=0; j
<irregular
->nb_iterators
[i
];j
++)
703 OSL_strdup(result
->iterators
[i
][j
], irregular
->iterators
[i
][j
]);
706 result
->nb_predicates
= (int*)malloc(sizeof(int)*result
->nb_statements
);
707 result
->predicates
= (int**)malloc(sizeof(int*)*result
->nb_statements
);
708 if (result
->nb_predicates
== NULL
||
709 result
->predicates
== NULL
)
711 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
714 for(i
=0; i
<irregular
->nb_statements
; i
++)
716 result
->predicates
[i
] = (int*)malloc(sizeof(int)*irregular
->nb_predicates
[i
]);
717 if (result
->predicates
[i
] == NULL
)
719 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
722 result
->nb_predicates
[i
] = irregular
->nb_predicates
[i
];
723 for(j
=0; j
<irregular
->nb_predicates
[i
]; j
++)
724 result
->predicates
[i
][j
]=irregular
->predicates
[i
][j
];
727 result
->predicates
[irregular
->nb_statements
] = (int*)malloc(sizeof(int)*nb_add_predicates
);
728 if (result
->predicates
[irregular
->nb_statements
] == NULL
)
730 fprintf(stderr
, "[OpenScop] Error: memory overflow.\n");
733 for(i
=0; i
<nb_add_predicates
; i
++)
734 result
->predicates
[irregular
->nb_statements
][i
] = predicates
[i
];
735 result
->nb_predicates
[irregular
->nb_statements
] = nb_add_predicates
;
744 * osl_irregular_interface function:
745 * this function creates an interface structure corresponding to the irregular
746 * extension and returns it).
747 * \return An interface structure for the irregular extension.
749 osl_interface_p
osl_irregular_interface() {
750 osl_interface_p interface
= osl_interface_malloc();
752 OSL_strdup(interface
->URI
, OSL_URI_IRREGULAR
);
753 interface
->idump
= (osl_idump_f
)osl_irregular_idump
;
754 interface
->sprint
= (osl_sprint_f
)osl_irregular_sprint
;
755 interface
->sread
= (osl_sread_f
)osl_irregular_sread
;
756 interface
->malloc
= (osl_malloc_f
)osl_irregular_malloc
;
757 interface
->free
= (osl_free_f
)osl_irregular_free
;
758 interface
->clone
= (osl_clone_f
)osl_irregular_clone
;
759 interface
->equal
= (osl_equal_f
)osl_irregular_equal
;