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

#include <BEMValidator.hh>

Collaboration diagram for BEMValidator:
Collaboration graph

Public Member Functions

 BEMValidator (const BinaryEncoding &bem, const TTAMachine::Machine &machine)
 
 ~BEMValidator ()
 
bool validate ()
 
int errorCount () const
 
std::string errorMessage (int index) const
 
int warningCount () const
 
std::string warningMessage (int index) const
 

Private Types

typedef std::vector< std::string > StringVector
 Vector type for string.
 

Private Member Functions

void checkMoveSlot (const TTAMachine::Bus &bus)
 
void checkDestinationField (const TTAMachine::Bus &bus)
 
void checkSourceField (const TTAMachine::Bus &bus)
 
void checkGuardField (const TTAMachine::Bus &bus)
 
void checkSocketCodeTable (const SocketEncoding &socketEnc)
 
void checkImmediateSlot (const TTAMachine::ImmediateSlot &immSlot)
 
void checkImmediateControlField ()
 
void checkLImmDstRegisterFields ()
 
void checkImemMauWidth (TTAMachine::ControlUnit &gcu)
 
bool needsSourceField (const MoveSlot &slot) const
 
bool needsSocketCodeTable (const SocketEncoding &socketEnc) const
 

Private Attributes

const BinaryEncodingbem_
 The binary encoding map.
 
const TTAMachine::Machinemachine_
 The machine.
 
StringVector errorMessages_
 Contains the error messages.
 
StringVector warningMessages_
 Contains the warning messages.
 

Detailed Description

Validates binary encoding maps against machines. Checks that the BEM contains all the required information.

Definition at line 57 of file BEMValidator.hh.

Member Typedef Documentation

◆ StringVector

typedef std::vector<std::string> BEMValidator::StringVector
private

Vector type for string.

Definition at line 72 of file BEMValidator.hh.

Constructor & Destructor Documentation

◆ BEMValidator()

BEMValidator::BEMValidator ( const BinaryEncoding bem,
const TTAMachine::Machine machine 
)

The constructor.

Parameters
bemThe binary encoding map.
machineThe machine.

Definition at line 72 of file BEMValidator.cc.

74 :
75 bem_(bem), machine_(machine) {
76}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
const BinaryEncoding & bem_
The binary encoding map.
const TTAMachine::Machine & machine_
The machine.

◆ ~BEMValidator()

BEMValidator::~BEMValidator ( )

The destructor.

Definition at line 82 of file BEMValidator.cc.

82 {
83}

Member Function Documentation

◆ checkDestinationField()

void BEMValidator::checkDestinationField ( const TTAMachine::Bus bus)
private

Checks the destination field of the given bus for errors.

If errors are found, inserts the error messages to the vector of error messages.

Definition at line 317 of file BEMValidator.cc.

317 {
318
319 MoveSlot& moveSlot = bem_.moveSlot(bus.name());
320
321 // collect the input sockets to a set
322 typedef std::set<Socket*> SocketSet;
323 SocketSet inputSockets;
324
325 for (int i = 0; i < bus.segmentCount(); i++) {
326 Segment* segment = bus.segment(i);
327 for (int i = 0; i < segment->connectionCount(); i++) {
328 Socket* socket = segment->connection(i);
329 if (socket->portCount() > 0 &&
330 socket->direction() == Socket::INPUT) {
331 inputSockets.insert(socket);
332 }
333 }
334 }
335
336 // check the destination field
337 if (inputSockets.size() > 1) {
338 if (!moveSlot.hasDestinationField()) {
339 format errorMsg(
340 "Move slot of bus %1% does not contain destination field.");
341 errorMsg % bus.name();
342 errorMessages_.push_back(errorMsg.str());
343 } else {
344 DestinationField& dstField = moveSlot.destinationField();
345 for (SocketSet::const_iterator iter = inputSockets.begin();
346 iter != inputSockets.end(); iter++) {
347 Socket* socket = *iter;
348 if (!dstField.hasSocketEncoding(socket->name())) {
349 format errorMsg(
350 "Destination field of move slot of bus %1% does not"
351 "have an encoding for socket %2%.");
352 errorMsg % bus.name() % socket->name();
353 errorMessages_.push_back(errorMsg.str());
354 } else {
355 SocketEncoding& socketEnc = dstField.socketEncoding(
356 socket->name());
357 if (needsSocketCodeTable(socketEnc)) {
358 if (!socketEnc.hasSocketCodes()) {
359 format errorMsg(
360 "Encoding of socket %1% in destination "
361 "field of move slot %2% does not refer to "
362 "any socket code table.");
363 errorMsg % socket->name() % bus.name();
364 errorMessages_.push_back(errorMsg.str());
365 } else {
366 checkSocketCodeTable(socketEnc);
367 }
368 }
369 }
370 }
371 }
372 }
373}
StringVector errorMessages_
Contains the error messages.
bool needsSocketCodeTable(const SocketEncoding &socketEnc) const
void checkSocketCodeTable(const SocketEncoding &socketEnc)
MoveSlot & moveSlot(int index) const
DestinationField & destinationField() const
Definition MoveSlot.cc:341
bool hasDestinationField() const
Definition MoveSlot.cc:327
bool hasSocketEncoding(const std::string &socket) const
Definition SlotField.cc:188
SocketEncoding & socketEncoding(int index) const
Definition SlotField.cc:170
bool hasSocketCodes() const
virtual Segment * segment(int index) const
Definition Bus.cc:329
virtual int segmentCount() const
Definition Bus.cc:385
virtual TCEString name() const
const Connection & connection(const Socket &socket) const
Definition Segment.cc:250
int connectionCount() const
@ INPUT
Data goes from bus to port.
Definition Socket.hh:59
Direction direction() const
int portCount() const

References bem_, checkSocketCodeTable(), TTAMachine::Segment::connection(), TTAMachine::Segment::connectionCount(), MoveSlot::destinationField(), TTAMachine::Socket::direction(), errorMessages_, MoveSlot::hasDestinationField(), SocketEncoding::hasSocketCodes(), SlotField::hasSocketEncoding(), TTAMachine::Socket::INPUT, BinaryEncoding::moveSlot(), TTAMachine::Component::name(), needsSocketCodeTable(), TTAMachine::Socket::portCount(), TTAMachine::Bus::segment(), TTAMachine::Bus::segmentCount(), and SlotField::socketEncoding().

Referenced by checkMoveSlot().

Here is the call graph for this function:

◆ checkGuardField()

void BEMValidator::checkGuardField ( const TTAMachine::Bus bus)
private

Checks the guard field of the given bus for errors.

If errors are found, inserts the error messages to the vector of error messages.

Parameters
busThe bus.

Definition at line 385 of file BEMValidator.cc.

385 {
386
387 MoveSlot& slot = bem_.moveSlot(bus.name());
388
389 if (bus.guardCount() < 2) {
390 return;
391 } else if (!slot.hasGuardField()) {
392 format errorMsg("Move slot %1% does not contain guard field.");
393 errorMsg % bus.name();
394 errorMessages_.push_back(errorMsg.str());
395 return;
396 }
397
398 GuardField& grdField = slot.guardField();
399
400 for (int i = 0; i < bus.guardCount(); i++) {
401 Guard* guard = bus.guard(i);
402 UnconditionalGuard* ucGuard =
403 dynamic_cast<UnconditionalGuard*>(guard);
404 PortGuard* portGuard = dynamic_cast<PortGuard*>(guard);
405 RegisterGuard* regGuard = dynamic_cast<RegisterGuard*>(guard);
406 if (ucGuard != NULL &&
407 !grdField.hasUnconditionalGuardEncoding(ucGuard->isInverted())) {
408 format errorMsg(
409 "Guard field of move slot %1% does not have encoding "
410 "for always-%2% guard.");
411 errorMsg % bus.name();
412 if (ucGuard->isInverted()) {
413 errorMsg % "false";
414 } else {
415 errorMsg % "true";
416 }
417 errorMessages_.push_back(errorMsg.str());
418
419 } else if (portGuard != NULL) {
420 FUPort* port = portGuard->port();
421 FunctionUnit* fu = port->parentUnit();
422 if (!grdField.hasFUGuardEncoding(
423 fu->name(), port->name(), portGuard->isInverted())) {
424 format errorMsg(
425 "Guard field of move slot %1% does not have encoding "
426 "for %2% FU port guard of port %3% of FU %4%.");
427 errorMsg % bus.name();
428 if (portGuard->isInverted()) {
429 errorMsg % "inverted";
430 } else {
431 errorMsg % "non-inverted";
432 }
433 errorMsg % port->name() % fu->name();
434 errorMessages_.push_back(errorMsg.str());
435 }
436 } else if (regGuard != NULL) {
437 string regFile = regGuard->registerFile()->name();
438 if (!grdField.hasGPRGuardEncoding(
439 regFile, regGuard->registerIndex(),
440 regGuard->isInverted())) {
441 format errorMsg(
442 "Guard field of move slot %1% does not have encoding "
443 "for %2% GPR guard of register %3% of register file "
444 "%4%.");
445 errorMsg % bus.name();
446 if (regGuard->isInverted()) {
447 errorMsg % "inverted";
448 } else {
449 errorMsg % "non-inverted";
450 }
451 errorMsg % regGuard->registerIndex() % regFile;
452 errorMessages_.push_back(errorMsg.str());
453 }
454 }
455 }
456}
bool hasUnconditionalGuardEncoding(bool inverted) const
bool hasGPRGuardEncoding(const std::string &regFile, int index, bool inverted) const
bool hasFUGuardEncoding(const std::string &fu, const std::string &port, bool inverted) const
GuardField & guardField() const
Definition MoveSlot.cc:215
bool hasGuardField() const
Definition MoveSlot.cc:202
FunctionUnit * parentUnit() const
Definition BaseFUPort.cc:96
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual bool isInverted() const
FUPort * port() const
virtual std::string name() const
Definition Port.cc:141
const RegisterFile * registerFile() const

References bem_, errorMessages_, TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), MoveSlot::guardField(), GuardField::hasFUGuardEncoding(), GuardField::hasGPRGuardEncoding(), MoveSlot::hasGuardField(), GuardField::hasUnconditionalGuardEncoding(), TTAMachine::Guard::isInverted(), BinaryEncoding::moveSlot(), TTAMachine::Component::name(), TTAMachine::Port::name(), TTAMachine::BaseFUPort::parentUnit(), TTAMachine::PortGuard::port(), TTAMachine::RegisterGuard::registerFile(), and TTAMachine::RegisterGuard::registerIndex().

Referenced by checkMoveSlot().

Here is the call graph for this function:

◆ checkImemMauWidth()

void BEMValidator::checkImemMauWidth ( TTAMachine::ControlUnit gcu)
private

Checks that the instruction memory width (MAU) is greater or equal than the width of one instruction.

Parameters
gcuGlobal Control Unit of the machine

Definition at line 691 of file BEMValidator.cc.

691 {
692 int imemWidth = 0;
693 if (gcu.hasAddressSpace()) {
694 imemWidth = gcu.addressSpace()->width();
695 } else {
696 string errorMsg("GCU does not have an address space");
697 errorMessages_.push_back(errorMsg);
698 }
699 int instructionWidth = bem_.width();
700
701 if (imemWidth < instructionWidth) {
702 string warningMsg(
703 "Warning: Instruction width is greater than the instruction "
704 "memory width.");
705 warningMessages_.push_back(warningMsg);
706 }
707}
StringVector warningMessages_
Contains the warning messages.
virtual int width(const TCEString &templateName) const
virtual int width() const
virtual AddressSpace * addressSpace() const
virtual bool hasAddressSpace() const

References TTAMachine::FunctionUnit::addressSpace(), bem_, errorMessages_, TTAMachine::FunctionUnit::hasAddressSpace(), warningMessages_, TTAMachine::AddressSpace::width(), and BinaryEncoding::width().

Here is the call graph for this function:

◆ checkImmediateControlField()

void BEMValidator::checkImmediateControlField ( )
private

Checks that the BEM contains a valid immediate control field.

If errors are found, inserts the error messages to the vector of error messages.

Definition at line 596 of file BEMValidator.cc.

596 {
599 if (iTempNav.count() > 1) {
601 string errorMsg("BEM does not contain immediate control field.");
602 errorMessages_.push_back(errorMsg);
603 } else {
605 for (int i = 0; i < iTempNav.count(); i++) {
606 InstructionTemplate* iTemp = iTempNav.item(i);
607 if (!field.hasTemplateEncoding(iTemp->name())) {
608 format errorMsg(
609 "Immediate control field does not have encoding "
610 "for instruction template %1%.");
611 errorMsg % iTemp->name();
612 errorMessages_.push_back(errorMsg.str());
613 }
614 }
615 }
616 }
617}
ImmediateControlField & immediateControlField() const
bool hasImmediateControlField() const
bool hasTemplateEncoding(const std::string &name) const
ComponentType * item(int index) const
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428

References bem_, TTAMachine::Machine::Navigator< ComponentType >::count(), errorMessages_, BinaryEncoding::hasImmediateControlField(), ImmediateControlField::hasTemplateEncoding(), BinaryEncoding::immediateControlField(), TTAMachine::Machine::instructionTemplateNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, and TTAMachine::Component::name().

Referenced by validate().

Here is the call graph for this function:

◆ checkImmediateSlot()

void BEMValidator::checkImmediateSlot ( const TTAMachine::ImmediateSlot immSlot)
private

Checks that the BEM contains a valid immediate slot field for the given immediate slot.

If errors are found, inserts the error messages to the vector of error messages.

Parameters
immSlotThe immediate slot.

Definition at line 568 of file BEMValidator.cc.

568 {
569
570 if (immSlot.width() == 0) {
571 return;
572 }
573
574 if (!bem_.hasImmediateSlot(immSlot.name())) {
575 format errorMsg(
576 "BEM does not contain field for immediate slot %1%.");
577 errorMsg % immSlot.name();
578 errorMessages_.push_back(errorMsg.str());
579 } else {
580 ImmediateSlotField& field = bem_.immediateSlot(immSlot.name());
581 if (field.width() < immSlot.width()) {
582 format errorMsg("Immediate slot %1% is too narrow in BEM.");
583 errorMessages_.push_back(errorMsg.str());
584 }
585 }
586}
bool hasImmediateSlot(const std::string &name) const
ImmediateSlotField & immediateSlot(int index) const
virtual int width() const

References bem_, errorMessages_, BinaryEncoding::hasImmediateSlot(), BinaryEncoding::immediateSlot(), TTAMachine::Component::name(), ImmediateSlotField::width(), and TTAMachine::ImmediateSlot::width().

Referenced by validate().

Here is the call graph for this function:

◆ checkLImmDstRegisterFields()

void BEMValidator::checkLImmDstRegisterFields ( )
private

Checks that the BEM contains valid long immediate destination register fields.

If errors are found, inserts the error messages to the vector of error messages.

Definition at line 628 of file BEMValidator.cc.

628 {
629
634
635 for (int i = 0; i < itNav.count(); i++) {
636
637 InstructionTemplate* iTemp = itNav.item(i);
638 typedef std::set<std::string> StringSet;
639
640 StringSet iTempDestinations;
641 for (int i = 0; i < iuNav.count(); i++) {
642 ImmediateUnit* iu = iuNav.item(i);
643 if (iTemp->isOneOfDestinations(*iu) &&
644 iu->numberOfRegisters() > 1) {
645 iTempDestinations.insert(iu->name());
646 }
647 }
648
649 StringSet destinationsInBEM;
650 for (int i = 0; i < bem_.longImmDstRegisterFieldCount(); i++) {
652 if (field.usedByInstructionTemplate(iTemp->name())) {
653 string dstIU = field.immediateUnit(iTemp->name());
654 destinationsInBEM.insert(dstIU);
655 if (AssocTools::containsKey(iTempDestinations, dstIU)) {
656 ImmediateUnit* iu = iuNav.item(dstIU);
657 int regIndexWidth = MathTools::bitLength(
658 iu->numberOfRegisters() - 1);
659 if (field.width() < regIndexWidth) {
660 format errorMsg(
661 "Long immediate destination register field is "
662 "too narrow for destination %1% in instruction "
663 "template %2%.");
664 errorMsg % dstIU % iTemp->name();
665 errorMessages_.push_back(errorMsg.str());
666 }
667 }
668 }
669 }
670
671 StringSet intersection;
673 iTempDestinations, destinationsInBEM, intersection);
674 if (intersection.size() < iTempDestinations.size()) {
675 format errorMsg(
676 "Long immediate destination register fields do not "
677 "cover all the destinations of instruction template %1%.");
678 errorMsg % iTemp->name();
679 errorMessages_.push_back(errorMsg.str());
680 }
681 }
682}
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
LImmDstRegisterField & longImmDstRegisterField(int index) const
int longImmDstRegisterFieldCount() const
bool usedByInstructionTemplate(const std::string &instructionTemplate) const
virtual int width() const
std::string immediateUnit(const std::string &instructionTemplate) const
static unsigned int bitLength(long unsigned int number)
static void intersection(const std::set< ValueType > &firstContainer, const std::set< ValueType > &secondContainer, std::set< ValueType > &intersection)
virtual int numberOfRegisters() const
virtual bool isOneOfDestinations(const ImmediateUnit &dstUnit) const
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416

References bem_, MathTools::bitLength(), AssocTools::containsKey(), TTAMachine::Machine::Navigator< ComponentType >::count(), errorMessages_, LImmDstRegisterField::immediateUnit(), TTAMachine::Machine::immediateUnitNavigator(), TTAMachine::Machine::instructionTemplateNavigator(), SetTools::intersection(), TTAMachine::InstructionTemplate::isOneOfDestinations(), TTAMachine::Machine::Navigator< ComponentType >::item(), BinaryEncoding::longImmDstRegisterField(), BinaryEncoding::longImmDstRegisterFieldCount(), machine_, TTAMachine::Component::name(), TTAMachine::BaseRegisterFile::numberOfRegisters(), LImmDstRegisterField::usedByInstructionTemplate(), and LImmDstRegisterField::width().

Referenced by validate().

Here is the call graph for this function:

◆ checkMoveSlot()

void BEMValidator::checkMoveSlot ( const TTAMachine::Bus bus)
private

Checks that the move slot for the given bus is valid in BEM.

If errors are found, error messages are inserted to the vector of error messages.

Parameters
busThe bus.

Definition at line 204 of file BEMValidator.cc.

204 {
205
206 if (!bem_.hasMoveSlot(bus.name())) {
207 format errorMsg("BEM does not contain move slot for bus %1%.");
208 errorMsg % bus.name();
209 errorMessages_.push_back(errorMsg.str());
210 return;
211 }
212
213 checkSourceField(bus);
215 checkGuardField(bus);
216}
void checkDestinationField(const TTAMachine::Bus &bus)
void checkSourceField(const TTAMachine::Bus &bus)
void checkGuardField(const TTAMachine::Bus &bus)
bool hasMoveSlot(const std::string &name) const

References bem_, checkDestinationField(), checkGuardField(), checkSourceField(), errorMessages_, BinaryEncoding::hasMoveSlot(), and TTAMachine::Component::name().

Referenced by validate().

Here is the call graph for this function:

◆ checkSocketCodeTable()

void BEMValidator::checkSocketCodeTable ( const SocketEncoding socketEnc)
private

Checks that the socket code table of the given socket encoding is valid.

If errors are found, inserts the error messages to the vector of error messages.

Parameters
socketEncThe socket encoding.

Definition at line 468 of file BEMValidator.cc.

468 {
469
470 SlotField* slotField = socketEnc.parent();
471 bool srcField = (dynamic_cast<SourceField*>(slotField) != NULL);
472 string busName = slotField->parent()->name();
473 string socketName = socketEnc.socketName();
474
475 assert(socketEnc.hasSocketCodes());
476 SocketCodeTable& table = socketEnc.socketCodes();
478 assert(socketNav.hasItem(socketName));
479 Socket* socket = socketNav.item(socketName);
480
481 for (int i = 0; i < socket->portCount(); i++) {
482 Port* port = socket->port(i);
483 Unit* parentUnit = port->parentUnit();
484 FunctionUnit* fu = dynamic_cast<FunctionUnit*>(parentUnit);
485 RegisterFile* rf = dynamic_cast<RegisterFile*>(parentUnit);
486 ImmediateUnit* iu = dynamic_cast<ImmediateUnit*>(parentUnit);
487
488 if (fu != NULL) {
489 BaseFUPort* fuPort = dynamic_cast<BaseFUPort*>(port);
490 assert(fuPort != NULL);
491 if (fuPort->isOpcodeSetting()) {
492 for (int i = 0; i < fu->operationCount(); i++) {
493 HWOperation* operation = fu->operation(i);
494 if (!table.hasFUPortCode(
495 fu->name(), port->name(), operation->name())) {
496 format errorMsg(
497 "Socket code table of socket %1% in %2% field "
498 "of move slot %3% does not contain FU port code "
499 "for operation %4% for port %5% of FU %6%.");
500 errorMsg % socketEnc.socketName();
501 if (srcField) {
502 errorMsg % "source";
503 } else {
504 errorMsg % "destination";
505 }
506 errorMsg % busName % operation->name() %
507 port->name() % fu->name();
508 errorMessages_.push_back(errorMsg.str());
509 }
510 }
511 } else {
512 if (!table.hasFUPortCode(fu->name(), port->name())) {
513 format errorMsg(
514 "Socket code table of socket %1% in %2% field of "
515 "move slot %3% does not contain FU port code for "
516 "port %4% of FU %5%.");
517 errorMsg % socketEnc.socketName();
518 if (srcField) {
519 errorMsg % "source";
520 } else {
521 errorMsg % "destination";
522 }
523 errorMsg % busName % port->name() % fu->name();
524 errorMessages_.push_back(errorMsg.str());
525 }
526 }
527
528 } else if (rf != NULL && iu == NULL
529 && !table.hasRFPortCode(rf->name())) {
530 format errorMsg(
531 "Socket code table of socket %1% in %2% field of move "
532 "slot %3% does not contain RF port code for RF %4%.");
533 errorMsg % socketName;
534 if (srcField) {
535 errorMsg % "source";
536 } else {
537 errorMsg % "destination";
538 }
539 errorMsg % busName % rf->name();
540 errorMessages_.push_back(errorMsg.str());
541 } else if (iu != NULL && !table.hasIUPortCode(iu->name())) {
542 format errorMsg(
543 "Socket code table of socket %1% in %2% field of move slot "
544 "%3% does not contain IU port code for IU %4%.");
545 errorMsg % socketName;
546 if (srcField) {
547 errorMsg % "source";
548 } else {
549 errorMsg % "destination";
550 }
551 errorMsg % busName % iu->name();
552 errorMessages_.push_back(errorMsg.str());
553 }
554 }
555}
#define assert(condition)
std::string name() const
Definition MoveSlot.cc:136
MoveSlot * parent() const
Definition SlotField.cc:98
bool hasRFPortCode(const std::string &regFile) const
bool hasIUPortCode(const std::string &immediateUnit) const
bool hasFUPortCode(const std::string &fu, const std::string &port) const
SocketCodeTable & socketCodes() const
std::string socketName() const
SlotField * parent() const
virtual bool isOpcodeSetting() const =0
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
const std::string & name() const
bool hasItem(const std::string &name) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
Unit * parentUnit() const
Port * port(int index) const
Definition Socket.cc:266

References assert, errorMessages_, SocketCodeTable::hasFUPortCode(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), SocketCodeTable::hasIUPortCode(), SocketCodeTable::hasRFPortCode(), SocketEncoding::hasSocketCodes(), TTAMachine::BaseFUPort::isOpcodeSetting(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, MoveSlot::name(), TTAMachine::HWOperation::name(), TTAMachine::Component::name(), TTAMachine::Port::name(), TTAMachine::FunctionUnit::operation(), TTAMachine::FunctionUnit::operationCount(), SlotField::parent(), SocketEncoding::parent(), TTAMachine::Port::parentUnit(), TTAMachine::Socket::port(), TTAMachine::Socket::portCount(), SocketEncoding::socketCodes(), SocketEncoding::socketName(), and TTAMachine::Machine::socketNavigator().

Referenced by checkDestinationField(), and checkSourceField().

Here is the call graph for this function:

◆ checkSourceField()

void BEMValidator::checkSourceField ( const TTAMachine::Bus bus)
private

Checks the source field of the given bus for errors.

If errors are found, inserts the error messages to the vector of error messages.

Definition at line 226 of file BEMValidator.cc.

226 {
227
228 MoveSlot& moveSlot = bem_.moveSlot(bus.name());
229
230 // collect the output sockets to a set
231 typedef std::set<Socket*> SocketSet;
232 SocketSet outputSockets;
233
234 for (int i = 0; i < bus.segmentCount(); i++) {
235 Segment* segment = bus.segment(i);
236 for (int i = 0; i < segment->connectionCount(); i++) {
237 Socket* socket = segment->connection(i);
238 if (socket->portCount() > 0 &&
239 socket->direction() == Socket::OUTPUT) {
240 outputSockets.insert(socket);
241 }
242 }
243 }
244
245 if (needsSourceField(moveSlot)) {
246 if (!moveSlot.hasSourceField()) {
247 format errorMsg(
248 "Move slot of bus %1% does not contain source field.");
249 errorMsg % bus.name();
250 errorMessages_.push_back(errorMsg.str());
251 } else {
252 // check the source field for socket encodings
253 SourceField& srcField = moveSlot.sourceField();
254 for (SocketSet::const_iterator iter = outputSockets.begin();
255 iter != outputSockets.end(); iter++) {
256 Socket* socket = *iter;
257 if (!srcField.hasSocketEncoding(socket->name())) {
258 format errorMsg(
259 "Source field of move slot of bus %1% does not"
260 "have an encoding for socket %2%.");
261 errorMsg % bus.name() % socket->name();
262 errorMessages_.push_back(errorMsg.str());
263 } else {
264 SocketEncoding& socketEnc = srcField.socketEncoding(
265 socket->name());
266 if (needsSocketCodeTable(socketEnc)) {
267 if (!socketEnc.hasSocketCodes()) {
268 format errorMsg(
269 "Encoding of socket %1% in source "
270 "field of move slot %2% does not refer to "
271 "any socket code table.");
272 errorMsg % socket->name() % bus.name();
273 errorMessages_.push_back(errorMsg.str());
274 } else {
275 checkSocketCodeTable(socketEnc);
276 }
277 }
278 }
279 }
280
281 // check the source field for bridge encodings
283 for (int i = 0; i < bridgeNav.count(); i++) {
284 Bridge* bridge = bridgeNav.item(i);
285 if (bridge->destinationBus() == &bus &&
286 !moveSlot.sourceField().hasBridgeEncoding(
287 bridge->name())) {
288 format errorMsg(
289 "Source field of bus %1% does not have encoding "
290 "for bridge %2%.");
291 errorMsg % bus.name() % bridge->name();
292 errorMessages_.push_back(errorMsg.str());
293 }
294 }
295
296 // check the source field for immediate encoding
297 if (bus.immediateWidth() > 0 &&
298 !srcField.hasImmediateEncoding()) {
299 format errorMsg(
300 "Source field of bus %1% does not have an immediate "
301 "encoding.");
302 errorMsg % bus.name();
303 errorMessages_.push_back(errorMsg.str());
304 }
305 }
306 }
307}
bool needsSourceField(const MoveSlot &slot) const
SourceField & sourceField() const
Definition MoveSlot.cc:277
bool hasSourceField() const
Definition MoveSlot.cc:264
bool hasBridgeEncoding(const std::string &bridge) const
bool hasImmediateEncoding() const
Bus * destinationBus() const
int immediateWidth() const
Definition Bus.cc:160
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404
@ OUTPUT
Data goes from port to bus.
Definition Socket.hh:60

References bem_, TTAMachine::Machine::bridgeNavigator(), checkSocketCodeTable(), TTAMachine::Segment::connection(), TTAMachine::Segment::connectionCount(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Bridge::destinationBus(), TTAMachine::Socket::direction(), errorMessages_, SourceField::hasBridgeEncoding(), SourceField::hasImmediateEncoding(), SocketEncoding::hasSocketCodes(), SlotField::hasSocketEncoding(), MoveSlot::hasSourceField(), TTAMachine::Bus::immediateWidth(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, BinaryEncoding::moveSlot(), TTAMachine::Component::name(), needsSocketCodeTable(), needsSourceField(), TTAMachine::Socket::OUTPUT, TTAMachine::Socket::portCount(), TTAMachine::Bus::segment(), TTAMachine::Bus::segmentCount(), SlotField::socketEncoding(), and MoveSlot::sourceField().

Referenced by checkMoveSlot().

Here is the call graph for this function:

◆ errorCount()

int BEMValidator::errorCount ( ) const

Returns the number of errors found.

Returns
The number of errors.

Definition at line 145 of file BEMValidator.cc.

145 {
146 return errorMessages_.size();
147}

References errorMessages_.

Referenced by errorMessage(), ProGe::ProGeUI::generateProcessor(), and validate().

◆ errorMessage()

std::string BEMValidator::errorMessage ( int  index) const

Returns an error message by the given index.

Parameters
indexThe index.
Returns
The error message by the given index.
Exceptions
OutOfRangeIf the given index is negative or not smaller than the number of errors.

Definition at line 159 of file BEMValidator.cc.

159 {
160 if (index < 0 || index >= errorCount()) {
161 throw OutOfRange(__FILE__, __LINE__, __func__);
162 } else {
163 return errorMessages_[index];
164 }
165}
#define __func__
int errorCount() const

References __func__, errorCount(), and errorMessages_.

Referenced by ProGe::ProGeUI::generateProcessor().

Here is the call graph for this function:

◆ needsSocketCodeTable()

bool BEMValidator::needsSocketCodeTable ( const SocketEncoding socketEnc) const
private

Tells whether the given socket encoding needs a socket code table.

Parameters
socketEncThe socket encoding.
Returns
True if the socket encoding needs a socket code table, otherwise false.

Definition at line 767 of file BEMValidator.cc.

767 {
768
769 string socketName = socketEnc.socketName();
771 assert(socketNav.hasItem(socketName));
772 Socket* socket = socketNav.item(socketName);
773
774 if (socket->portCount() > 1) {
775 return true;
776 } else if (socket->portCount() == 0) {
777 return false;
778 }
779
780 Port* port = socket->port(0);
781 Unit* unit = port->parentUnit();
782 BaseRegisterFile* rf = dynamic_cast<BaseRegisterFile*>(unit);
783 if (rf != NULL && rf->numberOfRegisters() > 1) {
784 return true;
785 }
786
787 FunctionUnit* fu = dynamic_cast<FunctionUnit*>(unit);
788 if (fu != NULL) {
789 BaseFUPort* fuPort = dynamic_cast<BaseFUPort*>(port);
790 assert(fuPort != NULL);
791 if (fuPort->isOpcodeSetting() && fu->operationCount() > 1) {
792 return true;
793 }
794 }
795
796 return false;
797}

References assert, TTAMachine::Machine::Navigator< ComponentType >::hasItem(), TTAMachine::BaseFUPort::isOpcodeSetting(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, TTAMachine::BaseRegisterFile::numberOfRegisters(), TTAMachine::FunctionUnit::operationCount(), TTAMachine::Port::parentUnit(), TTAMachine::Socket::port(), TTAMachine::Socket::portCount(), SocketEncoding::socketName(), and TTAMachine::Machine::socketNavigator().

Referenced by checkDestinationField(), and checkSourceField().

Here is the call graph for this function:

◆ needsSourceField()

bool BEMValidator::needsSourceField ( const MoveSlot slot) const
private

Tells whether the given move slot needs source field.

Parameters
slotThe move slot.
Returns
True if the move slot needs source field, otherwise false.

Definition at line 716 of file BEMValidator.cc.

716 {
717
718 string busName = slot.name();
720 assert(busNav.hasItem(busName));
721 Bus* bus = busNav.item(busName);
722
723 // check output sockets
724 for (int i = 0; i < bus->segmentCount(); i++) {
725 Segment* segment = bus->segment(i);
726 for (int i = 0; i < segment->connectionCount(); i++) {
727 Socket* socket = segment->connection(i);
728 if (socket->portCount() > 0 &&
729 socket->direction() == Socket::OUTPUT) {
730 return true;
731 }
732 }
733 }
734
735 // check bridges
736 if (bus->hasNextBus()) {
737 Bus* nextBus = bus->nextBus();
738 if (bus->canRead(*nextBus)) {
739 return true;
740 }
741 }
742
743 if (bus->hasPreviousBus()) {
744 Bus* prevBus = bus->previousBus();
745 if (bus->canRead(*prevBus)) {
746 return true;
747 }
748 }
749
750 // check immediate
751 if (bus->immediateWidth() > 0) {
752 return true;
753 }
754
755 return false;
756}
virtual Bus * previousBus() const
Definition Bus.cc:518
virtual bool hasPreviousBus() const
Definition Bus.cc:473
virtual bool hasNextBus() const
Definition Bus.cc:488
virtual Bus * nextBus() const
Definition Bus.cc:501
virtual bool canRead(const Bus &bus) const
Definition Bus.cc:537
virtual BusNavigator busNavigator() const
Definition Machine.cc:356

References assert, TTAMachine::Machine::busNavigator(), TTAMachine::Bus::canRead(), TTAMachine::Segment::connection(), TTAMachine::Segment::connectionCount(), TTAMachine::Socket::direction(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), TTAMachine::Bus::hasNextBus(), TTAMachine::Bus::hasPreviousBus(), TTAMachine::Bus::immediateWidth(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, MoveSlot::name(), TTAMachine::Bus::nextBus(), TTAMachine::Socket::OUTPUT, TTAMachine::Socket::portCount(), TTAMachine::Bus::previousBus(), TTAMachine::Bus::segment(), and TTAMachine::Bus::segmentCount().

Referenced by checkSourceField().

Here is the call graph for this function:

◆ validate()

bool BEMValidator::validate ( )

Validates the binary encoding map against the machine.

Updates the error and warning messages that can be queried with {error,warning}Count and {error,warning}Message methods.

Returns
True if the BEM is valid for the machine, otherwise false.

Definition at line 95 of file BEMValidator.cc.

95 {
96
97 errorMessages_.clear();
98
99 // check move slots for each bus
101 for (int i = 0; i < busNav.count(); i++) {
102 Bus* bus = busNav.item(i);
103 checkMoveSlot(*bus);
104 }
105
106 // check immediate slots
109 for (int i = 0; i < immSlotNav.count(); i++) {
110 ImmediateSlot* immSlot = immSlotNav.item(i);
111 checkImmediateSlot(*immSlot);
112 }
113
114 // check immediate control field
116
117 // check long immediate destination register fields
119
121 if (gcu == NULL) {
122 string errorMsg("Error: Couldn't find GCU from machine");
123 errorMessages_.push_back(errorMsg);
124 } else {
125 // no reason to check this as we are generating the
126 // instruction memory width according to the instruction
127 // width always (instruction indexed imem assumed)
128 // checkImemMauWidth(*gcu);
129 }
130
131 if (errorCount() == 0) {
132 return true;
133 } else {
134 return false;
135 }
136}
void checkMoveSlot(const TTAMachine::Bus &bus)
void checkImmediateSlot(const TTAMachine::ImmediateSlot &immSlot)
void checkLImmDstRegisterFields()
void checkImmediateControlField()
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345

References TTAMachine::Machine::busNavigator(), checkImmediateControlField(), checkImmediateSlot(), checkLImmDstRegisterFields(), checkMoveSlot(), TTAMachine::Machine::controlUnit(), TTAMachine::Machine::Navigator< ComponentType >::count(), errorCount(), errorMessages_, TTAMachine::Machine::immediateSlotNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), and machine_.

Referenced by ProGe::ProGeUI::generateProcessor().

Here is the call graph for this function:

◆ warningCount()

int BEMValidator::warningCount ( ) const

Returns the number of warnings found.

Returns
The number of warnings.

Definition at line 173 of file BEMValidator.cc.

173 {
174 return warningMessages_.size();
175}

References warningMessages_.

Referenced by ProGe::ProGeUI::generateProcessor(), and warningMessage().

◆ warningMessage()

std::string BEMValidator::warningMessage ( int  index) const

Returns an warning message by the given index.

Parameters
indexThe index.
Returns
The warning message by the given index.
Exceptions
OutOfRangeIf the given index is negative or not smaller than the number of errors.

Definition at line 186 of file BEMValidator.cc.

186 {
187
188 if (index < 0 || index >= warningCount()) {
189 throw OutOfRange(__FILE__, __LINE__, __func__);
190 } else {
191 return warningMessages_[index];
192 }
193}
int warningCount() const

References __func__, warningCount(), and warningMessages_.

Referenced by ProGe::ProGeUI::generateProcessor().

Here is the call graph for this function:

Member Data Documentation

◆ bem_

const BinaryEncoding& BEMValidator::bem_
private

◆ errorMessages_

StringVector BEMValidator::errorMessages_
private

◆ machine_

const TTAMachine::Machine& BEMValidator::machine_
private

◆ warningMessages_

StringVector BEMValidator::warningMessages_
private

Contains the warning messages.

Definition at line 95 of file BEMValidator.hh.

Referenced by checkImemMauWidth(), warningCount(), and warningMessage().


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