#include "ReferenceInterface.h"\r
#include "FunctionalInterface.h"\r
#include "BlockParameter.h"\r
+#include <QHashIterator>\r
\r
\r
BlockImplementation::BlockImplementation(const QString& _xmlFile) {\r
- xmlFile = _xmlFile; \r
+ xmlFile = _xmlFile;\r
+ productionCounter = "";\r
+ delta = "";\r
\r
evaluator = new ArithmeticEvaluator;\r
evaluator->setVariableMarkers("@$");\r
\r
BlockImplementation::BlockImplementation(const QString& _xmlFile, const QString &_referenceXml, const QString &_referenceMd5) {\r
xmlFile = _xmlFile; \r
+ productionCounter = "";\r
+ delta = "";\r
referenceXml = _referenceXml;\r
referenceMd5 = _referenceMd5;\r
}\r
\r
-void BlockImplementation::assignPatterns(FunctionalBlock *_block) throw(Exception) {\r
+void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) {\r
+ \r
+ QDomNodeList patternNode = root.elementsByTagName("patterns");\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
+ if (patternNode.isEmpty()) {\r
+ cout << "impl has no patterns" << endl;\r
+ return;\r
}\r
- if (!document.setContent(&implFile)) {\r
- implFile.close();\r
- throw(Exception(IMPLFILE_NOACCESS));\r
- }\r
- implFile.close();\r
- QDomElement impl = document.documentElement();\r
- QDomNodeList patternNode = impl.elementsByTagName("patterns");\r
- if (patternNode.isEmpty()) return;\r
+ \r
QDomElement patternElt = patternNode.at(0).toElement();\r
\r
+ QDomElement eltDelta = patternElt.firstChildElement("delta");\r
+ delta = eltDelta.attribute("value","none");\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
+ 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
+ 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
+}\r
+\r
+bool BlockImplementation::checkPatterns() {\r
+ if (reference == NULL) return false;\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
+ }\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
+ } \r
+ return true; \r
}\r
\r
void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &path) throw(Exception) {\r
toWrite << impl.xmlFile;\r
toWrite << impl.referenceXml;\r
toWrite << impl.referenceMd5;\r
-\r
+ // saving patterns\r
+ toWrite << impl.delta;\r
+ toWrite << impl.consumptionPattern;\r
+ toWrite << impl.productionPattern;\r
+ toWrite << impl.productionCounter;\r
+ \r
out << blockData;\r
\r
return out;\r
in >> impl.xmlFile;\r
in >> impl.referenceXml;\r
in >> impl.referenceMd5;\r
+ // loading patterns\r
+ in >> impl.delta;\r
+ in >> impl.consumptionPattern;\r
+ in >> impl.productionPattern;\r
+ in >> impl.productionCounter;\r
\r
return in;\r
}\r