From 48d8506d64179f84beb26789fd8b1d0449a3f81f Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Wed, 4 Aug 2010 09:55:15 +0200 Subject: [PATCH] Introduce cloog_input_dump_cloog It dumps the content of a CloogInput data structure into a .cloog file which is supposed to generate the same output as the CloogInput data structure. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- doc/cloog.texi | 10 +++++ include/cloog/input.h | 2 + source/input.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/doc/cloog.texi b/doc/cloog.texi index 9a17c29..efc83bf 100644 --- a/doc/cloog.texi +++ b/doc/cloog.texi @@ -1801,6 +1801,8 @@ CloogInput *cloog_input_read(FILE *file, CloogOptions *options); CloogInput *cloog_input_alloc(CloogDomain *context, CloogUnionDomain *ud); void cloog_input_free(CloogInput *input); + +void cloog_input_dump_cloog(FILE *, CloogInput *, CloogOptions *); @end group @end example @@ -1814,6 +1816,14 @@ the @code{language} field of the @code{CloogOptions} structure. The constructed @code{CloogInput} can be used as input to a @code{cloog_clast_create_from_input} call. +A @code{CloogInput} data structure and a @code{CloogOptions} contain +the same information as a .cloog file. This function dumps the .cloog +description of the given data structures into a file. + +@node Dump CLooG Input File Function +@subsection Dump CLooG Input File Function +@example +@end example @node CLooG Output @section CLooG Output diff --git a/include/cloog/input.h b/include/cloog/input.h index bd32711..4ad59fa 100644 --- a/include/cloog/input.h +++ b/include/cloog/input.h @@ -15,6 +15,8 @@ CloogInput *cloog_input_read(FILE *file, CloogOptions *options); CloogInput *cloog_input_alloc(CloogDomain *context, CloogUnionDomain *ud); void cloog_input_free(CloogInput *input); +void cloog_input_dump_cloog(FILE *file, CloogInput *input, CloogOptions *opt); + #if defined(__cplusplus) } #endif diff --git a/source/input.c b/source/input.c index f0ebd11..9bd994c 100644 --- a/source/input.c +++ b/source/input.c @@ -75,3 +75,103 @@ void cloog_input_free(CloogInput *input) cloog_union_domain_free(input->ud); free(input); } + +/** + * Dump the .cloog description of a CloogInput and a CloogOptions data structure + * into a file. The generated .cloog file will contain the same information as + * the data structures. The file can be used to run the cloog program on the + * example. + */ +void cloog_input_dump_cloog(FILE *file, CloogInput *input, CloogOptions *opt) +{ + int i, num_statements; + CloogUnionDomain *ud = input->ud; + CloogNamedDomainList *ndl = ud->domain; + + fprintf(file, + "# CLooG -> CLooG\n" + "# This is an automatic dump of a CLooG input file from a " + "CloogInput data\n" + "# structure.\n\n"); + + /* Language. */ + if (opt->language == LANGUAGE_FORTRAN) { + fprintf(file, "# Language: FORTRAN\n"); + fprintf(file, "f\n\n"); + } else { + fprintf(file, "# Language: C\n"); + fprintf(file, "c\n\n"); + } + + /* Context. */ + fprintf(file, "# Context:\n"); + cloog_domain_print_constraints(file, input->context, 0); + + fprintf(file, "\n%d # Parameter name(s)\n", + ud->name[CLOOG_PARAM] ? 1 : 0); + + if (ud->name[CLOOG_PARAM]) + for (i = 0; i < ud->n_name[CLOOG_PARAM]; i++) + fprintf(file, "%s ", ud->name[CLOOG_PARAM][i]); + + /* Statement number. */ + i = 0; + while (ndl != NULL) { + i++; + ndl = ndl->next; + } + num_statements = i; + fprintf(file, "\n# Statement number:\n%d\n\n", num_statements); + + /* Iteration domains. */ + i = 1; + ndl = ud->domain; + while (ndl != NULL) { + fprintf(file, "# Iteration domain of statement %d (%s).\n", i, + ndl->name); + + cloog_domain_print_constraints(file, ndl->domain, 1); + fprintf(file,"\n0 0 0 # For future options.\n\n"); + + i++; + ndl = ndl->next; + } + + fprintf(file, "\n%d # Iterator name(s)\n\n", + ud->name[CLOOG_SCAT] ? 1 : 0); + + if (ud->name[CLOOG_ITER]) + for (i = 0; i < ud->n_name[CLOOG_ITER]; i++) + fprintf(file, "%s ", ud->name[CLOOG_ITER][i]); + + /* Exit, if no scattering is supplied. */ + if (!ud->domain || !ud->domain->scattering) { + fprintf(file, "# No scattering functions.\n0\n\n"); + return; + } + + /* Scattering relations. */ + fprintf(file, + "# --------------------- SCATTERING --------------------\n"); + + fprintf(file, "%d # Scattering functions\n", num_statements); + + i = 1; + ndl = ud->domain; + while (ndl != NULL) { + fprintf(file, "\n# Scattering of statement %d (%s).\n", i, + ndl->name); + + cloog_scattering_print_constraints(file, ndl->scattering, 1); + + i++; + ndl = ndl->next; + } + + fprintf(file, "\n%d # Scattering dimension name(s)\n", + ud->name[CLOOG_SCAT] ? 1 : 0); + + if (ud->name[CLOOG_SCAT]) + for (i = 0; i < ud->n_name[CLOOG_SCAT]; i++) + fprintf(file, "%s ", ud->name[CLOOG_SCAT][i]); +} -- 2.11.4.GIT