<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
#
# Note: You might need to install the Verilog::VCD package using CPAN..

use strict;
use Data::Dumper;
use Verilog::VCD qw(parse_vcd list_sigs);

$| = 1;

my $from_time = -1;
my $to_time = -1;

while (1)
{
	if ($ARGV[0] eq '-f') {
		$from_time = +$ARGV[1];
		shift @ARGV;
		shift @ARGV;
		next;
	}
	if ($ARGV[0] eq '-t') {
		$to_time = +$ARGV[1];
		shift @ARGV;
		shift @ARGV;
		next;
	}
	last;
}

if ($#ARGV &lt; 0) {
	print STDERR "\n";
	print STDERR "VCD2TXT - Convert VCD to tab-separated text file\n";
	print STDERR "\n";
	print STDERR "Usage: $0 [-f from_time] [-t to_time] input.vcd [&lt;signal regex&gt; ...]\n";
	print STDERR "\n";
	exit 1;
}

my $vcd = parse_vcd($ARGV[0]);

for my $node (keys $vcd) {
	for my $net (@{$vcd-&gt;{$node}-&gt;{'nets'}}) {
		my $dump_this = $#ARGV == 0;
		for (my $i = 1; $i &lt;= $#ARGV; $i++) {
			my $regex = $ARGV[$i];
			$dump_this = 1 if ($net-&gt;{"hier"} . "." . $net-&gt;{"name"}) =~ /$regex/;
		}
		next unless $dump_this;
		my $cached_value = "";
		for my $tv (@{$vcd-&gt;{$node}-&gt;{'tv'}}) {
			$cached_value = $tv-&gt;[1], next if $from_time &gt;= 0 and +$tv-&gt;[0] &lt; $from_time;
			next if $to_time &gt;= 0 and +$tv-&gt;[0] &gt; $to_time;
			printf "%s\t%s\t%s\t%s\n", $node, $from_time, $net-&gt;{"hier"} . "." . $net-&gt;{"name"}, $cached_value
					if $cached_value ne "" and $from_time &gt;= 0 and +$tv-&gt;[0] &gt; $from_time;
			printf "%s\t%s\t%s\t%s\n", $node, $tv-&gt;[0], $net-&gt;{"hier"} . "." . $net-&gt;{"name"}, $tv-&gt;[1];
			$cached_value = "";
		}
	}
}

</pre></body></html>