mknet.pl
2.61 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
exit(0) if ($#ARGV != 0);
$dir = "Wir";
$dir = ".";
$name=$ARGV[0];
$verilog = "$dir/" . $name . ".v";
open V, $verilog or die "can't open verilog netlist: $verilog $!\n";
$nnet = 0;
$nsym = 0;
$ncomp = 0;
# read the verilog file
undef $/;
$file=<V>;
$/="\n";
# strip comments
$file =~ s|//.*\n|\n|g;
# strip newlines
$file =~ s/\n/ /g;
# split at ; separators
@file = split ';', $file;
# parse file
$inmodule=0;
for (@file) {
split;
#print "$_[0]\n";
if ($_[0] eq "module") {
$modname = $_[1];
$inmodule = 1;
#print "module xx$modname\n";
next;
}
$inmodule = 0 if ($_[0] eq "endmodule");
if ($inmodule == 1 && $_[0] eq "wire") {
if ($#_ == 2) {
$nname[$nnet] = $_[2];
$nwidth[$nnet] = $_[1];
} else {
$nname[$nnet] = $_[1];
}
$nnet++;
next;
}
if ($inmodule == 1) {
$compname[$ncomp] = $_[0];
$instname[$ncomp] = $_[1];
shift @_; shift @_;
$sig[$ncomp] = join '',@_;
# print "$sig[$ncomp]\n";
$ncomp++;
}
}
# read symbols
for($i = 0; $i < $ncomp; $i++) {
$cname = $compname[$i];
$sname = "$dir/" . $cname . ".pin";
open S, $sname or die "can't open $sname: $!\n";
$n=0;
$sym{$cname} = [ () ];
while(<S>) {
split;
$pin = $_[0];
$type = $_[1];
if ($pin =~ /(\w+)(\[.*\])/) {
$pin = $1;
$width = $2;
} else {
$width = "";
}
#print "$pin -- $width -- $type\n";
push @{$sym{$cname}}, [($pin , $width, $type)];
}
# print "$cname\n";
# for $x (@{$sym{$cname}}) {
# print "\t[ @$x ]\n";
# }
# print "@{$sym{$cname}} \n";
close S;
}
print "DW $ARGV[0]\n";
# symbols
for($i = 0; $i < $ncomp; $i++) {
print "AS $compname[$i] xx ";
for $x (@{$sym{$compname[$i]}}) {
($pin, $width, $type) = @$x;
printf "%s ",$pin.$width;
}
print "\n";
$j = 1;
for $x (@{$sym{$compname[$i]}}) {
($pin, $width, $type) = @$x;
printf "AP %-10s %3d NAME %s\n",$compname[$i],$j,$pin.$width;
printf "AP %-10s %3d PINTYPE %s\n",$compname[$i],$j,$type;
$j++;
}
}
# nets
for($i = 0; $i < $nnet; $i++) {
print "G $nname[$i]\n";
}
# instances
for($i = 0; $i < $ncomp; $i++) {
printf "I %s %s ", $instname[$i], $compname[$i];
$x = $sig[$i];
# remove outer ()
$x =~ s/\((.*)\)/\1/;
@x = split ',',$x;
%px = ();
for $s (@x) {
$s =~ /\.([\w\[\]:]+)\(([\w\[\]:]+)?\)/;
$p = $1;
$n = $2;
$n = "?" unless defined $n;
# if ($n =~ /\w+(\[.*\])/) {
# $p = $p . $1;
# }
$px{$p} = $n;
# print "$p, $n\n";
}
for $y (@{$sym{$compname[$i]}}) {
($pin, $width, $type) = @$y;
$n = $px{$pin};
$n = "?" unless defined $n;
print "$n ";
}
print "\n\n";
}