4 #include "../include/cloog/cloog.h"
6 #define ALLOC(type) (type*)malloc(sizeof(type))
8 static char *next_line(FILE *input
, char *line
, unsigned len
)
13 if (!(p
= fgets(line
, len
, input
)))
15 while (isspace(*p
) && *p
!= '\n')
17 } while (*p
== '#' || *p
== '\n');
23 * Read input from a .cloog file, putting most of the information
24 * in the returned CloogInput. The chosen language is put in
27 CloogInput
*cloog_input_read(FILE *file
, CloogOptions
*options
)
29 char line
[MAX_STRING
];
35 /* First of all, we read the language to use. */
36 if (!next_line(file
, line
, sizeof(line
)))
37 cloog_die("Input error.\n");
38 if (sscanf(line
, "%c", &language
) != 1)
39 cloog_die("Input error.\n");
42 options
->language
= LANGUAGE_FORTRAN
;
44 options
->language
= LANGUAGE_C
;
46 /* We then read the context data. */
47 context
= cloog_domain_read_context(options
->state
, file
);
48 nb_par
= cloog_domain_parameter_dimension(context
);
50 ud
= cloog_union_domain_read(file
, nb_par
, options
);
52 return cloog_input_alloc(context
, ud
);
56 * Create a CloogInput from a CloogDomain context and a CloogUnionDomain.
58 CloogInput
*cloog_input_alloc(CloogDomain
*context
, CloogUnionDomain
*ud
)
62 input
= ALLOC(CloogInput
);
64 cloog_die("memory overflow.\n");
66 input
->context
= context
;
72 void cloog_input_free(CloogInput
*input
)
74 cloog_domain_free(input
->context
);
75 cloog_union_domain_free(input
->ud
);
79 static void print_names(FILE *file
, CloogUnionDomain
*ud
,
80 enum cloog_dim_type type
, const char *name
)
84 fprintf(file
, "\n%d # %s name(s)\n", ud
->name
[type
] ? 1 : 0, name
);
88 for (i
= 0; i
< ud
->n_name
[type
]; i
++)
89 fprintf(file
, "%s ", ud
->name
[type
][i
]);
95 * Dump the .cloog description of a CloogInput and a CloogOptions data structure
96 * into a file. The generated .cloog file will contain the same information as
97 * the data structures. The file can be used to run the cloog program on the
100 void cloog_input_dump_cloog(FILE *file
, CloogInput
*input
, CloogOptions
*opt
)
102 int i
, num_statements
;
103 CloogUnionDomain
*ud
= input
->ud
;
104 CloogNamedDomainList
*ndl
= ud
->domain
;
108 "# This is an automatic dump of a CLooG input file from a "
113 if (opt
->language
== LANGUAGE_FORTRAN
) {
114 fprintf(file
, "# Language: FORTRAN\n");
115 fprintf(file
, "f\n\n");
117 fprintf(file
, "# Language: C\n");
118 fprintf(file
, "c\n\n");
122 fprintf(file
, "# Context:\n");
123 cloog_domain_print_constraints(file
, input
->context
, 1);
125 print_names(file
, ud
, CLOOG_PARAM
, "Parameter");
127 /* Statement number. */
129 while (ndl
!= NULL
) {
134 fprintf(file
, "\n# Statement number:\n%d\n\n", num_statements
);
136 /* Iteration domains. */
139 while (ndl
!= NULL
) {
140 fprintf(file
, "# Iteration domain of statement %d (%s).\n", i
,
143 cloog_domain_print_constraints(file
, ndl
->domain
, 1);
144 fprintf(file
,"\n0 0 0 # For future options.\n\n");
150 print_names(file
, ud
, CLOOG_ITER
, "Iterator");
152 /* Exit, if no scattering is supplied. */
153 if (!ud
->domain
|| !ud
->domain
->scattering
) {
154 fprintf(file
, "# No scattering functions.\n0\n\n");
158 /* Scattering relations. */
160 "# --------------------- SCATTERING --------------------\n");
162 fprintf(file
, "%d # Scattering functions\n", num_statements
);
166 while (ndl
!= NULL
) {
167 fprintf(file
, "\n# Scattering of statement %d (%s).\n", i
,
170 cloog_scattering_print_constraints(file
, ndl
->scattering
);
176 print_names(file
, ud
, CLOOG_SCAT
, "Scattering dimension");