Skip to content

Commit

Permalink
Add support for OpenSCop Coordinates extension
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Cedric Bastoul committed Feb 17, 2012
1 parent 3f88770 commit f427d2e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions doc/cloog.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion osl
Submodule osl updated from ffcf94 to a1b65c
81 changes: 80 additions & 1 deletion source/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@

#define ALLOC(type) (type*)malloc(sizeof(type))

#ifdef OSL_SUPPORT
#include <osl/scop.h>
#include <osl/extensions/coordinates.h>
#endif

/******************************************************************************
* Structure display function *
Expand Down Expand Up @@ -355,6 +359,78 @@ static void print_callable_postamble(FILE *file, CloogProgram *program)
fprintf(file, "}\n");
}

/**
* 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
Expand All @@ -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
Expand Down

0 comments on commit f427d2e

Please sign in to comment.