OpenASIP
2.0
src
base
tpef
SectionOffsetReplacer.cc
Go to the documentation of this file.
1
/*
2
Copyright (c) 2002-2009 Tampere University.
3
4
This file is part of TTA-Based Codesign Environment (TCE).
5
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
23
*/
24
/**
25
* @file SectionOffsetReplacer.cc
26
*
27
* Definition of SectionOffsetReplacer class.
28
*
29
* @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30
*
31
* @note rating: yellow
32
*/
33
34
#include "
SectionOffsetReplacer.hh
"
35
#include "
SafePointer.hh
"
36
#include "
BinaryStream.hh
"
37
38
namespace
TPEF
{
39
40
using
ReferenceManager::SafePointer;
41
using
ReferenceManager::SectionOffsetKey;
42
43
/**
44
* Constructor.
45
*/
46
SectionOffsetReplacer::SectionOffsetReplacer
(
const
SafePointable
* obj) :
47
ValueReplacer
(obj) {
48
}
49
50
/**
51
* Copy constructor.
52
*/
53
SectionOffsetReplacer::SectionOffsetReplacer
(
54
const
SectionOffsetReplacer
& replacer) :
ValueReplacer
(replacer) {
55
}
56
57
/**
58
* Destructor.
59
*/
60
SectionOffsetReplacer::~SectionOffsetReplacer
() {
61
}
62
63
/**
64
* Tries to do replacement in to the stream.
65
*
66
* @return True if replacement were done.
67
*/
68
bool
69
SectionOffsetReplacer::tryToReplace
() {
70
try
{
71
SectionOffsetKey
key =
72
SafePointer::sectionOffsetKeyFor
(
reference
());
73
74
stream
().
setWritePosition
(
streamPosition
());
75
stream
().
writeWord
(key.
offset
());
76
return
true
;
77
78
}
catch
(
KeyNotFound
& e) {
79
stream
().
writeWord
(0);
80
return
false
;
81
}
82
}
83
84
/**
85
* Creates dynamically allocated copy of replacer.
86
*
87
* @return Dynamically allocated copy of replacer.
88
*/
89
ValueReplacer
*
90
SectionOffsetReplacer::clone
() {
91
return
new
SectionOffsetReplacer
(*
this
);
92
}
93
94
}
TPEF::ReferenceManager::SectionOffsetKey::offset
SectionOffset offset() const
SectionOffsetReplacer.hh
TPEF::BinaryStream::writeWord
void writeWord(Word word)
Definition:
BinaryStream.cc:368
SafePointer.hh
TPEF::SectionOffsetReplacer::tryToReplace
virtual bool tryToReplace()
Definition:
SectionOffsetReplacer.cc:69
TPEF::SectionOffsetReplacer
Definition:
SectionOffsetReplacer.hh:47
TPEF::ValueReplacer::stream
static BinaryStream & stream()
Definition:
ValueReplacer.cc:160
TPEF::BinaryStream::setWritePosition
void setWritePosition(unsigned int position)
Definition:
BinaryStream.cc:689
TPEF::ReferenceManager::SafePointer::sectionOffsetKeyFor
static SectionOffsetKey sectionOffsetKeyFor(const SafePointable *obj)
Definition:
SafePointer.cc:380
TPEF::SafePointable
Definition:
SafePointable.hh:48
TPEF::ValueReplacer::streamPosition
unsigned int streamPosition() const
Definition:
ValueReplacer.cc:180
TPEF::SectionOffsetReplacer::clone
virtual ValueReplacer * clone()
Definition:
SectionOffsetReplacer.cc:90
TPEF::SectionOffsetReplacer::SectionOffsetReplacer
SectionOffsetReplacer(const SafePointable *obj)
Definition:
SectionOffsetReplacer.cc:46
TPEF::SectionOffsetReplacer::~SectionOffsetReplacer
virtual ~SectionOffsetReplacer()
Definition:
SectionOffsetReplacer.cc:60
TPEF::ReferenceManager::SectionOffsetKey
Definition:
ReferenceKey.hh:93
BinaryStream.hh
KeyNotFound
Definition:
Exception.hh:285
TPEF::ValueReplacer
Definition:
ValueReplacer.hh:71
TPEF
Definition:
Assembler.hh:43
TPEF::ValueReplacer::reference
const SafePointable * reference() const
Definition:
ValueReplacer.cc:170
Generated by
1.8.17