OpenASIP 2.2
Loading...
Searching...
No Matches
SectionIndexReplacer.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 SectionIndexReplacer.cc
26 *
27 * Definition of SectionIndexReplacer class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
35#include "SafePointer.hh"
36#include "BinaryStream.hh"
37
38namespace TPEF {
39
40using ReferenceManager::SafePointer;
41using ReferenceManager::SectionIndexKey;
42
43/**
44 * Constructor.
45 */
47 const SafePointable* obj, Byte size) :
48 ValueReplacer(obj), fieldSize_(size) {
49}
50
51/**
52 * Copy constructor.
53 */
55 const SectionIndexReplacer& replacer) :
56 ValueReplacer(replacer), fieldSize_(replacer.fieldSize_) {
57}
58
59/**
60 * Destructor.
61 */
64
65/**
66 * Tries to do replacement in to the stream.
67 *
68 * @return True if replacement were done.
69 */
70bool
72 try {
73 SectionIndexKey key =
75
78 return true;
79
80 } catch (KeyNotFound& e) {
82 return false;
83 }
84}
85
86/**
87 * Creates dynamically allocated copy of replacer.
88 *
89 * @return Dynamically allocated copy of replacer.
90 */
95
96/**
97 * Writes value with one, two or four bytes wide.
98 *
99 * @param value Value to be written.
100 */
101void
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}
131
132}
#define assert(condition)
const Byte HALFWORD_BITWIDTH
Definition BaseType.hh:137
unsigned char Byte
Definition BaseType.hh:116
void writeByte(Byte byte)
void writeHalfWord(HalfWord halfword)
void setWritePosition(unsigned int position)
void writeWord(Word word)
static SectionIndexKey sectionIndexKeyFor(const SafePointable *obj)
SectionIndexReplacer(const SafePointable *obj, Byte fieldSize)
virtual ValueReplacer * clone()
const Byte fieldSize_
Field how many bytes of stream are replaced with section index.
static BinaryStream & stream()
unsigned int streamPosition() const
const SafePointable * reference() const