nbConsumingPorts = 0;\r
productionPattern = NULL;\r
lengthPP = 0;\r
- nbProducingPorts = 0; \r
+ nbProducingPorts = 0;\r
+ if (reference->getImplementations().isEmpty()) {\r
+ implementation = NULL;\r
+ cout << "block has no implementation" << endl;\r
+ }\r
+ else {\r
+ implementation = reference->getImplementations().at(0);\r
+ }\r
}\r
\r
\r
return ((ReferenceBlock *)reference)->getHashMd5();\r
}\r
\r
-void FunctionalBlock::computeOutputPattern(int nbExec) {\r
+bool FunctionalBlock::createPatterns() {\r
+ evaluator = new ArithmeticEvaluator();\r
+ bool ok = true;\r
+ ok = ok & createDelta();\r
+ if (ok) ok = ok & createConsumptionPattern();\r
+ if (ok) ok = ok & createProductionCounter();\r
+ if (ok) ok = ok & createProductionPattern();\r
+ delete evaluator;\r
+ return ok;\r
+}\r
+\r
+bool FunctionalBlock::createDelta() {\r
+ QString delta = implementation->getDelta();\r
+ cout << "delta for " << qPrintable(name) << " = " << qPrintable(delta) << endl;\r
+ \r
+ // look for parameter names\r
+ QHash<QString,double> vars;\r
+ QRegularExpression re("[$][a-zA-Z0-9_]+");\r
+ QRegularExpressionMatchIterator matcher = re.globalMatch(delta);\r
+ while(matcher.hasNext()) {\r
+ QRegularExpressionMatch m = matcher.next();\r
+ QString var = m.captured(0);\r
+ cout << qPrintable(var) << endl;\r
+ vars.insert(var,0.0); \r
+ }\r
+ QHashIterator<QString,double> iterV(vars);\r
+ while (iterV.hasNext()) {\r
+ iterV.next();\r
+ QString var = iterV.key();\r
+ QString paramName = var.remove(0,1);\r
+ BlockParameter* param = reference->getParameterFromName(paramName);\r
+ cout << "param = " << qPrintable(param->getStringValue()) << endl;\r
+ if (param == NULL) {\r
+ cerr << "found an unknown parameter in delta"<< endl;\r
+ return false;\r
+ }\r
+ bool ok;\r
+ int val = param->getIntValue(&ok);\r
+ vars.insert(var,(double)val);\r
+ }\r
+ cout << "set expr " << endl;\r
+ evaluator->setExpression(delta);\r
+ cout << "set vars " << endl;\r
+ evaluator->setVariablesValue(vars);\r
+ double result = evaluator->evaluate();\r
+ cout << "delta = " << result << endl;\r
+ \r
+ return true;\r
+}\r
+\r
+bool FunctionalBlock::createConsumptionPattern() {\r
+ return true;\r
+}\r
+\r
+bool FunctionalBlock::createProductionPattern() {\r
+ return true;\r
+}\r
+\r
+bool FunctionalBlock::createProductionCounter() {\r
+ return true;\r
+}\r
+\r
+bool FunctionalBlock::computeOutputPattern(int nbExec) {\r
\r
/* case 1: the block is a generator for which output pattern\r
must be computed for a nbExec following executions\r
else {\r
if (in.size() < minLen) minLen = in.size();\r
}\r
- inputPattern[idIface] = new char[in.size()];\r
- int i = 0;\r
- foreach(char c, in) inputPattern[idIface][i++] = c;\r
+ if (in.size() > 0) {\r
+ inputPattern[idIface] = new char[in.size()];\r
+ int i = 0;\r
+ foreach(char c, in) inputPattern[idIface][i++] = c;\r
+ }\r
+ else {\r
+ inputPattern[idIface] = NULL;\r
+ }\r
idIface += 1; \r
}\r
+ // if some patterns are not available, ens now, returning false\r
+ if (minLen == 0) {\r
+ for(int i=0;i<nbConsumingPorts; i++) {\r
+ if (inputPattern[i] != NULL) delete [] inputPattern[i];\r
+ }\r
+ delete [] inputPattern;\r
+ return false;\r
+ }\r
// initialize the output pattern \r
char** outputPattern = NULL;\r
outputPattern = new char*[nbProducingPorts];\r
}\r
delete [] outputPattern;\r
}\r
+ return true;\r
}\r
\r
bool FunctionalBlock::isValidDataGroup(char** pattern, int nbPorts, int clock) {\r