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
)
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"
32 "static unsigned h;\n"
39 " unsigned char c[1];\n"
42 " for (i = 0; i < sizeof(int); ++i) {\n"
50 " unsigned h_good, h_test;\n";
53 static const char postamble
[] =
58 static const char *call
[] = {"good", "test"};
60 static void print_macros(FILE *file
)
62 fprintf(file
, "/* Useful macros. */\n") ;
64 "#define floord(n,d) (((n)<0) ? -((-(n)+(d)-1)/(d)) : (n)/(d))\n");
66 "#define ceild(n,d) (((n)<0) ? -((-(n))/(d)) : ((n)+(d)-1)/(d))\n");
67 fprintf(file
, "#define max(x,y) ((x) > (y) ? (x) : (y))\n") ;
68 fprintf(file
, "#define min(x,y) ((x) < (y) ? (x) : (y))\n\n") ;
76 CloogState
*state
= cloog_state_malloc();
77 CloogOptions
*options
= cloog_options_malloc(state
);
79 CloogDomain
*cube
, *tmp
;
81 CloogStatement
*statement
;
85 domain
= get_param_domain(options
);
86 dim
= cloog_domain_dimension(domain
);
97 cloog_int_set_si(m
, 0);
98 cloog_int_set_si(M
, range
);
99 cube
= cloog_domain_cube(state
, dim
, m
, M
);
100 domain
= cloog_domain_intersection(tmp
= domain
, cube
);
101 cloog_domain_free(tmp
);
102 cloog_domain_free(cube
);
104 p
= cloog_program_malloc();
106 p
->names
= cloog_names_malloc();
108 p
->names
->nb_iterators
= dim
;
109 p
->names
->iterators
= cloog_names_generate_items(dim
, "p", 0);
111 p
->context
= cloog_domain_universe(state
, 0);
112 statement
= cloog_statement_alloc(state
, 1);
113 p
->loop
= cloog_loop_malloc(state
);
114 p
->loop
->domain
= domain
;
115 p
->loop
->block
= cloog_block_alloc(statement
, 0, NULL
, dim
);
116 p
->blocklist
= cloog_block_list_alloc(p
->loop
->block
);
117 p
= cloog_program_generate(p
, options
);
119 printf("%s", preamble
);
120 for (i
= 0; i
< dim
; ++i
)
121 printf("\tint %s;\n", p
->names
->iterators
[i
]);
122 printf("#define S1(");
123 for (i
= 0; i
< dim
; ++i
) {
129 for (j
= 0; j
< 2; ++j
) {
130 printf(" h = 2166136261u;");
131 printf(" %s(", call
[j
]);
132 for (i
= 0; i
< dim
; ++i
) {
138 printf(" h_%s = h;", call
[j
]);
140 printf(" assert(h_good == h_test);");
141 printf(" } while (0)\n");
142 print_macros(stdout
);
143 cloog_program_pprint(stdout
, p
, options
);
144 printf("%s", postamble
);
148 cloog_program_free(p
);
149 cloog_options_free(options
);
150 cloog_state_free(state
);