OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFUDataSectionWriter.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 TPEFUDataSectionWriter.cc
26 *
27 * Definition of TPEFUDataSectionWriter class.
28 *
29 * @author Jussi Nykänen 2003 (nykanen-no.spam-cs.tut.fi)
30 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
31 *
32 * @note rating: yellow
33 */
34
35#include <cmath>
36
38#include "Exception.hh"
40#include "TPEFBaseType.hh"
41#include "ReferenceKey.hh"
42#include "SafePointer.hh"
43#include "UDataSection.hh"
44#include "BinaryStream.hh"
45
46namespace TPEF {
47
48using ReferenceManager::SafePointer;
49using ReferenceManager::FileOffsetKey;
50using ReferenceManager::SectionOffsetKey;
51using ReferenceManager::SectionKey;
52
53const TPEFUDataSectionWriter TPEFUDataSectionWriter::instance_;
54
55/**
56 * Constructor.
57 *
58 * Registers itself to SectionWriter.
59 */
63
64/**
65 * Destructor.
66 */
69
70/**
71 * Returns the type of section, that writer can write.
72 *
73 * @return The type of the section, that writer can write.
74 */
79
80/**
81 * Returns the fixed size of section elements in bytes.
82 *
83 * Size of element depends on address space of section.
84 *
85 * @param section Section which is written.
86 * @return Size of uninitialized data element in bytes.
87 */
88Word
90 return static_cast<Word>(
91 ceil(static_cast<double>(section->aSpace()->MAU()) /
93}
94
95/**
96 * Writes section's size into stream.
97 *
98 * @param stream Stream to write.
99 * @param sect Section which size to write.
100 */
101void
103 const Section* sect) const {
104
105 const UDataSection* uSect = dynamic_cast<const UDataSection*>(sect);
106 stream.writeWord(uSect->length());
107}
108
109/**
110 * Creates keys to make able to reference UData chunks with section offsets.
111 *
112 * @param sect Section which for keys will be created.
113 */
114void
116 const UDataSection* uDSection = dynamic_cast<const UDataSection*>(sect);
117
118 assert(uDSection != NULL);
119
120 SectionOffset sectOffset = 0;
121 SectionKey sKey = SafePointer::sectionKeyFor(uDSection);
122 SectionId id = sKey.sectionId();
123
124 // key for first element is always set
125 Chunk* chunk = uDSection->chunk(0);
126
128 SectionOffsetKey(id, sectOffset), chunk);
129
130 // go through requested chunks..
131 for (unsigned int i = 0; i < uDSection->referredChunkCount(); i++) {
132 try {
133 chunk = uDSection->referredChunk(i);
134 } catch (const NotChunkable& n) {
135 bool sectionToWriteIsNotChunkable = false;
136 assert(sectionToWriteIsNotChunkable);
137 }
138
139 sectOffset = chunk->offset();
140
141 // add section offset to element if really referenced element
142 if (SafePointer::isReferenced(chunk) && sectOffset != 0) {
144 SectionOffsetKey(id, sectOffset), chunk);
145 }
146 }
147}
148
149}
#define assert(condition)
const Byte BYTE_BITWIDTH
Definition BaseType.hh:136
Byte MAU() const
void writeWord(Word word)
SectionOffset offset() const
Chunk * referredChunk(Word index) const
Definition Section.cc:378
virtual Chunk * chunk(SectionOffset offset) const
Definition Section.cc:212
virtual Word length() const
Definition Section.cc:275
Word referredChunkCount() const
Definition Section.cc:366
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
static SectionKey sectionKeyFor(const SafePointable *obj)
static bool isReferenced(const SafePointable *object)
static void registerSectionWriter(const SectionWriter *sWriter)
@ ST_UDATA
Uninitialized data section.
Definition Section.hh:81
ASpaceElement * aSpace() const
virtual void createKeys(const Section *sect) const
static const TPEFUDataSectionWriter instance_
Unique instance of a class.
virtual Word elementSize(const Section *section) const
virtual Section::SectionType type() const
virtual void writeSize(BinaryStream &stream, const Section *sect) const
HalfWord SectionId
Type for storing binary file section ids.
Word SectionOffset
Type for storing offsets relative to a given base offset value.