OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
TTAProgram::CodeLabel Class Reference

#include <CodeLabel.hh>

Inheritance diagram for TTAProgram::CodeLabel:
Inheritance graph
Collaboration diagram for TTAProgram::CodeLabel:
Collaboration graph

Public Member Functions

 CodeLabel (const InstructionReference &ins, std::string name)
 
 CodeLabel (const Procedure &proc)
 
virtual ~CodeLabel ()
 
virtual Address address () const
 
const InstructionReference instructionReference () const
 
const Procedureprocedure () const
 
- Public Member Functions inherited from TTAProgram::Label
virtual ~Label ()
 
std::string name () const
 
const Scopescope () const
 
void setAddress (Address address)
 

Private Attributes

const InstructionReference ins_
 Reference to instruction corresponding to this label. More...
 
const Procedureproc_
 Procedure corresponding to this label. More...
 

Additional Inherited Members

- Protected Member Functions inherited from TTAProgram::Label
 Label ()
 
 Label (const std::string &name, Address address, const Scope &scope)
 
void setName (const std::string &name)
 
void setScope (const Scope &scope)
 

Detailed Description

A symbolic name that stands for a location in the program.

Definition at line 49 of file CodeLabel.hh.

Constructor & Destructor Documentation

◆ CodeLabel() [1/2]

TTAProgram::CodeLabel::CodeLabel ( const InstructionReference ins,
std::string  name 
)

Constructor.

Registers this label to the owning scope.

Parameters
insInstruction corresponding to this label.
nameName of the label. Must be unique within the owning scope.
Exceptions
IllegalRegistrationif the given instruction does not belong to a procedure, or its parent procedure does not belong to a program.

Definition at line 61 of file CodeLabel.cc.

62  :
63 
64  ins_(ins) {
65  proc_ = NULL;
66  setName(name);
67  setAddress(ins.instruction().address());
68  // scope is the global scope for now
69  setScope(ins.instruction().parent().parent().globalScope());
70 }

References TTAProgram::Instruction::address(), TTAProgram::Program::globalScope(), TTAProgram::InstructionReference::instruction(), TTAProgram::Label::name(), TTAProgram::CodeSnippet::parent(), TTAProgram::Instruction::parent(), proc_, TTAProgram::Label::setAddress(), TTAProgram::Label::setName(), and TTAProgram::Label::setScope().

Here is the call graph for this function:

◆ CodeLabel() [2/2]

TTAProgram::CodeLabel::CodeLabel ( const Procedure proc)

An alternative constructor that takes the procedure.

Parameters
procProcedure corresponding to this label
Exceptions
IllegalRegistrationif the given procedure does not belong to a program.

Definition at line 79 of file CodeLabel.cc.

80  : ins_(InstructionReference(NULL)), proc_(&proc) {
81  setName(proc.name());
82  setAddress(proc.startAddress());
83  // scope is the global scope for now
84  setScope(proc.parent().globalScope());
85 }

References TTAProgram::Program::globalScope(), TTAProgram::Procedure::name(), TTAProgram::CodeSnippet::parent(), TTAProgram::Label::setAddress(), TTAProgram::Label::setName(), TTAProgram::Label::setScope(), and TTAProgram::CodeSnippet::startAddress().

Here is the call graph for this function:

◆ ~CodeLabel()

TTAProgram::CodeLabel::~CodeLabel ( )
virtual

The destructor.

Definition at line 90 of file CodeLabel.cc.

90  {
91 }

Member Function Documentation

◆ address()

Address TTAProgram::CodeLabel::address ( ) const
virtual

Returns the address of the instruction or procedure corresponding to this label.

Returns
The address of the instruction or procedure corresponding to this label.

Reimplemented from TTAProgram::Label.

Definition at line 101 of file CodeLabel.cc.

101  {
103  return ins_.instruction().address();
104  } else {
105  return proc_->startAddress();
106  }
107 }

References TTAProgram::Instruction::address(), ins_, TTAProgram::NullInstruction::instance(), TTAProgram::InstructionReference::instruction(), proc_, and TTAProgram::CodeSnippet::startAddress().

Referenced by TTAProgram::GlobalScope::copyAndRelocate(), TTAProgram::ProgramWriter::createBinary(), DisassemblyGridTable::loadProgram(), and SimControlLanguageCommand::parseInstructionAddressExpression().

Here is the call graph for this function:

◆ instructionReference()

const InstructionReference TTAProgram::CodeLabel::instructionReference ( ) const

Returns a reference to the instruction corresponding to this label.

Returns
a reference to the instruction corresponding to this label.
Exceptions
IllegalRegistrationif the label points to a procedure that has no instructions.

Definition at line 117 of file CodeLabel.cc.

117  {
119  return ins_;
120  } else if (proc_->instructionCount() == 0) {
121  throw IllegalRegistration(__FILE__, __LINE__);
122  } else {
124  }
125 }

References TTAProgram::InstructionReferenceManager::createReference(), TTAProgram::CodeSnippet::firstInstruction(), ins_, TTAProgram::NullInstruction::instance(), TTAProgram::InstructionReference::instruction(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Program::instructionReferenceManager(), TTAProgram::CodeSnippet::parent(), and proc_.

Here is the call graph for this function:

◆ procedure()

const Procedure & TTAProgram::CodeLabel::procedure ( ) const

Return the procedure that contains this label.

Returns
The procedure that contains this label or the procedure at which this labels points.
Exceptions
IllegalRegistrationif the label is not registered in a procedure.

Definition at line 136 of file CodeLabel.cc.

136  {
137  if (proc_ == NULL) {
138  const Procedure* proc = dynamic_cast<const Procedure*>(
139  &(ins_.instruction().parent()));
140  assert(proc != NULL);
141  return *proc;
142  } else {
143  return *proc_;
144  }
145 }

References assert, ins_, TTAProgram::InstructionReference::instruction(), TTAProgram::Instruction::parent(), and proc_.

Here is the call graph for this function:

Member Data Documentation

◆ ins_

const InstructionReference TTAProgram::CodeLabel::ins_
private

Reference to instruction corresponding to this label.

Definition at line 63 of file CodeLabel.hh.

Referenced by address(), instructionReference(), and procedure().

◆ proc_

const Procedure* TTAProgram::CodeLabel::proc_
private

Procedure corresponding to this label.

Definition at line 65 of file CodeLabel.hh.

Referenced by address(), CodeLabel(), instructionReference(), and procedure().


The documentation for this class was generated from the following files:
TTAProgram::InstructionReference::instruction
Instruction & instruction() const
Definition: InstructionReference.cc:138
TTAProgram::CodeSnippet::firstInstruction
virtual Instruction & firstInstruction() const
Definition: CodeSnippet.cc:216
TTAProgram::Label::setName
void setName(const std::string &name)
Definition: Label.cc:102
TTAProgram::InstructionReferenceManager::createReference
InstructionReference createReference(Instruction &ins)
Definition: InstructionReferenceManager.cc:73
TTAProgram::CodeLabel::ins_
const InstructionReference ins_
Reference to instruction corresponding to this label.
Definition: CodeLabel.hh:63
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TTAProgram::Label::setAddress
void setAddress(Address address)
Definition: Label.cc:110
TTAProgram::Label::setScope
void setScope(const Scope &scope)
Definition: Label.cc:118
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Label::name
std::string name() const
Definition: Label.cc:74
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
TTAProgram::CodeLabel::proc_
const Procedure * proc_
Procedure corresponding to this label.
Definition: CodeLabel.hh:65
IllegalRegistration
Definition: Exception.hh:532
TTAProgram::Program::instructionReferenceManager
InstructionReferenceManager & instructionReferenceManager() const
Definition: Program.cc:688
TTAProgram::CodeSnippet::parent
virtual Program & parent() const
Definition: CodeSnippet.cc:118
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327