X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/cfe8322b50c9ef08ffbc3e52b0849bca4cd1d0bf..e40a5399ec7887c2606f18575c809b0d05b09278:/AbstractBlock.cpp diff --git a/AbstractBlock.cpp b/AbstractBlock.cpp index c71b2e0..116494e 100644 --- a/AbstractBlock.cpp +++ b/AbstractBlock.cpp @@ -3,16 +3,22 @@ #include #include "AbstractInterface.h" #include "BlockParameter.h" +#include "Parameters.h" +#include "GroupBlock.h" +#include "ConnectedInterface.h" + AbstractBlock::AbstractBlock() { name = ""; parent = NULL; } +/* AbstractBlock::AbstractBlock(const QString& _name) { - name = _name; + name = Parameters::normalizeName(_name); parent = NULL; } +*/ AbstractBlock::~AbstractBlock() { @@ -25,7 +31,7 @@ AbstractBlock::~AbstractBlock() { } void AbstractBlock::setName(const QString& str) { - name = str; + name = Parameters::normalizeName(str); } void AbstractBlock::setParent(AbstractBlock* _parent) { @@ -51,11 +57,14 @@ bool AbstractBlock::isTopGroupBlock() { bool AbstractBlock::isSourceBlock() { return false; } - +/* NB: a generator is a block that has no data inputs + * and has at least one data output. + * By the way, blocks that have no data input/output + * (like clkrstgen) are not generators ! + */ bool AbstractBlock::isGeneratorBlock() { - foreach(AbstractInterface* iface, inputs) { - if (iface->getPurpose() == AbstractInterface::Data) return false; - } + if (getDataInputs().size() > 0) return false; + if (getDataOutputs().size() == 0) return false; return true; } @@ -126,42 +135,58 @@ void AbstractBlock::defineBlockParam(BlockParameter *param) param->setValue(value); } -QList AbstractBlock::getInterfaces() { +QList AbstractBlock::getInterfaces(int direction, int purpose) { QList list; - list.append(inputs); - list.append(outputs); - list.append(bidirs); + bool selIn = false; + bool selOut = false; + bool selInOut = false; + + if (direction == AbstractInterface::AnyDirection) { + selIn = true; + selOut = true; + selInOut = true; + } + else if (direction == AbstractInterface::Input) { + selIn = true; + } + else if (direction == AbstractInterface::Output) { + selOut = true; + } + else if (direction == AbstractInterface::InOut) { + selInOut = true; + } + if (selIn) { + foreach(AbstractInterface* iface, inputs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } + if (selOut) { + foreach(AbstractInterface* iface, outputs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } + if (selInOut) { + foreach(AbstractInterface* iface, bidirs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } return list; } QList AbstractBlock::getDataInputs() { - QList list; - foreach(AbstractInterface* iface, inputs) { - if (iface->getPurpose() == AbstractInterface::Data) { - list.append(iface); - } - } - return list; + return getInterfaces(AbstractInterface::Input, AbstractInterface::Data); +} + +QList AbstractBlock::getDataOutputs() { + return getInterfaces(AbstractInterface::Output, AbstractInterface::Data); } QList AbstractBlock::getControlInputs() { - QList list; - foreach(AbstractInterface* iface, inputs) { - if (iface->getPurpose() == AbstractInterface::Control) { - list.append(iface); - } - } - return list; + return getInterfaces(AbstractInterface::Input, AbstractInterface::Control); } QList AbstractBlock::getControlOutputs() { - QList list; - foreach(AbstractInterface* iface, outputs) { - if (iface->getPurpose() == AbstractInterface::Control) { - list.append(iface); - } - } - return list; + return getInterfaces(AbstractInterface::Output, AbstractInterface::Control); } AbstractInterface* AbstractBlock::getIfaceFromName(QString name) { @@ -217,3 +242,96 @@ QList AbstractBlock::getWishboneParameters() { } return lst; } + +void AbstractBlock::connectClock(QString clkName, int idGen) throw(Exception) { + + GroupBlock* parentBlock = AB_TO_GRP(parent); + ConnectedInterface* fromClk = NULL; + ConnectedInterface* toClk = AI_TO_CON(getIfaceFromName(clkName)); + + if (parentBlock->isTop()) { + QString genName = "clkrstgen_" + QString::number(idGen); + AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName(genName); + if (clkrstgen == NULL) { + throw(Exception(IFACE_TOP_NOCLKRSTGEN,this)); + } + else { + fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk")); + } + cout << "connecting clock for " << qPrintable(name) << " to " << qPrintable(genName) << endl; + } + else { + // searching for ext_clk_idGen + QString name = "ext_clk_"+QString::number(idGen); + fromClk = AI_TO_CON(parentBlock->getIfaceFromName(name)); + cout << "connecting clk for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl; + } + + if (fromClk == NULL) { + throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock)); + } + else { + fromClk->connectTo(toClk); + cout << "connection done between " << qPrintable(toClk->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toClk->getConnectedFrom()->getName()); + cout << " and " << qPrintable(toClk->getOwner()->getName()) << "/" << qPrintable(toClk->getName()) << endl; + } +} + +void AbstractBlock::connectReset(QString rstName, int idGen) throw(Exception) { + + GroupBlock* parentBlock = AB_TO_GRP(parent); + ConnectedInterface* fromRst = NULL; + ConnectedInterface* toRst = AI_TO_CON(getIfaceFromName(rstName)); + + if (parentBlock->isTop()) { + QString genName = "clkrstgen_" + QString::number(idGen); + AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName(genName); + if (clkrstgen == NULL) { + throw(Exception(IFACE_TOP_NOCLKRSTGEN,this)); + } + else { + fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset")); + } + cout << "connecting reset for " << qPrintable(name) << " to " << qPrintable(genName) << endl; + } + else { + QString name = "ext_reset_"+QString::number(idGen); + fromRst = AI_TO_CON(parentBlock->getIfaceFromName(name)); + cout << "connecting reset for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl; + } + + if (fromRst == NULL) { + throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock)); + } + else { + fromRst->connectTo(toRst); + cout << "connection done between " << qPrintable(toRst->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toRst->getConnectedFrom()->getName()); + cout << " and " << qPrintable(toRst->getOwner()->getName()) << "/" << qPrintable(toRst->getName()) << endl; + } +} + +void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) { + + out << "entity " << name << " is" << endl; + try { + generateEntityOrComponentBody(out, 0, hasController); + } + catch(Exception e) { + throw(e); + } + out << "end entity " << name << ";" << endl << endl; +} + +void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) { + + out << " component " << name << " is" << endl; + try { + generateEntityOrComponentBody(out, 2, hasController); + } + catch(Exception e) { + throw(e); + } + out << " end component; " << endl << endl; +} + +