5 #include <isl/union_set.h>
12 ISL_ARGS_START(struct options
, options_args
)
13 ISL_ARG_ARG(struct options
, eqv1
, "eqv1", NULL
)
14 ISL_ARG_ARG(struct options
, eqv2
, "eqv2", NULL
)
17 ISL_ARG_DEF(options
, struct options
, options_args
)
22 isl_union_set
*proved
;
23 isl_union_set
*not_proved
;
26 static void *eqv_free(struct eqv
*eqv
)
31 isl_union_set_free(eqv
->only1
);
32 isl_union_set_free(eqv
->only2
);
33 isl_union_set_free(eqv
->proved
);
34 isl_union_set_free(eqv
->not_proved
);
40 static __isl_give isl_union_set
*extract_set(isl_ctx
*ctx
,
41 yaml_document_t
*document
, yaml_node_t
*node
)
43 if (node
->type
!= YAML_SCALAR_NODE
)
44 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
47 return isl_union_set_read_from_str(ctx
,
48 (char *) node
->data
.scalar
.value
);
51 static struct eqv
*extract_eqv(isl_ctx
*ctx
, yaml_document_t
*document
,
55 yaml_node_pair_t
* pair
;
60 if (node
->type
!= YAML_MAPPING_NODE
)
61 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
64 eqv
= isl_calloc_type(ctx
, struct eqv
);
68 for (pair
= node
->data
.mapping
.pairs
.start
;
69 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
70 yaml_node_t
*key
, *value
;
72 key
= yaml_document_get_node(document
, pair
->key
);
73 value
= yaml_document_get_node(document
, pair
->value
);
75 if (key
->type
!= YAML_SCALAR_NODE
)
76 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
77 return eqv_free(eqv
));
78 if (!strcmp((char *) key
->data
.scalar
.value
,
79 "Equivalence proved"))
80 eqv
->proved
= extract_set(ctx
, document
, value
);
81 if (!strcmp((char *) key
->data
.scalar
.value
,
82 "Equivalence NOT proved"))
83 eqv
->not_proved
= extract_set(ctx
, document
, value
);
84 if (!strcmp((char *) key
->data
.scalar
.value
,
86 eqv
->only1
= extract_set(ctx
, document
, value
);
87 if (!strcmp((char *) key
->data
.scalar
.value
,
89 eqv
->only2
= extract_set(ctx
, document
, value
);
95 static struct eqv
*eqv_parse(isl_ctx
*ctx
, FILE *in
)
97 struct eqv
*eqv
= NULL
;
100 yaml_document_t document
= { 0 };
102 yaml_parser_initialize(&parser
);
104 yaml_parser_set_input_file(&parser
, in
);
106 if (!yaml_parser_load(&parser
, &document
))
109 root
= yaml_document_get_root_node(&document
);
111 eqv
= extract_eqv(ctx
, &document
, root
);
113 yaml_document_delete(&document
);
115 yaml_parser_delete(&parser
);
119 yaml_parser_delete(&parser
);
124 static int eqv_is_equal(struct eqv
*eqv1
, struct eqv
*eqv2
)
129 if (!eqv1
->only1
!= !eqv2
->only1
)
131 if (!isl_union_set_is_equal(eqv1
->only1
, eqv2
->only1
)) {
132 isl_union_set_dump(eqv1
->only1
);
133 isl_union_set_dump(eqv2
->only1
);
137 if (!eqv1
->only2
!= !eqv2
->only2
)
139 if (!isl_union_set_is_equal(eqv1
->only2
, eqv2
->only2
)) {
140 isl_union_set_dump(eqv1
->only2
);
141 isl_union_set_dump(eqv2
->only2
);
145 if (!eqv1
->proved
!= !eqv2
->proved
)
147 if (!isl_union_set_is_equal(eqv1
->proved
, eqv2
->proved
)) {
148 isl_union_set_dump(eqv1
->proved
);
149 isl_union_set_dump(eqv2
->proved
);
153 if (!eqv1
->not_proved
!= !eqv2
->not_proved
)
155 if (!isl_union_set_is_equal(eqv1
->not_proved
, eqv2
->not_proved
)) {
156 isl_union_set_dump(eqv1
->not_proved
);
157 isl_union_set_dump(eqv2
->not_proved
);
164 int main(int argc
, char **argv
)
167 struct options
*options
;
168 struct eqv
*eqv1
, *eqv2
;
172 options
= options_new_with_defaults();
174 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
175 ctx
= isl_ctx_alloc_with_options(&options_args
, options
);
177 file1
= fopen(options
->eqv1
, "r");
179 file2
= fopen(options
->eqv2
, "r");
182 eqv1
= eqv_parse(ctx
, file1
);
183 eqv2
= eqv_parse(ctx
, file2
);
185 equal
= eqv_is_equal(eqv1
, eqv2
);
194 return equal
? 0 : 1;