fail svinterfaces testcases on yosys error exit
[yosys.git] / tests / tools / vcd2txt.pl
1 #!/usr/bin/perl -w
2 #
3 # Note: You might need to install the Verilog::VCD package using CPAN..
4
5 use strict;
6 use Data::Dumper;
7 use Verilog::VCD qw(parse_vcd list_sigs);
8
9 $| = 1;
10
11 my $from_time = -1;
12 my $to_time = -1;
13
14 while (1)
15 {
16 if ($ARGV[0] eq '-f') {
17 $from_time = +$ARGV[1];
18 shift @ARGV;
19 shift @ARGV;
20 next;
21 }
22 if ($ARGV[0] eq '-t') {
23 $to_time = +$ARGV[1];
24 shift @ARGV;
25 shift @ARGV;
26 next;
27 }
28 last;
29 }
30
31 if ($#ARGV < 0) {
32 print STDERR "\n";
33 print STDERR "VCD2TXT - Convert VCD to tab-separated text file\n";
34 print STDERR "\n";
35 print STDERR "Usage: $0 [-f from_time] [-t to_time] input.vcd [<signal regex> ...]\n";
36 print STDERR "\n";
37 exit 1;
38 }
39
40 my $vcd = parse_vcd($ARGV[0]);
41
42 for my $node (keys $vcd) {
43 for my $net (@{$vcd->{$node}->{'nets'}}) {
44 my $dump_this = $#ARGV == 0;
45 for (my $i = 1; $i <= $#ARGV; $i++) {
46 my $regex = $ARGV[$i];
47 $dump_this = 1 if ($net->{"hier"} . "." . $net->{"name"}) =~ /$regex/;
48 }
49 next unless $dump_this;
50 my $cached_value = "";
51 for my $tv (@{$vcd->{$node}->{'tv'}}) {
52 $cached_value = $tv->[1], next if $from_time >= 0 and +$tv->[0] < $from_time;
53 next if $to_time >= 0 and +$tv->[0] > $to_time;
54 printf "%s\t%s\t%s\t%s\n", $node, $from_time, $net->{"hier"} . "." . $net->{"name"}, $cached_value
55 if $cached_value ne "" and $from_time >= 0 and +$tv->[0] > $from_time;
56 printf "%s\t%s\t%s\t%s\n", $node, $tv->[0], $net->{"hier"} . "." . $net->{"name"}, $tv->[1];
57 $cached_value = "";
58 }
59 }
60 }
61