OpenASIP 2.2
Loading...
Searching...
No Matches
ProDeIUEditPolicy.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 ProDeIUEditPolicy.cc
26 *
27 * Definition of ProDeIUEditPolicy class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: yellow
31 * @note reviewed Jul 20 2004 by vpj, jn, am
32 */
33
34#include <boost/format.hpp>
35#include <string>
36
37#include "ProDeIUEditPolicy.hh"
38#include "ImmediateUnit.hh"
39#include "Request.hh"
40#include "ComponentCommand.hh"
41#include "ModifyIUCmd.hh"
42#include "DeleteIUCmd.hh"
43#include "CopyComponent.hh"
44#include "ProDeTextGenerator.hh"
45#include "EditPart.hh"
46#include "SetStatusTextCmd.hh"
47#include "Conversion.hh"
48
49using boost::format;
50using std::string;
51using namespace TTAMachine;
52
53/**
54 * The Constructor.
55 */
58
59/**
60 * The Destructor.
61 */
64
65/**
66 * Returns the Command corresponding to the type of the Request.
67 *
68 * @param request Request to be handled.
69 * @return NULL if the Request cannot be handled.
70 */
73
74 Request::RequestType type = request->type();
75
76 if (type == Request::MODIFY_REQUEST) {
77 ModifyIUCmd* modifyCmd = new ModifyIUCmd(host_);
78 return modifyCmd;
79
80 } else if (type == Request::DELETE_REQUEST) {
81 DeleteIUCmd* deleteCmd = new DeleteIUCmd(host_);
82 return deleteCmd;
83
84 } else if (type == Request::COPY_REQUEST) {
85 CopyComponent* copyCmd = new CopyComponent(host_);
86 return copyCmd;
87
88 } else if (type == Request::STATUS_REQUEST) {
89
90 ImmediateUnit* iu = dynamic_cast<ImmediateUnit*>(host_->model());
92 format fmt = generator->text(
94 string extension = "";
95 if (iu->extensionMode() == Machine::SIGN) {
96 extension = generator->text(
98 } else if (iu->extensionMode() == Machine::ZERO) {
99 extension = generator->text(
101 } else {
102 // unknown extension
103 assert(false);
104 }
105 fmt % iu->name() % Conversion::toString(iu->numberOfRegisters()) %
106 Conversion::toString(iu->width()) % extension;
107 SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
108 return statusCmd;
109
110 } else {
111 return NULL;
112 }
113}
114
115/**
116 * Tells whether this EditPolicy is able to handle a certain type
117 * of Request.
118 *
119 * @param request Request to be asked if it can be handled.
120 * @return True if the Request can be handled, false otherwise.
121 */
122bool
124 Request::RequestType type = request->type();
125 if (type == Request::MODIFY_REQUEST ||
126 type == Request::DELETE_REQUEST ||
127 type == Request::COPY_REQUEST ||
128 type == Request::STATUS_REQUEST) {
129 return true;
130 } else {
131 return false;
132 }
133}
#define assert(condition)
static std::string toString(const T &source)
TTAMachine::MachinePart * model() const
EditPart * host_
Host EditPart of this EditPolicy.
Definition EditPolicy.hh:74
virtual bool canHandle(Request *request) const
virtual ComponentCommand * getCommand(Request *request)
static ProDeTextGenerator * instance()
@ TXT_RADIO_EXTENSION_ZERO
Label for 'zero' radio button.
@ TXT_RADIO_EXTENSION_SIGN
Label for 'sign' radio button.
@ STATUS_IMMEDIATE_UNIT
Status line template for IUs,.
RequestType
Data type for determining the type of a Request.
Definition Request.hh:46
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49
@ COPY_REQUEST
Copy request.
Definition Request.hh:51
RequestType type() const
virtual int numberOfRegisters() const
virtual int width() const
virtual TCEString name() const
virtual Machine::Extension extensionMode() const
@ SIGN
Sign extension.
Definition Machine.hh:82
@ ZERO
Zero extension.
Definition Machine.hh:81
virtual boost::format text(int textId)