OpenASIP  2.0
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 
42 using std::string;
43 
44 namespace TTAMachine {
45 
46 // initialization of static data members
47 const string BaseRegisterFile::OSNAME_BASE_REGISTER_FILE = "baseregfile";
48 const string BaseRegisterFile::OSKEY_SIZE = "size";
49 const 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  */
60 BaseRegisterFile::BaseRegisterFile(const std::string& name, int size, int width)
61  : Unit(name), size_(size), width_(width) {
63  setWidth(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  */
85 }
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  */
95 void
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  */
111 void
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  */
128 RFPort*
129 BaseRegisterFile::port(const std::string& name) const {
130  Port* port = Unit::port(name);
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  */
145 RFPort*
146 BaseRegisterFile::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();
162  state->setAttribute(OSKEY_SIZE, size_);
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  */
175 void
178  Unit::loadState(state);
179 }
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  */
189 void
191  try {
194  } catch (...) {
195  string procName = "BaseRegisterFile::loadStateWithoutReferences";
196  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
197  }
198 }
199 }
TTAMachine::BaseRegisterFile::setWidth
virtual void setWidth(int width)
Definition: BaseRegisterFile.cc:112
BaseRegisterFile.hh
TTAMachine::BaseRegisterFile::OSKEY_SIZE
static const std::string OSKEY_SIZE
ObjectState attribute key for the number of registers.
Definition: BaseRegisterFile.hh:68
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ObjectStateLoadingException
Definition: Exception.hh:551
OutOfRange
Definition: Exception.hh:320
TTAMachine::BaseRegisterFile::~BaseRegisterFile
virtual ~BaseRegisterFile()
Definition: BaseRegisterFile.cc:84
TTAMachine::BaseRegisterFile::size_
int size_
Number of registers in the register file.
Definition: BaseRegisterFile.hh:80
TTAMachine::BaseRegisterFile::loadState
virtual void loadState(const ObjectState *state)
Definition: BaseRegisterFile.cc:176
TTAMachine::Unit::loadState
virtual void loadState(const ObjectState *state)
Definition: Unit.cc:309
ObjectState
Definition: ObjectState.hh:59
TTAMachine::BaseRegisterFile::BaseRegisterFile
BaseRegisterFile(const std::string &name, int size, int width)
Definition: BaseRegisterFile.cc:60
ObjectState::setName
void setName(const std::string &name)
TTAMachine::RFPort
Definition: RFPort.hh:45
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::Unit::saveState
virtual ObjectState * saveState() const
Definition: Unit.cc:285
TTAMachine::BaseRegisterFile::OSKEY_WIDTH
static const std::string OSKEY_WIDTH
ObjectState attribute key for bit width of the registers.
Definition: BaseRegisterFile.hh:70
TTAMachine::Unit
Definition: Unit.hh:51
TTAMachine::Port
Definition: Port.hh:54
Application.hh
TTAMachine::Unit::port
virtual Port * port(const std::string &name) const
Definition: Unit.cc:116
TTAMachine::BaseRegisterFile::loadStateWithoutReferences
void loadStateWithoutReferences(const ObjectState *state)
Definition: BaseRegisterFile.cc:190
ObjectState.hh
Guard.hh
Machine.hh
Bus.hh
TTAMachine::BaseRegisterFile::setNumberOfRegisters
virtual void setNumberOfRegisters(int registers)
Definition: BaseRegisterFile.cc:96
TTAMachine::BaseRegisterFile::port
virtual RFPort * port(const std::string &name) const
Definition: BaseRegisterFile.cc:129
TTAMachine::BaseRegisterFile::saveState
virtual ObjectState * saveState() const
Definition: BaseRegisterFile.cc:159
RegisterFile.hh
TTAMachine::BaseRegisterFile::OSNAME_BASE_REGISTER_FILE
static const std::string OSNAME_BASE_REGISTER_FILE
ObjectState name for BaseRegisterFile.
Definition: BaseRegisterFile.hh:66
TTAMachine::BaseRegisterFile::width_
int width_
Bit width of the registers in the register file.
Definition: BaseRegisterFile.hh:82
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
TTAMachine
Definition: Assembler.hh:48
TTAMachine::BaseRegisterFile::size
virtual int size() const
TTAMachine::BaseRegisterFile::width
virtual int width() const
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100