OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFDebugSectionWriter.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 TPEFDebugSectionWriter.cc
26 *
27 * Definition of TPEFDebugSectionWriter class.
28 *
29 * @author Mikael Lepistö 2004 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
34#include <list>
35
37#include "SafePointer.hh"
38#include "ReferenceKey.hh"
39#include "SectionElement.hh"
42#include "SectionIdReplacer.hh"
43#include "DebugElement.hh"
44#include "SectionSymElement.hh"
45#include "BinaryStream.hh"
46
47namespace TPEF {
48
49using std::list;
50using ReferenceManager::SafePointer;
51using ReferenceManager::SectionKey;
52using ReferenceManager::FileOffsetKey;
53using ReferenceManager::SectionIndexKey;
54
55const TPEFDebugSectionWriter TPEFDebugSectionWriter::instance_;
56
57/**
58 * Constructor.
59 *
60 * Registers itself to SectionWriter.
61 */
65
66/**
67 * Destructor.
68 */
71
72/**
73 * Returns the section type this writer can write.
74 *
75 * @return The section type writer can write.
76 */
81
82/**
83 * Writes the data of the section in to stream.
84 *
85 * @param stream The stream to be written to.
86 * @param sect The section to be written.
87 */
88void
90 BinaryStream& stream,
91 const Section* sect) const {
92
93 FileOffset startOffset = stream.writePosition();
94
95 // file offset to data of section
97 FileOffsetKey(startOffset), sect->element(0));
98
99 for (Word i = 0; i < sect->elementCount(); i++) {
100
101 DebugElement* elem = dynamic_cast<DebugElement*>(sect->element(i));
102 assert(elem != NULL);
103
104 // write type
105 stream.writeHalfWord(static_cast<HalfWord>(elem->type()));
106
107 // debug string
108 assert(elem->debugString() != NULL);
109 SectionOffsetReplacer sOffReplacer(elem->debugString());
110 sOffReplacer.resolve();
111
112 // write variable data
113 stream.writeWord(elem->length());
114
115 for (unsigned int j = 0; j < elem->length(); j++) {
116 stream.writeByte(elem->byte(j));
117 }
118 }
119 SectionSizeReplacer::setSize(sect, stream.writePosition() - startOffset);
120}
121
122/**
123 * Returns the fixed size length of section elements.
124 *
125 * @return The fixed size length of section elements.
126 */
127Word
129 return 0;
130}
131
132/**
133 * Creates needed keys for section if noBits flag is set.
134 *
135 * @param sect Section which for keys will be created.
136 */
137void
141
142}
#define assert(condition)
void writeByte(Byte byte)
void writeHalfWord(HalfWord halfword)
unsigned int writePosition()
void writeWord(Word word)
virtual ElementType type() const =0
Chunk * debugString() const
virtual Word length() const =0
Returns the length of additional data of debug element.
virtual Byte byte(Word index) const =0
Returns one byte of additional data.
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
static void setSize(const SafePointable *obj, Word size)
static void registerSectionWriter(const SectionWriter *sWriter)
@ ST_DEBUG
Debug section.
Definition Section.hh:73
SectionElement * element(Word index) const
Word elementCount() const
static const TPEFDebugSectionWriter instance_
A unique instance of this class.
virtual void createKeys(const Section *sect) const
virtual void actualWriteData(BinaryStream &stream, const Section *section) const
virtual Section::SectionType type() const
virtual Word elementSize(const Section *section) const
Word FileOffset
Type for storing absolute file offsets.