OpenASIP 2.2
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
POMValidator Class Reference

#include <POMValidator.hh>

Collaboration diagram for POMValidator:
Collaboration graph

Public Types

enum  ErrorCode { CONNECTION_MISSING , LONG_IMMEDIATE_NOT_SUPPORTED , SIMULATION_NOT_POSSIBLE , COMPILED_SIMULATION_NOT_POSSIBLE }
 Error codes for different errors. More...
 

Public Member Functions

 POMValidator (const TTAProgram::Program &program)
 
virtual ~POMValidator ()
 
POMValidatorResultsvalidate (const std::set< ErrorCode > &errorsToCheck)
 

Private Member Functions

void checkConnectivity (POMValidatorResults &results)
 
void checkLongImmediates (POMValidatorResults &results)
 
void checkSimulatability (POMValidatorResults &results)
 
void checkCompiledSimulatability (POMValidatorResults &results)
 

Private Attributes

const TTAProgram::Program::InstructionVector instructions_
 The program's instructions in a quickly accessed vector.
 

Detailed Description

POMValidator validates a program object model against a target processor architecture using varoius criteria.

Definition at line 49 of file POMValidator.hh.

Member Enumeration Documentation

◆ ErrorCode

Error codes for different errors.

Enumerator
CONNECTION_MISSING 

Connection required for a move is missing.

LONG_IMMEDIATE_NOT_SUPPORTED 

Instruction template missing for a long immediate.

SIMULATION_NOT_POSSIBLE 

Program contains operations with unknown behaviour.

COMPILED_SIMULATION_NOT_POSSIBLE 

Compiled simulation is not possible.

Definition at line 53 of file POMValidator.hh.

53 {
54 /// Connection required for a move is missing.
56 /// Instruction template missing for a long immediate.
58 /// Program contains operations with unknown behaviour.
60 /// Compiled simulation is not possible
62 };
@ CONNECTION_MISSING
Connection required for a move is missing.
@ LONG_IMMEDIATE_NOT_SUPPORTED
Instruction template missing for a long immediate.
@ SIMULATION_NOT_POSSIBLE
Program contains operations with unknown behaviour.
@ COMPILED_SIMULATION_NOT_POSSIBLE
Compiled simulation is not possible.

Constructor & Destructor Documentation

◆ POMValidator()

POMValidator::POMValidator ( const TTAProgram::Program program)

The Constructor.

Parameters
programPOM to validate.

Definition at line 61 of file POMValidator.cc.

61 :
62 instructions_(program.instructionVector()) {
63
64}
find Finds info of the inner loops in the program
const TTAProgram::Program::InstructionVector instructions_
The program's instructions in a quickly accessed vector.

◆ ~POMValidator()

POMValidator::~POMValidator ( )
virtual

The Destructor.

Definition at line 69 of file POMValidator.cc.

69 {
70}

Member Function Documentation

◆ checkCompiledSimulatability()

void POMValidator::checkCompiledSimulatability ( POMValidatorResults results)
private

Checks for problems specific to compiled simulation only.

Used to check if the program cannot be simulated with the compiled simulator.

Parameters
resultsPOMValidator results where the error messages are added.

Definition at line 325 of file POMValidator.cc.

325 {
326
327 for (std::size_t instrI = 0; instrI < instructions_.size(); ++instrI) {
328 const Instruction* instruction = instructions_.at(instrI);
329 for (int i = 0; i < instruction->moveCount(); i++) {
330 Move& move = instruction->move(i);
331 Terminal* destination = &move.destination();
332 // clocked operations
333 if (destination->isFUPort()) {
334 if (destination->isOpcodeSetting() &&
335 destination->operation().isClocked()) {
336 InstructionAddress address = instruction->address().location();
337 std::string errorMessage =
338 "Instruction at address: " +
339 Conversion::toString(address) +
340 "' cannot be simulated with the compiled simulator. "
341 "(Operation " + destination->operation().name() +
342 " is a clocked operation).";
343
345 errorMessage);
346 }
347 }
348 } // end for
349 }
350}
UInt32 InstructionAddress
Definition BaseType.hh:175
static std::string toString(const T &source)
virtual TCEString name() const
Definition Operation.cc:93
virtual bool isClocked() const
Definition Operation.cc:282
void addError(POMValidator::ErrorCode code, const std::string &errorMsg)
InstructionAddress location() const
Move & move(int i) const
Address address() const
Terminal & destination() const
Definition Move.cc:323
virtual bool isOpcodeSetting() const
Definition Terminal.cc:285
virtual Operation & operation() const
Definition Terminal.cc:319
virtual bool isFUPort() const
Definition Terminal.cc:118

References POMValidatorResults::addError(), TTAProgram::Instruction::address(), COMPILED_SIMULATION_NOT_POSSIBLE, TTAProgram::Move::destination(), instructions_, Operation::isClocked(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isOpcodeSetting(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), Operation::name(), TTAProgram::Terminal::operation(), and Conversion::toString().

Referenced by validate().

Here is the call graph for this function:

◆ checkConnectivity()

void POMValidator::checkConnectivity ( POMValidatorResults results)
private

Checks if the target machine has connectivity needed for program moves.

Parameters
resultsPOMValidator results where the error messages are added.

Definition at line 108 of file POMValidator.cc.

108 {
109
110 for (std::size_t instrI = 0; instrI < instructions_.size(); ++instrI) {
111 const Instruction* instruction = instructions_.at(instrI);
112 // Test all moves in the current instruction.
113 for (int i = 0; i < instruction->moveCount(); i++) {
114 const Move& move = instruction->move(i);
115
116 const Bus& bus = move.bus();
117
118 // Test move source connectivity.
119 if (move.source().isGPR() ||
120 move.source().isFUPort() ||
121 move.source().isImmediateRegister()) {
122
123 const Port& port = move.source().port();
124
125 if (port.outputSocket() == NULL) {
126 // ERROR: Source port is not connected to an output socket.
127 InstructionAddress address = instruction->address().location();
128 std::string errorMessage =
129 Conversion::toString(address) + ": " +
130 "Source port '" + port.parentUnit()->name() +
131 "." + port.name() + "' of the move on bus '" +
132 bus.name() + "' is not connected to an output socket.";
133
134 results.addError(CONNECTION_MISSING, errorMessage);
135
136 } else if (!port.outputSocket()->isConnectedTo(bus)) {
137 // ERROR: Output socket of the source port is not connected
138 // to the move bus.
139 InstructionAddress address = instruction->address().location();
140 std::string errorMessage =
141 Conversion::toString(address) + ": " +
142 "Source port '" + port.parentUnit()->name() +
143 "." + port.name() + "' of the move on bus '" +
144 bus.name() + "' is not connected to the bus.";
145 results.addError(CONNECTION_MISSING, errorMessage);
146 }
147
148 }
149
150 // Test move target connectivity.
151 if (move.destination().isGPR() ||
152 move.destination().isFUPort() ||
154
155 const Port& port = move.destination().port();
156
157 if (port.inputSocket() == NULL) {
158 // ERROR: Destination port is not connected to an output
159 // socket.
160 InstructionAddress address = instruction->address().location();
161 std::string errorMessage =
162 Conversion::toString(address) + ": " +
163 "Destination port '" + port.parentUnit()->name() +
164 "." + port.name() + "' of the move on bus '" +
165 bus.name() + "' is not connected to an input socket.";
166
167 results.addError(CONNECTION_MISSING, errorMessage);
168
169 } else if (!port.inputSocket()->isConnectedTo(bus)) {
170 // ERROR: Output socket of the target port is not connected
171 // to the move bus.
172 InstructionAddress address = instruction->address().location();
173 std::string errorMessage =
174 Conversion::toString(address) + ": " +
175 "Destination port '" + port.parentUnit()->name() +
176 "." + port.name() + "' of the move on bus '" +
177 bus.name() + "' is not connected to the bus.";
178 results.addError(CONNECTION_MISSING, errorMessage);
179 }
180
181 }
182 }
183 }
184}
virtual TCEString name() const
virtual Socket * outputSocket() const
Definition Port.cc:281
Unit * parentUnit() const
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual std::string name() const
Definition Port.cc:141
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
Terminal & source() const
Definition Move.cc:302
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378

References POMValidatorResults::addError(), TTAProgram::Instruction::address(), TTAProgram::Move::bus(), CONNECTION_MISSING, TTAProgram::Move::destination(), TTAMachine::Port::inputSocket(), instructions_, TTAMachine::Socket::isConnectedTo(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAMachine::Component::name(), TTAMachine::Port::name(), TTAMachine::Port::outputSocket(), TTAMachine::Port::parentUnit(), TTAProgram::Terminal::port(), TTAProgram::Move::source(), and Conversion::toString().

Referenced by validate().

Here is the call graph for this function:

◆ checkLongImmediates()

void POMValidator::checkLongImmediates ( POMValidatorResults results)
private

Checks long immediate assignments.

Parameters
resultsPOMValidator results where the error messages are added.

Definition at line 192 of file POMValidator.cc.

192 {
193
194 for (std::size_t instrI = 0; instrI < instructions_.size(); ++instrI) {
195 const Instruction* instruction = instructions_.at(instrI);
196
197 const InstructionTemplate& templ =
198 instruction->instructionTemplate();
199
200 std::set<std::string> destinations;
201 for (int i = 0; i < instruction->immediateCount(); i++) {
202
203 const Immediate& immediate = instruction->immediate(i);
204
205 // Check that the immediate destination terminal is an IU.
206 if (!immediate.destination().isImmediateRegister()) {
207 InstructionAddress address = instruction->address().location();
208 std::string errorMessage =
209 Conversion::toString(address) + ": " +
210 "Long immediate destination terminal is not an "
211 "immediate unit.";
212 results.addError(LONG_IMMEDIATE_NOT_SUPPORTED, errorMessage);
213 continue;
214 }
215
216 int width = immediate.value().value().width();
217 const ImmediateUnit& iu =
218 immediate.destination().immediateUnit();
219 int supportedWidth = templ.supportedWidth(iu);
220 if (width <= INT_WORD_SIZE &&
221 supportedWidth != width) {
222 // Raw magic! If the SimValue reports width higher then
223 // INT_WORD_SIZE it means immediate is floating point,
224 // and should be just respected:-)
225 // If width is less, the actuall width is recomputed
226 // based on target as if it was integer
227 // FIXME: find out how to deal with floating point
228 if (iu.extensionMode() == Machine::ZERO) {
229 // Actual required width depends on target immediate unit
231 immediate.value().value().unsignedValue());
232 }
233 if (iu.extensionMode() == Machine::SIGN) {
234 // Actual required width depends on target immediate unit
236 immediate.value().value().intValue());
237 }
238 }
239 // Check that the destination IU isn't already destination
240 // of a long immediate in the current instruction.
241 std::pair<std::set<std::string>::iterator, bool> result =
242 destinations.insert(iu.name());
243
244 if (!result.second) {
245 // Destination already in the set.
246 InstructionAddress address = instruction->address().location();
247 std::string errorMessage =
248 Conversion::toString(address) + ": " +
249 "Multiple long immediates with destination IU '" +
250 iu.name() + "'.";
251 results.addError(LONG_IMMEDIATE_NOT_SUPPORTED, errorMessage);
252 continue;
253 }
254
255 // Check that the instruction template supports long immediates
256 // with the current long immediate's width and destination IU.
257 if (supportedWidth < width) {
258 InstructionAddress address = instruction->address().location();
259 std::string errorMessage =
260 Conversion::toString(address) + ": " +
261 "Long immediate with destination IU '" +
262 iu.name() + "' has width of " +
263 Conversion::toString(width) + " bits. Instruction's " +
264 "template only supports long immediates with width of " +
266 " bits or less. For template " + templ.name();
267 results.addError(LONG_IMMEDIATE_NOT_SUPPORTED, errorMessage);
268 continue;
269 }
270 }
271 }
272}
const Byte INT_WORD_SIZE
Definition BaseType.hh:154
static int requiredBits(unsigned long int number)
static int requiredBitsSigned(SLongWord number)
int intValue() const
Definition SimValue.cc:895
unsigned int unsignedValue() const
Definition SimValue.cc:919
int width() const
Definition SimValue.cc:103
virtual Machine::Extension extensionMode() const
@ SIGN
Sign extension.
Definition Machine.hh:82
@ ZERO
Zero extension.
Definition Machine.hh:81
TerminalImmediate & value() const
Definition Immediate.cc:103
const Terminal & destination() const
Definition Immediate.cc:92
Immediate & immediate(int i) const
const TTAMachine::InstructionTemplate & instructionTemplate() const
virtual SimValue value() const
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition Terminal.cc:240

References POMValidatorResults::addError(), TTAProgram::Instruction::address(), TTAProgram::Immediate::destination(), TTAMachine::ImmediateUnit::extensionMode(), TTAProgram::Instruction::immediate(), TTAProgram::Instruction::immediateCount(), TTAProgram::Terminal::immediateUnit(), instructions_, TTAProgram::Instruction::instructionTemplate(), INT_WORD_SIZE, SimValue::intValue(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Address::location(), LONG_IMMEDIATE_NOT_SUPPORTED, TTAMachine::Component::name(), MathTools::requiredBits(), MathTools::requiredBitsSigned(), TTAMachine::Machine::SIGN, TTAMachine::InstructionTemplate::supportedWidth(), Conversion::toString(), SimValue::unsignedValue(), TTAProgram::Immediate::value(), TTAProgram::TerminalImmediate::value(), SimValue::width(), and TTAMachine::Machine::ZERO.

Referenced by validate().

Here is the call graph for this function:

◆ checkSimulatability()

void POMValidator::checkSimulatability ( POMValidatorResults results)
private

Checks that all operations in the program have known behaviour and can be simulated.

Parameters
resultsPOMValidator results where the error messages are added.

Definition at line 281 of file POMValidator.cc.

281 {
282
283 std::set<std::string> errOpNames;
284
285 for (std::size_t instrI = 0; instrI < instructions_.size(); ++instrI) {
286 const Instruction* instruction = instructions_.at(instrI);
287
288 for (int i = 0; i < instruction->moveCount(); i++) {
289 Move& move = instruction->move(i);
290 Terminal* destination = &move.destination();
291 if (destination->isFUPort()) {
292 if (destination->isOpcodeSetting() &&
293 !destination->operation().canBeSimulated() &&
295 errOpNames, destination->operation().name())) {
296
297 std::string opName = destination->operation().name();
298 InstructionAddress address =
299 instruction->address().location();
300
301 std::string errorMessage =
302 Conversion::toString(address) + ": " +
303 "Operation '" + opName +
304 "' cannot be simulated.";
305
306 results.addError(
307 SIMULATION_NOT_POSSIBLE, errorMessage);
308
309 errOpNames.insert(opName);
310 }
311 }
312 }
313 }
314}
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
virtual bool canBeSimulated() const
Definition Operation.cc:612

References POMValidatorResults::addError(), TTAProgram::Instruction::address(), Operation::canBeSimulated(), ContainerTools::containsValue(), TTAProgram::Move::destination(), instructions_, TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isOpcodeSetting(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), Operation::name(), TTAProgram::Terminal::operation(), SIMULATION_NOT_POSSIBLE, and Conversion::toString().

Referenced by validate().

Here is the call graph for this function:

◆ validate()

POMValidatorResults * POMValidator::validate ( const std::set< ErrorCode > &  errorsToCheck)

Checks the program against the target machine for given error check set.

Parameters
errorsToCheckSet of error codes which are checked.
Returns
POMValidatorResults object contaning possible error messages.

Definition at line 79 of file POMValidator.cc.

79 {
80
82 for (std::set<ErrorCode>::const_iterator iter = errorsToCheck.begin();
83 iter != errorsToCheck.end(); iter++) {
84 ErrorCode code = *iter;
85 if (code == CONNECTION_MISSING) {
86 checkConnectivity(*results);
87 } else if (code == LONG_IMMEDIATE_NOT_SUPPORTED) {
88 checkLongImmediates(*results);
89 } else if (code == SIMULATION_NOT_POSSIBLE) {
90 checkSimulatability(*results);
91 } else if (code == COMPILED_SIMULATION_NOT_POSSIBLE) {
93 } else {
94 assert(false);
95 }
96 }
97
98 return results;
99}
#define assert(condition)
void checkSimulatability(POMValidatorResults &results)
void checkCompiledSimulatability(POMValidatorResults &results)
ErrorCode
Error codes for different errors.
void checkConnectivity(POMValidatorResults &results)
void checkLongImmediates(POMValidatorResults &results)

References assert, checkCompiledSimulatability(), checkConnectivity(), checkLongImmediates(), checkSimulatability(), COMPILED_SIMULATION_NOT_POSSIBLE, CONNECTION_MISSING, LONG_IMMEDIATE_NOT_SUPPORTED, and SIMULATION_NOT_POSSIBLE.

Referenced by SimulatorFrontend::loadProgram().

Here is the call graph for this function:

Member Data Documentation

◆ instructions_

const TTAProgram::Program::InstructionVector POMValidator::instructions_
private

The program's instructions in a quickly accessed vector.

Definition at line 76 of file POMValidator.hh.

Referenced by checkCompiledSimulatability(), checkConnectivity(), checkLongImmediates(), and checkSimulatability().


The documentation for this class was generated from the following files: