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