44 #include <osl/vector.h> 45 #include <osl/relation.h> 46 #include <osl/relation_list.h> 47 #include <osl/statement.h> 48 #include <osl/strings.h> 49 #include <osl/extensions/scatnames.h> 50 #include <osl/extensions/arrays.h> 51 #include <osl/extensions/coordinates.h> 52 #include <osl/extensions/clay.h> 53 #include <osl/extensions/extbody.h> 54 #include <osl/generic.h> 57 #include <source/parser.h> 58 #include <clan/macros.h> 111 if ((scop != NULL) && (options->
castle)) {
112 fprintf(file,
"# \n");
113 fprintf(file,
"# <| \n");
114 fprintf(file,
"# A \n");
115 fprintf(file,
"# /.\\ \n");
116 fprintf(file,
"# <| [\"\"M# \n");
117 fprintf(file,
"# A | # Clan McCloog Castle \n");
118 fprintf(file,
"# /.\\ [\"\"M# [Generated by Clan ");
119 fprintf(file,
"%s]\n", CLAN_VERSION);
120 fprintf(file,
"# [\"\"M# | # U\"U#U \n");
121 fprintf(file,
"# | # | # \\ .:/ \n");
122 fprintf(file,
"# | # | #___| # \n");
123 fprintf(file,
"# | \"--' .-\" \n");
124 fprintf(file,
"# |\"-\"-\"-\"-\"-#-#-## \n");
125 fprintf(file,
"# | # ## ###### \n");
126 fprintf(file,
"# \\ .::::'/ \n");
127 fprintf(file,
"# \\ ::::'/ \n");
128 fprintf(file,
"# :8a| # # ## \n");
129 fprintf(file,
"# ::88a ### \n");
130 fprintf(file,
"# ::::888a 8a ##::. \n");
131 fprintf(file,
"# ::::::888a88a[]:::: \n");
132 fprintf(file,
"# :::::::::SUNDOGa8a::::. .. \n");
133 fprintf(file,
"# :::::8::::888:Y8888:::::::::... \n");
134 fprintf(file,
"#::':::88::::888::Y88a______________________________");
135 fprintf(file,
"________________________\n");
136 fprintf(file,
"#:: ::::88a::::88a:Y88a ");
137 fprintf(file,
" __---__-- __\n");
138 fprintf(file,
"#' .: ::Y88a:::::8a:Y88a ");
139 fprintf(file,
"__----_-- -------_-__\n");
140 fprintf(file,
"# :' ::::8P::::::::::88aa. _ _- -");
141 fprintf(file,
"- --_ --- __ --- __--\n");
142 fprintf(file,
"#.:: :::::::::::::::::::Y88as88a...s88aa.\n#\n");
146 osl_scop_print_scoplib(file, scop);
148 osl_scop_print(file, scop);
162 osl_statement_p current, deepest;
163 osl_scatnames_p scatnames;
164 osl_strings_p iterators = NULL;
165 osl_strings_p names = NULL;
166 osl_generic_p extension;
167 osl_body_p body = NULL;
168 char buffer[CLAN_MAX_STRING];
173 current = scop->statement;
174 while (current != NULL) {
175 if (current->domain->nb_output_dims > max_depth) {
176 max_depth = current->domain->nb_output_dims;
178 body = (osl_body_p)osl_generic_lookup(deepest->extension, OSL_URI_BODY);
180 iterators = body->iterators;
182 current = current->next;
190 names = osl_strings_malloc();
191 for (i = 0; i < max_depth; i++) {
192 sprintf(buffer,
"b%d", i);
193 osl_strings_add(names, buffer);
194 osl_strings_add(names, iterators->string[i]);
196 sprintf(buffer,
"b%d", max_depth);
197 osl_strings_add(names, buffer);
200 scatnames = osl_scatnames_malloc();
201 scatnames->names = names;
204 extension = osl_generic_malloc();
205 extension->interface = osl_scatnames_interface();
206 extension->data = scatnames;
207 osl_generic_add(&scop->extension, extension);
219 osl_coordinates_p coordinates;
220 osl_generic_p extension;
223 coordinates = osl_coordinates_malloc();
224 CLAN_strdup(coordinates->name, name);
227 coordinates->column_start = 0;
228 coordinates->column_end = 0;
232 extension = osl_generic_malloc();
233 extension->interface = osl_coordinates_interface();
234 extension->data = coordinates;
235 osl_generic_add(&scop->extension, extension);
248 osl_generic_p extension;
250 if ((script != NULL) && (strlen(script) > 0)) {
252 clay = osl_clay_malloc();
253 CLAN_strdup(clay->script, script);
256 extension = osl_generic_malloc();
257 extension->interface = osl_clay_interface();
258 extension->data = clay;
259 osl_generic_add(&scop->extension, extension);
277 int coordinates[5][CLAN_MAX_SCOPS]) {
279 osl_coordinates_p old;
281 while (scop != NULL) {
282 if (i > CLAN_MAX_SCOPS)
283 CLAN_error(
"too many SCoPs! Change CLAN_MAX_SCOPS and recompile Clan.");
285 old = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES);
287 CLAN_error(
"coordinates extension not present");
291 old->line_start = coordinates[0][i] + ((coordinates[2][i] == 0)? 1 : 0);
292 old->line_end = coordinates[1][i];
293 old->column_start = coordinates[2][i];
294 old->column_end = coordinates[3][i] - ((coordinates[3][i] > 0)? 1 : 0);
314 int coordinates[5][CLAN_MAX_SCOPS]) {
315 int i, j, line, column;
320 CLAN_debug(
"coordinates:");
321 for (i = 0; i < 5; i++) {
322 for (j = 0; j < nb_scops; j++)
323 printf(
"%3d ", coordinates[i][j]);
328 if ((autopragma = fopen(CLAN_AUTOPRAGMA_FILE,
"w")) == NULL)
329 CLAN_error(
"cannot create the autopragma file");
333 while ((c = fgetc(input)) != EOF) {
335 if ((line == coordinates[0][i]) && (column == coordinates[2][i])) {
336 fprintf(autopragma,
"\n#pragma scop\n");
337 for (j = 0; j < coordinates[2][i] - 1; j++)
338 fprintf(autopragma,
" ");
340 if ((line == coordinates[1][i]) && (column == coordinates[3][i])) {
341 fprintf(autopragma,
"\n#pragma endscop\n");
342 for (j = 0; j < coordinates[3][i] - 1; j++)
343 fprintf(autopragma,
" ");
344 if (i < nb_scops - 1) {
347 while ((i < nb_scops - 1) && !coordinates[4][i]);
351 fputc(c, autopragma);
377 char s1[CLAN_MAX_STRING];
378 char s2[CLAN_MAX_STRING];
381 CLAN_error(
"negative line number");
383 if (!(file = fopen(filename,
"r")))
384 CLAN_error(
"unable to read the file");
387 while ((lines < line_start - 1) && (read != EOF)) {
388 read = fscanf(file,
"%c", &c);
395 if (lines != line_start - 1) {
397 CLAN_error(
"not enough lines in the file");
400 if (fscanf(file,
" %s %s", s1, s2) != 2) {
402 CLAN_debug(
"pragma not found: cannot read the two chains");
407 if (strcmp(s1,
"#pragma") || strcmp(s2,
"scop")) {
408 CLAN_debug(
"pragma not found: do not match \"#pragma scop\"");
412 CLAN_debug(
"pragma found");
429 int infos[5][CLAN_MAX_SCOPS];
431 osl_coordinates_p coordinates;
432 FILE* input, *output;
437 while (scop != NULL) {
438 coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES);
439 infos[0][n] = coordinates->line_start;
440 infos[1][n] = coordinates->line_end;
441 infos[2][n] = coordinates->column_start;
442 infos[3][n] = coordinates->column_end + 1;
450 for (i = n - 2; i >= 0; i--) {
451 for (j = 0; j <= i; j++) {
452 if (infos[0][j] > infos[0][j+1]) {
453 tmp[0]=infos[0][j]; infos[0][j]=infos[0][j+1]; infos[0][j+1]=tmp[0];
454 tmp[1]=infos[1][j]; infos[1][j]=infos[1][j+1]; infos[1][j+1]=tmp[1];
455 tmp[2]=infos[2][j]; infos[2][j]=infos[2][j+1]; infos[2][j+1]=tmp[2];
456 tmp[3]=infos[3][j]; infos[3][j]=infos[3][j+1]; infos[3][j+1]=tmp[3];
457 tmp[4]=infos[4][j]; infos[4][j]=infos[4][j+1]; infos[4][j+1]=tmp[4];
463 for (i = 0; i < n - 1; i++)
464 if (infos[1][i] > infos[0][i+1])
465 CLAN_error(
"SCoP interleaving");
468 if (!(input = fopen(filename,
"r")))
469 CLAN_error(
"unable to read the input file");
475 if (!(input = fopen(CLAN_AUTOPRAGMA_FILE,
"rb")))
476 CLAN_error(
"unable to read the temporary file");
478 if (!(output = fopen(filename,
"wb")))
479 CLAN_error(
"unable to write the output file");
481 while ((size = fread(buffer, 1, BUFSIZ, input))) {
482 fwrite(buffer, 1, size, output);
488 if (
remove(CLAN_AUTOPRAGMA_FILE) == -1)
489 CLAN_warning(
"unable to remove the temporary file");
500 osl_statement_p statement;
502 while (scop != NULL) {
503 statement = scop->statement;
504 while (statement != NULL) {
506 statement = statement->next;
void clan_scop_print(FILE *file, osl_scop_p scop, clan_options_p options)
void clan_scop_generate_coordinates(osl_scop_p scop, char *name)
osl_scop_p clan_scop_extract(FILE *input, clan_options_p options)
void clan_scop_simplify(osl_scop_p scop)
osl_scop_p clan_parse(FILE *, clan_options_p)
void clan_scop_print_autopragma(FILE *input, int nb_scops, int coordinates[5][CLAN_MAX_SCOPS])
void clan_scop_generate_clay(osl_scop_p scop, char *script)
void clan_statement_compact(osl_statement_p statement, int nb_parameters)
void clan_scop_generate_scatnames(osl_scop_p scop)
void clan_scop_update_coordinates(osl_scop_p scop, int coordinates[5][CLAN_MAX_SCOPS])
void clan_scop_compact(osl_scop_p scop)
void clan_scop_insert_pragmas(osl_scop_p scop, char *filename, int test)
void clan_relation_simplify(osl_relation_p relation)
static int clan_scop_no_pragma(char *filename, int line_start)