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
20 #include "isl_stream.h"
21 #include "isl_map_private.h"
23 #include "isl_polynomial_private.h"
24 #include <isl_union_map.h>
25 #include <isl_mat_private.h>
31 struct variable *next;
40 static struct vars *vars_new(struct isl_ctx *ctx)
43 v = isl_alloc_type(ctx, struct vars);
52 static void variable_free(struct variable *var)
55 struct variable *next = var->next;
56 isl_vec_free(var->def);
63 static void vars_free(struct vars *v)
71 static void vars_drop(struct vars *v, int n)
82 struct variable *next = var->next;
83 isl_vec_free(var->def);
91 static struct variable *variable_new(struct vars *v, const char *name, int len,
95 var = isl_alloc_type(v->ctx, struct variable);
98 var->name = strdup(name);
99 var->name[len] = '\0';
109 static int vars_pos(struct vars *v, const char *s, int len)
116 for (q = v->v; q; q = q->next) {
117 if (strncmp(q->name, s, len) == 0 && q->name[len] == '\0')
124 v->v = variable_new(v, s, len, v->n);
132 static int vars_add_anon(struct vars *v)
134 v->v = variable_new(v, "", 0, v->n);
143 static __isl_give isl_basic_map *set_name(__isl_take isl_basic_map *bmap,
144 enum isl_dim_type type, unsigned pos, char *name)
153 prime = strchr(name, '\'');
156 bmap = isl_basic_map_set_dim_name(bmap, type, pos, name);
163 static int accept_cst_factor(struct isl_stream *s, isl_int *f)
165 struct isl_token *tok;
167 tok = isl_stream_next_token(s);
168 if (!tok || tok->type != ISL_TOKEN_VALUE) {
169 isl_stream_error(s, tok, "expecting constant value");
173 isl_int_mul(*f, *f, tok->u.v);
177 if (isl_stream_eat_if_available(s, '*'))
178 return accept_cst_factor(s, f);
186 static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v);
187 static int read_div_definition(struct isl_stream *s, struct vars *v);
189 static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s,
192 struct isl_token *tok = NULL;
195 tok = isl_stream_next_token(s);
197 isl_stream_error(s, NULL, "unexpected EOF");
200 if (tok->type == ISL_TOKEN_IDENT) {
202 int pos = vars_pos(v, tok->u.s, -1);
206 isl_stream_error(s, tok, "unknown identifier");
210 aff = isl_vec_alloc(v->ctx, 1 + v->n);
213 isl_seq_clr(aff->el, aff->size);
214 isl_int_set_si(aff->el[1 + pos], 1);
216 } else if (tok->type == ISL_TOKEN_VALUE) {
217 if (isl_stream_eat_if_available(s, '*')) {
218 aff = accept_affine_factor(s, v);
219 aff = isl_vec_scale(aff, tok->u.v);
221 aff = isl_vec_alloc(v->ctx, 1 + v->n);
224 isl_seq_clr(aff->el, aff->size);
225 isl_int_set(aff->el[0], tok->u.v);
228 } else if (tok->type == '(') {
231 aff = accept_affine(s, v);
234 if (isl_stream_eat(s, ')'))
236 } else if (tok->type == '[') {
237 if (vars_add_anon(v) < 0)
239 aff = isl_vec_alloc(v->ctx, 1 + v->n);
242 isl_seq_clr(aff->el, aff->size);
243 isl_int_set_si(aff->el[1 + v->n - 1], 1);
244 isl_stream_push_token(s, tok);
246 if (read_div_definition(s, v) < 0)
249 isl_stream_error(s, tok, "expecting factor");
252 if (isl_stream_eat_if_available(s, '*')) {
255 isl_int_set_si(f, 1);
256 if (accept_cst_factor(s, &f) < 0) {
260 aff = isl_vec_scale(aff, f);
271 static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
273 struct isl_token *tok = NULL;
277 aff = isl_vec_alloc(v->ctx, 1 + v->n);
280 isl_seq_clr(aff->el, aff->size);
283 tok = isl_stream_next_token(s);
285 isl_stream_error(s, NULL, "unexpected EOF");
288 if (tok->type == '-') {
293 if (tok->type == '(' || tok->type == '[' ||
294 tok->type == ISL_TOKEN_IDENT) {
296 isl_stream_push_token(s, tok);
298 aff2 = accept_affine_factor(s, v);
300 aff2 = isl_vec_scale(aff2, s->ctx->negone);
301 aff = isl_vec_zero_extend(aff, 1 + v->n);
302 aff = isl_vec_add(aff, aff2);
306 } else if (tok->type == ISL_TOKEN_VALUE) {
308 isl_int_neg(tok->u.v, tok->u.v);
309 if (isl_stream_eat_if_available(s, '*') ||
310 isl_stream_next_token_is(s, ISL_TOKEN_IDENT)) {
312 aff2 = accept_affine_factor(s, v);
313 aff2 = isl_vec_scale(aff2, tok->u.v);
314 aff = isl_vec_zero_extend(aff, 1 + v->n);
315 aff = isl_vec_add(aff, aff2);
319 isl_int_add(aff->el[0], aff->el[0], tok->u.v);
323 isl_stream_error(s, tok, "unexpected isl_token");
324 isl_stream_push_token(s, tok);
330 tok = isl_stream_next_token(s);
331 if (tok && tok->type == '-') {
334 } else if (tok && tok->type == '+') {
337 } else if (tok && tok->type == ISL_TOKEN_VALUE &&
338 isl_int_is_neg(tok->u.v)) {
339 isl_stream_push_token(s, tok);
342 isl_stream_push_token(s, tok);
354 /* Add any variables in the variable list "v" that are not already in "bmap"
355 * as existentially quantified variables in "bmap".
357 static __isl_give isl_basic_map *add_divs(__isl_take isl_basic_map *bmap,
362 struct variable *var;
364 extra = v->n - isl_basic_map_total_dim(bmap);
369 bmap = isl_basic_map_extend_dim(bmap, isl_basic_map_get_dim(bmap),
370 extra, 0, 2 * extra);
372 for (i = 0; i < extra; ++i)
373 if (isl_basic_map_alloc_div(bmap) < 0)
376 for (i = 0, var = v->v; i < extra; ++i, var = var->next) {
377 int k = bmap->n_div - 1 - i;
379 isl_seq_cpy(bmap->div[k], var->def->el, 2 + var->pos);
380 isl_seq_clr(bmap->div[k] + 2 + var->pos, v->n - var->pos);
382 if (isl_basic_map_add_div_constraints(bmap, k) < 0)
388 isl_basic_map_free(bmap);
392 static __isl_give isl_basic_map *read_var_def(struct isl_stream *s,
393 __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
399 if (vars_add_anon(v) < 0)
403 vec = accept_affine(s, v);
407 bmap = add_divs(bmap, v);
408 bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
409 k = isl_basic_map_alloc_equality(bmap);
411 isl_seq_cpy(bmap->eq[k], vec->el, vec->size);
412 isl_int_set_si(bmap->eq[k][1 + n - 1], -1);
418 vars_drop(v, v->n - n);
422 isl_basic_map_free(bmap);
426 static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
427 __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
430 struct isl_token *tok;
432 while ((tok = isl_stream_next_token(s)) != NULL) {
435 if (tok->type == ISL_TOKEN_IDENT) {
437 int p = vars_pos(v, tok->u.s, -1);
444 bmap = isl_basic_map_add(bmap, type, 1);
445 bmap = set_name(bmap, type, i, v->v->name);
447 } else if (tok->type == ISL_TOKEN_IDENT ||
448 tok->type == ISL_TOKEN_VALUE ||
451 if (type == isl_dim_param) {
452 isl_stream_error(s, tok,
453 "expecting unique identifier");
456 isl_stream_push_token(s, tok);
458 bmap = isl_basic_map_add(bmap, type, 1);
459 bmap = read_var_def(s, bmap, type, v);
463 tok = isl_stream_next_token(s);
464 if (!tok || tok->type != ',')
471 isl_stream_push_token(s, tok);
473 bmap = isl_basic_map_simplify(bmap);
474 bmap = isl_basic_map_finalize(bmap);
478 isl_basic_map_free(bmap);
482 static __isl_give isl_mat *accept_affine_list(struct isl_stream *s,
487 struct isl_token *tok = NULL;
489 vec = accept_affine(s, v);
490 mat = isl_mat_from_row_vec(vec);
495 tok = isl_stream_next_token(s);
497 isl_stream_error(s, NULL, "unexpected EOF");
500 if (tok->type != ',') {
501 isl_stream_push_token(s, tok);
506 vec = accept_affine(s, v);
507 mat = isl_mat_add_zero_cols(mat, 1 + v->n - isl_mat_cols(mat));
508 mat = isl_mat_vec_concat(mat, vec);
519 static int read_div_definition(struct isl_stream *s, struct vars *v)
521 struct isl_token *tok;
524 struct variable *var;
526 if (isl_stream_eat(s, '['))
529 tok = isl_stream_next_token(s);
532 if (tok->type == '(') {
536 isl_stream_push_token(s, tok);
540 aff = accept_affine(s, v);
544 var->def = isl_vec_alloc(s->ctx, 2 + v->n);
550 isl_seq_cpy(var->def->el + 1, aff->el, aff->size);
554 if (seen_paren && isl_stream_eat(s, ')'))
556 if (isl_stream_eat(s, '/'))
559 tok = isl_stream_next_token(s);
562 if (tok->type != ISL_TOKEN_VALUE) {
563 isl_stream_error(s, tok, "expected denominator");
564 isl_stream_push_token(s, tok);
567 isl_int_set(var->def->el[0], tok->u.v);
570 if (isl_stream_eat(s, ']'))
576 static struct isl_basic_map *add_div_definition(struct isl_stream *s,
577 struct vars *v, struct isl_basic_map *bmap, int k)
579 struct variable *var = v->v;
581 if (read_div_definition(s, v) < 0)
584 isl_seq_cpy(bmap->div[k], var->def->el, 2 + v->n);
586 if (isl_basic_map_add_div_constraints(bmap, k) < 0)
591 isl_basic_map_free(bmap);
595 static struct isl_basic_map *read_defined_var_list(struct isl_stream *s,
596 struct vars *v, struct isl_basic_map *bmap)
598 struct isl_token *tok;
600 while ((tok = isl_stream_next_token(s)) != NULL) {
604 unsigned total = isl_basic_map_total_dim(bmap);
606 if (tok->type != ISL_TOKEN_IDENT)
609 p = vars_pos(v, tok->u.s, -1);
613 isl_stream_error(s, tok, "expecting unique identifier");
617 bmap = isl_basic_map_cow(bmap);
618 bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
621 if ((k = isl_basic_map_alloc_div(bmap)) < 0)
623 isl_seq_clr(bmap->div[k], 1 + 1 + total);
626 tok = isl_stream_next_token(s);
627 if (tok && tok->type == '=') {
629 bmap = add_div_definition(s, v, bmap, k);
630 tok = isl_stream_next_token(s);
633 if (!tok || tok->type != ',')
639 isl_stream_push_token(s, tok);
644 isl_basic_map_free(bmap);
648 static int next_is_tuple(struct isl_stream *s)
650 struct isl_token *tok;
653 tok = isl_stream_next_token(s);
656 if (tok->type == '[') {
657 isl_stream_push_token(s, tok);
660 if (tok->type != ISL_TOKEN_IDENT) {
661 isl_stream_push_token(s, tok);
665 is_tuple = isl_stream_next_token_is(s, '[');
667 isl_stream_push_token(s, tok);
672 static __isl_give isl_basic_map *read_tuple(struct isl_stream *s,
673 __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v);
675 static __isl_give isl_basic_map *read_nested_tuple(struct isl_stream *s,
676 __isl_take isl_basic_map *bmap, struct vars *v)
678 bmap = read_tuple(s, bmap, isl_dim_in, v);
679 if (isl_stream_eat(s, ISL_TOKEN_TO))
681 bmap = read_tuple(s, bmap, isl_dim_out, v);
682 bmap = isl_basic_map_from_range(isl_basic_map_wrap(bmap));
685 isl_basic_map_free(bmap);
689 static __isl_give isl_basic_map *read_tuple(struct isl_stream *s,
690 __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
692 struct isl_token *tok;
695 tok = isl_stream_next_token(s);
696 if (tok && tok->type == ISL_TOKEN_IDENT) {
697 name = strdup(tok->u.s);
701 tok = isl_stream_next_token(s);
703 if (!tok || tok->type != '[') {
704 isl_stream_error(s, tok, "expecting '['");
708 if (type != isl_dim_param && next_is_tuple(s)) {
709 isl_dim *dim = isl_basic_map_get_dim(bmap);
710 int nparam = isl_dim_size(dim, isl_dim_param);
711 int n_in = isl_dim_size(dim, isl_dim_in);
712 isl_basic_map *nested;
713 if (type == isl_dim_out)
714 dim = isl_dim_move(dim, isl_dim_param, nparam,
715 isl_dim_in, 0, n_in);
716 nested = isl_basic_map_alloc_dim(dim, 0, 0, 0);
717 nested = read_nested_tuple(s, nested, v);
718 if (type == isl_dim_in) {
719 nested = isl_basic_map_reverse(nested);
720 bmap = isl_basic_map_intersect(nested, bmap);
723 dim = isl_dim_range(isl_basic_map_get_dim(nested));
724 dim = isl_dim_drop(dim, isl_dim_param, nparam, n_in);
725 dim = isl_dim_join(isl_basic_map_get_dim(bmap), dim);
726 bset = isl_basic_map_domain(bmap);
727 nested = isl_basic_map_reset_dim(nested, dim);
728 bmap = isl_basic_map_intersect_domain(nested, bset);
731 bmap = read_var_list(s, bmap, type, v);
732 tok = isl_stream_next_token(s);
733 if (!tok || tok->type != ']') {
734 isl_stream_error(s, tok, "expecting ']'");
740 bmap = isl_basic_map_set_tuple_name(bmap, type, name);
748 isl_basic_map_free(bmap);
752 static struct isl_basic_map *add_constraints(struct isl_stream *s,
753 struct vars *v, struct isl_basic_map *bmap);
755 static struct isl_basic_map *add_exists(struct isl_stream *s,
756 struct vars *v, struct isl_basic_map *bmap)
758 struct isl_token *tok;
765 tok = isl_stream_next_token(s);
768 if (tok->type == '(') {
772 isl_stream_push_token(s, tok);
774 bmap = read_defined_var_list(s, v, bmap);
778 if (isl_stream_eat(s, ':'))
780 bmap = add_constraints(s, v, bmap);
781 if (seen_paren && isl_stream_eat(s, ')'))
785 isl_basic_map_free(bmap);
789 static __isl_give isl_basic_map *construct_constraint(
790 __isl_take isl_basic_map *bmap, enum isl_token_type type,
791 isl_int *left, isl_int *right)
799 len = 1 + isl_basic_map_total_dim(bmap);
802 k = isl_basic_map_alloc_inequality(bmap);
805 if (type == ISL_TOKEN_LE)
806 isl_seq_combine(bmap->ineq[k], ctx->negone, left,
809 else if (type == ISL_TOKEN_GE)
810 isl_seq_combine(bmap->ineq[k], ctx->one, left,
813 else if (type == ISL_TOKEN_LT) {
814 isl_seq_combine(bmap->ineq[k], ctx->negone, left,
817 isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
818 } else if (type == ISL_TOKEN_GT) {
819 isl_seq_combine(bmap->ineq[k], ctx->one, left,
822 isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
824 isl_seq_combine(bmap->ineq[k], ctx->one, left,
827 isl_basic_map_inequality_to_equality(bmap, k);
832 isl_basic_map_free(bmap);
836 static int is_comparator(struct isl_token *tok)
853 static struct isl_basic_map *add_constraint(struct isl_stream *s,
854 struct vars *v, struct isl_basic_map *bmap)
857 struct isl_token *tok = NULL;
858 struct isl_mat *aff1 = NULL, *aff2 = NULL;
860 tok = isl_stream_next_token(s);
863 if (tok->type == ISL_TOKEN_EXISTS) {
865 return add_exists(s, v, bmap);
867 isl_stream_push_token(s, tok);
870 bmap = isl_basic_map_cow(bmap);
872 aff1 = accept_affine_list(s, v);
875 tok = isl_stream_next_token(s);
876 if (!is_comparator(tok)) {
877 isl_stream_error(s, tok, "missing operator");
879 isl_stream_push_token(s, tok);
884 aff2 = accept_affine_list(s, v);
888 aff1 = isl_mat_add_zero_cols(aff1, aff2->n_col - aff1->n_col);
891 bmap = add_divs(bmap, v);
892 bmap = isl_basic_map_extend_constraints(bmap, 0,
893 aff1->n_row * aff2->n_row);
894 for (i = 0; i < aff1->n_row; ++i)
895 for (j = 0; j < aff2->n_row; ++j)
896 bmap = construct_constraint(bmap, tok->type,
897 aff1->row[i], aff2->row[j]);
902 tok = isl_stream_next_token(s);
903 if (!is_comparator(tok)) {
905 isl_stream_push_token(s, tok);
917 isl_basic_map_free(bmap);
921 static struct isl_basic_map *add_constraints(struct isl_stream *s,
922 struct vars *v, struct isl_basic_map *bmap)
924 struct isl_token *tok;
927 bmap = add_constraint(s, v, bmap);
930 tok = isl_stream_next_token(s);
932 isl_stream_error(s, NULL, "unexpected EOF");
935 if (tok->type != ISL_TOKEN_AND)
939 isl_stream_push_token(s, tok);
945 isl_basic_map_free(bmap);
949 static struct isl_basic_map *read_disjunct(struct isl_stream *s,
950 struct vars *v, __isl_take isl_dim *dim)
953 struct isl_token *tok;
954 struct isl_basic_map *bmap;
956 bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
960 tok = isl_stream_next_token(s);
963 if (tok->type == '(') {
967 isl_stream_push_token(s, tok);
969 bmap = add_constraints(s, v, bmap);
970 bmap = isl_basic_map_simplify(bmap);
971 bmap = isl_basic_map_finalize(bmap);
973 if (seen_paren && isl_stream_eat(s, ')'))
978 isl_basic_map_free(bmap);
982 static struct isl_map *read_disjuncts(struct isl_stream *s,
983 struct vars *v, __isl_take isl_dim *dim)
985 struct isl_token *tok;
988 tok = isl_stream_next_token(s);
990 isl_stream_error(s, NULL, "unexpected EOF");
993 if (tok->type == '}') {
994 isl_stream_push_token(s, tok);
995 return isl_map_universe(dim);
997 isl_stream_push_token(s, tok);
999 map = isl_map_empty(isl_dim_copy(dim));
1001 struct isl_basic_map *bmap;
1004 bmap = read_disjunct(s, v, isl_dim_copy(dim));
1005 map = isl_map_union(map, isl_map_from_basic_map(bmap));
1007 vars_drop(v, v->n - n);
1009 tok = isl_stream_next_token(s);
1010 if (!tok || tok->type != ISL_TOKEN_OR)
1012 isl_token_free(tok);
1015 isl_stream_push_token(s, tok);
1024 static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map *bmap, int pos)
1026 if (pos < isl_basic_map_dim(bmap, isl_dim_out))
1027 return 1 + isl_basic_map_dim(bmap, isl_dim_param) +
1028 isl_basic_map_dim(bmap, isl_dim_in) + pos;
1029 pos -= isl_basic_map_dim(bmap, isl_dim_out);
1031 if (pos < isl_basic_map_dim(bmap, isl_dim_in))
1032 return 1 + isl_basic_map_dim(bmap, isl_dim_param) + pos;
1033 pos -= isl_basic_map_dim(bmap, isl_dim_in);
1035 if (pos < isl_basic_map_dim(bmap, isl_dim_div))
1036 return 1 + isl_basic_map_dim(bmap, isl_dim_param) +
1037 isl_basic_map_dim(bmap, isl_dim_in) +
1038 isl_basic_map_dim(bmap, isl_dim_out) + pos;
1039 pos -= isl_basic_map_dim(bmap, isl_dim_div);
1041 if (pos < isl_basic_map_dim(bmap, isl_dim_param))
1047 static __isl_give isl_basic_map *basic_map_read_polylib_constraint(
1048 struct isl_stream *s, __isl_take isl_basic_map *bmap)
1051 struct isl_token *tok;
1061 nparam = isl_basic_map_dim(bmap, isl_dim_param);
1062 dim = isl_basic_map_dim(bmap, isl_dim_out);
1064 tok = isl_stream_next_token(s);
1065 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1066 isl_stream_error(s, tok, "expecting coefficient");
1068 isl_stream_push_token(s, tok);
1071 if (!tok->on_new_line) {
1072 isl_stream_error(s, tok, "coefficient should appear on new line");
1073 isl_stream_push_token(s, tok);
1077 type = isl_int_get_si(tok->u.v);
1078 isl_token_free(tok);
1080 isl_assert(s->ctx, type == 0 || type == 1, goto error);
1082 k = isl_basic_map_alloc_equality(bmap);
1085 k = isl_basic_map_alloc_inequality(bmap);
1091 for (j = 0; j < 1 + isl_basic_map_total_dim(bmap); ++j) {
1093 tok = isl_stream_next_token(s);
1094 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1095 isl_stream_error(s, tok, "expecting coefficient");
1097 isl_stream_push_token(s, tok);
1100 if (tok->on_new_line) {
1101 isl_stream_error(s, tok,
1102 "coefficient should not appear on new line");
1103 isl_stream_push_token(s, tok);
1106 pos = polylib_pos_to_isl_pos(bmap, j);
1107 isl_int_set(c[pos], tok->u.v);
1108 isl_token_free(tok);
1113 isl_basic_map_free(bmap);
1117 static __isl_give isl_basic_map *basic_map_read_polylib(struct isl_stream *s,
1121 struct isl_token *tok;
1122 struct isl_token *tok2;
1125 unsigned in = 0, out, local = 0;
1126 struct isl_basic_map *bmap = NULL;
1131 tok = isl_stream_next_token(s);
1133 isl_stream_error(s, NULL, "unexpected EOF");
1136 tok2 = isl_stream_next_token(s);
1138 isl_token_free(tok);
1139 isl_stream_error(s, NULL, "unexpected EOF");
1142 n_row = isl_int_get_si(tok->u.v);
1143 n_col = isl_int_get_si(tok2->u.v);
1144 on_new_line = tok2->on_new_line;
1145 isl_token_free(tok2);
1146 isl_token_free(tok);
1147 isl_assert(s->ctx, !on_new_line, return NULL);
1148 isl_assert(s->ctx, n_row >= 0, return NULL);
1149 isl_assert(s->ctx, n_col >= 2 + nparam, return NULL);
1150 tok = isl_stream_next_token_on_same_line(s);
1152 if (tok->type != ISL_TOKEN_VALUE) {
1153 isl_stream_error(s, tok,
1154 "expecting number of output dimensions");
1155 isl_stream_push_token(s, tok);
1158 out = isl_int_get_si(tok->u.v);
1159 isl_token_free(tok);
1161 tok = isl_stream_next_token_on_same_line(s);
1162 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1163 isl_stream_error(s, tok,
1164 "expecting number of input dimensions");
1166 isl_stream_push_token(s, tok);
1169 in = isl_int_get_si(tok->u.v);
1170 isl_token_free(tok);
1172 tok = isl_stream_next_token_on_same_line(s);
1173 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1174 isl_stream_error(s, tok,
1175 "expecting number of existentials");
1177 isl_stream_push_token(s, tok);
1180 local = isl_int_get_si(tok->u.v);
1181 isl_token_free(tok);
1183 tok = isl_stream_next_token_on_same_line(s);
1184 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1185 isl_stream_error(s, tok,
1186 "expecting number of parameters");
1188 isl_stream_push_token(s, tok);
1191 nparam = isl_int_get_si(tok->u.v);
1192 isl_token_free(tok);
1193 if (n_col != 1 + out + in + local + nparam + 1) {
1194 isl_stream_error(s, NULL,
1195 "dimensions don't match");
1199 out = n_col - 2 - nparam;
1200 bmap = isl_basic_map_alloc(s->ctx, nparam, in, out, local, n_row, n_row);
1204 for (i = 0; i < local; ++i) {
1205 int k = isl_basic_map_alloc_div(bmap);
1208 isl_seq_clr(bmap->div[k], 1 + 1 + nparam + in + out + local);
1211 for (i = 0; i < n_row; ++i)
1212 bmap = basic_map_read_polylib_constraint(s, bmap);
1214 tok = isl_stream_next_token_on_same_line(s);
1216 isl_stream_error(s, tok, "unexpected extra token on line");
1217 isl_stream_push_token(s, tok);
1221 bmap = isl_basic_map_simplify(bmap);
1222 bmap = isl_basic_map_finalize(bmap);
1225 isl_basic_map_free(bmap);
1229 static struct isl_map *map_read_polylib(struct isl_stream *s, int nparam)
1231 struct isl_token *tok;
1232 struct isl_token *tok2;
1234 struct isl_map *map;
1236 tok = isl_stream_next_token(s);
1238 isl_stream_error(s, NULL, "unexpected EOF");
1241 tok2 = isl_stream_next_token_on_same_line(s);
1243 isl_stream_push_token(s, tok2);
1244 isl_stream_push_token(s, tok);
1245 return isl_map_from_basic_map(basic_map_read_polylib(s, nparam));
1247 n = isl_int_get_si(tok->u.v);
1248 isl_token_free(tok);
1250 isl_assert(s->ctx, n >= 1, return NULL);
1252 map = isl_map_from_basic_map(basic_map_read_polylib(s, nparam));
1254 for (i = 1; i < n; ++i)
1255 map = isl_map_union(map,
1256 isl_map_from_basic_map(basic_map_read_polylib(s, nparam)));
1261 static int optional_power(struct isl_stream *s)
1264 struct isl_token *tok;
1266 tok = isl_stream_next_token(s);
1269 if (tok->type != '^') {
1270 isl_stream_push_token(s, tok);
1273 isl_token_free(tok);
1274 tok = isl_stream_next_token(s);
1275 if (!tok || tok->type != ISL_TOKEN_VALUE) {
1276 isl_stream_error(s, tok, "expecting exponent");
1278 isl_stream_push_token(s, tok);
1281 pow = isl_int_get_si(tok->u.v);
1282 isl_token_free(tok);
1286 static __isl_give isl_div *read_div(struct isl_stream *s,
1287 __isl_keep isl_basic_map *bmap, struct vars *v)
1289 unsigned total = isl_basic_map_total_dim(bmap);
1292 bmap = isl_basic_map_copy(bmap);
1293 bmap = isl_basic_map_cow(bmap);
1294 bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
1297 if ((k = isl_basic_map_alloc_div(bmap)) < 0)
1299 isl_seq_clr(bmap->div[k], 1 + 1 + total);
1301 if (vars_add_anon(v) < 0)
1303 bmap = add_div_definition(s, v, bmap, k);
1306 return isl_basic_map_div(bmap, k);
1308 isl_basic_map_free(bmap);
1312 static __isl_give isl_qpolynomial *read_term(struct isl_stream *s,
1313 __isl_keep isl_basic_map *bmap, struct vars *v);
1315 static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
1316 __isl_keep isl_basic_map *bmap, struct vars *v)
1318 struct isl_qpolynomial *qp;
1319 struct isl_token *tok;
1321 tok = isl_stream_next_token(s);
1323 isl_stream_error(s, NULL, "unexpected EOF");
1326 if (tok->type == '(') {
1327 isl_token_free(tok);
1328 qp = read_term(s, bmap, v);
1331 if (isl_stream_eat(s, ')'))
1333 } else if (tok->type == ISL_TOKEN_VALUE) {
1334 struct isl_token *tok2;
1335 tok2 = isl_stream_next_token(s);
1336 if (tok2 && tok2->type == '/') {
1337 isl_token_free(tok2);
1338 tok2 = isl_stream_next_token(s);
1339 if (!tok2 || tok2->type != ISL_TOKEN_VALUE) {
1340 isl_stream_error(s, tok2, "expected denominator");
1341 isl_token_free(tok);
1342 isl_token_free(tok2);
1345 qp = isl_qpolynomial_rat_cst(isl_basic_map_get_dim(bmap),
1346 tok->u.v, tok2->u.v);
1347 isl_token_free(tok2);
1349 isl_stream_push_token(s, tok2);
1350 qp = isl_qpolynomial_cst(isl_basic_map_get_dim(bmap),
1353 isl_token_free(tok);
1354 } else if (tok->type == ISL_TOKEN_INFTY) {
1355 isl_token_free(tok);
1356 qp = isl_qpolynomial_infty(isl_basic_map_get_dim(bmap));
1357 } else if (tok->type == ISL_TOKEN_NAN) {
1358 isl_token_free(tok);
1359 qp = isl_qpolynomial_nan(isl_basic_map_get_dim(bmap));
1360 } else if (tok->type == ISL_TOKEN_IDENT) {
1362 int pos = vars_pos(v, tok->u.s, -1);
1365 isl_token_free(tok);
1369 isl_stream_error(s, tok, "unknown identifier");
1370 isl_token_free(tok);
1373 isl_token_free(tok);
1374 pow = optional_power(s);
1375 qp = isl_qpolynomial_pow(isl_basic_map_get_dim(bmap), pos, pow);
1376 } else if (tok->type == '[') {
1380 isl_stream_push_token(s, tok);
1381 div = read_div(s, bmap, v);
1382 pow = optional_power(s);
1383 qp = isl_qpolynomial_div_pow(div, pow);
1384 } else if (tok->type == '-') {
1385 struct isl_qpolynomial *qp2;
1387 isl_token_free(tok);
1388 qp = isl_qpolynomial_cst(isl_basic_map_get_dim(bmap),
1390 qp2 = read_factor(s, bmap, v);
1391 qp = isl_qpolynomial_mul(qp, qp2);
1393 isl_stream_error(s, tok, "unexpected isl_token");
1394 isl_stream_push_token(s, tok);
1398 if (isl_stream_eat_if_available(s, '*') ||
1399 isl_stream_next_token_is(s, ISL_TOKEN_IDENT)) {
1400 struct isl_qpolynomial *qp2;
1402 qp2 = read_factor(s, bmap, v);
1403 qp = isl_qpolynomial_mul(qp, qp2);
1408 isl_qpolynomial_free(qp);
1412 static __isl_give isl_qpolynomial *read_term(struct isl_stream *s,
1413 __isl_keep isl_basic_map *bmap, struct vars *v)
1415 struct isl_token *tok;
1416 struct isl_qpolynomial *qp;
1418 qp = read_factor(s, bmap, v);
1421 tok = isl_stream_next_token(s);
1425 if (tok->type == '+') {
1426 struct isl_qpolynomial *qp2;
1428 isl_token_free(tok);
1429 qp2 = read_factor(s, bmap, v);
1430 qp = isl_qpolynomial_add(qp, qp2);
1431 } else if (tok->type == '-') {
1432 struct isl_qpolynomial *qp2;
1434 isl_token_free(tok);
1435 qp2 = read_factor(s, bmap, v);
1436 qp = isl_qpolynomial_sub(qp, qp2);
1437 } else if (tok->type == ISL_TOKEN_VALUE &&
1438 isl_int_is_neg(tok->u.v)) {
1439 struct isl_qpolynomial *qp2;
1441 isl_stream_push_token(s, tok);
1442 qp2 = read_factor(s, bmap, v);
1443 qp = isl_qpolynomial_add(qp, qp2);
1445 isl_stream_push_token(s, tok);
1453 static __isl_give isl_map *read_optional_disjuncts(struct isl_stream *s,
1454 __isl_take isl_basic_map *bmap, struct vars *v)
1456 struct isl_token *tok;
1457 struct isl_map *map;
1459 tok = isl_stream_next_token(s);
1461 isl_stream_error(s, NULL, "unexpected EOF");
1464 map = isl_map_from_basic_map(isl_basic_map_copy(bmap));
1465 if (tok->type == ':') {
1466 isl_token_free(tok);
1467 map = isl_map_intersect(map,
1468 read_disjuncts(s, v, isl_basic_map_get_dim(bmap)));
1470 isl_stream_push_token(s, tok);
1472 isl_basic_map_free(bmap);
1476 isl_basic_map_free(bmap);
1480 static struct isl_obj obj_read_poly(struct isl_stream *s,
1481 __isl_take isl_basic_map *bmap, struct vars *v, int n)
1483 struct isl_obj obj = { isl_obj_pw_qpolynomial, NULL };
1484 struct isl_pw_qpolynomial *pwqp;
1485 struct isl_qpolynomial *qp;
1486 struct isl_map *map;
1487 struct isl_set *set;
1489 qp = read_term(s, bmap, v);
1490 map = read_optional_disjuncts(s, bmap, v);
1491 set = isl_map_range(map);
1493 pwqp = isl_pw_qpolynomial_alloc(set, qp);
1495 vars_drop(v, v->n - n);
1501 static struct isl_obj obj_read_poly_or_fold(struct isl_stream *s,
1502 __isl_take isl_basic_map *bmap, struct vars *v, int n)
1504 struct isl_obj obj = { isl_obj_pw_qpolynomial_fold, NULL };
1505 struct isl_obj obj_p;
1506 isl_qpolynomial *qp;
1507 isl_qpolynomial_fold *fold = NULL;
1508 isl_pw_qpolynomial_fold *pwf;
1512 if (!isl_stream_eat_if_available(s, ISL_TOKEN_MAX))
1513 return obj_read_poly(s, bmap, v, n);
1515 if (isl_stream_eat(s, '('))
1518 qp = read_term(s, bmap, v);
1519 fold = isl_qpolynomial_fold_alloc(isl_fold_max, qp);
1521 while (isl_stream_eat_if_available(s, ',')) {
1522 isl_qpolynomial_fold *fold_i;
1523 qp = read_term(s, bmap, v);
1524 fold_i = isl_qpolynomial_fold_alloc(isl_fold_max, qp);
1525 fold = isl_qpolynomial_fold_fold(fold, fold_i);
1528 if (isl_stream_eat(s, ')'))
1531 map = read_optional_disjuncts(s, bmap, v);
1532 set = isl_map_range(map);
1533 pwf = isl_pw_qpolynomial_fold_alloc(isl_fold_max, set, fold);
1535 vars_drop(v, v->n - n);
1540 isl_basic_map_free(bmap);
1541 isl_qpolynomial_fold_free(fold);
1542 obj.type = isl_obj_none;
1546 static struct isl_obj obj_read_body(struct isl_stream *s,
1547 __isl_take isl_basic_map *bmap, struct vars *v)
1549 struct isl_map *map = NULL;
1550 struct isl_token *tok;
1551 struct isl_obj obj = { isl_obj_set, NULL };
1554 if (!next_is_tuple(s))
1555 return obj_read_poly_or_fold(s, bmap, v, n);
1557 bmap = read_tuple(s, bmap, isl_dim_in, v);
1560 tok = isl_stream_next_token(s);
1561 if (tok && tok->type == ISL_TOKEN_TO) {
1562 obj.type = isl_obj_map;
1563 isl_token_free(tok);
1564 if (!next_is_tuple(s)) {
1565 bmap = isl_basic_map_reverse(bmap);
1566 return obj_read_poly_or_fold(s, bmap, v, n);
1568 bmap = read_tuple(s, bmap, isl_dim_out, v);
1572 bmap = isl_basic_map_reverse(bmap);
1574 isl_stream_push_token(s, tok);
1577 map = read_optional_disjuncts(s, bmap, v);
1579 vars_drop(v, v->n - n);
1584 isl_basic_map_free(bmap);
1585 obj.type = isl_obj_none;
1589 static struct isl_obj to_union(isl_ctx *ctx, struct isl_obj obj)
1591 if (obj.type == isl_obj_map) {
1592 obj.v = isl_union_map_from_map(obj.v);
1593 obj.type = isl_obj_union_map;
1594 } else if (obj.type == isl_obj_set) {
1595 obj.v = isl_union_set_from_set(obj.v);
1596 obj.type = isl_obj_union_set;
1597 } else if (obj.type == isl_obj_pw_qpolynomial) {
1598 obj.v = isl_union_pw_qpolynomial_from_pw_qpolynomial(obj.v);
1599 obj.type = isl_obj_union_pw_qpolynomial;
1600 } else if (obj.type == isl_obj_pw_qpolynomial_fold) {
1601 obj.v = isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(obj.v);
1602 obj.type = isl_obj_union_pw_qpolynomial_fold;
1604 isl_assert(ctx, 0, goto error);
1607 obj.type->free(obj.v);
1608 obj.type = isl_obj_none;
1612 static struct isl_obj obj_add(struct isl_ctx *ctx,
1613 struct isl_obj obj1, struct isl_obj obj2)
1615 if (obj1.type == isl_obj_set && obj2.type == isl_obj_union_set)
1616 obj1 = to_union(ctx, obj1);
1617 if (obj1.type == isl_obj_union_set && obj2.type == isl_obj_set)
1618 obj2 = to_union(ctx, obj2);
1619 if (obj1.type == isl_obj_map && obj2.type == isl_obj_union_map)
1620 obj1 = to_union(ctx, obj1);
1621 if (obj1.type == isl_obj_union_map && obj2.type == isl_obj_map)
1622 obj2 = to_union(ctx, obj2);
1623 if (obj1.type == isl_obj_pw_qpolynomial &&
1624 obj2.type == isl_obj_union_pw_qpolynomial)
1625 obj1 = to_union(ctx, obj1);
1626 if (obj1.type == isl_obj_union_pw_qpolynomial &&
1627 obj2.type == isl_obj_pw_qpolynomial)
1628 obj2 = to_union(ctx, obj2);
1629 if (obj1.type == isl_obj_pw_qpolynomial_fold &&
1630 obj2.type == isl_obj_union_pw_qpolynomial_fold)
1631 obj1 = to_union(ctx, obj1);
1632 if (obj1.type == isl_obj_union_pw_qpolynomial_fold &&
1633 obj2.type == isl_obj_pw_qpolynomial_fold)
1634 obj2 = to_union(ctx, obj2);
1635 isl_assert(ctx, obj1.type == obj2.type, goto error);
1636 if (obj1.type == isl_obj_map && !isl_map_has_equal_dim(obj1.v, obj2.v)) {
1637 obj1 = to_union(ctx, obj1);
1638 obj2 = to_union(ctx, obj2);
1640 if (obj1.type == isl_obj_set && !isl_set_has_equal_dim(obj1.v, obj2.v)) {
1641 obj1 = to_union(ctx, obj1);
1642 obj2 = to_union(ctx, obj2);
1644 if (obj1.type == isl_obj_pw_qpolynomial &&
1645 !isl_pw_qpolynomial_has_equal_dim(obj1.v, obj2.v)) {
1646 obj1 = to_union(ctx, obj1);
1647 obj2 = to_union(ctx, obj2);
1649 if (obj1.type == isl_obj_pw_qpolynomial_fold &&
1650 !isl_pw_qpolynomial_fold_has_equal_dim(obj1.v, obj2.v)) {
1651 obj1 = to_union(ctx, obj1);
1652 obj2 = to_union(ctx, obj2);
1654 obj1.v = obj1.type->add(obj1.v, obj2.v);
1657 obj1.type->free(obj1.v);
1658 obj2.type->free(obj2.v);
1659 obj1.type = isl_obj_none;
1664 static struct isl_obj obj_read(struct isl_stream *s, int nparam)
1666 isl_basic_map *bmap = NULL;
1667 struct isl_token *tok;
1668 struct vars *v = NULL;
1669 struct isl_obj obj = { isl_obj_set, NULL };
1671 tok = isl_stream_next_token(s);
1673 isl_stream_error(s, NULL, "unexpected EOF");
1676 if (tok->type == ISL_TOKEN_VALUE) {
1677 struct isl_map *map;
1678 isl_stream_push_token(s, tok);
1679 map = map_read_polylib(s, nparam);
1682 if (isl_map_dim(map, isl_dim_in) > 0)
1683 obj.type = isl_obj_map;
1687 v = vars_new(s->ctx);
1689 isl_stream_push_token(s, tok);
1692 bmap = isl_basic_map_alloc(s->ctx, 0, 0, 0, 0, 0, 0);
1693 if (tok->type == '[') {
1694 isl_stream_push_token(s, tok);
1695 bmap = read_tuple(s, bmap, isl_dim_param, v);
1699 isl_assert(s->ctx, nparam == v->n, goto error);
1700 tok = isl_stream_next_token(s);
1701 if (!tok || tok->type != ISL_TOKEN_TO) {
1702 isl_stream_error(s, tok, "expecting '->'");
1704 isl_stream_push_token(s, tok);
1707 isl_token_free(tok);
1708 tok = isl_stream_next_token(s);
1709 } else if (nparam > 0)
1710 bmap = isl_basic_map_add(bmap, isl_dim_param, nparam);
1711 if (!tok || tok->type != '{') {
1712 isl_stream_error(s, tok, "expecting '{'");
1714 isl_stream_push_token(s, tok);
1717 isl_token_free(tok);
1719 tok = isl_stream_next_token(s);
1722 else if (tok->type == ISL_TOKEN_IDENT && !strcmp(tok->u.s, "Sym")) {
1723 isl_token_free(tok);
1724 if (isl_stream_eat(s, '='))
1726 bmap = read_tuple(s, bmap, isl_dim_param, v);
1730 isl_assert(s->ctx, nparam == v->n, goto error);
1731 } else if (tok->type == '}') {
1732 obj.type = isl_obj_union_set;
1733 obj.v = isl_union_set_empty(isl_basic_map_get_dim(bmap));
1734 isl_token_free(tok);
1737 isl_stream_push_token(s, tok);
1742 o = obj_read_body(s, isl_basic_map_copy(bmap), v);
1743 if (o.type == isl_obj_none || !o.v)
1748 obj = obj_add(s->ctx, obj, o);
1749 if (obj.type == isl_obj_none || !obj.v)
1752 tok = isl_stream_next_token(s);
1753 if (!tok || tok->type != ';')
1755 isl_token_free(tok);
1758 if (tok && tok->type == '}') {
1759 isl_token_free(tok);
1761 isl_stream_error(s, tok, "unexpected isl_token");
1763 isl_token_free(tok);
1768 isl_basic_map_free(bmap);
1772 isl_basic_map_free(bmap);
1773 obj.type->free(obj.v);
1780 struct isl_obj isl_stream_read_obj(struct isl_stream *s)
1782 return obj_read(s, -1);
1785 __isl_give isl_map *isl_stream_read_map(struct isl_stream *s, int nparam)
1788 struct isl_map *map;
1790 obj = obj_read(s, nparam);
1792 isl_assert(s->ctx, obj.type == isl_obj_map ||
1793 obj.type == isl_obj_set, goto error);
1797 obj.type->free(obj.v);
1801 __isl_give isl_set *isl_stream_read_set(struct isl_stream *s, int nparam)
1804 struct isl_set *set;
1806 obj = obj_read(s, nparam);
1808 isl_assert(s->ctx, obj.type == isl_obj_set, goto error);
1812 obj.type->free(obj.v);
1816 static struct isl_basic_map *basic_map_read(struct isl_stream *s, int nparam)
1819 struct isl_map *map;
1820 struct isl_basic_map *bmap;
1822 obj = obj_read(s, nparam);
1827 isl_assert(map->ctx, map->n <= 1, goto error);
1830 bmap = isl_basic_map_empty_like_map(map);
1832 bmap = isl_basic_map_copy(map->p[0]);
1842 __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
1843 FILE *input, int nparam)
1845 struct isl_basic_map *bmap;
1846 struct isl_stream *s = isl_stream_new_file(ctx, input);
1849 bmap = basic_map_read(s, nparam);
1854 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
1855 FILE *input, int nparam)
1857 struct isl_basic_map *bmap;
1858 bmap = isl_basic_map_read_from_file(ctx, input, nparam);
1861 isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
1862 return (struct isl_basic_set *)bmap;
1864 isl_basic_map_free(bmap);
1868 struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
1869 const char *str, int nparam)
1871 struct isl_basic_map *bmap;
1872 struct isl_stream *s = isl_stream_new_str(ctx, str);
1875 bmap = basic_map_read(s, nparam);
1880 struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
1881 const char *str, int nparam)
1883 struct isl_basic_map *bmap;
1884 bmap = isl_basic_map_read_from_str(ctx, str, nparam);
1887 isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
1888 return (struct isl_basic_set *)bmap;
1890 isl_basic_map_free(bmap);
1894 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
1895 FILE *input, int nparam)
1897 struct isl_map *map;
1898 struct isl_stream *s = isl_stream_new_file(ctx, input);
1901 map = isl_stream_read_map(s, nparam);
1906 __isl_give isl_map *isl_map_read_from_str(struct isl_ctx *ctx,
1907 const char *str, int nparam)
1909 struct isl_map *map;
1910 struct isl_stream *s = isl_stream_new_str(ctx, str);
1913 map = isl_stream_read_map(s, nparam);
1918 __isl_give isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
1919 FILE *input, int nparam)
1921 struct isl_map *map;
1922 map = isl_map_read_from_file(ctx, input, nparam);
1925 isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
1926 return (struct isl_set *)map;
1932 struct isl_set *isl_set_read_from_str(struct isl_ctx *ctx,
1933 const char *str, int nparam)
1935 struct isl_map *map;
1936 map = isl_map_read_from_str(ctx, str, nparam);
1939 isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
1940 return (struct isl_set *)map;
1946 static char *next_line(FILE *input, char *line, unsigned len)
1951 if (!(p = fgets(line, len, input)))
1953 while (isspace(*p) && *p != '\n')
1955 } while (*p == '#' || *p == '\n');
1960 static struct isl_vec *isl_vec_read_from_file_polylib(struct isl_ctx *ctx,
1963 struct isl_vec *vec = NULL;
1972 isl_assert(ctx, next_line(input, line, sizeof(line)), return NULL);
1973 isl_assert(ctx, sscanf(line, "%u", &size) == 1, return NULL);
1975 vec = isl_vec_alloc(ctx, size);
1977 p = next_line(input, line, sizeof(line));
1978 isl_assert(ctx, p, goto error);
1980 for (j = 0; j < size; ++j) {
1981 n = sscanf(p, "%s%n", val, &offset);
1982 isl_assert(ctx, n != 0, goto error);
1983 isl_int_read(vec->el[j], val);
1993 struct isl_vec *isl_vec_read_from_file(struct isl_ctx *ctx,
1994 FILE *input, unsigned input_format)
1996 if (input_format == ISL_FORMAT_POLYLIB)
1997 return isl_vec_read_from_file_polylib(ctx, input);
1999 isl_assert(ctx, 0, return NULL);
2002 __isl_give isl_pw_qpolynomial *isl_stream_read_pw_qpolynomial(
2003 struct isl_stream *s)
2006 struct isl_pw_qpolynomial *pwqp;
2008 obj = obj_read(s, -1);
2010 isl_assert(s->ctx, obj.type == isl_obj_pw_qpolynomial,
2015 obj.type->free(obj.v);
2019 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_read_from_str(isl_ctx *ctx,
2022 isl_pw_qpolynomial *pwqp;
2023 struct isl_stream *s = isl_stream_new_str(ctx, str);
2026 pwqp = isl_stream_read_pw_qpolynomial(s);