#!/usr/bin/perl #!/usr/local/bin/perl # # gen-driver - Generate driver file for any ncopy function # use Getopt::Std; $n = 0; getopts('hcrn:f:b:'); if ($opt_h) { print STDERR "Usage $argv[0] [-h] [-c] [-n N] [-f FILE]\n"; print STDERR " -h print help message\n"; print STDERR " -c include correctness checking code\n"; print STDERR " -n N set number of elements\n"; print STDERR " -f FILE set input file (default stdin)\n"; print STDERR " -b blim set byte limit for function\n"; print STDERR " -r Allow random result\n"; die "\n"; } $check = 0; if ($opt_c) { $check = 1; } $bytelim = 1000; if ($opt_b) { $bytelim = $opt_b; } if ($opt_n) { $n = $opt_n; if ($n < 0) { print STDERR "n must be at least 0\n"; die "\n"; } } $randomval = 0; # Accumulated count $rval = 0; if ($opt_r) { $randomval = 1; } else { # Value that should be returned by function $tval = int($n/2); } # The data to be stored. @data = (); for ($i = 0; $i < $n; $i++) { $data[$i] = -($i+1); if ($randomval) { if (int(rand(2)) == 1) { $data[$i] = -$data[$i]; $rval++; } } else { if ($rval < $tval && int(rand(2)) % 2 == 1 || $tval - $rval >= $n - $i) { $data[$i] = -$data[$i]; $rval++; } } } # Values to put at beginning and end of destination $Preval = "0xbcdefa"; $Postval = "0xdefabc"; print <) { printf "%s", $_; } } else { while (<>) { printf "%s", $_; } } print "EndFun:\n"; if ($check) { print <