2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the MIT 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
16 #include <isl_ctx_private.h>
17 #include <isl_map_private.h>
20 #include <isl_stream_private.h>
22 #include "isl_polynomial_private.h"
23 #include <isl/union_map.h>
24 #include <isl_mat_private.h>
25 #include <isl_aff_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
;
62 static void vars_free(struct vars
*v
)
70 static void vars_drop(struct vars
*v
, int n
)
81 struct variable
*next
= var
->next
;
89 static struct variable
*variable_new(struct vars
*v
, const char *name
, int len
,
93 var
= isl_calloc_type(v
->ctx
, struct variable
);
96 var
->name
= strdup(name
);
97 var
->name
[len
] = '\0';
106 static int vars_pos(struct vars
*v
, const char *s
, int len
)
113 for (q
= v
->v
; q
; q
= q
->next
) {
114 if (strncmp(q
->name
, s
, len
) == 0 && q
->name
[len
] == '\0')
121 v
->v
= variable_new(v
, s
, len
, v
->n
);
129 static int vars_add_anon(struct vars
*v
)
131 v
->v
= variable_new(v
, "", 0, v
->n
);
140 static __isl_give isl_map
*set_name(__isl_take isl_map
*map
,
141 enum isl_dim_type type
, unsigned pos
, char *name
)
150 prime
= strchr(name
, '\'');
153 map
= isl_map_set_dim_name(map
, type
, pos
, name
);
160 /* Obtain next token, with some preprocessing.
161 * In particular, evaluate expressions of the form x^y,
162 * with x and y values.
164 static struct isl_token
*next_token(struct isl_stream
*s
)
166 struct isl_token
*tok
, *tok2
;
168 tok
= isl_stream_next_token(s
);
169 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
)
171 if (!isl_stream_eat_if_available(s
, '^'))
173 tok2
= isl_stream_next_token(s
);
174 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
175 isl_stream_error(s
, tok2
, "expecting constant value");
179 isl_int_pow_ui(tok
->u
.v
, tok
->u
.v
, isl_int_get_ui(tok2
->u
.v
));
181 isl_token_free(tok2
);
185 isl_token_free(tok2
);
189 static int accept_cst_factor(struct isl_stream
*s
, isl_int
*f
)
191 struct isl_token
*tok
;
194 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
195 isl_stream_error(s
, tok
, "expecting constant value");
199 isl_int_mul(*f
, *f
, tok
->u
.v
);
203 if (isl_stream_eat_if_available(s
, '*'))
204 return accept_cst_factor(s
, f
);
212 /* Given an affine expression aff, return an affine expression
213 * for aff % d, with d the next token on the stream, which is
214 * assumed to be a constant.
216 * We introduce an integer division q = [aff/d] and the result
217 * is set to aff - d q.
219 static __isl_give isl_pw_aff
*affine_mod(struct isl_stream
*s
,
220 struct vars
*v
, __isl_take isl_pw_aff
*aff
)
222 struct isl_token
*tok
;
226 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
227 isl_stream_error(s
, tok
, "expecting constant value");
231 q
= isl_pw_aff_copy(aff
);
232 q
= isl_pw_aff_scale_down(q
, tok
->u
.v
);
233 q
= isl_pw_aff_floor(q
);
234 q
= isl_pw_aff_scale(q
, tok
->u
.v
);
236 aff
= isl_pw_aff_sub(aff
, q
);
241 isl_pw_aff_free(aff
);
246 static __isl_give isl_pw_aff
*accept_affine(struct isl_stream
*s
,
247 __isl_take isl_space
*dim
, struct vars
*v
);
248 static __isl_give isl_pw_aff_list
*accept_affine_list(struct isl_stream
*s
,
249 __isl_take isl_space
*dim
, struct vars
*v
);
251 static __isl_give isl_pw_aff
*accept_minmax(struct isl_stream
*s
,
252 __isl_take isl_space
*dim
, struct vars
*v
)
254 struct isl_token
*tok
;
255 isl_pw_aff_list
*list
= NULL
;
258 tok
= isl_stream_next_token(s
);
261 min
= tok
->type
== ISL_TOKEN_MIN
;
264 if (isl_stream_eat(s
, '('))
267 list
= accept_affine_list(s
, isl_space_copy(dim
), v
);
271 if (isl_stream_eat(s
, ')'))
275 return min
? isl_pw_aff_list_min(list
) : isl_pw_aff_list_max(list
);
278 isl_pw_aff_list_free(list
);
282 static __isl_give isl_pw_aff
*accept_div(struct isl_stream
*s
,
283 __isl_take isl_space
*dim
, struct vars
*v
)
285 struct isl_token
*tok
;
288 isl_pw_aff
*pwaff
= NULL
;
290 if (isl_stream_eat_if_available(s
, ISL_TOKEN_FLOORD
))
292 else if (isl_stream_eat_if_available(s
, ISL_TOKEN_CEILD
))
295 if (isl_stream_eat(s
, '('))
298 if (isl_stream_eat(s
, '['))
302 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
305 if (isl_stream_eat(s
, ','))
311 if (tok
->type
!= ISL_TOKEN_VALUE
) {
312 isl_stream_error(s
, tok
, "expected denominator");
313 isl_stream_push_token(s
, tok
);
316 isl_pw_aff_scale_down(pwaff
, tok
->u
.v
);
321 pwaff
= isl_pw_aff_ceil(pwaff
);
323 pwaff
= isl_pw_aff_floor(pwaff
);
326 if (isl_stream_eat(s
, ')'))
329 if (isl_stream_eat(s
, ']'))
337 isl_pw_aff_free(pwaff
);
341 static __isl_give isl_pw_aff
*accept_affine_factor(struct isl_stream
*s
,
342 __isl_take isl_space
*dim
, struct vars
*v
)
344 struct isl_token
*tok
= NULL
;
345 isl_pw_aff
*res
= NULL
;
349 isl_stream_error(s
, NULL
, "unexpected EOF");
353 if (tok
->type
== ISL_TOKEN_AFF
) {
354 res
= isl_pw_aff_copy(tok
->u
.pwaff
);
356 } else if (tok
->type
== ISL_TOKEN_IDENT
) {
358 int pos
= vars_pos(v
, tok
->u
.s
, -1);
364 isl_stream_error(s
, tok
, "unknown identifier");
368 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(isl_space_copy(dim
)));
371 isl_int_set_si(aff
->v
->el
[2 + pos
], 1);
372 res
= isl_pw_aff_from_aff(aff
);
374 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
375 if (isl_stream_eat_if_available(s
, '*')) {
376 res
= accept_affine_factor(s
, isl_space_copy(dim
), v
);
377 res
= isl_pw_aff_scale(res
, tok
->u
.v
);
381 ls
= isl_local_space_from_space(isl_space_copy(dim
));
382 aff
= isl_aff_zero_on_domain(ls
);
383 aff
= isl_aff_add_constant(aff
, tok
->u
.v
);
384 res
= isl_pw_aff_from_aff(aff
);
387 } else if (tok
->type
== '(') {
390 res
= accept_affine(s
, isl_space_copy(dim
), v
);
393 if (isl_stream_eat(s
, ')'))
395 } else if (tok
->type
== '[' ||
396 tok
->type
== ISL_TOKEN_FLOORD
||
397 tok
->type
== ISL_TOKEN_CEILD
) {
398 isl_stream_push_token(s
, tok
);
400 res
= accept_div(s
, isl_space_copy(dim
), v
);
401 } else if (tok
->type
== ISL_TOKEN_MIN
|| tok
->type
== ISL_TOKEN_MAX
) {
402 isl_stream_push_token(s
, tok
);
404 res
= accept_minmax(s
, isl_space_copy(dim
), v
);
406 isl_stream_error(s
, tok
, "expecting factor");
409 if (isl_stream_eat_if_available(s
, '%') ||
410 isl_stream_eat_if_available(s
, ISL_TOKEN_MOD
)) {
412 return affine_mod(s
, v
, res
);
414 if (isl_stream_eat_if_available(s
, '*')) {
417 isl_int_set_si(f
, 1);
418 if (accept_cst_factor(s
, &f
) < 0) {
422 res
= isl_pw_aff_scale(res
, f
);
425 if (isl_stream_eat_if_available(s
, '/')) {
428 isl_int_set_si(f
, 1);
429 if (accept_cst_factor(s
, &f
) < 0) {
433 res
= isl_pw_aff_scale_down(res
, f
);
442 isl_pw_aff_free(res
);
447 static __isl_give isl_pw_aff
*add_cst(__isl_take isl_pw_aff
*pwaff
, isl_int v
)
452 space
= isl_pw_aff_get_domain_space(pwaff
);
453 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(space
));
454 aff
= isl_aff_add_constant(aff
, v
);
456 return isl_pw_aff_add(pwaff
, isl_pw_aff_from_aff(aff
));
459 static __isl_give isl_pw_aff
*accept_affine(struct isl_stream
*s
,
460 __isl_take isl_space
*dim
, struct vars
*v
)
462 struct isl_token
*tok
= NULL
;
467 ls
= isl_local_space_from_space(isl_space_copy(dim
));
468 res
= isl_pw_aff_from_aff(isl_aff_zero_on_domain(ls
));
475 isl_stream_error(s
, NULL
, "unexpected EOF");
478 if (tok
->type
== '-') {
483 if (tok
->type
== '(' || tok
->type
== '[' ||
484 tok
->type
== ISL_TOKEN_MIN
|| tok
->type
== ISL_TOKEN_MAX
||
485 tok
->type
== ISL_TOKEN_FLOORD
||
486 tok
->type
== ISL_TOKEN_CEILD
||
487 tok
->type
== ISL_TOKEN_IDENT
||
488 tok
->type
== ISL_TOKEN_AFF
) {
490 isl_stream_push_token(s
, tok
);
492 term
= accept_affine_factor(s
, isl_space_copy(dim
), v
);
494 res
= isl_pw_aff_sub(res
, term
);
496 res
= isl_pw_aff_add(res
, term
);
500 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
502 isl_int_neg(tok
->u
.v
, tok
->u
.v
);
503 if (isl_stream_eat_if_available(s
, '*') ||
504 isl_stream_next_token_is(s
, ISL_TOKEN_IDENT
)) {
506 term
= accept_affine_factor(s
,
507 isl_space_copy(dim
), v
);
508 term
= isl_pw_aff_scale(term
, tok
->u
.v
);
509 res
= isl_pw_aff_add(res
, term
);
513 res
= add_cst(res
, tok
->u
.v
);
517 isl_stream_error(s
, tok
, "unexpected isl_token");
518 isl_stream_push_token(s
, tok
);
519 isl_pw_aff_free(res
);
526 if (tok
&& tok
->type
== '-') {
529 } else if (tok
&& tok
->type
== '+') {
532 } else if (tok
&& tok
->type
== ISL_TOKEN_VALUE
&&
533 isl_int_is_neg(tok
->u
.v
)) {
534 isl_stream_push_token(s
, tok
);
537 isl_stream_push_token(s
, tok
);
547 isl_pw_aff_free(res
);
551 static int is_comparator(struct isl_token
*tok
)
569 static struct isl_map
*read_disjuncts(struct isl_stream
*s
,
570 struct vars
*v
, __isl_take isl_map
*map
);
571 static __isl_give isl_pw_aff
*accept_extended_affine(struct isl_stream
*s
,
572 __isl_take isl_space
*dim
, struct vars
*v
);
574 /* Accept a ternary operator, given the first argument.
576 static __isl_give isl_pw_aff
*accept_ternary(struct isl_stream
*s
,
577 __isl_take isl_map
*cond
, struct vars
*v
)
580 isl_pw_aff
*pwaff1
= NULL
, *pwaff2
= NULL
, *pa_cond
;
585 if (isl_stream_eat(s
, '?'))
588 dim
= isl_space_wrap(isl_map_get_space(cond
));
589 pwaff1
= accept_extended_affine(s
, dim
, v
);
593 if (isl_stream_eat(s
, ':'))
596 dim
= isl_pw_aff_get_domain_space(pwaff1
);
597 pwaff2
= accept_extended_affine(s
, dim
, v
);
601 pa_cond
= isl_set_indicator_function(isl_map_wrap(cond
));
602 return isl_pw_aff_cond(pa_cond
, pwaff1
, pwaff2
);
605 isl_pw_aff_free(pwaff1
);
606 isl_pw_aff_free(pwaff2
);
610 /* Accept an affine expression that may involve ternary operators.
611 * We first read an affine expression.
612 * If it is not followed by a comparison operator, we simply return it.
613 * Otherwise, we assume the affine epxression is part of the first
614 * argument of a ternary operator and try to parse that.
616 static __isl_give isl_pw_aff
*accept_extended_affine(struct isl_stream
*s
,
617 __isl_take isl_space
*dim
, struct vars
*v
)
622 struct isl_token
*tok
;
623 int line
= -1, col
= -1;
626 tok
= isl_stream_next_token(s
);
630 isl_stream_push_token(s
, tok
);
633 pwaff
= accept_affine(s
, dim
, v
);
637 tok
= isl_stream_next_token(s
);
639 return isl_pw_aff_free(pwaff
);
641 is_comp
= is_comparator(tok
);
642 isl_stream_push_token(s
, tok
);
646 tok
= isl_token_new(s
->ctx
, line
, col
, 0);
648 return isl_pw_aff_free(pwaff
);
649 tok
->type
= ISL_TOKEN_AFF
;
650 tok
->u
.pwaff
= pwaff
;
652 space
= isl_pw_aff_get_domain_space(pwaff
);
653 cond
= isl_map_universe(isl_space_unwrap(space
));
655 isl_stream_push_token(s
, tok
);
657 cond
= read_disjuncts(s
, v
, cond
);
659 return accept_ternary(s
, cond
, v
);
662 static __isl_give isl_map
*read_var_def(struct isl_stream
*s
,
663 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
)
669 if (type
== isl_dim_param
)
670 pos
= isl_map_dim(map
, isl_dim_param
);
672 pos
= isl_map_dim(map
, isl_dim_in
);
673 if (type
== isl_dim_out
)
674 pos
+= isl_map_dim(map
, isl_dim_out
);
679 def
= accept_extended_affine(s
, isl_space_wrap(isl_map_get_space(map
)), v
);
680 def_map
= isl_map_from_pw_aff(def
);
681 def_map
= isl_map_equate(def_map
, type
, pos
, isl_dim_out
, 0);
682 def_map
= isl_set_unwrap(isl_map_domain(def_map
));
684 map
= isl_map_intersect(map
, def_map
);
689 static __isl_give isl_map
*read_var_list(struct isl_stream
*s
,
690 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
)
693 struct isl_token
*tok
;
695 if (isl_stream_next_token_is(s
, ']'))
696 return isl_map_add_dims(map
, type
, 0);
698 while ((tok
= next_token(s
)) != NULL
) {
701 if (tok
->type
== ISL_TOKEN_IDENT
) {
703 int p
= vars_pos(v
, tok
->u
.s
, -1);
710 map
= isl_map_add_dims(map
, type
, 1);
711 map
= set_name(map
, type
, i
, v
->v
->name
);
713 if (isl_stream_eat_if_available(s
, '='))
714 map
= read_var_def(s
, map
, type
, v
);
716 if (type
== isl_dim_param
) {
717 isl_stream_error(s
, tok
,
718 "expecting unique identifier");
721 isl_stream_push_token(s
, tok
);
723 if (vars_add_anon(v
) < 0)
725 map
= isl_map_add_dims(map
, type
, 1);
726 map
= read_var_def(s
, map
, type
, v
);
729 tok
= isl_stream_next_token(s
);
730 if (tok
&& tok
->type
== ']' &&
731 isl_stream_next_token_is(s
, '[')) {
733 tok
= isl_stream_next_token(s
);
734 } else if (!tok
|| tok
->type
!= ',')
741 isl_stream_push_token(s
, tok
);
750 static __isl_give isl_pw_aff_list
*accept_affine_list(struct isl_stream
*s
,
751 __isl_take isl_space
*dim
, struct vars
*v
)
754 isl_pw_aff_list
*list
;
755 struct isl_token
*tok
= NULL
;
757 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
758 list
= isl_pw_aff_list_from_pw_aff(pwaff
);
763 tok
= isl_stream_next_token(s
);
765 isl_stream_error(s
, NULL
, "unexpected EOF");
768 if (tok
->type
!= ',') {
769 isl_stream_push_token(s
, tok
);
774 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
775 list
= isl_pw_aff_list_concat(list
,
776 isl_pw_aff_list_from_pw_aff(pwaff
));
785 isl_pw_aff_list_free(list
);
789 static __isl_give isl_map
*read_defined_var_list(struct isl_stream
*s
,
790 struct vars
*v
, __isl_take isl_map
*map
)
792 struct isl_token
*tok
;
794 while ((tok
= isl_stream_next_token(s
)) != NULL
) {
798 if (tok
->type
!= ISL_TOKEN_IDENT
)
801 p
= vars_pos(v
, tok
->u
.s
, -1);
805 isl_stream_error(s
, tok
, "expecting unique identifier");
809 map
= isl_map_add_dims(map
, isl_dim_out
, 1);
812 tok
= isl_stream_next_token(s
);
813 if (tok
&& tok
->type
== '=') {
815 map
= read_var_def(s
, map
, isl_dim_out
, v
);
816 tok
= isl_stream_next_token(s
);
819 if (!tok
|| tok
->type
!= ',')
825 isl_stream_push_token(s
, tok
);
834 static int next_is_tuple(struct isl_stream
*s
)
836 struct isl_token
*tok
;
839 tok
= isl_stream_next_token(s
);
842 if (tok
->type
== '[') {
843 isl_stream_push_token(s
, tok
);
846 if (tok
->type
!= ISL_TOKEN_IDENT
&& !tok
->is_keyword
) {
847 isl_stream_push_token(s
, tok
);
851 is_tuple
= isl_stream_next_token_is(s
, '[');
853 isl_stream_push_token(s
, tok
);
858 static __isl_give isl_map
*read_tuple(struct isl_stream
*s
,
859 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
);
861 static __isl_give isl_set
*read_nested_tuple(struct isl_stream
*s
,
862 __isl_take isl_map
*map
, struct vars
*v
)
864 map
= read_tuple(s
, map
, isl_dim_in
, v
);
865 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
867 map
= read_tuple(s
, map
, isl_dim_out
, v
);
868 return isl_map_wrap(map
);
874 static __isl_give isl_map
*read_tuple(struct isl_stream
*s
,
875 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
)
877 struct isl_token
*tok
;
880 tok
= isl_stream_next_token(s
);
881 if (tok
&& (tok
->type
== ISL_TOKEN_IDENT
|| tok
->is_keyword
)) {
882 name
= strdup(tok
->u
.s
);
886 tok
= isl_stream_next_token(s
);
888 if (!tok
|| tok
->type
!= '[') {
889 isl_stream_error(s
, tok
, "expecting '['");
893 if (type
!= isl_dim_param
&& next_is_tuple(s
)) {
894 isl_space
*dim
= isl_map_get_space(map
);
895 int nparam
= isl_space_dim(dim
, isl_dim_param
);
896 int n_in
= isl_space_dim(dim
, isl_dim_in
);
898 if (type
== isl_dim_out
) {
899 dim
= isl_space_move_dims(dim
, isl_dim_param
, nparam
,
900 isl_dim_in
, 0, n_in
);
901 dim
= isl_space_params(dim
);
903 nested
= read_nested_tuple(s
, isl_map_universe(dim
), v
);
904 if (type
== isl_dim_in
) {
905 nested
= isl_map_reverse(nested
);
906 map
= isl_map_intersect_params(nested
, map
);
909 dim
= isl_set_get_space(nested
);
910 dim
= isl_space_drop_dims(dim
, isl_dim_param
, nparam
, n_in
);
911 dim
= isl_space_join(isl_map_get_space(map
), dim
);
912 set
= isl_map_domain(map
);
913 nested
= isl_map_reset_space(nested
, dim
);
914 map
= isl_map_intersect_domain(nested
, set
);
917 map
= read_var_list(s
, map
, type
, v
);
918 tok
= isl_stream_next_token(s
);
919 if (!tok
|| tok
->type
!= ']') {
920 isl_stream_error(s
, tok
, "expecting ']'");
926 map
= isl_map_set_tuple_name(map
, type
, name
);
938 static __isl_give isl_set
*construct_constraints(
939 __isl_take isl_set
*set
, int type
,
940 __isl_keep isl_pw_aff_list
*left
, __isl_keep isl_pw_aff_list
*right
)
944 if (type
== ISL_TOKEN_LE
)
945 cond
= isl_pw_aff_list_le_set(isl_pw_aff_list_copy(left
),
946 isl_pw_aff_list_copy(right
));
947 else if (type
== ISL_TOKEN_GE
)
948 cond
= isl_pw_aff_list_ge_set(isl_pw_aff_list_copy(left
),
949 isl_pw_aff_list_copy(right
));
950 else if (type
== ISL_TOKEN_LT
)
951 cond
= isl_pw_aff_list_lt_set(isl_pw_aff_list_copy(left
),
952 isl_pw_aff_list_copy(right
));
953 else if (type
== ISL_TOKEN_GT
)
954 cond
= isl_pw_aff_list_gt_set(isl_pw_aff_list_copy(left
),
955 isl_pw_aff_list_copy(right
));
956 else if (type
== ISL_TOKEN_NE
)
957 cond
= isl_pw_aff_list_ne_set(isl_pw_aff_list_copy(left
),
958 isl_pw_aff_list_copy(right
));
960 cond
= isl_pw_aff_list_eq_set(isl_pw_aff_list_copy(left
),
961 isl_pw_aff_list_copy(right
));
963 return isl_set_intersect(set
, cond
);
966 static __isl_give isl_map
*add_constraint(struct isl_stream
*s
,
967 struct vars
*v
, __isl_take isl_map
*map
)
969 struct isl_token
*tok
= NULL
;
970 isl_pw_aff_list
*list1
= NULL
, *list2
= NULL
;
973 set
= isl_map_wrap(map
);
974 list1
= accept_affine_list(s
, isl_set_get_space(set
), v
);
977 tok
= isl_stream_next_token(s
);
978 if (!is_comparator(tok
)) {
979 isl_stream_error(s
, tok
, "missing operator");
981 isl_stream_push_token(s
, tok
);
986 list2
= accept_affine_list(s
, isl_set_get_space(set
), v
);
990 set
= construct_constraints(set
, tok
->type
, list1
, list2
);
992 isl_pw_aff_list_free(list1
);
995 tok
= isl_stream_next_token(s
);
996 if (!is_comparator(tok
)) {
998 isl_stream_push_token(s
, tok
);
1002 isl_pw_aff_list_free(list1
);
1004 return isl_set_unwrap(set
);
1007 isl_token_free(tok
);
1008 isl_pw_aff_list_free(list1
);
1009 isl_pw_aff_list_free(list2
);
1014 static __isl_give isl_map
*read_exists(struct isl_stream
*s
,
1015 struct vars
*v
, __isl_take isl_map
*map
)
1018 int seen_paren
= isl_stream_eat_if_available(s
, '(');
1020 map
= isl_map_from_domain(isl_map_wrap(map
));
1021 map
= read_defined_var_list(s
, v
, map
);
1023 if (isl_stream_eat(s
, ':'))
1026 map
= read_disjuncts(s
, v
, map
);
1027 map
= isl_set_unwrap(isl_map_domain(map
));
1029 vars_drop(v
, v
->n
- n
);
1030 if (seen_paren
&& isl_stream_eat(s
, ')'))
1039 /* Parse an expression between parentheses and push the result
1040 * back on the stream.
1042 * The parsed expression may be either an affine expression
1043 * or a condition. The first type is pushed onto the stream
1044 * as an isl_pw_aff, while the second is pushed as an isl_map.
1046 * If the initial token indicates the start of a condition,
1047 * we parse it as such.
1048 * Otherwise, we first parse an affine expression and push
1049 * that onto the stream. If the affine expression covers the
1050 * entire expression between parentheses, we return.
1051 * Otherwise, we assume that the affine expression is the
1052 * start of a condition and continue parsing.
1054 static int resolve_paren_expr(struct isl_stream
*s
,
1055 struct vars
*v
, __isl_take isl_map
*map
)
1057 struct isl_token
*tok
, *tok2
;
1061 tok
= isl_stream_next_token(s
);
1062 if (!tok
|| tok
->type
!= '(')
1065 if (isl_stream_next_token_is(s
, '('))
1066 if (resolve_paren_expr(s
, v
, isl_map_copy(map
)))
1069 if (isl_stream_next_token_is(s
, ISL_TOKEN_EXISTS
) ||
1070 isl_stream_next_token_is(s
, ISL_TOKEN_NOT
) ||
1071 isl_stream_next_token_is(s
, ISL_TOKEN_TRUE
) ||
1072 isl_stream_next_token_is(s
, ISL_TOKEN_FALSE
) ||
1073 isl_stream_next_token_is(s
, ISL_TOKEN_MAP
)) {
1074 map
= read_disjuncts(s
, v
, map
);
1075 if (isl_stream_eat(s
, ')'))
1077 tok
->type
= ISL_TOKEN_MAP
;
1079 isl_stream_push_token(s
, tok
);
1083 tok2
= isl_stream_next_token(s
);
1088 isl_stream_push_token(s
, tok2
);
1090 pwaff
= accept_affine(s
, isl_space_wrap(isl_map_get_space(map
)), v
);
1094 tok2
= isl_token_new(s
->ctx
, line
, col
, 0);
1097 tok2
->type
= ISL_TOKEN_AFF
;
1098 tok2
->u
.pwaff
= pwaff
;
1100 if (isl_stream_eat_if_available(s
, ')')) {
1101 isl_stream_push_token(s
, tok2
);
1102 isl_token_free(tok
);
1107 isl_stream_push_token(s
, tok2
);
1109 map
= read_disjuncts(s
, v
, map
);
1110 if (isl_stream_eat(s
, ')'))
1113 tok
->type
= ISL_TOKEN_MAP
;
1115 isl_stream_push_token(s
, tok
);
1119 isl_pw_aff_free(pwaff
);
1121 isl_token_free(tok
);
1126 static __isl_give isl_map
*read_conjunct(struct isl_stream
*s
,
1127 struct vars
*v
, __isl_take isl_map
*map
)
1129 if (isl_stream_next_token_is(s
, '('))
1130 if (resolve_paren_expr(s
, v
, isl_map_copy(map
)))
1133 if (isl_stream_next_token_is(s
, ISL_TOKEN_MAP
)) {
1134 struct isl_token
*tok
;
1135 tok
= isl_stream_next_token(s
);
1139 map
= isl_map_copy(tok
->u
.map
);
1140 isl_token_free(tok
);
1144 if (isl_stream_eat_if_available(s
, ISL_TOKEN_EXISTS
))
1145 return read_exists(s
, v
, map
);
1147 if (isl_stream_eat_if_available(s
, ISL_TOKEN_TRUE
))
1150 if (isl_stream_eat_if_available(s
, ISL_TOKEN_FALSE
)) {
1151 isl_space
*dim
= isl_map_get_space(map
);
1153 return isl_map_empty(dim
);
1156 return add_constraint(s
, v
, map
);
1162 static __isl_give isl_map
*read_conjuncts(struct isl_stream
*s
,
1163 struct vars
*v
, __isl_take isl_map
*map
)
1168 negate
= isl_stream_eat_if_available(s
, ISL_TOKEN_NOT
);
1169 res
= read_conjunct(s
, v
, isl_map_copy(map
));
1171 res
= isl_map_subtract(isl_map_copy(map
), res
);
1173 while (isl_stream_eat_if_available(s
, ISL_TOKEN_AND
)) {
1176 negate
= isl_stream_eat_if_available(s
, ISL_TOKEN_NOT
);
1177 res_i
= read_conjunct(s
, v
, isl_map_copy(map
));
1179 res
= isl_map_subtract(res
, res_i
);
1181 res
= isl_map_intersect(res
, res_i
);
1188 static struct isl_map
*read_disjuncts(struct isl_stream
*s
,
1189 struct vars
*v
, __isl_take isl_map
*map
)
1193 if (isl_stream_next_token_is(s
, '}')) {
1194 isl_space
*dim
= isl_map_get_space(map
);
1196 return isl_map_universe(dim
);
1199 res
= read_conjuncts(s
, v
, isl_map_copy(map
));
1200 while (isl_stream_eat_if_available(s
, ISL_TOKEN_OR
)) {
1203 res_i
= read_conjuncts(s
, v
, isl_map_copy(map
));
1204 res
= isl_map_union(res
, res_i
);
1211 static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map
*bmap
, int pos
)
1213 if (pos
< isl_basic_map_dim(bmap
, isl_dim_out
))
1214 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) +
1215 isl_basic_map_dim(bmap
, isl_dim_in
) + pos
;
1216 pos
-= isl_basic_map_dim(bmap
, isl_dim_out
);
1218 if (pos
< isl_basic_map_dim(bmap
, isl_dim_in
))
1219 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) + pos
;
1220 pos
-= isl_basic_map_dim(bmap
, isl_dim_in
);
1222 if (pos
< isl_basic_map_dim(bmap
, isl_dim_div
))
1223 return 1 + isl_basic_map_dim(bmap
, isl_dim_param
) +
1224 isl_basic_map_dim(bmap
, isl_dim_in
) +
1225 isl_basic_map_dim(bmap
, isl_dim_out
) + pos
;
1226 pos
-= isl_basic_map_dim(bmap
, isl_dim_div
);
1228 if (pos
< isl_basic_map_dim(bmap
, isl_dim_param
))
1234 static __isl_give isl_basic_map
*basic_map_read_polylib_constraint(
1235 struct isl_stream
*s
, __isl_take isl_basic_map
*bmap
)
1238 struct isl_token
*tok
;
1248 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1249 dim
= isl_basic_map_dim(bmap
, isl_dim_out
);
1251 tok
= isl_stream_next_token(s
);
1252 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1253 isl_stream_error(s
, tok
, "expecting coefficient");
1255 isl_stream_push_token(s
, tok
);
1258 if (!tok
->on_new_line
) {
1259 isl_stream_error(s
, tok
, "coefficient should appear on new line");
1260 isl_stream_push_token(s
, tok
);
1264 type
= isl_int_get_si(tok
->u
.v
);
1265 isl_token_free(tok
);
1267 isl_assert(s
->ctx
, type
== 0 || type
== 1, goto error
);
1269 k
= isl_basic_map_alloc_equality(bmap
);
1272 k
= isl_basic_map_alloc_inequality(bmap
);
1278 for (j
= 0; j
< 1 + isl_basic_map_total_dim(bmap
); ++j
) {
1280 tok
= isl_stream_next_token(s
);
1281 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1282 isl_stream_error(s
, tok
, "expecting coefficient");
1284 isl_stream_push_token(s
, tok
);
1287 if (tok
->on_new_line
) {
1288 isl_stream_error(s
, tok
,
1289 "coefficient should not appear on new line");
1290 isl_stream_push_token(s
, tok
);
1293 pos
= polylib_pos_to_isl_pos(bmap
, j
);
1294 isl_int_set(c
[pos
], tok
->u
.v
);
1295 isl_token_free(tok
);
1300 isl_basic_map_free(bmap
);
1304 static __isl_give isl_basic_map
*basic_map_read_polylib(struct isl_stream
*s
)
1307 struct isl_token
*tok
;
1308 struct isl_token
*tok2
;
1311 unsigned in
= 0, out
, local
= 0;
1312 struct isl_basic_map
*bmap
= NULL
;
1315 tok
= isl_stream_next_token(s
);
1317 isl_stream_error(s
, NULL
, "unexpected EOF");
1320 tok2
= isl_stream_next_token(s
);
1322 isl_token_free(tok
);
1323 isl_stream_error(s
, NULL
, "unexpected EOF");
1326 if (tok
->type
!= ISL_TOKEN_VALUE
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
1327 isl_stream_push_token(s
, tok2
);
1328 isl_stream_push_token(s
, tok
);
1329 isl_stream_error(s
, NULL
,
1330 "expecting constraint matrix dimensions");
1333 n_row
= isl_int_get_si(tok
->u
.v
);
1334 n_col
= isl_int_get_si(tok2
->u
.v
);
1335 on_new_line
= tok2
->on_new_line
;
1336 isl_token_free(tok2
);
1337 isl_token_free(tok
);
1338 isl_assert(s
->ctx
, !on_new_line
, return NULL
);
1339 isl_assert(s
->ctx
, n_row
>= 0, return NULL
);
1340 isl_assert(s
->ctx
, n_col
>= 2 + nparam
, return NULL
);
1341 tok
= isl_stream_next_token_on_same_line(s
);
1343 if (tok
->type
!= ISL_TOKEN_VALUE
) {
1344 isl_stream_error(s
, tok
,
1345 "expecting number of output dimensions");
1346 isl_stream_push_token(s
, tok
);
1349 out
= isl_int_get_si(tok
->u
.v
);
1350 isl_token_free(tok
);
1352 tok
= isl_stream_next_token_on_same_line(s
);
1353 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1354 isl_stream_error(s
, tok
,
1355 "expecting number of input dimensions");
1357 isl_stream_push_token(s
, tok
);
1360 in
= isl_int_get_si(tok
->u
.v
);
1361 isl_token_free(tok
);
1363 tok
= isl_stream_next_token_on_same_line(s
);
1364 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1365 isl_stream_error(s
, tok
,
1366 "expecting number of existentials");
1368 isl_stream_push_token(s
, tok
);
1371 local
= isl_int_get_si(tok
->u
.v
);
1372 isl_token_free(tok
);
1374 tok
= isl_stream_next_token_on_same_line(s
);
1375 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1376 isl_stream_error(s
, tok
,
1377 "expecting number of parameters");
1379 isl_stream_push_token(s
, tok
);
1382 nparam
= isl_int_get_si(tok
->u
.v
);
1383 isl_token_free(tok
);
1384 if (n_col
!= 1 + out
+ in
+ local
+ nparam
+ 1) {
1385 isl_stream_error(s
, NULL
,
1386 "dimensions don't match");
1390 out
= n_col
- 2 - nparam
;
1391 bmap
= isl_basic_map_alloc(s
->ctx
, nparam
, in
, out
, local
, n_row
, n_row
);
1395 for (i
= 0; i
< local
; ++i
) {
1396 int k
= isl_basic_map_alloc_div(bmap
);
1399 isl_seq_clr(bmap
->div
[k
], 1 + 1 + nparam
+ in
+ out
+ local
);
1402 for (i
= 0; i
< n_row
; ++i
)
1403 bmap
= basic_map_read_polylib_constraint(s
, bmap
);
1405 tok
= isl_stream_next_token_on_same_line(s
);
1407 isl_stream_error(s
, tok
, "unexpected extra token on line");
1408 isl_stream_push_token(s
, tok
);
1412 bmap
= isl_basic_map_simplify(bmap
);
1413 bmap
= isl_basic_map_finalize(bmap
);
1416 isl_basic_map_free(bmap
);
1420 static struct isl_map
*map_read_polylib(struct isl_stream
*s
)
1422 struct isl_token
*tok
;
1423 struct isl_token
*tok2
;
1425 struct isl_map
*map
;
1427 tok
= isl_stream_next_token(s
);
1429 isl_stream_error(s
, NULL
, "unexpected EOF");
1432 tok2
= isl_stream_next_token_on_same_line(s
);
1433 if (tok2
&& tok2
->type
== ISL_TOKEN_VALUE
) {
1434 isl_stream_push_token(s
, tok2
);
1435 isl_stream_push_token(s
, tok
);
1436 return isl_map_from_basic_map(basic_map_read_polylib(s
));
1439 isl_stream_error(s
, tok2
, "unexpected token");
1440 isl_stream_push_token(s
, tok2
);
1441 isl_stream_push_token(s
, tok
);
1444 n
= isl_int_get_si(tok
->u
.v
);
1445 isl_token_free(tok
);
1447 isl_assert(s
->ctx
, n
>= 1, return NULL
);
1449 map
= isl_map_from_basic_map(basic_map_read_polylib(s
));
1451 for (i
= 1; map
&& i
< n
; ++i
)
1452 map
= isl_map_union(map
,
1453 isl_map_from_basic_map(basic_map_read_polylib(s
)));
1458 static int optional_power(struct isl_stream
*s
)
1461 struct isl_token
*tok
;
1463 tok
= isl_stream_next_token(s
);
1466 if (tok
->type
!= '^') {
1467 isl_stream_push_token(s
, tok
);
1470 isl_token_free(tok
);
1471 tok
= isl_stream_next_token(s
);
1472 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1473 isl_stream_error(s
, tok
, "expecting exponent");
1475 isl_stream_push_token(s
, tok
);
1478 pow
= isl_int_get_si(tok
->u
.v
);
1479 isl_token_free(tok
);
1483 static __isl_give isl_pw_qpolynomial
*read_term(struct isl_stream
*s
,
1484 __isl_keep isl_map
*map
, struct vars
*v
);
1486 static __isl_give isl_pw_qpolynomial
*read_factor(struct isl_stream
*s
,
1487 __isl_keep isl_map
*map
, struct vars
*v
)
1489 isl_pw_qpolynomial
*pwqp
;
1490 struct isl_token
*tok
;
1492 tok
= next_token(s
);
1494 isl_stream_error(s
, NULL
, "unexpected EOF");
1497 if (tok
->type
== '(') {
1500 isl_token_free(tok
);
1501 pwqp
= read_term(s
, map
, v
);
1504 if (isl_stream_eat(s
, ')'))
1506 pow
= optional_power(s
);
1507 pwqp
= isl_pw_qpolynomial_pow(pwqp
, pow
);
1508 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
1509 struct isl_token
*tok2
;
1510 tok2
= isl_stream_next_token(s
);
1511 isl_qpolynomial
*qp
;
1512 if (tok2
&& tok2
->type
== '/') {
1513 isl_token_free(tok2
);
1514 tok2
= next_token(s
);
1515 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
1516 isl_stream_error(s
, tok2
, "expected denominator");
1517 isl_token_free(tok
);
1518 isl_token_free(tok2
);
1521 qp
= isl_qpolynomial_rat_cst_on_domain(isl_map_get_space(map
),
1522 tok
->u
.v
, tok2
->u
.v
);
1523 isl_token_free(tok2
);
1525 isl_stream_push_token(s
, tok2
);
1526 qp
= isl_qpolynomial_cst_on_domain(isl_map_get_space(map
),
1529 isl_token_free(tok
);
1530 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
1531 } else if (tok
->type
== ISL_TOKEN_INFTY
) {
1532 isl_qpolynomial
*qp
;
1533 isl_token_free(tok
);
1534 qp
= isl_qpolynomial_infty_on_domain(isl_map_get_space(map
));
1535 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
1536 } else if (tok
->type
== ISL_TOKEN_NAN
) {
1537 isl_qpolynomial
*qp
;
1538 isl_token_free(tok
);
1539 qp
= isl_qpolynomial_nan_on_domain(isl_map_get_space(map
));
1540 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
1541 } else if (tok
->type
== ISL_TOKEN_IDENT
) {
1543 int pos
= vars_pos(v
, tok
->u
.s
, -1);
1545 isl_qpolynomial
*qp
;
1547 isl_token_free(tok
);
1551 vars_drop(v
, v
->n
- n
);
1552 isl_stream_error(s
, tok
, "unknown identifier");
1553 isl_token_free(tok
);
1556 isl_token_free(tok
);
1557 pow
= optional_power(s
);
1558 qp
= isl_qpolynomial_var_pow_on_domain(isl_map_get_space(map
), pos
, pow
);
1559 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
1560 } else if (tok
->type
== '[') {
1564 isl_stream_push_token(s
, tok
);
1565 pwaff
= accept_div(s
, isl_map_get_space(map
), v
);
1566 pow
= optional_power(s
);
1567 pwqp
= isl_pw_qpolynomial_from_pw_aff(pwaff
);
1568 pwqp
= isl_pw_qpolynomial_pow(pwqp
, pow
);
1569 } else if (tok
->type
== '-') {
1570 isl_token_free(tok
);
1571 pwqp
= read_factor(s
, map
, v
);
1572 pwqp
= isl_pw_qpolynomial_neg(pwqp
);
1574 isl_stream_error(s
, tok
, "unexpected isl_token");
1575 isl_stream_push_token(s
, tok
);
1579 if (isl_stream_eat_if_available(s
, '*') ||
1580 isl_stream_next_token_is(s
, ISL_TOKEN_IDENT
)) {
1581 isl_pw_qpolynomial
*pwqp2
;
1583 pwqp2
= read_factor(s
, map
, v
);
1584 pwqp
= isl_pw_qpolynomial_mul(pwqp
, pwqp2
);
1589 isl_pw_qpolynomial_free(pwqp
);
1593 static __isl_give isl_pw_qpolynomial
*read_term(struct isl_stream
*s
,
1594 __isl_keep isl_map
*map
, struct vars
*v
)
1596 struct isl_token
*tok
;
1597 isl_pw_qpolynomial
*pwqp
;
1599 pwqp
= read_factor(s
, map
, v
);
1602 tok
= next_token(s
);
1606 if (tok
->type
== '+') {
1607 isl_pw_qpolynomial
*pwqp2
;
1609 isl_token_free(tok
);
1610 pwqp2
= read_factor(s
, map
, v
);
1611 pwqp
= isl_pw_qpolynomial_add(pwqp
, pwqp2
);
1612 } else if (tok
->type
== '-') {
1613 isl_pw_qpolynomial
*pwqp2
;
1615 isl_token_free(tok
);
1616 pwqp2
= read_factor(s
, map
, v
);
1617 pwqp
= isl_pw_qpolynomial_sub(pwqp
, pwqp2
);
1618 } else if (tok
->type
== ISL_TOKEN_VALUE
&&
1619 isl_int_is_neg(tok
->u
.v
)) {
1620 isl_pw_qpolynomial
*pwqp2
;
1622 isl_stream_push_token(s
, tok
);
1623 pwqp2
= read_factor(s
, map
, v
);
1624 pwqp
= isl_pw_qpolynomial_add(pwqp
, pwqp2
);
1626 isl_stream_push_token(s
, tok
);
1634 static __isl_give isl_map
*read_optional_disjuncts(struct isl_stream
*s
,
1635 __isl_take isl_map
*map
, struct vars
*v
)
1637 struct isl_token
*tok
;
1639 tok
= isl_stream_next_token(s
);
1641 isl_stream_error(s
, NULL
, "unexpected EOF");
1644 if (tok
->type
== ':' ||
1645 (tok
->type
== ISL_TOKEN_OR
&& !strcmp(tok
->u
.s
, "|"))) {
1646 isl_token_free(tok
);
1647 map
= read_disjuncts(s
, v
, map
);
1649 isl_stream_push_token(s
, tok
);
1657 static struct isl_obj
obj_read_poly(struct isl_stream
*s
,
1658 __isl_take isl_map
*map
, struct vars
*v
, int n
)
1660 struct isl_obj obj
= { isl_obj_pw_qpolynomial
, NULL
};
1661 isl_pw_qpolynomial
*pwqp
;
1662 struct isl_set
*set
;
1664 pwqp
= read_term(s
, map
, v
);
1665 map
= read_optional_disjuncts(s
, map
, v
);
1666 set
= isl_map_range(map
);
1668 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
1670 vars_drop(v
, v
->n
- n
);
1676 static struct isl_obj
obj_read_poly_or_fold(struct isl_stream
*s
,
1677 __isl_take isl_set
*set
, struct vars
*v
, int n
)
1679 struct isl_obj obj
= { isl_obj_pw_qpolynomial_fold
, NULL
};
1680 isl_pw_qpolynomial
*pwqp
;
1681 isl_pw_qpolynomial_fold
*pwf
= NULL
;
1683 if (!isl_stream_eat_if_available(s
, ISL_TOKEN_MAX
))
1684 return obj_read_poly(s
, set
, v
, n
);
1686 if (isl_stream_eat(s
, '('))
1689 pwqp
= read_term(s
, set
, v
);
1690 pwf
= isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max
, pwqp
);
1692 while (isl_stream_eat_if_available(s
, ',')) {
1693 isl_pw_qpolynomial_fold
*pwf_i
;
1694 pwqp
= read_term(s
, set
, v
);
1695 pwf_i
= isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max
,
1697 pwf
= isl_pw_qpolynomial_fold_fold(pwf
, pwf_i
);
1700 if (isl_stream_eat(s
, ')'))
1703 set
= read_optional_disjuncts(s
, set
, v
);
1704 pwf
= isl_pw_qpolynomial_fold_intersect_domain(pwf
, set
);
1706 vars_drop(v
, v
->n
- n
);
1712 isl_pw_qpolynomial_fold_free(pwf
);
1713 obj
.type
= isl_obj_none
;
1717 static int is_rational(struct isl_stream
*s
)
1719 struct isl_token
*tok
;
1721 tok
= isl_stream_next_token(s
);
1724 if (tok
->type
== ISL_TOKEN_RAT
&& isl_stream_next_token_is(s
, ':')) {
1725 isl_token_free(tok
);
1726 isl_stream_eat(s
, ':');
1730 isl_stream_push_token(s
, tok
);
1735 static struct isl_obj
obj_read_body(struct isl_stream
*s
,
1736 __isl_take isl_map
*map
, struct vars
*v
)
1738 struct isl_token
*tok
;
1739 struct isl_obj obj
= { isl_obj_set
, NULL
};
1743 map
= isl_map_set_rational(map
);
1745 if (isl_stream_next_token_is(s
, ':')) {
1746 obj
.type
= isl_obj_set
;
1747 obj
.v
= read_optional_disjuncts(s
, map
, v
);
1751 if (!next_is_tuple(s
))
1752 return obj_read_poly_or_fold(s
, map
, v
, n
);
1754 map
= read_tuple(s
, map
, isl_dim_in
, v
);
1757 tok
= isl_stream_next_token(s
);
1760 if (tok
->type
== ISL_TOKEN_TO
) {
1761 obj
.type
= isl_obj_map
;
1762 isl_token_free(tok
);
1763 if (!next_is_tuple(s
)) {
1764 isl_set
*set
= isl_map_domain(map
);
1765 return obj_read_poly_or_fold(s
, set
, v
, n
);
1767 map
= read_tuple(s
, map
, isl_dim_out
, v
);
1771 map
= isl_map_reverse(map
);
1772 isl_stream_push_token(s
, tok
);
1775 map
= read_optional_disjuncts(s
, map
, v
);
1777 vars_drop(v
, v
->n
- n
);
1783 obj
.type
= isl_obj_none
;
1787 static struct isl_obj
to_union(isl_ctx
*ctx
, struct isl_obj obj
)
1789 if (obj
.type
== isl_obj_map
) {
1790 obj
.v
= isl_union_map_from_map(obj
.v
);
1791 obj
.type
= isl_obj_union_map
;
1792 } else if (obj
.type
== isl_obj_set
) {
1793 obj
.v
= isl_union_set_from_set(obj
.v
);
1794 obj
.type
= isl_obj_union_set
;
1795 } else if (obj
.type
== isl_obj_pw_qpolynomial
) {
1796 obj
.v
= isl_union_pw_qpolynomial_from_pw_qpolynomial(obj
.v
);
1797 obj
.type
= isl_obj_union_pw_qpolynomial
;
1798 } else if (obj
.type
== isl_obj_pw_qpolynomial_fold
) {
1799 obj
.v
= isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(obj
.v
);
1800 obj
.type
= isl_obj_union_pw_qpolynomial_fold
;
1802 isl_assert(ctx
, 0, goto error
);
1805 obj
.type
->free(obj
.v
);
1806 obj
.type
= isl_obj_none
;
1810 static struct isl_obj
obj_add(struct isl_ctx
*ctx
,
1811 struct isl_obj obj1
, struct isl_obj obj2
)
1813 if (obj1
.type
== isl_obj_set
&& obj2
.type
== isl_obj_union_set
)
1814 obj1
= to_union(ctx
, obj1
);
1815 if (obj1
.type
== isl_obj_union_set
&& obj2
.type
== isl_obj_set
)
1816 obj2
= to_union(ctx
, obj2
);
1817 if (obj1
.type
== isl_obj_map
&& obj2
.type
== isl_obj_union_map
)
1818 obj1
= to_union(ctx
, obj1
);
1819 if (obj1
.type
== isl_obj_union_map
&& obj2
.type
== isl_obj_map
)
1820 obj2
= to_union(ctx
, obj2
);
1821 if (obj1
.type
== isl_obj_pw_qpolynomial
&&
1822 obj2
.type
== isl_obj_union_pw_qpolynomial
)
1823 obj1
= to_union(ctx
, obj1
);
1824 if (obj1
.type
== isl_obj_union_pw_qpolynomial
&&
1825 obj2
.type
== isl_obj_pw_qpolynomial
)
1826 obj2
= to_union(ctx
, obj2
);
1827 if (obj1
.type
== isl_obj_pw_qpolynomial_fold
&&
1828 obj2
.type
== isl_obj_union_pw_qpolynomial_fold
)
1829 obj1
= to_union(ctx
, obj1
);
1830 if (obj1
.type
== isl_obj_union_pw_qpolynomial_fold
&&
1831 obj2
.type
== isl_obj_pw_qpolynomial_fold
)
1832 obj2
= to_union(ctx
, obj2
);
1833 isl_assert(ctx
, obj1
.type
== obj2
.type
, goto error
);
1834 if (obj1
.type
== isl_obj_map
&& !isl_map_has_equal_space(obj1
.v
, obj2
.v
)) {
1835 obj1
= to_union(ctx
, obj1
);
1836 obj2
= to_union(ctx
, obj2
);
1838 if (obj1
.type
== isl_obj_set
&& !isl_set_has_equal_space(obj1
.v
, obj2
.v
)) {
1839 obj1
= to_union(ctx
, obj1
);
1840 obj2
= to_union(ctx
, obj2
);
1842 if (obj1
.type
== isl_obj_pw_qpolynomial
&&
1843 !isl_pw_qpolynomial_has_equal_space(obj1
.v
, obj2
.v
)) {
1844 obj1
= to_union(ctx
, obj1
);
1845 obj2
= to_union(ctx
, obj2
);
1847 if (obj1
.type
== isl_obj_pw_qpolynomial_fold
&&
1848 !isl_pw_qpolynomial_fold_has_equal_space(obj1
.v
, obj2
.v
)) {
1849 obj1
= to_union(ctx
, obj1
);
1850 obj2
= to_union(ctx
, obj2
);
1852 obj1
.v
= obj1
.type
->add(obj1
.v
, obj2
.v
);
1855 obj1
.type
->free(obj1
.v
);
1856 obj2
.type
->free(obj2
.v
);
1857 obj1
.type
= isl_obj_none
;
1862 static struct isl_obj
obj_read(struct isl_stream
*s
)
1864 isl_map
*map
= NULL
;
1865 struct isl_token
*tok
;
1866 struct vars
*v
= NULL
;
1867 struct isl_obj obj
= { isl_obj_set
, NULL
};
1869 tok
= next_token(s
);
1871 isl_stream_error(s
, NULL
, "unexpected EOF");
1874 if (tok
->type
== ISL_TOKEN_VALUE
) {
1875 struct isl_token
*tok2
;
1876 struct isl_map
*map
;
1878 tok2
= isl_stream_next_token(s
);
1879 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
||
1880 isl_int_is_neg(tok2
->u
.v
)) {
1882 isl_stream_push_token(s
, tok2
);
1883 obj
.type
= isl_obj_int
;
1884 obj
.v
= isl_int_obj_alloc(s
->ctx
, tok
->u
.v
);
1885 isl_token_free(tok
);
1888 isl_stream_push_token(s
, tok2
);
1889 isl_stream_push_token(s
, tok
);
1890 map
= map_read_polylib(s
);
1893 if (isl_map_may_be_set(map
))
1894 obj
.v
= isl_map_range(map
);
1896 obj
.type
= isl_obj_map
;
1901 v
= vars_new(s
->ctx
);
1903 isl_stream_push_token(s
, tok
);
1906 map
= isl_map_universe(isl_space_params_alloc(s
->ctx
, 0));
1907 if (tok
->type
== '[') {
1908 isl_stream_push_token(s
, tok
);
1909 map
= read_tuple(s
, map
, isl_dim_param
, v
);
1912 tok
= isl_stream_next_token(s
);
1913 if (!tok
|| tok
->type
!= ISL_TOKEN_TO
) {
1914 isl_stream_error(s
, tok
, "expecting '->'");
1916 isl_stream_push_token(s
, tok
);
1919 isl_token_free(tok
);
1920 tok
= isl_stream_next_token(s
);
1922 if (!tok
|| tok
->type
!= '{') {
1923 isl_stream_error(s
, tok
, "expecting '{'");
1925 isl_stream_push_token(s
, tok
);
1928 isl_token_free(tok
);
1930 tok
= isl_stream_next_token(s
);
1933 else if (tok
->type
== ISL_TOKEN_IDENT
&& !strcmp(tok
->u
.s
, "Sym")) {
1934 isl_token_free(tok
);
1935 if (isl_stream_eat(s
, '='))
1937 map
= read_tuple(s
, map
, isl_dim_param
, v
);
1940 } else if (tok
->type
== '}') {
1941 obj
.type
= isl_obj_union_set
;
1942 obj
.v
= isl_union_set_empty(isl_map_get_space(map
));
1943 isl_token_free(tok
);
1946 isl_stream_push_token(s
, tok
);
1951 o
= obj_read_body(s
, isl_map_copy(map
), v
);
1952 if (o
.type
== isl_obj_none
|| !o
.v
)
1957 obj
= obj_add(s
->ctx
, obj
, o
);
1958 if (obj
.type
== isl_obj_none
|| !obj
.v
)
1961 tok
= isl_stream_next_token(s
);
1962 if (!tok
|| tok
->type
!= ';')
1964 isl_token_free(tok
);
1965 if (isl_stream_next_token_is(s
, '}')) {
1966 tok
= isl_stream_next_token(s
);
1971 if (tok
&& tok
->type
== '}') {
1972 isl_token_free(tok
);
1974 isl_stream_error(s
, tok
, "unexpected isl_token");
1976 isl_token_free(tok
);
1986 obj
.type
->free(obj
.v
);
1993 struct isl_obj
isl_stream_read_obj(struct isl_stream
*s
)
1998 __isl_give isl_map
*isl_stream_read_map(struct isl_stream
*s
)
2004 isl_assert(s
->ctx
, obj
.type
== isl_obj_map
||
2005 obj
.type
== isl_obj_set
, goto error
);
2007 if (obj
.type
== isl_obj_set
)
2008 obj
.v
= isl_map_from_range(obj
.v
);
2012 obj
.type
->free(obj
.v
);
2016 __isl_give isl_set
*isl_stream_read_set(struct isl_stream
*s
)
2022 if (obj
.type
== isl_obj_map
&& isl_map_may_be_set(obj
.v
)) {
2023 obj
.v
= isl_map_range(obj
.v
);
2024 obj
.type
= isl_obj_set
;
2026 isl_assert(s
->ctx
, obj
.type
== isl_obj_set
, goto error
);
2031 obj
.type
->free(obj
.v
);
2035 __isl_give isl_union_map
*isl_stream_read_union_map(struct isl_stream
*s
)
2040 if (obj
.type
== isl_obj_map
) {
2041 obj
.type
= isl_obj_union_map
;
2042 obj
.v
= isl_union_map_from_map(obj
.v
);
2044 if (obj
.type
== isl_obj_set
) {
2045 obj
.type
= isl_obj_union_set
;
2046 obj
.v
= isl_union_set_from_set(obj
.v
);
2048 if (obj
.v
&& obj
.type
== isl_obj_union_set
&&
2049 isl_union_set_is_empty(obj
.v
))
2050 obj
.type
= isl_obj_union_map
;
2051 if (obj
.v
&& obj
.type
!= isl_obj_union_map
)
2052 isl_die(s
->ctx
, isl_error_invalid
, "invalid input", goto error
);
2056 obj
.type
->free(obj
.v
);
2060 __isl_give isl_union_set
*isl_stream_read_union_set(struct isl_stream
*s
)
2065 if (obj
.type
== isl_obj_set
) {
2066 obj
.type
= isl_obj_union_set
;
2067 obj
.v
= isl_union_set_from_set(obj
.v
);
2070 isl_assert(s
->ctx
, obj
.type
== isl_obj_union_set
, goto error
);
2074 obj
.type
->free(obj
.v
);
2078 static __isl_give isl_basic_map
*basic_map_read(struct isl_stream
*s
)
2081 struct isl_map
*map
;
2082 struct isl_basic_map
*bmap
;
2089 isl_assert(map
->ctx
, map
->n
<= 1, goto error
);
2092 bmap
= isl_basic_map_empty_like_map(map
);
2094 bmap
= isl_basic_map_copy(map
->p
[0]);
2104 static __isl_give isl_basic_set
*basic_set_read(struct isl_stream
*s
)
2106 isl_basic_map
*bmap
;
2107 bmap
= basic_map_read(s
);
2110 if (!isl_basic_map_may_be_set(bmap
))
2111 isl_die(s
->ctx
, isl_error_invalid
,
2112 "input is not a set", goto error
);
2113 return isl_basic_map_range(bmap
);
2115 isl_basic_map_free(bmap
);
2119 __isl_give isl_basic_map
*isl_basic_map_read_from_file(isl_ctx
*ctx
,
2122 struct isl_basic_map
*bmap
;
2123 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2126 bmap
= basic_map_read(s
);
2131 __isl_give isl_basic_set
*isl_basic_set_read_from_file(isl_ctx
*ctx
,
2134 isl_basic_set
*bset
;
2135 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2138 bset
= basic_set_read(s
);
2143 struct isl_basic_map
*isl_basic_map_read_from_str(struct isl_ctx
*ctx
,
2146 struct isl_basic_map
*bmap
;
2147 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2150 bmap
= basic_map_read(s
);
2155 struct isl_basic_set
*isl_basic_set_read_from_str(struct isl_ctx
*ctx
,
2158 isl_basic_set
*bset
;
2159 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2162 bset
= basic_set_read(s
);
2167 __isl_give isl_map
*isl_map_read_from_file(struct isl_ctx
*ctx
,
2170 struct isl_map
*map
;
2171 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2174 map
= isl_stream_read_map(s
);
2179 __isl_give isl_map
*isl_map_read_from_str(struct isl_ctx
*ctx
,
2182 struct isl_map
*map
;
2183 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2186 map
= isl_stream_read_map(s
);
2191 __isl_give isl_set
*isl_set_read_from_file(struct isl_ctx
*ctx
,
2195 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2198 set
= isl_stream_read_set(s
);
2203 struct isl_set
*isl_set_read_from_str(struct isl_ctx
*ctx
,
2207 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2210 set
= isl_stream_read_set(s
);
2215 __isl_give isl_union_map
*isl_union_map_read_from_file(isl_ctx
*ctx
,
2218 isl_union_map
*umap
;
2219 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2222 umap
= isl_stream_read_union_map(s
);
2227 __isl_give isl_union_map
*isl_union_map_read_from_str(struct isl_ctx
*ctx
,
2230 isl_union_map
*umap
;
2231 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2234 umap
= isl_stream_read_union_map(s
);
2239 __isl_give isl_union_set
*isl_union_set_read_from_file(isl_ctx
*ctx
,
2242 isl_union_set
*uset
;
2243 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2246 uset
= isl_stream_read_union_set(s
);
2251 __isl_give isl_union_set
*isl_union_set_read_from_str(struct isl_ctx
*ctx
,
2254 isl_union_set
*uset
;
2255 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2258 uset
= isl_stream_read_union_set(s
);
2263 static __isl_give isl_vec
*isl_vec_read_polylib(struct isl_stream
*s
)
2265 struct isl_vec
*vec
= NULL
;
2266 struct isl_token
*tok
;
2270 tok
= isl_stream_next_token(s
);
2271 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2272 isl_stream_error(s
, tok
, "expecting vector length");
2276 size
= isl_int_get_si(tok
->u
.v
);
2277 isl_token_free(tok
);
2279 vec
= isl_vec_alloc(s
->ctx
, size
);
2281 for (j
= 0; j
< size
; ++j
) {
2282 tok
= isl_stream_next_token(s
);
2283 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2284 isl_stream_error(s
, tok
, "expecting constant value");
2287 isl_int_set(vec
->el
[j
], tok
->u
.v
);
2288 isl_token_free(tok
);
2293 isl_token_free(tok
);
2298 static __isl_give isl_vec
*vec_read(struct isl_stream
*s
)
2300 return isl_vec_read_polylib(s
);
2303 __isl_give isl_vec
*isl_vec_read_from_file(isl_ctx
*ctx
, FILE *input
)
2306 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2314 __isl_give isl_pw_qpolynomial
*isl_stream_read_pw_qpolynomial(
2315 struct isl_stream
*s
)
2321 isl_assert(s
->ctx
, obj
.type
== isl_obj_pw_qpolynomial
,
2326 obj
.type
->free(obj
.v
);
2330 __isl_give isl_pw_qpolynomial
*isl_pw_qpolynomial_read_from_str(isl_ctx
*ctx
,
2333 isl_pw_qpolynomial
*pwqp
;
2334 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2337 pwqp
= isl_stream_read_pw_qpolynomial(s
);
2342 __isl_give isl_pw_qpolynomial
*isl_pw_qpolynomial_read_from_file(isl_ctx
*ctx
,
2345 isl_pw_qpolynomial
*pwqp
;
2346 struct isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2349 pwqp
= isl_stream_read_pw_qpolynomial(s
);
2354 /* Read an affine expression from "s" with domain (space) "dom".
2355 * We call accept_affine to parse a possibly piecewise affine expression
2356 * and then check that the result is a single affine expression on
2357 * a universe domain.
2359 static __isl_give isl_aff
*read_aff_with_dom(struct isl_stream
*s
,
2360 __isl_take isl_set
*dom
, struct vars
*v
)
2362 isl_aff
*aff
= NULL
;
2363 isl_pw_aff
*pwaff
= NULL
;
2365 if (!isl_set_plain_is_universe(dom
))
2366 isl_die(s
->ctx
, isl_error_invalid
,
2367 "expecting universe domain", goto error
);
2369 if (!isl_set_is_params(dom
) && isl_stream_eat(s
, ISL_TOKEN_TO
))
2372 if (isl_stream_eat(s
, '['))
2375 pwaff
= accept_affine(s
, isl_set_get_space(dom
), v
);
2377 if (isl_stream_eat(s
, ']'))
2379 if (isl_stream_eat(s
, '}'))
2386 isl_die(s
->ctx
, isl_error_invalid
,
2387 "expecting single affine expression", goto error
);
2388 if (!isl_set_plain_is_universe(pwaff
->p
[0].set
))
2389 isl_die(s
->ctx
, isl_error_invalid
,
2390 "expecting universe domain", goto error
);
2392 aff
= isl_aff_copy(pwaff
->p
[0].aff
);
2395 isl_pw_aff_free(pwaff
);
2400 isl_pw_aff_free(pwaff
);
2405 /* Is the next token an identifer not in "v"?
2407 static int next_is_fresh_ident(struct isl_stream
*s
, struct vars
*v
)
2411 struct isl_token
*tok
;
2413 tok
= isl_stream_next_token(s
);
2416 fresh
= tok
->type
== ISL_TOKEN_IDENT
&& vars_pos(v
, tok
->u
.s
, -1) >= n
;
2417 isl_stream_push_token(s
, tok
);
2419 vars_drop(v
, v
->n
- n
);
2424 /* First read the domain of the affine expression, which may be
2425 * a parameter space or a set.
2426 * The tricky part is that we don't know if the domain is a set or not,
2427 * so when we are trying to read the domain, we may actually be reading
2428 * the affine expression itself (defined on a parameter domains)
2429 * If the tuple we are reading is named, we assume it's the domain.
2430 * Also, if inside the tuple, the first thing we find is a nested tuple
2431 * or a new identifier, we again assume it's the domain.
2432 * Otherwise, we assume we are reading an affine expression.
2434 static __isl_give isl_set
*read_aff_domain(struct isl_stream
*s
,
2435 __isl_take isl_set
*dom
, struct vars
*v
)
2437 struct isl_token
*tok
;
2439 tok
= isl_stream_next_token(s
);
2440 if (tok
&& (tok
->type
== ISL_TOKEN_IDENT
|| tok
->is_keyword
)) {
2441 isl_stream_push_token(s
, tok
);
2442 return read_tuple(s
, dom
, isl_dim_set
, v
);
2444 if (!tok
|| tok
->type
!= '[') {
2445 isl_stream_error(s
, tok
, "expecting '['");
2448 if (next_is_tuple(s
) || next_is_fresh_ident(s
, v
)) {
2449 isl_stream_push_token(s
, tok
);
2450 dom
= read_tuple(s
, dom
, isl_dim_set
, v
);
2452 isl_stream_push_token(s
, tok
);
2457 isl_stream_push_token(s
, tok
);
2463 /* Read an affine expression from "s".
2464 * We first read the domain of the affine expression, which may be
2465 * a parameter space or a set, and then call read_aff_with_dom.
2467 __isl_give isl_aff
*isl_stream_read_aff(struct isl_stream
*s
)
2470 isl_set
*dom
= NULL
;
2472 v
= vars_new(s
->ctx
);
2476 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
2477 if (next_is_tuple(s
)) {
2478 dom
= read_tuple(s
, dom
, isl_dim_param
, v
);
2479 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
2482 if (isl_stream_eat(s
, '{'))
2485 dom
= read_aff_domain(s
, dom
, v
);
2486 return read_aff_with_dom(s
, dom
, v
);
2493 /* Read a piecewise affine expression from "s" with domain (space) "dom".
2495 static __isl_give isl_pw_aff
*read_pw_aff_with_dom(struct isl_stream
*s
,
2496 __isl_take isl_set
*dom
, struct vars
*v
)
2498 isl_pw_aff
*pwaff
= NULL
;
2500 if (!isl_set_is_params(dom
) && isl_stream_eat(s
, ISL_TOKEN_TO
))
2503 if (isl_stream_eat(s
, '['))
2506 pwaff
= accept_affine(s
, isl_set_get_space(dom
), v
);
2508 if (isl_stream_eat(s
, ']'))
2511 dom
= read_optional_disjuncts(s
, dom
, v
);
2512 pwaff
= isl_pw_aff_intersect_domain(pwaff
, dom
);
2517 isl_pw_aff_free(pwaff
);
2521 __isl_give isl_pw_aff
*isl_stream_read_pw_aff(struct isl_stream
*s
)
2524 isl_set
*dom
= NULL
;
2526 isl_pw_aff
*pa
= NULL
;
2529 v
= vars_new(s
->ctx
);
2533 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
2534 if (next_is_tuple(s
)) {
2535 dom
= read_tuple(s
, dom
, isl_dim_param
, v
);
2536 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
2539 if (isl_stream_eat(s
, '{'))
2543 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
2544 pa
= read_pw_aff_with_dom(s
, aff_dom
, v
);
2545 vars_drop(v
, v
->n
- n
);
2547 while (isl_stream_eat_if_available(s
, ';')) {
2551 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
2552 pa_i
= read_pw_aff_with_dom(s
, aff_dom
, v
);
2553 vars_drop(v
, v
->n
- n
);
2555 pa
= isl_pw_aff_union_add(pa
, pa_i
);
2558 if (isl_stream_eat(s
, '}'))
2567 isl_pw_aff_free(pa
);
2571 __isl_give isl_aff
*isl_aff_read_from_str(isl_ctx
*ctx
, const char *str
)
2574 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2577 aff
= isl_stream_read_aff(s
);
2582 __isl_give isl_pw_aff
*isl_pw_aff_read_from_str(isl_ctx
*ctx
, const char *str
)
2585 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2588 pa
= isl_stream_read_pw_aff(s
);
2593 /* Read an isl_pw_multi_aff from "s".
2594 * We currently read a generic object and if it turns out to be a set or
2595 * a map, we convert that to an isl_pw_multi_aff.
2596 * It would be more efficient if we were to construct the isl_pw_multi_aff
2599 __isl_give isl_pw_multi_aff
*isl_stream_read_pw_multi_aff(struct isl_stream
*s
)
2607 if (obj
.type
== isl_obj_map
)
2608 return isl_pw_multi_aff_from_map(obj
.v
);
2609 if (obj
.type
== isl_obj_set
)
2610 return isl_pw_multi_aff_from_set(obj
.v
);
2612 obj
.type
->free(obj
.v
);
2613 isl_die(s
->ctx
, isl_error_invalid
, "unexpected object type",
2617 __isl_give isl_pw_multi_aff
*isl_pw_multi_aff_read_from_str(isl_ctx
*ctx
,
2620 isl_pw_multi_aff
*pma
;
2621 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2624 pma
= isl_stream_read_pw_multi_aff(s
);
2629 /* Read a multi-affine expression from "s".
2630 * We call isl_stream_read_pw_multi_aff to parse a possibly piecewise
2631 * multi-affine expression and then check that the result is
2632 * a single multi-affine expression on a universe domain.
2634 __isl_give isl_multi_aff
*isl_stream_read_multi_aff(struct isl_stream
*s
)
2636 isl_pw_multi_aff
*pma
;
2637 isl_multi_aff
*maff
;
2639 pma
= isl_stream_read_pw_multi_aff(s
);
2643 isl_die(s
->ctx
, isl_error_invalid
,
2644 "expecting single list of affine expressions",
2645 return isl_pw_multi_aff_free(pma
));
2646 if (!isl_set_plain_is_universe(pma
->p
[0].set
))
2647 isl_die(s
->ctx
, isl_error_invalid
, "expecting universe domain",
2648 return isl_pw_multi_aff_free(pma
));
2649 maff
= isl_multi_aff_copy(pma
->p
[0].maff
);
2650 isl_pw_multi_aff_free(pma
);
2654 __isl_give isl_multi_aff
*isl_multi_aff_read_from_str(isl_ctx
*ctx
,
2657 isl_multi_aff
*maff
;
2658 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2661 maff
= isl_stream_read_multi_aff(s
);
2666 __isl_give isl_union_pw_qpolynomial
*isl_stream_read_union_pw_qpolynomial(
2667 struct isl_stream
*s
)
2672 if (obj
.type
== isl_obj_pw_qpolynomial
) {
2673 obj
.type
= isl_obj_union_pw_qpolynomial
;
2674 obj
.v
= isl_union_pw_qpolynomial_from_pw_qpolynomial(obj
.v
);
2677 isl_assert(s
->ctx
, obj
.type
== isl_obj_union_pw_qpolynomial
,
2682 obj
.type
->free(obj
.v
);
2686 __isl_give isl_union_pw_qpolynomial
*isl_union_pw_qpolynomial_read_from_str(
2687 isl_ctx
*ctx
, const char *str
)
2689 isl_union_pw_qpolynomial
*upwqp
;
2690 struct isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2693 upwqp
= isl_stream_read_union_pw_qpolynomial(s
);