OpenASIP 2.2
Loading...
Searching...
No Matches
OperationTriggeredEncoding.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 OperationTriggeredEncoding.cc
26 *
27 * Implementation of OperationTriggeredEncoding class.
28 *
29 * @author Kari Hepola 2021 (kari.hepola@tuni.fi)
30 * @note rating: red
31 */
32
35#include "InstructionFormat.hh"
36#include "ObjectState.hh"
37#include <algorithm>
38
40 "ota-encoding";
41
43 "name";
44
45/**
46 * The constructor.
47 *
48 * Adds the instruction format to the parent binary encoding automatically.
49 *
50 * @param name Name of the instruction format.
51 * @param parent The parent Instruction Format.
52 */
53
55 const std::string& name, InstructionFormat& parent)
56 : name_(name) {
57 parent.addEncoding(*this);
58}
59
60/**
61 * The constructor.
62 *
63 * Loads the state of the instruction format from the given ObjectState tree.
64 *
65 * @param state The ObjectState tree.
66 * @param parent The parent binary encoding map.
67 * @exception ObjectStateLoadingException If an error occurs while loading
68 the state.
69 */
70
76
77/**
78 * The destructor
79 *
80 */
81
83 for (unsigned int i = 0; i < fields_.size(); i++) {
84 delete fields_.at(i);
85 }
86}
87
88/**
89 * Returns the name of the instruction format.
90 *
91 * @return The name of the instruction format
92 */
93
94std::string
96 return name_;
97}
98
99/**
100 * Sets the name of the instruction format.
101 *
102 * @param name The name of the instruction format.
103 */
104
105void
106OperationTriggeredEncoding::setName(const std::string& name) {
107 name_ = name;
108}
109
110/**
111 * Returns the number of operation triggered fields.
112 *
113 * @return The number of child fields.
114 */
115
116int
118 return fields_.size();
119}
120
121/**
122 * Returns the bit width of the instruction format.
123 *
124 * @return Bit width of the instruction format.
125 */
126
127int
129 int width = 0;
130 for (unsigned int i = 0; i < fields_.size(); i++) {
131 OperationTriggeredField* field = fields_.at(i);
132 width += field->width();
133 }
134 return width;
135}
136
137void
139 // TODO: Inspect that field is valid
140 fields_.push_back(&field);
141}
142
143/**
144 * Loads the state of the instruction format from the given ObjectState tree.
145 *
146 * @param state The ObjectState tree.
147 * @exception ObjectStateLoadingException If an error occurs while loading
148 * the state.
149 */
150
151void
153 ObjectState* newState = new ObjectState(*state);
154 try {
156 for (int i = 0; i < newState->childCount(); i++) {
157 ObjectState* child = newState->child(i);
159 new OperationTriggeredField(child, *this);
160 }
161 }
162 } catch (const Exception& exception) {
163 const std::string procName = "OperationTriggeredEncoding::loadState";
165 __FILE__, __LINE__, procName, exception.errorMessage());
166 }
167 delete newState;
168}
169
170/**
171 * Saves the state of the instruction format to an ObjectState tree.
172 *
173 * @return The newly created ObjectState tree.
174 */
175
180 for (unsigned int i = 0; i < fields_.size(); i++) {
182 ObjectState* fieldObj = it->saveState();
183 state->addChild(fieldObj);
184 }
185 return state;
186}
std::string errorMessage() const
Definition Exception.cc:123
void addEncoding(OperationTriggeredEncoding &encoding)
void setAttribute(const std::string &name, const std::string &value)
ObjectState * child(int index) const
void addChild(ObjectState *child)
std::string stringAttribute(const std::string &name) const
std::string name() const
int childCount() const
virtual ObjectState * saveState() const
void addField(OperationTriggeredField &field)
void setName(const std::string &name)
virtual void loadState(const ObjectState *state)
static const std::string OSNAME_OTA_ENCODING
OperationTriggeredEncoding(const std::string &name, InstructionFormat &parent)
static const std::string OSKEY_OTA_ENCODING_NAME
std::vector< OperationTriggeredField * > fields_
virtual ObjectState * saveState() const
static const std::string OSNAME_FIELD