OpenASIP  2.0
FUGenerated.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2017 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 FUGenerated.cc
26  *
27  * Implementation of FUGenerated.
28  *
29  * @author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
30  */
31 
32 #include "FUGenerated.hh"
33 #include "MachineImplementation.hh"
34 
35 namespace IDF {
36 
37 const std::string ATTRIB_NAME = "name";
38 const std::string TAG_OPERATION = "operation";
39 const std::string TAG_OPERATION_ID = "operation-id";
40 const std::string TAG_OPERATION_LATENCY = "operation-latency";
41 const std::string TAG_OPTION = "option";
42 const std::string TAG_FUGENERATE = "fu-generate";
43 const std::string TAG_HDBFILE = "hdb-file";
44 
45 FUGenerated::FUGenerated(const std::string& name) : name_(name) {}
46 
47 void
50 
51  for (int i = state->childCount() - 1; i >= 0; --i) {
52  ObjectState* child = state->child(i);
53 
54  if (child->name() == TAG_OPERATION) {
55  std::string opName = child->stringAttribute(ATTRIB_NAME);
56  std::string hdbFile =
58  int id = child->childByName(TAG_OPERATION_ID)->intValue();
59  int latency = 0;
60  if (child->hasChild(TAG_OPERATION_LATENCY)) {
61  latency =
63  }
64  Info info = {opName, hdbFile, id, latency};
65  operations_.emplace_back(info);
66  } else if (child->name() == TAG_OPTION) {
67  options_.emplace_back(child->stringValue());
68  }
69  }
70 }
71 
75 
77 
78  for (const auto operation : operations_) {
79  ObjectState* opState = new ObjectState(TAG_OPERATION);
80  opState->setAttribute(ATTRIB_NAME, operation.operationName);
81  ObjectState* hdbState = new ObjectState(TAG_HDBFILE);
82  hdbState->setValue(operation.hdb);
84  idState->setValue(operation.id);
85  ObjectState* latencyState = new ObjectState(TAG_OPERATION_LATENCY);
86  latencyState->setValue(operation.latency);
87  opState->addChild(hdbState);
88  opState->addChild(idState);
89  opState->addChild(latencyState);
90  state->addChild(opState);
91  }
92 
93  for (const auto option : options_) {
94  ObjectState* opState = new ObjectState(TAG_OPTION);
95  opState->setValue(option);
96  state->addChild(opState);
97  }
98 
99  return state;
100 }
101 
102 std::string
104  return name_;
105 }
106 
107 void
108 FUGenerated::name(const std::string& newName) {
109  name_ = newName;
110 }
111 
112 std::vector<FUGenerated::Info>&
114  return operations_;
115 }
116 
117 const std::vector<FUGenerated::Info>&
118 FUGenerated::operations() const {
119  return operations_;
120 }
121 
122 const std::vector<std::string>&
124  return dagOperations_;
125 }
126 
127 void
129  operations_.emplace_back(op);
130 }
131 
132 void
134  dagOperations_.emplace_back(op.operationName);
135  for (auto&& subop : op.suboperations) {
136  operations_.emplace_back(subop);
137  }
138 }
139 
140 const std::vector<std::string>&
142  return options_;
143 }
144 } // namespace IDF
IDF::TAG_OPERATION_LATENCY
const std::string TAG_OPERATION_LATENCY
Definition: FUGenerated.cc:40
IDF::FUGenerated::dagOperations
const std::vector< std::string > & dagOperations() const
Definition: FUGenerated.cc:123
IDF::FUGenerated::loadState
void loadState(const ObjectState *state) override
Definition: FUGenerated.cc:48
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
IDF::TAG_OPTION
const std::string TAG_OPTION
Definition: FUGenerated.cc:41
IDF::FUGenerated::name_
std::string name_
Definition: FUGenerated.hh:72
ObjectState::intValue
int intValue() const
IDF::TAG_HDBFILE
const std::string TAG_HDBFILE
Definition: FUGenerated.cc:43
IDF::FUGenerated::options
const std::vector< std::string > & options() const
Definition: FUGenerated.cc:141
ObjectState
Definition: ObjectState.hh:59
FUGenerated.hh
IDF::FUGenerated::saveState
ObjectState * saveState() const override
Definition: FUGenerated.cc:73
ObjectState::childByName
ObjectState * childByName(const std::string &name) const
Definition: ObjectState.cc:443
IDF::TAG_OPERATION_ID
const std::string TAG_OPERATION_ID
Definition: FUGenerated.cc:39
IDF::FUGenerated::operations_
std::vector< Info > operations_
Definition: FUGenerated.hh:73
IDF::FUGenerated::options_
std::vector< std::string > options_
Definition: FUGenerated.hh:75
IDF::FUGenerated::operations
std::vector< Info > & operations()
Definition: FUGenerated.cc:113
IDF::FUGenerated::Info
Definition: FUGenerated.hh:43
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
ObjectState::childCount
int childCount() const
ObjectState::hasChild
bool hasChild(const std::string &name) const
Definition: ObjectState.cc:358
ObjectState::name
std::string name() const
IDF::FUGenerated::dagOperations_
std::vector< std::string > dagOperations_
Definition: FUGenerated.hh:74
IDF::TAG_FUGENERATE
const std::string TAG_FUGENERATE
Definition: FUGenerated.cc:42
IDF::FUGenerated::addOperation
void addOperation(const Info &op)
Definition: FUGenerated.cc:128
IDF::ATTRIB_NAME
const std::string ATTRIB_NAME
Definition: FUGenerated.cc:37
ObjectState::stringValue
std::string stringValue() const
IDF::FUGenerated::FUGenerated
FUGenerated()=default
IDF::FUGenerated::DAGOperation::operationName
std::string operationName
Definition: FUGenerated.hh:50
IDF::FUGenerated::DAGOperation
Definition: FUGenerated.hh:49
IDF::FUGenerated::DAGOperation::suboperations
std::vector< Info > suboperations
Definition: FUGenerated.hh:51
IDF::FUGenerated::name
std::string name() const
Definition: FUGenerated.cc:103
ObjectState::setValue
void setValue(const std::string &value)
IDF::TAG_OPERATION
const std::string TAG_OPERATION
Definition: FUGenerated.cc:38
IDF
Definition: DSDBManager.hh:54
MachineImplementation.hh
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100