OpenASIP  2.0
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 
49 using boost::format;
50 using std::string;
51 using namespace TTAMachine;
52 
53 /**
54  * The Constructor.
55  */
57 }
58 
59 /**
60  * The Destructor.
61  */
63 }
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  */
122 bool
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 }
CopyComponent
Definition: CopyComponent.hh:42
Request::type
RequestType type() const
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ProDeIUEditPolicy.hh
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
ProDeIUEditPolicy::~ProDeIUEditPolicy
virtual ~ProDeIUEditPolicy()
Definition: ProDeIUEditPolicy.cc:62
ImmediateUnit.hh
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
Conversion::toString
static std::string toString(const T &source)
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
TTAMachine::BaseRegisterFile::numberOfRegisters
virtual int numberOfRegisters() const
assert
#define assert(condition)
Definition: Application.hh:86
Request.hh
ProDeIUEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition: ProDeIUEditPolicy.cc:72
ProDeTextGenerator::STATUS_IMMEDIATE_UNIT
@ STATUS_IMMEDIATE_UNIT
Status line template for IUs,.
Definition: ProDeTextGenerator.hh:287
ModifyIUCmd
Definition: ModifyIUCmd.hh:43
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
EditPart.hh
CopyComponent.hh
Conversion.hh
ProDeTextGenerator::TXT_RADIO_EXTENSION_ZERO
@ TXT_RADIO_EXTENSION_ZERO
Label for 'zero' radio button.
Definition: ProDeTextGenerator.hh:100
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
ProDeIUEditPolicy::ProDeIUEditPolicy
ProDeIUEditPolicy()
Definition: ProDeIUEditPolicy.cc:56
ProDeTextGenerator::TXT_RADIO_EXTENSION_SIGN
@ TXT_RADIO_EXTENSION_SIGN
Label for 'sign' radio button.
Definition: ProDeTextGenerator.hh:101
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPolicy
Definition: EditPolicy.hh:47
SetStatusTextCmd.hh
ProDeIUEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDeIUEditPolicy.cc:123
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
DeleteIUCmd
Definition: DeleteIUCmd.hh:42
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::ImmediateUnit::extensionMode
virtual Machine::Extension extensionMode() const
Definition: ImmediateUnit.cc:143
TTAMachine
Definition: Assembler.hh:48
TTAMachine::BaseRegisterFile::width
virtual int width() const
ModifyIUCmd.hh
DeleteIUCmd.hh
ComponentCommand.hh
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50