OpenScop  0.9.0
irregular.c
Go to the documentation of this file.
00001 
00002     /*+-----------------------------------------------------------------**
00003      **                       OpenScop Library                          **
00004      **-----------------------------------------------------------------**
00005      **                     extensions/irregular.c                      **
00006      **-----------------------------------------------------------------**
00007      **                   First version: 07/12/2010                     **
00008      **-----------------------------------------------------------------**
00009 
00010  
00011  *****************************************************************************
00012  * OpenScop: Structures and formats for polyhedral tools to talk together    *
00013  *****************************************************************************
00014  *    ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__,                *
00015  *    /   / /  //  //  //  // /   / /  //  //   / /  // /  /|,_,             *
00016  *   /   / /  //  //  //  // /   / /  //  //   / /  // /  / / /\             *
00017  *  |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/  \            *
00018  *  | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\  \ /\           *
00019  *  | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\          *
00020  *  | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \  \         *
00021  *  | P |n| l | = | s | t |=| = |d| = | = | = | |   |=| o | | \# \  \        *
00022  *  | H | | y |   | e | o | | = |l|   |   | = | |   | | G | |  \  \  \       *
00023  *  | I | |   |   | e |   | |   | |   |   |   | |   | |   | |   \  \  \      *
00024  *  | T | |   |   |   |   | |   | |   |   |   | |   | |   | |    \  \  \     *
00025  *  | E | |   |   |   |   | |   | |   |   |   | |   | |   | |     \  \  \    *
00026  *  | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | /      \* \  \   *
00027  *  | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/        \  \ /   *
00028  *  '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---'          '--'    *
00029  *                                                                           *
00030  * Copyright (C) 2008 University Paris-Sud 11 and INRIA                      *
00031  *                                                                           *
00032  * (3-clause BSD license)                                                    *
00033  * Redistribution and use in source  and binary forms, with or without       *
00034  * modification, are permitted provided that the following conditions        *
00035  * are met:                                                                  *
00036  *                                                                           *
00037  * 1. Redistributions of source code must retain the above copyright notice, *
00038  *    this list of conditions and the following disclaimer.                  *
00039  * 2. Redistributions in binary form must reproduce the above copyright      *
00040  *    notice, this list of conditions and the following disclaimer in the    *
00041  *    documentation and/or other materials provided with the distribution.   *
00042  * 3. The name of the author may not be used to endorse or promote products  *
00043  *    derived from this software without specific prior written permission.  *
00044  *                                                                           *
00045  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      *
00046  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
00047  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
00048  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          *
00049  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  *
00050  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
00051  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     *
00052  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       *
00053  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  *
00054  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         *
00055  *                                                                           *
00056  * OpenScop Library, a library to manipulate OpenScop formats and data       *
00057  * structures. Written by:                                                   *
00058  * Cedric Bastoul     <Cedric.Bastoul@u-psud.fr> and                         *
00059  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr>                          *
00060  *                                                                           *
00061  *****************************************************************************/
00062 
00063 #include <stdlib.h>
00064 #include <stdio.h>
00065 #include <string.h>
00066 
00067 #include <osl/macros.h>
00068 #include <osl/util.h>
00069 #include <osl/strings.h>
00070 #include <osl/interface.h>
00071 #include <osl/extensions/irregular.h>
00072 
00073 
00074 /*+***************************************************************************
00075  *                          Structure display function                       *
00076  *****************************************************************************/
00077 
00078 
00089 void osl_irregular_idump(FILE * file, osl_irregular_p irregular, int level) {
00090   int i,j;
00091 
00092   // Go to the right level.
00093   for (j = 0; j < level; j++)
00094     fprintf(file, "|\t");
00095 
00096   if (irregular != NULL)
00097     fprintf(file, "+-- osl_irregular_t\n");
00098   else
00099     fprintf(file, "+-- NULL irregular\n");
00100 
00101   if (irregular != NULL) {
00102     // Go to the right level.
00103     for(j = 0; j <= level; j++)
00104       fprintf(file, "|\t");
00105   
00106     // Display the irregular contents.
00107 
00108     // Print statements
00109     for (i = 0; i < irregular->nb_statements; i++) {
00110       fprintf(file, "statement%d's predicats : ", i);
00111       for(j = 0; j < irregular->nb_predicates[i]; j++)
00112         fprintf(file, "%d ", irregular->predicates[i][j]);
00113       fprintf(file, "\n");
00114     }
00115     // Print predicats
00116     // controls :
00117     for (i = 0; i < irregular->nb_control; i++) {
00118       fprintf(file, "predicat%d's\niterators : ", i);
00119       for(j = 0; j < irregular->nb_iterators[i]; j++)
00120         fprintf(file, "%s ", irregular->iterators[i][j]);
00121       fprintf(file, "\ncontrol body: %s\n", irregular->body[i]);
00122     }
00123     // exits :
00124     for(i = irregular->nb_control;
00125         i < irregular->nb_control + irregular->nb_exit; i++) {
00126       fprintf(file, "predicat%d's\niterators : ", i);
00127       for(j = 0; j < irregular->nb_iterators[i]; j++)
00128         fprintf(file, "%s ", irregular->iterators[i][j]);
00129       fprintf(file, "\nexit body: %s\n", irregular->body[i]);
00130     }
00131   }
00132 
00133   // The last line.
00134   for (j = 0; j <= level; j++)
00135     fprintf(file, "|\t");
00136   fprintf(file, "\n");
00137 }
00138 
00139 
00147 void osl_irregular_dump(FILE * file, osl_irregular_p irregular) {
00148   osl_irregular_idump(file, irregular, 0);
00149 }
00150 
00151 
00159 char * osl_irregular_sprint(osl_irregular_p irregular) {
00160   int high_water_mark = OSL_MAX_STRING,i,j;
00161   char * string = NULL;
00162   char * buffer;
00163 
00164   if (irregular != NULL) {
00165     OSL_malloc(string, char *, high_water_mark * sizeof(char));
00166     OSL_malloc(buffer, char *, OSL_MAX_STRING * sizeof(char));
00167     string[0] = '\0';
00168    
00169     // Print the begin tag.
00170     sprintf(buffer, OSL_TAG_IRREGULAR_START);
00171     osl_util_safe_strcat(&string, buffer, &high_water_mark);
00172 
00173     // Print the content.
00174     sprintf(buffer, "\n%d\n", irregular->nb_statements);
00175     for(i=0; i<irregular->nb_statements; i++) {
00176       sprintf(buffer, "%s%d ", buffer, irregular->nb_predicates[i]);
00177       for(j=0; j<irregular->nb_predicates[i]; j++) {
00178         sprintf(buffer, "%s%d ", buffer, irregular->predicates[i][j]);
00179       }
00180       sprintf(buffer, "%s\n", buffer);
00181     }
00182     // Print the predicates.
00183     // controls:
00184     sprintf(buffer, "%s%d\n", buffer, irregular->nb_control);
00185     sprintf(buffer, "%s%d\n", buffer, irregular->nb_exit);
00186     for(i=0; i<irregular->nb_control; i++) {
00187       sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[i]);
00188       for(j=0; j<irregular->nb_iterators[i];j++)
00189         sprintf(buffer, "%s%s ", buffer, irregular->iterators[i][j]);
00190       sprintf(buffer, "%s\n%s\n", buffer, irregular->body[i]);
00191     }
00192     // exits: 
00193     for(i=0; i<irregular->nb_exit; i++) {
00194       sprintf(buffer, "%s%d ", buffer, irregular->nb_iterators[
00195                                         irregular->nb_control + i]);
00196       for(j=0; j<irregular->nb_iterators[irregular->nb_control + i];j++)
00197         sprintf(buffer, "%s%s ", buffer, irregular->iterators[
00198                                           irregular->nb_control+i][j]);
00199       sprintf(buffer, "%s\n%s\n", buffer, irregular->body[
00200                                           irregular->nb_control + i]);
00201     }
00202 
00203     osl_util_safe_strcat(&string, buffer, &high_water_mark);
00204 
00205     // Print the end tag.
00206     sprintf(buffer, OSL_TAG_IRREGULAR_STOP"\n");
00207     osl_util_safe_strcat(&string, buffer, &high_water_mark);
00208   
00209     // Keep only the memory space we need.
00210     OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
00211     free(buffer);
00212   }
00213 
00214   return string;
00215 }
00216 
00217 
00218 /*****************************************************************************
00219  *                               Reading function                            *
00220  *****************************************************************************/
00221 
00230 osl_irregular_p osl_irregular_sread(char ** extensions_fixme) {
00231   char * content,*tok;
00232   int i,j;
00233   osl_irregular_p irregular;
00234 
00235   // FIXME: this is a quick and dirty thing to accept char ** instead
00236   //        of char * in the parameter: really do it and update the
00237   //        pointer to after what has been read.
00238   content = *extensions_fixme;
00239 
00240   if (content == NULL) {
00241     OSL_debug("no irregular optional tag");
00242     return NULL;
00243   }
00244 
00245   if (strlen(content) > OSL_MAX_STRING)
00246     OSL_error("irregular too long");
00247 
00248   irregular = osl_irregular_malloc();
00249 
00250   // nb statements
00251   tok = strtok(content," \n");
00252   irregular->nb_statements = atoi(tok);
00253   OSL_malloc(irregular->predicates, int **, 
00254                   sizeof(int*) * irregular->nb_statements);
00255   OSL_malloc(irregular->nb_predicates, int *, 
00256                   sizeof(int) * irregular->nb_statements);
00257   
00258   // get predicats
00259   for(i = 0; i < irregular->nb_statements; i++) {
00260     // nb conditions
00261     tok = strtok(NULL," \n");
00262     irregular->nb_predicates[i] = atoi(tok);
00263     OSL_malloc(irregular->predicates[i], int *,
00264                     sizeof(int) * irregular->nb_predicates[i]);
00265     for(j = 0; j < irregular->nb_predicates[i]; j++){
00266       tok = strtok(NULL, " \n");
00267       irregular->predicates[i][j] = atoi(tok);
00268     }
00269   }
00270   // Get nb predicat
00271   // control and exits :
00272   tok = strtok(NULL, " \n");
00273   irregular->nb_control=atoi(tok);
00274   tok = strtok(NULL, " \n");
00275   irregular->nb_exit = atoi(tok);
00276 
00277   int nb_predicates = irregular->nb_control + irregular->nb_exit;
00278 
00279   OSL_malloc(irregular->iterators, char ***,
00280                   sizeof(char **) * nb_predicates);
00281   OSL_malloc(irregular->nb_iterators, int *, sizeof(int) * nb_predicates);
00282   OSL_malloc(irregular->body, char **, sizeof(char *) * nb_predicates);
00283   
00284   for(i = 0; i < nb_predicates; i++) {
00285     // Get number of iterators
00286     tok = strtok(NULL, " \n");
00287     irregular->nb_iterators[i] = atoi(tok);
00288     OSL_malloc(irregular->iterators[i], char **,
00289                     sizeof(char *) * irregular->nb_iterators[i]);
00290     
00291     // Get iterators
00292     for(j = 0; j < irregular->nb_iterators[i]; j++)
00293       OSL_strdup(irregular->iterators[i][j], strtok(NULL, " \n"));
00294     // Get predicat string
00295     OSL_strdup(irregular->body[i], strtok(NULL, "\n"));
00296   }
00297   
00298   return irregular;
00299 }
00300 
00301 
00302 /*+***************************************************************************
00303  *                    Memory allocation/deallocation function                *
00304  *****************************************************************************/
00305 
00306 
00315 osl_irregular_p osl_irregular_malloc() {
00316   osl_irregular_p irregular;
00317 
00318   OSL_malloc(irregular, osl_irregular_p,
00319                   sizeof(osl_irregular_t));
00320   irregular->nb_statements = 0;
00321   irregular->predicates = NULL;
00322   irregular->nb_predicates = NULL;
00323   irregular->nb_control = 0;
00324   irregular->nb_exit = 0;
00325   irregular->nb_iterators = NULL;
00326   irregular->iterators = NULL;
00327   irregular->body = NULL;
00328 
00329   return irregular;
00330 }
00331 
00332 
00339 void osl_irregular_free(osl_irregular_p irregular) {
00340   int i, j, nb_predicates;
00341 
00342   if (irregular != NULL) {
00343     for(i = 0; i < irregular->nb_statements; i++)
00344       free(irregular->predicates[i]);
00345     
00346     if(irregular->predicates != NULL)
00347       free(irregular->predicates);
00348 
00349     nb_predicates = irregular->nb_control + irregular->nb_exit;
00350     for(i = 0; i < nb_predicates; i++) {
00351       for(j = 0; j < irregular->nb_iterators[i]; j++)
00352         free(irregular->iterators[i][j]);
00353       free(irregular->iterators[i]);
00354       free(irregular->body[i]);
00355     }
00356     if(irregular->iterators != NULL)
00357       free(irregular->iterators);
00358     if(irregular->nb_iterators != NULL)
00359       free(irregular->nb_iterators);
00360     if(irregular->body != NULL)
00361       free(irregular->body);
00362     if(irregular->nb_predicates != NULL)
00363       free(irregular->nb_predicates);
00364     free(irregular);
00365   }
00366 }
00367 
00368 
00369 /*+***************************************************************************
00370  *                            Processing functions                           *
00371  *****************************************************************************/
00372 
00373 
00381 osl_irregular_p osl_irregular_clone(osl_irregular_p irregular) {
00382   int i,j;
00383   osl_irregular_p copy;
00384 
00385   if (irregular == NULL)
00386     return NULL;
00387 
00388   copy = osl_irregular_malloc();
00389   copy->nb_statements = irregular->nb_statements;
00390   copy->nb_predicates = (int *)malloc(sizeof(int)*copy->nb_statements);
00391   if (copy->nb_predicates == NULL)
00392   {
00393     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00394     exit(1);
00395   }
00396   copy->predicates = (int **)malloc(sizeof(int*)*copy->nb_statements);
00397   if (copy->predicates == NULL)
00398   {
00399     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00400     exit(1);
00401   }
00402   for(i=0; i<copy->nb_statements; i++)
00403   {
00404     copy->nb_predicates[i]=irregular->nb_predicates[i];
00405     copy->predicates[i] = (int *)malloc(sizeof(int)*copy->nb_predicates[i]);
00406     if (copy->predicates[i] == NULL)
00407     {
00408       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00409       exit(1);
00410     }
00411     for(j=0; j<copy->nb_predicates[i]; j++)
00412       copy->predicates[i][j] = irregular->predicates[i][j];
00413   }
00414 
00415   copy->nb_control  = irregular->nb_control;
00416   copy->nb_exit     = irregular->nb_exit;
00417   int nb_predicates = irregular->nb_control + irregular->nb_exit;
00418   copy->nb_iterators = (int *)malloc(sizeof(int)*nb_predicates);
00419   if (copy->nb_iterators == NULL)
00420   {
00421     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00422     exit(1);
00423   }
00424   copy->iterators = (char ***)malloc(sizeof(char**)*nb_predicates);
00425   if (copy->iterators == NULL)
00426   {
00427     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00428     exit(1);
00429   }
00430   copy->body = (char **)malloc(sizeof(char*)*nb_predicates);
00431   if (copy->body == NULL)
00432   {
00433     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00434     exit(1);
00435   }
00436   for(i=0; i<nb_predicates; i++)
00437   {
00438     copy->nb_iterators[i] = irregular->nb_iterators[i];
00439     copy->iterators[i] = (char**)malloc(sizeof(char*)*copy->nb_iterators[i]);
00440     if (copy->iterators[i] == NULL)
00441     {
00442       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00443       exit(1);
00444     }
00445     for(j=0;j<copy->nb_iterators[i];j++)
00446       OSL_strdup(copy->iterators[i][j], irregular->iterators[i][j]);
00447     OSL_strdup(copy->iterators[i][j], irregular->body[i]);
00448   }
00449 
00450   return copy;
00451 }
00452 
00453 
00462 int
00463 osl_irregular_equal(osl_irregular_p c1, osl_irregular_p c2)
00464 {
00465   int i,j,bool = 0;
00466   if (c1 == c2)
00467     return 1;
00468 
00469   if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL)))
00470     return 0;
00471 
00472   if(c1->nb_statements != c2->nb_statements ||
00473      c1->nb_control    != c2->nb_control    ||
00474      c1->nb_exit       != c2->nb_exit)
00475     return 0;
00476   i=0;
00477   while(bool == 0 && i < c1->nb_statements)
00478   {
00479     bool = c1->nb_predicates[i] != c2->nb_predicates[i] ? 1 : 0;
00480     i++;
00481   }
00482   if(bool != 0)
00483     return 0;
00484 
00485   i = 0;
00486   while(bool == 0 && i < c1->nb_control + c1->nb_exit)
00487   {
00488     bool += c1->nb_iterators[i] != c2->nb_iterators[i] ? 1 : 0;
00489     bool += strcmp(c1->body[i],c2->body[i]);
00490     j = 0;
00491     while(bool == 0 && j < c1->nb_iterators[i])
00492     {
00493       bool += strcmp(c1->iterators[i][j],c2->iterators[i][j]);
00494       j++;
00495     }
00496     i++;
00497   }
00498   if(bool != 0)
00499     return 0;
00500   return 1;
00501 }
00502 
00503 osl_irregular_p osl_irregular_add_control(
00504                                                osl_irregular_p irregular,
00505                                                char** iterators,
00506                                                int nb_iterators,
00507                                                char* body)
00508 {
00509   int i,j;
00510   osl_irregular_p result=osl_irregular_malloc();
00511 
00512   result->nb_control    = irregular->nb_control + 1;
00513   result->nb_exit       = irregular->nb_exit;
00514   result->nb_statements = irregular->nb_statements;
00515   int nb_predicates     = result->nb_control + result->nb_exit;
00516 
00517   result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
00518   result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
00519   result->body = (char**)malloc(sizeof(char*)*nb_predicates);
00520   if (result->iterators == NULL || 
00521       result->nb_iterators == NULL ||
00522       result->body == NULL)
00523   {
00524     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00525     exit(1);
00526   }
00527   //copy controls
00528   for(i=0; i<irregular->nb_control; i++)
00529   {
00530     result->nb_iterators[i] = irregular->nb_iterators[i];
00531     OSL_strdup(result->body[i], irregular->body[i]); 
00532     result->iterators[i] = (char**)malloc(sizeof(char*)  *  
00533                                           irregular->nb_iterators[i]);
00534     if (result->iterators[i] == NULL)
00535     {
00536       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00537       exit(1);
00538     }
00539     for(j=0; j<irregular->nb_iterators[i];j++)
00540       OSL_strdup(result->iterators[i][j], irregular->iterators[i][j]);
00541   }
00542   //add controls
00543   result->iterators[irregular->nb_control] = (char**)malloc(sizeof(char*)*nb_iterators);
00544   if (result->iterators[irregular->nb_control] == NULL)
00545   {
00546     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00547     exit(1);
00548   }
00549   for(i=0; i<nb_iterators; i++)
00550     OSL_strdup(result->iterators[irregular->nb_control][i], iterators[i]);
00551   result->nb_iterators[irregular->nb_control] = nb_iterators;
00552   OSL_strdup(result->body[irregular->nb_control], body);
00553   //copy exits
00554   for(i=result->nb_control; i<nb_predicates; i++)
00555   {
00556     result->nb_iterators[i] = irregular->nb_iterators[i-1];
00557     OSL_strdup(result->body[i], irregular->body[i-1]); 
00558     result->iterators[i] = (char**)malloc(sizeof(char*)  *  
00559                                           irregular->nb_iterators[i-1]);
00560     if (result->iterators[i] == NULL)
00561     {
00562       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00563       exit(1);
00564     }
00565     for(j=0; j<irregular->nb_iterators[i-1];j++)
00566       OSL_strdup(result->iterators[i][j], irregular->iterators[i-1][j]);
00567   }
00568   // copy statements
00569   result->nb_predicates = (int*)malloc(sizeof(int)*irregular->nb_statements);
00570   result->predicates = (int**)malloc(sizeof(int*)*irregular->nb_statements);
00571   if (result->nb_predicates == NULL || result->predicates == NULL)
00572   {
00573     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00574     exit(1);
00575   }
00576   for(i=0; i<irregular->nb_statements; i++)
00577   { 
00578     result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
00579     if (result->predicates[i] == NULL)
00580     {
00581       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00582       exit(1);
00583     }
00584     result->nb_predicates[i] = irregular->nb_predicates[i];
00585     for(j=0; j<irregular->nb_predicates[i]; j++)
00586       result->predicates[i][j]=irregular->predicates[i][j];
00587   }
00588   return result;
00589 }
00590 
00591 
00592 osl_irregular_p osl_irregular_add_exit(
00593                                                osl_irregular_p irregular,
00594                                                char** iterators,
00595                                                int nb_iterators,
00596                                                char* body)
00597 {
00598   int i,j;
00599   osl_irregular_p result=osl_irregular_malloc();
00600 
00601   result->nb_control    = irregular->nb_control;
00602   result->nb_exit       = irregular->nb_exit + 1;
00603   result->nb_statements = irregular->nb_statements;
00604   int nb_predicates     = result->nb_control + result->nb_exit;
00605 
00606   result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
00607   result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
00608   result->body = (char**)malloc(sizeof(char*)*nb_predicates);
00609   if (result->iterators == NULL || 
00610       result->nb_iterators == NULL ||
00611       result->body == NULL)
00612   {
00613     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00614     exit(1);
00615   }
00616   //copy controls and exits
00617   for(i=0; i<nb_predicates - 1; i++)
00618   {
00619     result->nb_iterators[i] = irregular->nb_iterators[i];
00620     OSL_strdup(result->body[i], irregular->body[i]); 
00621     result->iterators[i] = (char**)malloc(sizeof(char*)  *  
00622                                           irregular->nb_iterators[i]);
00623     if (result->iterators[i] == NULL)
00624     {
00625       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00626       exit(1);
00627     }
00628     for(j=0; j<irregular->nb_iterators[i];j++)
00629       OSL_strdup(result->iterators[i][j], irregular->iterators[i][j]);
00630   }
00631   //add exit
00632   result->iterators[nb_predicates-1] = (char**)malloc(sizeof(char*)*nb_iterators);
00633   if (result->iterators[nb_predicates-1] == NULL)
00634   {
00635     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00636     exit(1);
00637   }
00638 
00639   for(i=0; i<nb_iterators; i++)
00640     OSL_strdup(result->iterators[nb_predicates-1][i], iterators[i]);
00641   result->nb_iterators[nb_predicates-1] = nb_iterators;
00642   OSL_strdup(result->body[nb_predicates-1], body);
00643   // copy statements
00644   result->nb_predicates = (int*)malloc(sizeof(int)*irregular->nb_statements);
00645   result->predicates = (int**)malloc(sizeof(int*)*irregular->nb_statements);
00646   if (result->nb_predicates == NULL || result->predicates == NULL)
00647   {
00648     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00649     exit(1);
00650   }
00651   for(i=0; i<irregular->nb_statements; i++)
00652   { 
00653     result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
00654     if (result->predicates[i] == NULL)
00655     {
00656       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00657       exit(1);
00658     }
00659     result->nb_predicates[i] = irregular->nb_predicates[i];
00660     for(j=0; j<irregular->nb_predicates[i]; j++)
00661       result->predicates[i][j]=irregular->predicates[i][j];
00662   }
00663   return result;
00664 }
00665 
00666 
00667 osl_irregular_p osl_irregular_add_predicates(
00668                                                osl_irregular_p irregular,
00669                                                int* predicates, 
00670                                                int nb_add_predicates)
00671 {
00672   int i,j;
00673   osl_irregular_p result=osl_irregular_malloc();
00674 
00675   result->nb_control    = irregular->nb_control;
00676   result->nb_exit       = irregular->nb_exit;
00677   result->nb_statements = irregular->nb_statements+1;
00678   int nb_predicates     = result->nb_control + result->nb_exit;
00679 
00680   result->iterators = (char***)malloc(sizeof(char**)*nb_predicates);
00681   result->nb_iterators = (int*)malloc(sizeof(int)*nb_predicates);
00682   result->body = (char**)malloc(sizeof(char*)*nb_predicates);
00683   if (result->iterators == NULL || 
00684       result->nb_iterators == NULL ||
00685       result->body == NULL)
00686   {
00687     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00688     exit(1);
00689   }
00690   //copy controls and exits
00691   for(i=0; i<nb_predicates; i++)
00692   {
00693     result->nb_iterators[i] = irregular->nb_iterators[i];
00694     OSL_strdup(result->body[i], irregular->body[i]); 
00695     result->iterators[i] = (char**)malloc(sizeof(char*)  *  
00696                                           irregular->nb_iterators[i]);
00697     if (result->iterators[i] == NULL)
00698     {
00699       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00700       exit(1);
00701     }
00702     for(j=0; j<irregular->nb_iterators[i];j++)
00703       OSL_strdup(result->iterators[i][j], irregular->iterators[i][j]);
00704   }
00705   //copy statements
00706   result->nb_predicates = (int*)malloc(sizeof(int)*result->nb_statements);
00707   result->predicates = (int**)malloc(sizeof(int*)*result->nb_statements);
00708   if (result->nb_predicates == NULL || 
00709       result->predicates == NULL)
00710   {
00711     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00712     exit(1);
00713   }
00714   for(i=0; i<irregular->nb_statements; i++)
00715   { 
00716     result->predicates[i] = (int*)malloc(sizeof(int)*irregular->nb_predicates[i]);
00717     if (result->predicates[i] == NULL)
00718     {
00719       fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00720       exit(1);
00721     }
00722     result->nb_predicates[i] = irregular->nb_predicates[i];
00723     for(j=0; j<irregular->nb_predicates[i]; j++)
00724       result->predicates[i][j]=irregular->predicates[i][j];
00725   }
00726   //add statement
00727   result->predicates[irregular->nb_statements] = (int*)malloc(sizeof(int)*nb_add_predicates);
00728   if (result->predicates[irregular->nb_statements] == NULL)
00729   {
00730     fprintf(stderr, "[OpenScop] Error: memory overflow.\n");
00731     exit(1);
00732   }
00733   for(i=0; i<nb_add_predicates; i++)
00734     result->predicates[irregular->nb_statements][i] = predicates[i];
00735   result->nb_predicates[irregular->nb_statements] = nb_add_predicates;
00736 
00737   return result;
00738 
00739 
00740 }
00741 
00742 
00749 osl_interface_p osl_irregular_interface() {
00750   osl_interface_p interface = osl_interface_malloc();
00751   
00752   OSL_strdup(interface->URI, OSL_URI_IRREGULAR);
00753   interface->idump  = (osl_idump_f)osl_irregular_idump;
00754   interface->sprint = (osl_sprint_f)osl_irregular_sprint;
00755   interface->sread  = (osl_sread_f)osl_irregular_sread;
00756   interface->malloc = (osl_malloc_f)osl_irregular_malloc;
00757   interface->free   = (osl_free_f)osl_irregular_free;
00758   interface->clone  = (osl_clone_f)osl_irregular_clone;
00759   interface->equal  = (osl_equal_f)osl_irregular_equal;
00760 
00761   return interface;
00762 }
00763 
00764