X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/cfe8322b50c9ef08ffbc3e52b0849bca4cd1d0bf..8e89ca269960b7bb43ccc054696dfc28e84d409a:/FunctionalBlock.cpp diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index 93e8377..5731794 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -18,7 +18,14 @@ FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference nbConsumingPorts = 0; productionPattern = NULL; lengthPP = 0; - nbProducingPorts = 0; + nbProducingPorts = 0; + if (reference->getImplementations().isEmpty()) { + implementation = NULL; + cout << "block has no implementation" << endl; + } + else { + implementation = reference->getImplementations().at(0); + } } @@ -106,7 +113,69 @@ QString FunctionalBlock::getReferenceHashMd5() { return ((ReferenceBlock *)reference)->getHashMd5(); } -void FunctionalBlock::computeOutputPattern(int nbExec) { +bool FunctionalBlock::createPatterns() { + evaluator = new ArithmeticEvaluator(); + bool ok = true; + ok = ok & createDelta(); + if (ok) ok = ok & createConsumptionPattern(); + if (ok) ok = ok & createProductionCounter(); + if (ok) ok = ok & createProductionPattern(); + delete evaluator; + return ok; +} + +bool FunctionalBlock::createDelta() { + QString delta = implementation->getDelta(); + cout << "delta for " << qPrintable(name) << " = " << qPrintable(delta) << endl; + + // look for parameter names + QHash vars; + QRegularExpression re("[$][a-zA-Z0-9_]+"); + QRegularExpressionMatchIterator matcher = re.globalMatch(delta); + while(matcher.hasNext()) { + QRegularExpressionMatch m = matcher.next(); + QString var = m.captured(0); + cout << qPrintable(var) << endl; + vars.insert(var,0.0); + } + QHashIterator iterV(vars); + while (iterV.hasNext()) { + iterV.next(); + QString var = iterV.key(); + QString paramName = var.remove(0,1); + BlockParameter* param = reference->getParameterFromName(paramName); + cout << "param = " << qPrintable(param->getStringValue()) << endl; + if (param == NULL) { + cerr << "found an unknown parameter in delta"<< endl; + return false; + } + bool ok; + int val = param->getIntValue(&ok); + vars.insert(var,(double)val); + } + cout << "set expr " << endl; + evaluator->setExpression(delta); + cout << "set vars " << endl; + evaluator->setVariablesValue(vars); + double result = evaluator->evaluate(); + cout << "delta = " << result << endl; + + return true; +} + +bool FunctionalBlock::createConsumptionPattern() { + return true; +} + +bool FunctionalBlock::createProductionPattern() { + return true; +} + +bool FunctionalBlock::createProductionCounter() { + return true; +} + +bool FunctionalBlock::computeOutputPattern(int nbExec) { /* case 1: the block is a generator for which output pattern must be computed for a nbExec following executions @@ -137,11 +206,24 @@ void FunctionalBlock::computeOutputPattern(int nbExec) { else { if (in.size() < minLen) minLen = in.size(); } - inputPattern[idIface] = new char[in.size()]; - int i = 0; - foreach(char c, in) inputPattern[idIface][i++] = c; + if (in.size() > 0) { + inputPattern[idIface] = new char[in.size()]; + int i = 0; + foreach(char c, in) inputPattern[idIface][i++] = c; + } + else { + inputPattern[idIface] = NULL; + } idIface += 1; } + // if some patterns are not available, ens now, returning false + if (minLen == 0) { + for(int i=0;i