Revert "nasmlib.c: fix issues with strrep utility function"
[nasm/avx512.git] / phash.pl
blob3ef6e714b2e34a9d27dbf974c05a4f651e2bd914
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 # Read input file
43 sub read_input() {
44 my $key,$val;
45 my %out;
46 my $x = 0;
48 while (defined($l = <STDIN>)) {
49 chomp $l;
50 $l =~ s/\s*(\#.*|)$//;
52 next if ($l eq '');
54 if ($l =~ /^([^=]+)\=([^=]+)$/) {
55 $out{$1} = $2;
56 $x = $2;
57 } else {
58 $out{$l} = $x;
60 $x++;
63 return %out;
67 # Main program
69 sub main() {
70 my $n;
71 my %data;
72 my @hashinfo;
73 my $x, $i;
75 %data = read_input();
76 @hashinfo = gen_perfect_hash(\%data);
78 if (!@hashinfo) {
79 die "$0: no hash found\n";
82 verify_hash_table(\%data, \@hashinfo);
84 ($n, $sv, $f1, $f2, $g) = @hashinfo;
86 print "static int HASHNAME_fg1[$n] =\n";
87 print "{\n";
88 for ($i = 0; $i < $n; $i++) {
89 print "\t", ${$g}[${$f1}[$i]], "\n";
91 print "};\n\n";
93 print "static int HASHNAME_fg2[$n] =\n";
94 print "{\n";
95 for ($i = 0; $i < $n; $i++) {
96 print "\t", ${$g}[${$f2}[$i]], "\n";
98 print "};\n\n";
100 print "struct p_hash HASHNAME =\n";
101 print "{\n";
102 print "\t$n\n";
103 print "\t$sv\n";
104 print "\tHASHNAME_fg1,\n";
105 print "\tHASHNAME_fg2,\n";
106 print "};\n";
109 main();