Clan
0.8.0
|
00001 00002 /*+------- <| --------------------------------------------------------** 00003 ** A Clan ** 00004 **--- /.\ -----------------------------------------------------** 00005 ** <| [""M# clan.c ** 00006 **- A | # -----------------------------------------------------** 00007 ** /.\ [""M# First version: 30/04/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 #include <stdlib.h> 00039 #include <stdio.h> 00040 #include <string.h> 00041 00042 #include <clan/clan.h> 00043 #include <osl/scop.h> 00044 00045 int main(int argc, char* argv[]) { 00046 osl_scop_p scop = NULL; 00047 clan_options_p options; 00048 FILE* input, *output, *autopragma; 00049 char **input_files = NULL; 00050 char c; 00051 int i; 00052 00053 // Options and input/output file setting. 00054 options = clan_options_read(argc, argv, &input_files, &output); 00055 00056 i = 0; 00057 while (input_files[i]) { 00058 if (options->name) 00059 free(options->name); 00060 options->name = strdup(input_files[i]); 00061 00062 if (!strcmp(options->name, "stdin")) 00063 input = stdin; 00064 else 00065 input = fopen(options->name, "r"); 00066 00067 if (input == NULL) { 00068 fprintf(stderr, "[Clan] Error: Unable to open input file %s\n", 00069 input_files[i]); 00070 break; 00071 } 00072 00073 printf("[Clan] Info: parsing file #%d (%s)\n", i+1, input_files[i]); 00074 00075 // Extraction of the polyhedral representation of the SCoP from the input. 00076 if (input != NULL) { 00077 if (options->inputscop) { 00078 // Input is a .scop file. 00079 scop = osl_scop_read(input); 00080 } 00081 else { 00082 // Input is a source code. 00083 if (scop) 00084 osl_scop_free(scop); 00085 scop = clan_scop_extract(input, options); 00086 fclose(input); 00087 } 00088 00089 // Printing of the internal data structure of the SCoP if asked. 00090 if (options->structure) 00091 osl_scop_dump(stdout, scop); 00092 00093 if (!options->autopragma && !options->autoinsert) { 00094 // Generation of the .scop output file. 00095 clan_scop_print(output, scop, options); 00096 } else { 00097 if (options->autopragma) { 00098 clan_scop_insert_pragmas(scop, options->name, 1); 00099 // Output the file with inserted SCoP pragmas. 00100 if ((autopragma = fopen(CLAN_AUTOPRAGMA_FILE, "r")) == NULL) 00101 CLAN_error("cannot read the temporary file"); 00102 while ((c = fgetc(autopragma)) != EOF) 00103 fputc(c, output); 00104 fclose(autopragma); 00105 remove(CLAN_AUTOPRAGMA_FILE); 00106 } 00107 if (options->autoinsert) { 00108 clan_scop_insert_pragmas(scop, options->name, 0); 00109 } 00110 } 00111 } 00112 00113 i++; 00114 } 00115 00116 // Save the planet. 00117 i = 0; 00118 while (input_files[i]) { 00119 free(input_files[i]); 00120 i++; 00121 } 00122 free(input_files); 00123 00124 clan_options_free(options); 00125 osl_scop_free(scop); 00126 fclose(output); 00127 00128 return 0; 00129 }