OpenASIP  2.0
RFPortCode.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 RFPortCode.cc
26  *
27  * Implementation of RFPortCode 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 "RFPortCode.hh"
36 #include "SocketCodeTable.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
41 const std::string RFPortCode::OSNAME_RF_PORT_CODE = "rf_port_code";
42 
43 /**
44  * The constructor.
45  *
46  * Registers the created instance to the given socket code table
47  * automatically.
48  *
49  * @param regFile Name of the register file.
50  * @param encoding The encoding for the register file port.
51  * @param extraBits The number of extra zero bits in the encoding.
52  * @param indexWidth The number of bits reserved for the register index.
53  * @param parent The parent socket code table.
54  * @exception ObjectAlreadyExists If the socket code table has an encoding
55  * defined for the same port already, or if
56  * the encoding is ambiguous with another
57  * encoding in the same socket code table.
58  * @exception OutOfRange If some of the given values is out of range.
59  */
61  const std::string& regFile, unsigned int encoding, unsigned int extraBits,
62  int indexWidth, SocketCodeTable& parent)
63  : PortCode(regFile, encoding, extraBits, indexWidth) {
64  setParent(NULL);
65  parent.addRFPortCode(*this);
66  setParent(&parent);
67 }
68 
69 /**
70  * The constructor.
71  *
72  * Creates an RF port code without port encoding. That is, the port
73  * code consists of mere register index. This is useful when the
74  * parent socket code table does not have other port codes. Registers
75  * the created instance to the given socket code table automatically.
76  *
77  * @param regFile Name of the register file.
78  * @param indexWidth The number of bits reserved for the register index.
79  * @param parent The parent socket code table.
80  * @exception ObjectAlreadyExists If the socket code table has an encoding
81  * defined for the same port already, or if
82  * the encoding is ambiguous with another
83  * encoding in the same socket code table.
84  * @exception OutOfRange If the given index width is negative.
85  */
87  const std::string& regFile, int indexWidth, SocketCodeTable& parent)
88  : PortCode(regFile, indexWidth) {
89  setParent(NULL);
90  parent.addRFPortCode(*this);
91  setParent(&parent);
92 }
93 
94 /**
95  * The constructor.
96  *
97  * Loads the state of the object from the given ObjectState tree.
98  *
99  * @param state The ObjectState tree.
100  * @param parent The parent encoding map.
101  * @exception ObjectStateLoadingException If an error occurs while loading
102  * the state.
103  * @exception ObjectAlreadyExists If the socket code table has an encoding
104  * defined for the same port already, or if
105  * the encoding is ambiguous with another
106  * encoding in the same socket code table.
107  */
109  : PortCode(state) {
110  if (state->name() != OSNAME_RF_PORT_CODE) {
111  const string procName = "RFPortCode::RFPortCode";
112  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
113  }
114 
115  setParent(NULL);
116  parent.addRFPortCode(*this);
117  setParent(&parent);
118 }
119 
120 /**
121  * The destructor.
122  */
124  SocketCodeTable* parent = this->parent();
125  setParent(NULL);
126  parent->removeRFPortCode(*this);
127 }
128 
129 
130 /**
131  * Saves the state of the object to an ObjectState tree.
132  *
133  * @return The newly created ObjectState tree.
134  */
137  ObjectState* state = PortCode::saveState();
139  return state;
140 }
RFPortCode::~RFPortCode
virtual ~RFPortCode()
Definition: RFPortCode.cc:123
PortCode
Definition: PortCode.hh:45
ObjectStateLoadingException
Definition: Exception.hh:551
SocketCodeTable::removeRFPortCode
void removeRFPortCode(RFPortCode &code)
Definition: SocketCodeTable.cc:458
SocketCodeTable.hh
ObjectState
Definition: ObjectState.hh:59
RFPortCode.hh
RFPortCode::OSNAME_RF_PORT_CODE
static const std::string OSNAME_RF_PORT_CODE
ObjectState name for RF port code.
Definition: RFPortCode.hh:57
ObjectState::setName
void setName(const std::string &name)
SocketCodeTable
Definition: SocketCodeTable.hh:68
ObjectState.hh
ObjectState::name
std::string name() const
PortCode::setParent
void setParent(SocketCodeTable *parent)
Definition: PortCode.cc:256
RFPortCode::RFPortCode
RFPortCode(const std::string &regFile, unsigned int encoding, unsigned int extraBits, int indexWidth, SocketCodeTable &parent)
Definition: RFPortCode.cc:60
RFPortCode::saveState
virtual ObjectState * saveState() const
Definition: RFPortCode.cc:136
PortCode::parent
SocketCodeTable * parent() const
Definition: PortCode.cc:226
SocketCodeTable::addRFPortCode
void addRFPortCode(RFPortCode &code)
Definition: SocketCodeTable.cc:428
PortCode::saveState
virtual ObjectState * saveState() const
Definition: PortCode.cc:237