OpenASIP 2.2
Loading...
Searching...
No Matches
BaseRegisterFile.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 BaseRegisterFile.cc
26 *
27 * Implementation of abstract BaseRegisterFile class.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 * @note reviewed 10 Jun 2004 by vpj, am, tr, ll
31 * @note rating: red
32 */
33
34#include "BaseRegisterFile.hh"
35#include "Machine.hh"
36#include "Bus.hh"
37#include "Guard.hh"
38#include "RegisterFile.hh"
39#include "Application.hh"
40#include "ObjectState.hh"
41
42using std::string;
43
44namespace TTAMachine {
45
46// initialization of static data members
47const string BaseRegisterFile::OSNAME_BASE_REGISTER_FILE = "baseregfile";
48const string BaseRegisterFile::OSKEY_SIZE = "size";
49const string BaseRegisterFile::OSKEY_WIDTH = "width";
50
51/**
52 * Constructor.
53 *
54 * @param name Name of the register file.
55 * @param size Number of registers in the register file.
56 * @param width Bit width of the registers in the register file.
57 * @exception OutOfRange If the given size or width is out of range.
58 * @exception InvalidName If the given name is not a valid component name.
59 */
60BaseRegisterFile::BaseRegisterFile(const std::string& name, int size, int width)
61 : Unit(name), size_(size), width_(width) {
64}
65
66/**
67 * Constructor.
68 *
69 * Loads the state of the object from the given ObjectState instance. Does
70 * not load references to other components.
71 *
72 * @param state The ObjectState instance from which the state is loaded.
73 * @exception ObjectStateLoadingException If the given ObjectState instance
74 * is invalid.
75 */
77 : Unit(state), size_(0), width_(0) {
79}
80
81/**
82 * Destructor.
83 */
86
87
88/**
89 * Sets the number of registers in the register file.
90 *
91 * @param registers The new amount of registers.
92 * @exception OutOfRange If the given number of registers is less or equal
93 * to zero.
94 */
95void
97 if (registers <= 0) {
98 string procName = "BaseRegisterFile::setNumberOfRegisters";
99 throw OutOfRange(__FILE__, __LINE__, procName);
100 }
101
102 size_ = registers;
103}
104
105/**
106 * Sets the bit width of the registers.
107 *
108 * @param width The new bit width.
109 * @exception OutOfRange If the given width is less or equal to zero.
110 */
111void
113 if (width <= 0) {
114 string procName = "BaseRegisterFile::setWidth";
115 throw OutOfRange(__FILE__, __LINE__, procName);
116 }
117
118 width_ = width;
119}
120
121/**
122 * Returns the requested port.
123 *
124 * @param name Name of the port.
125 * @return The requested port.
126 * @exception InstanceNotFound If a port is not found by the given name.
127 */
128RFPort*
129BaseRegisterFile::port(const std::string& name) const {
131 RFPort* rfPort = static_cast<RFPort*>(port);
132 return rfPort;
133}
134
135/**
136 * Returns a port by the given index.
137 *
138 * The index must be greater or equal to 0 and smaller than the number of
139 * ports in the unit.
140 *
141 * @param index Index.
142 * @return The port by the given index.
143 * @exception OutOfRange If the given index is out of range.
144 */
145RFPort*
146BaseRegisterFile::port(int index) const {
147 Port* port = Unit::port(index);
148 RFPort* rfPort = dynamic_cast<RFPort*>(port);
149 assert(rfPort != NULL);
150 return rfPort;
151}
152
153/**
154 * Saves the state of the object into an ObjectState tree.
155 *
156 * @return The newly created ObjectState tree.
157 */
160 ObjectState* state = Unit::saveState();
164 return state;
165}
166
167
168/**
169 * Loads its the from the given ObjectState instance.
170 *
171 * @param state The ObjectState instance.
172 * @exception ObjectStateLoadingException If the given ObjectState instance
173 * is invalid.
174 */
175void
180
181/**
182 * Loads its state from the given ObjectState instance without references
183 * to other components.
184 *
185 * @param state The ObjectState instance.
186 * @exception ObjectStateLoadingException If the given ObjectState instance
187 * is invalid.
188 */
189void
191 try {
194 } catch (...) {
195 string procName = "BaseRegisterFile::loadStateWithoutReferences";
196 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
197 }
198}
199}
#define assert(condition)
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
int intAttribute(const std::string &name) const
virtual void setNumberOfRegisters(int registers)
static const std::string OSKEY_SIZE
ObjectState attribute key for the number of registers.
virtual ObjectState * saveState() const
virtual int size() const
static const std::string OSKEY_WIDTH
ObjectState attribute key for bit width of the registers.
static const std::string OSNAME_BASE_REGISTER_FILE
ObjectState name for BaseRegisterFile.
void loadStateWithoutReferences(const ObjectState *state)
virtual int width() const
int width_
Bit width of the registers in the register file.
virtual void setWidth(int width)
int size_
Number of registers in the register file.
virtual RFPort * port(const std::string &name) const
virtual void loadState(const ObjectState *state)
BaseRegisterFile(const std::string &name, int size, int width)
virtual TCEString name() const
virtual Port * port(const std::string &name) const
Definition Unit.cc:116
virtual void loadState(const ObjectState *state)
Definition Unit.cc:309
virtual ObjectState * saveState() const
Definition Unit.cc:285