Netlist.pm 1.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## @file

## @class FIJI::Netlist
#
#
package FIJI::Netlist;

use strict;
use warnings;

use Log::Log4perl qw(get_logger :easy);

use Verilog::Netlist;

15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
sub new ($) {
  my ($class) = @_;

  my $self  = {};
  bless $self, $class;

  $self->{'nl'} = new Verilog::Netlist(
                                           # options => $opt,
                                           # keep_comments => 1, # include comments in netlist
                                           link_read_nonfatal => 1, # do not fail if module description not found
                                          );
  return $self;
}

30

31
32
33
34
sub read_file ($) {
  my $logger = get_logger();
  my ($self, $filename) = @_;
  eval {
35
    $self->{'nl'}->read_file(filename => $filename); # read Verilog file
36
37
38
39
40
41
42
43
    $self->{'nl'}->link(); # Read in any sub-modules
  };

  if ($self->{'nl'}->errors() != 0 || $@) {
    $logger->error("Could not parse $filename!", $@ ? "\n".$@ : "");
    return 1;
  }

44
  $logger->info("Successfully read in netlist from file \"$filename\".");
45
46
47
  return 0;
}

48
49
50
51

# returns an array with all net names
#
# possible future extension:
52
53
54
55
# returns a hash with array of...
# - the 'names' of all nets
# - the 'paths' of all nets (TODO)
# - the 'metadata' of all nets (i.e. what VP's module->nets() returns) (TODO. needed? - it's huge)
56
sub get_nets ($) {
57
  my ($self) = @_;
58
59
  # my $nets_ref = {'metadata' => [], 'names' => [], 'nets' => []};
  my $nets_ref = [];
60
  foreach my $mod ($self->{'nl'}->top_modules_sorted) {
61
    $self->_get_subnets($nets_ref, $mod);
62
  }
63
  return $nets_ref;
64
65
}

66
67

sub _get_subnets ($$) {
68
  my ($self, $nets_ref, $mod) = @_;
69
  foreach my $n ($mod->nets) {
70
    push(@{$nets_ref}, $n->name);
71
72
  }

73
74
  foreach my $cell ($mod->cells_sorted) {
    if (defined($cell->submod)) {
75
      $self->_get_subnets($nets_ref, $cell->submod);
76
77
78
79
80
    }
  }
}

1;