File: PinSelection.pm

package info (click to toggle)
libverilog-perl 3.482-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,728 kB
  • sloc: perl: 8,685; yacc: 3,387; cpp: 2,266; lex: 1,502; makefile: 8; fortran: 3
file content (136 lines) | stat: -rw-r--r-- 3,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Verilog - Verilog Perl Interface
# See copyright, etc in below POD section.
######################################################################

package Verilog::Netlist::PinSelection;

use vars qw($VERSION);
use strict;
use warnings;

$VERSION = '3.427';

######################################################################
#### Methods

## Constructor
sub new {
    my ($class, $netname, $msb, $lsb) = @_;

    my $self = bless({}, $class);
    $self->{_netname} = $netname;
    $self->{_msb} = $msb;
    $self->{_lsb} = $lsb;
    return $self;
}

## Standard accessors
sub netname {
    # ($self, $new) = @_;
    $_[0]->{_netname} = $_[1] if (@_ == 2);
    return $_[0]->{_netname};
}

sub lsb {
    # ($self, $new) = @_;
    $_[0]->{_lsb} = $_[1] if (@_ == 2);
    return $_[0]->{_lsb};
}

sub msb {
    # ($self, $new) = @_;
    $_[0]->{_msb} = $_[1] if (@_ == 2);
    return $_[0]->{_msb};
}

## Member functions
sub bracketed_msb_lsb {
    my $self = shift;
    my $out = "";
    # Handle sized constant numbers (e.g., 7'b0) distinctively
    # but leave unsized constants (msb/lsb undefined) alone.
    if ($self->netname =~ /^'/) {
	$out .= $self->msb + 1 if defined($self->msb);
	$out .= $self->netname;
    } else {
	$out .= $self->netname;
	if (defined($self->msb)) {
	    if ($self->msb == $self->lsb) {
		$out .= "[".$self->msb."]";
	    } else {
		$out .= "[".$self->msb.":".$self->lsb."]";
	    }
	}
    }
    return $out;
}

######################################################################
#### Package return
1;
__END__

=pod

=head1 NAME

Verilog::Netlist::PinSelection - Nets attached to a Verilog Cell's Pins

=head1 DESCRIPTION

Verilog::Netlist::PinSelection objects are used by Verilog::Netlist::Pin
to define ranges of nets attached to the respective pin of a cell.

=head1 ACCESSORS

=over 4

=item $self->netname

Name of the respective net, or, if use_pinselects is disabled, the string
representation of the whole pin value. In the case of a sized constant only
the part following the ' is stored while the width is encoded in the msb
and lsb fields.

=item $self->lsb

Least significant bit of the underlying net within the selection.

=item $self->msb

Most significant bit of the underlying net within the selection.

=back

=head1 MEMBER FUNCTIONS

=over 4

=item $self->bracketed_msb_lsb

Returns the common string representation of a vectored net, e.g. netA[15:8].

=back

=head1 DISTRIBUTION

Verilog-Perl is part of the L<https://www.veripool.org/> free Verilog EDA
software tool suite.  The latest version is available from CPAN and from
L<https://www.veripool.org/verilog-perl>.

Copyright 2000-2024 by Wilson Snyder.  This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.

=head1 AUTHORS

Stefan Tauner <tauner@technikum-wien.at>
Wilson Snyder <wsnyder@wsnyder.org>

# =head1 SEE ALSO

# L<Verilog-Perl>,
# L<Verilog::Netlist>
# L<Verilog::Netlist::Pin>

=cut