OpenASIP
2.0
|
#include <ValueReplacer.hh>
Public Member Functions | |
void | resolve () |
Static Public Member Functions | |
static void | finalize () |
static void | initialize (BinaryStream &stream) |
Protected Member Functions | |
ValueReplacer (const SafePointable *obj) | |
ValueReplacer (const ValueReplacer &replacer) | |
virtual | ~ValueReplacer () |
virtual bool | tryToReplace ()=0 |
Does replacement if can. If can't returns false. More... | |
virtual ValueReplacer * | clone ()=0 |
Creates dynamically allocated clone of object. More... | |
const SafePointable * | reference () const |
unsigned int | streamPosition () const |
Static Protected Member Functions | |
static BinaryStream & | stream () |
Static Private Member Functions | |
static void | addReplacement (ValueReplacer *obj) |
Private Attributes | |
unsigned int | streamPosition_ |
File offset where replacement is done. More... | |
const SafePointable * | reference_ |
Reference which to be written. More... | |
Static Private Attributes | |
static BinaryStream * | stream_ = NULL |
Stream for writing replacements. More... | |
static std::set< ValueReplacer * > | replacements_ |
Replacements which should be done afterwards. More... | |
Abstract base class of value replacer classes.
A value replacer class handles writing of object references into an output binary stream. An object reference is represented with a value in the stream. The order in which reference values are computed may depend on the data already written into the stream, which may include other references whose value is not yet available. When an object reference must be written out and its corresponding value is not yet available, value replacers are used.
E.g., If file offset to the body of the section should is written while writing section header, FileOffsetReplacer is used to write FileOffset of the first element of the section. When file offset of the first element is known, the FileOffsetReplacer object knows where to replace write that offset.
Value replacers defer the writing of the actual reference values. A dummy reference value is written out in stream sequential order and later replaced witht he actual value whent his becomes available.
The ValueReplacer base class is not a pure interface: it handles all bookkeeping of deferred replacements.
Each concrete value replacer handles the writing of reference to a specific object type in a specific data format.
Definition at line 71 of file ValueReplacer.hh.
|
protected |
Constructor
obj | Object whole key is used for replacing bytes in stream. |
Definition at line 53 of file ValueReplacer.cc.
References assert, stream_, streamPosition_, and TPEF::BinaryStream::writePosition().
|
protected |
Copy constructor
@para replacer Replacer which is copied.
Definition at line 72 of file ValueReplacer.cc.
|
protectedvirtual |
|
staticprivate |
Adds a replacement object for later writing.
replacer | Replacement that should be done later. |
Definition at line 150 of file ValueReplacer.cc.
References replacements_.
Referenced by resolve().
|
protectedpure virtual |
Creates dynamically allocated clone of object.
Implemented in TPEF::SectionSizeReplacer, TPEF::FileOffsetReplacer, TPEF::SectionIndexReplacer, TPEF::SectionIdReplacer, and TPEF::SectionOffsetReplacer.
Referenced by resolve().
|
static |
Tries to do those replacement which couldn't do while writing.
Deletes all remaining replacer instances after replacements were done. When method is runned and no exceptions are thrown method cleans up key tables of reference manager and unset's BinaryStream where replacements were written. So initilize() method must be called again before starting new writing. If MissingKeys exception is thrown, then those replacements are not freed, which could not be done before. Keys can be added and finalize may be called again.
MissingKeys | If ReferenceManager doesn't contain needed keys. |
UnreachableStream | Writing can't be done, because of bad stream. |
WritePastEOF | If replacer tried to write past end of file. |
Definition at line 127 of file ValueReplacer.cc.
References __func__, replacements_, stream_, and tryToReplace().
Referenced by TPEF::BinaryWriter::writeBinary().
|
static |
Initializes ValueReplacer for writing.
Sets stream which we want write to and clears up key table of reference manager so there won't be any keys with wrong values.
stream | Stream where replacements are done. |
Definition at line 105 of file ValueReplacer.cc.
References assert, replacements_, stream(), and stream_.
Referenced by TPEF::BinaryWriter::writeBinary().
|
protected |
Returns referenced object.
Definition at line 170 of file ValueReplacer.cc.
References reference_.
Referenced by TPEF::SectionIdReplacer::tryToReplace(), TPEF::SectionOffsetReplacer::tryToReplace(), TPEF::FileOffsetReplacer::tryToReplace(), TPEF::SectionIndexReplacer::tryToReplace(), and TPEF::SectionSizeReplacer::tryToReplace().
void TPEF::ValueReplacer::resolve | ( | ) |
Does replacement or set it to be done later.
UnreachableStream | Writing can't be done, because of bad stream. |
WritePastEOF | If replacer tried to write past end of file. |
Definition at line 90 of file ValueReplacer.cc.
References addReplacement(), clone(), and tryToReplace().
Referenced by TPEF::TPEFWriter::actualWriteBinary(), TPEF::TPEFLineNumSectionWriter::actualWriteData(), TPEF::TPEFRelocSectionWriter::actualWriteData(), TPEF::TPEFResourceSectionWriter::actualWriteData(), TPEF::TPEFDebugSectionWriter::actualWriteData(), TPEF::TPEFSymbolSectionWriter::actualWriteData(), TPEF::TPEFSectionWriter::actualWriteHeader(), TPEF::TPEFSectionWriter::writeBodyStartOffset(), TPEF::TPEFASpaceSectionWriter::writeElement(), TPEF::TPEFLineNumSectionWriter::writeInfo(), TPEF::TPEFRelocSectionWriter::writeInfo(), TPEF::TPEFSectionWriter::writeSize(), and TPEF::TPEFSymbolSectionWriter::writeValueAndSize().
|
staticprotected |
Returns stream where to write.
Definition at line 160 of file ValueReplacer.cc.
References stream_.
Referenced by initialize(), TPEF::SectionOffsetReplacer::tryToReplace(), TPEF::SectionIdReplacer::tryToReplace(), TPEF::FileOffsetReplacer::tryToReplace(), TPEF::SectionIndexReplacer::tryToReplace(), TPEF::SectionSizeReplacer::tryToReplace(), and TPEF::SectionIndexReplacer::writeReplacement().
|
protected |
Stream position where to write reference.
Definition at line 180 of file ValueReplacer.cc.
References streamPosition_.
Referenced by TPEF::SectionIdReplacer::tryToReplace(), TPEF::SectionOffsetReplacer::tryToReplace(), TPEF::FileOffsetReplacer::tryToReplace(), TPEF::SectionIndexReplacer::tryToReplace(), and TPEF::SectionSizeReplacer::tryToReplace().
|
protectedpure virtual |
Does replacement if can. If can't returns false.
Implemented in TPEF::SectionSizeReplacer, TPEF::FileOffsetReplacer, TPEF::SectionIndexReplacer, TPEF::SectionIdReplacer, and TPEF::SectionOffsetReplacer.
Referenced by finalize(), and resolve().
|
private |
Reference which to be written.
Definition at line 102 of file ValueReplacer.hh.
Referenced by reference().
|
staticprivate |
Replacements which should be done afterwards.
Definition at line 107 of file ValueReplacer.hh.
Referenced by addReplacement(), finalize(), and initialize().
|
staticprivate |
Stream for writing replacements.
Definition at line 104 of file ValueReplacer.hh.
Referenced by finalize(), initialize(), stream(), and ValueReplacer().
|
private |
File offset where replacement is done.
Definition at line 100 of file ValueReplacer.hh.
Referenced by streamPosition(), and ValueReplacer().