#!/usr/bin/perl # # sweep mapped blif file and do the following things: # # 1. statistics of test cases # # 2. Also sometimes SIS can't map all the gates and most likey the buffer # doesn't get mapped. (Strange thing?) # # This script is to map all the left buffer into smallest library # buffer cell # # 3. remove unused inputs and outputs # # 12/06/04: accept buffer name # 12/06/04: remove flip-flop outputs from output list require "getopts.pl"; &Getopts('hk'); $removeFlopOutputs = 0; if ($opt_h || @ARGV < 2) { print "Usage: sweep mapped_blif_file buf_name\n"; exit (0); } if ($opt_k) { $removeFlopOutputs = 1; } # create a copy #system "cp $ARGV[0] $ARGV[0].bak"; if ($removeFlopOutputs) { $ff_file = $ARGV[0]; $ff_file =~ s/blif$/fflist/; open FFLIST, $ff_file || die "Cannot open file $ff_file to read.\n"; $ff_output = ; $ff_output =~ s/^(\S+).*/$1/; chomp $ff_output; print "Remove outputs starting from $ff_output .\n"; } my %nodes; open BLIF, $ARGV[0] || die "Cannot open file $ARGV[0] to read.\n"; while ($string = ) { chomp $string; while ($string =~ /\\$/) { chop $string; # remove ending \\ $string .= " ".; chomp $string; } $string =~ s/^\s+//; if ($string =~ /^\.inputs\b/i) { my @fields = split /\s+/, $string; shift @fields; foreach $f (@fields) { if ($nodes{$f}) { $nodes{$f}++; } else { $nodes{$f} = 1; } } } elsif ($string =~ /^\.outputs\b/i) { my @fields = split /\s+/, $string; shift @fields; foreach $f (@fields) { if ($nodes{$f}) { $nodes{$f}++; } else { $nodes{$f} = 1; } } } elsif ($string =~ /^\.gate\b/i || $string =~ /^\.mlatch\b/i) { my @fields = split /\s+/, $string; foreach $f (@fields) { if ($f =~ /\b\w+=/) { $f =~ s/^\w+=//; if ($nodes{$f}) { $nodes{$f}++; } else { $nodes{$f} = 1; } } } } elsif ($string =~ /^\.names\b/i) { my @fields = split /\s+/, $string; shift @fields; foreach $f (@fields) { if ($nodes{$f}) { $nodes{$f}++; } else { $nodes{$f} = 1; } } } } close BLIF; ##################################################### # start to count and new file generation ##################################################### my $Num_inputs = 0; my $Num_outputs = 0; my $Num_gates = 0; my $Num_latches = 0; open BLIF, $ARGV[0] || die "Cannot open file $ARGV[0] to read."; my $tmp = "/tmp/tmp.blif"; open OUT, ">$tmp" || die "Cannot open file $tmp to write."; while ($string = ) { chomp $string; while ($string =~ /\\$/) { chop $string; # remove ending \\ $string .= " ".; chomp $string; } $string =~ s/^\s+//; if ($string =~ /^\.inputs\b/i) { my @fields = split /\s+/, $string; my $new_str = shift (@fields); foreach $f (@fields) { if ($nodes{$f} > 1) { $Num_inputs ++; # add a symbol to all purely digital node name # since Capo will think it as weight number otherwise $f =~ /(\d+)/; if ($1) { if ($f eq $1) { $f = "N$f"; } } $new_str .= " $f"; } } print OUT "$new_str\n"; } elsif ($string =~ /^\.outputs\b/i) { my @fields = split /\s+/, $string; my $new_str = shift (@fields); foreach $f (@fields) { if ($removeFlopOutputs && $ff_output eq $f) { print "Found $ff_output in the output list\n"; last; } if ($nodes{$f} > 1) { $Num_outputs ++; # add a symbol to all purely digital node name # since Capo will think it as weight number otherwise $f =~ /(\d+)/; if ($1) { if ($f eq $1) { $f = "N$f"; } } $new_str .= " $f"; } } print OUT "$new_str\n"; } elsif ($string =~ /^\.gate\b/i || $string =~ /^\.mlatch\b/i) { $Num_gates ++; if ($string =~ /^\.mlatch\b/i) { $Num_latches++; } # add a symbol to all purely digital node name # since Capo will think it as weight number otherwise my @fields = split /\s+/, $string; foreach $f (@fields) { if ($f =~ /\b(\w+)=(\d+)\b/) { if ($2) { if ($f eq "$1=$2") { $f = "$1=N$2"; } } } } print OUT "@fields\n"; } elsif ($string =~ /^\.names\b/i) { my @fields = split /\s+/, $string; if (@fields == 3) { $string = ; chomp $string; if ($string eq "1 1") { $fields[1] =~ /(\d+)/; if ($1) { if ($fields[1] eq $1) { $fields[1] = "N$fields[1]"; } } $fields[2] =~ /(\d+)/; if ($1) { if ($fields[2] eq $1) { $fields[2] = "N$fields[2]"; } } print OUT ".gate $ARGV[1] A=$fields[1] O=$fields[2]\n"; } } } else { print OUT "$string\n"; } } close BLIF; close OUT; system "mv $tmp $ARGV[0]"; ################################### # print statistics ################################### my $cir = $ARGV[0]; $cir =~ s/\.blif//; # output for LaTeX table #print "$cir & & $Num_inputs & $Num_outputs & $Num_latches & $Num_gates \\\\ \\hline\n"; #print "$cir\t\t$Num_inputs\t$Num_outputs\t$Num_latches\t$Num_gates\n"; write (STDOUT); format STDOUT = #Test name Input# Output# Latch# Gate# @<<<<<<<<<<<< &@||||||| &@||||||| &@||||||| &@||||||| \\ \hline $cir, $Num_inputs, $Num_outputs, $Num_latches, $Num_gates .