| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Verilog::VCD::Writer; | ||||||||||
| 4 | 2 | $Verilog::VCD::Writer::VERSION = '0.004'; | |||||||||
| 5 | 2 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Verilog::VCD::Writer::Module; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: VCD waveform File creation module. | ||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 2 | has timescale =>(is =>'ro',default=>'1ps'); | |||||||||
| 18 | 2 | has vcdfile =>(is =>'ro'); | |||||||||
| 19 | 2 | ▶ | has date =>(is=>'ro',isa=>'DateTime',default=>sub{DateTime->now()}); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | has _modules=>(is=>'ro',isa=>'ArrayRef[Verilog::VCD::Writer::Module]', | ||||||||||
| 21 | 4 | ▶ | default=>sub{[]}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | traits=>['Array'], | |||||||||
| 23 | handles=>{modules_push=>'push', | ||||||||||
| 24 | modules_all=>'elements'} | ||||||||||
| 25 | ); | ||||||||||
| 26 | has _comments=>(is=>'ro',isa=>'ArrayRef', | ||||||||||
| 27 | 4 | ▶ | default=>sub{[]}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | traits=>['Array'], | |||||||||
| 29 | handles=>{comments_push=>'push', | ||||||||||
| 30 | comments_all=>'elements'} | ||||||||||
| 31 | ); | ||||||||||
| 32 | 2 | has _fh=>(is=>'ro',lazy=>1,builder=>"_redirectSTDOUT"); | |||||||||
| 33 | |||||||||||
| 34 | 2 | ▶ | sub _redirectSTDOUT{ | ||||||||
|
Subroutine
_redirectSTDOUT: called CC=4 SCAR=14.0
| |||||||||||
| 35 | 2 | my $self=shift; | |||||||||
| 36 | 2 | my $fh; | |||||||||
| 37 | 2 | ▶ | if(defined $self->vcdfile){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 1 | ▶ | open($fh, ">", $self->vcdfile) or die "unable to write to $self->vcdfile"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | }else{ | ||||||||||
| 40 | 1 | ▶ | open($fh, ">-") or die "unable to write to STDOUT"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | } | ||||||||||
| 42 | 2 | return $fh; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | sub writeHeaders{ | ||||||||
|
Subroutine
writeHeaders: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 2 | my $self=shift; | |||||||||
| 48 | 2 | my $fh=$self->_fh; | |||||||||
| 49 | 2 | say $fh '$date'; | |||||||||
| 50 | 2 | say $fh $self->date; | |||||||||
| 51 | 2 | say $fh '$end | |||||||||
| 52 | $version | ||||||||||
| 53 | Perl VCD Writer Version '.$Verilog::VCD::Writer::VERSION.' | ||||||||||
| 54 | $end | ||||||||||
| 55 | $comment'; | ||||||||||
| 56 | 2 | say $fh join("::\n",$self->comments_all); | |||||||||
| 57 | 2 | say $fh '$end | |||||||||
| 58 | $timescale '.$self->timescale.' $end'; | ||||||||||
| 59 | 2 | $_->printScope($fh) foreach ($self->modules_all); | |||||||||
| 60 | 2 | say $fh '$enddefinitions $end | |||||||||
| 61 | $dumpvars | ||||||||||
| 62 | '; | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | 4 | ▶ | sub addModule{ | ||||||||
|
Subroutine
addModule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 4 | my ($self,$modulename)=@_; | |||||||||
| 68 | 4 | my $m=Verilog::VCD::Writer::Module->new(name=>$modulename,type=>"module"); | |||||||||
| 69 | 4 | $self->modules_push($m); | |||||||||
| 70 | 4 | return $m; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 4 | ▶ | sub setTime { | ||||||||
|
Subroutine
setTime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | 4 | my ($self,$time)=@_; | |||||||||
| 77 | 4 | my $fh=$self->_fh; | |||||||||
| 78 | 4 | say $fh '#'.$time; | |||||||||
| 79 | |||||||||||
| 80 | } | ||||||||||
| 81 | 6 | ▶ | sub _dec2bin { | ||||||||
|
Subroutine
_dec2bin: called CC=1 SCAR=0.0
| |||||||||||
| 82 | 6 | my $str = unpack("B32", pack("N", shift)); | |||||||||
| 83 | 6 | $str =~ s/^0+(?=\d)//; # otherwise you'll get leading zeros | |||||||||
| 84 | 6 | return $str; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | 12 | ▶ | sub addValue { | ||||||||
|
Subroutine
addValue: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 89 | 12 | my ($self,$sig,$value)=@_; | |||||||||
| 90 | 12 | my $fh=$self->_fh; | |||||||||
| 91 | #say STDERR "Adding Values $sig $value"; | ||||||||||
| 92 | 12 | ▶ | if ($sig->width == 1){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 6 | say $fh $value.$sig->symbol; | |||||||||
| 94 | }else { | ||||||||||
| 95 | 6 | say $fh "b"._dec2bin($value)." ". $sig->symbol; | |||||||||
| 96 | } | ||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | |||||||||||
| 100 | 2 | ▶ | sub addComment{ | ||||||||
|
Subroutine
addComment: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 101 | 2 | my ($self,$comment)=@_; | |||||||||
| 102 | 2 | $self->comments_push(" ".$comment); | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | 2 | ▶ | sub flush{ | ||||||||
|
Subroutine
flush: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 107 | 2 | my ($self)=shift; | |||||||||
| 108 | 2 | my$fh=$self->_fh; | |||||||||
| 109 | 2 | $fh->autoflush(1); | |||||||||
| 110 | |||||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | 2 | 1; | |||||||||
| 116 | |||||||||||
| 117 | __END__ | ||||||||||