5 #include "isl_map_private.h"
6 #include "isl_input_omega.h"
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');
22 static struct isl_basic_set *isl_basic_set_read_from_file_polylib(
23 struct isl_ctx *ctx, FILE *input, unsigned nparam)
25 struct isl_basic_set *bset = NULL;
27 unsigned n_row, n_col;
33 isl_assert(ctx, next_line(input, line, sizeof(line)), return NULL);
34 isl_assert(ctx, sscanf(line, "%u %u", &n_row, &n_col) == 2, return NULL);
35 isl_assert(ctx, n_col >= 2, return NULL);
36 dim = n_col - 2 - nparam;
37 bset = isl_basic_set_alloc(ctx, nparam, dim, 0, n_row, n_row);
40 for (i = 0; i < n_row; ++i) {
47 p = next_line(input, line, sizeof(line));
48 isl_assert(ctx, p, goto error);
49 n = sscanf(p, "%u%n", &type, &offset);
50 isl_assert(ctx, n != 0, goto error);
52 isl_assert(ctx, type == 0 || type == 1, goto error);
54 k = isl_basic_set_alloc_equality(bset);
57 k = isl_basic_set_alloc_inequality(bset);
60 isl_assert(ctx, k >= 0, goto error);
61 for (j = 0; j < dim; ++j) {
62 n = sscanf(p, "%s%n", val, &offset);
63 isl_assert(ctx, n != 0, goto error);
64 isl_int_read(c[1+nparam+j], val);
67 for (j = 0; j < nparam; ++j) {
68 n = sscanf(p, "%s%n", val, &offset);
69 isl_assert(ctx, n != 0, goto error);
70 isl_int_read(c[1+j], val);
73 n = sscanf(p, "%s%n", val, &offset);
74 isl_assert(ctx, n != 0, goto error);
75 isl_int_read(c[0], val);
77 bset = isl_basic_set_simplify(bset);
78 bset = isl_basic_set_finalize(bset);
81 isl_basic_set_free(bset);
85 static struct isl_set *isl_set_read_from_file_polylib(
86 struct isl_ctx *ctx, FILE *input, unsigned nparam)
88 struct isl_set *set = NULL;
93 isl_assert(ctx, next_line(input, line, sizeof(line)), return NULL);
94 isl_assert(ctx, sscanf(line, "%u", &n) == 1, return NULL);
96 set = isl_set_alloc(ctx, nparam, 0, n, 0);
101 for (i = 0; i < n; ++i) {
102 set->p[i] = isl_basic_set_read_from_file_polylib(ctx, input,
108 isl_dim_free(set->dim);
109 set->dim = isl_dim_copy(set->p[0]->dim);
110 for (i = 1; i < n; ++i)
111 isl_assert(ctx, isl_dim_equal(set->dim, set->p[i]->dim),
119 struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx,
120 FILE *input, unsigned nparam, unsigned input_format)
122 if (input_format == ISL_FORMAT_POLYLIB)
123 return isl_basic_set_read_from_file_polylib(ctx, input, nparam);
124 else if (input_format == ISL_FORMAT_OMEGA) {
125 isl_assert(ctx, nparam == 0, return NULL);
126 return isl_basic_set_read_from_file_omega(ctx, input);
128 isl_assert(ctx, 0, return NULL);
131 struct isl_basic_map *isl_basic_map_read_from_file(struct isl_ctx *ctx,
132 FILE *input, unsigned nparam, unsigned input_format)
134 if (input_format == ISL_FORMAT_OMEGA)
135 return isl_basic_map_read_from_file_omega(ctx, input);
137 isl_assert(ctx, 0, return NULL);
140 struct isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
141 FILE *input, unsigned nparam, unsigned input_format)
143 if (input_format == ISL_FORMAT_POLYLIB)
144 return isl_set_read_from_file_polylib(ctx, input, nparam);
146 isl_assert(ctx, 0, return NULL);