package permute; use europa_module_factory; @ISA = qw(europa_module_factory); use strict; sub _width { my $this = shift; return scalar @{$this->mapping()}; } sub add_contents_to_module { my $this = shift; my $module = $this->module(); my $width = $this->_width(); $module->add_contents( e_signal->new({ name => 'a', width => $width, }), e_signal->new({ name => 'x', width => $width, }), ); my @mapping = @{$this->mapping()}; for my $i (0 .. -1 + $width) { $module->add_contents( e_assign->new({ lhs => "x\[$i\]", rhs => "a\[$mapping[$i]\]", }), ); } } # Note: static method; can be called for constructing help text. sub get_fields { my $class = shift; my %fields = ( mapping => {ref => [], }, ); return \%fields; } sub declare_ports { my $this = shift; my $width = $this->_width(); my %outputs = ( x => {width => $width,}, ); my %inputs = ( a => {width => $width,}, ); map {$inputs{$_}->{direction} = "input"} keys %inputs; map {$outputs{$_}->{direction} = "output"} keys %outputs; my %ports = ( %inputs, %outputs, ); return \%ports; } 1;