Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Problem with storing values

by mavericknik (Sexton)
on Apr 16, 2015 at 18:37 UTC ( #1123651=perlquestion: print w/replies, xml ) Need Help??

mavericknik has asked for the wisdom of the Perl Monks concerning the following question:

Hello people, Im pretty new to perl, just learning right now. I'm looking to replace some cells in a verilog file using the verilog-perl module. My question is this: The verilog perl module has a function called "->dump_drivers". So basically when I do:
$netdrivers = ($pin->net)->dump_drivers;
The output I see on the screen is:
Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in
What I am trying to so is this :
$netdrivers = ($pin->net)->dump_drivers; my @netdrivers_split = split(/\n/,$netdrivers); foreach my $val (@netdrivers_split) { #some code }
What I want it to do is save
Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in
Then split it into an array using the newline delimiter so I can use the individual values. But when I do
$netdrivers = ($pin->net)->dump_drivers; my @netdrivers_split = split(/\n/,$netdrivers); print @netdrivers_split;
I get:
Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in 0 but true
Why is the value in "@netdrivers_split" "0 but true"? Is this the right way to do it?

Replies are listed 'Best First'.
Re: Problem with storing values (Verilog::Netlist::Net)
by toolic (Bishop) on Apr 16, 2015 at 19:13 UTC
    I don't think this is the right way to do what you want. According to Verilog::Netlist::Net, dump_drivers is for debugging purposes. Since it doesn't give many more details about what it does, you should not rely on it to provide output in a consistent manner. It could change any any time in the future.

    Looking at the source code, dump_drivers prints to STDOUT. So, to capture its output into a variable, you'd probably have to use select. But, I don't think that's worth it.

    The reason you see 0 but true is because that is the return value of the last statement executed by sub dump_drivers:

    flush STDOUT;

    You should gather all the info you need for each pin as you descend through the Verilog module hierarchy.

    UPDATE: Again, I don't recommend it, but to capture the STDOUT, you could do something like:

    my $fh; my $out; my $old_stdout; open $fh, '>', \$out; $old_stdout = select $fh; my $x = $pin->net->dump_drivers(); select $old_stdout; close $fh; print $out; # This has the output you want
      Thank you very much for your reply. Well, the reason I was trying to do this is I'm trying to reuse bits of code that one of my seniors wrote for something similar. It appears that the source code of "dump_drivers" has changed since he used it(a few years back). I tried your method using select, it does seem to work for now. Could you explain what exactly did you do there? The thing is, this is much easier for me to write code for the pins like this as I am cycling through all the pins in the design like so:
      foreach my $cell ($mod->cells) { foreach my $pin ($cell->pins) { $netdrivers = ($pin->net)->dump_drivers; } }
      Then I'm using the drivers to check some conditions. Maybe I could store all the pin drivers for the design beforehand and look them up when required, but this is just so convenient. Is the only reason you would now recomment obtaining the values from STDOUT be that the functionality of "dump_drivers" could change again at anytime? Or is there some other reason? Thanks!
        You're welcome.

        Yes, as I stated, I don't think you should use the dump_drivers output. The primary reason is that it can change in future versions of Verilog-Perl without notice.

        The module author provides some support at http://www.veripool.org/projects/verilog-perl/boards

Re: Problem with storing values
by FreeBeerReekingMonk (Deacon) on Apr 16, 2015 at 21:52 UTC

    Create your own function! you might want to look at this: Extend a module Thus, something like this (untested)

    use Verilog::Netlist::Net; sub Verilog::Netlist::Net::my_dump_drivers { my $self = shift; my $indent = shift||0; my @ret; push @ret, " "x$indent,"Net:",$self->name,"\n"; if (my $port = $self->port) { push @ret, " "x$indent," Port: ",$port->name," ",$port->directio +n,"\n"; } foreach my $cell ($self->module->cells_sorted) { foreach my $pin ($cell->pins_sorted) { if ($pin->port && $pin->net && $pin->net == $self) { push @ret, " "x$indent," Pin: ",$cell->name,".",$pin->name ," ",$pin->port->direction,"\n"; } elsif ($pin->net && $self->name eq $pin->net->name) { push @ret, "%Warning: Internal net name duplicate: ".$cell->na +me." ".$self->name."\n" .$self->comment." ".$pin->net->comment."\n" ."$self ".$pin->net->name."\n"; } } } return @ret; }

    Lateron, you just use @A = my_dump_drivers() instead of dump_drivers(), capturing the output, etc...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1123651]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-12-09 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?