OpenASIP 2.2
Loading...
Searching...
No Matches
MachineEditPartFactory.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 MachineEditPartFactory.cc
26 *
27 * Definition of MachineEditPartFactory class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: yellow
31 * @note reviewed Jul 13 2004 by vpj, ll, jn, am
32 */
33
34#include <set>
35
36#include "Application.hh"
37#include "ContainerTools.hh"
39#include "Machine.hh"
40#include "FunctionUnit.hh"
41#include "ControlUnit.hh"
42#include "RegisterFile.hh"
43#include "ImmediateUnit.hh"
44#include "Port.hh"
45#include "Socket.hh"
46#include "Bus.hh"
47#include "Bridge.hh"
48#include "FUFactory.hh"
49#include "RFFactory.hh"
50#include "IUFactory.hh"
51#include "SocketFactory.hh"
52#include "BusFactory.hh"
53#include "GCUFactory.hh"
54#include "BridgeFactory.hh"
55#include "EditPart.hh"
56#include "ContentsFigure.hh"
57#include "BidirBridgeFigure.hh"
59#include "BusContainerFigure.hh"
61#include "BusChainFigure.hh"
62#include "ConnectionEditPart.hh"
63
64#include "EditPolicyFactory.hh"
65
66using std::vector;
67using std::set;
68using namespace TTAMachine;
69
70/**
71 * The Constructor.
72 */
74 EditPolicyFactory& editPolicyFactory) :
75 EditPartFactory(editPolicyFactory) {
76
77 registerFactory(new GCUFactory(editPolicyFactory));
78 registerFactory(new FUFactory(editPolicyFactory));
79 registerFactory(new IUFactory(editPolicyFactory));
80 registerFactory(new RFFactory(editPolicyFactory));
81 registerFactory(new BridgeFactory(editPolicyFactory));
82 registerFactory(new SocketFactory(editPolicyFactory));
83 registerFactory(new BusFactory(editPolicyFactory));
84}
85
86
87/**
88 * The Destructor.
89 */
92
93/**
94 * Delegates to registered factories to create the EditPart.
95 *
96 * @param component Component of which to create the corresponding
97 * EditPart.
98 * @return NULL if none of the factories can create the EditPart.
99 */
102
103 EditPart* ep = EditPartFactory::checkCache(component);
104
105 if (ep != NULL) {
106 return ep;
107 }
108
109 vector<Factory*>::const_iterator i = factories_.begin();
110
111 for (; i != factories_.end(); i++) {
112 ep = (*i)->createEditPart(component);
113 if (ep != NULL) {
115 return ep;
116 }
117 }
118
119 return NULL;
120}
121
122/**
123 * Overloaded implementation for creating the contents EditPart from the
124 * machine.
125 *
126 * @param machine Machine to create the EditPart from.
127 * @return The created contents EditPart corresponding to the machine.
128 */
131
132 EditPart* contents = new EditPart();
133 contents->setFigure(new ContentsFigure());
134
135 contents->addChild(getUnits(machine));
136 contents->addChild(getSockets(machine));
137 contents->addChild(getBusChains(machine));
138
139 return contents;
140}
141
142/**
143 * Navigates through the machine and creates a unit container EditPart.
144 *
145 * Returns a NULL pointer if there are no units in the given machine.
146 *
147 * @param machine Machine to navigate through.
148 * @return An EditPart containing EditParts for all the units in the
149 * given machine or NULL if there aren't any.
150 */
153
157
159 EditPart* units = NULL;
160
161 if (fuNav.count() > 0 || rfNav.count() > 0 || iuNav.count() > 0 ||
162 gcu != NULL) {
163
164 units = new EditPart();
165 units->setFigure(new UnitContainerFigure());
166
167 for (int i = 0; i < fuNav.count(); i++) {
168 FunctionUnit* fu = fuNav.item(i);
169 EditPart* ep = createEditPart(fu);
170 assert(ep != NULL);
171 units->addChild(ep);
172 }
173
174 for (int i = 0; i < rfNav.count(); i++) {
175 RegisterFile* rf = rfNav.item(i);
176 EditPart* ep = createEditPart(rf);
177 assert(ep != NULL);
178 units->addChild(ep);
179 }
180
181 for (int i = 0; i < iuNav.count(); i++) {
182 ImmediateUnit* iu = iuNav.item(i);
183 EditPart* ep = createEditPart(iu);
184 assert(ep != NULL);
185 units->addChild(ep);
186 }
187
188 if (gcu != NULL) {
189 EditPart* ep = createEditPart(gcu);
190 assert(ep != NULL);
191 units->addChild(ep);
192 }
193 }
194
195 return units;
196}
197
198/**
199 * Navigates through the machine and creates a socket container EditPart.
200 *
201 * Returns a NULL pointer if there are no sockets in the given machine.
202 *
203 * @param machine Machine to navigate through.
204 * @return An EditPart containing EditParts for all the sockets in the
205 * given machine or NULL if there aren't any.
206 */
209
211 EditPart* sockets = NULL;
212
213 if (socketNav.count() > 0) {
214
215 sockets = new EditPart();
216 sockets->setFigure(new SocketContainerFigure());
217
218 for (int i = 0; i < socketNav.count(); i++) {
219 Socket* socket = socketNav.item(i);
220 EditPart* ep = createEditPart(socket);
221 assert(ep != NULL);
222 sockets->addChild(ep);
223 }
224 }
225
226 return sockets;
227}
228
229/**
230 * Navigates through the machine and creates a bus container EditPart.
231 *
232 * Returns a NULL pointer if there are no buses in the given machine.
233 *
234 * @param machine Machine to navigate through.
235 * @return An EditPart containing EditParts for all the buses and bus
236 * chains in the given machine or NULL if there aren't any.
237 */
240
242
243 EditPart* busContainer = NULL;
244
245 if (busNav.count() > 0) {
246
247 set<Bus*> sorted;
248 busContainer = new EditPart();
249 busContainer->setFigure(new BusContainerFigure());
250 vector<Bus*> buses;
251
252 for (int i = 0; i < busNav.count(); i++) {
253 buses.push_back(busNav.item(i));
254 }
255
256 // get bridges
257
259 vector<Bridge*> bridges;
260
261 for (int i = 0; i < bridgeNav.count(); i++) {
262 bridges.push_back(bridgeNav.item(i));
263 }
264
265 // sort the bus chains
266
267 for (unsigned int i = 0; i < buses.size(); i++) {
268
269 if (!ContainerTools::containsValue(sorted, buses[i])) {
270
271 sorted.insert(buses[i]);
272 Bus* first = buses[i];
273
274 // browse to the beginning of the chain
275 while (first->hasPreviousBus()) {
276 first = first->previousBus();
277 }
278
279 // start adding buses to the chain
280
281 if (first->hasNextBus()) {
282
283 EditPart* busChain = new EditPart();
284 busChain->setFigure(new BusChainFigure());
285
286 while (true) {
287 sorted.insert(first);
288
289 // find also the bridge(s) in between
290 ConnectionEditPart* bridgeEditPart = NULL;
291 ConnectionEditPart* biDirBridge = NULL;
292
293 if (first->hasNextBus()) {
295 bridgeEditPart, biDirBridge, bridges, first);
296 }
297
298 // add the bus and the following bridge to the chain
299
300 EditPart* nextEditPart = createEditPart(first);
301 assert(nextEditPart != NULL);
302 busChain->addChild(nextEditPart);
303
304 if (biDirBridge != NULL) {
305 busChain->addChild(biDirBridge);
306 } else if (bridgeEditPart != NULL) {
307 busChain->addChild(bridgeEditPart);
308 }
309
310 if (first->hasNextBus()) {
311 first = first->nextBus();
312 } else {
313 break;
314 }
315 }
316
317 busContainer->addChild(busChain);
318
319 } else {
320 // add a single bus
321 EditPart* busEditPart = createEditPart(buses[i]);
322 assert(busEditPart != NULL);
323 busContainer->addChild(busEditPart);
324 }
325 }
326 }
327 }
328
329 return busContainer;
330}
331
332/**
333 * Creates an EditPart for a bidirectional bridge.
334 *
335 * @param bridge EditPart representing one of the bridges.
336 * @param opposite The opposite bridge.
337 * @return EditPart for the bidirectional bridge.
338 */
341 ConnectionEditPart* bridge,
342 Bridge* opposite) {
343
344 ConnectionEditPart* biDirBridge = new ConnectionEditPart();
345 biDirBridge->setSelectable(true);
348 biDirBridge->setFigure(fig);
349 EditPart* oppositeBridge = createEditPart(opposite);
350 bridge->setSelectable(false);
351 oppositeBridge->setSelectable(false);
352
353 biDirBridge->setModel(bridge->model());
354 biDirBridge->setSource(bridge->source());
355 biDirBridge->setTarget(bridge->target());
356
357 biDirBridge->installEditPolicy(
359
360 biDirBridge->addChild(bridge);
361 biDirBridge->addChild(oppositeBridge);
362
363 return biDirBridge;
364}
365
366/**
367 * Finds and returns the bridge or bridges that are connected to a bus.
368 *
369 * @param bridgeEditPart Where to store one bridge, no change if no
370 bridge found.
371 * @param biDirBridge Where to store the other bridge, no change if no other
372 * bridge found.
373 * @param bridges Which bridges to search.
374 * @param bus Bus to which the searched bridges should be connected.
375 */
376void
378 ConnectionEditPart*& bridgeEditPart,
379 ConnectionEditPart*& biDirBridge,
380 vector<Bridge*>& bridges,
381 Bus* bus) {
382
383 unsigned int j = 0;
384
385 while (j < bridges.size()) {
386 if (connected(bridges[j], bus, bus->nextBus())) {
387 bridgeEditPart = dynamic_cast<ConnectionEditPart*>(
388 createEditPart(bridges[j]));
389 break;
390 }
391 j++;
392 }
393
394 // check if the bridge is bidirectional
395 j++;
396 while (j < bridges.size()) {
397 if (connected(bridges[j], bus, bus->nextBus())) {
398 biDirBridge =
399 createBiDirBridge(bridgeEditPart, bridges[j]);
400 break;
401 }
402 j++;
403 }
404}
405
406/**
407 * Tells whether a bridge is connected to two specific buses.
408 *
409 * @param bridge The bridge.
410 * @param bus1 One bus.
411 * @param bus2 The other bus.
412 * @return True if the bridge is connected to the buses, false otherwise.
413 */
414bool
416 const Bridge* bridge,
417 const Bus* bus1,
418 const Bus* bus2) {
419
420 return (bridge->sourceBus() == bus1 &&
421 bridge->destinationBus() == bus2) ||
422 (bridge->destinationBus() == bus1 &&
423 bridge->sourceBus() == bus2);
424}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
void setDirection(BridgeFigure::Direction direction)
EditPart * source() const
EditPart * target() const
void setSource(EditPart *source)
void setTarget(EditPart *target)
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
void registerFactory(Factory *factory)
std::vector< Factory * > factories_
Registered factories.
EditPart * checkCache(const TTAMachine::MachinePart *component) const
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
void writeToCache(EditPart *editPart)
void setModel(TTAMachine::MachinePart *model)
void installEditPolicy(EditPolicy *editpolicy)
Definition EditPart.cc:247
void setFigure(Figure *figure)
void setSelectable(bool selectable)
void addChild(EditPart *child)
Definition EditPart.cc:260
TTAMachine::MachinePart * model() const
virtual EditPolicy * createBridgeEditPolicy()
EditPart * getUnits(TTAMachine::Machine *machine)
bool connected(const TTAMachine::Bridge *bridge, const TTAMachine::Bus *bus1, const TTAMachine::Bus *bus2)
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
void findConnectedBridges(ConnectionEditPart *&bridgeEditPart, ConnectionEditPart *&biDirBridge, std::vector< TTAMachine::Bridge * > &bridges, TTAMachine::Bus *bus)
EditPart * getSockets(TTAMachine::Machine *machine)
EditPart * getBusChains(TTAMachine::Machine *machine)
ConnectionEditPart * createBiDirBridge(ConnectionEditPart *bridge, TTAMachine::Bridge *opposite)
MachineEditPartFactory(EditPolicyFactory &editPolicyFactory)
Bus * destinationBus() const
Bus * sourceBus() const
virtual Bus * previousBus() const
Definition Bus.cc:518
virtual bool hasPreviousBus() const
Definition Bus.cc:473
virtual bool hasNextBus() const
Definition Bus.cc:488
virtual Bus * nextBus() const
Definition Bus.cc:501
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345