Remove some files left in builddir after make clean
[cloog-ppl.git] / source / options.c
blob5a09e9c08a0f2f76c772d7aee5c8c7323f5592ae
2 /**-------------------------------------------------------------------**
3 ** CLooG **
4 **-------------------------------------------------------------------**
5 ** options.c **
6 **-------------------------------------------------------------------**
7 ** First version: april 19th 2003 **
8 **-------------------------------------------------------------------**/
11 /******************************************************************************
12 * CLooG : the Chunky Loop Generator (experimental) *
13 ******************************************************************************
14 * *
15 * Copyright (C) 2001-2005 Cedric Bastoul *
16 * *
17 * This is free software; you can redistribute it and/or modify it under the *
18 * terms of the GNU General Public License as published by the Free Software *
19 * Foundation; either version 2 of the License, or (at your option) any later *
20 * version. *
21 * *
22 * This software is distributed in the hope that it will be useful, but *
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
25 * for more details. *
26 * *
27 * You should have received a copy of the GNU General Public License along *
28 * with software; if not, write to the Free Software Foundation, Inc., *
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
30 * *
31 * CLooG, the Chunky Loop Generator *
32 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
33 * *
34 ******************************************************************************/
37 # include <stdlib.h>
38 # include <stdio.h>
39 # include <string.h>
40 # include "../include/cloog/cloog.h"
42 /**
43 * Maximum number of rays in the dual representation of PolyLib, see
44 * domain.c for the original declaration.
46 extern int MAX_RAYS ;
49 /******************************************************************************
50 * Structure display function *
51 ******************************************************************************/
54 /**
55 * cloog_option_print function:
56 * This function prints the content of a CloogOptions structure (program) into
57 * a file (foo, possibly stdout).
58 * - April 19th 2003: first version.
60 void cloog_options_print(FILE * foo, CloogOptions * options)
61 { fprintf(foo,"Options:\n") ;
62 fprintf(foo,"OPTIONS FOR LOOP GENERATION\n") ;
63 fprintf(foo,"l = %3d,\n",options->l) ;
64 fprintf(foo,"f = %3d,\n",options->f) ;
65 fprintf(foo,"stop = %3d,\n",options->stop) ;
66 fprintf(foo,"strides = %3d,\n",options->strides) ;
67 fprintf(foo,"sh = %3d,\n",options->sh);
68 fprintf(foo,"OPTIONS FOR PRETTY PRINTING\n") ;
69 fprintf(foo,"esp = %3d,\n",options->esp) ;
70 fprintf(foo,"csp = %3d,\n",options->csp) ;
71 fprintf(foo,"fsp = %3d,\n",options->fsp) ;
72 fprintf(foo,"otl = %3d.\n",options->otl) ;
73 fprintf(foo,"block = %3d.\n",options->block) ;
74 fprintf(foo,"cpp = %3d.\n",options->cpp) ;
75 fprintf(foo,"compilable = %3d.\n",options->compilable) ;
76 fprintf(foo,"UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY\n") ;
77 fprintf(foo,"leaks = %3d.\n",options->leaks) ;
78 fprintf(foo,"nobacktrack = %3d.\n",options->nobacktrack) ;
79 fprintf(foo,"override = %3d.\n",options->override) ;
80 fprintf(foo,"structure = %3d.\n",options->structure) ;
81 fprintf(foo,"noscalars = %3d.\n",options->noscalars) ;
82 fprintf(foo,"noblocks = %3d.\n",options->noblocks) ;
83 fprintf(foo,"nosimplify = %3d.\n",options->nosimplify) ;
87 /******************************************************************************
88 * Memory deallocation function *
89 ******************************************************************************/
92 /**
93 * cloog_options_free function:
94 * This function frees the allocated memory for a CloogOptions structure.
95 * - April 19th 2003: first version.
97 void cloog_options_free(CloogOptions * options)
98 { free(options) ;
102 /******************************************************************************
103 * Processing functions *
104 ******************************************************************************/
108 * cloog_options_help function:
109 * This function displays the quick help when the user set the option -help
110 * while calling cloog. Prints are cutted to respect the 509 characters
111 * limitation of the ISO C 89 compilers.
112 * - August 5th 2002: first version.
114 static void cloog_options_help (void)
115 { printf(
116 "Usage: cloog [ options | file ] ...\n"
117 "Options for code generation:\n"
118 " -l <depth> Last loop depth to optimize (-1: infinity)\n"
119 " (default setting: -1).\n"
120 " -f <depth> First loop depth to start loop separation (-1: "
121 "infinity)\n (default setting: 1).\n") ;
122 printf(
123 " -stop <depth> Loop depth to stop code generation (-1: infinity)"
124 "\n (default setting: -1).\n"
125 " -strides <boolean> Handle non-unit strides (1) or not (0)\n"
126 " (default setting: 0).\n") ;
127 printf(
128 "\nOptions for pretty printing:\n"
129 " -otl <boolean> Simplify loops running one time (1) or not (0)\n"
130 " (default setting: 1).\n") ;
131 printf(
132 " -esp <boolean> Allow complex equalities spreading (1) or not (0)\n"
133 " (default setting: 0).\n"
134 " -csp <boolean> Allow constant spreading (1) or not (0)\n"
135 " (default setting: 1).\n") ;
136 printf(
137 " -fsp <level> First level to begin the spreading\n"
138 " (default setting: 1).\n"
139 " -block <boolean> Make a new statement block per iterator in C\n"
140 " programs (1) or not (0) (default setting: 0).\n") ;
141 printf(
142 " -cpp <boolean> Compilable block by using preprocessor (1) or not "
143 "(0)\n (default setting: 0).\n"
144 " -compilable <number> Compilable code by using preprocessor (not 0) or"
145 "\n not (0), number being the value of the parameters"
146 "\n (default setting: 0).\n");
147 printf(
148 "\nGeneral options:\n"
149 " -o <output> Name of the output file; 'stdout' is a special\n"
150 " value: when used, output is standard output\n"
151 " (default setting: stdout).\n"
152 " -v, --version Display the version information (and more).\n"
153 " -h, --help Display this information.\n\n") ;
154 printf(
155 "The special value 'stdin' for 'file' makes CLooG to read data on\n"
156 "standard input.\n\n"
157 "For bug reporting or any suggestions, please send an email to the author\n"
158 "<cedric.bastoul@inria.fr>.\n") ;
163 * cloog_options_version function:
164 * This function displays some version informations when the user set the
165 * option -version while calling cloog. Prints are cutted to respect the 509
166 * characters limitation of the ISO C 89 compilers.
167 * - August 5th 2002: first version.
169 static void cloog_options_version (void)
170 { printf("%s The Chunky Loop Generator\n", cloog_version());
171 printf(
172 "-----\n"
173 "This is a loop generator for scanning Z-polyhedra. It is based on the "
174 "work of\nF. Quillere and C. Bastoul on high level code generation and of "
175 "the PolyLib Team\non polyhedral computation. This program is distributed "
176 "under the terms of the\nGNU General Public License "
177 "(details at http://www.gnu.org/copyleft/gpl.html).\n"
178 "-----\n") ;
179 printf(
180 "It would be fair to refer the following paper in any publication "
181 "resulting from\nthe use of this software or its library:\n"
182 "@InProceedings{Bas04,\n"
183 "author = {Cedric Bastoul},\n"
184 "title = {Code Generation in the Polyhedral Model Is Easier Than You "
185 "Think},\n"
186 "booktitle = {PACT'13 IEEE International Conference on Parallel "
187 "Architecture\n and Compilation Techniques},\n"
188 "pages = {7--16},\n"
189 "month = {september},\n"
190 "year = 2004,\n"
191 "address = {Juan-les-Pins}\n"
192 "}\n"
193 "-----\n"
194 "For any information, please ask the author at "
195 "<cedric.bastoul@inria.fr>.\n") ;
200 * cloog_options_set function:
201 * This function sets the value of an option thanks to the user's calling line.
202 * - option is the value to set,
203 * - argc are the elements of the user's calling line,
204 * - number is the number of the element corresponding to the considered option,
205 * this function adds 1 to number to pass away the option value.
207 * - August 5th 2002: first version.
208 * - June 29th 2003: (debug) lack of argument now detected.
210 static void cloog_options_set (int * option, int argv, char ** argc, int * number)
211 { char ** endptr ;
213 if (*number+1 >= argv)
214 { fprintf(stderr, "[CLooG]ERROR: an option lacks of argument.\n") ;
215 exit(1) ;
218 endptr = NULL ;
219 *option = strtol(argc[*number+1],endptr,10) ;
220 if (endptr != NULL)
221 { fprintf(stderr, "[CLooG]ERROR: %s value for %s option is not valid.\n",
222 argc[*number+1],argc[*number]) ;
223 exit(1) ;
225 *number = *number + 1 ;
230 * cloog_options_malloc function:
231 * This functions allocate the memory space for a CLoogOptions structure and
232 * fill its fields with the defaults values. It returns a pointer to the
233 * allocated CloogOptions structure.
234 * - April 19th 2003: first version.
235 * - November 21th 2005: name changed (before it was cloog_options_init).
237 CloogOptions * cloog_options_malloc(void)
238 { CloogOptions * options ;
240 /* Memory allocation for the CloogOptions structure. */
241 options = (CloogOptions *)malloc(sizeof(CloogOptions)) ;
242 if (options == NULL)
243 { fprintf(stderr, "[CLooG]ERROR: memory overflow.\n") ;
244 exit(1) ;
247 /* We set the various fields with default values. */
248 /* OPTIONS FOR LOOP GENERATION */
249 options->l = -1 ; /* Last level to optimize: infinity. */
250 options->f = 1 ; /* First level to optimize: the first. */
251 options->stop = -1 ; /* Generate all the code. */
252 options->strides = 0 ; /* Generate a code with unit strides. */
253 options->sh = 0; /* Compute actual convex hull. */
254 options->name = 0;
255 /* OPTIONS FOR PRETTY PRINTING */
256 options->esp = 0 ; /* We don't want Equality SPreading.*/
257 options->csp = 1 ; /* We want only Constant SPreading. */
258 options->fsp = 1 ; /* The First level to SPread is the first. */
259 options->otl = 1 ; /* We want to fire One Time Loops. */
260 options->block = 0 ; /* We don't want to force statement blocks. */
261 options->cpp = 0 ; /* No preprocessing facilities. */
262 options->compilable = 0 ; /* No compilable code. */
263 /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
264 options->leaks = 0 ; /* I don't want to print allocation statistics.*/
265 options->nobacktrack = 0 ; /* No backtrack in Quillere's algorithm.*/
266 options->override = 0 ; /* I don't want to override CLooG decisions.*/
267 options->structure = 0 ; /* I don't want to print internal structure.*/
268 options->noblocks = 0 ; /* I do want to make statement blocks.*/
269 options->noscalars = 0 ; /* I do want to use scalar dimensions.*/
270 options->nosimplify = 0 ; /* I do want to simplify polyhedra.*/
272 return options ;
278 * cloog_options_read function:
279 * This functions reads all the options and the input/output files thanks
280 * the the user's calling line elements (in argc). It fills a CloogOptions
281 * structure and the FILE structure corresponding to input and output files.
282 * - August 5th 2002: first version.
283 * - April 19th 2003: now in options.c and support of the CloogOptions structure.
285 void cloog_options_read(int argv, char **argc, FILE **input, FILE **output, CloogOptions **options)
286 { int i, infos=0, input_is_set=0 ;
288 /* CloogOptions structure allocation and initialization. */
289 *options = cloog_options_malloc() ;
291 /* The default output is the standard output. */
292 *output = stdout ;
294 for (i=1;i<argv;i++)
295 if (argc[i][0] == '-')
296 { if (strcmp(argc[i],"-l") == 0)
297 cloog_options_set(&(*options)->l,argv,argc,&i) ;
298 else
299 if (strcmp(argc[i],"-f") == 0)
300 cloog_options_set(&(*options)->f,argv,argc,&i) ;
301 else
302 if (strcmp(argc[i],"-stop") == 0)
303 cloog_options_set(&(*options)->stop,argv,argc,&i) ;
304 else
305 if (strcmp(argc[i],"-strides") == 0)
306 cloog_options_set(&(*options)->strides,argv,argc,&i) ;
307 else if (strcmp(argc[i],"-sh") == 0)
308 cloog_options_set(&(*options)->sh,argv,argc,&i) ;
309 else
310 if (strcmp(argc[i],"-otl") == 0)
311 cloog_options_set(&(*options)->otl,argv,argc,&i) ;
312 else
313 if (strcmp(argc[i],"-esp") == 0)
314 cloog_options_set(&(*options)->esp,argv,argc,&i) ;
315 else
316 if (strcmp(argc[i],"-csp") == 0)
317 cloog_options_set(&(*options)->csp,argv,argc,&i) ;
318 else
319 if (strcmp(argc[i],"-fsp") == 0)
320 cloog_options_set(&(*options)->fsp,argv,argc,&i) ;
321 else
322 if (strcmp(argc[i],"-block") == 0)
323 cloog_options_set(&(*options)->block,argv,argc,&i) ;
324 else
325 if (strcmp(argc[i],"-cpp") == 0)
326 cloog_options_set(&(*options)->cpp,argv,argc,&i) ;
327 else
328 if (strcmp(argc[i],"-compilable") == 0)
329 { cloog_options_set(&(*options)->compilable,argv,argc,&i) ;
330 (*options)->cpp = 1 ;
332 else
333 if (strcmp(argc[i],"-rays") == 0)
334 { if (i+1 >= argv)
335 { fprintf(stderr, "[CLooG]ERROR: an option lacks of argument.\n") ;
336 exit(1) ;
339 MAX_RAYS = atoi(argc[i+1]) ;
340 if (MAX_RAYS < 1)
341 { fprintf(stderr, "[CLooG]ERROR: %s value for %s option is not valid.\n",
342 argc[i+1],argc[i]) ;
343 exit(1) ;
345 i++ ;
347 else
348 if (strcmp(argc[i],"-loopo") == 0) /* Special option for the LooPo team ! */
349 { (*options)->esp = 0 ;
350 (*options)->csp = 0 ;
351 (*options)->block = 1 ;
352 (*options)->cpp = 1 ;
354 else
355 if (strcmp(argc[i],"-bipbip") == 0)/* Special option for the author only !*/
356 { (*options)->nobacktrack = 1 ;
357 MAX_RAYS = 50 ;
359 else
360 if (strcmp(argc[i],"-leaks") == 0)
361 (*options)->leaks = 1 ;
362 else
363 if (strcmp(argc[i],"-nobacktrack") == 0)
364 (*options)->nobacktrack = 1 ;
365 else
366 if (strcmp(argc[i],"-override") == 0)
367 (*options)->override = 1 ;
368 else
369 if (strcmp(argc[i],"-noblocks") == 0)
370 (*options)->noblocks = 1 ;
371 else
372 if (strcmp(argc[i],"-noscalars") == 0)
373 (*options)->noscalars = 1 ;
374 else
375 if (strcmp(argc[i],"-nosimplify") == 0)
376 (*options)->nosimplify = 1 ;
377 else
378 if ((strcmp(argc[i],"-struct") == 0) || (strcmp(argc[i],"-structure") == 0))
379 (*options)->structure = 1 ;
380 else
381 if ((strcmp(argc[i],"--help") == 0) || (strcmp(argc[i],"-h") == 0))
382 { cloog_options_help() ;
383 infos = 1 ;
385 else
386 if ((strcmp(argc[i],"--version") == 0) || (strcmp(argc[i],"-v") == 0))
387 { cloog_options_version() ;
388 infos = 1 ;
390 else
391 if (strcmp(argc[i],"-o") == 0)
392 { if (i+1 >= argv)
393 { fprintf(stderr, "[CLooG]ERROR: no output name for -o option.\n") ;
394 exit(1) ;
397 /* stdout is a special value, when used, we set output to standard
398 * output.
400 if (strcmp(argc[i+1],"stdout") == 0)
401 *output = stdout ;
402 else
403 { *output = fopen(argc[i+1],"w") ;
404 if (*output == NULL)
405 { fprintf(stderr, "[CLooG]ERROR: can't create output file %s.\n",
406 argc[i+1]) ;
407 exit(1) ;
410 i ++ ;
412 else
413 fprintf(stderr, "[CLooG]WARNING: unknown %s option.\n",argc[i]) ;
415 else
416 { if (!input_is_set)
417 { input_is_set = 1 ;
418 (*options)->name = argc[i] ;
419 /* stdin is a special value, when used, we set input to standard input. */
420 if (strcmp(argc[i],"stdin") == 0)
421 *input = stdin ;
422 else
423 { *input = fopen(argc[i],"r") ;
424 if (*input == NULL)
425 { fprintf(stderr, "[CLooG]ERROR: %s file does not exist.\n",argc[i]) ;
426 exit(1) ;
430 else
431 { fprintf(stderr, "[CLooG]ERROR: multiple input files.\n") ;
432 exit(1) ;
435 if (!input_is_set)
436 { if (!infos)
437 fprintf(stderr, "[CLooG]ERROR: no input file (-h for help).\n") ;
438 exit(1) ;