OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFResourceSectionReader.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 TPEFResourceSectionReader.cc
26 *
27 * Definition of TPEFResourceSectionReader class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
35#include "ResourceSection.hh"
36#include "SafePointer.hh"
37#include "Exception.hh"
38#include "ReferenceKey.hh"
39#include "SectionReader.hh"
40#include "TPEFBaseType.hh"
41#include "ResourceElement.hh"
42#include "BinaryStream.hh"
43
44namespace TPEF {
45
46using ReferenceManager::SafePointer;
47using ReferenceManager::SectionKey;
48using ReferenceManager::SectionIndexKey;
49using ReferenceManager::SectionOffsetKey;
50
51TPEFResourceSectionReader TPEFResourceSectionReader::proto_;
52
53/**
54 * Constructor.
55 *
56 * Registers itself to SectionReader.
57 */
62
63/**
64 * Destructor.
65 */
68
69/**
70 * Returns the type of section which reader can read.
71 *
72 * @return The type of section which reader can read.
73 */
78
79/**
80 * Reads section data from TPEF binary file.
81 *
82 * @param stream Stream to be read from.
83 * @param section Section where the information is to be 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 value 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 */
91void
93 BinaryStream& stream, Section* section) const {
94 // base classes implementation must be called with these
95 TPEFSectionReader::readData(stream, section);
96
97 ResourceSection* resourceSection =
98 dynamic_cast<ResourceSection*>(section);
99 assert(resourceSection != NULL);
100
101 // check that link section is defined properly
102 assert(header().linkId != 0);
103
104 if (!section->noBits()) {
105 // store start of first element
106 SectionOffset elementStart = header().bodyOffset;
107
108 while (elementStart + header().elementSize <=
109 header().bodyOffset + header().bodyLength) {
110
111 ResourceElement *elem = new ResourceElement();
112
113 // TODO: check that OP, SR and PORT share the same id space and
114 // don't collide
115
116 elem->setId(stream.readHalfWord());
117
118 elem->setType(
120 (stream.readByte()));
121
123 nameSectOffset(header().linkId, stream.readWord());
124
125 elem->setName(CREATE_SAFEPOINTER(nameSectOffset));
126
127 elem->setInfo(stream.readWord());
128
129 section->addElement(elem);
130
131 elementStart += header().elementSize;
132 stream.setReadPosition(elementStart);
133 }
134 }
135}
136}
#define assert(condition)
void setReadPosition(unsigned int position)
HalfWord readHalfWord()
void setId(HalfWord aId)
void setName(ReferenceManager::SafePointer *aName)
ResourceType
Resource types.
void setInfo(Word aInfo)
void setType(ResourceType aType)
static void registerSectionReader(const SectionReader *sReader)
virtual void addElement(SectionElement *element)
Definition Section.cc:133
@ ST_MR
Machine resources section.
Definition Section.hh:78
bool noBits() const
static TPEFResourceSectionReader proto_
Prototype instance to be registered.
virtual Section::SectionType type() const
virtual void readData(BinaryStream &stream, Section *section) const
virtual void readData(BinaryStream &stream, Section *section) const
static const Header & header()
Word SectionOffset
Type for storing offsets relative to a given base offset value.