OpenASIP  2.0
FileOffsetReplacer.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 FileOffsetReplacer.cc
26  *
27  * Non-inline implementations of FileOffsetReplacer class.
28  *
29  * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30  *
31  * @note rating: yellow
32  */
33 
34 #include "FileOffsetReplacer.hh"
35 #include "SafePointer.hh"
36 #include "BinaryStream.hh"
37 
38 namespace TPEF {
39 
40 using ReferenceManager::SafePointer;
41 using ReferenceManager::FileOffsetKey;
42 
43 /**
44  * Constructor.
45  */
47  ValueReplacer(obj) {
48 }
49 
50 /**
51  * Copy constructor.
52  */
54  const FileOffsetReplacer& replacer) : ValueReplacer(replacer) {
55 }
56 
57 /**
58  * Destructor.
59  */
61 }
62 
63 /**
64  * Tries to do replacement in to the stream.
65  *
66  * @return True if replacement were done.
67  */
68 bool
70  try {
71  FileOffsetKey key =
73 
75  stream().writeWord(key.fileOffset());
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  */
91  return new FileOffsetReplacer(*this);
92 }
93 
94 }
TPEF::ReferenceManager::FileOffsetKey::fileOffset
FileOffset fileOffset() const
TPEF::FileOffsetReplacer::tryToReplace
virtual bool tryToReplace()
Definition: FileOffsetReplacer.cc:69
TPEF::ReferenceManager::SafePointer::fileOffsetKeyFor
static FileOffsetKey fileOffsetKeyFor(const SafePointable *obj)
Definition: SafePointer.cc:394
TPEF::BinaryStream::writeWord
void writeWord(Word word)
Definition: BinaryStream.cc:368
SafePointer.hh
TPEF::FileOffsetReplacer
Definition: FileOffsetReplacer.hh:48
TPEF::ValueReplacer::stream
static BinaryStream & stream()
Definition: ValueReplacer.cc:160
TPEF::BinaryStream::setWritePosition
void setWritePosition(unsigned int position)
Definition: BinaryStream.cc:689
FileOffsetReplacer.hh
TPEF::FileOffsetReplacer::~FileOffsetReplacer
virtual ~FileOffsetReplacer()
Definition: FileOffsetReplacer.cc:60
TPEF::SafePointable
Definition: SafePointable.hh:48
TPEF::ValueReplacer::streamPosition
unsigned int streamPosition() const
Definition: ValueReplacer.cc:180
TPEF::ReferenceManager::FileOffsetKey
Definition: ReferenceKey.hh:121
BinaryStream.hh
TPEF::FileOffsetReplacer::clone
virtual ValueReplacer * clone()
Definition: FileOffsetReplacer.cc:90
KeyNotFound
Definition: Exception.hh:285
TPEF::ValueReplacer
Definition: ValueReplacer.hh:71
TPEF::FileOffsetReplacer::FileOffsetReplacer
FileOffsetReplacer(const SafePointable *obj)
Definition: FileOffsetReplacer.cc:46
TPEF
Definition: Assembler.hh:43
TPEF::ValueReplacer::reference
const SafePointable * reference() const
Definition: ValueReplacer.cc:170