2 * Copyright 2017 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
12 #include <isl/options.h>
13 #include <isl/union_map.h>
14 #include <isl/stream.h>
17 struct isl_options
*isl
;
22 ISL_ARGS_START(struct options
, options_args
)
23 ISL_ARG_CHILD(struct options
, isl
, "isl", &isl_options_args
, "isl options")
24 ISL_ARG_ARG(struct options
, flow1
, "flow1", NULL
)
25 ISL_ARG_ARG(struct options
, flow2
, "flow2", NULL
)
28 ISL_ARG_DEF(options
, struct options
, options_args
)
30 static void die(const char *msg
)
32 fprintf(stderr
, "%s\n", msg
);
36 static FILE *open_or_die(const char *filename
)
40 file
= fopen(filename
, "r");
42 fprintf(stderr
, "Unable to open %s\n", filename
);
49 #define BASE union_map
50 #include "read_in_string_templ.c"
52 /* Given two YAML descriptions of isl_union_flow objects, check whether
53 * they are equivalent.
54 * Return EXIT_SUCCESS if they are and EXIT_FAILURE if they are not
55 * or if anything else went wrong.
57 * The descriptions are checked field by field, meaning that the fields
58 * are expected to appear in the same order in both inputs.
60 int main(int argc
, char **argv
)
64 struct options
*options
;
65 FILE *input1
, *input2
;
68 options
= options_new_with_defaults();
72 ctx
= isl_ctx_alloc_with_options(&options_args
, options
);
73 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
75 input1
= open_or_die(options
->flow1
);
76 input2
= open_or_die(options
->flow2
);
77 s1
= isl_stream_new_file(ctx
, input1
);
78 s2
= isl_stream_new_file(ctx
, input2
);
80 if (isl_stream_yaml_read_start_mapping(s1
))
81 isl_die(ctx
, isl_error_unknown
, "arg1 not a YAML mapping",
83 if (isl_stream_yaml_read_start_mapping(s2
))
84 isl_die(ctx
, isl_error_unknown
, "arg2 not a YAML mapping",
87 while ((more
= isl_stream_yaml_next(s1
)) > 0) {
90 isl_union_map
*umap1
, *umap2
;
92 more2
= isl_stream_yaml_next(s2
);
96 isl_die(ctx
, isl_error_unknown
, "arg2 shorter",
98 if (isl_stream_eat(s1
, ISL_TOKEN_IDENT
) < 0)
100 if (isl_stream_eat(s2
, ISL_TOKEN_IDENT
) < 0)
102 more
= isl_stream_yaml_next(s1
);
103 more2
= isl_stream_yaml_next(s2
);
104 if (more
< 0 || more2
< 0)
107 isl_die(ctx
, isl_error_unknown
, "missing value",
108 return EXIT_FAILURE
);
110 umap1
= read_union_map(s1
);
111 umap2
= read_union_map(s2
);
112 equal
= isl_union_map_is_equal(umap1
, umap2
);
113 isl_union_map_free(umap1
);
114 isl_union_map_free(umap2
);
118 die("field not equal");
124 if (isl_stream_yaml_read_end_mapping(s1
) < 0) {
125 isl_stream_error(s1
, NULL
, "unexpected extra elements");
128 if (isl_stream_yaml_read_end_mapping(s2
) < 0) {
129 isl_stream_error(s2
, NULL
, "unexpected extra elements");