\r
evaluator = new ArithmeticEvaluator;\r
evaluator->setVariableMarkers("@$");\r
+\r
+ noPatterns = true;\r
}\r
\r
BlockImplementation::BlockImplementation(const QString& _xmlFile, const QString &_referenceXml, const QString &_referenceMd5) {\r
delta = "";\r
referenceXml = _referenceXml;\r
referenceMd5 = _referenceMd5;\r
+\r
+ noPatterns = true;\r
}\r
\r
void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) {\r
\r
QDomElement eltDelta = patternElt.firstChildElement("delta");\r
delta = eltDelta.attribute("value","none");\r
- \r
+ if (delta == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
+\r
QDomElement eltCons = eltDelta.nextSiblingElement("consumption");\r
\r
QDomNodeList listNodeInput = eltCons.elementsByTagName("input");\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
+ QString patternStr = elt.attribute("pattern","none");\r
+ if (patternStr == "none") throw(Exception(IMPLFILE_CORRUPTED));\r
consumptionPattern.insert(nameStr,patternStr);\r
}\r
\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
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
- if (reference == NULL) return false;\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) return false;\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) return false;\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
}\r
\r
-void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &path) throw(Exception) {\r
-\r
- block = _block;\r
-\r
- QFile implFile(xmlFile);\r
-\r
- // reading in into QDomDocument\r
- QDomDocument document("implFile");\r
-\r
- if (!implFile.open(QIODevice::ReadOnly)) {\r
- throw(Exception(IMPLFILE_NOACCESS));\r
- }\r
- if (!document.setContent(&implFile)) {\r
- implFile.close();\r
- throw(Exception(IMPLFILE_NOACCESS));\r
- }\r
- implFile.close();\r
-\r
- bool genController = false;\r
- QString coreFile = "";\r
- QString controllerFile = "";\r
-\r
- if (reference->isWBConfigurable()) {\r
- genController = true;\r
- controllerFile = path;\r
- controllerFile.append(block->getName());\r
- controllerFile.append("_ctrl.vhd"); \r
- }\r
- else {\r
- controllerFile = "nofile.vhd"; \r
- }\r
- coreFile = path;\r
- coreFile.append(block->getName());\r
- coreFile.append(".vhd");\r
-\r
- QFile vhdlCore(coreFile);\r
- QFile vhdlController(controllerFile);\r
-\r
- if (!vhdlCore.open(QIODevice::WriteOnly)) {\r
- throw(Exception(VHDLFILE_NOACCESS));\r
- }\r
-\r
- if (genController) {\r
- if (!vhdlController.open(QIODevice::WriteOnly)) {\r
- throw(Exception(VHDLFILE_NOACCESS));\r
- }\r
- }\r
- QTextStream outCore(&vhdlCore);\r
- QTextStream outController;\r
- if (genController) {\r
- outController.setDevice(&vhdlController);\r
- }\r
-\r
- try {\r
-\r
-\r
- //Get the root element\r
- QDomElement impl = document.documentElement();\r
- QDomElement eltComments = impl.firstChildElement("comments");\r
- generateComments(eltComments, coreFile, outCore);\r
- QDomElement eltLibs = eltComments.nextSiblingElement("libraries");\r
- generateLibraries(eltLibs, outCore);\r
- generateEntity(outCore, genController);\r
- QDomElement eltArch = eltLibs.nextSiblingElement("architecture");\r
- generateArchitecture(eltArch, outCore);\r
- if (genController) {\r
- generateController(outController);\r
- }\r
- }\r
- catch(Exception err) {\r
- throw(err);\r
- }\r
-\r
- vhdlCore.close();\r
- vhdlController.close();\r
-}\r
-\r
-// This function generates the comments part of the VHDL document\r
-void BlockImplementation::generateComments(QDomElement &elt, QString coreFile, QTextStream& out) throw(Exception) {\r
-\r
- for(int i = 0; i < 50; i++) {\r
- out << "--";\r
- }\r
- out << "\n--\n";\r
- QString fileName = coreFile;\r
- out << "-- File : " << fileName << "\n";\r
- out << "--\n";\r
- QDomElement eltAuthor = elt.firstChildElement("author");\r
- QString firstName = eltAuthor.attribute("firstname","");\r
- QString lastName = eltAuthor.attribute("lastname","");\r
- QString mail = eltAuthor.attribute("mail","");\r
- out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")\n";\r
- out << "--\n";\r
- QDomElement eltDate = eltAuthor.nextSiblingElement("date");\r
- QString crea = eltDate.attribute("creation","");\r
- out << "-- Creation Date : "<<crea<<"\n";\r
- out << "--\n";\r
- QDomElement eltRelated = eltDate.nextSiblingElement("related_files");\r
- QString relateds = eltRelated.attribute("list","");\r
- out << "-- Related files :\n"<<relateds<<"\n";\r
- out << "--\n";\r
- QDomElement eltDesc = eltRelated.nextSiblingElement("description");\r
- QDomElement desc = eltDesc.firstChildElement();\r
- QString descTxt = desc.text();\r
- out << "-- Decription :\n"<<descTxt<<"\n";\r
- out << "--\n";\r
- QDomElement eltNote = eltDesc.nextSiblingElement("description");\r
- QDomElement note = eltNote.firstChildElement();\r
- QString noteTxt = note.text();\r
- out << "-- Note :\n"<<noteTxt<<"\n";\r
- out << "--\n";\r
- for(int i = 0; i < 50; i++) {\r
- out << "--";\r
- }\r
- out << "\n\n";\r
-}\r
-\r
-// This function generates the library part of the VHDL document\r
-void BlockImplementation::generateLibraries(QDomElement &elt, QTextStream& out) throw(Exception) {\r
-\r
- QDomNodeList listLib = elt.elementsByTagName("library");\r
- for(int i = 0; i < listLib.length(); i++) {\r
- QDomNode nodeLib = listLib.item(i);\r
- QDomElement eltLib = nodeLib.toElement();\r
- QString nameLib = eltLib.attribute("name", "");\r
- out << "library " << nameLib << ";\n";\r
- QDomNodeList listPack = eltLib.elementsByTagName("package");\r
- for(int j = 0; j < listPack.length(); j++) {\r
- QDomNode nodePack = listPack.item(j);\r
- QDomElement eltPack = nodePack.toElement();\r
- QString namePack = eltPack.attribute("name", "");\r
- QString usePack = elt.attribute("use","");\r
- out << "use " << nameLib << "." << namePack << "." << usePack << ";\n";\r
- }\r
- out << "\n";\r
- }\r
-}\r
-\r
-// This function generates the entity part of the VHDL document\r
-void BlockImplementation::generateEntity(QTextStream& out, bool hasController) throw(Exception) {\r
-\r
- int i=0;\r
- nameEnt = reference->getName();\r
- //QList<BlockParameter*> listParams = reference->getParameters();\r
- QList<AbstractInterface*> listInputs = reference->getInputs();\r
- QList<AbstractInterface*> listOutputs = reference->getOutputs();\r
- QList<AbstractInterface*> listBidirs = reference->getBidirs();\r
- QString typePort, namePort;\r
-\r
- out << "entity " << nameEnt << " is\n";\r
-\r
-\r
- /* TODO : rewrite the generation to take into acocunt the new object hierarchy */\r
-\r
- // Generation of the generics\r
- QList<BlockParameter*> listGenerics = reference->getGenericParameters();\r
- if ((!listGenerics.isEmpty()) || (hasController)) {\r
- out << " generic (" << endl;\r
- if (hasController) {\r
- out << " wb_data_width : integer = 16;" << endl;\r
- out << " wb_addr_width : integer = 12";\r
- if (!listGenerics.isEmpty()) out << ";";\r
- out << endl;\r
- }\r
- for(i=0;i<listGenerics.size()-1;i++) {\r
- out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0);\r
- }\r
- out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma);\r
-\r
- 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
toWrite << impl.referenceXml;\r
toWrite << impl.referenceMd5;\r
// saving patterns\r
+ toWrite << impl.noPatterns;\r
toWrite << impl.delta;\r
toWrite << impl.consumptionPattern;\r
toWrite << impl.productionPattern;\r
in >> impl.referenceXml;\r
in >> impl.referenceMd5;\r
// loading patterns\r
+ in >> impl.noPatterns;\r
in >> impl.delta;\r
in >> impl.consumptionPattern;\r
in >> impl.productionPattern;\r