avrora.core
Class LabelMapping
java.lang.Object
avrora.core.SourceMapping
avrora.core.LabelMapping
- public class LabelMapping
- extends SourceMapping
The LabelMapping
class is a simple implementation of the SourceMapping
class that maps labels to addresses in the program. It does not record module information, line
number information, etc.
Field Summary |
protected java.util.HashMap |
labels
|
protected java.util.HashMap |
reverseMap
|
Constructor Summary |
LabelMapping(Program p)
The constructor for the LabelMapping class constructs a new instance of this source
mapping for the specified program. |
Method Summary |
int |
getAddress(java.lang.String name)
The getAddress() method translates a source level name into a machine-code level
address. |
SourceMapping.Location |
getLocation(java.lang.String name)
The getLocation() method retrieves an object that represents a location for the given name,
if the name exists in the program. |
java.lang.String |
getName(int address)
The getName() method translates a code address into a name that is more useful to
the user, such as a label. |
void |
newLocation(java.lang.String name,
int address)
The newLocatiobn() method creates a new program location with the specified label name that
is stored internally. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
labels
protected final java.util.HashMap labels
reverseMap
protected final java.util.HashMap reverseMap
LabelMapping
public LabelMapping(Program p)
- The constructor for the
LabelMapping
class constructs a new instance of this source
mapping for the specified program.
- Parameters:
p
- the program to create a new source mapping for
getName
public java.lang.String getName(int address)
- The
getName()
method translates a code address into a name that is more useful to
the user, such as a label. In the implementation of the label mapping, this method will return
the label name for this address if there is one. If there is no label for the specified address,
this method will render the address as a hexadecimal string via the StringUtil.addrToString()<.code>
method.
- Specified by:
getName
in class SourceMapping
- Parameters:
address
- the address of an instruction in the program
- Returns:
- a string representation of the address as a label or a hexadecimal string
getAddress
public int getAddress(java.lang.String name)
- The
getAddress()
method translates a source level name into a machine-code level
address. In this implementation, the name is considered to be a label within the assembly program.
If the name is not known in the program, this method will return -1.
- Specified by:
getAddress
in class SourceMapping
- Parameters:
name
- the name of some program label as a string
- Returns:
- the address of that program entity as a byte address in the code of the program; -1 if
the name is not present in this program
getLocation
public SourceMapping.Location getLocation(java.lang.String name)
- The
getLocation() method retrieves an object that represents a location for the given name,
if the name exists in the program. If the name does not exist in the program, this method will return null.
For strings beginning with "0x", this method will evaluate them as hexadecimal literals and return a
location corresponding to an unnamed location at that address.
- Specified by:
getLocation
in class SourceMapping
- Parameters:
name
- the name of a program location as a label or a hexadecimal constant
- Returns:
- a
Location
object representing that program location; null
if the
specified label is not contained in the program
newLocation
public void newLocation(java.lang.String name,
int address)
- The
newLocatiobn()
method creates a new program location with the specified label name that
is stored internally.
- Parameters:
name
- the name of the labeladdress
- the address in the program for which to create and store a new location