Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

VM::InstructionStorage Class Reference

Program instruction storage. More...

#include <storage.h>

Inheritance diagram for VM::InstructionStorage:

Inheritance graph
[legend]
Collaboration diagram for VM::InstructionStorage:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 InstructionStorage (PrgAdr prealloc_size=0)
 Create empty instruction (program) storage.

 ~InstructionStorage ()
 Destroy and free instruction (program) storage.

PrgAdr length () const
 Get current address of the instruction program end.

char & index (PrgAdr i)
 Index into program memory. Array boundaries NOT checked.

INST::IID InstructionAt (PrgAdr i) const
 Get instruction at address. Address unchecked.

void append (const char *pbuf, PrgAdr plen)
 Append instruction(s) to the program storage.

void TightenSize ()
 Free excessive memory.

TLString DumpInstruction (PrgAdr adr) const
 Format the instruction at the specified address into a string.

void append (INST::IID inst)
void append (INST::IID inst, uint32 a)
void append (INST::IID inst, int32 a)
void append (INST::IID inst, uint8 a, uint8 b)
void append (INST::IID inst, uint16 a, uint8 b)
void append (INST::IID inst, uint32 a, uint8 b)
void append (INST::IID inst, int32 a, uint8 b)
void append (INST::IID inst, uint64 a, uint8 b)
void append (INST::IID inst, flt a, uint8 b)
void append (INST::IID inst, flt a, flt b, uint8 z)
void append (INST::IID inst, flt a, flt b, flt c, uint8 z)
void append (INST::IID inst, flt a, flt b, flt c, flt d, uint8 z)
void append (INST::IID inst, dbl a, uint8 b)
void append (INST::IID inst, dbl a, dbl b, uint8 z)
void append (INST::IID inst, dbl a, dbl b, dbl c, uint8 z)
void append (INST::IID inst, dbl a, dbl b, dbl c, dbl d, uint8 z)
INST::IID extract (PrgAdr adr) const
INST::IID extract (PrgAdr adr, uint32 *a) const
INST::IID extract (PrgAdr adr, int32 *a) const
INST::IID extract (PrgAdr adr, uint8 *a, uint8 *b) const
INST::IID extract (PrgAdr adr, uint16 *a, uint8 *b) const
INST::IID extract (PrgAdr adr, uint32 *a, uint8 *b) const
INST::IID extract (PrgAdr adr, int32 *a, uint8 *b) const
INST::IID extract (PrgAdr adr, uint64 *a, uint8 *b) const
INST::IID extract (PrgAdr adr, flt *a, uint8 *b) const
INST::IID extract (PrgAdr adr, flt *a, flt *b, uint8 *z) const
INST::IID extract (PrgAdr adr, flt *a, flt *b, flt *c, uint8 *z) const
INST::IID extract (PrgAdr adr, flt *a, flt *b, flt *c, flt *d, uint8 *z) const
INST::IID extract (PrgAdr adr, dbl *a, uint8 *b) const
INST::IID extract (PrgAdr adr, dbl *a, dbl *b, uint8 *z) const
INST::IID extract (PrgAdr adr, dbl *a, dbl *b, dbl *c, uint8 *z) const
INST::IID extract (PrgAdr adr, dbl *a, dbl *b, dbl *c, dbl *d, uint8 *z) const

Private Member Functions

void _ReallocStore (PrgAdr needlen)
 Re-allocate prg[] storage to hold at least needlen bytes.

 InstructionStorage (const InstructionStorage &)
 Do not use.

void operator= (const InstructionStorage &)
 Do not use.


Private Attributes

char * prg
 The actual program memory.

PrgAdr prg_asize
 Allocated amount of memory for program storage?

PrgAdr prg_len
 Actual size of the program (prg[0..prg_len-1]).


Detailed Description

Program instruction storage.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Stores the program instructions: Array of single instructions.

The instruction (program) storage is organized in a byte-wise manner and instructions differ in size. All instructions are of even size (i.e. at least 2 bytes) and the first 2 bytes of each instruction is the instruction ID.

The instruction (program) storage internally uses the machine order (LSB/MSB first) and the machine representation for floating point numbers. For distribution over network, this must first be converted.

This class is NOT C++-safe.

Definition at line 53 of file storage.h.


Constructor & Destructor Documentation

VM::InstructionStorage::InstructionStorage const InstructionStorage  )  [private]
 

Do not use.

VM::InstructionStorage::InstructionStorage PrgAdr  prealloc_size = 0  ) 
 

Create empty instruction (program) storage.

If prealloc_size is >0, pre-allocate that amount of memory for the function. This can be used to avoid re-allocations in case the size is known in advance.

Definition at line 52 of file storage.cc.

References prg, prg_asize, prg_len, and VM::PrgAdr.

VM::InstructionStorage::~InstructionStorage  ) 
 

Destroy and free instruction (program) storage.

Definition at line 59 of file storage.cc.

References FREE(), prg, prg_asize, and prg_len.


Member Function Documentation

void VM::InstructionStorage::_ReallocStore PrgAdr  needlen  )  [private]
 

Re-allocate prg[] storage to hold at least needlen bytes.

For internal use only.

Definition at line 23 of file storage.cc.

References Assert, prg, prg_asize, prg_len, VM::PrgAdr, and REALLOC().

Referenced by append().

void VM::InstructionStorage::append INST::IID  inst,
dbl  a,
dbl  b,
dbl  c,
dbl  d,
uint8  z
 

Definition at line 332 of file instgen.cc.

References VM::_AssertAC(), append(), dbl, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
dbl  a,
dbl  b,
dbl  c,
uint8  z
 

Definition at line 314 of file instgen.cc.

References VM::_AssertAC(), append(), dbl, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
dbl  a,
dbl  b,
uint8  z
 

Definition at line 297 of file instgen.cc.

References VM::_AssertAC(), append(), dbl, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
dbl  a,
uint8  b
 

Definition at line 281 of file instgen.cc.

References VM::_AssertAC(), append(), dbl, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
flt  a,
flt  b,
flt  c,
flt  d,
uint8  z
 

Definition at line 262 of file instgen.cc.

References VM::_AssertAC(), append(), flt, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
flt  a,
flt  b,
flt  c,
uint8  z
 

Definition at line 244 of file instgen.cc.

References VM::_AssertAC(), append(), flt, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
flt  a,
flt  b,
uint8  z
 

Definition at line 227 of file instgen.cc.

References VM::_AssertAC(), append(), flt, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
flt  a,
uint8  b
 

Definition at line 211 of file instgen.cc.

References VM::_AssertAC(), append(), flt, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
uint64  a,
uint8  b
 

Definition at line 195 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, uint16, uint32, uint64, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
int32  a,
uint8  b
 

Definition at line 180 of file instgen.cc.

References VM::_AssertAC(), append(), int32, VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
uint32  a,
uint8  b
 

Definition at line 165 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, uint16, uint32, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
uint16  a,
uint8  b
 

Definition at line 150 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, uint16, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
uint8  a,
uint8  b
 

Definition at line 135 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, uint16, and uint8.

void VM::InstructionStorage::append INST::IID  inst,
int32  a
 

Definition at line 121 of file instgen.cc.

References VM::_AssertAC(), append(), int32, VM::IPush(), SIZECHECK, and uint16.

void VM::InstructionStorage::append INST::IID  inst,
uint32  a
 

Definition at line 107 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, uint16, and uint32.

void VM::InstructionStorage::append INST::IID  inst  ) 
 

Definition at line 94 of file instgen.cc.

References VM::_AssertAC(), append(), VM::IPush(), SIZECHECK, and uint16.

void VM::InstructionStorage::append const char *  pbuf,
PrgAdr  plen
[inline]
 

Append instruction(s) to the program storage.

This is a "raw" (direct) function; the instruction code is passed in pbuf of size plen (must be even...) and is directly appended to the storage. You can add any number of instructions in a single call.

The code internally uses alloc-ahead to handle appending of code more efficiently. Use TightenSize() to free excess memory after having added all the code.

Definition at line 112 of file storage.h.

References _ReallocStore(), prg, prg_asize, prg_len, VM::PrgAdr, and uint16.

Referenced by VM::VMLinker::_CreateInitFunction(), VM::VMLinker::_LinkFunction(), and append().

TLString VM::InstructionStorage::DumpInstruction PrgAdr  adr  )  const
 

Format the instruction at the specified address into a string.

The string will not have indention at the beginning or newline at the end.

Definition at line 34 of file inst2str.cc.

References VM::_strpcp(), VM::INST::DescEntry::argcomb, Assert, TLString::assign(), VM::INST::DescEntry::codemark_off, dbl, extract(), FastFloat2String(), FastInt2String(), flt, InstructionAt(), int32, VM::INST::DescEntry::name, VM::PrgAdr, VM::INST::DescEntry::symref_off, VM::INST::DescEntry::typeid_off, uint16, uint32, uint64, and uint8.

Referenced by VM::AssemblerFile_Plaintext::_WriteFunctionProgram().

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
dbl a,
dbl b,
dbl c,
dbl d,
uint8 z
const
 

Definition at line 581 of file instgen.cc.

References VM::_AssertAC(), dbl, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
dbl a,
dbl b,
dbl c,
uint8 z
const
 

Definition at line 563 of file instgen.cc.

References VM::_AssertAC(), dbl, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
dbl a,
dbl b,
uint8 z
const
 

Definition at line 547 of file instgen.cc.

References VM::_AssertAC(), dbl, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
dbl a,
uint8 b
const
 

Definition at line 532 of file instgen.cc.

References VM::_AssertAC(), dbl, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
flt a,
flt b,
flt c,
flt d,
uint8 z
const
 

Definition at line 513 of file instgen.cc.

References VM::_AssertAC(), flt, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
flt a,
flt b,
flt c,
uint8 z
const
 

Definition at line 495 of file instgen.cc.

References VM::_AssertAC(), flt, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
flt a,
flt b,
uint8 z
const
 

Definition at line 479 of file instgen.cc.

References VM::_AssertAC(), flt, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
flt a,
uint8 b
const
 

Definition at line 464 of file instgen.cc.

References VM::_AssertAC(), flt, InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
uint64 a,
uint8 b
const
 

Definition at line 449 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, uint64, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
int32 a,
uint8 b
const
 

Definition at line 434 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), int32, VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
uint32 a,
uint8 b
const
 

Definition at line 419 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, uint32, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
uint16 a,
uint8 b
const
 

Definition at line 404 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, uint16, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
uint8 a,
uint8 b
const
 

Definition at line 390 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint8.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
int32 a
const
 

Definition at line 377 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), int32, VM::IPop(), prg, VM::PrgAdr, and SIZECHECK2.

INST::IID VM::InstructionStorage::extract PrgAdr  adr,
uint32 a
const
 

Definition at line 364 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), VM::IPop(), prg, VM::PrgAdr, SIZECHECK2, and uint32.

INST::IID VM::InstructionStorage::extract PrgAdr  adr  )  const
 

Arguments must match the instruction; the instruction ID is returned.

There is no range check on the program address.

Definition at line 353 of file instgen.cc.

References VM::_AssertAC(), InstructionAt(), prg, VM::PrgAdr, and SIZECHECK2.

Referenced by DumpInstruction().

char& VM::InstructionStorage::index PrgAdr  i  )  [inline]
 

Index into program memory. Array boundaries NOT checked.

Definition at line 93 of file storage.h.

References prg, and VM::PrgAdr.

Referenced by VM::VMLinker::_LinkFunction(), VM::AssemblerFile_Plaintext::_ParseProgram_FinishFunction(), and VM::AssemblerFile_Plaintext::_WriteFunctionProgram().

INST::IID VM::InstructionStorage::InstructionAt PrgAdr  i  )  const [inline]
 

Get instruction at address. Address unchecked.

Definition at line 97 of file storage.h.

References prg, VM::PrgAdr, and uint16.

Referenced by VM::VMLinker::_LinkFunction(), VM::AssemblerFile_Plaintext::_ParseProgram_FinishFunction(), VM::AssemblerFile_Plaintext::_WriteFunctionProgram(), DumpInstruction(), and extract().

PrgAdr VM::InstructionStorage::length  )  const [inline]
 

Get current address of the instruction program end.

This returns the length of the current program in bytes, i.e. the (offset) address of the (current) function program end in bytes.

This can be used to record addresses of code labels.

Definition at line 89 of file storage.h.

References prg_len, and VM::PrgAdr.

Referenced by VM::VMLinker::_LinkFunction(), VM::AssemblerFile_Plaintext::_ParseProgram_FinishFunction(), VM::AssemblerFile_Plaintext::_ParseProgram_Label(), and VM::AssemblerFile_Plaintext::_WriteFunctionProgram().

void VM::InstructionStorage::operator= const InstructionStorage  )  [private]
 

Do not use.

void VM::InstructionStorage::TightenSize  ) 
 

Free excessive memory.

This function will make sure that the amount of memory allocated for the storage is just big enough for the complete program and not bigger (as usually while appending code).

Definition at line 42 of file storage.cc.

References prg, prg_asize, prg_len, and REALLOC().

Referenced by VM::AssemblerFile_Plaintext::_ParseProgram_FinishFunction().


Member Data Documentation

char* VM::InstructionStorage::prg [private]
 

The actual program memory.

Definition at line 56 of file storage.h.

Referenced by _ReallocStore(), append(), extract(), index(), InstructionAt(), InstructionStorage(), TightenSize(), and ~InstructionStorage().

PrgAdr VM::InstructionStorage::prg_asize [private]
 

Allocated amount of memory for program storage?

Definition at line 57 of file storage.h.

Referenced by _ReallocStore(), append(), InstructionStorage(), TightenSize(), and ~InstructionStorage().

PrgAdr VM::InstructionStorage::prg_len [private]
 

Actual size of the program (prg[0..prg_len-1]).

Definition at line 58 of file storage.h.

Referenced by _ReallocStore(), append(), InstructionStorage(), length(), TightenSize(), and ~InstructionStorage().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:36:14 2005 for Ray by doxygen 1.3.5