1 /* poc.c A complete C to polyhedra to C compiler */
6 #include <cloog/cloog.h>
8 /* Use the Clan library to convert a SCoP from C to OpenScop */
9 osl_scop_p
read_scop_from_c(FILE* input
, char* input_name
) {
10 clan_options_p clanoptions
;
13 clanoptions
= clan_options_malloc();
14 clanoptions
->precision
= OSL_PRECISION_MP
;
15 CLAN_strdup(clanoptions
->name
, input_name
);
16 scop
= clan_scop_extract(input
, clanoptions
);
17 clan_options_free(clanoptions
);
21 /* Use the CLooG library to output a SCoP from OpenScop to C */
22 void print_scop_to_c(FILE* output
, osl_scop_p scop
) {
24 CloogOptions
* options
;
26 struct clast_stmt
* clast
;
28 state
= cloog_state_malloc();
29 options
= cloog_options_malloc(state
);
30 options
->openscop
= 1;
31 cloog_options_copy_from_osl_scop(scop
, options
);
32 input
= cloog_input_from_osl_scop(options
->state
, scop
);
33 clast
= cloog_clast_create_from_input(input
, options
);
34 clast_pprint(output
, clast
, 0, options
);
36 cloog_clast_free(clast
);
37 options
->scop
= NULL
; // don't free the scop
38 cloog_options_free(options
);
39 cloog_state_free(state
); // the input is freed inside
42 int main(int argc
, char* argv
[]) {
46 if ((argc
< 2) || (argc
> 2)) {
47 fprintf(stderr
, "usage: %s file.c\n", argv
[0]);
54 input
= fopen(argv
[1], "r");
57 fprintf(stderr
, "cannot open input file\n");
61 scop
= read_scop_from_c(input
, argv
[1]);
62 osl_scop_print(stdout
, scop
);
64 // UPDATE THE SCOP IN A SMART WAY HERE
66 print_scop_to_c(stdout
, scop
);