#!/usr/bin/perl
# This version of add_ports is used only with EDIF files
#A component of the add-ports script, used to split an EDIF file
#somewhere in its interface list
if (@ARGV < 3)
{ print "add_ports entity acf_file edf_file\n";
}
$entity=@ARGV[0];
$acf=@ARGV[1];
$edif=@ARGV[2];
$edif_new="$edif.new";
$edif_bak="$edif.bak";
$s = 0;
$rsv_pat="[Rr][Ss][Vv][0-9]+[Zz]";
print "looking for entity '$entity'\n";
print "in file '$acf' to edit '$edif'\n";
$s=0;
$cnt = 0;
while( <IN1> ) {
if (/CHIP $entity/) {
print "Located entity '$entity' in '$acf'\n";
$s=1;
break;
}
if($s==1 && /END;/)
{
$s=0;
break;
}
if( $s==1 && /($rsv_pat)/ ) {
@rsv[$cnt++] = $1;
}
}
#for ($i=0;$i<$cnt;$i++) {
# print @rsv[$i],"\n";
# }
$s=0;
$del = 0;
while ( <IN> ) {
#Look for a cell declaration
# for EDIF with the cellname on the next line there will be only one word
# trash all previously reserved pins first
if (s/\
(port
($rsv_pat) \
( direction INPUT\
)\
)//g
) {
$del++;
}
break;
}
else {
if( /\(cell\s*$entity/m) {
$s = 1;
print "located '$entity' in '$edif'\n";
}
elsif ( /\(cell\s*/ ) {
$s = 0;
}
if( $s==1 && /\(interface\s*(.*)/) {
$remainder = $1;
# printf ("in interface of %s\n",$entity);
print OUT
"(interface\n";
for($i=0;$i<$cnt;$i++) {
print OUT
"(port $rsv[$i] ( direction INPUT))\n";
}
print OUT
"$remainder\n";
$s= 0;
}
else {
}
}
}
print "inserted $cnt reservations, removed $del reservations from $entity\n";
# sort out file names