OpenCores
URL https://opencores.org/ocsvn/t48/t48/trunk

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_4_beta/] [sw/] [vcd2vec.pl] - Blame information for rev 345

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 47 arniml
#!/usr/bin/perl -w
2
#
3
# ############################################################################
4
#
5
# vcd2vec.pl
6
#
7
# $Id: vcd2vec.pl,v 1.1 2004-04-09 19:16:00 arniml Exp $
8
#
9
# Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
10
#
11
# All rights reserved
12
#
13
#  This program is free software; you can redistribute it and/or modify
14
#  it under the terms of the GNU General Public License as published by
15
#  the Free Software Foundation; either version 2 of the License, or
16
#  (at your option) any later version. See also the file COPYING which
17
#  came with this application.
18
#
19
#  This program is distributed in the hope that it will be useful,
20
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
#  GNU General Public License for more details.
23
#
24
#  You should have received a copy of the GNU General Public License
25
#  along with this program; if not, write to the Free Software
26
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
#
28
# ############################################################################
29
#
30
# Purpose:
31
# ========
32
#
33
# Converts a VCD-file to a vector file.
34
#
35
# Reads VCD from STDIN and writes the resulting vector stream to STDOUT.
36
# vcd2vec.pl -s <signals file> [-i] [-h]
37
#  -s : Name of the file containing the signals for vector output
38
#  -i : Read initial state from VCD (given with $dumpvars)
39
#  -h : Print this help
40
#
41
 
42
 
43
use strict;
44
 
45
use Getopt::Std;
46
 
47
 
48
my $time_unit = 'ns';
49
 
50
sub print_usage {
51
    print <<EOU;
52
Reads VCD from STDIN and writes the resulting vector stream to STDOUT.
53
Usage:
54
 vcd2vec.pl -s <signals file> [-i] [-h]
55
  -s : Name of the file containing the signals for vector output
56
  -i : Read initial state from VCD (given with \$dumpvars)
57
  -h : Print this help
58
EOU
59
}
60
 
61
sub print_index {
62
    my $index = shift;
63
    my ($tok, $desc);
64
 
65
    while (($tok, $desc) = each %{$index}) {
66
        print("Token $tok:\n");
67
        print("  $desc->{'name'}\n");
68
        print("  $desc->{'pos'}\n");
69
    }
70
}
71
 
72
sub dump_state {
73
    my ($state, $time, $dump_signals) = @_;
74
    my $signal;
75
 
76
    print("${time}>");
77
    foreach $signal (@{$dump_signals}) {
78
        if (exists($state->{$signal})) {
79
            print(" ".$state->{$signal});
80
        } else {
81
            print(STDERR "Error: Signal '$signal' not included in VCD!\n");
82
        }
83
    }
84
    print("\n");
85
}
86
 
87
sub read_scope {
88
    my $scope = shift;
89
    my $index = shift;
90
    my $pos   = shift;
91
    my ($token, $base, $extension);
92
    my $ipt;
93
 
94
    print("Processing scope '$scope'\n");
95
 
96
    while (<STDIN>) {
97
        last if (/^\$upscope/);
98
 
99
        last if (/^\$enddefinitions/);
100
 
101
        if (/^\$var +\S+ +\S+ +(\S+) +(\S+) +(([^\$]\S*)|\$end)/) {
102
            $token = $1;
103
            $base  = $2;
104
 
105
            $extension = defined($4) ? $4 : '';
106
            $extension =~ s/[\[\]]//g;
107
 
108
            $index->{$token} = {};
109
            $ipt = $index->{$token};
110
            $ipt->{'name'} = "$scope.$base$extension";
111
            $ipt->{'pos'}  = $$pos++;
112
 
113
            print("Appended ".$ipt->{'name'}."\n");
114
        }
115
 
116
        if (/^\$scope +\S+ +(\S+)/) {
117
            read_scope("$scope.$1", $index, $pos);
118
        }
119
 
120
        if (/^\$timescale/) {
121
            $_ = <STDIN>;
122
            if (/^\s*1(\S+)/) {
123
                $time_unit = $1;
124
            }
125
        }
126
    }
127
}
128
 
129
my %options;
130
my %index;
131
my %state;
132
my ($i, $time, $pos);
133
my $index;
134
my $token;
135
my ($ipt, $val);
136
my ($tok, $desc);
137
my $signal;
138
my $initial_states = 0;
139
local *SIGNALS_FILE;
140
 
141
my @dump_signals;
142
 
143
# process command line options
144
if (!getopts('s:ih', \%options)) {
145
    print_usage();
146
    exit(1);
147
}
148
 
149
if (exists($options{'h'})) {
150
    print_usage();
151
    exit(0);
152
}
153
 
154
if (exists($options{'i'})) {
155
    $initial_states = 1;
156
}
157
 
158
if (exists($options{'s'})) {
159
} else {
160
    print(STDERR "File with signal names is required!\n");
161
    print_usage();
162
    exit(1);
163
}
164
 
165
 
166
##############################################################################
167
# Read signals file
168
#
169
if (!open(SIGNALS_FILE, "<$options{'s'}")) {
170
    print(STDERR  "Cannot read signals file '$options{'s'}'!\n");
171
    exit(1);
172
}
173
 
174
@dump_signals = <SIGNALS_FILE>;
175
close(SIGNALS_FILE);
176
chomp(@dump_signals);
177
 
178
 
179
# parse header
180
$index = {};
181
$pos   = 0;
182
read_scope("", $index, \$pos);
183
 
184
 
185
if ($initial_states) {
186
    # read initial state
187
    while (<STDIN>) { last if (/^\$dumpvars/) }
188
    while (<STDIN>) {
189
        last if (/^\$end/);
190
        if (/^(.)(\S+)/) {
191
            $val   = $1;
192
            $token = $2;
193
            $state{$index->{$token}->{'name'}} = $val;
194
        }
195
    }
196
}
197
 
198
$time = '0';
199
 
200
print("time:");
201
foreach $signal (@dump_signals) {
202
    print(" $signal");
203
}
204
print("\n");
205
 
206
# now read all state changes
207
while (<STDIN>) {
208
    if (/^#(\d+)/) {
209
        if ($1 != 0) {
210
            # dump previous state
211
            dump_state(\%state, $time, \@dump_signals);
212
        }
213
        $time = $1;
214
        next;
215
    } else {
216
        if (/^(\S)(\S+)$/) {
217
            $val   = $1;
218
            $token = $2;
219
            $state{$index->{$token}->{'name'}} = $val;
220
        }
221
 
222
        if (/^(\S+) (\S+)$/) {
223
            $val   = $1;
224
            $token = $2;
225
            $state{$index->{$token}->{'name'}} = $val;
226
        }
227
    }
228
 
229
}
230
 
231
# final dump
232
dump_state(\%state, $time, \@dump_signals);
233
 
234
0;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.