Add exit predicates to irregular extension
[openscop.git] / source / extensions / irregular.c
blob4ef494cd2fda27b94472d75e23df165a3626de68
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
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 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
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 <string.h>
66 # include <openscop/extension.h>
69 /*+***************************************************************************
70 * Structure display function *
71 *****************************************************************************/
74 /**
75 * openscop_irregular_idump function:
76 * this function displays an openscop_irregular_t structure (*irregular) into a
77 * file (file, possibly stdout) in a way that trends to be understandable. It
78 * includes an indentation level (level) in order to work with others
79 * print_structure functions.
80 * \param file The file where the information has to be printed.
81 * \param irregular The irregular structure whose information has to be printed.
82 * \param level Number of spaces before printing, for each line.
84 void
85 openscop_irregular_idump(FILE * file, openscop_irregular_p irregular,
86 int level)
88 int i,j;
90 // Go to the right level.
91 for (j = 0; j < level; j++)
92 fprintf(file, "|\t");
94 if (irregular != NULL)
95 fprintf(file, "+-- openscop_irregular_t\n");
96 else
97 fprintf(file, "+-- NULL irregular\n");
99 if (irregular != NULL)
101 // Go to the right level.
102 for(j = 0; j <= level; j++)
103 fprintf(file, "|\t");
105 // Display the irregular contents.
107 // Print statements
108 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]);
113 fprintf(file, "\n");
115 // Print predicats
116 // controls :
117 for (i=0; i<irregular->nb_control; i++)
119 fprintf(file, "predicat%d's\niterators : ", i);
120 for(j=0; j<irregular->nb_iterators[i]; j++)
121 fprintf(file, "%s ", irregular->iterators[i][j]);
122 fprintf(file, "\ncontrol body: %s\n", irregular->body[i]);
124 // exits :
125 for(i=irregular->nb_control;i<irregular->nb_control+irregular->nb_exit;i++)
127 fprintf(file, "predicat%d's\niterators : ", i);
128 for(j=0; j<irregular->nb_iterators[i]; j++)
129 fprintf(file, "%s ", irregular->iterators[i][j]);
130 fprintf(file, "\nexit body: %s\n", irregular->body[i]);
134 // The last line.
135 for (j = 0; j <= level; j++)
136 fprintf(file, "|\t");
137 fprintf(file, "\n");
142 * openscop_irregular_dump function:
143 * this function prints the content of an openscop_irregular_t structure
144 * (*irregular) into a file (file, possibly stdout).
145 * \param file The file where the information has to be printed.
146 * \param irregular The irregular structure whose information has to be printed.
148 void
149 openscop_irregular_dump(FILE * file, openscop_irregular_p irregular)
151 openscop_irregular_idump(file, irregular, 0);
156 * openscop_irregular_sprint function:
157 * this function prints the content of an openscop_irregular_t structure
158 * (*irregular) into a string (returned) in the OpenScop textual format.
159 * \param irregular The irregular structure whose information has to be printed.
160 * \return A string containing the OpenScop dump of the irregular structure.
162 char *
163 openscop_irregular_sprint(openscop_irregular_p irregular)
165 int high_water_mark = OPENSCOP_MAX_STRING,i,j;
166 char * string = NULL;
167 char * buffer;
169 if (irregular != NULL)
171 string = (char *)malloc(high_water_mark * sizeof(char));
172 buffer = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char));
173 if ((string == NULL) || (buffer == NULL))
175 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
176 exit(1);
178 string[0] = '\0';
180 // Print the begin tag.
181 sprintf(buffer, OPENSCOP_TAG_IRREGULAR_START);
182 openscop_util_safe_strcat(&string, buffer, &high_water_mark);
184 // Print the content.
185 sprintf(buffer, "\n%d\n", irregular->nb_statements);
186 for(i=0; i<irregular->nb_statements; i++)
188 sprintf(buffer, "%s%d ", buffer, irregular->nb_predicates[i]);
189 for(j=0; j<irregular->nb_predicates[i]; j++)
191 sprintf(buffer, "%s%d ", buffer, irregular->predicates[i][j]);
193 sprintf(buffer, "%s\n", buffer);
195 // Print the predicats.
196 // controls :
197 sprintf(buffer, "%s%d\n", buffer, irregular->nb_control);
198 sprintf(buffer, "%s%d\n", buffer, irregular->nb_exit);
199 for(i=0; i<irregular->nb_control; i++)
201 sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[i]);
202 for(j=0; j<irregular->nb_iterators[i];j++)
203 sprintf(buffer, "%s%s ", buffer, irregular->iterators[i][j]);
204 sprintf(buffer, "%s\n%s\n", buffer, irregular->body[i]);
206 // exits :
207 for(i=0; i<irregular->nb_exit; i++)
209 sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[
210 irregular->nb_control + i]);
211 for(j=0; j<irregular->nb_iterators[irregular->nb_control + i];j++)
212 sprintf(buffer, "%s%s ", buffer, irregular->iterators[
213 irregular->nb_control+i][j]);
214 sprintf(buffer, "%s\n%s\n", buffer, irregular->body[
215 irregular->nb_control + i]);
218 openscop_util_safe_strcat(&string, buffer, &high_water_mark);
220 // Print the end tag.
221 sprintf(buffer, OPENSCOP_TAG_IRREGULAR_STOP"\n");
222 openscop_util_safe_strcat(&string, buffer, &high_water_mark);
224 // Keep only the memory space we need.
225 string = (char *)realloc(string, (strlen(string) + 1) * sizeof(char));
226 free(buffer);
229 return string;
233 /*****************************************************************************
234 * Reading function *
235 *****************************************************************************/
238 * openscop_irregular_sread function:
239 * this function reads a irregular structure from a string complying to the
240 * OpenScop textual format and returns a pointer to this irregular structure.
241 * The string should contain only one textual format of a irregular structure.
242 * \param extensions The input string where to find a irregular structure.
243 * \return A pointer to the irregular structure that has been read.
245 openscop_irregular_p
246 openscop_irregular_sread(char * extensions)
248 char * content,*tok;
249 int i,j;
250 openscop_irregular_p irregular;
252 content = openscop_util_tag_content(extensions, OPENSCOP_TAG_IRREGULAR_START,
253 OPENSCOP_TAG_IRREGULAR_STOP);
254 if (content == NULL)
256 fprintf(stderr, "[OpenScop] Info: no irregular optional tag.\n");
257 return NULL;
260 if (strlen(content) > OPENSCOP_MAX_STRING)
262 fprintf(stderr, "[OpenScop] Error: irregular too long.\n");
263 exit(1);
266 irregular = openscop_irregular_malloc();
268 // nb statements
269 tok = strtok(content," \n");
270 irregular->nb_statements = atoi(tok);
271 irregular->predicates = (int**) malloc(sizeof(int*) *
272 irregular->nb_statements);
273 irregular->nb_predicates = (int*) malloc(sizeof(int) *
274 irregular->nb_statements);
275 if (irregular->predicates == NULL)
277 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
278 exit(1);
280 // get predicats
281 for(i=0; i<irregular->nb_statements; i++)
283 // nb conditions
284 tok = strtok(NULL," \n");
285 irregular->nb_predicates[i] = atoi(tok);
286 irregular->predicates[i] = (int* )malloc(sizeof(int)*
287 irregular->nb_predicates[i]);
288 if (irregular->predicates[i] == NULL)
290 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
291 exit(1);
293 for(j=0; j<irregular->nb_predicates[i]; j++){
294 tok = strtok(NULL," \n");
295 irregular->predicates[i][j]=atoi(tok);
298 // Get nb predicat
299 // control and exits :
300 tok = strtok(NULL," \n");
301 irregular->nb_control=atoi(tok);
302 tok = strtok(NULL," \n");
303 irregular->nb_exit=atoi(tok);
305 int nb_predicates = irregular->nb_control + irregular->nb_exit;
307 irregular->iterators = (char***) malloc(sizeof(char**) *
308 nb_predicates);
309 if (irregular->iterators == NULL)
311 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
312 exit(1);
314 irregular->nb_iterators = (int*) malloc(sizeof(int) *
315 nb_predicates);
316 if (irregular->nb_iterators == NULL)
318 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
319 exit(1);
321 irregular->body = (char**) malloc(sizeof(char*) *
322 nb_predicates);
323 if (irregular->body == NULL)
325 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
326 exit(1);
328 for(i=0; i<nb_predicates; i++)
330 // Get number of iterators
331 tok = strtok(NULL," \n");
332 irregular->nb_iterators[i]=atoi(tok);
333 irregular->iterators[i] = (char**) malloc(sizeof(char*) *
334 irregular->nb_iterators[i]);
335 if (irregular->iterators[i] == NULL)
337 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
338 exit(1);
340 // Get iterators
341 for(j=0; j<irregular->nb_iterators[i]; j++)
342 irregular->iterators[i][j]=strdup(strtok(NULL," \n"));
343 // Get predicat string
344 irregular->body[i] = strdup(strtok(NULL,"\n"));
347 return irregular;
351 /*+***************************************************************************
352 * Memory allocation/deallocation function *
353 *****************************************************************************/
357 * openscop_irregular_malloc function:
358 * This function allocates the memory space for an openscop_irregular_t
359 * structure and sets its fields with default values. Then it returns a
360 * pointer to the allocated space.
361 * \return A pointer to an empty irregular structure with fields set to
362 * default values.
364 openscop_irregular_p
365 openscop_irregular_malloc()
367 openscop_irregular_p irregular;
369 irregular = (openscop_irregular_p)malloc(sizeof(openscop_irregular_t));
370 if (irregular == NULL)
372 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
373 exit(1);
376 irregular->nb_statements = 0;
377 irregular->predicates = NULL;
378 irregular->nb_predicates = NULL;
379 irregular->nb_control = 0;
380 irregular->nb_exit = 0;
381 irregular->nb_iterators = NULL;
382 irregular->iterators = NULL;
383 irregular->body = NULL;
385 return irregular;
390 * openscop_irregular_free function:
391 * This function frees the allocated memory for an openscop_irregular_t
392 * structure.
393 * \param irregular The pointer to the irregular structure we want to free.
395 void
396 openscop_irregular_free(openscop_irregular_p irregular)
398 int i,j,nb_predicates;
399 if (irregular != NULL)
401 for(i=0; i<irregular->nb_statements; i++)
403 free(irregular->predicates[i]);
405 if(irregular->predicates != NULL)
406 free(irregular->predicates);
408 nb_predicates = irregular->nb_control+irregular->nb_exit;
409 for(i=0; i<nb_predicates; i++)
411 for(j=0; j<irregular->nb_iterators[i]; j++)
412 free(irregular->iterators[i][j]);
413 free(irregular->iterators[i]);
414 free(irregular->body[i]);
416 if(irregular->iterators != NULL)
417 free(irregular->iterators);
418 if(irregular->nb_iterators != NULL)
419 free(irregular->nb_iterators);
420 if(irregular->body != NULL)
421 free(irregular->body);
422 if(irregular->nb_predicates != NULL)
423 free(irregular->nb_predicates);
424 free(irregular);
429 /*+***************************************************************************
430 * Processing functions *
431 *****************************************************************************/
435 * openscop_irregular_copy function:
436 * This function builds and returns a "hard copy" (not a pointer copy) of an
437 * openscop_irregular_t data structure.
438 * \param irregular The pointer to the irregular structure we want to copy.
439 * \return A pointer to the copy of the irregular structure.
441 openscop_irregular_p
442 openscop_irregular_copy(openscop_irregular_p irregular)
444 int i,j;
445 openscop_irregular_p copy;
447 if (irregular == NULL)
448 return NULL;
450 copy = openscop_irregular_malloc();
451 if (copy == NULL)
453 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
454 exit(1);
457 copy->nb_statements = irregular->nb_statements;
458 copy->nb_predicates = (int *)malloc(sizeof(int)*copy->nb_statements);
459 if (copy->nb_predicates == NULL)
461 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
462 exit(1);
464 copy->predicates = (int **)malloc(sizeof(int*)*copy->nb_statements);
465 if (copy->predicates == NULL)
467 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
468 exit(1);
470 for(i=0; i<copy->nb_statements; i++)
472 copy->nb_predicates[i]=irregular->nb_predicates[i];
473 copy->predicates[i] = (int *)malloc(sizeof(int)*copy->nb_predicates[i]);
474 if (copy->predicates[i] == NULL)
476 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
477 exit(1);
479 for(j=0; j<copy->nb_predicates[i]; j++)
480 copy->predicates[i][j] = irregular->predicates[i][j];
483 copy->nb_control = irregular->nb_control;
484 copy->nb_exit = irregular->nb_exit;
485 int nb_predicates = irregular->nb_control + irregular->nb_exit;
486 copy->nb_iterators = (int *)malloc(sizeof(int)*nb_predicates);
487 if (copy->nb_iterators == NULL)
489 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
490 exit(1);
492 copy->iterators = (char ***)malloc(sizeof(char**)*nb_predicates);
493 if (copy->iterators == NULL)
495 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
496 exit(1);
498 copy->body = (char **)malloc(sizeof(char*)*nb_predicates);
499 if (copy->body == NULL)
501 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
502 exit(1);
504 for(i=0; i<nb_predicates; i++)
506 copy->nb_iterators[i] = irregular->nb_iterators[i];
507 copy->iterators[i] = (char**)malloc(sizeof(char*)*copy->nb_iterators[i]);
508 if (copy->iterators[i] == NULL)
510 fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
511 exit(1);
513 for(j=0;j<copy->nb_iterators[i];j++)
514 copy->iterators[i][j] = strdup(irregular->iterators[i][j]);
515 copy->body[i] = strdup(irregular->body[i]);
518 return copy;
523 * openscop_irregular_equal function:
524 * this function returns true if the two irregular structures are the same
525 * (content-wise), false otherwise. This functions considers two irregular
526 * \param c1 The first irregular structure.
527 * \param c2 The second irregular structure.
528 * \return 1 if c1 and c2 are the same (content-wise), 0 otherwise.
531 openscop_irregular_equal(openscop_irregular_p c1, openscop_irregular_p c2)
533 int i,j,bool = 0;
534 if (c1 == c2)
535 return 1;
537 if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL)))
538 return 0;
540 if(c1->nb_statements != c2->nb_statements ||
541 c1->nb_control != c2->nb_control ||
542 c1->nb_exit != c2->nb_exit)
543 return 0;
544 i=0;
545 while(bool == 0 && i < c1->nb_statements)
547 bool = c1->nb_predicates[i] != c2->nb_predicates[i] ? 1 : 0;
548 i++;
550 if(bool != 0)
551 return 0;
553 i = 0;
554 while(bool == 0 && i < c1->nb_control + c1->nb_exit)
556 bool += c1->nb_iterators[i] != c2->nb_iterators[i] ? 1 : 0;
557 bool += strcmp(c1->body[i],c2->body[i]);
558 j = 0;
559 while(bool == 0 && j < c1->nb_iterators[i])
561 bool += strcmp(c1->iterators[i][j],c2->iterators[i][j]);
562 j++;
564 i++;
566 if(bool != 0)
567 return 0;
568 return 1;
571 openscop_irregular_p openscop_irregular_add_control(
572 openscop_irregular_p irregular,
573 char** iterators,
574 int nb_iterators,
575 char* body)
577 int i,j;
578 openscop_irregular_p result=openscop_irregular_malloc();
580 result->nb_control = irregular->nb_control + 1;
581 result->nb_exit = irregular->nb_exit;
582 result->nb_statements = irregular->nb_statements;
583 int nb_predicates = result->nb_control + result->nb_exit;
585 result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
586 result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
587 result->body = (char**)malloc(sizeof(char*)*nb_predicates);
588 //copy controls
589 for(i=0; i<irregular->nb_control; i++)
591 result->nb_iterators[i] = irregular->nb_iterators[i];
592 result->body[i] = strdup(irregular->body[i]);
593 result->iterators[i] = (char**)malloc(sizeof(char*) *
594 irregular->nb_iterators[i]);
595 for(j=0; j<irregular->nb_iterators[i];j++)
596 result->iterators[i][j] = strdup(irregular->iterators[i][j]);
598 //add controls
599 result->iterators[irregular->nb_control] = (char**)malloc(sizeof(char*)*nb_iterators);
600 for(i=0; i<nb_iterators; i++)
601 result->iterators[irregular->nb_control][i] = strdup(iterators[i]);
602 result->nb_iterators[irregular->nb_control] = nb_iterators;
603 result->body[irregular->nb_control] = strdup(body);
604 //copy exits
605 for(i=result->nb_control; i<nb_predicates; i++)
607 result->nb_iterators[i] = irregular->nb_iterators[i-1];
608 result->body[i] = strdup(irregular->body[i-1]);
609 result->iterators[i] = (char**)malloc(sizeof(char*) *
610 irregular->nb_iterators[i-1]);
611 for(j=0; j<irregular->nb_iterators[i-1];j++)
612 result->iterators[i][j] = strdup(irregular->iterators[i-1][j]);
614 // copy statements
615 result->nb_predicates = (int*)malloc(sizeof(int)*irregular->nb_statements);
616 result->predicates = (int**)malloc(sizeof(int*)*irregular->nb_statements);
617 for(i=0; i<irregular->nb_statements; i++)
619 result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
620 result->nb_predicates[i] = irregular->nb_predicates[i];
621 for(j=0; j<irregular->nb_predicates[i]; j++)
622 result->predicates[i][j]=irregular->predicates[i][j];
624 return result;
628 openscop_irregular_p openscop_irregular_add_exit(
629 openscop_irregular_p irregular,
630 char** iterators,
631 int nb_iterators,
632 char* body)
634 int i,j;
635 openscop_irregular_p result=openscop_irregular_malloc();
637 result->nb_control = irregular->nb_control;
638 result->nb_exit = irregular->nb_exit + 1;
639 result->nb_statements = irregular->nb_statements;
640 int nb_predicates = result->nb_control + result->nb_exit;
642 result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
643 result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
644 result->body = (char**)malloc(sizeof(char*)*nb_predicates);
645 //copy controls and exits
646 for(i=0; i<nb_predicates - 1; i++)
648 result->nb_iterators[i] = irregular->nb_iterators[i];
649 result->body[i] = strdup(irregular->body[i]);
650 result->iterators[i] = (char**)malloc(sizeof(char*) *
651 irregular->nb_iterators[i]);
652 for(j=0; j<irregular->nb_iterators[i];j++)
653 result->iterators[i][j] = strdup(irregular->iterators[i][j]);
655 //add exit
656 result->iterators[nb_predicates-1] = (char**)malloc(sizeof(char*)*nb_iterators);
657 for(i=0; i<nb_iterators; i++)
658 result->iterators[nb_predicates-1][i] = strdup(iterators[i]);
659 result->nb_iterators[nb_predicates-1] = nb_iterators;
660 result->body[nb_predicates-1] = strdup(body);
661 // copy statements
662 result->nb_predicates = (int*)malloc(sizeof(int)*irregular->nb_statements);
663 result->predicates = (int**)malloc(sizeof(int*)*irregular->nb_statements);
664 for(i=0; i<irregular->nb_statements; i++)
666 result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
667 result->nb_predicates[i] = irregular->nb_predicates[i];
668 for(j=0; j<irregular->nb_predicates[i]; j++)
669 result->predicates[i][j]=irregular->predicates[i][j];
671 return result;
675 openscop_irregular_p openscop_irregular_add_predicates(
676 openscop_irregular_p irregular,
677 int* predicates,
678 int nb_add_predicates)
680 int i,j;
681 openscop_irregular_p result=openscop_irregular_malloc();
683 result->nb_control = irregular->nb_control;
684 result->nb_exit = irregular->nb_exit;
685 result->nb_statements = irregular->nb_statements+1;
686 int nb_predicates = result->nb_control + result->nb_exit;
688 result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
689 result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
690 result->body = (char**)malloc(sizeof(char*)*nb_predicates);
691 //copy controls and exits
692 for(i=0; i<nb_predicates; i++)
694 result->nb_iterators[i] = irregular->nb_iterators[i];
695 result->body[i] = strdup(irregular->body[i]);
696 result->iterators[i] = (char**)malloc(sizeof(char*) *
697 irregular->nb_iterators[i]);
698 for(j=0; j<irregular->nb_iterators[i];j++)
699 result->iterators[i][j] = strdup(irregular->iterators[i][j]);
701 //copy statements
702 result->nb_predicates = (int*)malloc(sizeof(int)*result->nb_statements);
703 result->predicates = (int**)malloc(sizeof(int*)*result->nb_statements);
704 for(i=0; i<irregular->nb_statements; i++)
706 result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
707 result->nb_predicates[i] = irregular->nb_predicates[i];
708 for(j=0; j<irregular->nb_predicates[i]; j++)
709 result->predicates[i][j]=irregular->predicates[i][j];
711 //add statement
712 result->predicates[irregular->nb_statements] = (int*)malloc(sizeof(int)*nb_add_predicates);
713 for(i=0; i<nb_add_predicates; i++)
714 result->predicates[irregular->nb_statements][i] = predicates[i];
715 result->nb_predicates[irregular->nb_statements] = nb_add_predicates;
717 return result;