allow building without isl
[cloog/uuh.git] / source / statement.c
blob9805ec38e126d156e0d1c14aa462fdd214c9ee74
2 /**-------------------------------------------------------------------**
3 ** CLooG **
4 **-------------------------------------------------------------------**
5 ** statement.c **
6 **-------------------------------------------------------------------**
7 ** First version: november 4th 2001 **
8 **-------------------------------------------------------------------**/
11 /******************************************************************************
12 * CLooG : the Chunky Loop Generator (experimental) *
13 ******************************************************************************
14 * *
15 * Copyright (C) 2001-2005 Cedric Bastoul *
16 * *
17 * This library is free software; you can redistribute it and/or *
18 * modify it under the terms of the GNU Lesser General Public *
19 * License as published by the Free Software Foundation; either *
20 * version 2.1 of the License, or (at your option) any later version. *
21 * *
22 * This library is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
25 * Lesser General Public License for more details. *
26 * *
27 * You should have received a copy of the GNU Lesser General Public *
28 * License along with this library; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
30 * Boston, MA 02110-1301 USA *
31 * *
32 * CLooG, the Chunky Loop Generator *
33 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
34 * *
35 ******************************************************************************/
36 /* CAUTION: the english used for comments is probably the worst you ever read,
37 * please feel free to correct and improve it !
40 # include <stdlib.h>
41 # include <stdio.h>
42 # include <string.h>
43 # include "../include/cloog/cloog.h"
46 /******************************************************************************
47 * Memory leaks hunting *
48 ******************************************************************************/
51 /**
52 * These functions and global variables are devoted to memory leaks hunting: we
53 * want to know at each moment how many CloogStatement structures had been
54 * allocated (cloog_statement_allocated) and how many had been freed
55 * (cloog_statement_freed). Each time a CloogStatement structure is allocated,
56 * a call to the function cloog_statement_leak_up() must be carried out, and
57 * respectively cloog_statement_leak_down() when a CloogStatement structure is
58 * freed. The special variable cloog_statement_max gives the maximal number of
59 * CloogStatement structures simultaneously alive (i.e. allocated and
60 * non-freed) in memory.
61 * - July 3rd->11th 2003: first version (memory leaks hunt and correction).
65 static void cloog_statement_leak_up(CloogState *state)
67 state->statement_allocated++;
68 if ((state->statement_allocated - state->statement_freed) > state->statement_max)
69 state->statement_max = state->statement_allocated - state->statement_freed ;
73 static void cloog_statement_leak_down(CloogState *state)
75 state->statement_freed++;
79 /******************************************************************************
80 * Structure display function *
81 ******************************************************************************/
84 /**
85 * cloog_domain_print_structure :
86 * this function is a human-friendly way to display the CloogDomain data
87 * structure, it includes an indentation level (level) in order to work with
88 * others print_structure functions.
89 * - June 16th 2005: first version.
91 void cloog_statement_print_structure(file, statement, level)
92 FILE * file ;
93 CloogStatement * statement ;
94 int level ;
95 { int i ;
97 if (statement != NULL)
98 { /* Go to the right level. */
99 for (i=0; i<level; i++)
100 fprintf(file,"|\t") ;
101 fprintf(file,"+-- CloogStatement %d \n",statement->number) ;
103 statement = statement->next ;
105 while (statement != NULL)
106 { for (i=0; i<level; i++)
107 fprintf(file,"|\t") ;
108 fprintf(file,"| |\n");
109 for (i=0; i<level; i++)
110 fprintf(file,"|\t") ;
111 fprintf(file,"| V\n");
113 for (i=0; i<level; i++)
114 fprintf(file,"|\t") ;
115 fprintf(file,"| CloogStatement %d \n",statement->number) ;
116 statement = statement->next ;
119 else
120 { for (i=0; i<level; i++)
121 fprintf(file,"|\t") ;
123 fprintf(file,"+-- No CloogStatement\n") ;
129 * cloog_statement_print function:
130 * This function prints the content of a CloogStatement structure (statement)
131 * into a file (file, possibly stdout).
133 void cloog_statement_print(FILE * file, CloogStatement * statement)
134 { cloog_statement_print_structure(file,statement,0) ;
138 /******************************************************************************
139 * Memory deallocation function *
140 ******************************************************************************/
144 * cloog_statement_free function:
145 * This function frees the allocated memory for a CloogStatement structure.
147 void cloog_statement_free(CloogStatement * statement)
148 { CloogStatement * next ;
150 while (statement != NULL) {
151 cloog_statement_leak_down(statement->state);
153 next = statement->next ;
154 /* free(statement->usr) ; Actually, this is user's job ! */
155 free(statement) ;
156 statement = next ;
161 /******************************************************************************
162 * Processing functions *
163 ******************************************************************************/
167 * cloog_statement_malloc function:
168 * This function allocates the memory space for a CloogStatement structure and
169 * sets its fields with default values. Then it returns a pointer to the
170 * allocated space.
171 * - November 21th 2005: first version.
173 CloogStatement *cloog_statement_malloc(CloogState *state)
174 { CloogStatement * statement ;
176 /* Memory allocation for the CloogStatement structure. */
177 statement = (CloogStatement *)malloc(sizeof(CloogStatement)) ;
178 if (statement == NULL)
179 cloog_die("memory overflow.\n");
180 cloog_statement_leak_up(state);
182 /* We set the various fields with default values. */
183 statement->state = state;
184 statement->number = 0;
185 statement->usr = NULL ; /* To fill it is actually user's job ! */
186 statement->next = NULL ;
188 return statement ;
193 * cloog_statement_alloc function:
194 * This function allocates the memory space for a CloogStatement structure and
195 * sets its fields with those given as input. Then it returns a pointer to the
196 * allocated space.
197 * - number is the statement number.
199 * - September 9th 2002: first version.
200 * - March 17th 2003: fix for the usr field in CloogStatement structure.
201 * - April 16th 2005: adaptation to new CloogStatement structure (with
202 * number), cloog_statement_read becomes
203 * cloog_statement_alloc sincethere is nothing more to
204 * read on a file.
205 * - November 21th 2005: use of cloog_statement_malloc.
207 CloogStatement *cloog_statement_alloc(CloogState *state, int number)
208 { CloogStatement * statement ;
210 /* Memory allocation and initialization of the structure. */
211 statement = cloog_statement_malloc(state);
213 statement->number = number ;
215 return statement ;
220 * cloog_statement_copy function:
221 * This function returns a copy of the CloogStatement structure given as input.
222 * - October 28th 2001: first version (in loop.c).
223 * - March 17th 2003: fix for the usr field in CloogStatement structure.
224 * - April 16th 2005: adaptation to new CloogStatement struct (with number).
226 CloogStatement * cloog_statement_copy(CloogStatement * source)
227 { CloogStatement * statement, * temp, * now = NULL ;
229 statement = NULL ;
231 while (source != NULL) {
232 cloog_statement_leak_up(source->state);
234 temp = (CloogStatement *)malloc(sizeof(CloogStatement)) ;
235 if (temp == NULL)
236 cloog_die("memory overflow.\n");
238 temp->state = source->state;
239 temp->number = source->number ;
240 temp->usr = source->usr ;
241 temp->next = NULL ;
243 if (statement == NULL)
244 { statement = temp ;
245 now = statement ;
247 else
248 { now->next = temp ;
249 now = now->next ;
251 source = source->next ;
253 return(statement) ;
257 /**
258 * cloog_statement_add function:
259 * This function adds a CloogStatement structure (statement) at a given place
260 * (now) of a NULL terminated list of CloogStatement structures. The beginning
261 * of this list is (start). This function updates (now) to (loop), and
262 * updates (start) if the added element is the first one -that is when (start)
263 * is NULL-.
264 * - March 27th 2004: first version.
266 void cloog_statement_add(start, now, statement)
267 CloogStatement ** start, ** now, * statement ;
268 { if (*start == NULL)
269 { *start = statement ;
270 *now = *start ;
272 else
273 { (*now)->next = statement ;
274 *now = (*now)->next ;