| 1 | # $Id$ | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | package CPU::Z80::Assembler::Segment; | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | CPU::Z80::Assembler::Segment - Represents one segment of assembly opcodes | ||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 36 | our $VERSION = '2.23'; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 36 | ▶ | use Asm::Preproc::Line; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | #use Class::Struct ( | ||||||||||||||||||||||||||||||
| 23 | # child => '@', # list of children of this node | ||||||||||||||||||||||||||||||
| 24 | # line => 'Asm::Preproc::Line', | ||||||||||||||||||||||||||||||
| 25 | # # line of first token | ||||||||||||||||||||||||||||||
| 26 | # name => '$', # name of the segment | ||||||||||||||||||||||||||||||
| 27 | # address => '$', # start address of segment | ||||||||||||||||||||||||||||||
| 28 | #); | ||||||||||||||||||||||||||||||
| 29 | sub new { | ||||||||||||||||||||||||||||||
| 30 | 2799 | ▶ | my($class, %args) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 31 | bless [ | ||||||||||||||||||||||||||||||
| 32 | $args{name}, | ||||||||||||||||||||||||||||||
| 33 | $args{address}, | ||||||||||||||||||||||||||||||
| 34 | $args{line} || Asm::Preproc::Line->new(), | ||||||||||||||||||||||||||||||
| 35 | 2799 | ▶ | $args{child} || [], | ||||||||||||||||||||||||||||
|
Condition40%2/5
$args{'line'} || 'Asm::Preproc::Line'->new
$args{'child'} || []
MC/DC0%0/2
$args{'line'} || 'Asm::Preproc::Line'->new
$args{'line'}
'Asm::Preproc::Line'->new
MC/DC0%0/1
$args{'child'} || []
$args{'child'}
Truth table33%1/3
A || B
A= $args{'line'}B= 'Asm::Preproc::Line'->new
Truth table50%1/2
A
A= $args{'child'}
| |||||||||||||||||||||||||||||||
| 36 | ], $class; | ||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||
| 38 | 44 | ▶ | sub name { defined($_[1]) ? $_[0][0] = $_[1] : $_[0][0] } | ||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 39 | 36122 | ▶ | sub address { defined($_[1]) ? $_[0][1] = $_[1] : $_[0][1] } | ||||||||||||||||||||||||||||
|
Subroutine
address: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 40 | 2817 | ▶ | sub line { defined($_[1]) ? $_[0][2] = $_[1] : $_[0][2] } | ||||||||||||||||||||||||||||
|
Subroutine
line: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | 109905 | ▶ | sub child { defined($_[1]) ? $_[0][3] = $_[1] : $_[0][3] } | ||||||||||||||||||||||||||||
|
Subroutine
child: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | use CPU::Z80::Assembler::Segment; | ||||||||||||||||||||||||||||||
| 48 | my $segment = CPU::Z80::Assembler::Segment->new( | ||||||||||||||||||||||||||||||
| 49 | name => $name, | ||||||||||||||||||||||||||||||
| 50 | address => 0, | ||||||||||||||||||||||||||||||
| 51 | line => $line, | ||||||||||||||||||||||||||||||
| 52 | child => [$opcode, ...]); | ||||||||||||||||||||||||||||||
| 53 | $self->add(@opcodes); | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | This module defines the class that represents one continuous segment of assembly | ||||||||||||||||||||||||||||||
| 58 | instruction opcodes L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode>. | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | =head1 EXPORTS | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | Nothing. | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | =head2 new | ||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | Creates a new object, see L<Class::Struct|Class::Struct>. | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | =head2 child | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | Each child is one L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode> object. | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | =head2 name | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | Get/set of segment name. | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | =head2 address | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | Get/set of base address of the segment. | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | =head2 line | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | Get/set the line - text, file name and line number of the start of the segment. | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | =head2 add | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | Adds the opcodes to the segment. The line of the first opcode added is copied to | ||||||||||||||||||||||||||||||
| 93 | the segment for error messages. | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | sub add { | ||||||||||||||||||||||||||||||
| 100 | 22054 | ▶ | my($self, @opcodes) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | 22054 | ▶ | if (@opcodes) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | # update line if first opcodes | ||||||||||||||||||||||||||||||
| 104 | 22053 | ▶ | if (! @{$self->child}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 105 | 2794 | $self->line( $opcodes[0]->line ); | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | # save opcodes | ||||||||||||||||||||||||||||||
| 109 | 22053 | push(@{$self->child}, @opcodes); | |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | =head1 BUGS and FEEDBACK | ||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | See L<CPU::Z80::Assembler|CPU::Z80::Assembler>. | ||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | L<CPU::Z80::Assembler|CPU::Z80::Assembler> | ||||||||||||||||||||||||||||||
| 122 | L<CPU::Z80::Assembler::Opcode|CPU::Z80::Assembler::Opcode> | ||||||||||||||||||||||||||||||
| 123 | L<Asm::Preproc::Line|Asm::Preproc::Line> | ||||||||||||||||||||||||||||||
| 124 | L<Class::Struct|Class::Struct> | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | =head1 AUTHORS, COPYRIGHT and LICENCE | ||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | See L<CPU::Z80::Assembler|CPU::Z80::Assembler>. | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | 36 | 1; | |||||||||||||||||||||||||||||