Simple Machine

ISA
Class Memory

java.lang.Object
  extended by java.util.Observable
      extended by Util.AbstractDataModel
          extended by ISA.Memory
All Implemented Interfaces:
java.util.Observer, DataModel

public class Memory
extends AbstractDataModel
implements java.util.Observer

From the ISA perspective, memory consists of a set of code or data regions. Regions are data models available for gui. Memory observes the PC register and fires a cursor-change event on regions as PC moves though code. As data models, regions can be updated by the gui and they fire change events when they change. Regions can be extended after creation and if a region extends into another the two are coallesced. Regions themselves are views of memory and register as observers on memory so they can reflect memory changes to region observers. The translation between InstructionRegions and Memory is tricky, because (a) it requires assembly/disassembly and (b) InstructionRegions contain line comments and labels that are not sorted in memory, but that are nevertheless retained.


Nested Class Summary
static class Memory.FileTypeException
          Exception for errors in put file type.
 class Memory.InputFileSyntaxException
          Exception for syntax errors in asm and mac input files.
 class Memory.LabelMap
           
static class Memory.LabelMapEventType
           
static interface Memory.LengthChangedListener
          Interface for classes that listen for length change events.
static interface Memory.StateChangedListener
           
 
Constructor Summary
Memory(AbstractISA anISA, DataModel aMainMemory, DataModel aPC)
           
 
Method Summary
 void add(MemoryCell cell)
          Add cell to appropriate region; creating or extending the region, possibly coallescing two regions.
 void addLabelOnly(MemoryCell cell)
          Add cell's label to symbol table without adding cell to memory.
 void addLengthChangedListener(Memory.LengthChangedListener l)
           
 void addObserver(java.util.Observer anObserver)
           
 void addStatedChangeListener(Memory.StateChangedListener l)
           
protected  void addUndo(javax.swing.undo.UndoableEdit e)
           
 void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
           
 void checkpointData(boolean changesMemory)
          Checkpoint Data
 void clear()
          Clear all regions
 void fireDeleted(int address, int length, int lastAddress)
           
 void fireInserted(int address, int length, int lastAddress)
           
 java.lang.Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 java.lang.String getIsaName()
           
 Memory.LabelMap getLabelMap()
           
 java.lang.String getLoadedFilename()
           
 java.util.List<Region> getRegions()
          Get a list of all memory regions.
 int getRowCount()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 boolean hasLoadedFile()
           
 boolean hasUnsavedChanges()
           
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 void loadFile(java.lang.String filename)
          Load a file into memory where type of file is determined by it's extension (i.e., *.s for assembly langauge and *.gold for machine code).
 void restoreDataFromCheckpoint()
          Restore from checkpoint
 void saveToFile(java.lang.String filename)
          Save to file
 void setChanged(boolean isChanged)
           
 void setValueAt(java.lang.Object[] aValue, int rowIndex, int columnIndex)
           
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void setValueAtByUser(java.lang.Object[] aValue, int rowIndex, int columnIndex)
           
 void setValueAtByUser(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void update(java.util.Observable o, java.lang.Object arg)
          Called when the PC or memory that backs a region changes.
 
Methods inherited from class Util.AbstractDataModel
canDeleteRow, canInsertRow, deleteRow, insertRow, tellObservers, tellObservers
 
Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Memory

public Memory(AbstractISA anISA,
              DataModel aMainMemory,
              DataModel aPC)
Method Detail

getLabelMap

public Memory.LabelMap getLabelMap()

hasLoadedFile

public boolean hasLoadedFile()

getLoadedFilename

public java.lang.String getLoadedFilename()

hasUnsavedChanges

public boolean hasUnsavedChanges()

setChanged

public void setChanged(boolean isChanged)

addStatedChangeListener

public void addStatedChangeListener(Memory.StateChangedListener l)

addLengthChangedListener

public void addLengthChangedListener(Memory.LengthChangedListener l)

fireInserted

public void fireInserted(int address,
                         int length,
                         int lastAddress)

fireDeleted

public void fireDeleted(int address,
                        int length,
                        int lastAddress)

getRegions

public java.util.List<Region> getRegions()
Get a list of all memory regions.


addLabelOnly

public void addLabelOnly(MemoryCell cell)
Add cell's label to symbol table without adding cell to memory. Adding cell to memory does automatically add its label to the symbol table.


add

public void add(MemoryCell cell)
Add cell to appropriate region; creating or extending the region, possibly coallescing two regions.


clear

public void clear()
Clear all regions


update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Called when the PC or memory that backs a region changes.

Specified by:
update in interface java.util.Observer

getIsaName

public java.lang.String getIsaName()

checkpointData

public void checkpointData(boolean changesMemory)
Checkpoint Data


restoreDataFromCheckpoint

public void restoreDataFromCheckpoint()
Restore from checkpoint


saveToFile

public void saveToFile(java.lang.String filename)
                throws java.io.FileNotFoundException
Save to file

Throws:
java.io.FileNotFoundException

loadFile

public void loadFile(java.lang.String filename)
              throws Memory.InputFileSyntaxException,
                     java.io.FileNotFoundException,
                     java.io.IOException,
                     Memory.FileTypeException
Load a file into memory where type of file is determined by it's extension (i.e., *.s for assembly langauge and *.gold for machine code).

Throws:
Memory.FileTypeException - indicates unknown file type
Memory.InputFileSyntaxException
java.io.FileNotFoundException
java.io.IOException

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
Specified by:
addUndoableEditListener in interface DataModel
Overrides:
addUndoableEditListener in class AbstractDataModel

addUndo

protected void addUndo(javax.swing.undo.UndoableEdit e)

addObserver

public void addObserver(java.util.Observer anObserver)
Specified by:
addObserver in interface DataModel
Overrides:
addObserver in class java.util.Observable

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface DataModel
Overrides:
getColumnClass in class AbstractDataModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface DataModel
Overrides:
getColumnCount in class AbstractDataModel

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface DataModel
Overrides:
getColumnName in class AbstractDataModel

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface DataModel
Overrides:
getRowCount in class AbstractDataModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface DataModel
Overrides:
getValueAt in class AbstractDataModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface DataModel
Overrides:
isCellEditable in class AbstractDataModel

setValueAt

public void setValueAt(java.lang.Object[] aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface DataModel
Overrides:
setValueAt in class AbstractDataModel

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface DataModel
Overrides:
setValueAt in class AbstractDataModel

setValueAtByUser

public void setValueAtByUser(java.lang.Object aValue,
                             int rowIndex,
                             int columnIndex)
Specified by:
setValueAtByUser in interface DataModel
Overrides:
setValueAtByUser in class AbstractDataModel

setValueAtByUser

public void setValueAtByUser(java.lang.Object[] aValue,
                             int rowIndex,
                             int columnIndex)
Specified by:
setValueAtByUser in interface DataModel
Overrides:
setValueAtByUser in class AbstractDataModel

Simple Machine