OpenASIP 2.2
Loading...
Searching...
No Matches
ImmediateSlot.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 ImmediateSlot.cc
26 *
27 * Implementation of ImmediateSlot 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 "ImmediateSlot.hh"
36#include "MOMTextGenerator.hh"
37#include "Machine.hh"
38#include "ObjectState.hh"
39
40using boost::format;
41using std::string;
42
43namespace TTAMachine {
44
45const std::string ImmediateSlot::OSNAME_IMMEDIATE_SLOT = "immediate_slot";
46
47/**
48 * The constructor.
49 *
50 * @param name Name of the immediate slot.
51 * @param parent The parent machine.
52 * @exception InvalidName If the given name is not a valid component name.
53 * @exception ComponentAlreadyExists If the machine already contains a
54 * bus or immediate slot with the same
55 * name.
56 */
57ImmediateSlot::ImmediateSlot(const std::string& name, Machine& parent)
58 : Component(name) {
59 setMachine(parent);
60}
61
62/**
63 * The constructor.
64 *
65 * Loads the state of the object from the given ObjectState instance.
66 *
67 * @param state The ObjectState instance.
68 * @param parent The parent machine.
69 * @exception ObjectStateLoadingException If an error occurs while loading
70 * the state.
71 * @exception ComponentAlreadyExists If the machine already contains a
72 * bus or immediate slot with the same
73 * name.
74 */
76 : Component(state) {
77 const string procName = "ImmediateSlot::ImmediateSlot";
78
79 if (parent.busNavigator().hasItem(name())) {
80 MOMTextGenerator textGenerator;
81 format text = textGenerator.text(
83 text % name();
85 __FILE__, __LINE__, procName, text.str());
86 }
87 if (parent.immediateSlotNavigator().hasItem(name())) {
88 MOMTextGenerator textGenerator;
89 format text = textGenerator.text(
91 text % name();
93 __FILE__, __LINE__, procName, text.str());
94 }
95
96 setMachine(parent);
97 loadState(state);
98}
99
100/**
101 * The destructor.
102 */
106
107
108/**
109 * Returns the bit width of the immediate slot.
110 *
111 * The bit width is determined by the instruction templates which use the
112 * immediate slot.
113 *
114 * @return The bit width of the immediate slot.
115 */
116int
118
119 int width = 0;
120
123 for (int i = 0; i < itNav.count(); i++) {
124 InstructionTemplate* iTemp = itNav.item(i);
125 if (iTemp->supportedWidth(name()) > width) {
126 width = iTemp->supportedWidth(name());
127 }
128 }
129
130 return width;
131}
132
133
134/**
135 * Registers the immediate slot to a machine.
136 *
137 * @param mach Machine to which the immediate slot is going to be registered.
138 * @exception ComponentAlreadyExists If the given machine already has another
139 * immediate slot or bus by the same name.
140 */
141void
146
147/**
148 * Removes registration of the immediate slot from its current machine.
149 */
150void
152 assert(machine() != NULL);
153 Machine* mach = machine();
154
155 // delete the template slots that use this slot
158 for (int i = 0; i < itNav.count(); i++) {
159 InstructionTemplate* iTemp = itNav.item(i);
160 iTemp->removeSlot(name());
161 }
162
164 mach->deleteImmediateSlot(*this);
165}
166
167
168/**
169 * Sets the name of the immediate slot.
170 *
171 * @param name The new name.
172 * @exception ComponentAlreadyExists If the machine already contains an
173 * immediate slot or bus with the same
174 * name.
175 * @exception InvalidName If the given name is not a valid component name.
176 */
177void
178ImmediateSlot::setName(const std::string& name) {
179 if (name == this->name()) {
180 return;
181 }
182
183 Machine* mach = machine();
184 if (mach->immediateSlotNavigator().hasItem(name) ||
185 mach->busNavigator().hasItem(name)) {
186 const string procName = "ImmediateSlot::setName";
187 throw ComponentAlreadyExists(__FILE__, __LINE__, procName);
188 } else {
190 }
191}
192
193/**
194 * Saves the state of the object to an ObjectState instance.
195 *
196 * @return The newly created ObjectState instance.
197 */
202 return state;
203}
204
205
206/**
207 * Loads the state of the object from the given ObjectState instance.
208 *
209 * @param state The ObjectState instance.
210 * @exception ObjectStateLoadingException If an error occurs when loading
211 * the state.
212 */
213void
215 if (state->name() != OSNAME_IMMEDIATE_SLOT) {
216 const string procName = "ImmediateSlot::loadState";
217 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
218 }
219
221}
222}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
void setName(const std::string &name)
std::string name() const
virtual void setName(const std::string &name)
virtual Machine * machine() const
virtual void loadState(const ObjectState *state)
void internalSetMachine(Machine &machine)
virtual TCEString name() const
virtual ObjectState * saveState() const
virtual void setMachine(Machine &machine)
virtual void loadState(const ObjectState *state)
ImmediateSlot(const std::string &name, Machine &parent)
static const std::string OSNAME_IMMEDIATE_SLOT
ObjectState name for ImmediateSlot.
virtual ObjectState * saveState() const
virtual void setName(const std::string &name)
virtual void removeSlot(const std::string &slotName)
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual void addImmediateSlot(ImmediateSlot &slot)
Definition Machine.cc:299
virtual void deleteImmediateSlot(ImmediateSlot &slot)
Definition Machine.cc:635
virtual boost::format text(int textId)