xref: /llvm-project/polly/lib/External/isl/schedule_cmp.c (revision 8b40f8c6c7d48de36acfd6870bb7c837a8acf358)
1*8b40f8c6STobias Grosser /*
2*8b40f8c6STobias Grosser  * Copyright 2017      Sven Verdoolaege
3*8b40f8c6STobias Grosser  *
4*8b40f8c6STobias Grosser  * Use of this software is governed by the MIT license
5*8b40f8c6STobias Grosser  *
6*8b40f8c6STobias Grosser  * Written by Sven Verdoolaege.
7*8b40f8c6STobias Grosser  */
8*8b40f8c6STobias Grosser 
9*8b40f8c6STobias Grosser #include <stdlib.h>
10*8b40f8c6STobias Grosser 
11*8b40f8c6STobias Grosser #include <isl/arg.h>
12*8b40f8c6STobias Grosser #include <isl/options.h>
13*8b40f8c6STobias Grosser #include <isl/schedule.h>
14*8b40f8c6STobias Grosser 
15*8b40f8c6STobias Grosser struct options {
16*8b40f8c6STobias Grosser 	struct isl_options *isl;
17*8b40f8c6STobias Grosser 	char *schedule1;
18*8b40f8c6STobias Grosser 	char *schedule2;
19*8b40f8c6STobias Grosser };
20*8b40f8c6STobias Grosser 
ISL_ARGS_START(struct options,options_args)21*8b40f8c6STobias Grosser ISL_ARGS_START(struct options, options_args)
22*8b40f8c6STobias Grosser ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
23*8b40f8c6STobias Grosser ISL_ARG_ARG(struct options, schedule1, "schedule1", NULL)
24*8b40f8c6STobias Grosser ISL_ARG_ARG(struct options, schedule2, "schedule2", NULL)
25*8b40f8c6STobias Grosser ISL_ARGS_END
26*8b40f8c6STobias Grosser 
27*8b40f8c6STobias Grosser ISL_ARG_DEF(options, struct options, options_args)
28*8b40f8c6STobias Grosser 
29*8b40f8c6STobias Grosser static void die(const char *msg)
30*8b40f8c6STobias Grosser {
31*8b40f8c6STobias Grosser 	fprintf(stderr, "%s\n", msg);
32*8b40f8c6STobias Grosser 	exit(EXIT_FAILURE);
33*8b40f8c6STobias Grosser }
34*8b40f8c6STobias Grosser 
open_or_die(const char * filename)35*8b40f8c6STobias Grosser static FILE *open_or_die(const char *filename)
36*8b40f8c6STobias Grosser {
37*8b40f8c6STobias Grosser 	FILE *file;
38*8b40f8c6STobias Grosser 
39*8b40f8c6STobias Grosser 	file = fopen(filename, "r");
40*8b40f8c6STobias Grosser 	if (!file) {
41*8b40f8c6STobias Grosser 		fprintf(stderr, "Unable to open %s\n", filename);
42*8b40f8c6STobias Grosser 		exit(EXIT_FAILURE);
43*8b40f8c6STobias Grosser 	}
44*8b40f8c6STobias Grosser 	return file;
45*8b40f8c6STobias Grosser }
46*8b40f8c6STobias Grosser 
47*8b40f8c6STobias Grosser /* Given two YAML descriptions of isl_schedule objects, check whether
48*8b40f8c6STobias Grosser  * they are equivalent.
49*8b40f8c6STobias Grosser  * Return EXIT_SUCCESS if they are and EXIT_FAILURE if they are not
50*8b40f8c6STobias Grosser  * or if anything else went wrong.
51*8b40f8c6STobias Grosser  */
main(int argc,char ** argv)52*8b40f8c6STobias Grosser int main(int argc, char **argv)
53*8b40f8c6STobias Grosser {
54*8b40f8c6STobias Grosser 	isl_ctx *ctx;
55*8b40f8c6STobias Grosser 	struct options *options;
56*8b40f8c6STobias Grosser 	FILE *input1, *input2;
57*8b40f8c6STobias Grosser 	isl_bool equal;
58*8b40f8c6STobias Grosser 	isl_schedule *s1, *s2;
59*8b40f8c6STobias Grosser 
60*8b40f8c6STobias Grosser 	options = options_new_with_defaults();
61*8b40f8c6STobias Grosser 	if (!options)
62*8b40f8c6STobias Grosser 		return EXIT_FAILURE;
63*8b40f8c6STobias Grosser 
64*8b40f8c6STobias Grosser 	ctx = isl_ctx_alloc_with_options(&options_args, options);
65*8b40f8c6STobias Grosser 	argc = options_parse(options, argc, argv, ISL_ARG_ALL);
66*8b40f8c6STobias Grosser 
67*8b40f8c6STobias Grosser 	input1 = open_or_die(options->schedule1);
68*8b40f8c6STobias Grosser 	input2 = open_or_die(options->schedule2);
69*8b40f8c6STobias Grosser 	s1 = isl_schedule_read_from_file(ctx, input1);
70*8b40f8c6STobias Grosser 	s2 = isl_schedule_read_from_file(ctx, input2);
71*8b40f8c6STobias Grosser 
72*8b40f8c6STobias Grosser 	equal = isl_schedule_plain_is_equal(s1, s2);
73*8b40f8c6STobias Grosser 	if (equal < 0)
74*8b40f8c6STobias Grosser 		return EXIT_FAILURE;
75*8b40f8c6STobias Grosser 	if (!equal)
76*8b40f8c6STobias Grosser 		die("schedules differ");
77*8b40f8c6STobias Grosser 
78*8b40f8c6STobias Grosser 	isl_schedule_free(s1);
79*8b40f8c6STobias Grosser 	isl_schedule_free(s2);
80*8b40f8c6STobias Grosser 	fclose(input1);
81*8b40f8c6STobias Grosser 	fclose(input2);
82*8b40f8c6STobias Grosser 	isl_ctx_free(ctx);
83*8b40f8c6STobias Grosser 
84*8b40f8c6STobias Grosser 	return EXIT_SUCCESS;
85*8b40f8c6STobias Grosser }
86