Clan  0.8.1
clan.c
Go to the documentation of this file.
1 
2  /*+------- <| --------------------------------------------------------**
3  ** A Clan **
4  **--- /.\ -----------------------------------------------------**
5  ** <| [""M# clan.c **
6  **- A | # -----------------------------------------------------**
7  ** /.\ [""M# First version: 30/04/2008 **
8  **- [""M# | # U"U#U -----------------------------------------------**
9  | # | # \ .:/
10  | # | #___| #
11  ****** | "--' .-" ******************************************************
12  * |"-"-"-"-"-#-#-## Clan : the Chunky Loop Analyzer (experimental) *
13  **** | # ## ###### *****************************************************
14  * \ .::::'/ *
15  * \ ::::'/ Copyright (C) 2008 University Paris-Sud 11 *
16  * :8a| # # ## *
17  * ::88a ### This is free software; you can redistribute it *
18  * ::::888a 8a ##::. and/or modify it under the terms of the GNU Lesser *
19  * ::::::::888a88a[]::: General Public License as published by the Free *
20  *::8:::::::::SUNDOGa8a::. Software Foundation, either version 2.1 of the *
21  *::::::::8::::888:Y8888:: License, or (at your option) any later version. *
22  *::::':::88::::888::Y88a::::::::::::... *
23  *::'::.. . ..... .. ... . *
24  * This software is distributed in the hope that it will be useful, but *
25  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
26  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
27  * for more details. *
28  * *
29  * You should have received a copy of the GNU Lesser General Public License *
30  * along with software; if not, write to the Free Software Foundation, Inc., *
31  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
32  * *
33  * Clan, the Chunky Loop Analyzer *
34  * Written by Cedric Bastoul, Cedric.Bastoul@u-psud.fr *
35  * *
36  ******************************************************************************/
37 
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41 
42 #include <clan/clan.h>
43 #include <osl/scop.h>
44 
45 int main(int argc, char* argv[]) {
46  osl_scop_p scop = NULL;
47  clan_options_p options;
48  FILE* input, *output, *autopragma;
49  char **input_files = NULL;
50  char c;
51  int i;
52 
53  // Options and input/output file setting.
54  options = clan_options_read(argc, argv, &input_files, &output);
55 
56  i = 0;
57  while (input_files[i]) {
58  if (options->name)
59  free(options->name);
60  options->name = strdup(input_files[i]);
61 
62  if (!strcmp(options->name, "stdin"))
63  input = stdin;
64  else
65  input = fopen(options->name, "r");
66 
67  if (input == NULL) {
68  fprintf(stderr, "[Clan] Error: Unable to open input file %s\n",
69  input_files[i]);
70  break;
71  }
72 
73  printf("[Clan] Info: parsing file #%d (%s)\n", i+1, input_files[i]);
74 
75  // Extraction of the polyhedral representation of the SCoP from the input.
76  if (input != NULL) {
77  if (options->inputscop) {
78  // Input is a .scop file.
79  scop = osl_scop_read(input);
80  }
81  else {
82  // Input is a source code.
83  if (scop)
84  osl_scop_free(scop);
85  scop = clan_scop_extract(input, options);
86  fclose(input);
87  }
88 
89  // Printing of the internal data structure of the SCoP if asked.
90  if (options->structure)
91  osl_scop_dump(stdout, scop);
92 
93  if (!options->autopragma && !options->autoinsert) {
94  // Generation of the .scop output file.
95  clan_scop_print(output, scop, options);
96  } else {
97  if (options->autopragma) {
98  clan_scop_insert_pragmas(scop, options->name, 1);
99  // Output the file with inserted SCoP pragmas.
100  if ((autopragma = fopen(CLAN_AUTOPRAGMA_FILE, "r")) == NULL)
101  CLAN_error("cannot read the temporary file");
102  while ((c = fgetc(autopragma)) != EOF)
103  fputc(c, output);
104  fclose(autopragma);
105  remove(CLAN_AUTOPRAGMA_FILE);
106  }
107  if (options->autoinsert) {
108  clan_scop_insert_pragmas(scop, options->name, 0);
109  }
110  }
111  }
112 
113  i++;
114  }
115 
116  // Save the planet.
117  i = 0;
118  while (input_files[i]) {
119  free(input_files[i]);
120  i++;
121  }
122  free(input_files);
123 
124  clan_options_free(options);
125  osl_scop_free(scop);
126  fclose(output);
127 
128  return 0;
129 }
void clan_scop_print(FILE *file, osl_scop_p scop, clan_options_p options)
Definition: scop.c:109
int autopragma
Definition: options.h:60
osl_scop_p clan_scop_extract(FILE *input, clan_options_p options)
Definition: scop.c:84
char * name
Definition: options.h:56
clan_options_p clan_options_read(int argv, char **argc, char ***input_files, FILE **output)
Definition: options.c:243
int autoinsert
Definition: options.h:62
void clan_options_free(clan_options_p options)
Definition: options.c:92
void clan_scop_insert_pragmas(osl_scop_p scop, char *filename, int test)
Definition: scop.c:427
int main(int argc, char *argv[])
Definition: clan.c:45
int inputscop
Definition: options.h:63
int structure
Definition: options.h:58