edu.cornell.cs.sam.core
Class SamProgram

java.lang.Object
  extended by edu.cornell.cs.sam.core.SamProgram
All Implemented Interfaces:
Program, java.io.Serializable

public class SamProgram
extends java.lang.Object
implements Program, java.io.Serializable

Implementation of Program using an ArrayList for storage. See Program interface for more information

See Also:
Serialized Form

Constructor Summary
SamProgram()
           
 
Method Summary
 void addInst(Instruction i)
          Add instruction to the program
 void addInst(Instruction[] arr)
          Add multiple instructions to the program
 Instruction getInst(int pos)
          Get instruction at specificed location
 java.util.List<Instruction> getInstList()
          Get all instructions as a list
 int getLength()
          Gets total number of instructions in program
 ReferenceTable getReferenceTable()
          Returns the references table
 SymbolTable getSymbolTable()
          Returns the symbol table
 boolean isExecutable()
          Returns whether this program can be executed - it is executable if all symbols have been resolved.
 void resolveReferences()
          Resolves references in this program from the symbol table
 void resolveReferencesFrom(Program prog)
          Resolves prog's references from the symbol table
 void setReferenceTable(ReferenceTable table)
          Sets the references table
 void setSymbolTable(SymbolTable table)
          Sets the symbol table
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SamProgram

public SamProgram()
Method Detail

getInst

public Instruction getInst(int pos)
Description copied from interface: Program
Get instruction at specificed location

Specified by:
getInst in interface Program
Parameters:
pos - The instruction address
Returns:
The instruction located at that address

getInstList

public java.util.List<Instruction> getInstList()
Description copied from interface: Program
Get all instructions as a list

Specified by:
getInstList in interface Program
Returns:
The list of instructions

addInst

public void addInst(Instruction i)
Description copied from interface: Program
Add instruction to the program

Specified by:
addInst in interface Program
Parameters:
i - The instruction to add

addInst

public void addInst(Instruction[] arr)
Description copied from interface: Program
Add multiple instructions to the program

Specified by:
addInst in interface Program
Parameters:
arr - An array of instructions to add

getLength

public int getLength()
Description copied from interface: Program
Gets total number of instructions in program

Specified by:
getLength in interface Program
Returns:
The number of instructions

getSymbolTable

public SymbolTable getSymbolTable()
Description copied from interface: Program
Returns the symbol table

Specified by:
getSymbolTable in interface Program
Returns:
The symbol table for this program

getReferenceTable

public ReferenceTable getReferenceTable()
Description copied from interface: Program
Returns the references table

Specified by:
getReferenceTable in interface Program
Returns:
The references table for this program

setSymbolTable

public void setSymbolTable(SymbolTable table)
Description copied from interface: Program
Sets the symbol table

Specified by:
setSymbolTable in interface Program
Parameters:
table - The symbol table for this program

setReferenceTable

public void setReferenceTable(ReferenceTable table)
Description copied from interface: Program
Sets the references table

Specified by:
setReferenceTable in interface Program
Parameters:
table - The references table for this program

resolveReferences

public void resolveReferences()
Description copied from interface: Program
Resolves references in this program from the symbol table

Specified by:
resolveReferences in interface Program

resolveReferencesFrom

public void resolveReferencesFrom(Program prog)
Description copied from interface: Program
Resolves prog's references from the symbol table

Specified by:
resolveReferencesFrom in interface Program
Parameters:
prog - The program whose references to resolve

isExecutable

public boolean isExecutable()
Description copied from interface: Program
Returns whether this program can be executed - it is executable if all symbols have been resolved.

Specified by:
isExecutable in interface Program
Returns:
true if this program contains no unresolved references

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object