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
);
75 if (options
->openscop
) {
76 cloog_die("CLooG has not been compiled with OpenScop support.\n");
80 /* First of all, we read the language to use. */
81 if (!next_line(file
, line
, sizeof(line
)))
82 cloog_die("Input error.\n");
83 if (sscanf(line
, "%c", &language
) != 1)
84 cloog_die("Input error.\n");
87 options
->language
= CLOOG_LANGUAGE_FORTRAN
;
89 options
->language
= CLOOG_LANGUAGE_C
;
91 /* We then read the context data. */
92 context
= cloog_domain_read_context(options
->state
, file
);
93 nb_par
= cloog_domain_parameter_dimension(context
);
95 ud
= cloog_union_domain_read(file
, nb_par
, options
);
97 return cloog_input_alloc(context
, ud
);
101 * Create a CloogInput from a CloogDomain context and a CloogUnionDomain.
103 CloogInput
*cloog_input_alloc(CloogDomain
*context
, CloogUnionDomain
*ud
)
107 input
= ALLOC(CloogInput
);
109 cloog_die("memory overflow.\n");
111 input
->context
= context
;
117 void cloog_input_free(CloogInput
*input
)
119 cloog_domain_free(input
->context
);
120 cloog_union_domain_free(input
->ud
);
124 static void print_names(FILE *file
, CloogUnionDomain
*ud
,
125 enum cloog_dim_type type
, const char *name
)
129 fprintf(file
, "\n%d # %s name(s)\n", ud
->name
[type
] ? 1 : 0, name
);
133 for (i
= 0; i
< ud
->n_name
[type
]; i
++)
134 fprintf(file
, "%s ", ud
->name
[type
][i
]);
140 * Dump the .cloog description of a CloogInput and a CloogOptions data structure
141 * into a file. The generated .cloog file will contain the same information as
142 * the data structures. The file can be used to run the cloog program on the
145 void cloog_input_dump_cloog(FILE *file
, CloogInput
*input
, CloogOptions
*opt
)
147 int i
, num_statements
;
148 CloogUnionDomain
*ud
= input
->ud
;
149 CloogNamedDomainList
*ndl
= ud
->domain
;
153 "# This is an automatic dump of a CLooG input file from a "
158 if (opt
->language
== CLOOG_LANGUAGE_FORTRAN
) {
159 fprintf(file
, "# Language: FORTRAN\n");
160 fprintf(file
, "f\n\n");
162 fprintf(file
, "# Language: C\n");
163 fprintf(file
, "c\n\n");
167 fprintf(file
, "# Context:\n");
168 cloog_domain_print_constraints(file
, input
->context
, 1);
170 print_names(file
, ud
, CLOOG_PARAM
, "Parameter");
172 /* Statement number. */
174 while (ndl
!= NULL
) {
179 fprintf(file
, "\n# Statement number:\n%d\n\n", num_statements
);
181 /* Iteration domains. */
184 while (ndl
!= NULL
) {
185 fprintf(file
, "# Iteration domain of statement %d (%s).\n", i
,
188 cloog_domain_print_constraints(file
, ndl
->domain
, 1);
189 fprintf(file
,"\n0 0 0 # For future options.\n\n");
195 print_names(file
, ud
, CLOOG_ITER
, "Iterator");
197 /* Exit, if no scattering is supplied. */
198 if (!ud
->domain
|| !ud
->domain
->scattering
) {
199 fprintf(file
, "# No scattering functions.\n0\n\n");
203 /* Scattering relations. */
205 "# --------------------- SCATTERING --------------------\n");
207 fprintf(file
, "%d # Scattering functions\n", num_statements
);
211 while (ndl
!= NULL
) {
212 fprintf(file
, "\n# Scattering of statement %d (%s).\n", i
,
215 cloog_scattering_print_constraints(file
, ndl
->scattering
);
221 print_names(file
, ud
, CLOOG_SCAT
, "Scattering dimension");