X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..4327c2b8817b627249d98d889835726217c81a4e:/AbstractBlock.cpp?ds=sidebyside diff --git a/AbstractBlock.cpp b/AbstractBlock.cpp index 6e9cc86..218ea61 100644 --- a/AbstractBlock.cpp +++ b/AbstractBlock.cpp @@ -3,31 +3,29 @@ #include #include "AbstractInterface.h" #include "BlockParameter.h" +#include "Parameters.h" +#include "GroupBlock.h" +#include "ConnectedInterface.h" -AbstractBlock::AbstractBlock() { + +AbstractBlock::AbstractBlock(Graph *_graph) { name = ""; parent = NULL; + specialType = NotSpecial; + graph = _graph; } +/* AbstractBlock::AbstractBlock(const QString& _name) { - name = _name; + name = Parameters::normalizeName(_name); parent = NULL; } +*/ AbstractBlock::~AbstractBlock() { - foreach(AbstractInterface* iface, inputs) { - delete iface; - } - foreach(AbstractInterface* iface, outputs) { - delete iface; - } - foreach(AbstractInterface* iface, bidirs) { - delete iface; - } - inputs.clear(); - outputs.clear(); - bidirs.clear(); + removeAllInterfaces(); + foreach(BlockParameter* p, params) { delete p; } @@ -35,7 +33,16 @@ AbstractBlock::~AbstractBlock() { } void AbstractBlock::setName(const QString& str) { - name = str; + name = Parameters::normalizeName(str); +} + +void AbstractBlock::setSpecialType(int type) { + if ((type >= NotSpecial) && (type <= ClkConvert)) { + specialType = type; + } + else { + specialType = NotSpecial; + } } void AbstractBlock::setParent(AbstractBlock* _parent) { @@ -50,10 +57,52 @@ bool AbstractBlock::isFunctionalBlock() { return false; } +bool AbstractBlock::isSpecialBlock() { + return false; +} + bool AbstractBlock::isGroupBlock() { return false; } +bool AbstractBlock::isTopGroupBlock() { + return false; +} + +bool AbstractBlock::isStimuliBlock() { + return false; +} +/* NB: a source 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 sources ! + */ +bool AbstractBlock::isSourceBlock() { + if (getDataInputs().size() > 0) return false; + if (getDataOutputs().size() == 0) return false; + return true; +} + +/* NB: a sink is a block without outputs of any type */ +bool AbstractBlock::isSinkBlock() { + if (getOutputs().size() == 0) return true; + return false; +} + +int AbstractBlock::getSpecialTypeFromString(QString str) { + if (str == "source") { + return Source; + } + else if (str == "sink") { + return Sink; + } + else if (str == "clkconvert") { + return ClkConvert; + } + return NotSpecial; +} + + void AbstractBlock::addParameter(BlockParameter *param) { params.append(param); } @@ -90,6 +139,23 @@ void AbstractBlock::removeInterface(AbstractInterface *inter) { delete inter; } +void AbstractBlock::removeAllInterfaces() { + + foreach(AbstractInterface* iface, inputs) { + delete iface; + } + foreach(AbstractInterface* iface, outputs) { + delete iface; + } + foreach(AbstractInterface* iface, bidirs) { + delete iface; + } + inputs.clear(); + outputs.clear(); + bidirs.clear(); + +} + void AbstractBlock::defineBlockParam(BlockParameter *param) { cout << "definition of param : " << param->getName().toStdString() << endl; @@ -104,14 +170,60 @@ 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() { + return getInterfaces(AbstractInterface::Input, AbstractInterface::Data); +} + +QList AbstractBlock::getDataOutputs() { + return getInterfaces(AbstractInterface::Output, AbstractInterface::Data); +} + +QList AbstractBlock::getControlInputs() { + return getInterfaces(AbstractInterface::Input, AbstractInterface::Control); +} + +QList AbstractBlock::getControlOutputs() { + return getInterfaces(AbstractInterface::Output, AbstractInterface::Control); +} + AbstractInterface* AbstractBlock::getIfaceFromName(QString name) { foreach(AbstractInterface* iface, inputs) { @@ -165,3 +277,29 @@ QList AbstractBlock::getWishboneParameters() { } return lst; } + +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; +} + +