OpenASIP  2.0
AOutStringSectionReader.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 AOutStringSectionReader.cc
26  *
27  * Definition of AOutStringSectionReader class.
28  *
29  * @author Ari Metsähalme (ari.metsahalme-no.spam-tut.fi)
30  * @author Mikael Lepistö 2004 (tmlepist-no.spam-cs.tut.fi)
31  * @note reviewed 17 October 2003 by kl, pj, am, rm
32  *
33  * @note rating: yellow
34  */
35 
36 #include "Section.hh"
37 #include "SafePointer.hh"
38 #include "ReferenceKey.hh"
39 #include "StringSection.hh"
42 
43 namespace TPEF {
44 
45 using std::string;
46 using ReferenceManager::SectionKey;
47 using ReferenceManager::SafePointer;
48 
49 AOutStringSectionReader AOutStringSectionReader::proto_;
50 
51 /**
52  * Constructor.
53  *
54  * Registers to SectionReader.
55  */
58 }
59 
60 /**
61  * Destructor.
62  */
64 }
65 
66 /**
67  * Returns the type of section that this class can read.
68  *
69  * @return Type of section to read.
70  */
73  return Section::ST_STRTAB;
74 }
75 
76 /**
77  * Reads string section from a.out binary file.
78  *
79  * Reads section from stream and makes sure that section starts withs
80  * zero.
81  *
82  * @param stream Stream to be read from.
83  * @param section Section where to the information is stored.
84  * @exception UnreachableStream If reading of section fails.
85  * @exception KeyAlreadyExists Key was in use when trying to register object.
86  * @exception EndOfFile If end of file were reached while it shouldn't.
87  * @exception OutOfRange Some of read values were out of range.
88  * @exception WrongSubclass Some class couldn't do what it was asked for.
89  * @exception UnexpectedValue If there was unexpected value when reading.
90  */
91 void
93  BinaryStream& stream, Section* section) const {
94  AOutReader* aOutReader = dynamic_cast<AOutReader*>(parent());
95 
96  StringSection* strSect = dynamic_cast<StringSection*>(section);
97  assert(strSect != NULL);
98 
99  for (unsigned int i = 0;
100  i < aOutReader->header().sectionSizeString(); i++) {
101  strSect->addByte(stream.readByte());
102  }
103 
104  // add zero byte if no data
105  if (strSect->length() == 0) {
106  strSect->addByte(0);
107  }
108 
109  // section must start with zero.
110  assert(strSect->byte(strSect->chunk(0)) == 0);
111 }
112 }
TPEF::DataSection::byte
virtual Byte byte(const Chunk *chunk) const
Definition: DataSection.cc:114
TPEF::AOutStringSectionReader::readData
virtual void readData(BinaryStream &stream, Section *section) const
Definition: AOutStringSectionReader.cc:92
TPEF::BinaryStream
Definition: BinaryStream.hh:59
SafePointer.hh
StringSection.hh
TPEF::DataSection::addByte
virtual void addByte(Byte aByte)
Definition: DataSection.cc:200
TPEF::AOutStringSectionReader::~AOutStringSectionReader
virtual ~AOutStringSectionReader()
Definition: AOutStringSectionReader.cc:63
TPEF::Section
Definition: Section.hh:64
TPEF::StringSection
Definition: StringSection.hh:48
AOutSymbolSectionReader.hh
AOutStringSectionReader.hh
TPEF::AOutStringSectionReader::proto_
static AOutStringSectionReader proto_
Static attribute enables registering to SectionReader before main function is executed.
Definition: AOutStringSectionReader.hh:66
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::AOutReader
Definition: AOutReader.hh:54
TPEF::AOutSectionReader::parent
virtual BinaryReader * parent() const
Definition: AOutSectionReader.cc:57
TPEF::SectionReader::registerSectionReader
static void registerSectionReader(const SectionReader *sReader)
Definition: SectionReader.cc:145
TPEF::BinaryStream::readByte
Byte readByte()
Definition: BinaryStream.cc:120
TPEF::AOutReader::header
static const Header & header()
TPEF::AOutStringSectionReader::AOutStringSectionReader
AOutStringSectionReader()
Definition: AOutStringSectionReader.cc:56
TPEF::Section::ST_STRTAB
@ ST_STRTAB
String table.
Definition: Section.hh:71
TPEF::AOutSectionReader
Definition: AOutSectionReader.hh:45
Section.hh
TPEF::AOutStringSectionReader::type
virtual Section::SectionType type() const
Definition: AOutStringSectionReader.cc:72
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
TPEF::DataSection::length
virtual Word length() const
Definition: DataSection.cc:210
TPEF::RawSection::chunk
virtual Chunk * chunk(SectionOffset offset) const
Definition: Section.cc:212
ReferenceKey.hh
TPEF
Definition: Assembler.hh:43