X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FScheme79asm.pm;h=374a8a3f43af771517da7dec974c96f7e2bb798d;hb=04be023f8bc114edb6dddae6cee3bd58ea758561;hp=fdbbd21c3f3f3fe7c3c042ee104511ee70f6fc0f;hpb=5ff3fe858f211c57fe63987adbebfded324774ad;p=app-scheme79asm.git diff --git a/lib/App/Scheme79asm.pm b/lib/App/Scheme79asm.pm index fdbbd21..374a8a3 100644 --- a/lib/App/Scheme79asm.pm +++ b/lib/App/Scheme79asm.pm @@ -3,12 +3,14 @@ package App::Scheme79asm; use 5.014000; use strict; use warnings; +use re '/s'; +use Carp qw/croak/; use Data::Dumper qw/Dumper/; use Data::SExpression qw/consp scalarp/; use Scalar::Util qw/looks_like_number/; -our $VERSION = '0.004'; +our $VERSION = '0.005001'; our %TYPES = ( LIST => 0, @@ -66,9 +68,10 @@ sub process { } $addr += (1 << $self->{addr_bits}) if $addr < 0; - die "Type too large: $type\n" unless $type < (1 << $self->{type_bits}); - die "Addr too large: $addr\n" unless $addr < (1 << $self->{addr_bits}); + die "Type too large: $type\n" if $type >= (1 << $self->{type_bits}); + die "Addr too large: $addr\n" if $addr >= (1 << $self->{addr_bits}); my $result = ($type << $self->{addr_bits}) + $addr; + unless ($location) { $self->{freeptr}++; $location = $self->{freeptr} @@ -118,9 +121,9 @@ sub print_binary16 { die "addr_bits + type_bits >= 16\n"if $self->{addr_bits} + $self->{type_bits} > 16; my $length = @{$self->{memory}}; - print $fh pack('n', $length); + print $fh pack 'n', $length or croak "Failed to print memory size: $!"; # uncoverable branch true for (@{$self->{memory}}) { - print $fh pack('n', $_) + print $fh pack 'n', $_ or croak "Failed to print memory: $!" # uncoverable branch true } } @@ -142,9 +145,9 @@ sub print_verilog { my $spaces = ' ' x ($bits + 5 - (length $val)); $index = sprintf $index_format, $index; - print $fh "mem[$index] <= $val;"; - print $fh "$spaces // $comment" if defined $comment; - print $fh "\n"; + my $string = "mem[$index] <= $val;"; + $string .= "$spaces // $comment" if defined $comment; + say $fh $string or croak "Failed to print verilog: $!"; # uncoverable branch true } }