The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CPU::Z80::Assembler::Preprocessor - Preprocessor for the Z80 assembler

SYNOPSIS

  use CPU::Z80::Assembler::Preprocessor;

  open($fh, $file1) or die;
  my $stream = z80preprocessor("#include 'file2'\n", sub {<$fh>});
  my $line = $stream->get;

DESCRIPTION

This module provides a preprocessor to handle file includes. It is called by CPU::Z80::Assembler::Lexer to retrieve each line of input to scan.

EXPORTS

By default the 'z80preprocessor' subroutine is exported.

FUNCTIONS

z80preprocessor

This takes as parameter a list of either text lines to parse, or iterators that return text lines to parse.

The result is a CPU::Z80::Assembler::Stream of CPU::Z80::Assembler::Line objects that contain each of the input lines of the input.

PREPROCESSING

The following preprocessor-like lines are processed:

  %line N+M FILE

nasm-like line directive, telling that the next input line is line N from file FILE, followed by lines N+M, N+2*M, ... This information is used to generate error messages. Usefull to assemble a file preprocessed by nasm.

  #line N "FILE"

cpp-like line directive, telling that the next input line is line N from file FILE, followed by lines N+1, N+2, ... This information is used to generate error messages. Usefull to assemble a file preprocessed by cpp.

  include 'FILE'
  include "FILE"
  include <FILE>
  %include ...
  #include ...

nasm/cpp-like include directive, asking to insert the contents of the given file in the input stream. The preprocessor inserts %line directives to synchronize file positions before and after the file inclusion.

The easiest form to ask z80asm to assemble a file is to write:

  z80asm("include 'FILE'");

All the other preprocessor-like lines are ignored, i.e. lines starting with '#' or '%'.

BUGS and FEEDBACK

See CPU::Z80::Assembler.

SEE ALSO

CPU::Z80::Assembler CPU::Z80::Assembler::Line CPU::Z80::Assembler::Lexer CPU::Z80::Assembler::Stream

AUTHORS, COPYRIGHT and LICENCE

See CPU::Z80::Assembler.