#!/usr/bin/perl

use Getopt::Long;

my $exec = "./haskell2dafny";

my $verbose=0;
my $expandconstants=0;
my $result = GetOptions( "verbose"  => \$verbose,
			 "expandconstants" => \$expandconstants );

die "Usage: testme [-v|--verbose] [-e|--expandconstants] inputfile " .
    "arg [arg...]\n" unless $result && @ARGV>1;

my $optstr = "";
$optstr .= "-v" if $verbose;
$optstr .= "-e" if $expandconstants;
my $inputfile = shift @ARGV;

warn "\nsource: $inputfile:\n\n";
open( my $fh, "<", $inputfile ) || die "can't open $inputfile\n";
while( <$fh> )
{
	warn $_;
}
close( $fh );

foreach my $arg (@ARGV)
{
	warn "\nParsing $inputfile with arg1=$arg\n";
	system( "$exec $optstr $arg < $inputfile > eek.c" ) == 0 ||
		die "error from haskell2dafny\n";
	#warn "Compiling with gcc\n";
	#system( "gcc -Wall eek.c -o eek" ) == 0 ||
	#	die "error from gcc\n";
	#warn "Compilation succeeded\n" if $verbose;
	#warn "Running executable with arg=$arg\n" if $verbose;
	#system( "./eek" ) == 0 ||
	#	die "error from executable\n";
}
