byucc.jhdl.platforms.util
Class GenericMemory

java.lang.Object
  extended bybyucc.jhdl.platforms.util.GenericMemory
All Implemented Interfaces:
Checkpointable, LargeMemoryInterface, LargeWritableMemory, MemoryFileParserInterface

public class GenericMemory
extends java.lang.Object
implements LargeWritableMemory, Checkpointable, MemoryFileParserInterface

This class is used to help create memory models for board models. It uses a "chunky" memory model, meaning that the user (board model designer) can set the block size. A block is only constructed if a memory space in that block is written. Also, the model will keep track of which addresses have valid data (data has been written to that address) and will throw and exception if the data is not valid.


Field Summary
static int HUGE
          HUGE block size.
static int LARGE
          LARGE block size.
static int MEDIUM
          MEDIUM block size.
static int SMALL
          SMALL block size.
static int TINY
          TINY block size.
 
Constructor Summary
GenericMemory(int addr_bits, int chunk_size, int width)
          Constructor used to create the GenericMemory object.
GenericMemory(int addr_bits, int chunk_size, int width, JHDLOutput jout)
          Constructor used to create the GenericMemory object.
 
Method Summary
 void addMemoryElement(BV value)
          Called when a line is parsed which contains a value to be placed in the memory.
 void endParse(java.lang.String filename)
           
 java.io.Serializable getData()
          Since GenericMemory is not a cell, these functions will need to be called in the getData and setData (respectively) of the Cells who use GenericMemory
 BV getEmpty()
          Returns a copy of the "empty" value.
 BV getMemoryElement(int address, BV ret)
          Return the given memory position
 BV[] getMemoryRange(int sIndex, int elements, BV[] ret)
          Return the given memory range
 int getMemoryWidth()
          Returns the memory width
 long getSize()
          Returns the memory size
 boolean loadMemoryFile(java.lang.String filename)
          Loads memory from a file.
static void main(java.lang.String[] args)
           
 BV readMemoryLocation(int address)
          Reads an entry in the memory and returns it as a BV (Bit Vector).
 BV readMemoryLocation(int address, BV output)
          Reads an entry in the memory and returns it as a BV (Bit Vector).
 void setAddressPointer(BV value)
           
 void setData(java.io.Serializable data)
          Since GenericMemory is not a cell, these functions will need to be called in the getData and setData (respectively) of the Cells who use GenericMemory
 void setEmpty(BV value)
          Sets the empty value.
 void setEmpty(java.lang.String value)
          Sets the empty value.
 void setJHDLOutput(JHDLOutput jout)
          Sets the JHDLOutput object that will be used by this memory.
 void startParse(java.lang.String filename)
           
 void writeMemoryElement(int address, BV value)
           
 void writeMemoryLocation(int address, BV value)
          Writes a value to the specified address.
 void writeMemoryRange(int address, int elements, BV[] values)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TINY

public static final int TINY
TINY block size. Sets block to be 8 bits (256 entries)

See Also:
Constant Field Values

SMALL

public static final int SMALL
SMALL block size. Sets block to be 10 bits (1024 entries)

See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
MEDIUM block size. Sets block to be 12 bits (4096 entries)

See Also:
Constant Field Values

LARGE

public static final int LARGE
LARGE block size. Sets block to be 14 bits (16384 entries)

See Also:
Constant Field Values

HUGE

public static final int HUGE
HUGE block size. Sets block to be 16 bits (65536 entries)

See Also:
Constant Field Values
Constructor Detail

GenericMemory

public GenericMemory(int addr_bits,
                     int chunk_size,
                     int width)
Constructor used to create the GenericMemory object.

Parameters:
addr_bits - Number of address bits for this memory. This number is used to compute the depth of the memory.
chunk_size - Number of address bits represented in each chunk.
width - Width of the data in the memory.

GenericMemory

public GenericMemory(int addr_bits,
                     int chunk_size,
                     int width,
                     JHDLOutput jout)
Constructor used to create the GenericMemory object.

Parameters:
addr_bits - Number of address bits for this memory. This number is used to compute the depth of the memory.
chunk_size - Number of address bits represented in each chunk.
width - Width of the data in the memory.
jout - JHDLOutput stream to use when printing messages. If null, then it will default to the "platforms" output stream.
Method Detail

setJHDLOutput

public void setJHDLOutput(JHDLOutput jout)
Sets the JHDLOutput object that will be used by this memory.

Parameters:
jout - JHDLOutput to be set as the output stream.

setEmpty

public void setEmpty(BV value)
Sets the empty value. Any uninitialized reads will return this value.


setEmpty

public void setEmpty(java.lang.String value)
Sets the empty value. Any uninitialized reads will return this value.


getEmpty

public BV getEmpty()
Returns a copy of the "empty" value.


readMemoryLocation

public BV readMemoryLocation(int address)
                      throws UtilMemoryReadException
Reads an entry in the memory and returns it as a BV (Bit Vector). If the requested location is unitialized, an exception will be thrown. IMPORTANT NOTE: The returned BV is reused and therefore will be modified the next time readMemoryLocation is called. If you do not use the returned value immediately, you must make a copy. This is to avoid creating garbage by making a new BV each time. It is recommened that you reuse the same BV as well. Creating garbage can significantly degrade simulation performance.

Parameters:
address - Address to be read.
Returns:
BV representing the value of the requested memory location.
Throws:
UtilMemoryReadException - The exception is thrown if an attempt is made to read from an uninitialized 0r non-existent memory location. The board model writer is forced to catch this exception and can decide whether to report it as an error, a warning, not at all, or allow the user to choose.

loadMemoryFile

public boolean loadMemoryFile(java.lang.String filename)
Loads memory from a file. The format is as follows:

Specified by:
loadMemoryFile in interface LargeWritableMemory
Parameters:
filename - Name of the file to load.

readMemoryLocation

public BV readMemoryLocation(int address,
                             BV output)
                      throws UtilMemoryReadException
Reads an entry in the memory and returns it as a BV (Bit Vector). If the requested location is unitialized, an exception will be thrown. IMPORTANT NOTE: The returned BV is reused and therefore will be modified the next time readMemoryLocation is called. If you do not use the returned value immediately, you must make a copy. This is to avoid creating garbage by making a new BV each time. It is recommened that you reuse the same BV as well. Creating garbage can significantly degrade simulation performance.

Parameters:
address - Address to be read.
output - BV to which the result should be written.
Returns:
output BV that was passed in by user.
Throws:
UtilMemoryReadException - The exception is thrown if an attempt is made to read from an uninitialized 0r non-existent memory location. The board model writer is forced to catch this exception and can decide whether to report it as an error, a warning, not at all, or allow the user to choose.

writeMemoryLocation

public void writeMemoryLocation(int address,
                                BV value)
Writes a value to the specified address. If no address in that block has been written, a new block will be made and the value will be written. Writing to an address will set the valid bit to true for that entry. If the address is out of the memory range, the method simply returns.

Parameters:
address - Address to be written.
value - Value to write to the address.

writeMemoryRange

public void writeMemoryRange(int address,
                             int elements,
                             BV[] values)
Specified by:
writeMemoryRange in interface LargeWritableMemory

writeMemoryElement

public void writeMemoryElement(int address,
                               BV value)
Specified by:
writeMemoryElement in interface LargeWritableMemory

getMemoryRange

public BV[] getMemoryRange(int sIndex,
                           int elements,
                           BV[] ret)
Description copied from interface: LargeMemoryInterface
Return the given memory range

Specified by:
getMemoryRange in interface LargeMemoryInterface
Parameters:
sIndex - the starting index
elements - how many entries to get
ret - where to stick the results
Returns:
the modified results

getMemoryElement

public BV getMemoryElement(int address,
                           BV ret)
Description copied from interface: LargeMemoryInterface
Return the given memory position

Specified by:
getMemoryElement in interface LargeMemoryInterface
Parameters:
address - the memory address to get
ret - where to stick the results
Returns:
the modified results

getSize

public long getSize()
Description copied from interface: LargeMemoryInterface
Returns the memory size

Specified by:
getSize in interface LargeMemoryInterface
Returns:
the number of addresses

getMemoryWidth

public int getMemoryWidth()
Description copied from interface: LargeMemoryInterface
Returns the memory width

Specified by:
getMemoryWidth in interface LargeMemoryInterface
Returns:
the number of bits per address

getData

public java.io.Serializable getData()
Since GenericMemory is not a cell, these functions will need to be called in the getData and setData (respectively) of the Cells who use GenericMemory

Specified by:
getData in interface Checkpointable
Returns:
all state to be saved

setData

public void setData(java.io.Serializable data)
Since GenericMemory is not a cell, these functions will need to be called in the getData and setData (respectively) of the Cells who use GenericMemory

Specified by:
setData in interface Checkpointable
Parameters:
data - the state that was saved earlier

startParse

public void startParse(java.lang.String filename)
Specified by:
startParse in interface MemoryFileParserInterface

endParse

public void endParse(java.lang.String filename)
Specified by:
endParse in interface MemoryFileParserInterface

setAddressPointer

public void setAddressPointer(BV value)
Specified by:
setAddressPointer in interface MemoryFileParserInterface

addMemoryElement

public void addMemoryElement(BV value)
Description copied from interface: MemoryFileParserInterface
Called when a line is parsed which contains a value to be placed in the memory.

Specified by:
addMemoryElement in interface MemoryFileParserInterface
Parameters:
value - Value to be added to the memory. Please note that this BV will be altered during subsequent parsing. The user is responsible to keep a copy of the BV if it is needed.

main

public static void main(java.lang.String[] args)


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.