lib/CPU/Z80/Assembler/JumpOpcode.pm

filter: Statementstmt 100% 34 / 34 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 8 / 8 totaltotal 88.7% 63 / 71 SCAR 19.5
CC
7
Cov
92%
new
3.1
short_jump
2.1
long_jump
2.1
CRAP 7.0
« lib/CPU/Z80/Assembler/Opcode.pm ↑ Summary script/z80masm »
1 # $Id$
2  
3 package CPU::Z80::Assembler::JumpOpcode;
4  
5 #------------------------------------------------------------------------------
6  
7 =head1 NAME
8  
9 CPU::Z80::Assembler::JumpOpcode - Represents one jump assembly instruction to be
10 computed at link time
11  
12 =cut
13  
14 #------------------------------------------------------------------------------
15  
16 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 36 our $VERSION = '2.24';
20  
21 36 ▶use Asm::Preproc::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 sub new {
24 3234 ▶ my($class, %args) = @_;
Subroutine new: called CC=3 SCAR=11.4
Pod documented
25 bless [
26 $args{short_jump} || CPU::Z80::Assembler::Opcode->new(),
27 # short jump opcode
28 3234 ▶ $args{long_jump} || CPU::Z80::Assembler::Opcode->new(),
Condition66%4/6
$args{'short_jump'} || 'CPU::Z80::Assembler::Opcode'->new
l!l&&r!l&&!r
323310
$args{'long_jump'} || 'CPU::Z80::Assembler::Opcode'->new
l!l&&r!l&&!r
323310
MC/DC0%0/2
$args{'short_jump'} || 'CPU::Z80::Assembler::Opcode'->new
$args{'short_jump'} 'CPU::Z80::Assembler::Opcode'->new
MC/DC0%0/2
$args{'long_jump'} || 'CPU::Z80::Assembler::Opcode'->new
$args{'long_jump'} 'CPU::Z80::Assembler::Opcode'->new
Truth table66%2/3
A || B
A= $args{'short_jump'}B= 'CPU::Z80::Assembler::Opcode'->new
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args{'long_jump'}B= 'CPU::Z80::Assembler::Opcode'->new
ABresult
1X1
011
000
29 # long jump opcode
30 ], $class;
31 }
32 25847 ▶sub short_jump { defined($_[1]) ? $_[0][0] = $_[1] : $_[0][0] }
Subroutine short_jump: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 25847 25847
33 12041 ▶sub long_jump { defined($_[1]) ? $_[0][1] = $_[1] : $_[0][1] }
Subroutine long_jump: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 12041 12041
34  
35 # address and line : read from short_jump, write to short_jump and long_jump
36 sub address {
37 8872 ▶ my($self, $address) = @_;
Subroutine address: called CC=2 SCAR=6.9
Pod documented
38 8872 ▶ if (defined $address) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $address) { } 8869 3 8872
39 8869 $self->short_jump->address($address);
40 8869 $self->long_jump->address($address);
41 8869 return $address;
42 }
43 else {
44 3 return $self->short_jump->address;
45 }
46 }
47  
48 sub line {
49 77 ▶ my($self, $line) = @_;
Subroutine line: called CC=2 SCAR=6.9
Pod documented
50 77 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) { } 1 76 77
51 1 $self->short_jump->line($line);
52 1 $self->long_jump->line($line);
53 1 return $line;
54 }
55 else {
56 76 return $self->short_jump->line;
57 }
58 }
59  
60 #------------------------------------------------------------------------------
61  
62 =head1 SYNOPSIS
63  
64 use CPU::Z80::Assembler::JumpOpcode;
65 $opcode = CPU::Z80::Assembler::Opcode->new(
66 short_jump => CPU::Z80::Assemble::Opcode->new( ... JR instr ...),
67 long_jump => CPU::Z80::Assemble::Opcode->new( ... JP instr ...));
68 $opcode->address;
69 $opcode->line;
70 $dist = short_jump_dist($address, \%symbol_table);
71 $bytes = $opcode->bytes($address, \%symbol_table);
72 $size = $opcode->size;
73  
74 =head1 DESCRIPTION
75  
76 This module defines the class that represents one jump instruction to be
77 added to the object code. The object contains both the short jump form and
78 the long jump form.
79  
80 During address allocation all short jumps that are out of range are replaced
81 by long jumps.
82  
83 =head1 EXPORTS
84  
85 Nothing.
86  
87 =head1 FUNCTIONS
88  
89 =head2 new
90  
91 Creates a new object.
92  
93 =head2 address
94  
95 Address where this opcode is loaded, computed at link time.
96  
97 =head2 short_jump
98  
99 Returns the L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode> object representing the short jump.
100  
101 =head2 long_jump
102  
103 Returns the L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode> object representing the long jump.
104  
105 =head2 line
106  
107 Get/set the line - text, file name and line number where the token was read.
108  
109 =cut
110  
111 #------------------------------------------------------------------------------
112  
113 =head2 short_jump_dist
114  
115 Gets the short jump distance, in relation to the address of the next
116 instruction.
117  
118 Returns more than 127 or less than -128 if the short jump is out of range.
119  
120 =cut
121  
122 #------------------------------------------------------------------------------
123  
124 sub short_jump_dist {
125 4013 ▶ my($self, $address, $symbol_table) = @_;
Subroutine short_jump_dist: called CC=1 SCAR=0.0
Pod documented
126
127 # expr in a short jump is always second byte
128 4013 my $dist = $self->short_jump->child->[1]->evaluate($address, $symbol_table);
129 4013 return $dist;
130 }
131  
132 #------------------------------------------------------------------------------
133  
134 =head2 bytes
135  
136 $bytes = $opcode->bytes($address, \%symbol_table);
137  
138 Computes all the expressions in the short jump and returns the bytes string
139 with the result object code.
140  
141 =cut
142  
143 #------------------------------------------------------------------------------
144  
145 sub bytes {
146 2429 ▶ my($self, $address, $symbol_table) = @_;
Subroutine bytes: called CC=1 SCAR=0.0
Pod documented
147 2429 return $self->short_jump->bytes($address, $symbol_table);
148 }
149  
150 #------------------------------------------------------------------------------
151  
152 =head2 size
153  
154 $size = $opcode->size;
155  
156 Return the number of bytes that the short_jump opcode will generate.
157  
158 =cut
159  
160 #------------------------------------------------------------------------------
161  
162 sub size {
163 8869 ▶ my($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod documented
164 8869 return $self->short_jump->size;
165 }
166  
167 #------------------------------------------------------------------------------
168  
169 =head1 BUGS and FEEDBACK
170  
171 See L<CPU::Z80::Assembler|CPU::Z80::Assembler>.
172  
173 =head1 SEE ALSO
174  
175 L<CPU::Z80::Assembler|CPU::Z80::Assembler>
176 L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode>
177 L<Asm::Preproc::Line|Asm::Preproc::Line>
178  
179 =head1 AUTHORS, COPYRIGHT and LICENCE
180  
181 See L<CPU::Z80::Assembler|CPU::Z80::Assembler>.
182  
183 =cut
184  
185 #------------------------------------------------------------------------------
186  
187 36 1;
188  
« lib/CPU/Z80/Assembler/Opcode.pm ↑ Summary script/z80masm »