Update library usage examples
[cloog.git] / examples / example / example-isl.c
blob6dede4caac5c4d2a762904e8a234f68798011899
1 /* example-isl.c */
2 #include <cloog/cloog.h>
3 #include <cloog/isl/cloog.h>
5 /* Input problem */
6 int nb_parameters = 1;
7 char *parameter_name[] = {"N"};
8 char *iterator_name[] = {"i", "j"};
9 char *scattering_name[] = {"t0", "t1", "t2"};
10 char *str_context = "[N] -> { : N > 0}";
11 char *str_domain1 = "[N] -> {[i, j] : 0 <= i < N and 0 <= j < N}";
12 char *str_domain2 = "[N] -> {[i, j] : 0 <= i < N and 0 <= j < N}";
13 char *str_scattering1 = "[N] -> {[i, j] -> [0, i + j, j]}";
14 char *str_scattering2 = "[N] -> {[i, j] -> [1, i, -j]}";
16 int main() {
17 isl_ctx *ctx;
18 isl_set *set_context, *set1, *set2;
19 isl_map *map1, *map2;
20 CloogDomain *context, *domain1, *domain2;
21 CloogScattering *scattering1, *scattering2;
22 CloogUnionDomain *domains;
23 CloogInput *input;
24 CloogState *state;
25 CloogOptions *options;
26 struct clast_stmt *root;
28 /* Build isl structures for context, sets and mapping */
29 ctx = isl_ctx_alloc();
30 set_context = isl_set_read_from_str(ctx, str_context);
31 set1 = isl_set_read_from_str(ctx, str_domain1);
32 set2 = isl_set_read_from_str(ctx, str_domain2);
33 map1 = isl_map_read_from_str(ctx, str_scattering1);
34 map2 = isl_map_read_from_str(ctx, str_scattering2);
36 /* Translate them to CLooG context, domains and scattering */
37 context = cloog_domain_from_isl_set(set_context);
38 domain1 = cloog_domain_from_isl_set(set1);
39 domain2 = cloog_domain_from_isl_set(set2);
40 scattering1 = cloog_scattering_from_isl_map(map1);
41 scattering2 = cloog_scattering_from_isl_map(map2);
43 /* Prepare the list of domains to scan */
44 domains = cloog_union_domain_alloc(nb_parameters);
45 cloog_union_domain_add_domain(domains, "S1", domain1, scattering1, NULL);
46 cloog_union_domain_add_domain(domains, "S2", domain2, scattering2, NULL);
47 cloog_union_domain_set_name(domains, CLOOG_PARAM, 0, parameter_name[0]);
48 cloog_union_domain_set_name(domains, CLOOG_ITER, 0, iterator_name[0]);
49 cloog_union_domain_set_name(domains, CLOOG_ITER, 1, iterator_name[1]);
50 cloog_union_domain_set_name(domains, CLOOG_SCAT, 0, scattering_name[0]);
51 cloog_union_domain_set_name(domains, CLOOG_SCAT, 1, scattering_name[1]);
52 cloog_union_domain_set_name(domains, CLOOG_SCAT, 2, scattering_name[2]);
54 /* Build the input, generate the AST of the scanning code and print it */
55 input = cloog_input_alloc(context, domains);
56 state = cloog_isl_state_malloc(ctx);
57 options = cloog_options_malloc(state);
58 root = cloog_clast_create_from_input(input, options);
59 clast_pprint(stdout, root, 0, options);
61 /* Recycle allocated memory */
62 cloog_clast_free(root);
63 cloog_options_free(options);
64 cloog_state_free(state);
65 isl_ctx_free(ctx);