OpenASIP 2.2
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TTAProgram::GlobalScope Class Reference

#include <GlobalScope.hh>

Inheritance diagram for TTAProgram::GlobalScope:
Inheritance graph
Collaboration diagram for TTAProgram::GlobalScope:
Collaboration graph

Classes

class  LabelOwner
 

Public Member Functions

 GlobalScope ()
 
virtual ~GlobalScope ()
 
virtual bool isGlobal () const
 
int globalCodeLabelCount (Address address) const
 
const CodeLabelglobalCodeLabel (Address address, int index) const
 
int globalCodeLabelCount () const
 
const CodeLabelglobalCodeLabel (int index) const
 
int globalDataLabelCount (Address address) const
 
const DataLabelglobalDataLabel (Address address, int index) const
 
int globalDataLabelCount () const
 
const DataLabelglobalDataLabel (int index) const
 
virtual void removeCodeLabels (InstructionAddress address)
 
virtual Scopecopy () const
 
virtual ScopecopyAndRelocate (const TTAProgram::Program &program) const
 
virtual void setDataLabelAddressSpace (const TTAMachine::AddressSpace &space)
 
- Public Member Functions inherited from TTAProgram::Scope
 Scope ()
 
virtual ~Scope ()
 
virtual bool isUnit () const
 
virtual bool isProcedure () const
 
virtual bool isLocal () const
 
bool containsCodeLabel (const std::string &name) const
 
bool containsDataLabel (const std::string &name) const
 
const CodeLabelcodeLabel (const std::string &name) const
 
const DataLabeldataLabel (const std::string &name) const
 
int codeLabelCount (Address address) const
 
const CodeLabelcodeLabel (Address address, int index) const
 
int dataLabelCount (Address address) const
 
const DataLabeldataLabel (Address address, int index) const
 
virtual void addCodeLabel (const CodeLabel *codeLabel)
 
virtual void addDataLabel (const DataLabel *dataLabel)
 

Protected Member Functions

virtual void addGlobalCodeLabel (const CodeLabel &codeLabel, const Scope &owner)
 
virtual void addGlobalDataLabel (const DataLabel &codeLabel, const Scope &owner)
 
- Protected Member Functions inherited from TTAProgram::Scope
Scopeparent () const
 
void setParent (Scope &scope)
 
int childCount () const
 
void addChild (const Scope &scope)
 
const Scopechild (int index) const
 

Private Types

typedef std::vector< LabelOwner * > LabelOwnerList
 List for LabelOwners.
 

Private Member Functions

 GlobalScope (const GlobalScope &)
 Copying not allowed.
 
GlobalScopeoperator= (const GlobalScope &)
 Assignment not allowed.
 

Private Attributes

LabelOwnerList allCodeLabels_
 Container for all code labels contained in the global scope and its child scopes.
 
LabelOwnerList allDataLabels_
 Container for all data labels.
 

Additional Inherited Members

- Protected Types inherited from TTAProgram::Scope
typedef std::vector< const Scope * > ScopeList
 List for child scopes.
 
typedef std::vector< const DataLabel * > DataLabelList
 List of data labels.
 
typedef std::vector< const CodeLabel * > CodeLabelList
 List of code labels.
 
- Protected Attributes inherited from TTAProgram::Scope
ScopeList children_
 Child scopes.
 
DataLabelList dataLabels_
 Data labels contained by this scope.
 
CodeLabelList codeLabels_
 Code labels contained by this scope.
 

Detailed Description

Definition at line 47 of file GlobalScope.hh.

Member Typedef Documentation

◆ LabelOwnerList

typedef std::vector<LabelOwner*> TTAProgram::GlobalScope::LabelOwnerList
private

List for LabelOwners.

Definition at line 109 of file GlobalScope.hh.

Constructor & Destructor Documentation

◆ GlobalScope() [1/2]

TTAProgram::GlobalScope::GlobalScope ( )

Constructor.

Definition at line 50 of file GlobalScope.cc.

50 {
51}

Referenced by copy(), and copyAndRelocate().

◆ ~GlobalScope()

TTAProgram::GlobalScope::~GlobalScope ( )
virtual

Destructor.

Definition at line 56 of file GlobalScope.cc.

56 {
59}
static void deleteAllItems(SequenceType &aSequence)
LabelOwnerList allCodeLabels_
Container for all code labels contained in the global scope and its child scopes.
LabelOwnerList allDataLabels_
Container for all data labels.

References allCodeLabels_, allDataLabels_, and SequenceTools::deleteAllItems().

Here is the call graph for this function:

◆ GlobalScope() [2/2]

TTAProgram::GlobalScope::GlobalScope ( const GlobalScope )
private

Copying not allowed.

Member Function Documentation

◆ addGlobalCodeLabel()

void TTAProgram::GlobalScope::addGlobalCodeLabel ( const CodeLabel codeLabel,
const Scope owner 
)
protectedvirtual

Adds a code label to the global bookkeeping.

Parameters
codeLabelThe label to be added.
ownerThe owner scope of the label.

Implements TTAProgram::Scope.

Definition at line 78 of file GlobalScope.cc.

79 {
80
81 allCodeLabels_.push_back(new LabelOwner(codeLabel, owner));
82}
const CodeLabel & codeLabel(const std::string &name) const
Definition Scope.cc:233

References allCodeLabels_, and TTAProgram::Scope::codeLabel().

Here is the call graph for this function:

◆ addGlobalDataLabel()

void TTAProgram::GlobalScope::addGlobalDataLabel ( const DataLabel dataLabel,
const Scope owner 
)
protectedvirtual

Adds a data label to the global bookkeeping.

Applies to all child scopes of this global scope.

Parameters
dataLabelThe label to be added.
ownerThe owner scope of the label.

Implements TTAProgram::Scope.

Definition at line 180 of file GlobalScope.cc.

181 {
182
183 allDataLabels_.push_back(new LabelOwner(dataLabel, owner));
184}
const DataLabel & dataLabel(const std::string &name) const
Definition Scope.cc:251

References allDataLabels_, and TTAProgram::Scope::dataLabel().

Here is the call graph for this function:

◆ copy()

Scope * TTAProgram::GlobalScope::copy ( ) const
virtual

Creates a copy of the scope and its labels.

The targets of the labels are not converted to point to the instructions of the given program and data of the data sections.

Returns
A copy of the scope.

Implements TTAProgram::Scope.

Definition at line 282 of file GlobalScope.cc.

282 {
283
284 GlobalScope* newScope = new GlobalScope();
285 for (unsigned int i = 0; i < allDataLabels_.size(); ++i) {
286 const DataLabel& source = dynamic_cast<const DataLabel&>(
287 allDataLabels_.at(i)->label());
288 newScope->addDataLabel(new DataLabel(source));
289 }
290
291 for (unsigned int i = 0; i < allCodeLabels_.size(); ++i) {
292 const CodeLabel& source = dynamic_cast<const CodeLabel&>(
293 allCodeLabels_.at(i)->label());
294 newScope->addCodeLabel(new CodeLabel(source));
295 }
296 return newScope;
297}

References TTAProgram::Scope::addCodeLabel(), TTAProgram::Scope::addDataLabel(), allCodeLabels_, allDataLabels_, and GlobalScope().

Here is the call graph for this function:

◆ copyAndRelocate()

Scope * TTAProgram::GlobalScope::copyAndRelocate ( const TTAProgram::Program program) const
virtual

Creates a copy of the scope and its labels.

The targets of the labels are converted to point to the instructions of the given program. The data labels still point to the old address spaces, assuming the target machine is still the same.

Parameters
programThe Program containing the instructions code labels should be converted to point to.
Returns
A copy of the scope.

Definition at line 334 of file GlobalScope.cc.

335 {
336
337 GlobalScope* newScope = new GlobalScope();
338 for (unsigned int i = 0; i < allDataLabels_.size(); ++i) {
339 const Label& source = allDataLabels_.at(i)->label();
340 newScope->addDataLabel(new DataLabel(
341 source.name(), source.address(),
342 *newScope));
343 }
344
345 for (unsigned int i = 0; i < allCodeLabels_.size(); ++i) {
346 const CodeLabel& source = dynamic_cast<const CodeLabel&>(
347 allCodeLabels_.at(i)->label());
348 newScope->addCodeLabel(
349 new CodeLabel(
350 program.instructionReferenceManager().createReference(
351 program.instructionAt(source.address().location())),
352 source.name()));
353 }
354 return newScope;
355}
find Finds info of the inner loops in the program

References TTAProgram::Scope::addCodeLabel(), TTAProgram::Scope::addDataLabel(), TTAProgram::CodeLabel::address(), TTAProgram::Label::address(), allCodeLabels_, allDataLabels_, GlobalScope(), TTAProgram::Address::location(), TTAProgram::Label::name(), and program.

Referenced by TTAProgram::Program::copyFrom().

Here is the call graph for this function:

◆ globalCodeLabel() [1/2]

const CodeLabel & TTAProgram::GlobalScope::globalCodeLabel ( Address  address,
int  index 
) const

Returns the code label in the given address.

Applies to all child scopes of this global scope.

Parameters
addressThe address of the label.
indexThe index of the label if there are many labels at the address.
Exceptions
KeyNotFoundIf no code labels in the given address were found.
Returns
The code label in the given address.

Definition at line 118 of file GlobalScope.cc.

118 {
119 int found = 0;
120
121 for (unsigned int i = 0; i < allCodeLabels_.size(); i++) {
122
123 if (allCodeLabels_.at(i)->label().address().location() ==
124 address.location() &&
125 &allCodeLabels_.at(i)->label().address().space() ==
126 &address.space()) {
127
128 if (index == found) {
129 return dynamic_cast<const CodeLabel&>(
130 allCodeLabels_.at(i)->label());
131 } else {
132 found++;
133 }
134 }
135 }
136
137 throw KeyNotFound(__FILE__, __LINE__);
138}

References allCodeLabels_, TTAProgram::Address::location(), and TTAProgram::Address::space().

Referenced by TTAProgram::ProgramWriter::createBinary(), and DisassemblyGridTable::loadProgram().

Here is the call graph for this function:

◆ globalCodeLabel() [2/2]

const CodeLabel & TTAProgram::GlobalScope::globalCodeLabel ( int  index) const

Returns the code label of requested index.

Applies to all child scopes of this global scope.

Parameters
indexThe index of the label.
Exceptions
KeyNotFoundIf no code labels in the given index.
Returns
The code label in the given index.

Definition at line 162 of file GlobalScope.cc.

162 {
163 if (index < globalCodeLabelCount()) {
164 return dynamic_cast<const CodeLabel&>(
165 allCodeLabels_.at(index)->label());
166 }
167
168 throw KeyNotFound(__FILE__, __LINE__);
169}
int globalCodeLabelCount() const

References allCodeLabels_, and globalCodeLabelCount().

Here is the call graph for this function:

◆ globalCodeLabelCount() [1/2]

int TTAProgram::GlobalScope::globalCodeLabelCount ( ) const

Returns the number of code labels in program.

Applies to all child scopes of this global scope.

Returns
The number of code labels in program.

Definition at line 148 of file GlobalScope.cc.

148 {
149 return allCodeLabels_.size();
150}

References allCodeLabels_.

Referenced by globalCodeLabel().

◆ globalCodeLabelCount() [2/2]

int TTAProgram::GlobalScope::globalCodeLabelCount ( Address  address) const

Returns the number of code labels at the given address.

Applies to all child scopes of this global scope.

Parameters
addressThe address of the label(s).
Returns
The number of code labels at the given address.

Definition at line 93 of file GlobalScope.cc.

93 {
94 int count = 0;
95 for (unsigned int i = 0; i < allCodeLabels_.size(); i++) {
96 if (allCodeLabels_.at(i)->label().address().location() ==
97 address.location() &&
98 &allCodeLabels_.at(i)->label().address().space() ==
99 &address.space()) {
100 count++;
101 }
102 }
103 return count;
104}

References allCodeLabels_, TTAProgram::Address::location(), and TTAProgram::Address::space().

Referenced by TTAProgram::ProgramWriter::createBinary(), POMDisassembler::labelCount(), and DisassemblyGridTable::loadProgram().

Here is the call graph for this function:

◆ globalDataLabel() [1/2]

const DataLabel & TTAProgram::GlobalScope::globalDataLabel ( Address  address,
int  index 
) const

Returns the data label in the given address.

Applies to all child scopes of this global scope.

Parameters
addressThe address of the label.
indexThe index of the label if there are many labels at the address.
Exceptions
KeyNotFoundIf no data labels in the given address were found.
Returns
The data label in the given address.

Definition at line 220 of file GlobalScope.cc.

220 {
221 int found = 0;
222
223 for (unsigned int i = 0; i < allDataLabels_.size(); i++) {
224
225 if (allDataLabels_.at(i)->label().address().location() ==
226 address.location() &&
227 &allDataLabels_.at(i)->label().address().space() ==
228 &address.space()) {
229
230 if (index == found) {
231 return dynamic_cast<const DataLabel&>(
232 allDataLabels_.at(i)->label());
233 } else {
234 found++;
235 }
236 }
237 }
238
239 throw KeyNotFound(__FILE__, __LINE__);
240}

References allDataLabels_, TTAProgram::Address::location(), and TTAProgram::Address::space().

Referenced by TTAProgram::Program::convertSymbolRef(), TTAProgram::ProgramWriter::createBinary(), and setDataLabelAddressSpace().

Here is the call graph for this function:

◆ globalDataLabel() [2/2]

const DataLabel & TTAProgram::GlobalScope::globalDataLabel ( int  index) const

Returns the data label of given index.

Applies to all child scopes of this global scope.

Parameters
indexThe index of the label.
Exceptions
KeyNotFoundIf no data labels with given index.
Returns
The data label of given index.

Definition at line 264 of file GlobalScope.cc.

264 {
265 if (index < globalDataLabelCount()) {
266 return dynamic_cast<const DataLabel&>(
267 allDataLabels_.at(index)->label());
268 }
269
270 throw KeyNotFound(__FILE__, __LINE__);
271}
int globalDataLabelCount() const

References allDataLabels_, and globalDataLabelCount().

Here is the call graph for this function:

◆ globalDataLabelCount() [1/2]

int TTAProgram::GlobalScope::globalDataLabelCount ( ) const

Returns the number of data labels in the program.

Applies to all child scopes of this global scope.

Returns
The number of data labels in the program.

Definition at line 250 of file GlobalScope.cc.

250 {
251 return allDataLabels_.size();
252}

References allDataLabels_.

Referenced by globalDataLabel(), and setDataLabelAddressSpace().

◆ globalDataLabelCount() [2/2]

int TTAProgram::GlobalScope::globalDataLabelCount ( Address  address) const

Returns the number of data labels at the given address.

Applies to all child scopes of this global scope.

Parameters
addressThe address of the label(s).
Returns
The number of data labels at the given address.

Definition at line 195 of file GlobalScope.cc.

195 {
196 int count = 0;
197 for (unsigned int i = 0; i < allDataLabels_.size(); i++) {
198 if (allDataLabels_.at(i)->label().address().location() ==
199 address.location() &&
200 &allDataLabels_.at(i)->label().address().space() ==
201 &address.space()) {
202 count++;
203 }
204 }
205 return count;
206}

References allDataLabels_, TTAProgram::Address::location(), and TTAProgram::Address::space().

Referenced by TTAProgram::Program::convertSymbolRef(), and TTAProgram::ProgramWriter::createBinary().

Here is the call graph for this function:

◆ isGlobal()

bool TTAProgram::GlobalScope::isGlobal ( ) const
virtual

Tells whether this is a global scope.

Returns
True always.

Reimplemented from TTAProgram::Scope.

Definition at line 67 of file GlobalScope.cc.

67 {
68 return true;
69}

◆ operator=()

GlobalScope & TTAProgram::GlobalScope::operator= ( const GlobalScope )
private

Assignment not allowed.

◆ removeCodeLabels()

void TTAProgram::GlobalScope::removeCodeLabels ( InstructionAddress  address)
virtual

Removes all code labels attached to the given instruction address.

Parameters
addressThe instruction address.

Reimplemented from TTAProgram::Scope.

Definition at line 363 of file GlobalScope.cc.

363 {
364
365 for (LabelOwnerList::iterator i = allCodeLabels_.begin();
366 i != allCodeLabels_.end(); ) {
367 if ((*i)->label().address().location() == address) {
368 delete (*i);
369 i = allCodeLabels_.erase(i); //returns the following element or end
370 } else {
371 i++; // advance to next
372 }
373 }
374}

References allCodeLabels_.

Referenced by TTAProgram::Procedure::remove(), and TTAProgram::Program::removeProcedure().

◆ setDataLabelAddressSpace()

void TTAProgram::GlobalScope::setDataLabelAddressSpace ( const TTAMachine::AddressSpace space)
virtual

Sets the address space of all data labels.

Parameters
spaceThe address space.

Definition at line 305 of file GlobalScope.cc.

306 {
307
308 LabelOwnerList newDataLabels_;
309 for (int i = 0; i < globalDataLabelCount(); ++i) {
310 const DataLabel& source = globalDataLabel(i);
311
312 LabelOwner* labelOwner = new LabelOwner(
313 *(new DataLabel(
314 source.name(), Address(source.address().location(), space),
315 *this)), *this);
316 newDataLabels_.push_back(labelOwner);
317 }
319 allDataLabels_ = newDataLabels_;
320}
const DataLabel & globalDataLabel(Address address, int index) const
std::vector< LabelOwner * > LabelOwnerList
List for LabelOwners.

References TTAProgram::Label::address(), allDataLabels_, SequenceTools::deleteAllItems(), globalDataLabel(), globalDataLabelCount(), TTAProgram::Address::location(), and TTAProgram::Label::name().

Referenced by TTAProgram::Program::replaceUniversalAddressSpaces().

Here is the call graph for this function:

Member Data Documentation

◆ allCodeLabels_

LabelOwnerList TTAProgram::GlobalScope::allCodeLabels_
private

Container for all code labels contained in the global scope and its child scopes.

Definition at line 113 of file GlobalScope.hh.

Referenced by addGlobalCodeLabel(), copy(), copyAndRelocate(), globalCodeLabel(), globalCodeLabel(), globalCodeLabelCount(), globalCodeLabelCount(), removeCodeLabels(), and ~GlobalScope().

◆ allDataLabels_

LabelOwnerList TTAProgram::GlobalScope::allDataLabels_
private

The documentation for this class was generated from the following files: