OpenASIP  2.0
ProDeRFEditPolicy.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 ProDeRFEditPolicy.cc
26  *
27  * Definition of ProDeRFEditPolicy 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 "ProDeRFEditPolicy.hh"
38 #include "Request.hh"
39 #include "ComponentCommand.hh"
40 #include "ModifyRFCmd.hh"
41 #include "DeleteRFCmd.hh"
42 #include "CopyComponent.hh"
43 #include "RegisterFile.hh"
44 #include "EditPart.hh"
45 #include "SetStatusTextCmd.hh"
46 #include "ProDeTextGenerator.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  ModifyRFCmd* modifyCmd = new ModifyRFCmd(host_);
78  return modifyCmd;
79 
80  } else if (type == Request::DELETE_REQUEST) {
81  DeleteRFCmd* deleteCmd = new DeleteRFCmd(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  RegisterFile* rf = dynamic_cast<RegisterFile*>(host_->model());
92  format fmt = generator->text(ProDeTextGenerator::STATUS_REGISTER_FILE);
93  string type = "";
94  if (rf->isNormal()) {
95  type = generator->text(
97  } else if (rf->isVolatile()) {
98  type = generator->text(
100  } else if (rf->isReserved()) {
101  type = generator->text(
103  } else {
104  // unknown rf type
105  assert(false);
106  }
107 
108  fmt % rf->name() % type %
111 
112  SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
113  return statusCmd;
114 
115  } else {
116  return NULL;
117  }
118 }
119 
120 /**
121  * Tells whether this EditPolicy is able to handle a certain type
122  * of Request.
123  *
124  * @param request Request to be asked if it can be handled.
125  * @return True if the Request can be handled, false otherwise.
126  */
127 bool
129  Request::RequestType type = request->type();
130  if (type == Request::MODIFY_REQUEST ||
131  type == Request::DELETE_REQUEST ||
132  type == Request::COPY_REQUEST ||
133  type == Request::STATUS_REQUEST) {
134  return true;
135  } else {
136  return false;
137  }
138 }
CopyComponent
Definition: CopyComponent.hh:42
Request::type
RequestType type() const
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::RegisterFile::isReserved
virtual bool isReserved() const
Definition: RegisterFile.cc:184
DeleteRFCmd
Definition: DeleteRFCmd.hh:42
ProDeRFEditPolicy.hh
ProDeRFEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition: ProDeRFEditPolicy.cc:72
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
ModifyRFCmd
Definition: ModifyRFCmd.hh:43
ProDeRFEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDeRFEditPolicy.cc:128
ProDeRFEditPolicy::ProDeRFEditPolicy
ProDeRFEditPolicy()
Definition: ProDeRFEditPolicy.cc:56
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ModifyRFCmd.hh
ProDeTextGenerator.hh
Conversion::toString
static std::string toString(const T &source)
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
DeleteRFCmd.hh
TTAMachine::BaseRegisterFile::numberOfRegisters
virtual int numberOfRegisters() const
assert
#define assert(condition)
Definition: Application.hh:86
ProDeTextGenerator::TXT_RF_TYPE_NORMAL
@ TXT_RF_TYPE_NORMAL
Register file type: normal.
Definition: ProDeTextGenerator.hh:157
Request.hh
TTAMachine::RegisterFile::isNormal
virtual bool isNormal() const
Definition: RegisterFile.cc:158
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
EditPart.hh
CopyComponent.hh
Conversion.hh
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPolicy
Definition: EditPolicy.hh:47
SetStatusTextCmd.hh
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
ProDeTextGenerator::STATUS_REGISTER_FILE
@ STATUS_REGISTER_FILE
Status line template for RFs.
Definition: ProDeTextGenerator.hh:286
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
RegisterFile.hh
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
ProDeTextGenerator::TXT_RF_TYPE_RESERVED
@ TXT_RF_TYPE_RESERVED
Register file type: reserved.
Definition: ProDeTextGenerator.hh:159
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
ProDeTextGenerator::TXT_RF_TYPE_VOLATILE
@ TXT_RF_TYPE_VOLATILE
Register file type: volatile.
Definition: ProDeTextGenerator.hh:158
TTAMachine
Definition: Assembler.hh:48
TTAMachine::RegisterFile::isVolatile
virtual bool isVolatile() const
Definition: RegisterFile.cc:171
TTAMachine::BaseRegisterFile::width
virtual int width() const
ProDeRFEditPolicy::~ProDeRFEditPolicy
virtual ~ProDeRFEditPolicy()
Definition: ProDeRFEditPolicy.cc:62
ComponentCommand.hh