2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
19 #include "isl_stream.h"
20 #include "isl_map_private.h"
25 struct variable
*next
;
34 static struct vars
*vars_new(struct isl_ctx
*ctx
)
37 v
= isl_alloc_type(ctx
, struct vars
);
46 static void variable_free(struct variable
*var
)
49 struct variable
*next
= var
->next
;
56 static void vars_free(struct vars
*v
)
64 static struct variable
*variable_new(struct vars
*v
, const char *name
, int len
,
68 var
= isl_alloc_type(v
->ctx
, struct variable
);
71 var
->name
= strdup(name
);
72 var
->name
[len
] = '\0';
81 static int vars_pos(struct vars
*v
, const char *s
, int len
)
88 for (q
= v
->v
; q
; q
= q
->next
) {
89 if (strncmp(q
->name
, s
, len
) == 0 && q
->name
[len
] == '\0')
96 v
->v
= variable_new(v
, s
, len
, v
->n
);
104 static struct vars
*read_var_list(struct isl_stream
*s
, struct vars
*v
)
106 struct isl_token
*tok
;
108 while ((tok
= isl_stream_next_token(s
)) != NULL
) {
112 if (tok
->type
!= ISL_TOKEN_IDENT
)
115 p
= vars_pos(v
, tok
->u
.s
, -1);
119 isl_stream_error(s
, tok
, "expecting unique identifier");
123 tok
= isl_stream_next_token(s
);
124 if (!tok
|| tok
->type
!= ',')
130 isl_stream_push_token(s
, tok
);
139 static struct isl_vec
*accept_affine(struct isl_stream
*s
, struct vars
*v
)
141 struct isl_token
*tok
= NULL
;
145 aff
= isl_vec_alloc(v
->ctx
, 1 + v
->n
);
146 isl_seq_clr(aff
->el
, aff
->size
);
151 tok
= isl_stream_next_token(s
);
153 isl_stream_error(s
, NULL
, "unexpected EOF");
156 if (tok
->type
== ISL_TOKEN_IDENT
) {
158 int pos
= vars_pos(v
, tok
->u
.s
, -1);
162 isl_stream_error(s
, tok
, "unknown identifier");
166 isl_int_add_ui(aff
->el
[1 + pos
],
167 aff
->el
[1 + pos
], 1);
169 isl_int_sub_ui(aff
->el
[1 + pos
],
170 aff
->el
[1 + pos
], 1);
172 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
173 struct isl_token
*tok2
;
176 tok2
= isl_stream_next_token(s
);
177 if (tok2
&& tok2
->type
== ISL_TOKEN_IDENT
) {
178 pos
= vars_pos(v
, tok2
->u
.s
, -1);
182 isl_stream_error(s
, tok2
,
183 "unknown identifier");
184 isl_token_free(tok2
);
187 isl_token_free(tok2
);
189 isl_stream_push_token(s
, tok2
);
191 isl_int_neg(tok
->u
.v
, tok
->u
.v
);
192 isl_int_add(aff
->el
[1 + pos
],
193 aff
->el
[1 + pos
], tok
->u
.v
);
195 } else if (tok
->type
== '-') {
197 } else if (tok
->type
== '+') {
200 isl_stream_push_token(s
, tok
);
212 static __isl_give isl_mat
*accept_affine_list(struct isl_stream
*s
,
217 struct isl_token
*tok
= NULL
;
219 vec
= accept_affine(s
, v
);
220 mat
= isl_mat_from_row_vec(vec
);
225 tok
= isl_stream_next_token(s
);
227 isl_stream_error(s
, NULL
, "unexpected EOF");
230 if (tok
->type
!= ',') {
231 isl_stream_push_token(s
, tok
);
236 vec
= accept_affine(s
, v
);
237 mat
= isl_mat_vec_concat(mat
, vec
);
248 static struct isl_basic_map
*add_div_definition(struct isl_stream
*s
,
249 struct vars
*v
, struct isl_basic_map
*bmap
, int k
)
251 struct isl_token
*tok
;
255 if (isl_stream_eat(s
, '['))
258 tok
= isl_stream_next_token(s
);
261 if (tok
->type
== '(') {
265 isl_stream_push_token(s
, tok
);
267 aff
= accept_affine(s
, v
);
271 isl_seq_cpy(bmap
->div
[k
] + 1, aff
->el
, aff
->size
);
275 if (seen_paren
&& isl_stream_eat(s
, ')'))
277 if (isl_stream_eat(s
, '/'))
280 tok
= isl_stream_next_token(s
);
283 if (tok
->type
!= ISL_TOKEN_VALUE
) {
284 isl_stream_error(s
, tok
, "expected denominator");
285 isl_stream_push_token(s
, tok
);
288 isl_int_set(bmap
->div
[k
][0], tok
->u
.v
);
291 if (isl_stream_eat(s
, ']'))
294 if (isl_basic_map_add_div_constraints(bmap
, k
) < 0)
299 isl_basic_map_free(bmap
);
303 static struct isl_basic_map
*read_defined_var_list(struct isl_stream
*s
,
304 struct vars
*v
, struct isl_basic_map
*bmap
)
306 struct isl_token
*tok
;
308 while ((tok
= isl_stream_next_token(s
)) != NULL
) {
312 unsigned total
= isl_basic_map_total_dim(bmap
);
314 if (tok
->type
!= ISL_TOKEN_IDENT
)
317 p
= vars_pos(v
, tok
->u
.s
, -1);
321 isl_stream_error(s
, tok
, "expecting unique identifier");
326 bmap
= isl_basic_map_cow(bmap
);
327 bmap
= isl_basic_map_extend_dim(bmap
, isl_dim_copy(bmap
->dim
),
330 if ((k
= isl_basic_map_alloc_div(bmap
)) < 0)
332 isl_seq_clr(bmap
->div
[k
], 1 + 1 + total
);
334 tok
= isl_stream_next_token(s
);
335 if (tok
&& tok
->type
== '=') {
337 bmap
= add_div_definition(s
, v
, bmap
, k
);
338 tok
= isl_stream_next_token(s
);
341 if (!tok
|| tok
->type
!= ',')
347 isl_stream_push_token(s
, tok
);
352 isl_basic_map_free(bmap
);
356 static struct vars
*read_tuple(struct isl_stream
*s
, struct vars
*v
)
358 struct isl_token
*tok
;
360 tok
= isl_stream_next_token(s
);
361 if (!tok
|| tok
->type
!= '[') {
362 isl_stream_error(s
, tok
, "expecting '['");
366 v
= read_var_list(s
, v
);
367 tok
= isl_stream_next_token(s
);
368 if (!tok
|| tok
->type
!= ']') {
369 isl_stream_error(s
, tok
, "expecting ']'");
382 static struct isl_basic_map
*add_constraints(struct isl_stream
*s
,
383 struct vars
**v
, struct isl_basic_map
*bmap
);
385 static struct isl_basic_map
*add_exists(struct isl_stream
*s
,
386 struct vars
**v
, struct isl_basic_map
*bmap
)
388 struct isl_token
*tok
;
395 tok
= isl_stream_next_token(s
);
398 if (tok
->type
== '(') {
402 isl_stream_push_token(s
, tok
);
404 bmap
= read_defined_var_list(s
, *v
, bmap
);
408 if (isl_stream_eat(s
, ':'))
410 bmap
= add_constraints(s
, v
, bmap
);
411 if (seen_paren
&& isl_stream_eat(s
, ')'))
415 isl_basic_map_free(bmap
);
419 static __isl_give isl_basic_map
*construct_constraint(
420 __isl_take isl_basic_map
*bmap
, enum isl_token_type type
,
421 isl_int
*left
, isl_int
*right
)
429 len
= 1 + isl_basic_map_total_dim(bmap
);
432 k
= isl_basic_map_alloc_inequality(bmap
);
435 if (type
== ISL_TOKEN_LE
)
436 isl_seq_combine(bmap
->ineq
[k
], ctx
->negone
, left
,
439 else if (type
== ISL_TOKEN_GE
)
440 isl_seq_combine(bmap
->ineq
[k
], ctx
->one
, left
,
443 else if (type
== ISL_TOKEN_LT
) {
444 isl_seq_combine(bmap
->ineq
[k
], ctx
->negone
, left
,
447 isl_int_sub_ui(bmap
->ineq
[k
][0], bmap
->ineq
[k
][0], 1);
448 } else if (type
== ISL_TOKEN_GT
) {
449 isl_seq_combine(bmap
->ineq
[k
], ctx
->one
, left
,
452 isl_int_sub_ui(bmap
->ineq
[k
][0], bmap
->ineq
[k
][0], 1);
454 isl_seq_combine(bmap
->ineq
[k
], ctx
->one
, left
,
457 isl_basic_map_inequality_to_equality(bmap
, k
);
462 isl_basic_map_free(bmap
);
466 static struct isl_basic_map
*add_constraint(struct isl_stream
*s
,
467 struct vars
**v
, struct isl_basic_map
*bmap
)
470 unsigned total
= isl_basic_map_total_dim(bmap
);
471 struct isl_token
*tok
= NULL
;
472 struct isl_mat
*aff1
= NULL
, *aff2
= NULL
;
474 tok
= isl_stream_next_token(s
);
477 if (tok
->type
== ISL_TOKEN_EXISTS
) {
479 return add_exists(s
, v
, bmap
);
481 isl_stream_push_token(s
, tok
);
484 bmap
= isl_basic_map_cow(bmap
);
486 aff1
= accept_affine_list(s
, *v
);
489 tok
= isl_stream_next_token(s
);
498 isl_stream_error(s
, tok
, "missing operator");
499 isl_stream_push_token(s
, tok
);
503 aff2
= accept_affine_list(s
, *v
);
506 isl_assert(aff1
->ctx
, aff1
->n_col
== 1 + total
, goto error
);
507 isl_assert(aff2
->ctx
, aff2
->n_col
== 1 + total
, goto error
);
509 bmap
= isl_basic_map_extend_constraints(bmap
, 0, aff1
->n_row
* aff2
->n_row
);
510 for (i
= 0; i
< aff1
->n_row
; ++i
)
511 for (j
= 0; j
< aff2
->n_row
; ++j
)
512 bmap
= construct_constraint(bmap
, tok
->type
,
513 aff1
->row
[i
], aff2
->row
[j
]);
524 isl_basic_map_free(bmap
);
528 static struct isl_basic_map
*add_constraints(struct isl_stream
*s
,
529 struct vars
**v
, struct isl_basic_map
*bmap
)
531 struct isl_token
*tok
;
534 bmap
= add_constraint(s
, v
, bmap
);
537 tok
= isl_stream_next_token(s
);
539 isl_stream_error(s
, NULL
, "unexpected EOF");
542 if (tok
->type
!= ISL_TOKEN_AND
)
546 isl_stream_push_token(s
, tok
);
552 isl_basic_map_free(bmap
);
556 static struct isl_basic_map
*read_disjunct(struct isl_stream
*s
,
557 struct vars
**v
, __isl_take isl_dim
*dim
)
559 struct isl_basic_map
*bmap
;
561 bmap
= isl_basic_map_alloc_dim(dim
, 0, 0, 0);
565 bmap
= add_constraints(s
, v
, bmap
);
566 bmap
= isl_basic_map_simplify(bmap
);
567 bmap
= isl_basic_map_finalize(bmap
);
571 static struct isl_map
*read_disjuncts(struct isl_stream
*s
,
572 struct vars
**v
, __isl_take isl_dim
*dim
)
574 struct isl_token
*tok
;
577 tok
= isl_stream_next_token(s
);
579 isl_stream_error(s
, NULL
, "unexpected EOF");
582 if (tok
->type
== '}') {
583 isl_stream_push_token(s
, tok
);
584 return isl_map_universe(dim
);
586 isl_stream_push_token(s
, tok
);
588 map
= isl_map_empty(isl_dim_copy(dim
));
590 struct isl_basic_map
*bmap
;
592 bmap
= read_disjunct(s
, v
, isl_dim_copy(dim
));
593 map
= isl_map_union(map
, isl_map_from_basic_map(bmap
));
595 tok
= isl_stream_next_token(s
);
596 if (!tok
|| tok
->type
!= ISL_TOKEN_OR
)
601 isl_stream_push_token(s
, tok
);
610 static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map
*bmap
, int pos
)
612 if (pos
< isl_basic_map_dim(bmap
, isl_dim_out
))
613 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) +
614 isl_basic_map_dim(bmap
, isl_dim_in
) + pos
;
615 pos
-= isl_basic_map_dim(bmap
, isl_dim_out
);
617 if (pos
< isl_basic_map_dim(bmap
, isl_dim_in
))
618 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) + pos
;
619 pos
-= isl_basic_map_dim(bmap
, isl_dim_in
);
621 if (pos
< isl_basic_map_dim(bmap
, isl_dim_div
))
622 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) +
623 isl_basic_map_dim(bmap
, isl_dim_in
) +
624 isl_basic_map_dim(bmap
, isl_dim_out
) + pos
;
625 pos
-= isl_basic_map_dim(bmap
, isl_dim_div
);
627 if (pos
< isl_basic_map_dim(bmap
, isl_dim_param
))
633 static __isl_give isl_basic_map
*basic_map_read_polylib_constraint(
634 struct isl_stream
*s
, __isl_take isl_basic_map
*bmap
)
637 struct isl_token
*tok
;
647 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
648 dim
= isl_basic_map_dim(bmap
, isl_dim_out
);
650 tok
= isl_stream_next_token(s
);
651 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
652 isl_stream_error(s
, tok
, "expecting coefficient");
654 isl_stream_push_token(s
, tok
);
657 if (!tok
->on_new_line
) {
658 isl_stream_error(s
, tok
, "coefficient should appear on new line");
659 isl_stream_push_token(s
, tok
);
663 type
= isl_int_get_si(tok
->u
.v
);
666 isl_assert(s
->ctx
, type
== 0 || type
== 1, goto error
);
668 k
= isl_basic_map_alloc_equality(bmap
);
671 k
= isl_basic_map_alloc_inequality(bmap
);
677 for (j
= 0; j
< 1 + isl_basic_map_total_dim(bmap
); ++j
) {
679 tok
= isl_stream_next_token(s
);
680 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
681 isl_stream_error(s
, tok
, "expecting coefficient");
683 isl_stream_push_token(s
, tok
);
686 if (tok
->on_new_line
) {
687 isl_stream_error(s
, tok
,
688 "coefficient should not appear on new line");
689 isl_stream_push_token(s
, tok
);
692 pos
= polylib_pos_to_isl_pos(bmap
, j
);
693 isl_int_set(c
[pos
], tok
->u
.v
);
699 isl_basic_map_free(bmap
);
703 static __isl_give isl_basic_map
*basic_map_read_polylib(struct isl_stream
*s
,
707 struct isl_token
*tok
;
708 struct isl_token
*tok2
;
711 unsigned in
= 0, out
, local
= 0;
712 struct isl_basic_map
*bmap
= NULL
;
717 tok
= isl_stream_next_token(s
);
719 isl_stream_error(s
, NULL
, "unexpected EOF");
722 tok2
= isl_stream_next_token(s
);
725 isl_stream_error(s
, NULL
, "unexpected EOF");
728 n_row
= isl_int_get_si(tok
->u
.v
);
729 n_col
= isl_int_get_si(tok2
->u
.v
);
730 on_new_line
= tok2
->on_new_line
;
731 isl_token_free(tok2
);
733 isl_assert(s
->ctx
, !on_new_line
, return NULL
);
734 isl_assert(s
->ctx
, n_row
>= 0, return NULL
);
735 isl_assert(s
->ctx
, n_col
>= 2 + nparam
, return NULL
);
736 tok
= isl_stream_next_token_on_same_line(s
);
738 if (tok
->type
!= ISL_TOKEN_VALUE
) {
739 isl_stream_error(s
, tok
,
740 "expecting number of output dimensions");
741 isl_stream_push_token(s
, tok
);
744 out
= isl_int_get_si(tok
->u
.v
);
747 tok
= isl_stream_next_token_on_same_line(s
);
748 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
749 isl_stream_error(s
, tok
,
750 "expecting number of input dimensions");
752 isl_stream_push_token(s
, tok
);
755 in
= isl_int_get_si(tok
->u
.v
);
758 tok
= isl_stream_next_token_on_same_line(s
);
759 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
760 isl_stream_error(s
, tok
,
761 "expecting number of existentials");
763 isl_stream_push_token(s
, tok
);
766 local
= isl_int_get_si(tok
->u
.v
);
769 tok
= isl_stream_next_token_on_same_line(s
);
770 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
771 isl_stream_error(s
, tok
,
772 "expecting number of parameters");
774 isl_stream_push_token(s
, tok
);
777 nparam
= isl_int_get_si(tok
->u
.v
);
779 if (n_col
!= 1 + out
+ in
+ local
+ nparam
+ 1) {
780 isl_stream_error(s
, NULL
,
781 "dimensions don't match");
785 out
= n_col
- 2 - nparam
;
786 bmap
= isl_basic_map_alloc(s
->ctx
, nparam
, in
, out
, local
, n_row
, n_row
);
790 for (i
= 0; i
< local
; ++i
) {
791 int k
= isl_basic_map_alloc_div(bmap
);
796 for (i
= 0; i
< n_row
; ++i
)
797 bmap
= basic_map_read_polylib_constraint(s
, bmap
);
799 bmap
= isl_basic_map_simplify(bmap
);
800 bmap
= isl_basic_map_finalize(bmap
);
803 isl_basic_map_free(bmap
);
807 static struct isl_map
*map_read_polylib(struct isl_stream
*s
, int nparam
)
809 struct isl_token
*tok
;
810 struct isl_token
*tok2
;
814 tok
= isl_stream_next_token(s
);
816 isl_stream_error(s
, NULL
, "unexpected EOF");
819 tok2
= isl_stream_next_token(s
);
822 isl_stream_error(s
, NULL
, "unexpected EOF");
825 if (!tok2
->on_new_line
) {
826 isl_stream_push_token(s
, tok2
);
827 isl_stream_push_token(s
, tok
);
828 return isl_map_from_basic_map(basic_map_read_polylib(s
, nparam
));
830 isl_stream_push_token(s
, tok2
);
831 n
= isl_int_get_si(tok
->u
.v
);
834 isl_assert(s
->ctx
, n
>= 1, return NULL
);
836 map
= isl_map_from_basic_map(basic_map_read_polylib(s
, nparam
));
838 for (i
= 1; i
< n
; ++i
)
839 map
= isl_map_union(map
,
840 isl_map_from_basic_map(basic_map_read_polylib(s
, nparam
)));
845 static struct isl_dim
*set_names(struct isl_dim
*dim
, struct vars
*vars
,
846 enum isl_dim_type type
, int offset
, int n
)
851 for (i
= 0, v
= vars
->v
; i
< offset
; ++i
, v
= v
->next
)
853 for (i
= n
- 1; i
>= 0; --i
, v
= v
->next
)
854 dim
= isl_dim_set_name(dim
, type
, i
, v
->name
);
859 static struct isl_dim
*dim_from_vars(struct vars
*vars
,
860 int nparam
, int n_in
, int n_out
)
864 dim
= isl_dim_alloc(vars
->ctx
, nparam
, n_in
, n_out
);
865 dim
= set_names(dim
, vars
, isl_dim_param
, n_out
+ n_in
, nparam
);
866 dim
= set_names(dim
, vars
, isl_dim_in
, n_out
, n_in
);
867 dim
= set_names(dim
, vars
, isl_dim_out
, 0, n_out
);
872 static struct isl_map
*map_read(struct isl_stream
*s
, int nparam
)
874 struct isl_dim
*dim
= NULL
;
875 struct isl_map
*map
= NULL
;
876 struct isl_token
*tok
;
877 struct vars
*v
= NULL
;
881 tok
= isl_stream_next_token(s
);
883 isl_stream_error(s
, NULL
, "unexpected EOF");
886 if (tok
->type
== ISL_TOKEN_VALUE
) {
887 isl_stream_push_token(s
, tok
);
888 return map_read_polylib(s
, nparam
);
890 v
= vars_new(s
->ctx
);
891 if (tok
->type
== '[') {
892 isl_stream_push_token(s
, tok
);
893 v
= read_tuple(s
, v
);
897 isl_assert(s
->ctx
, nparam
== v
->n
, goto error
);
899 tok
= isl_stream_next_token(s
);
900 if (!tok
|| tok
->type
!= ISL_TOKEN_TO
) {
901 isl_stream_error(s
, tok
, "expecting '->'");
903 isl_stream_push_token(s
, tok
);
907 tok
= isl_stream_next_token(s
);
911 if (!tok
|| tok
->type
!= '{') {
912 isl_stream_error(s
, tok
, "expecting '{'");
914 isl_stream_push_token(s
, tok
);
918 v
= read_tuple(s
, v
);
922 tok
= isl_stream_next_token(s
);
923 if (tok
&& tok
->type
== ISL_TOKEN_TO
) {
925 v
= read_tuple(s
, v
);
928 n2
= v
->n
- n1
- nparam
;
931 isl_stream_push_token(s
, tok
);
935 dim
= dim_from_vars(v
, nparam
, n1
, n2
);
936 tok
= isl_stream_next_token(s
);
938 isl_stream_error(s
, NULL
, "unexpected EOF");
941 if (tok
->type
== ':') {
943 map
= read_disjuncts(s
, &v
, isl_dim_copy(dim
));
944 tok
= isl_stream_next_token(s
);
946 map
= isl_map_universe(isl_dim_copy(dim
));
947 if (tok
&& tok
->type
== '}') {
950 isl_stream_error(s
, tok
, "unexpected isl_token");
967 static struct isl_basic_map
*basic_map_read(struct isl_stream
*s
, int nparam
)
970 struct isl_basic_map
*bmap
;
972 map
= map_read(s
, nparam
);
976 isl_assert(map
->ctx
, map
->n
<= 1, goto error
);
979 bmap
= isl_basic_map_empty_like_map(map
);
981 bmap
= isl_basic_map_copy(map
->p
[0]);
991 __isl_give isl_basic_map
*isl_basic_map_read_from_file(isl_ctx
*ctx
,
992 FILE *input
, int nparam
)
994 struct isl_basic_map
*bmap
;
995 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
998 bmap
= basic_map_read(s
, nparam
);
1003 __isl_give isl_basic_set
*isl_basic_set_read_from_file(isl_ctx
*ctx
,
1004 FILE *input
, int nparam
)
1006 struct isl_basic_map
*bmap
;
1007 bmap
= isl_basic_map_read_from_file(ctx
, input
, nparam
);
1010 isl_assert(ctx
, isl_basic_map_n_in(bmap
) == 0, goto error
);
1011 return (struct isl_basic_set
*)bmap
;
1013 isl_basic_map_free(bmap
);
1017 struct isl_basic_map
*isl_basic_map_read_from_str(struct isl_ctx
*ctx
,
1018 const char *str
, int nparam
)
1020 struct isl_basic_map
*bmap
;
1021 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
1024 bmap
= basic_map_read(s
, nparam
);
1029 struct isl_basic_set
*isl_basic_set_read_from_str(struct isl_ctx
*ctx
,
1030 const char *str
, int nparam
)
1032 struct isl_basic_map
*bmap
;
1033 bmap
= isl_basic_map_read_from_str(ctx
, str
, nparam
);
1036 isl_assert(ctx
, isl_basic_map_n_in(bmap
) == 0, goto error
);
1037 return (struct isl_basic_set
*)bmap
;
1039 isl_basic_map_free(bmap
);
1043 __isl_give isl_map
*isl_map_read_from_file(struct isl_ctx
*ctx
,
1044 FILE *input
, int nparam
)
1046 struct isl_map
*map
;
1047 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
1050 map
= map_read(s
, nparam
);
1055 __isl_give isl_map
*isl_map_read_from_str(struct isl_ctx
*ctx
,
1056 const char *str
, int nparam
)
1058 struct isl_map
*map
;
1059 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
1062 map
= map_read(s
, nparam
);
1067 __isl_give isl_set
*isl_set_read_from_file(struct isl_ctx
*ctx
,
1068 FILE *input
, int nparam
)
1070 struct isl_map
*map
;
1071 map
= isl_map_read_from_file(ctx
, input
, nparam
);
1074 isl_assert(ctx
, isl_map_n_in(map
) == 0, goto error
);
1075 return (struct isl_set
*)map
;
1081 struct isl_set
*isl_set_read_from_str(struct isl_ctx
*ctx
,
1082 const char *str
, int nparam
)
1084 struct isl_map
*map
;
1085 map
= isl_map_read_from_str(ctx
, str
, nparam
);
1088 isl_assert(ctx
, isl_map_n_in(map
) == 0, goto error
);
1089 return (struct isl_set
*)map
;
1095 static char *next_line(FILE *input
, char *line
, unsigned len
)
1100 if (!(p
= fgets(line
, len
, input
)))
1102 while (isspace(*p
) && *p
!= '\n')
1104 } while (*p
== '#' || *p
== '\n');
1109 static struct isl_vec
*isl_vec_read_from_file_polylib(struct isl_ctx
*ctx
,
1112 struct isl_vec
*vec
= NULL
;
1121 isl_assert(ctx
, next_line(input
, line
, sizeof(line
)), return NULL
);
1122 isl_assert(ctx
, sscanf(line
, "%u", &size
) == 1, return NULL
);
1124 vec
= isl_vec_alloc(ctx
, size
);
1126 p
= next_line(input
, line
, sizeof(line
));
1127 isl_assert(ctx
, p
, goto error
);
1129 for (j
= 0; j
< size
; ++j
) {
1130 n
= sscanf(p
, "%s%n", val
, &offset
);
1131 isl_assert(ctx
, n
!= 0, goto error
);
1132 isl_int_read(vec
->el
[j
], val
);
1142 struct isl_vec
*isl_vec_read_from_file(struct isl_ctx
*ctx
,
1143 FILE *input
, unsigned input_format
)
1145 if (input_format
== ISL_FORMAT_POLYLIB
)
1146 return isl_vec_read_from_file_polylib(ctx
, input
);
1148 isl_assert(ctx
, 0, return NULL
);