NAME

CPU::Z80::Assembler::Program - Represents one assembly program

SYNOPSIS

use CPU::Z80::Assembler::Program;
my $program = CPU::Z80::Assembler::Program->new(
                  symbols => {},
                  macros  => {});
$program->parse($input);
$segment = $program->segment;
$segment = $program->segment("CODE");
$segment = $program->split_segment;
$program->add_opcodes(@opcodes);
$program->add_label($name, $line);
$program->org($address);
$bytes = $program->bytes;
$list_output = CPU::Z80::Assembler::List->new(input => \@input, output => \*STDOUT);
$bytes = $program->bytes($list_output);

DESCRIPTION

This module defines the class that represents one assembly program composed of CPU::Z80::Assembler::Segment.

EXPORTS

Nothing.

FUNCTIONS

new

Creates a new object, see Class::Struct.

child

Each child is one CPU::Z80::Assembler::Segment object, in the order found in the program.

symbols

Hash of all symbols defined in the program. The key is the symbol name, and the value is either a scalar for a constant, a CPU::Z80::Assembler::Expr for an expression, or a CPU::Z80::Assembler::Opcode for a label.

macros

Hash of macro names to CPU::Z80::Assembler::Macro objects for all defined macros.

parse

$program->parse($input);

Parse the assembly program and collect the opcodes into the object. $input is a stream of tokens as retrieved by CPU::Z80::Assembler z80lexer.

segment

Get/Set the current segment. The current segment is the one where new opcodes are added.

When called without arguments returns a CPU::Z80::Assembler::Segment object of the current segment.

When called with a $name, it sets the segment with the given name as current. If no such segment exists, a new segment with that name is appended to the list and set current.

split_segment

Splits the current segment at the current position, creating a new segment, inserting it just after the current one and setting it as current.

Returns the new current segment.

As a special case, if the current is empty, then nothing is done.

This is used to split one segment in two after a second ORG statement.

add_opcodes

Adds the opcodes to the current segment.

add_label

Add a new label at the current position with given name and line. The line is used for error messages and assembly listing.

It is an error to add a label twice with the same name.

org

Splits the current segment with split_segment() and sets the start address of the new current segment.

bytes

Allocate addresses for all child segments, starting at the first segment's address (defined by a "org" instruction), or at 0.

Computes the bytes of each segment, and concatenates them together. Returns the complete object code.

Gaps between segments are filled with $CPU::Z80::Assembler::fill_byte.

$list_output is an optional CPU::Z80::Assembler::List object to dump the assembly listing to.

BUGS and FEEDBACK

See CPU::Z80::Assembler.

SEE ALSO

CPU::Z80::Assembler CPU::Z80::Assembler::Segment CPU::Z80::Assembler::Parser Class::Struct

AUTHORS, COPYRIGHT and LICENCE

See CPU::Z80::Assembler.