X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..77e28a24d444098399304f0175b1aba43c83017f:/BlockImplementation.cpp?ds=sidebyside diff --git a/BlockImplementation.cpp b/BlockImplementation.cpp index 571b72b..46c9722 100644 --- a/BlockImplementation.cpp +++ b/BlockImplementation.cpp @@ -5,10 +5,13 @@ #include "ReferenceInterface.h" #include "FunctionalInterface.h" #include "BlockParameter.h" +#include BlockImplementation::BlockImplementation(const QString& _xmlFile) { - xmlFile = _xmlFile; + xmlFile = _xmlFile; + productionCounter = ""; + delta = ""; evaluator = new ArithmeticEvaluator; evaluator->setVariableMarkers("@$"); @@ -16,10 +19,89 @@ BlockImplementation::BlockImplementation(const QString& _xmlFile) { BlockImplementation::BlockImplementation(const QString& _xmlFile, const QString &_referenceXml, const QString &_referenceMd5) { xmlFile = _xmlFile; + productionCounter = ""; + delta = ""; referenceXml = _referenceXml; referenceMd5 = _referenceMd5; } +void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) { + + QDomNodeList patternNode = root.elementsByTagName("patterns"); + + if (patternNode.isEmpty()) { + cout << "impl has no patterns" << endl; + return; + } + + QDomElement patternElt = patternNode.at(0).toElement(); + + QDomElement eltDelta = patternElt.firstChildElement("delta"); + delta = eltDelta.attribute("value","none"); + + QDomElement eltCons = eltDelta.nextSiblingElement("consumption"); + + QDomNodeList listNodeInput = eltCons.elementsByTagName("input"); + for(int i=0; i iterP(productionPattern); + while (iterP.hasNext()) { + iterP.next(); + cout << qPrintable(iterP.key()) << " -> " << qPrintable(iterP.value()) << endl; + } + cout << "impls patterns read correctly" << endl; +} + +bool BlockImplementation::checkPatterns() { + + + if (reference == NULL) { + cout << "no ref. while checking patterns of implementation " << endl; + return false; + } + + AbstractInterface* iface; + QHashIterator iterI(consumptionPattern); + while (iterI.hasNext()) { + iterI.next(); + iface = reference->getIfaceFromName(iterI.key()); + if (iface == NULL) { + cout << "cannot found an input ref. iface for impl. iface " << qPrintable(iterI.key()) << endl; + return false; + } + } + QHashIterator iterO(productionPattern); + while (iterO.hasNext()) { + iterO.next(); + iface = reference->getIfaceFromName(iterO.key()); + if (iface == NULL) { + cout << "cannot found an output ref. iface for impl. iface " << qPrintable(iterI.key()) << endl; + return false; + } + } + return true; +} + void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &path) throw(Exception) { block = _block; @@ -45,6 +127,7 @@ void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &p if (reference->isWBConfigurable()) { genController = true; controllerFile = path; + controllerFile += "/"; controllerFile.append(block->getName()); controllerFile.append("_ctrl.vhd"); } @@ -52,6 +135,7 @@ void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &p controllerFile = "nofile.vhd"; } coreFile = path; + coreFile += "/"; coreFile.append(block->getName()); coreFile.append(".vhd"); @@ -103,38 +187,38 @@ void BlockImplementation::generateComments(QDomElement &elt, QString coreFile, Q for(int i = 0; i < 50; i++) { out << "--"; } - out << "\n--\n"; + out << "\n--" << endl; QString fileName = coreFile; - out << "-- File : " << fileName << "\n"; - out << "--\n"; + out << "-- File : " << fileName << endl; + out << "--" << endl; QDomElement eltAuthor = elt.firstChildElement("author"); QString firstName = eltAuthor.attribute("firstname",""); QString lastName = eltAuthor.attribute("lastname",""); QString mail = eltAuthor.attribute("mail",""); - out << "-- Author(s) : "<getName(); + nameEnt = block->getName(); //QList listParams = reference->getParameters(); - QList listInputs = reference->getInputs(); - QList listOutputs = reference->getOutputs(); - QList listBidirs = reference->getBidirs(); + QList listInputs = block->getInputs(); + QList listOutputs = block->getOutputs(); + QList listBidirs = block->getBidirs(); QString typePort, namePort; - out << "entity " << nameEnt << " is\n"; + out << "entity " << nameEnt << " is" << endl; /* TODO : rewrite the generation to take into acocunt the new object hierarchy */ // Generation of the generics - QList listGenerics = reference->getGenericParameters(); + QList listGenerics = block->getGenericParameters(); if ((!listGenerics.isEmpty()) || (hasController)) { out << " generic (" << endl; if (hasController) { @@ -185,9 +269,9 @@ void BlockImplementation::generateEntity(QTextStream& out, bool hasController) t out << endl; } for(i=0;itoVHDL(BlockParameter::Entity, 0); + out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl; } - out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma); + out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl; out << " );" << endl; } @@ -196,9 +280,9 @@ void BlockImplementation::generateEntity(QTextStream& out, bool hasController) t // Generation of the clk & rst signals out << " -- clk/rst" << endl; - for(int i = 0; i < listInputs.size(); i++) { - if(listInputs.at(i)->getPurpose() == AbstractInterface::Clock || listInputs.at(i)->getPurpose() == AbstractInterface::Reset) { - out << " " << listInputs.at(i)->getName() << " : in std_logic;" << endl; + foreach(AbstractInterface* iface, listInputs) { + if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) { + out << " " << iface->getName() << " : in std_logic;" << endl; } } @@ -207,55 +291,98 @@ void BlockImplementation::generateEntity(QTextStream& out, bool hasController) t out << " -- registers r/w via wishbone" << endl; QList listWB = reference->getWishboneParameters(); for(i=0;itoVHDL(BlockParameter::Entity, 0); + out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl; } - out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma); + out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl; } - // Generation of the data signals - out << "-- data ports\n"; - for(int i = 0; i < listInputs.size(); i++) { - namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listInputs.at(i)->getName())); - if(listInputs.at(i)->getWidth().compare("1")) - typePort = "std_logic"; - else - typePort = calculateWidth(listInputs.at(i)->getWidth()); - if(listInputs.at(i)->getPurpose() == 1) - out << namePort << " : in std_logic_vector(" << typePort << " -1 downto 0) ;\n"; + int count = 0; + foreach(AbstractInterface* iface, block->getInterfaces()) { + if((iface->getPurpose() == AbstractInterface::Data)||(iface->getPurpose() == AbstractInterface::Control)) count++; } + // Generation of the data/control signals - for(int i = 0; i < listOutputs.size(); i++) { - namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listOutputs.at(i)->getName())); - if(listOutputs.at(i)->getWidth().compare("1")) - typePort = "std_logic"; - else - typePort = calculateWidth(listOutputs.at(i)->getWidth()); - if(listOutputs.at(i)->getPurpose() == 1) - out << namePort << " : out std_logic_vector(" << typePort << " -1 downto 0) ;\n"; - } + int flag = 0; + bool first = true; - for(int i = 0; i < listBidirs.size(); i++) { - namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listBidirs.at(i)->getName())); - if(listBidirs.at(i)->getWidth().compare(("1"))) - typePort = "std_logic"; - else - typePort = calculateWidth((listBidirs.at(i)->getWidth())); - if(listBidirs.at(i)->getPurpose() == 1) - out << namePort << " : inout std_logic_vector(" << typePort << " -1 downto 0) ;\n"; + foreach(AbstractInterface* iface, listInputs) { + if(iface->getPurpose() == AbstractInterface::Data) { + if (first) { + out << " -- input data ports" << endl; + first = false; + } + count--; + if (count == 0) flag = AbstractInterface::NoComma; + out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl; + } } + first = true; + foreach(AbstractInterface* iface, listInputs) { + if(iface->getPurpose() == AbstractInterface::Control) { + if (first) { + out << " -- input control ports" << endl; + first = false; + } + count--; + if (count == 0) flag = AbstractInterface::NoComma; + out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl; + } + } + first = true; + foreach(AbstractInterface* iface, listOutputs) { + if(iface->getPurpose() == AbstractInterface::Data) { + if (first) { + out << " -- output data ports" << endl; + first = false; + } + count--; + if (count == 0) flag = AbstractInterface::NoComma; + out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl; + } + } + first = true; + foreach(AbstractInterface* iface, listOutputs) { + if(iface->getPurpose() == AbstractInterface::Control) { + if (first) { + out << " -- output control ports" << endl; + first = false; + } + count--; + if (count == 0) flag = AbstractInterface::NoComma; + out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl; + } + } + first = true; + foreach(AbstractInterface* iface, listBidirs) { + if(iface->getPurpose() == AbstractInterface::Data) { + if (first) { + out << " -- bidirs data ports" << endl; + first = false; + } + count--; + if (count == 0) flag = AbstractInterface::NoComma; + out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl; + } + } + out << " );" << endl << endl; + out << "end " << nameEnt << ";" << endl << endl; } // This function generates the architecture part of the VHDL document void BlockImplementation::generateArchitecture(QDomElement &elt, QTextStream& out) throw(Exception) { QString expr; - QDomElement eltArch = elt.nextSiblingElement("architecture"); - out << "architecture " << nameEnt <<"_1 of " << nameEnt << "is\n"; - QString implText = eltArch.text(); - QStringList listLine = implText.split("\n"); + QString code = elt.text(); + cout << qPrintable(code) << endl; + out << "architecture rtl of " << nameEnt << " is" << endl; + + QStringList listLine = code.split("\n"); for(int i =0; i < listLine.size(); i++) { - if(listLine.at(i).contains(QRegularExpression("@foreach{")) != -1) { + QString line = listLine.at(i).simplified(); + + /* + if(listLine.at(i).contains(QRegularExpression("@foreach{"))) { while(listLine.at(i).compare("@endforeach") != -1) { expr = expr + listLine.at(i) + '\n'; i++; @@ -263,7 +390,7 @@ void BlockImplementation::generateArchitecture(QDomElement &elt, QTextStream& ou expr = expr + listLine.at(i); out << evalComplex(expr, 1) << '\n'; } - if(listLine.at(i).contains(QRegularExpression("@caseeach{")) != -1) { + if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) { while(listLine.at(i).compare("@endcaseeach") != -1) { expr = expr + listLine.at(i) + '\n'; i++; @@ -271,11 +398,10 @@ void BlockImplementation::generateArchitecture(QDomElement &elt, QTextStream& ou expr = expr + listLine.at(i); out << evalComplex(expr, 2) << '\n'; } - - if(listLine.at(i).contains('@') == -1) - out << listLine.at(i) << "\n"; - else - out << eval(listLine.at(i), out) << "\n"; +*/ + if(line.contains("@{")) { + out << line << endl; + } } } @@ -503,7 +629,12 @@ QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) { toWrite << impl.xmlFile; toWrite << impl.referenceXml; toWrite << impl.referenceMd5; - + // saving patterns + toWrite << impl.delta; + toWrite << impl.consumptionPattern; + toWrite << impl.productionPattern; + toWrite << impl.productionCounter; + out << blockData; return out; @@ -520,6 +651,11 @@ QDataStream& operator>>(QDataStream &in, BlockImplementation &impl) { in >> impl.xmlFile; in >> impl.referenceXml; in >> impl.referenceMd5; + // loading patterns + in >> impl.delta; + in >> impl.consumptionPattern; + in >> impl.productionPattern; + in >> impl.productionCounter; return in; }