Merge branch 'master' of github.com:periscop/clay
[clay.git] / source / options.c
blob04fb8f74100b73111ab3fb749838e97a76088dba
2 /*--------------------------------------------------------------------+
3 | Clay |
4 |--------------------------------------------------------------------|
5 | options.c |
6 |--------------------------------------------------------------------|
7 | First version: 03/04/2012 |
8 +--------------------------------------------------------------------+
10 +--------------------------------------------------------------------------+
11 | / __)( ) /__\ ( \/ ) |
12 | ( (__ )(__ /(__)\ \ / Chunky Loop Alteration wizardrY |
13 | \___)(____)(__)(__)(__) |
14 +--------------------------------------------------------------------------+
15 | Copyright (C) 2012 University of Paris-Sud |
16 | |
17 | This library is free software; you can redistribute it and/or modify it |
18 | under the terms of the GNU Lesser General Public License as published by |
19 | the Free Software Foundation; either version 2.1 of the License, or |
20 | (at your option) any later version. |
21 | |
22 | This library is distributed in the hope that it will be useful but |
23 | WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
25 | General Public License for more details. |
26 | |
27 | You should have received a copy of the GNU Lesser General Public License |
28 | along with this software; if not, write to the Free Software Foundation, |
29 | Inc., 51 Franklin Street, Fifth Floor, |
30 | Boston, MA 02110-1301 USA |
31 | |
32 | Clay, the Chunky Loop Alteration wizardrY |
33 | Written by Joel Poudroux, joel.poudroux@u-psud.fr |
34 +--------------------------------------------------------------------------*/
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <clay/macros.h>
40 #include <clay/options.h>
41 #include <clay/functions.h>
43 extern const clay_prototype_t functions[];
46 /**
47 * clay_options_free function:
48 * This function frees the allocated memory for a clay_options_t structure.
49 * \param options Option structure to be freed.
51 void clay_options_free(clay_options_p options) {
52 free(options);
56 /**
57 * clay_options_list_functions function:
59 void clay_options_list_functions() {
60 int i;
61 printf(
62 "Types:\n\n"
63 " array: [n1, n2, ...]\n"
64 " array of integer\n\n"
65 " bool: 1 | 0 | true | false\n\n"
66 " string: \"blah\"\n\n"
67 " list: {n1, n2, ... | n3, n4, ... | ...}\n"
68 " list of arrays\n\n"
69 " multi: any object/variable\n\n"
71 " beta_loop The ident corresponds to a loop\n"
72 " beta_inner In the interchange, it corresponds to the inner loop\n"
73 " (or statement)\n\n"
75 "Variables: For the moment only variables a-z are available.\n\n"
77 "Available functions:\n\n");
79 for (i = 0 ; i < CLAY_FUNCTIONS_TOTAL ; i++)
80 printf(" %s\n", functions[i].string);
82 printf("\n\n"
83 "Notes:\n\n"
84 "For the function get_beta_loop, the value n could be 0. In this\n"
85 "case the beta will be []\n\n"
86 "You don't necessarily need all the output dims, paramaters or the\n"
87 "constant. For example, if you want to set output dims, but if you don't\n"
88 "want params, you can do this : {0,1 | | }, where [0,1] is for the\n"
89 "output dims. You can also just put the first values.\n\n"
90 "Warning: in the output part, don't put the transition columns\n"
91 " example: if the output dims are : {0 i 0 j 0}, just do {Ni, Nj}\n");
95 /**
96 * clay_options_help function:
97 * This function displays the quick help when the user set the option -help
98 * while calling clay. Prints are cut to respect the 509 characters
99 * limitation of the ISO C 89 compilers.
101 void clay_options_help() {
102 printf(
103 "Usage: clay [ options | file ] ...\n");
104 printf(
105 "\nGeneral options:\n"
106 #if defined(CLAN_LINKED) && defined(CLOOG_LINKED)
107 " -c Compile 'file' and create the chain clan|clay|cloog\n"
108 " equivalent to --readc --printc\n"
109 #endif
111 #if defined(CLAN_LINKED)
112 " --readc Read 'file' as a .c (with Clan)\n"
113 #endif
115 #if defined(CLOOG_LINKED)
116 " --printc Print a .c (with ClooG)\n"
117 #endif
119 #if defined(CANDL_LINKED)
120 " --nocandl Don't check dependencies and print the result\n"
121 " --candl-structure Set candl structure option \n"
122 " --candl-fullcheck Set candl fullcheck option \n"
123 #endif
124 " --script <file> Input script file. If not given the script is from\n"
125 " the scop structure.\n"
126 " --nonormalize Don't normalize the scop.\n"
127 " The normalization is done when at the begining of\n"
128 " clay and at the end of these following functions : \n"
129 " reorder, split, fuse, iss, strimine, and unroll.\n"
130 " --list List all the available functions.\n"
131 " --keep-extbody Each extbody are kept (otherwise, they are exported\n"
132 " to a basic body).\n"
133 " -v, --version Display the release information.\n"
134 " -h, --help Display this help.\n\n");
135 printf(
136 "The 'file' is optional, if it's not given, clay will the file from\n"
137 "the stdin. By default Clay read a scop and print a scop, Clay can\n"
138 "be linked with Clan and Cloog.\n\n"
139 "For bug reporting or any suggestions, please send an email to the author\n"
140 "Joel Poudroux <joel.poudroux@u-psud.fr>.\n");
145 * clay_options_version function:
146 * This function displays some version informations when the user set the
147 * option --version while calling clay. Prints are cut to respect the 509
148 * characters limitation of the ISO C 89 compilers.
150 void clay_options_version() {
151 printf("Clay %s Chunky Loop Alteration wizardrY\n", CLAY_VERSION);
152 printf(
153 "For any information, please send an email to the author\n"
154 "Joel Poudroux <joel.poudroux@u-psud.fr>.\n");
159 * clay_options_malloc function:
160 * Allocate a new options structure
162 clay_options_p clay_options_malloc() {
163 clay_options_p options;
164 CLAY_malloc(options, clay_options_p, sizeof(clay_options_t));
165 options->from_tag = 1;
166 options->script = NULL;
167 options->input = stdin;
168 options->input_name = NULL;
169 options->print_infos = 0;
170 options->normalize = 1;
171 options->keep_extbody = 0;
173 #if defined(CLAN_LINKED)
174 options->readc = 0;
175 #endif
177 #if defined(CLOOG_LINKED)
178 options->printc = 0;
179 #endif
181 #ifdef CANDL_LINKED
182 options->nocandl = 0;
183 options->candl_structure = 0;
184 options->candl_fullcheck = 0;
185 #endif
187 return options;
192 * clay_options_read function:
193 * This functions reads all the options. It fills a clay_options_t.
194 * \param argv Number of strings in command line.
195 * \param argc Array of command line strings.
197 clay_options_p clay_options_read(int argc, char ** argv) {
198 int i;
199 clay_options_p options = clay_options_malloc();
201 for (i = 1 ; i < argc ; i++) {
202 if (strcmp(argv[i], "--script") == 0) {
203 if (i >= argc-1)
204 CLAY_error("no file name for --script option");
205 options->script = fopen(argv[i+1], "r");
206 if (options->script == NULL) {
207 fprintf(stderr, "[Clay] Error: cannot open the file %s\n", argv[i+1]);
208 exit(1);
210 options->from_tag = 0;
211 i++;
212 } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
213 clay_options_help();
214 options->print_infos = 1;
216 #if defined(CLAN_LINKED) && defined(CLOOG_LINKED)
217 } else if (strcmp(argv[i], "-c") == 0) {
218 options->readc = 1;
219 options->printc = 1;
220 #endif
222 #if defined(CLAN_LINKED)
223 } else if (strcmp(argv[i], "--readc") == 0) {
224 options->readc = 1;
225 #endif
227 #if defined(CLOOG_LINKED)
228 } else if (strcmp(argv[i], "--printc") == 0) {
229 options->printc = 1;
230 #endif
232 #ifdef CANDL_LINKED
233 } else if (strcmp(argv[i], "--nocandl") == 0) {
234 options->nocandl = 1;
235 } else if (strcmp(argv[i], "--candl-structure") == 0) {
236 options->candl_structure = 1;
237 } else if (strcmp(argv[i], "--candl-fullcheck") == 0) {
238 options->candl_fullcheck = 1;
239 #endif
241 } else if (strcmp(argv[i], "--list") == 0) {
242 clay_options_list_functions();
243 options->print_infos = 1;
244 } else if (strcmp(argv[i], "--nonormalize") == 0) {
245 options->normalize = 0;
246 } else if (strcmp(argv[i], "--keep-extbody") == 0) {
247 options->keep_extbody = 1;
248 } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) {
249 clay_options_version();
250 options->print_infos = 1;
251 } else {
252 options->input = fopen(argv[i], "r");
253 if (options->input == NULL) {
254 fprintf(stderr, "[Clay] Error: cannot open the file %s\n", argv[i]);
255 exit(1);
257 options->input_name = argv[i];
261 return options;