OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFLineNumSectionWriter.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 TPEFLineNumSectionWriter.cc
26 *
27 * Definition of TPEFLineNumSectionWriter 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 "LineNumSection.hh"
41#include "LineNumProcedure.hh"
42#include "LineNumElement.hh"
46#include "SectionIdReplacer.hh"
47#include "BinaryStream.hh"
48
49namespace TPEF {
50
51using std::list;
52
53using ReferenceManager::SafePointer;
54using ReferenceManager::SectionKey;
55using ReferenceManager::FileOffsetKey;
56using ReferenceManager::SectionIndexKey;
57
58const TPEFLineNumSectionWriter TPEFLineNumSectionWriter::instance_;
60
61/**
62 * Constructor.
63 *
64 * Registers itself to SectionWriter.
65 */
69
70/**
71 * Destructor.
72 */
75
76/**
77 * Returns the section type this writer can write.
78 *
79 * @return The section type writer can write.
80 */
85
86/**
87 * Writes the data of the section in to stream.
88 *
89 * @param stream The stream to be written to.
90 * @param sect The section to be written.
91 */
92void
94 BinaryStream& stream,
95 const Section* sect) const {
96
97 FileOffset startOffset = stream.writePosition();
98 // file offset to data of section
100 FileOffsetKey(startOffset), sect->element(0));
101
102 for (Word i = 0; i < sect->elementCount(); i++) {
103 LineNumProcedure* elem =
104 dynamic_cast<LineNumProcedure*>(sect->element(i));
105 assert(elem != NULL);
106
107 if (elem->procedureSymbol() != NULL) {
109 replacer(elem->procedureSymbol(), sizeof(Word));
110 replacer.resolve();
111 } else {
112 bool procedureSymbolMustBeSet = false;
113 assert(procedureSymbolMustBeSet);
114 }
115
116 // line number zero represents procedure
117 stream.writeHalfWord(0);
118
119 // write line nums...
120 for(Word lineIndex = 0; lineIndex < elem->lineCount(); lineIndex++) {
121
122 const LineNumElement* lineElem = elem->line(lineIndex);
123
124 // write each line
125 SectionOffsetReplacer replacer(lineElem->instruction());
126 replacer.resolve();
127 stream.writeHalfWord(lineElem->lineNumber());
128 }
129 }
130 SectionSizeReplacer::setSize(sect, stream.writePosition() - startOffset);
131}
132
133/**
134 * Returns the fixed size length of section elements.
135 *
136 * @return The fixed size length of section elements.
137 */
138Word
140 return elementSize_;
141}
142
143/**
144 * Writes Info field of section header.
145 *
146 * @param stream The stream where to write.
147 * @param sect Section to write.
148 */
149void
151 BinaryStream& stream, const Section* sect) const {
152
153 const Section* codeSection =
154 dynamic_cast<const LineNumSection*>(sect)->codeSection();
155
156 SectionIdReplacer idReplacer(codeSection);
157 idReplacer.resolve();
158
159 stream.writeHalfWord(0);
160}
161
162}
#define assert(condition)
void writeHalfWord(HalfWord halfword)
unsigned int writePosition()
InstructionElement * instruction() const
HalfWord lineNumber() const
const LineNumElement * line(HalfWord index) const
HalfWord lineCount() const
SymbolElement * procedureSymbol() const
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
static void setSize(const SafePointable *obj, Word size)
static void registerSectionWriter(const SectionWriter *sWriter)
@ ST_LINENO
Line number section.
Definition Section.hh:75
SectionElement * element(Word index) const
Word elementCount() const
static const Word elementSize_
The fixed size address space element.
virtual Section::SectionType type() const
virtual void writeInfo(BinaryStream &stream, const Section *sect) const
static const TPEFLineNumSectionWriter instance_
An unique instance of class.
virtual Word elementSize(const Section *section) const
virtual void actualWriteData(BinaryStream &stream, const Section *section) const
Word FileOffset
Type for storing absolute file offsets.