summaryrefslogtreecommitdiff
path: root/polly/lib/External/isl/isl_multi_read_no_explicit_domain_templ.c
blob: 6baf562ad685785ab739643d89e5e7bdf70976e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright 2013      Ecole Normale Superieure
 *
 * Use of this software is governed by the MIT license
 *
 * Written by Sven Verdoolaege,
 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
 */

#include <isl/space.h>
#include <isl/set.h>

#include <isl_multi_macro.h>

/* This function is called for each element in a tuple inside
 * isl_stream_read_multi_*.
 * Read an EL from "s" and add it to *list.
 */
static __isl_give isl_space *FN(read_el,BASE)(__isl_keep isl_stream *s,
	struct vars *v, __isl_take isl_space *space, int rational, void *user)
{
	LIST(EL) **list = (LIST(EL) **) user;
	EL *el;

	el = FN(isl_stream_read,BASE)(s);
	*list = FN(LIST(EL),add)(*list, el);
	if (!*list)
		return isl_space_free(space);

	return space;
}

/* Read a multi expression from "s".
 *
 * We first read a tuple space, collecting the element values in a list.
 * Then we create an isl_multi_* from the space and the isl_*_list.
 */
__isl_give MULTI(BASE) *FN(isl_stream_read_multi,BASE)(
	__isl_keep isl_stream *s)
{
	struct vars *v;
	isl_set *dom = NULL;
	isl_space *space;
	MULTI(BASE) *multi = NULL;
	LIST(EL) *list;

	v = vars_new(s->ctx);
	if (!v)
		return NULL;

	dom = isl_set_universe(isl_space_params_alloc(s->ctx, 0));
	if (next_is_tuple(s)) {
		dom = read_map_tuple(s, dom, isl_dim_param, v, 1, 0);
		if (isl_stream_eat(s, ISL_TOKEN_TO))
			goto error;
	}
	if (!isl_set_plain_is_universe(dom))
		isl_die(s->ctx, isl_error_invalid,
			"expecting universe parameter domain", goto error);
	if (isl_stream_eat(s, '{'))
		goto error;

	space = isl_set_get_space(dom);

	list = FN(LIST(EL),alloc)(s->ctx, 0);
	space = read_tuple_space(s, v, space, 1, 0, &FN(read_el,BASE), &list);
	multi = FN(FN(MULTI(BASE),from),LIST(BASE))(space, list);

	if (isl_stream_eat(s, '}'))
		goto error;

	vars_free(v);
	isl_set_free(dom);
	return multi;
error:
	vars_free(v);
	isl_set_free(dom);
	FN(MULTI(BASE),free)(multi);
	return NULL;
}

#undef TYPE_BASE
#define TYPE_BASE	CAT(multi_,BASE)
#include "isl_read_from_str_templ.c"