#include <stdio.h>
#include <string.h>
#include <strings.h>
+#include <isl_ctx_private.h>
#include <isl_map_private.h>
#include <isl/set.h>
#include <isl/seq.h>
return bmap;
}
+/* Obtain next token, with some preprocessing.
+ * In particular, evaluate expressions of the form x^y,
+ * with x and y values.
+ */
+static struct isl_token *next_token(struct isl_stream *s)
+{
+ struct isl_token *tok, *tok2;
+
+ tok = isl_stream_next_token(s);
+ if (!tok || tok->type != ISL_TOKEN_VALUE)
+ return tok;
+ if (!isl_stream_eat_if_available(s, '^'))
+ return tok;
+ tok2 = isl_stream_next_token(s);
+ if (!tok2 || tok2->type != ISL_TOKEN_VALUE) {
+ isl_stream_error(s, tok2, "expecting constant value");
+ goto error;
+ }
+
+ isl_int_pow_ui(tok->u.v, tok->u.v, isl_int_get_ui(tok2->u.v));
+
+ isl_token_free(tok2);
+ return tok;
+error:
+ isl_token_free(tok);
+ isl_token_free(tok2);
+ return NULL;
+}
+
static int accept_cst_factor(struct isl_stream *s, isl_int *f)
{
struct isl_token *tok;
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok || tok->type != ISL_TOKEN_VALUE) {
isl_stream_error(s, tok, "expecting constant value");
goto error;
struct variable *var;
isl_vec *mod;
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok || tok->type != ISL_TOKEN_VALUE) {
isl_stream_error(s, tok, "expecting constant value");
goto error;
struct isl_token *tok = NULL;
isl_vec *aff = NULL;
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
goto error;
tok = NULL;
if (read_div_definition(s, v) < 0)
goto error;
+ aff = isl_vec_zero_extend(aff, 1 + v->n);
} else {
isl_stream_error(s, tok, "expecting factor");
goto error;
isl_seq_clr(aff->el, aff->size);
for (;;) {
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
goto error;
}
isl_token_free(tok);
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (tok && tok->type == '-') {
sign = -sign;
isl_token_free(tok);
int i = 0;
struct isl_token *tok;
- while ((tok = isl_stream_next_token(s)) != NULL) {
+ while ((tok = next_token(s)) != NULL) {
int new_name = 0;
if (tok->type == ISL_TOKEN_IDENT) {
if (isl_stream_eat(s, '/'))
return -1;
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok)
return -1;
if (tok->type != ISL_TOKEN_VALUE) {
}
}
+/* Add any variables in the variable list "v" that are not already in "bmap"
+ * as output variables in "bmap".
+ */
+static __isl_give isl_basic_map *add_lifted_divs(__isl_take isl_basic_map *bmap,
+ struct vars *v)
+{
+ int i;
+ int extra;
+ struct variable *var;
+
+ extra = v->n - isl_basic_map_total_dim(bmap);
+
+ if (extra == 0)
+ return bmap;
+
+ bmap = isl_basic_map_add(bmap, isl_dim_out, extra);
+ bmap = isl_basic_map_extend_dim(bmap, isl_basic_map_get_dim(bmap),
+ 0, 0, 2 * extra);
+
+ for (i = 0, var = v->v; i < extra; ++i, var = var->next) {
+ var->def = isl_vec_zero_extend(var->def, 2 + v->n);
+ if (!var->def)
+ goto error;
+ if (isl_basic_map_add_div_constraints_var(bmap, var->pos,
+ var->def->el) < 0)
+ goto error;
+ }
+
+ return bmap;
+error:
+ isl_basic_map_free(bmap);
+ return NULL;
+}
+
static struct isl_basic_map *add_constraint(struct isl_stream *s,
struct vars *v, struct isl_basic_map *bmap)
{
aff1 = isl_mat_add_zero_cols(aff1, aff2->n_col - aff1->n_col);
if (!aff1)
goto error;
- bmap = add_divs(bmap, v);
+ bmap = add_lifted_divs(bmap, v);
bmap = isl_basic_map_extend_constraints(bmap, 0,
aff1->n_row * aff2->n_row);
for (i = 0; i < aff1->n_row; ++i)
if (!bmap)
return NULL;
+ bmap = isl_basic_set_unwrap(isl_basic_set_lift(isl_basic_map_wrap(bmap)));
+
bmap = add_constraint(s, v, bmap);
bmap = isl_basic_map_simplify(bmap);
bmap = isl_basic_map_finalize(bmap);
+ bmap = isl_basic_set_unwrap(isl_basic_map_domain(bmap));
+
vars_drop(v, v->n - n);
return isl_map_from_basic_map(bmap);
-error:
- isl_basic_map_free(bmap);
- return NULL;
}
static struct isl_map *read_disjuncts(struct isl_stream *s,
struct isl_qpolynomial *qp;
struct isl_token *tok;
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
tok2 = isl_stream_next_token(s);
if (tok2 && tok2->type == '/') {
isl_token_free(tok2);
- tok2 = isl_stream_next_token(s);
+ tok2 = next_token(s);
if (!tok2 || tok2->type != ISL_TOKEN_VALUE) {
isl_stream_error(s, tok2, "expected denominator");
isl_token_free(tok);
qp = read_factor(s, bmap, v);
for (;;) {
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok)
return qp;
struct vars *v = NULL;
struct isl_obj obj = { isl_obj_set, NULL };
- tok = isl_stream_next_token(s);
+ tok = next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
goto error;
return NULL;
}
+__isl_give isl_union_map *isl_union_map_read_from_file(isl_ctx *ctx,
+ FILE *input)
+{
+ isl_union_map *umap;
+ struct isl_stream *s = isl_stream_new_file(ctx, input);
+ if (!s)
+ return NULL;
+ umap = isl_stream_read_union_map(s);
+ isl_stream_free(s);
+ return umap;
+}
+
__isl_give isl_union_map *isl_union_map_read_from_str(struct isl_ctx *ctx,
const char *str)
{
return umap;
}
+__isl_give isl_union_set *isl_union_set_read_from_file(isl_ctx *ctx,
+ FILE *input)
+{
+ isl_union_set *uset;
+ struct isl_stream *s = isl_stream_new_file(ctx, input);
+ if (!s)
+ return NULL;
+ uset = isl_stream_read_union_set(s);
+ isl_stream_free(s);
+ return uset;
+}
+
__isl_give isl_union_set *isl_union_set_read_from_str(struct isl_ctx *ctx,
const char *str)
{
return NULL;
}
-static __isl_give isl_vec *vec_read(struct isl_stream *s,
- unsigned input_format)
+static __isl_give isl_vec *vec_read(struct isl_stream *s)
{
- if (input_format == ISL_FORMAT_POLYLIB)
- return isl_vec_read_polylib(s);
- isl_assert(s->ctx, 0, return NULL);
+ return isl_vec_read_polylib(s);
}
-struct isl_vec *isl_vec_read_from_file(struct isl_ctx *ctx,
- FILE *input, unsigned input_format)
+__isl_give isl_vec *isl_vec_read_from_file(isl_ctx *ctx, FILE *input)
{
isl_vec *v;
struct isl_stream *s = isl_stream_new_file(ctx, input);
if (!s)
return NULL;
- v = vec_read(s, input_format);
+ v = vec_read(s);
isl_stream_free(s);
return v;
}