OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
const Procedureproc_
 Procedure corresponding to this label.
 

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;
67 setAddress(ins.instruction().address());
68 // scope is the global scope for now
69 setScope(ins.instruction().parent().parent().globalScope());
70}
const Procedure * proc_
Procedure corresponding to this label.
Definition CodeLabel.hh:65
const InstructionReference ins_
Reference to instruction corresponding to this label.
Definition CodeLabel.hh:63
void setScope(const Scope &scope)
Definition Label.cc:118
std::string name() const
Definition Label.cc:74
void setAddress(Address address)
Definition Label.cc:110
void setName(const std::string &name)
Definition Label.cc:102

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}
virtual Address startAddress() const
Address address() const
static NullInstruction & instance()

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}
virtual Instruction & firstInstruction() const
virtual int instructionCount() const
virtual Program & parent() const
InstructionReference createReference(Instruction &ins)
InstructionReferenceManager & instructionReferenceManager() const
Definition Program.cc:688

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}
#define assert(condition)
CodeSnippet & parent() const

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: