Clan
0.8.0
|
00001 00002 /*+------- <| --------------------------------------------------------** 00003 ** A Clan ** 00004 **--- /.\ -----------------------------------------------------** 00005 ** <| [""M# options.c ** 00006 **- A | # -----------------------------------------------------** 00007 ** /.\ [""M# First version: 24/05/2008 ** 00008 **- [""M# | # U"U#U -----------------------------------------------** 00009 | # | # \ .:/ 00010 | # | #___| # 00011 ****** | "--' .-" ****************************************************** 00012 * |"-"-"-"-"-#-#-## Clan : the Chunky Loop Analyzer (experimental) * 00013 **** | # ## ###### ***************************************************** 00014 * \ .::::'/ * 00015 * \ ::::'/ Copyright (C) 2008 University Paris-Sud 11 * 00016 * :8a| # # ## * 00017 * ::88a ### This is free software; you can redistribute it * 00018 * ::::888a 8a ##::. and/or modify it under the terms of the GNU Lesser * 00019 * ::::::::888a88a[]::: General Public License as published by the Free * 00020 *::8:::::::::SUNDOGa8a::. Software Foundation, either version 2.1 of the * 00021 *::::::::8::::888:Y8888:: License, or (at your option) any later version. * 00022 *::::':::88::::888::Y88a::::::::::::... * 00023 *::'::.. . ..... .. ... . * 00024 * This software is distributed in the hope that it will be useful, but * 00025 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * 00026 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * 00027 * for more details. * 00028 * * 00029 * You should have received a copy of the GNU Lesser General Public License * 00030 * along with software; if not, write to the Free Software Foundation, Inc., * 00031 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00032 * * 00033 * Clan, the Chunky Loop Analyzer * 00034 * Written by Cedric Bastoul, Cedric.Bastoul@u-psud.fr * 00035 * * 00036 ******************************************************************************/ 00037 00038 00039 #include <stdlib.h> 00040 #include <stdio.h> 00041 #include <string.h> 00042 00043 #include <osl/macros.h> 00044 #include <clan/macros.h> 00045 #include <clan/options.h> 00046 00047 00048 /*+**************************************************************************** 00049 * Structure display function * 00050 ******************************************************************************/ 00051 00052 00060 void clan_options_print(FILE* foo, clan_options_p options) { 00061 fprintf(foo, "Options:\n"); 00062 00063 if (options->name != NULL) 00064 fprintf(foo, "name = %s,\n", options->name); 00065 else 00066 fprintf(foo, "name = NULL,\n"); 00067 00068 fprintf(foo, "castle = %3d,\n", options->castle); 00069 fprintf(foo, "structure = %3d.\n", options->structure); 00070 fprintf(foo, "autoscop = %3d.\n", options->autoscop); 00071 fprintf(foo, "autopragma = %3d.\n", options->autopragma); 00072 fprintf(foo, "autoinsert = %3d.\n", options->autoinsert); 00073 fprintf(foo, "inputscop = %3d.\n", options->inputscop); 00074 fprintf(foo, "bounded_context = %3d.\n", options->bounded_context); 00075 fprintf(foo, "noloopcontext = %3d.\n", options->noloopcontext); 00076 fprintf(foo, "nosimplify = %3d.\n", options->nosimplify); 00077 fprintf(foo, "extbody = %3d.\n", options->extbody); 00078 } 00079 00080 00081 /*+**************************************************************************** 00082 * Memory deallocation function * 00083 ******************************************************************************/ 00084 00085 00091 void clan_options_free(clan_options_p options) { 00092 free(options->name); 00093 free(options); 00094 } 00095 00096 00097 /*+**************************************************************************** 00098 * Processing functions * 00099 ******************************************************************************/ 00100 00101 00108 void clan_options_help() { 00109 printf( 00110 "Usage: clan [ options | file ] ...\n"); 00111 printf( 00112 "\nGeneral options:\n" 00113 " -o <output> Name of the output file; 'stdout' is a special\n" 00114 " value: when used, output is standard output\n" 00115 " (default setting: stdout).\n" 00116 " -autoscop Automatic SCoP extraction.\n" 00117 " -autopragma Automatic insertion of SCoP pragmas in input code.\n" 00118 " -autoinsert Automatic insertion of SCoP pragmas in input file.\n" 00119 " -inputscop Read a .scop as the input.\n" 00120 " -precision <value> 32 to work in 32 bits, 64 for 64 bits, 0 for GMP.\n" 00121 " -boundedctxt Bound all global parameters to be >= -1.\n" 00122 " -noloopctxt Do not include loop context (simplifies domains).\n" 00123 " -nosimplify Do not simplify iteration domains.\n" 00124 " -outscoplib Print to the SCoPLib format.\n" 00125 " -extbody Will generate the extbody.\n" 00126 " -v, --version Display the release information (and more).\n" 00127 " -h, --help Display this information.\n\n"); 00128 printf( 00129 "The special value 'stdin' for 'file' or the special option '-' makes clan\n" 00130 "to read data on standard input.\n\n" 00131 "For bug reporting or any suggestions, please send an email to the author\n" 00132 "Cedric Bastoul <cedric.bastoul@inria.fr>.\n"); 00133 } 00134 00135 00142 void clan_options_version() { 00143 printf("clan %s ", CLAN_VERSION); 00144 printf(" The Chunky Loop Analyzer\n"); 00145 00146 printf( 00147 "-----\n" 00148 "This is a polyhedral representation extractor for imperative programs using " 00149 "a C\ngrammar for control flow and array accesses (this includes C, C++," 00150 " Java, C#\nand probably few toy languages too). This program is distributed " 00151 "under the\nterms of the GNU Lesser General Public License, see details of " 00152 "the licence at\nhttp://www.gnu.org/copyleft/lgpl.html\n" 00153 "-----\n"); 00154 printf( 00155 "It would be fair to refer the following paper in any publication " 00156 "resulting from\nthe use of this software or its library (it defines SCoPs):\n" 00157 "@InProceedings{Bas03,\n" 00158 "author = {Cedric Bastoul and Albert Cohen and Sylvain Girbal and\n" 00159 " Saurabh Sharma and Olivier Temam},\n" 00160 "title = {Putting Polyhedral Loop Transformations to Work},\n" 00161 "booktitle = {LCPC'16 International Workshop on Languages and\n" 00162 " Compilers for Parallel Computers, LNCS 2958},\n" 00163 "pages = {209--225},\n" 00164 "month = {october},\n" 00165 "year = 2003,\n" 00166 "address = {College Station, Texas}\n" 00167 "}\n" 00168 "-----\n"); 00169 printf( 00170 "For any information, please send an email to the author\n" 00171 "Cedric Bastoul <cedric.bastoul@inria.fr>.\n"); 00172 } 00173 00174 00184 void clan_options_set(int* option, int argv, char** argc, int* number) { 00185 char** endptr; 00186 00187 if (*number+1 >= argv) 00188 CLAN_error("an option lacks of argument"); 00189 00190 endptr = NULL; 00191 *option = strtol(argc[*number+1], endptr, 10); 00192 if (endptr != NULL) { 00193 fprintf(stderr, "[Clan] Error: %s value for %s option is not valid.\n", 00194 argc[*number + 1], argc[*number]); 00195 exit(1); 00196 } 00197 *number = *number + 1; 00198 } 00199 00200 00207 clan_options_p clan_options_malloc(void) { 00208 clan_options_p options; 00209 00210 // Memory allocation for the clan_options_t structure. 00211 CLAN_malloc(options, clan_options_p, sizeof(clan_options_t)); 00212 00213 // We set the various fields with default values. 00214 options->name = NULL; // Name of the input file is not set. 00215 options->castle = 1; // Do print the Clan McCloog castle in output. 00216 options->structure = 0; // Don't print internal structure. 00217 options->autoscop = 0; // Do not extract SCoPs automatically. 00218 options->autopragma = 0; // Do not insert SCoP pragmas in the input code. 00219 options->autoinsert = 0; // Do not insert SCoP pragmas in the input file. 00220 options->inputscop = 0; // Default input is a source file, not a .scop. 00221 options->precision = 64; // Work in 64 bits by default. 00222 options->bounded_context = 0;// Don't bound the global parameters. 00223 options->noloopcontext = 0;// Do include loop context in domains. 00224 options->nosimplify = 0;// Do simplify iteration domains. 00225 options->outscoplib = 0;// Default OpenScop format 00226 options->extbody = 0;// Don't generate the extbody 00227 return options; 00228 } 00229 00230 00242 clan_options_p clan_options_read(int argv, char** argc, 00243 char*** input_files, FILE** output) { 00244 int i, infos=0, input_is_stdin=0; 00245 clan_options_p options; 00246 int nb_input_files = 0; 00247 00248 // clan_options_t structure allocation and initialization. 00249 options = clan_options_malloc(); 00250 00251 // The default output is the standard output. 00252 *output = stdout; 00253 *input_files = NULL; 00254 00255 // Prepare an empty array of input file names. 00256 CLAN_malloc(*input_files, char**, sizeof(char*)); 00257 (*input_files)[0] = NULL; 00258 00259 for (i=1; i < argv; i++) { 00260 if (argc[i][0] == '-') { 00261 if (argc[i][1] == '\0') { 00262 // "-" alone is a special option to set input to standard input. 00263 nb_input_files++; 00264 input_is_stdin = 1; 00265 CLAN_realloc(*input_files, char**, sizeof(char*) * (nb_input_files+1)); 00266 CLAN_strdup((*input_files)[nb_input_files-1], "stdin"); 00267 (*input_files)[nb_input_files] = NULL; 00268 nb_input_files++; 00269 } else if (strcmp(argc[i], "-castle") == 0) { 00270 clan_options_set(&(options)->castle, argv, argc, &i); 00271 } else if (strcmp(argc[i], "-structure") == 0) { 00272 options->structure = 1; 00273 } else if (strcmp(argc[i], "-autoscop") == 0) { 00274 options->autoscop = 1; 00275 } else if (strcmp(argc[i], "-autopragma") == 0) { 00276 options->autoscop = 1; 00277 options->autopragma = 1; 00278 } else if (strcmp(argc[i], "-autoinsert") == 0) { 00279 options->autoscop = 1; 00280 options->autoinsert = 1; 00281 } else if (strcmp(argc[i], "-inputscop") == 0) { 00282 options->inputscop = 1; 00283 } else if (strcmp(argc[i], "-boundedctxt") == 0) { 00284 options->bounded_context = 1; 00285 } else if (strcmp(argc[i], "-noloopctxt") == 0) { 00286 options->noloopcontext = 1; 00287 } else if (strcmp(argc[i], "-nosimplify") == 0) { 00288 options->nosimplify = 1; 00289 } else if (strcmp(argc[i], "-outscoplib") == 0) { 00290 options->outscoplib = 1; 00291 } else if (strcmp(argc[i], "-extbody") == 0) { 00292 options->extbody = 1; 00293 } else if (strcmp(argc[i], "-precision") == 0) { 00294 clan_options_set(&(options)->precision, argv, argc, &i); 00295 } else if ((strcmp(argc[i], "--help") == 0) || 00296 (strcmp(argc[i], "-h") == 0)) { 00297 clan_options_help(); 00298 infos = 1; 00299 } else if ((strcmp(argc[i],"--version") == 0) || 00300 (strcmp(argc[i],"-v") == 0)) { 00301 clan_options_version(); 00302 infos = 1; 00303 } else if (strcmp(argc[i], "-o") == 0) { 00304 if (i+1 >= argv) 00305 CLAN_error("no output name for -o option"); 00306 00307 // stdout is a special value to set output to standard output. 00308 if (strcmp(argc[i+1], "stdout") == 0) { 00309 *output = stdout; 00310 } else { 00311 *output = fopen(argc[i+1], "w"); 00312 if (*output == NULL) 00313 CLAN_error("cannot open the output file"); 00314 } 00315 i++; 00316 } else { 00317 fprintf(stderr, "[Clan] Warning: unknown %s option.\n", argc[i]); 00318 } 00319 } else { 00320 if (!input_is_stdin) { 00321 nb_input_files++; 00322 CLAN_realloc(*input_files, char**, sizeof(char*) * (nb_input_files+1)); 00323 CLAN_strdup((*input_files)[nb_input_files-1], argc[i]); 00324 (*input_files)[nb_input_files] = NULL; 00325 // stdin is a special value to set input to standard input. 00326 if (strcmp(argc[i], "stdin") == 0) { 00327 input_is_stdin = 1; 00328 } 00329 } 00330 else { 00331 CLAN_error("Cannot have multiple input files with stdin"); 00332 } 00333 } 00334 } 00335 00336 if ((options->precision != OSL_PRECISION_MP) && 00337 (options->precision != OSL_PRECISION_SP) && 00338 (options->precision != OSL_PRECISION_DP)) 00339 CLAN_error("invalid precision (use 32, 64 or 0 for GMP)"); 00340 00341 if ((options->autoscop || options->autopragma || options->autoinsert) && 00342 !nb_input_files ) 00343 CLAN_error("autoscop/autopragma/autoinsert options need an input file"); 00344 00345 if (!input_is_stdin && !nb_input_files && !infos) 00346 CLAN_error("no input file (-h for help)"); 00347 00348 return options; 00349 }