4 #include "../include/cloog/cloog.h"
10 #define ALLOC(type) (type*)malloc(sizeof(type))
12 static char *next_line(FILE *input
, char *line
, unsigned len
)
17 if (!(p
= fgets(line
, len
, input
)))
19 while (isspace(*p
) && *p
!= '\n')
21 } while (*p
== '#' || *p
== '\n');
28 * This function translates an OpenScop scop to a CLooG input.
29 * \param[in,out] state CLooG state.
30 * \param[in] scop Scop to translate.
31 * \return A CloogInput corresponding to the scop input.
33 CloogInput
*cloog_input_from_osl_scop(CloogState
*state
, osl_scop_p scop
) {
34 CloogInput
*input
= NULL
;
35 CloogDomain
*context
= NULL
;
36 CloogUnionDomain
*ud
= NULL
;
39 /* Extract the context. */
40 context
= cloog_domain_from_osl_relation(state
, scop
->context
);
42 /* Extract the union of domains. */
43 ud
= cloog_union_domain_from_osl_scop(state
, scop
);
45 /* Build and return the input. */
46 input
= cloog_input_alloc(context
, ud
);
54 * Read input from a .cloog file, putting most of the information
55 * in the returned CloogInput. The chosen language is put in
58 CloogInput
*cloog_input_read(FILE *file
, CloogOptions
*options
)
60 char line
[MAX_STRING
];
67 if (options
->openscop
) {
68 osl_scop_p scop
= osl_scop_read(file
);
69 CloogInput
* input
= cloog_input_from_osl_scop(options
->state
,
71 cloog_options_copy_from_osl_scop(scop
, options
);
77 /* First of all, we read the language to use. */
78 if (!next_line(file
, line
, sizeof(line
)))
79 cloog_die("Input error.\n");
80 if (sscanf(line
, "%c", &language
) != 1)
81 cloog_die("Input error.\n");
84 options
->language
= CLOOG_LANGUAGE_FORTRAN
;
86 options
->language
= CLOOG_LANGUAGE_C
;
88 /* We then read the context data. */
89 context
= cloog_domain_read_context(options
->state
, file
);
90 nb_par
= cloog_domain_parameter_dimension(context
);
92 ud
= cloog_union_domain_read(file
, nb_par
, options
);
94 return cloog_input_alloc(context
, ud
);
98 * Create a CloogInput from a CloogDomain context and a CloogUnionDomain.
100 CloogInput
*cloog_input_alloc(CloogDomain
*context
, CloogUnionDomain
*ud
)
104 input
= ALLOC(CloogInput
);
106 cloog_die("memory overflow.\n");
108 input
->context
= context
;
114 void cloog_input_free(CloogInput
*input
)
116 cloog_domain_free(input
->context
);
117 cloog_union_domain_free(input
->ud
);
121 static void print_names(FILE *file
, CloogUnionDomain
*ud
,
122 enum cloog_dim_type type
, const char *name
)
126 fprintf(file
, "\n%d # %s name(s)\n", ud
->name
[type
] ? 1 : 0, name
);
130 for (i
= 0; i
< ud
->n_name
[type
]; i
++)
131 fprintf(file
, "%s ", ud
->name
[type
][i
]);
137 * Dump the .cloog description of a CloogInput and a CloogOptions data structure
138 * into a file. The generated .cloog file will contain the same information as
139 * the data structures. The file can be used to run the cloog program on the
142 void cloog_input_dump_cloog(FILE *file
, CloogInput
*input
, CloogOptions
*opt
)
144 int i
, num_statements
;
145 CloogUnionDomain
*ud
= input
->ud
;
146 CloogNamedDomainList
*ndl
= ud
->domain
;
150 "# This is an automatic dump of a CLooG input file from a "
155 if (opt
->language
== CLOOG_LANGUAGE_FORTRAN
) {
156 fprintf(file
, "# Language: FORTRAN\n");
157 fprintf(file
, "f\n\n");
159 fprintf(file
, "# Language: C\n");
160 fprintf(file
, "c\n\n");
164 fprintf(file
, "# Context:\n");
165 cloog_domain_print_constraints(file
, input
->context
, 1);
167 print_names(file
, ud
, CLOOG_PARAM
, "Parameter");
169 /* Statement number. */
171 while (ndl
!= NULL
) {
176 fprintf(file
, "\n# Statement number:\n%d\n\n", num_statements
);
178 /* Iteration domains. */
181 while (ndl
!= NULL
) {
182 fprintf(file
, "# Iteration domain of statement %d (%s).\n", i
,
185 cloog_domain_print_constraints(file
, ndl
->domain
, 1);
186 fprintf(file
,"\n0 0 0 # For future options.\n\n");
192 print_names(file
, ud
, CLOOG_ITER
, "Iterator");
194 /* Exit, if no scattering is supplied. */
195 if (!ud
->domain
|| !ud
->domain
->scattering
) {
196 fprintf(file
, "# No scattering functions.\n0\n\n");
200 /* Scattering relations. */
202 "# --------------------- SCATTERING --------------------\n");
204 fprintf(file
, "%d # Scattering functions\n", num_statements
);
208 while (ndl
!= NULL
) {
209 fprintf(file
, "\n# Scattering of statement %d (%s).\n", i
,
212 cloog_scattering_print_constraints(file
, ndl
->scattering
);
218 print_names(file
, ud
, CLOOG_SCAT
, "Scattering dimension");