OpenASIP  2.0
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 
40 using boost::format;
41 using std::string;
42 
43 namespace TTAMachine {
44 
45 const 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  */
57 ImmediateSlot::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  */
104  unsetMachine();
105 }
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  */
116 int
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  */
141 void
143  machine.addImmediateSlot(*this);
145 }
146 
147 /**
148  * Removes registration of the immediate slot from its current machine.
149  */
150 void
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  */
177 void
178 ImmediateSlot::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  */
213 void
215  if (state->name() != OSNAME_IMMEDIATE_SLOT) {
216  const string procName = "ImmediateSlot::loadState";
217  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
218  }
219 
220  Component::loadState(state);
221 }
222 }
TTAMachine::Component::internalUnsetMachine
void internalUnsetMachine()
TTAMachine::Component::setName
virtual void setName(const std::string &name)
Definition: MachinePart.cc:142
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::Machine::deleteImmediateSlot
virtual void deleteImmediateSlot(ImmediateSlot &slot)
Definition: Machine.cc:635
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ObjectStateLoadingException
Definition: Exception.hh:551
TTAMachine::ImmediateSlot::setMachine
virtual void setMachine(Machine &machine)
Definition: ImmediateSlot.cc:142
TTAMachine::Component::saveState
virtual ObjectState * saveState() const
Definition: MachinePart.cc:189
ObjectState
Definition: ObjectState.hh:59
MOMTextGenerator::TXT_IMM_SLOT_EXISTS_BY_SAME_NAME
@ TXT_IMM_SLOT_EXISTS_BY_SAME_NAME
Definition: MOMTextGenerator.hh:86
TTAMachine::ImmediateSlot::setName
virtual void setName(const std::string &name)
Definition: ImmediateSlot.cc:178
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ObjectState::setName
void setName(const std::string &name)
TTAMachine::Component::internalSetMachine
void internalSetMachine(Machine &machine)
TTAMachine::InstructionTemplate
Definition: InstructionTemplate.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::ImmediateSlot::ImmediateSlot
ImmediateSlot(const std::string &name, Machine &parent)
Definition: ImmediateSlot.cc:57
ImmediateSlot.hh
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
TTAMachine::ImmediateSlot::OSNAME_IMMEDIATE_SLOT
static const std::string OSNAME_IMMEDIATE_SLOT
ObjectState name for ImmediateSlot.
Definition: ImmediateSlot.hh:60
TTAMachine::Component::loadState
virtual void loadState(const ObjectState *state)
Definition: MachinePart.cc:205
ObjectState.hh
TTAMachine::Component
Definition: MachinePart.hh:90
TTAMachine::ImmediateSlot::unsetMachine
virtual void unsetMachine()
Definition: ImmediateSlot.cc:151
TTAMachine::InstructionTemplate::supportedWidth
virtual int supportedWidth() const
Definition: InstructionTemplate.cc:427
Machine.hh
ObjectState::name
std::string name() const
TTAMachine::ImmediateSlot::saveState
virtual ObjectState * saveState() const
Definition: ImmediateSlot.cc:199
TTAMachine::ImmediateSlot::width
int width() const
Definition: ImmediateSlot.cc:117
TTAMachine::Machine::immediateSlotNavigator
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition: Machine.cc:462
TTAMachine::ImmediateSlot::loadState
virtual void loadState(const ObjectState *state)
Definition: ImmediateSlot.cc:214
TTAMachine::ImmediateSlot::~ImmediateSlot
virtual ~ImmediateSlot()
Definition: ImmediateSlot.cc:103
TTAMachine::Component::machine
virtual Machine * machine() const
MOMTextGenerator
Definition: MOMTextGenerator.hh:40
TTAMachine::Machine::addImmediateSlot
virtual void addImmediateSlot(ImmediateSlot &slot)
Definition: Machine.cc:299
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
ComponentAlreadyExists
Definition: Exception.hh:510
MOMTextGenerator.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
MOMTextGenerator::TXT_BUS_AND_IMM_SLOT_WITH_SAME_NAME
@ TXT_BUS_AND_IMM_SLOT_WITH_SAME_NAME
Definition: MOMTextGenerator.hh:85
TTAMachine
Definition: Assembler.hh:48
TTAMachine::InstructionTemplate::removeSlot
virtual void removeSlot(const std::string &slotName)
Definition: InstructionTemplate.cc:201
TTAMachine::Machine::instructionTemplateNavigator
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition: Machine.cc:428
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::Machine
Definition: Machine.hh:73