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 parse_operand (scalar self, scalar lineref)
 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)
 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.

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 156 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::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::parse_constant ( scalar  self,
scalar  lineref,
scalar  symbol 
) [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
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 
) [private]

Parse operands and return the values of them.

Parameters:
[in]$selfIO object
[in,out]$linerefReference to the line that we're parsing
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::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 160 of file Source.pm.

scalar DASMIO::Source::debug_sym [private]

Whether we're debugging the symbol processing.

Definition at line 163 of file Source.pm.


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