File Coverage

blib/lib/CPU/x86_64/InstructionWriter/RipRelative.pm
Criterion Covered Total %
statement 23 28 82.1
branch 5 10 50.0
condition 2 7 28.5
subroutine 8 9 88.8
pod 1 5 20.0
total 39 59 66.1


line stmt bran cond sub pod time code
1             package CPU::x86_64::InstructionWriter::RipRelative;
2             our $VERSION = '0.005'; # VERSION
3 20     20   172 use strict;
  20         38  
  20         769  
4 20     20   95 use warnings;
  20         37  
  20         974  
5 20     20   160 use Carp;
  20         37  
  20         1310  
6 20     20   111 use Scalar::Util 'weaken';
  20         55  
  20         9516  
7              
8             # ABSTRACT: Object representing an offset to a label
9              
10              
11 636 100   636 1 980 sub instruction { weaken($_[0]{instruction}= $_[1]) if @_ > 1; $_[0]{instruction} }
  636         1055  
12 359 50   359 0 514 sub target { @_ > 1 && carp "Read-only"; $_[0]{target} }
  359         632  
13 0     0 0 0 sub name { 'rip-to-' . $_[0]{target}->name }
14             sub value {
15 179     179 0 216 my $self= shift;
16 179 50 50     266 if (($self->instruction->relative_to||0) == ($self->target->relative_to||0)) {
      50        
17 179         238 my $rip_ofs= $self->instruction->offset + $self->instruction->len;
18 179         254 my $label_ofs= $self->target->offset;
19 179 50       450 return defined $label_ofs? $label_ofs - $rip_ofs : undef;
20             } else {
21 0         0 my $start= $self->instruction->relative_to->value;
22 0         0 my $ofs= $self->instruction->offset + $self->instruction->len;
23 0         0 my $label_val= $self->target->value;
24 0 0 0     0 return !(defined $start && defined $label_val)? undef
25             : $label_val - ($start + $ofs);
26             }
27             }
28              
29             sub clone_into_writer {
30 1     1 0 3 my ($self, $writer, $offset, $label_map)= @_;
31             bless {
32             instruction => $self->instruction,
33 1         2 target => $label_map->{$self->target}
34             }, ref $self;
35             }
36              
37             1;
38              
39             __END__