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
);