Reworked test files for better error reporting
[nasm/perl-rewrite.git] / phash.pl
blob5dc385f18e0a10977292e8b6d850057f984c4e63
1 #!/usr/bin/perl
3 # Perfect Minimal Hash Generator written in Perl, which produces
4 # C output.
7 # I don't think this file is even used.
9 use lib qw'perllib';
11 require 'phash.ph';
14 # Main program
16 sub main() {
17 my $n;
18 my %data;
19 my @hashinfo;
20 my $x, $i;
22 %data = read_input();
23 @hashinfo = gen_perfect_hash(\%data);
25 if (!defined(@hashinfo)) {
26 die "$0: no hash found\n";
29 verify_hash_table(\%data, \@hashinfo);
31 ($n, $sv, $f1, $f2, $g) = @hashinfo;
33 print "static int HASHNAME_fg1[$n] =\n";
34 print "{\n";
35 for ($i = 0; $i < $n; $i++) {
36 print "\t", ${$g}[${$f1}[$i]], "\n";
38 print "};\n\n";
40 print "static int HASHNAME_fg2[$n] =\n";
41 print "{\n";
42 for ($i = 0; $i < $n; $i++) {
43 print "\t", ${$g}[${$f2}[$i]], "\n";
45 print "};\n\n";
47 print "struct p_hash HASHNAME =\n";
48 print "{\n";
49 print "\t$n\n";
50 print "\t$sv\n";
51 print "\tHASHNAME_fg1,\n";
52 print "\tHASHNAME_fg2,\n";
53 print "};\n";
56 main();