Fix system isl include path
[cloog.git] / test / generate_test.c
blobb4ef043d90f090c76b9587bec3e62ee30af3fb33
1 #include <stdio.h>
2 #include <cloog/cloog.h>
4 /* Generate code that scans part of the parameter domain of
5 * a given cloog problem, running both a function called "good"
6 * and a function called "test" for each value of the parameters.
7 * These functions are assumed to call the "hash" function,
8 * which is also generated by this program.
9 * If for any given value of the parameters, the final hash
10 * value computed by test is different from that computed by
11 * good, then an error is reported.
14 CloogDomain *get_param_domain(CloogOptions *options)
16 CloogDomain *domain;
17 CloogProgram *program;
19 program = cloog_program_read(stdin, options);
21 domain = cloog_domain_copy(program->context);
23 cloog_program_free(program);
25 return cloog_domain_from_context(domain);
28 static const char preamble[] =
29 "#include <assert.h>\n"
30 "#include <stdio.h>\n"
31 "\n"
32 "static unsigned h;\n"
33 "\n"
34 "void hash(int v)\n"
35 "{\n"
36 " int i;\n"
37 " union u {\n"
38 " int v;\n"
39 " unsigned char c[1];\n"
40 " } u;\n"
41 " u.v = v;\n"
42 " for (i = 0; i < sizeof(int); ++i) {\n"
43 " h *= 16777619;\n"
44 " h ^= u.c[i];\n"
45 " }\n"
46 "}\n"
47 "\n"
48 "int main()\n"
49 "{\n"
50 " unsigned h_good, h_test;\n";
53 static const char postamble[] =
54 " return 0;\n"
55 "}\n"
58 static const char *call[] = {"good", "test"};
60 int main()
62 int dim;
63 int range;
64 int i, j;
65 CloogState *state = cloog_state_malloc();
66 CloogOptions *options = cloog_options_malloc(state);
67 CloogDomain *domain;
68 CloogDomain *cube, *tmp;
69 CloogProgram *p;
70 CloogStatement *statement;
71 cloog_int_t m, M;
73 options->quiet = 1;
74 domain = get_param_domain(options);
75 dim = cloog_domain_dimension(domain);
77 if (dim >= 8)
78 range = 4;
79 else if (dim >= 5)
80 range = 6;
81 else
82 range = 30;
84 cloog_int_init(m);
85 cloog_int_init(M);
86 cloog_int_set_si(m, 0);
87 cloog_int_set_si(M, range);
88 cube = cloog_domain_cube(state, dim, m, M);
89 domain = cloog_domain_intersection(tmp = domain, cube);
90 cloog_domain_free(tmp);
91 cloog_domain_free(cube);
93 p = cloog_program_malloc();
94 assert(p);
95 p->names = cloog_names_malloc();
96 assert(p->names);
97 p->names->nb_iterators = dim;
98 p->names->iterators = cloog_names_generate_items(dim, "p", 0);
99 p->language = 'c';
100 p->context = cloog_domain_universe(state, 0);
101 statement = cloog_statement_alloc(state, 1);
102 p->loop = cloog_loop_malloc(state);
103 p->loop->domain = domain;
104 p->loop->block = cloog_block_alloc(statement, 0, NULL, dim);
105 p->blocklist = cloog_block_list_alloc(p->loop->block);
106 p = cloog_program_generate(p, options);
108 printf("%s", preamble);
109 for (i = 0; i < dim; ++i)
110 printf("\tint %s;\n", p->names->iterators[i]);
111 printf("#define S1(");
112 for (i = 0; i < dim; ++i) {
113 if (i)
114 printf(",");
115 printf("p%d", i);
117 printf(") do {");
118 for (j = 0; j < 2; ++j) {
119 printf(" h = 2166136261u;");
120 printf(" %s(", call[j]);
121 for (i = 0; i < dim; ++i) {
122 if (i)
123 printf(", ");
124 printf("p%d", i);
126 printf(");");
127 printf(" h_%s = h;", call[j]);
129 printf(" assert(h_good == h_test);");
130 printf(" } while (0)\n");
131 cloog_program_pprint(stdout, p, options);
132 printf("%s", postamble);
134 cloog_int_clear(m);
135 cloog_int_clear(M);
136 cloog_program_free(p);
137 cloog_options_free(options);
138 cloog_state_free(state);
140 return 0;