X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/8d3e09e430e829b9d847847334cbfe37790baca3..6ca6321283b9c93a6df9dcd5216bfa01df9ad24b:/BlockImplementation.cpp?ds=inline diff --git a/BlockImplementation.cpp b/BlockImplementation.cpp index af06ef3..365ccb7 100644 --- a/BlockImplementation.cpp +++ b/BlockImplementation.cpp @@ -5,516 +5,109 @@ #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("@$"); + + noPatterns = true; } BlockImplementation::BlockImplementation(const QString& _xmlFile, const QString &_referenceXml, const QString &_referenceMd5) { xmlFile = _xmlFile; + productionCounter = ""; + delta = ""; referenceXml = _referenceXml; referenceMd5 = _referenceMd5; + + noPatterns = true; } -void BlockImplementation::assignPatterns(FunctionalBlock *_block) throw(Exception) { +void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) { + + QDomNodeList patternNode = root.elementsByTagName("patterns"); - block = _block; - - QFile implFile(xmlFile); - - // reading in into QDomDocument - QDomDocument document("implFile"); - - if (!implFile.open(QIODevice::ReadOnly)) { - throw(Exception(IMPLFILE_NOACCESS)); + if (patternNode.isEmpty()) { + cout << "impl has no patterns" << endl; + return; } - if (!document.setContent(&implFile)) { - implFile.close(); - throw(Exception(IMPLFILE_NOACCESS)); - } - implFile.close(); - QDomElement impl = document.documentElement(); - QDomNodeList patternNode = impl.elementsByTagName("patterns"); - if (patternNode.isEmpty()) return; + QDomElement patternElt = patternNode.at(0).toElement(); -} - -void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &path) throw(Exception) { - - block = _block; - - QFile implFile(xmlFile); - - // reading in into QDomDocument - QDomDocument document("implFile"); - - if (!implFile.open(QIODevice::ReadOnly)) { - throw(Exception(IMPLFILE_NOACCESS)); - } - if (!document.setContent(&implFile)) { - implFile.close(); - throw(Exception(IMPLFILE_NOACCESS)); - } - implFile.close(); - - bool genController = false; - QString coreFile = ""; - QString controllerFile = ""; - - if (reference->isWBConfigurable()) { - genController = true; - controllerFile = path; - controllerFile.append(block->getName()); - controllerFile.append("_ctrl.vhd"); - } - else { - controllerFile = "nofile.vhd"; - } - coreFile = path; - coreFile.append(block->getName()); - coreFile.append(".vhd"); - - QFile vhdlCore(coreFile); - QFile vhdlController(controllerFile); - - if (!vhdlCore.open(QIODevice::WriteOnly)) { - throw(Exception(VHDLFILE_NOACCESS)); - } - - if (genController) { - if (!vhdlController.open(QIODevice::WriteOnly)) { - throw(Exception(VHDLFILE_NOACCESS)); - } - } - QTextStream outCore(&vhdlCore); - QTextStream outController; - if (genController) { - outController.setDevice(&vhdlController); - } - - try { - - - //Get the root element - QDomElement impl = document.documentElement(); - QDomElement eltComments = impl.firstChildElement("comments"); - generateComments(eltComments, coreFile, outCore); - QDomElement eltLibs = eltComments.nextSiblingElement("libraries"); - generateLibraries(eltLibs, outCore); - generateEntity(outCore, genController); - QDomElement eltArch = eltLibs.nextSiblingElement("architecture"); - generateArchitecture(eltArch, outCore); - if (genController) { - generateController(outController); - } - } - catch(Exception err) { - throw(err); - } - - vhdlCore.close(); - vhdlController.close(); -} - -// This function generates the comments part of the VHDL document -void BlockImplementation::generateComments(QDomElement &elt, QString coreFile, QTextStream& out) throw(Exception) { - - for(int i = 0; i < 50; i++) { - out << "--"; - } - out << "\n--\n"; - QString fileName = coreFile; - out << "-- File : " << fileName << "\n"; - out << "--\n"; - QDomElement eltAuthor = elt.firstChildElement("author"); - QString firstName = eltAuthor.attribute("firstname",""); - QString lastName = eltAuthor.attribute("lastname",""); - QString mail = eltAuthor.attribute("mail",""); - out << "-- Author(s) : "<getName(); - //QList listParams = reference->getParameters(); - QList listInputs = reference->getInputs(); - QList listOutputs = reference->getOutputs(); - QList listBidirs = reference->getBidirs(); - QString typePort, namePort; - - out << "entity " << nameEnt << " is\n"; - - - /* TODO : rewrite the generation to take into acocunt the new object hierarchy */ - - // Generation of the generics - QList listGenerics = reference->getGenericParameters(); - if ((!listGenerics.isEmpty()) || (hasController)) { - out << " generic (" << endl; - if (hasController) { - out << " wb_data_width : integer = 16;" << endl; - out << " wb_addr_width : integer = 12"; - if (!listGenerics.isEmpty()) out << ";"; - out << endl; - } - for(i=0;itoVHDL(BlockParameter::Entity, 0); - } - out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma); - - out << " );" << endl; - } - - out << " port (" << endl; - - // 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; - } - } - - if (hasController) { - // Generation of the wishbone signals - 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,BlockParameter::NoComma); - } + QDomElement eltDelta = patternElt.firstChildElement("delta"); + delta = eltDelta.attribute("value","none"); + if (delta == "none") throw(Exception(IMPLFILE_CORRUPTED)); - - // 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"; - } - - 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"; - } - - 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"; - } -} - -// 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"); - for(int i =0; i < listLine.size(); i++) { - if(listLine.at(i).contains(QRegularExpression("@foreach{")) != -1) { - while(listLine.at(i).compare("@endforeach") != -1) { - expr = expr + listLine.at(i) + '\n'; - i++; - } - expr = expr + listLine.at(i); - out << evalComplex(expr, 1) << '\n'; - } - if(listLine.at(i).contains(QRegularExpression("@caseeach{")) != -1) { - while(listLine.at(i).compare("@endcaseeach") != -1) { - expr = expr + listLine.at(i) + '\n'; - i++; - } - 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"; - } -} - -void BlockImplementation::generateController(QTextStream &out) throw(Exception) { -} - -QString BlockImplementation::eval(QString line, QTextStream& out) { - QString res, s, begLine, endLine, expr; - evaluator->setExpression(line); - QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)"); - QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)"); - QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*"); - - int nbAt = line.count('@'); - while(nbAt != 0) { - for(int i = 0; i < line.size(); i++) { - if(rxString->indexIn(line)) { - begLine = rxString->cap(1); - s = rxString->cap(2); - endLine = rxString->cap(3); - res = begLine + evalString(s) + endLine + '\n'; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxValue->indexIn(line)) { - begLine = rxValue->cap(1); - s = rxValue->cap(2); - endLine = rxValue->cap(3); - res = begLine + evalValue(s) + endLine + '\n'; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxExpr->indexIn(line)) { - expr = rxExpr->cap(1); - if(expr.count('@') == 0) { - evaluator->setExpression(expr); - s = QString::number(evaluator->evaluate()); - } - res = begLine + s + endLine + '\n'; - nbAt --; - } - } - } - return res; -} - -QString BlockImplementation::evalComplex(QString line, int id) { - QString res, s, begLine, endLine, expr; - QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)"); - QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)"); - QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*"); - QRegExp *rxFor = new QRegExp("@foreach{.*}(@{.*})(.*)@endforeach"); - QRegExp *rxCase = new QRegExp("@caseeach{.*,(.*),(.*)}(@{.*})(.*)@endcaseeach"); - QRegExp *rxCaseDown = new QRegExp("@#-:(.*)"); - QRegExp *rxCaseUp = new QRegExp("@#:(.*)"); - evaluator->setExpression(line); - - int nbAt = line.count('@') - 2; - while(nbAt != 0) { - for(int i = 0; i < line.size(); i++) { - if(rxString->indexIn(line)) { - begLine = rxString->cap(1); - s = rxString->cap(2); - endLine = rxString->cap(3); - if(evalStringComplex(s)->size() == 0) - line = begLine + evalString(s) + endLine; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxValue->indexIn(line)) { - begLine = rxValue->cap(1); - s = rxValue->cap(2); - endLine = rxValue->cap(3); - line = begLine + evalValue(s) + endLine; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxExpr->indexIn(line)) { - expr = rxExpr->cap(1); - if(expr.count('@') == 0) { - evaluator->setExpression(expr); - s = QString::number(evaluator->evaluate()); - } - res = begLine + s + endLine + '\n'; - nbAt --; - } - } - } - - if(id == 1) { - if(rxFor->indexIn(line)) { - QString intName, instruc; - intName = rxFor->cap(1); - instruc = rxFor->cap(2); - QList *intList = evalStringComplex(intName); - if(intList->size() != 0) { - for(int i = 0; i < intList->size(); i++) { - res = intList->at(i)->getName() + instruc + '\n'; - } - } - } + QDomElement eltCons = eltDelta.nextSiblingElement("consumption"); + + QDomNodeList listNodeInput = eltCons.elementsByTagName("input"); + for(int i=0; iindexIn(line)) { - QString intName, sigName, cases, instruc; - int number; - sigName = rxCase->cap(1); - cases = rxCase->cap(2); - intName = rxCase->cap(3); - instruc = rxCase->cap(4); - QList *intList = evalStringComplex(intName); - int listSize = intList->count(); - res = "case " + sigName + " is\n"; - if(rxCaseUp->indexIn(cases)) { - number = rxCaseUp->cap(1).toInt(); - for(int j = number; j < listSize; j++) { - if(listSize > 0) { - for(int i = 0; i < listSize; i++) { - res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n"; - } - } - else - res += "\twhen " + number + ' ' + intName + instruc + "\n"; - number++; - } - } - if(rxCaseDown->indexIn(cases)) { - number = rxCaseDown->cap(1).toInt(); - for(int j = number; j < listSize; j++) { - if(listSize > 0) { - for(int i = 0; i < listSize; i++) { - res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n"; - } - } - else - res += "\twhen " + number + ' ' + intName + instruc + "\n"; - number--; - } - res += "end case ;\n"; - } - } + + QDomElement eltProd = eltCons.nextSiblingElement("production"); + + productionCounter = eltProd.attribute("counter","none"); + QDomNodeList listNodeOutput = eltProd.elementsByTagName("output"); + for(int i=0; iAbstractBlock::getIfaceFromName(s)); - return name; -} - -QList* BlockImplementation::evalStringComplex(QString s) { - - int j = 0; - QList *listInterfaces = new QList(); - AbstractInterface *inter = block->AbstractBlock::getIfaceFromName(s); - QList listIntBlock = block->getInterfaces(); - for(int i = 0; i < listIntBlock.size(); i++) { - if(inter->getName().compare(listIntBlock.at(i)->getName()) < -1) { - listInterfaces->insert(j, inter); - j ++; - } + cout << "patterns summary:" << endl; + QHashIterator iterP(productionPattern); + while (iterP.hasNext()) { + iterP.next(); + cout << qPrintable(iterP.key()) << " -> " << qPrintable(iterP.value()) << endl; } - return listInterfaces; -} - -QString BlockImplementation::evalValue(QString s) { - - QString val = ""; - if(paramMap.contains(s)) - val = paramMap.value(s); - return val; + cout << "impls patterns read correctly" << endl; + noPatterns = false; } -QString BlockImplementation::getIfaceUserName(AbstractInterface* refIface) { +bool BlockImplementation::checkPatterns() { - if (! refIface->isReferenceInterface()) return ""; - AbstractInterface* funcIface = NULL; - - if (refIface->getDirection() == AbstractInterface::Input) { - foreach(AbstractInterface* iface, block->getInputs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } - } + if (reference == NULL) { + cout << "no ref. while checking patterns of implementation " << endl; + return false; } - else if (refIface->getDirection() == AbstractInterface::Output) { - foreach(AbstractInterface* iface, block->getOutputs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } + + 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; } } - else if (refIface->getDirection() == AbstractInterface::InOut) { - foreach(AbstractInterface* iface, block->getBidirs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } + 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; } - } - if (funcIface == NULL) return ""; - - return funcIface->getName(); + } + return true; } QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) { @@ -527,7 +120,14 @@ QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) { toWrite << impl.xmlFile; toWrite << impl.referenceXml; toWrite << impl.referenceMd5; - + toWrite << impl.resources; + // saving patterns + toWrite << impl.noPatterns; + toWrite << impl.delta; + toWrite << impl.consumptionPattern; + toWrite << impl.productionPattern; + toWrite << impl.productionCounter; + out << blockData; return out; @@ -544,41 +144,13 @@ QDataStream& operator>>(QDataStream &in, BlockImplementation &impl) { in >> impl.xmlFile; in >> impl.referenceXml; in >> impl.referenceMd5; + in >> impl.resources; + // loading patterns + in >> impl.noPatterns; + in >> impl.delta; + in >> impl.consumptionPattern; + in >> impl.productionPattern; + in >> impl.productionCounter; return in; } - -QString BlockImplementation::calculateWidth(QString s){ - QRegExp *rxWidth = new QRegExp("$*([a-zA-Z0-9_-]*)"); - QStringList matchList = s.split(" "); - int pos = 0; - QString res, line; - QList listParams = reference->getParameters(); - - while ((pos = rxWidth->indexIn(s, pos)) != -1) { - matchList << rxWidth->cap(1); - pos += rxWidth->matchedLength(); - } - - for (int i = 0; i < matchList.size(); i++) { - QString match = matchList.at(i); - if(rxWidth->indexIn(match)) { - for(int j = 0; j < listParams.size(); j++) { - if(match.compare(listParams.at(j)->getName())) { - BlockParameter *param = listParams.at(i); - if(param->getContext() == "generic") { - match = match.remove('$'); - } - else { - match = param->getValue().toString(); - } - } - } - } - } - line = matchList.join(' '); - evaluator->setExpression(line); - res = evaluator->evaluate(); - return res; -} -