OpenASIP  2.0
OperationBindingCheck.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 OperationBindingCheck.cc
26  *
27  * Implementation of OperationBindingCheck class.
28  *
29  * @author Heikki Kultala 2008 (hkultala-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <boost/format.hpp>
34 
35 #include "OperationBindingCheck.hh"
36 #include "HWOperation.hh"
37 #include "Machine.hh"
38 #include "ExecutionPipeline.hh"
39 #include "FUPort.hh"
40 #include "FunctionUnit.hh"
41 #include "MachineCheckResults.hh"
42 
43 using namespace TTAMachine;
44 
46  MachineCheck("Check operation binding, port directions, triggers") {}
47 
48 /**
49  * Checks that machine's FU's have legal port and trigger bindings
50  *
51  * @param mach machine to check
52  * @param results place where to put detailed error descriptions
53  * @return true if everything is ok, false if something is wrong
54  */
56  const TTAMachine::Machine& mach, MachineCheckResults& results) const {
57 
59  mach.functionUnitNavigator();
60 
61  bool retval = true;
62  bool triggerok = true;
63  for (int i = 0; i < fuNav.count(); i++) {
64  FunctionUnit& fu = *fuNav.item(i);
65 
66  // find trigger port
67  FUPort* triggerPort = NULL;
68  for (int j = 0; j < fu.operationPortCount(); j++) {
69  FUPort* port = fu.operationPort(j);
70  if (port->isTriggering()) {
71 
72  // check that we do not have multiple trigger ports.
73  if ( triggerPort != NULL) {
74  results.addError(
75  *this, (boost::format("Multiple trigger ports are "
76  "not supported, Used in FU: %s")
77  % fu.name()).str());
78  retval = false;
79  triggerok = false;
80  }
81  else {
82  // check trigger and fu ports are the same
83  triggerPort = port;
84  if (!port->isOpcodeSetting()) {
85  results.addError(
86  *this, (boost::format("Opcode setting and trigger "
87  "port differ in FU: ")
88  % fu.name()).str());
89  retval = false;
90  triggerok = false;
91  }
92  }
93  }
94  }
95  // check that we have a trigger port
96  if ( triggerPort == NULL) {
97  results.addError(
98  *this, (boost::format("Trigger port not found in FU: %s")
99  % fu.name()).str());
100  return false;
101  }
102 
103  // check all operations
104  for (int j = 0; j < fu.operationCount(); j++) {
105 
106  HWOperation& hwop = *fu.operation(j);
107  bool triggerRead = false;
108 
109  // check read port bindins
110  ExecutionPipeline& pipe = *hwop.pipeline();
111  const ExecutionPipeline::OperandSet reads = pipe.readOperands();
112  for (ExecutionPipeline::OperandSet::const_iterator iter =
113  reads.begin(); iter != reads.end(); iter++) {
114  Port* readPort = hwop.port(*iter);
115  if ( readPort->inputSocket() == NULL) {
116  std::string errorMsg =
117  (boost::format(
118  "Operation %s in FU %s reads operand %d which "
119  "is not connected to input socket. "
120  "Check port bindings!")
121  % hwop.name() % fu.name() % *iter).str();
122 
123  results.addError(*this, (errorMsg));
124  retval = false;
125  } else {
126  // check if this was read from the trigger
127  if (readPort == triggerPort) {
128  triggerRead = true;
129  }
130  }
131  }
132 
133  // was trigger actually read?
134  if ( triggerok && !triggerRead) {
135  std::string errorMsg =
136  (boost::format(
137  "Trigger not bound for operation: %s in FU %s") %
138  hwop.name() % fu.name()).str();
139  results.addError(*this, errorMsg);
140  retval = false;
141  }
142 
143  // check write port bidings
144  const ExecutionPipeline::OperandSet writes =
145  pipe.writtenOperands();
146  for (ExecutionPipeline::OperandSet::const_iterator iter =
147  writes.begin(); iter != writes.end(); iter++) {
148  Port* writePort = hwop.port(*iter);
149  if ( writePort->outputSocket() == NULL) {
150  results.addError(
151  *this, (boost::format("Operation %s in FU %s "
152  "writes operand %d"
153  "which is not connected to "
154  "output socket. "
155  "Check port bindings!")
156  % hwop.name() % fu.name() % *iter).str());
157  retval = false;
158  }
159  }
160  }
161  }
162  return retval;
163 }
TTAMachine::Port::inputSocket
virtual Socket * inputSocket() const
Definition: Port.cc:261
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::FUPort::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: FUPort.cc:195
TTAMachine::HWOperation
Definition: HWOperation.hh:52
ExecutionPipeline.hh
MachineCheckResults::addError
void addError(const MachineCheck &check, const std::string &errorMsg)
Definition: MachineCheckResults.cc:85
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands(int cycle) const
Definition: ExecutionPipeline.cc:429
OperationBindingCheck.hh
TTAMachine::Machine::Navigator::count
int count() const
TTAMachine::ExecutionPipeline::readOperands
OperandSet readOperands(int cycle) const
Definition: ExecutionPipeline.cc:408
TTAMachine::FUPort::isTriggering
virtual bool isTriggering() const
Definition: FUPort.cc:182
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
TTAMachine::FUPort
Definition: FUPort.hh:46
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
TTAMachine::Port
Definition: Port.hh:54
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
MachineCheckResults
Definition: MachineCheckResults.hh:46
Machine.hh
TTAMachine::ExecutionPipeline::OperandSet
std::set< int > OperandSet
Set for operand indexes.
Definition: ExecutionPipeline.hh:58
TTAMachine::FunctionUnit::operationPortCount
virtual int operationPortCount() const
Definition: FunctionUnit.cc:182
MachineCheckResults.hh
FUPort.hh
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
OperationBindingCheck::check
virtual bool check(const TTAMachine::Machine &mach, MachineCheckResults &results) const
Definition: OperationBindingCheck.cc:55
MachineCheck
Definition: MachineCheck.hh:50
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
OperationBindingCheck::OperationBindingCheck
OperationBindingCheck()
Definition: OperationBindingCheck.cc:45
TTAMachine::Machine
Definition: Machine.hh:73
FunctionUnit.hh