OpenASIP  2.0
PipelineElement.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 PipelineElement.cc
26  *
27  * Implementation of class PipelineElement.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  */
31 
32 #include "PipelineElement.hh"
33 #include "FunctionUnit.hh"
34 #include "ExecutionPipeline.hh"
35 #include "HWOperation.hh"
36 #include "MachineTester.hh"
37 
38 using std::string;
39 
40 namespace TTAMachine {
41 
42 /**
43  * Constructor.
44  *
45  * Pipeline elements are created automatically when pipeline of operation is
46  * created. Clients should not create pipeline elements.
47  *
48  * @param name Name of the pipeline element.
49  * @param parentUnit The parent unit.
50  * @exception ComponentAlreadyExists If there exists another pipeline element
51  * by the same name in the function unit.
52  * @exception InvalidName If the given name is not a valid component name.
53  */
55  const std::string& name, FunctionUnit& parentUnit)
56  : name_(""), parent_(&parentUnit) {
57  setName(name);
58 
59  // clear parent pointer to pass the assert in addPipelineElement
60  parent_ = NULL;
61 
64 }
65 
66 /**
67  * Destructor.
68  */
70 
71  FunctionUnit* parent = parent_;
72  parent_ = NULL;
73  parent->deletePipelineElement(*this);
74 
75  // remove usages of this resource
76  for (int i = 0; i < parent->operationCount(); i++) {
77  HWOperation* operation = parent->operation(i);
78  ExecutionPipeline* pLine = operation->pipeline();
79  pLine->removeResourceUse(name());
80  }
81 }
82 
83 
84 /**
85  * Sets the name of the pipeline element.
86  *
87  * @param name The new name.
88  * @exception ComponentAlreadyExists If another pipeline element exists by
89  * the same name in the same function unit.
90  * @exception InvalidName If the given name is not a valid component name.
91  */
92 void
93 PipelineElement::setName(const std::string& name) {
94  const string procName = "PipelineElement::setName";
95 
97  throw InvalidName(__FILE__, __LINE__, procName);
98  }
99 
100  if (name == this->name()) {
101  return;
102  }
103 
104  if (parentUnit()->hasPipelineElement(name)) {
105  throw ComponentAlreadyExists(__FILE__, __LINE__, procName);
106  }
107 
108  name_ = name;
109 }
110 
112  const PipelineElement* pe1, const PipelineElement* pe2) const {
113  if (pe1 == NULL) {
114  return false;
115  }
116  if (pe2 == NULL) {
117  return true;
118  }
119  if (pe1->name() > pe2->name()) {
120  return true;
121  }
122 
123  if (pe2->name() > pe1->name()) {
124  return false;
125  }
126 
127  if (pe1->parentUnit()->name() > pe2->parentUnit()->name()) {
128  return true;
129  }
130  return false;
131 }
132 
133 }
134 
135 
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::HWOperation
Definition: HWOperation.hh:52
ExecutionPipeline.hh
TTAMachine::FunctionUnit::addPipelineElement
virtual void addPipelineElement(PipelineElement &element)
Definition: FunctionUnit.cc:466
TTAMachine::PipelineElement::setName
void setName(const std::string &name)
Definition: PipelineElement.cc:93
TTAMachine::PipelineElement::~PipelineElement
virtual ~PipelineElement()
Definition: PipelineElement.cc:69
TTAMachine::ExecutionPipeline::removeResourceUse
void removeResourceUse(const std::string &name)
Definition: ExecutionPipeline.cc:189
TTAMachine::PipelineElement::name
const std::string & name() const
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::PipelineElement::name_
std::string name_
Name of the pipeline element.
Definition: PipelineElement.hh:62
TTAMachine::PipelineElement::parent_
FunctionUnit * parent_
The parent unit.
Definition: PipelineElement.hh:64
HWOperation.hh
InvalidName
Definition: Exception.hh:827
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition: MachineTester.cc:312
MachineTester.hh
TTAMachine::PipelineElement::parentUnit
FunctionUnit * parentUnit() const
TTAMachine::PipelineElement
Definition: PipelineElement.hh:46
PipelineElement.hh
ComponentAlreadyExists
Definition: Exception.hh:510
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::FunctionUnit::deletePipelineElement
virtual void deletePipelineElement(PipelineElement &element)
Definition: FunctionUnit.cc:489
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine::PipelineElement::PipelineElement
PipelineElement(const std::string &name, FunctionUnit &parentUnit)
Definition: PipelineElement.cc:54
TTAMachine
Definition: Assembler.hh:48
TTAMachine::PipelineElement::Comparator::operator()
bool operator()(const PipelineElement *pe1, const PipelineElement *pe2) const
Definition: PipelineElement.cc:111
FunctionUnit.hh