NASM 2.09rc3
[nasm/nasm.git] / phash.pl
blobe1071b2e7ec4adf2536e4f4b3dfae197978270e3
1 #!/usr/bin/perl
2 ## --------------------------------------------------------------------------
3 ##
4 ## Copyright 1996-2009 the NASM Authors - All rights reserved.
5 ##
6 ## Redistribution and use in source and binary forms, with or without
7 ## modification, are permitted provided that the following
8 ## conditions are met:
9 ##
10 ## * Redistributions of source code must retain the above copyright
11 ## notice, this list of conditions and the following disclaimer.
12 ## * Redistributions in binary form must reproduce the above
13 ## copyright notice, this list of conditions and the following
14 ## disclaimer in the documentation and/or other materials provided
15 ## with the distribution.
16 ##
17 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ## --------------------------------------------------------------------------
34 # Perfect Minimal Hash Generator written in Perl, which produces
35 # C output.
38 require 'phash.ph';
41 # Main program
43 sub main() {
44 my $n;
45 my %data;
46 my @hashinfo;
47 my $x, $i;
49 %data = read_input();
50 @hashinfo = gen_perfect_hash(\%data);
52 if (!defined(@hashinfo)) {
53 die "$0: no hash found\n";
56 verify_hash_table(\%data, \@hashinfo);
58 ($n, $sv, $f1, $f2, $g) = @hashinfo;
60 print "static int HASHNAME_fg1[$n] =\n";
61 print "{\n";
62 for ($i = 0; $i < $n; $i++) {
63 print "\t", ${$g}[${$f1}[$i]], "\n";
65 print "};\n\n";
67 print "static int HASHNAME_fg2[$n] =\n";
68 print "{\n";
69 for ($i = 0; $i < $n; $i++) {
70 print "\t", ${$g}[${$f2}[$i]], "\n";
72 print "};\n\n";
74 print "struct p_hash HASHNAME =\n";
75 print "{\n";
76 print "\t$n\n";
77 print "\t$sv\n";
78 print "\tHASHNAME_fg1,\n";
79 print "\tHASHNAME_fg2,\n";
80 print "};\n";
83 main();