OpenASIP  2.0
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"
40 #include "SectionSizeReplacer.hh"
41 #include "SectionOffsetReplacer.hh"
42 #include "SectionIdReplacer.hh"
43 #include "DebugElement.hh"
44 #include "SectionSymElement.hh"
45 #include "BinaryStream.hh"
46 
47 namespace TPEF {
48 
49 using std::list;
50 using ReferenceManager::SafePointer;
51 using ReferenceManager::SectionKey;
52 using ReferenceManager::FileOffsetKey;
53 using ReferenceManager::SectionIndexKey;
54 
55 const TPEFDebugSectionWriter TPEFDebugSectionWriter::instance_;
56 
57 /**
58  * Constructor.
59  *
60  * Registers itself to SectionWriter.
61  */
64 }
65 
66 /**
67  * Destructor.
68  */
70 }
71 
72 /**
73  * Returns the section type this writer can write.
74  *
75  * @return The section type writer can write.
76  */
79  return Section::ST_DEBUG;
80 }
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  */
88 void
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  */
127 Word
128 TPEFDebugSectionWriter::elementSize(const Section* /*section*/) const {
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  */
137 void
139  SectionSizeReplacer::setSize(sect, 0x0);
140 }
141 
142 }
TPEF::BinaryStream::writeHalfWord
void writeHalfWord(HalfWord halfword)
Definition: BinaryStream.cc:336
SectionSizeReplacer.hh
TPEFDebugSectionWriter.hh
SectionOffsetReplacer.hh
TPEF::TPEFDebugSectionWriter::createKeys
virtual void createKeys(const Section *sect) const
Definition: TPEFDebugSectionWriter.cc:138
SectionIdReplacer.hh
TPEF::Section::ST_DEBUG
@ ST_DEBUG
Debug section.
Definition: Section.hh:73
TPEF::TPEFDebugSectionWriter::instance_
static const TPEFDebugSectionWriter instance_
A unique instance of this class.
Definition: TPEFDebugSectionWriter.hh:68
TPEF::DebugElement::byte
virtual Byte byte(Word index) const =0
Returns one byte of additional data.
TPEF::BinaryStream::writeWord
void writeWord(Word word)
Definition: BinaryStream.cc:368
TPEF::BinaryStream
Definition: BinaryStream.hh:59
TPEF::BinaryStream::writePosition
unsigned int writePosition()
Definition: BinaryStream.cc:592
TPEF::TPEFDebugSectionWriter::actualWriteData
virtual void actualWriteData(BinaryStream &stream, const Section *section) const
Definition: TPEFDebugSectionWriter.cc:89
SafePointer.hh
TPEF::ReferenceManager::SafePointer::addObjectReference
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
Definition: SafePointer.cc:306
TPEF::ValueReplacer::resolve
void resolve()
Definition: ValueReplacer.cc:90
TPEF::Section
Definition: Section.hh:64
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::Section::element
SectionElement * element(Word index) const
TPEF::TPEFDebugSectionWriter::TPEFDebugSectionWriter
TPEFDebugSectionWriter()
Definition: TPEFDebugSectionWriter.cc:62
TPEF::SectionOffsetReplacer
Definition: SectionOffsetReplacer.hh:47
SectionSymElement.hh
TPEF::SectionWriter::registerSectionWriter
static void registerSectionWriter(const SectionWriter *sWriter)
Definition: SectionWriter.cc:148
TPEF::DebugElement::type
virtual ElementType type() const =0
TPEF::TPEFDebugSectionWriter::~TPEFDebugSectionWriter
virtual ~TPEFDebugSectionWriter()
Definition: TPEFDebugSectionWriter.cc:69
TPEF::TPEFDebugSectionWriter::type
virtual Section::SectionType type() const
Definition: TPEFDebugSectionWriter.cc:78
TPEF::FileOffset
Word FileOffset
Type for storing absolute file offsets.
Definition: TPEFBaseType.hh:52
TPEF::TPEFDebugSectionWriter::elementSize
virtual Word elementSize(const Section *section) const
Definition: TPEFDebugSectionWriter.cc:128
TPEF::DebugElement::length
virtual Word length() const =0
Returns the length of additional data of debug element.
TPEF::BinaryStream::writeByte
void writeByte(Byte byte)
Definition: BinaryStream.cc:310
TPEF::ReferenceManager::FileOffsetKey
Definition: ReferenceKey.hh:121
SectionElement.hh
TPEF::SectionSizeReplacer::setSize
static void setSize(const SafePointable *obj, Word size)
Definition: SectionSizeReplacer.cc:100
TPEF::DebugElement
Definition: DebugElement.hh:56
BinaryStream.hh
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
TPEF::DebugElement::debugString
Chunk * debugString() const
Definition: DebugElement.cc:58
DebugElement.hh
ReferenceKey.hh
TPEF::TPEFSectionWriter
Definition: TPEFSectionWriter.hh:49
TPEF::Section::elementCount
Word elementCount() const
TPEF
Definition: Assembler.hh:43