summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-11-22 09:12:28 -0300
committerGenerated from internal repo <nobody@neo900.org>2016-11-22 09:12:28 -0300
commit61c552aa779b02070e9c8a97131fdd16d7a5554e (patch)
tree007478e19d3f92296d5d7b3d24f8dafb1049e573 /scripts
parent6afcaa2dddb3449b3f80f6a0736b20b177b9b7ca (diff)
downloadee-61c552aa779b02070e9c8a97131fdd16d7a5554e.tar.gz
ee-61c552aa779b02070e9c8a97131fdd16d7a5554e.tar.bz2
ee-61c552aa779b02070e9c8a97131fdd16d7a5554e.zip
scripts/conncmp.pl: script to compare pins assignments on connectors
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/conncmp.pl86
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/conncmp.pl b/scripts/conncmp.pl
new file mode 100755
index 0000000..15ca699
--- /dev/null
+++ b/scripts/conncmp.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+#
+# conncmp.pl - Compare signal names on connectors
+#
+
+sub usage
+{
+ print STDERR <<"EOF";
+usage: $0 list-a.xml comp-a list-b.xml comp-b pat-a=pat-b ...
+
+ patterns can be constant, e.g., GND=GND3
+ or variable, e.g., %=%_U
+ Nets connecting to no other component are renamed to NC.
+EOF
+ exit(1);
+}
+
+
+sub get_pins
+{
+ local ($file, $comp) = @_;
+
+ my %pins = ();
+ my $net = undef;
+ my $single = undef;
+ my $conns = 0;
+
+ open(FILE, $file) || die "$file: $!";
+ while (<FILE>) {
+ if (/\(net\s+.*\(name\s+"([^"]+)"\)/ ||
+ /\(net\s+.*\(name\s+(\S+?)\)/) {
+ $pins{$single} = "NC" if $conns == 1;
+ $net = $1;
+ $net =~ s#^/.*/##;
+ $single = undef;
+ $conns = 0;
+ next;
+ }
+ next unless /\(node\s+\(ref\s+(\S+?)\)\s+\(pin\s+(\S+?)\)/;
+
+ $conns++;
+ next unless $1 eq $comp;
+ die "duplicate pin $1.$2" if defined $pins{$2};
+ die "undefined net" unless defined $net;
+ $pins{$2} = $net;
+ $single = $2;
+ }
+ close(FILE);
+ return \%pins;
+}
+
+
+&usage unless $#ARGV >= 3;
+%a = %{ &get_pins($ARGV[0], $ARGV[1]) };
+%b = %{ &get_pins($ARGV[2], $ARGV[3]) };
+@eq = @ARGV[4 .. $#ARGV];
+
+for (@eq) {
+ &usage unless $_ =~ /=/;
+}
+
+PIN: for $pin (keys %a) {
+ die "A.$pin has no matching B.$pin" unless defined $b{$pin};
+ my $a = $a{$pin};
+ my $b = $b{$pin};
+ delete $b{$pin};
+ next if $a eq $b;
+ for (@eq) {
+ die unless /=/;
+ my ($pa, $pb) = ($`, $');
+ if ($pa =~ /%/) {
+ my $pat = "^$`(.*)$'\$";
+ next unless $a =~ $pat;
+ my $var = $1;
+ $pb =~ s/%/$var/g;
+ next PIN if $b eq $pb;
+ } else {
+ next PIN if $a eq $pa && $b eq $pb;
+ }
+ }
+ die "A.$pin($a) does not seem to match B.$pin($b)\n";
+}
+
+for $pin (keys %b) {
+ die "B.$pin has no matching A.$pin";
+}