CPU::Z80::Assembler::Segment - Represents one segment of assembly opcodes


CPU-Z80-Assembler documentation Contained in the CPU-Z80-Assembler distribution.

Index


Code Index:

NAME

Top

CPU::Z80::Assembler::Segment - Represents one segment of assembly opcodes

SYNOPSIS

Top

  use CPU::Z80::Assembler::Segment;
  my $segment = CPU::Z80::Assembler::Segment->new(
					name => $name,
					address => 0,
					line => $line,
					child => [$opcode, ...]);
  $self->add(@opcodes);

DESCRIPTION

Top

This module defines the class that represents one continuous segment of assembly instruction opcodes CPU::Z80::Assembler::Opcode.

EXPORTS

Top

Nothing.

FUNCTIONS

Top

new

Creates a new object, see Class::Struct.

child

Each child is one CPU::Z80::Assembler::Opcode object.

name

Get/set of segment name.

address

Get/set of base address of the segment.

line

Get/set the line - text, file name and line number of the start of the segment.

add

Adds the opcodes to the segment. The line of the first opcode added is copied to the segment for error messages.

BUGS and FEEDBACK

Top

See CPU::Z80::Assembler.

SEE ALSO

Top

CPU::Z80::Assembler CPU::Z80::Assembler::Opcode Asm::Preproc::Line Class::Struct

AUTHORS, COPYRIGHT and LICENCE

Top


CPU-Z80-Assembler documentation Contained in the CPU-Z80-Assembler distribution.
# $Id: Segment.pm,v 1.10 2010/11/21 16:40:27 Paulo Exp $

package CPU::Z80::Assembler::Segment;

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------

use strict;
use warnings;

our $VERSION = '2.13';

use Asm::Preproc::Line;

#use Class::Struct (
#		child	=> '@',		# list of children of this node
#		line 	=> 'Asm::Preproc::Line',
#							# line of first token
#		name	=> '$',		# name of the segment
#		address	=> '$',		# start address of segment
#);
sub new { 
	my($class, %args) = @_;
	bless [
		$args{name}, 
		$args{address}, 
		$args{line} 	|| Asm::Preproc::Line->new(),
		$args{child} 	|| [], 
	], $class;
}
sub name	{ defined($_[1]) ? $_[0][0] = $_[1] : $_[0][0] }
sub address { defined($_[1]) ? $_[0][1] = $_[1] : $_[0][1] }
sub line 	{ defined($_[1]) ? $_[0][2] = $_[1] : $_[0][2] }
sub child 	{ defined($_[1]) ? $_[0][3] = $_[1] : $_[0][3] }

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------

sub add { 
	my($self, @opcodes) = @_;
	
	if (@opcodes) {
		# update line if first opcodes
		if (! @{$self->child}) {
			$self->line( $opcodes[0]->line );
		}

		# save opcodes
		push(@{$self->child}, @opcodes);
	}
}

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------

1;