/
mergeLib.pl
executable file
·59 lines (50 loc) · 1.24 KB
/
mergeLib.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
# This script is sourced from Brown (with slight modifications). It merges
# several timing libraries into one.
# ------------------------------------------------------------------------------
use strict;
use warnings;
my $sclname = $ARGV[0];
shift @ARGV;
my $cnt = @ARGV;
if($cnt>0){
process_header($ARGV[0]);
my $file;
foreach my $file (@ARGV) {
process_cells($file)
}
print "\n}\n";
} else {
print "use: mergeLib.pl new_library_name lib1 lib2 lib3 ....";
}
sub process_header {
my $filename = shift;
open(my $fh, '<', $filename) or die "Could not open file $filename $!";
while (<$fh>) {
if(/library\s*\(/) {
print "library ($sclname) {\n";
next;
}
last if(/^[\t\s]*cell\s*\(/);
print $_;
}
}
sub process_cells {
my $filename = shift;
open(my $fh, '<', $filename) or die "Could not open file $filename $!";
my $flag = 0;
# cut the cells
while (<$fh>) {
#chomp $_;
if(/^[\t\s]*cell\s*\(/) {#&& $flag==0){
die "Error! new cell before finishing the previous one!\n" if($flag!=0);
print "\n$_";
$flag=1;
} elsif($flag > 0){
$flag++ if(/\{/);
$flag-- if(/\}/);
#print "...}\n" if($flag==0);
print "$_";
}
}
}