OpenASIP  2.0
OperationTriggeredOperand.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2021 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 OperationTriggeredOperand.cc
26  *
27  * Implementation of OperationTriggeredOperand class.
28  *
29  * @author Kari Hepola 2021 (kari.hepola@tuni.fi)
30  * @note rating: red
31  */
32 
34 #include "ObjectState.hh"
36 #include "StringTools.hh"
37 
38 namespace TTAMachine {
39 
40 const std::string OperationTriggeredOperand::OSNAME_OPERAND = "operand";
41 const std::string OperationTriggeredOperand::OSKEY_NAME = "name";
42 const std::string OperationTriggeredOperand::OSKEY_TYPE = "type";
43 const std::string OperationTriggeredOperand::OSKEY_DIRECTION = "direction";
44 
45 /**
46  * The constructor.
47  *
48  * Registers the operation code encoding to the parent
49  * binary encoding automatically.
50  *
51  * @param parent The parent OperationTriggeredFormat.
52  */
53 
55  const std::string& name, OperationTriggeredFormat& parent)
56  : SubComponent(), name_(name), type_(""), direction_("") {
58  parent.addOperand(*this);
59 }
60 
61 /**
62  * The constructor
63  *
64  * Loads the state of the operation code encoding from
65  * the given ObjectState tree
66  *
67  * @param state The ObjectState tree
68  * @param parent The parent binary encoding map
69  * @exception ObjectStateLoadingException If an error occurs while loading
70  the state.
71  */
72 
74  const ObjectState* state, OperationTriggeredFormat& parent)
75  : SubComponent(), name_(""), type_(""), direction_("") {
76  const std::string procName =
77  "OperationTriggeredOperand::OperationTriggeredOperand";
78  // set name
79  try {
81  } catch (const Exception& exception) {
83  __FILE__, __LINE__, procName, exception.errorMessage());
84  }
85  parent.addOperand(*this);
86  loadState(state);
87 }
88 
89 /**
90  * Destructor.
91  */
93  // TODO
94 }
95 
96 /**
97  * Returns the name of the operation.
98  *
99  * @return The name of the operation.
100  */
101 const std::string&
103  return name_;
104 }
105 
106 /**
107  * Sets the name of the operand.
108  *
109  * @param name The new name.
110  */
111 void
112 OperationTriggeredOperand::setName(const std::string& name) {
113  std::string lowerName = StringTools::stringToLower(name);
114 
115  if (lowerName == this->name()) {
116  return;
117  }
118  name_ = lowerName;
119 }
120 
121 std::string
123  return type_;
124 }
125 
126 void
127 OperationTriggeredOperand::setType(const std::string& type) {
128  type_ = type;
129 }
130 
131 std::string
133  return direction_;
134 }
135 
136 void
137 OperationTriggeredOperand::setDirection(const std::string& direction) {
138  type_ = direction;
139 }
140 
141 void
143  ObjectState* newState = new ObjectState(*state);
144  try {
145  type_ = state->stringAttribute(OSKEY_TYPE);
147  } catch (const Exception& exception) {
148  const std::string procName = "OperationTriggeredOperand::loadState";
150  __FILE__, __LINE__, procName, exception.errorMessage());
151  }
152 
153  delete newState;
154 }
155 
156 /**
157  * Saves the state of the operation code encoding
158  * to an ObjectState tree.
159  *
160  * @return The newly created ObjectState tree.
161  */
162 
165  ObjectState* state = new ObjectState(OSNAME_OPERAND);
166  state->setAttribute(OSKEY_NAME, name_);
167  state->setAttribute(OSKEY_TYPE, type_);
169 
170  return state;
171 }
172 } // namespace TTAMachine
TTAMachine::OperationTriggeredOperand::setDirection
void setDirection(const std::string &direction)
Definition: OperationTriggeredOperand.cc:137
TTAMachine::SubComponent
Definition: MachinePart.hh:168
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
TTAMachine::OperationTriggeredOperand::direction_
std::string direction_
Definition: OperationTriggeredOperand.hh:77
TTAMachine::OperationTriggeredOperand::OSKEY_TYPE
static const std::string OSKEY_TYPE
Definition: OperationTriggeredOperand.hh:69
TTAMachine::OperationTriggeredOperand::type
std::string type() const
Definition: OperationTriggeredOperand.cc:122
TTAMachine::OperationTriggeredOperand::~OperationTriggeredOperand
virtual ~OperationTriggeredOperand()
Definition: OperationTriggeredOperand.cc:92
TTAMachine::OperationTriggeredOperand::OSKEY_NAME
static const std::string OSKEY_NAME
Definition: OperationTriggeredOperand.hh:71
ObjectState
Definition: ObjectState.hh:59
TTAMachine::OperationTriggeredOperand::OSKEY_DIRECTION
static const std::string OSKEY_DIRECTION
Definition: OperationTriggeredOperand.hh:70
TTAMachine::OperationTriggeredOperand::OSNAME_OPERAND
static const std::string OSNAME_OPERAND
Definition: OperationTriggeredOperand.hh:68
TTAMachine::OperationTriggeredOperand::name
const std::string & name() const
Definition: OperationTriggeredOperand.cc:102
StringTools.hh
OperationTriggeredOperand.hh
TTAMachine::OperationTriggeredOperand::name_
std::string name_
Definition: OperationTriggeredOperand.hh:75
TTAMachine::OperationTriggeredOperand::loadState
virtual void loadState(const ObjectState *state)
Definition: OperationTriggeredOperand.cc:142
ObjectState.hh
TTAMachine::OperationTriggeredOperand::setType
void setType(const std::string &type)
Definition: OperationTriggeredOperand.cc:127
TTAMachine::OperationTriggeredOperand::direction
std::string direction() const
Definition: OperationTriggeredOperand.cc:132
Exception
Definition: Exception.hh:54
TTAMachine::OperationTriggeredOperand::setName
virtual void setName(const std::string &name)
Definition: OperationTriggeredOperand.cc:112
TTAMachine::OperationTriggeredFormat
Definition: OperationTriggeredFormat.hh:44
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTAMachine::OperationTriggeredOperand::saveState
virtual ObjectState * saveState() const
Definition: OperationTriggeredOperand.cc:164
TTAMachine::OperationTriggeredFormat::addOperand
void addOperand(OperationTriggeredOperand &operand)
Definition: OperationTriggeredFormat.cc:156
OperationTriggeredFormat.hh
TTAMachine::OperationTriggeredOperand::type_
std::string type_
Definition: OperationTriggeredOperand.hh:76
TTAMachine
Definition: Assembler.hh:48
TTAMachine::OperationTriggeredOperand::OperationTriggeredOperand
OperationTriggeredOperand(const std::string &name, OperationTriggeredFormat &parent)
Definition: OperationTriggeredOperand.cc:54
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100