DASM
Private Attributes
DASMIO::Source Class Reference

DASM DCPU-16 source assembler class. More...

List of all members.

Private Member Functions

Public Functions
retval new (scalar proto, scalar dasm)
 Create an object upon which we can work.
retval identify (scalar self, scalar filename, scalar type)
 Identify whether we can handle reading or writing a given file by its filename.
retval extensions ()
 List the extensions we support.
retval parseline (scalar self, scalar line)
 Parse an instruction line.
retval rebindregister (scalar self, scalar new, scalar old)
 Bind register names, to give them other names than the default.
retval regbinding (scalar self, scalar reg)
 Map a register name to a standard register name.
retval op_DAT (scalar self, scalar lineref, scalar labelref)
 Special opcode 'DAT' to define data in the core.
retval op_RES (scalar self, scalar lineref, scalar labelref)
 Special opcode 'RES' to reserve a block of memory in the core.
retval op_CONST (scalar self, scalar lineref, scalar labelref)
 Special opcode 'CONST' to define a constant symbol.
retval op_ADDRESS (scalar self, scalar lineref, scalar labelref)
 Special opcode 'ADDRESS' to define an address symbol.
retval op_RN (scalar self, scalar lineref, scalar labelref)
 Special opcode 'RN' to define a register name (binding)
retval directive_ORIGIN (scalar self, scalar lineref)
 Assembler directive 'ORIGIN' to change compilation address.
retval directive_INCLUDE (scalar self, scalar lineref)
 Assembler directive 'ORIGIN' to change compilation address.
retval parse_operand (scalar self, scalar lineref, scalar wrap)
 Parse operands and return the values of them.
retval parse_symbol (scalar self, scalar lineref, scalar nonterm)
 Parse a symbol name or value.
retval parse_constant (scalar self, scalar lineref, scalar symbol, scalar wrap)
 Obtain a constant from an input line.
retval write (scalar self)
 Write out a compilable source file based on what we have in the core.
retval decode_operand (scalar self, scalar operand, scalar address, scalar memdataref)
 Decode an operand into a string.
retval decode_nextword (scalar self, scalar address, scalar memdataref)
 Read the next word from a memory address, whilst decoding operands.

Private Attributes

scalar debug_dat
 Whether we're debugging the 'DAT' instruction.
scalar debug_sym
 Whether we're debugging the symbol processing.
scalar disassemble_res_limit
 How much we reserve in our disassembly before changing to .ORIGIN.

Detailed Description

DASM DCPU-16 source assembler class.

This class provides the implementation of the source code assembler for DASM.

The files we support end in '.dasm'.

Source file format:

[<label>]    <opcode>       <operand a>, <operand b>
[<label>]    <ext-opcode>   <operand>
; <comment>

It also provides a disassembler which can produce source code which can be passed back to the assembler. If the source comes from one of the binary formats that doesn't offer relocations or symblols, the content will be more difficult to parse interpret, but should still work.

The structures we use are intended to be able to support libraries of relocatable, partially linked code. This has not yet been tested and the lack of any indication of which symbols are local and which are imported may be a problem in the future.

In addition to the 1.1 DCPU-16 specification, the assembler supports:

Note:
We should really consider changing the structure so that the DASMIO objects inherit from a parser class, rather than having to reference `$self->{'dasm'}` for parser operations like error().

Definition at line 168 of file Source.pm.


Member Function Documentation

retval DASMIO::Source::decode_nextword ( scalar  self,
scalar  address,
scalar  memdataref 
) [private]

Read the next word from a memory address, whilst decoding operands.

Apply any relocations that we know about such that the decode comes out as readable.

The actual value in memory is appended to the memdataref list. If the memory is not known, we return '?' and an undef entry in the array.

Parameters:
[in]$selfIO object
[in]$addressAddress of 'nextword'
[in,out]$memdatarefReference to an address of data read from memory which we will update if we read any data
Returns:
extword string
retval DASMIO::Source::decode_operand ( scalar  self,
scalar  operand,
scalar  address,
scalar  memdataref 
) [private]

Decode an operand into a string.

Parameters:
[in]$selfIO object
[in]$operandOperand value
[in]$addressAddress of 'nextword'
[in,out]$memdatarefReference to an address of data read from memory which we will update if we read any data
Returns:
Operand definition string
retval DASMIO::Source::directive_INCLUDE ( scalar  self,
scalar  lineref 
) [private]

Assembler directive 'ORIGIN' to change compilation address.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
retval DASMIO::Source::directive_ORIGIN ( scalar  self,
scalar  lineref 
) [private]

Assembler directive 'ORIGIN' to change compilation address.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
retval DASMIO::Source::extensions ( ) [private]

List the extensions we support.

Parameters:
[in]$selfOur object
Returns:
arrayref of extensions
retval DASMIO::Source::identify ( scalar  self,
scalar  filename,
scalar  type 
) [private]

Identify whether we can handle reading or writing a given file by its filename.

Parameters:
[in]$selfOur object
[in]$filenameFilename we're accessing
[in]$type'read' or 'write'
Return values:
1if we can access it
0if we cannot access it
retval DASMIO::Source::new ( scalar  proto,
scalar  dasm 
) [private]

Create an object upon which we can work.

Parameters:
[in]$protoPrototype object, or this class's name
[in]$dasmDASM object we're working on
Returns:
new object
retval DASMIO::Source::op_ADDRESS ( scalar  self,
scalar  lineref,
scalar  labelref 
) [private]

Special opcode 'ADDRESS' to define an address symbol.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
[in,out]$labelrefReference to the label for this line, updated to undef if we should not defined a label for this initial address
retval DASMIO::Source::op_CONST ( scalar  self,
scalar  lineref,
scalar  labelref 
) [private]

Special opcode 'CONST' to define a constant symbol.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
[in,out]$labelrefReference to the label for this line, updated to undef if we should not defined a label for this initial address
retval DASMIO::Source::op_DAT ( scalar  self,
scalar  lineref,
scalar  labelref 
) [private]

Special opcode 'DAT' to define data in the core.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
[in,out]$labelrefReference to the label for this line, updated to undef if we should not defined a label for this initial address
retval DASMIO::Source::op_RES ( scalar  self,
scalar  lineref,
scalar  labelref 
) [private]

Special opcode 'RES' to reserve a block of memory in the core.

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
[in,out]$labelrefReference to the label for this line, updated to undef if we should not defined a label for this initial address
retval DASMIO::Source::op_RN ( scalar  self,
scalar  lineref,
scalar  labelref 
) [private]

Special opcode 'RN' to define a register name (binding)

Parameters:
[in]$selfThis source object
[in,out]$linerefReference to the line end we are parsing, updated to leave remaining text
[in,out]$labelrefReference to the label for this line, updated to undef if we should not defined a label for this initial address
retval DASMIO::Source::parse_constant ( scalar  self,
scalar  lineref,
scalar  symbol,
scalar  wrap 
) [private]

Obtain a constant from an input line.

Parameters:
[in]$selfDASMIO object
[in,out]$linerefreference to line to read from
[in]$symbol'constant' : only a constant is acceptable 'symbol' : symbol is acceptable (default)
[in]$wrap'nowrap' : do not wrap large/small numbers 'wrap' : wrap numbers (default)
Returns:
$value The value to store $symbol Relocation symbol to apply, or none if not found
retval DASMIO::Source::parse_operand ( scalar  self,
scalar  lineref,
scalar  wrap 
) [private]

Parse operands and return the values of them.

Parameters:
[in]$selfIO object
[in,out]$linerefReference to the line that we're parsing
[in]$wrap'nowrap' : do not wrap large/small numbers 'wrap' : wrap numbers (default)
Returns:
hashref of operand details: 'type' => 'reg' (register value : register=>regname) 'regaddr' (register address : register=>regname) 'regindex' (registered indexed : register>regname) 'pop' (stack pop) 'peek' (stack peek) 'push' (stack push) 'sp' (stack pointer) 'pc' (program counter) 'o' (overflow) 'indirect' (dereference next address) 'load' (load next address) 'loadshort' (load short value : value=>short value) 'opval' => value in the operand register 'register' => register, if applicable 'nextword' => next word data, if applicable 'value' => value, if applicable
retval DASMIO::Source::parse_symbol ( scalar  self,
scalar  lineref,
scalar  nonterm 
) [private]

Parse a symbol name or value.

Parameters:
[in]$selfDASM object
[in,out]$linerefReference to the line that we're parsing
Returns:
hashref of symbol details: 'type' => 'constant' : a constant value 'address' : an address constant 'value' => value 'symbol' => any symbol name to use as relocation
retval DASMIO::Source::parseline ( scalar  self,
scalar  line 
) [private]

Parse an instruction line.

Parameters:
[in]$selfIO object
[in]$lineLine to process
retval DASMIO::Source::rebindregister ( scalar  self,
scalar  new,
scalar  old 
) [private]

Bind register names, to give them other names than the default.

Parameters:
[in]$selfThis source object
[in]$newNew register name
[in]$oldOld register name, or undef to remove mapping
retval DASMIO::Source::regbinding ( scalar  self,
scalar  reg 
) [private]

Map a register name to a standard register name.

Parameters:
[in]$selfThis object
[in]$regRegister to lookup
retval DASMIO::Source::write ( scalar  self) [private]

Write out a compilable source file based on what we have in the core.

Parameters:
[in]$selfAddress object
Returns:
Content to write

Member Data Documentation

scalar DASMIO::Source::debug_dat [private]

Whether we're debugging the 'DAT' instruction.

Definition at line 172 of file Source.pm.

scalar DASMIO::Source::debug_sym [private]

Whether we're debugging the symbol processing.

Definition at line 175 of file Source.pm.

How much we reserve in our disassembly before changing to .ORIGIN.

Definition at line 178 of file Source.pm.


The documentation for this class was generated from the following file: