From f427d2e669d69ec6f37a61c3ccf02dc806d89da2 Mon Sep 17 00:00:00 2001 From: Cedric Bastoul Date: Thu, 12 Jan 2012 00:10:11 +0100 Subject: [PATCH] Add support for OpenSCop Coordinates extension This patch allows a complete source-to-source experience with CLooG when using OpenScop's "Coordinates" extension. When this extension is provided, the generated code is now injected by the pretty-printer in the code pointed by the extension at the place of a given SCoP. Note that since the osl submodule is also updated with this patch, it also solves a building problem with GMP configuration which used to be different in CLooG and osl, as reported by rene.sugar. --- Makefile.am | 2 +- doc/cloog.texi | 9 +++++++ osl | 2 +- source/program.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 80bfc43..1749c95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,7 @@ endif if BUNDLED_OSL MAYBE_OSL = osl - OSL_LA = $(top_builddir)/osl/source/libosl.la + OSL_LA = $(top_builddir)/osl/libosl.la endif SUBDIRS = $(MAYBE_ISL) $(MAYBE_OSL) . doc test diff --git a/doc/cloog.texi b/doc/cloog.texi index 4dd2f7a..4a78d14 100644 --- a/doc/cloog.texi +++ b/doc/cloog.texi @@ -1246,6 +1246,15 @@ void test(int M, int N) the OpenScop specification instead of the native file format (@pxref{Bas11}). This option is available only if the OpenScop support has been enabled at compile time (@pxref{Optional Features}). + The following OpenScop extensions are supported by CLooG + (for the details about those extensions, @pxref{Bas11}): + @itemize @bullet + @item @emph{scatnames} to set the scattering dimension names. + @item @emph{coordinates} to inject the generated code at the + place of a given SCoP in a given file. The use of + this extension is disabled when the options + @emph{-compilable} or @emph{-callable} are set. + @end itemize @node Help @subsection Help @code{--help} or @code{-h} diff --git a/osl b/osl index ffcf94b..a1b65c3 160000 --- a/osl +++ b/osl @@ -1 +1 @@ -Subproject commit ffcf94b16c9fb94f4269bc4e9810dd72f65efd9d +Subproject commit a1b65c33bf8cfd3fcfc1b258cea056a58298566d diff --git a/source/program.c b/source/program.c index c52c1dd..2b3ec1a 100644 --- a/source/program.c +++ b/source/program.c @@ -53,6 +53,10 @@ #define ALLOC(type) (type*)malloc(sizeof(type)) +#ifdef OSL_SUPPORT +#include +#include +#endif /****************************************************************************** * Structure display function * @@ -356,6 +360,78 @@ static void print_callable_postamble(FILE *file, CloogProgram *program) } /** + * cloog_program_osl_pprint function: + * this function pretty-prints the C or FORTRAN code generated from an + * OpenScop specification by overwriting SCoP in a given code, if the + * options -compilable or -callable are not set. The SCoP coordinates are + * provided through the OpenScop "Coordinates" extension. It returns 1 if + * it succeeds to find an OpenScop coordinates information + * to pretty-print the generated code, 0 otherwise. + * \param[in] file The output stream (possibly stdout). + * \param[in] program The generated pseudo-AST to pretty-print. + * \param[in] options CLooG options (contains the OpenSCop specification). + * \return 1 on success to pretty-print at the place of a SCoP, 0 otherwise. + */ +int cloog_program_osl_pprint(FILE * file, CloogProgram * program, + CloogOptions * options) { +#ifdef OSL_SUPPORT + int lines = 0; + int read = 1; + char c; + osl_scop_p scop = options->scop; + osl_coordinates_p coordinates; + struct clast_stmt *root; + FILE * original; + + if (scop && !options->compilable && !options->callable) { + coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + if (coordinates) { + original = fopen(coordinates->name, "r"); + if (!original) { + cloog_msg(options, CLOOG_WARNING, + "unable to open the file specified in the SCoP " + "coordinates\n"); + return 0; + } + + /* Print the macros the generated code may need. */ + print_macros(file); + + /* Print what was before the SCoP in the original file. */ + while ((lines < coordinates->start) && (read != EOF)) { + read = fscanf(original, "%c", &c); + if (read != EOF) { + if (c == '\n') + lines ++; + fprintf(file, "%c", c); + } + } + + /* Generate the clast from the pseudo-AST then pretty-print it. */ + root = cloog_clast_create(program, options); + clast_pprint(file, root, coordinates->indent, options); + cloog_clast_free(root); + + /* Print what was after the SCoP in the original file. */ + while (read != EOF) { + read = fscanf(original, "%c", &c); + if (read != EOF) { + if (lines >= coordinates->end - 1) + fprintf(file, "%c", c); + if (c == '\n') + lines ++; + } + } + + fclose(original); + return 1; + } + } +#endif + return 0; +} + +/** * cloog_program_pprint function: * This function prints the content of a CloogProgram structure (program) into a * file (file, possibly stdout), in a C-like language. @@ -371,7 +447,10 @@ CloogOptions * options ; CloogBlockList * blocklist ; CloogBlock * block ; struct clast_stmt *root; - + + if (cloog_program_osl_pprint(file, program, options)) + return; + if (program->language == 'f') options->language = CLOOG_LANGUAGE_FORTRAN ; else -- 2.11.4.GIT