OpenASIP  2.0
RFPort.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 RFPort.cc
26  *
27  * Implementation of RFPort class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "RFPort.hh"
36 #include "BaseRegisterFile.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
41 namespace TTAMachine {
42 
43 const string RFPort::OSNAME_RFPORT = "rf_port";
44 
45 /**
46  * The constructor.
47  *
48  * @param name Name of the port.
49  * @param parent The parent register file of the port.
50  * @exception InvalidName If the given name is not a valid component name.
51  * @exception ComponentAlreadyExists If there is another port with the same
52  * name in the parent unit.
53  */
54 RFPort::RFPort(const std::string& name, BaseRegisterFile& parent)
55  : Port(name, parent) {}
56 
57 /**
58  * The constuctor.
59  *
60  * Loads the state of the object from the given ObjectState tree.
61  *
62  * @param state The ObjectState tree.
63  * @param parent The parent unit of the port.
64  * @exception ObjectStateLoadingException If an error occurs while loading
65  * the state.
66  */
67 RFPort::RFPort(const ObjectState* state, Unit& parent) : Port(state, parent) {}
68 
69 /**
70  * The destructor.
71  */
73 }
74 
75 
76 /**
77  * Returns the bit width of the port.
78  *
79  * @return The bit width of the port.
80  */
81 int
82 RFPort::width() const {
83  return parentUnit()->width();
84 }
85 
86 
87 /**
88  * Returns the parent register file.
89  *
90  * @return The parent register file.
91  */
94  return static_cast<BaseRegisterFile*>(Port::parentUnit());
95 }
96 
97 
98 /**
99  * Saves the state of the object to an ObjectState tree and returns it.
100  *
101  * @return The newly created ObjectState tree.
102  */
105  ObjectState* state = Port::saveState();
106  state->setName(OSNAME_RFPORT);
107  return state;
108 }
109 
110 
111 /**
112  * Loads the state of the object from the given ObjectState tree.
113  *
114  * @param state An ObjectState instance representing state of an RFPort.
115  * @exception ObjectStateLoadingException If the given ObjectState instance
116  * is invalid.
117  */
118 void
120  if (state->name() != OSNAME_RFPORT) {
121  const string procName = "RFPort::loadState";
122  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
123  }
124 
125  Port::loadState(state);
126 }
127 }
TTAMachine::RFPort::OSNAME_RFPORT
static const std::string OSNAME_RFPORT
ObjectState name for register file port.
Definition: RFPort.hh:58
BaseRegisterFile.hh
TTAMachine::RFPort::width
virtual int width() const
Definition: RFPort.cc:82
TTAMachine::Port::saveState
virtual ObjectState * saveState() const
Definition: Port.cc:404
ObjectStateLoadingException
Definition: Exception.hh:551
TTAMachine::RFPort::loadState
virtual void loadState(const ObjectState *state)
Definition: RFPort.cc:119
TTAMachine::RFPort::~RFPort
virtual ~RFPort()
Definition: RFPort.cc:72
ObjectState
Definition: ObjectState.hh:59
ObjectState::setName
void setName(const std::string &name)
TTAMachine::Port::loadState
virtual void loadState(const ObjectState *state)
Definition: Port.cc:459
TTAMachine::BaseRegisterFile
Definition: BaseRegisterFile.hh:48
TTAMachine::Unit
Definition: Unit.hh:51
TTAMachine::Port
Definition: Port.hh:54
ObjectState.hh
ObjectState::name
std::string name() const
TTAMachine::RFPort::parentUnit
BaseRegisterFile * parentUnit() const
Definition: RFPort.cc:93
RFPort.hh
TTAMachine
Definition: Assembler.hh:48
TTAMachine::RFPort::saveState
virtual ObjectState * saveState() const
Definition: RFPort.cc:104
TTAMachine::BaseRegisterFile::width
virtual int width() const
TTAMachine::RFPort::RFPort
RFPort(const std::string &name, BaseRegisterFile &parent)
Definition: RFPort.cc:54
TTAMachine::Port::parentUnit
Unit * parentUnit() const