- out << " );" << endl;\r
- }\r
-\r
- out << " port (" << endl;\r
-\r
- // Generation of the clk & rst signals\r
- out << " -- clk/rst" << endl;\r
- for(int i = 0; i < listInputs.size(); i++) {\r
- if(listInputs.at(i)->getPurpose() == AbstractInterface::Clock || listInputs.at(i)->getPurpose() == AbstractInterface::Reset) {\r
- out << " " << listInputs.at(i)->getName() << " : in std_logic;" << endl;\r
- }\r
- }\r
-\r
- if (hasController) {\r
- // Generation of the wishbone signals\r
- out << " -- registers r/w via wishbone" << endl;\r
- QList<BlockParameter*> listWB = reference->getWishboneParameters();\r
- for(i=0;i<listWB.size()-1;i++) {\r
- out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0);\r
- }\r
- out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma);\r
- }\r
-\r
-\r
- // Generation of the data signals\r
- out << "-- data ports\n";\r
- for(int i = 0; i < listInputs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listInputs.at(i)->getName()));\r
- if(listInputs.at(i)->getWidth().compare("1"))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth(listInputs.at(i)->getWidth());\r
- if(listInputs.at(i)->getPurpose() == 1)\r
- out << namePort << " : in std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\r
-\r
- for(int i = 0; i < listOutputs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listOutputs.at(i)->getName()));\r
- if(listOutputs.at(i)->getWidth().compare("1"))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth(listOutputs.at(i)->getWidth());\r
- if(listOutputs.at(i)->getPurpose() == 1)\r
- out << namePort << " : out std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\r
-\r
- for(int i = 0; i < listBidirs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listBidirs.at(i)->getName()));\r
- if(listBidirs.at(i)->getWidth().compare(("1")))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth((listBidirs.at(i)->getWidth()));\r
- if(listBidirs.at(i)->getPurpose() == 1)\r
- out << namePort << " : inout std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\r
-}\r
-\r
-// This function generates the architecture part of the VHDL document\r
-void BlockImplementation::generateArchitecture(QDomElement &elt, QTextStream& out) throw(Exception) {\r
-\r
- QString expr;\r
- QDomElement eltArch = elt.nextSiblingElement("architecture");\r
- out << "architecture " << nameEnt <<"_1 of " << nameEnt << "is\n";\r
- QString implText = eltArch.text();\r
- QStringList listLine = implText.split("\n");\r
- for(int i =0; i < listLine.size(); i++) {\r
- if(listLine.at(i).contains(QRegularExpression("@foreach{")) != -1) {\r
- while(listLine.at(i).compare("@endforeach") != -1) {\r
- expr = expr + listLine.at(i) + '\n';\r
- i++;\r
- }\r
- expr = expr + listLine.at(i);\r
- out << evalComplex(expr, 1) << '\n';\r
- }\r
- if(listLine.at(i).contains(QRegularExpression("@caseeach{")) != -1) {\r
- while(listLine.at(i).compare("@endcaseeach") != -1) {\r
- expr = expr + listLine.at(i) + '\n';\r
- i++;\r
- }\r
- expr = expr + listLine.at(i);\r
- out << evalComplex(expr, 2) << '\n';\r
- }\r
-\r
- if(listLine.at(i).contains('@') == -1)\r
- out << listLine.at(i) << "\n";\r
- else\r
- out << eval(listLine.at(i), out) << "\n";\r
- }\r
-}\r
-\r
-void BlockImplementation::generateController(QTextStream &out) throw(Exception) {\r
-}\r
-\r
-QString BlockImplementation::eval(QString line, QTextStream& out) {\r
- QString res, s, begLine, endLine, expr;\r
- evaluator->setExpression(line);\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
-\r
- int nbAt = line.count('@');\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- res = begLine + evalString(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- res = begLine + evalValue(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalComplex(QString line, int id) {\r
- QString res, s, begLine, endLine, expr;\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
- QRegExp *rxFor = new QRegExp("@foreach{.*}(@{.*})(.*)@endforeach");\r
- QRegExp *rxCase = new QRegExp("@caseeach{.*,(.*),(.*)}(@{.*})(.*)@endcaseeach");\r
- QRegExp *rxCaseDown = new QRegExp("@#-:(.*)");\r
- QRegExp *rxCaseUp = new QRegExp("@#:(.*)");\r
- evaluator->setExpression(line);\r
-\r
- int nbAt = line.count('@') - 2;\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- if(evalStringComplex(s)->size() == 0)\r
- line = begLine + evalString(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- line = begLine + evalValue(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
-\r
- if(id == 1) {\r
- if(rxFor->indexIn(line)) {\r
- QString intName, instruc;\r
- intName = rxFor->cap(1);\r
- instruc = rxFor->cap(2);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- if(intList->size() != 0) {\r
- for(int i = 0; i < intList->size(); i++) {\r
- res = intList->at(i)->getName() + instruc + '\n';\r
- }\r
- }\r
- }\r
- }\r
-\r
- else if(id == 2) {\r
- if(rxCase->indexIn(line)) {\r
- QString intName, sigName, cases, instruc;\r
- int number;\r
- sigName = rxCase->cap(1);\r
- cases = rxCase->cap(2);\r
- intName = rxCase->cap(3);\r
- instruc = rxCase->cap(4);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- int listSize = intList->count();\r
- res = "case " + sigName + " is\n";\r
- if(rxCaseUp->indexIn(cases)) {\r
- number = rxCaseUp->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number++;\r
- }\r
- }\r
- if(rxCaseDown->indexIn(cases)) {\r
- number = rxCaseDown->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number--;\r
- }\r
- res += "end case ;\n";\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalString(QString s) {\r
-\r
- QString name = getIfaceUserName(block->AbstractBlock::getIfaceFromName(s));\r
- return name;\r
-}\r
-\r
-QList<AbstractInterface*>* BlockImplementation::evalStringComplex(QString s) {\r
-\r
- int j = 0;\r
- QList<AbstractInterface*> *listInterfaces = new QList<AbstractInterface*>();\r
- AbstractInterface *inter = block->AbstractBlock::getIfaceFromName(s);\r
- QList<AbstractInterface*> listIntBlock = block->getInterfaces();\r
- for(int i = 0; i < listIntBlock.size(); i++) {\r
- if(inter->getName().compare(listIntBlock.at(i)->getName()) < -1) {\r
- listInterfaces->insert(j, inter);\r
- j ++;\r
- }\r
- }\r
- return listInterfaces;\r
-}\r
-\r
-QString BlockImplementation::evalValue(QString s) {\r
-\r
- QString val = "";\r
- if(paramMap.contains(s))\r
- val = paramMap.value(s);\r
- return val;\r
-}\r
-\r
-QString BlockImplementation::getIfaceUserName(AbstractInterface* refIface) {\r
-\r
- if (! refIface->isReferenceInterface()) return "";\r
-\r
- AbstractInterface* funcIface = NULL;\r
-\r
- if (refIface->getDirection() == AbstractInterface::Input) {\r
- foreach(AbstractInterface* iface, block->getInputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::Output) {\r
- foreach(AbstractInterface* iface, block->getOutputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::InOut) {\r
- foreach(AbstractInterface* iface, block->getBidirs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- if (funcIface == NULL) return "";\r
-\r
- return funcIface->getName();\r
+ noPatterns = true;\r
+}\r
+\r
+void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) {\r
+ \r
+ QDomNodeList patternNode = root.elementsByTagName("patterns");\r
+ \r
+ if (patternNode.isEmpty()) {\r
+ cout << "impl has no patterns" << endl;\r
+ return;\r
+ }\r
+ \r
+ QDomElement patternElt = patternNode.at(0).toElement();\r
+ \r
+ QDomElement eltDelta = patternElt.firstChildElement("delta");\r
+ delta = eltDelta.attribute("value","none");\r
+ if (delta == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+\r
+ QDomElement eltCons = eltDelta.nextSiblingElement("consumption");\r
+ \r
+ QDomNodeList listNodeInput = eltCons.elementsByTagName("input");\r
+ for(int i=0; i<listNodeInput.size(); i++) {\r
+ QDomNode node = listNodeInput.at(i); \r
+ QDomElement elt = node.toElement(); \r
+ QString nameStr = elt.attribute("name","none");\r
+ if (nameStr == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+ QString patternStr = elt.attribute("pattern","none");\r
+ if (patternStr == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+ consumptionPattern.insert(nameStr,patternStr);\r
+ }\r
+ \r
+ QDomElement eltProd = eltCons.nextSiblingElement("production");\r
+ \r
+ productionCounter = eltProd.attribute("counter","none");\r
+ QDomNodeList listNodeOutput = eltProd.elementsByTagName("output");\r
+ for(int i=0; i<listNodeOutput.size(); i++) {\r
+ QDomNode node = listNodeOutput.at(i); \r
+ QDomElement elt = node.toElement(); \r
+ QString nameStr = elt.attribute("name","none");\r
+ if (nameStr == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+ QString patternStr = elt.attribute("pattern","none"); \r
+ if (patternStr == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+ productionPattern.insert(nameStr,patternStr); \r
+ }\r
+ cout << "patterns summary:" << endl;\r
+ QHashIterator<QString,QString> iterP(productionPattern);\r
+ while (iterP.hasNext()) {\r
+ iterP.next();\r
+ cout << qPrintable(iterP.key()) << " -> " << qPrintable(iterP.value()) << endl;\r
+ }\r
+ cout << "impls patterns read correctly" << endl;\r
+ noPatterns = false;\r
+}\r
+\r
+bool BlockImplementation::checkPatterns() {\r
+\r
+\r
+ if (reference == NULL) {\r
+ cout << "no ref. while checking patterns of implementation " << endl;\r
+ return false;\r
+ }\r
+ \r
+ AbstractInterface* iface; \r
+ QHashIterator<QString,QString> iterI(consumptionPattern);\r
+ while (iterI.hasNext()) {\r
+ iterI.next();\r
+ iface = reference->getIfaceFromName(iterI.key());\r
+ if (iface == NULL) {\r
+ cout << "cannot found an input ref. iface for impl. iface " << qPrintable(iterI.key()) << endl;\r
+ return false;\r
+ }\r
+ }\r
+ QHashIterator<QString,QString> iterO(productionPattern);\r
+ while (iterO.hasNext()) {\r
+ iterO.next();\r
+ iface = reference->getIfaceFromName(iterO.key());\r
+ if (iface == NULL) {\r
+ cout << "cannot found an output ref. iface for impl. iface " << qPrintable(iterI.key()) << endl;\r
+ return false;\r
+ }\r
+ } \r
+ return true; \r