reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
/*
 * Copyright 2017      Sven Verdoolaege
 *
 * Use of this software is governed by the MIT license
 *
 * Written by Sven Verdoolaege.
 */

#include <stdlib.h>

#include <isl/arg.h>
#include <isl/options.h>
#include <isl/union_map.h>
#include <isl/stream.h>

struct options {
	struct isl_options *isl;
	char *flow1;
	char *flow2;
};

ISL_ARGS_START(struct options, options_args)
ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
ISL_ARG_ARG(struct options, flow1, "flow1", NULL)
ISL_ARG_ARG(struct options, flow2, "flow2", NULL)
ISL_ARGS_END

ISL_ARG_DEF(options, struct options, options_args)

static void die(const char *msg)
{
	fprintf(stderr, "%s\n", msg);
	exit(EXIT_FAILURE);
}

static FILE *open_or_die(const char *filename)
{
	FILE *file;

	file = fopen(filename, "r");
	if (!file) {
		fprintf(stderr, "Unable to open %s\n", filename);
		exit(EXIT_FAILURE);
	}
	return file;
}

#undef BASE
#define BASE union_map
#include "read_in_string_templ.c"

/* Given two YAML descriptions of isl_union_flow objects, check whether
 * they are equivalent.
 * Return EXIT_SUCCESS if they are and EXIT_FAILURE if they are not
 * or if anything else went wrong.
 *
 * The descriptions are checked field by field, meaning that the fields
 * are expected to appear in the same order in both inputs.
 */
int main(int argc, char **argv)
{
	int more;
	isl_ctx *ctx;
	struct options *options;
	FILE *input1, *input2;
	isl_stream *s1, *s2;

	options = options_new_with_defaults();
	if (!options)
		return EXIT_FAILURE;

	ctx = isl_ctx_alloc_with_options(&options_args, options);
	argc = options_parse(options, argc, argv, ISL_ARG_ALL);

	input1 = open_or_die(options->flow1);
	input2 = open_or_die(options->flow2);
	s1 = isl_stream_new_file(ctx, input1);
	s2 = isl_stream_new_file(ctx, input2);

	if (isl_stream_yaml_read_start_mapping(s1))
		isl_die(ctx, isl_error_unknown, "arg1 not a YAML mapping",
			return EXIT_FAILURE);
	if (isl_stream_yaml_read_start_mapping(s2))
		isl_die(ctx, isl_error_unknown, "arg2 not a YAML mapping",
			return EXIT_FAILURE);

	while ((more = isl_stream_yaml_next(s1)) > 0) {
		int more2;
		isl_bool equal;
		isl_union_map *umap1, *umap2;

		more2 = isl_stream_yaml_next(s2);
		if (more2 < 0)
			return EXIT_FAILURE;
		if (!more2)
			isl_die(ctx, isl_error_unknown, "arg2 shorter",
				return EXIT_FAILURE);
		if (isl_stream_eat(s1, ISL_TOKEN_IDENT) < 0)
			return EXIT_FAILURE;
		if (isl_stream_eat(s2, ISL_TOKEN_IDENT) < 0)
			return EXIT_FAILURE;
		more = isl_stream_yaml_next(s1);
		more2 = isl_stream_yaml_next(s2);
		if (more < 0 || more2 < 0)
			return EXIT_FAILURE;
		if (!more || !more2)
			isl_die(ctx, isl_error_unknown, "missing value",
				return EXIT_FAILURE);

		umap1 = read_union_map(s1);
		umap2 = read_union_map(s2);
		equal = isl_union_map_is_equal(umap1, umap2);
		isl_union_map_free(umap1);
		isl_union_map_free(umap2);
		if (equal < 0)
			return EXIT_FAILURE;
		if (!equal)
			die("field not equal");
	}
	if (more < 0)
		return EXIT_FAILURE;


	if (isl_stream_yaml_read_end_mapping(s1) < 0) {
		isl_stream_error(s1, NULL, "unexpected extra elements");
		return EXIT_FAILURE;
	}
	if (isl_stream_yaml_read_end_mapping(s2) < 0) {
		isl_stream_error(s2, NULL, "unexpected extra elements");
		return EXIT_FAILURE;
	}

	isl_stream_free(s1);
	isl_stream_free(s2);
	fclose(input1);
	fclose(input2);
	isl_ctx_free(ctx);

	return EXIT_SUCCESS;
}