OpenASIP  2.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
TPEF::SectionIndexReplacer Class Reference

#include <SectionIndexReplacer.hh>

Inheritance diagram for TPEF::SectionIndexReplacer:
Inheritance graph
Collaboration diagram for TPEF::SectionIndexReplacer:
Collaboration graph

Public Member Functions

 SectionIndexReplacer (const SafePointable *obj, Byte fieldSize)
 
virtual ~SectionIndexReplacer ()
 
- Public Member Functions inherited from TPEF::ValueReplacer
void resolve ()
 

Protected Member Functions

virtual bool tryToReplace ()
 
virtual ValueReplacerclone ()
 
- Protected Member Functions inherited from TPEF::ValueReplacer
 ValueReplacer (const SafePointable *obj)
 
 ValueReplacer (const ValueReplacer &replacer)
 
virtual ~ValueReplacer ()
 
const SafePointablereference () const
 
unsigned int streamPosition () const
 

Private Member Functions

 SectionIndexReplacer (const SectionIndexReplacer &replacer)
 
SectionIndexReplacer operator= (const SectionIndexReplacer &)
 
void writeReplacement (Word value)
 

Private Attributes

const Byte fieldSize_
 Field how many bytes of stream are replaced with section index. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from TPEF::ValueReplacer
static void finalize ()
 
static void initialize (BinaryStream &stream)
 
- Static Protected Member Functions inherited from TPEF::ValueReplacer
static BinaryStreamstream ()
 

Detailed Description

Replaces object reference with section index. Section index key must be stored in reference manager for that object whose section index is written.

Definition at line 48 of file SectionIndexReplacer.hh.

Constructor & Destructor Documentation

◆ SectionIndexReplacer() [1/2]

TPEF::SectionIndexReplacer::SectionIndexReplacer ( const SafePointable obj,
Byte  size 
)

Constructor.

Definition at line 46 of file SectionIndexReplacer.cc.

47  :
48  ValueReplacer(obj), fieldSize_(size) {
49 }

Referenced by clone().

◆ ~SectionIndexReplacer()

TPEF::SectionIndexReplacer::~SectionIndexReplacer ( )
virtual

Destructor.

Definition at line 62 of file SectionIndexReplacer.cc.

62  {
63 }

◆ SectionIndexReplacer() [2/2]

TPEF::SectionIndexReplacer::SectionIndexReplacer ( const SectionIndexReplacer replacer)
private

Copy constructor.

Definition at line 54 of file SectionIndexReplacer.cc.

55  :
56  ValueReplacer(replacer), fieldSize_(replacer.fieldSize_) {
57 }

Member Function Documentation

◆ clone()

ValueReplacer * TPEF::SectionIndexReplacer::clone ( )
protectedvirtual

Creates dynamically allocated copy of replacer.

Returns
Dynamically allocated copy of replacer.

Implements TPEF::ValueReplacer.

Definition at line 92 of file SectionIndexReplacer.cc.

92  {
93  return new SectionIndexReplacer(*this);
94 }

References SectionIndexReplacer().

Here is the call graph for this function:

◆ operator=()

SectionIndexReplacer TPEF::SectionIndexReplacer::operator= ( const SectionIndexReplacer )
private

◆ tryToReplace()

bool TPEF::SectionIndexReplacer::tryToReplace ( )
protectedvirtual

Tries to do replacement in to the stream.

Returns
True if replacement were done.

Implements TPEF::ValueReplacer.

Definition at line 71 of file SectionIndexReplacer.cc.

71  {
72  try {
73  SectionIndexKey key =
75 
77  writeReplacement(key.index());
78  return true;
79 
80  } catch (KeyNotFound& e) {
82  return false;
83  }
84 }

References TPEF::ReferenceManager::SectionIndexKey::index(), TPEF::ValueReplacer::reference(), TPEF::ReferenceManager::SafePointer::sectionIndexKeyFor(), TPEF::BinaryStream::setWritePosition(), TPEF::ValueReplacer::stream(), TPEF::ValueReplacer::streamPosition(), and writeReplacement().

Here is the call graph for this function:

◆ writeReplacement()

void TPEF::SectionIndexReplacer::writeReplacement ( Word  value)
private

Writes value with one, two or four bytes wide.

Parameters
valueValue to be written.

Definition at line 102 of file SectionIndexReplacer.cc.

102  {
103  switch (fieldSize_) {
104  case 1: {
105  stream().writeByte(value);
106  break;
107  }
108  case 2: {
109  stream().writeHalfWord(value);
110  break;
111  }
112  case 3: {
113  Byte firstByte = (value >> HALFWORD_BITWIDTH);
114  HalfWord lastBytes = (value << HALFWORD_BITWIDTH)
116 
117  // writing three bytes in big endian format
118  stream().writeHalfWord(lastBytes);
119  stream().writeByte(firstByte);
120  break;
121  }
122  case 4: {
123  stream().writeWord(value);
124  break;
125  }
126  default:
127  bool unsupportedFieldSizeOfReplacement = false;
128  assert(unsupportedFieldSizeOfReplacement);
129  }
130 }

References assert, fieldSize_, HALFWORD_BITWIDTH, TPEF::ValueReplacer::stream(), TPEF::BinaryStream::writeByte(), TPEF::BinaryStream::writeHalfWord(), and TPEF::BinaryStream::writeWord().

Referenced by tryToReplace().

Here is the call graph for this function:

Member Data Documentation

◆ fieldSize_

const Byte TPEF::SectionIndexReplacer::fieldSize_
private

Field how many bytes of stream are replaced with section index.

Definition at line 65 of file SectionIndexReplacer.hh.

Referenced by writeReplacement().


The documentation for this class was generated from the following files:
TPEF::SectionIndexReplacer::SectionIndexReplacer
SectionIndexReplacer(const SafePointable *obj, Byte fieldSize)
Definition: SectionIndexReplacer.cc:46
TPEF::BinaryStream::writeHalfWord
void writeHalfWord(HalfWord halfword)
Definition: BinaryStream.cc:336
TPEF::BinaryStream::writeWord
void writeWord(Word word)
Definition: BinaryStream.cc:368
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::SectionIndexReplacer::fieldSize_
const Byte fieldSize_
Field how many bytes of stream are replaced with section index.
Definition: SectionIndexReplacer.hh:65
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::ValueReplacer::stream
static BinaryStream & stream()
Definition: ValueReplacer.cc:160
TPEF::SectionIndexReplacer::writeReplacement
void writeReplacement(Word value)
Definition: SectionIndexReplacer.cc:102
TPEF::BinaryStream::setWritePosition
void setWritePosition(unsigned int position)
Definition: BinaryStream.cc:689
TPEF::BinaryStream::writeByte
void writeByte(Byte byte)
Definition: BinaryStream.cc:310
TPEF::ValueReplacer::streamPosition
unsigned int streamPosition() const
Definition: ValueReplacer.cc:180
TPEF::ReferenceManager::SafePointer::sectionIndexKeyFor
static SectionIndexKey sectionIndexKeyFor(const SafePointable *obj)
Definition: SafePointer.cc:366
KeyNotFound
Definition: Exception.hh:285
HALFWORD_BITWIDTH
const Byte HALFWORD_BITWIDTH
Definition: BaseType.hh:137
TPEF::ValueReplacer::ValueReplacer
ValueReplacer(const SafePointable *obj)
Definition: ValueReplacer.cc:53
TPEF::ValueReplacer::reference
const SafePointable * reference() const
Definition: ValueReplacer.cc:170