X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/7af5c69c22148510cf8f042552018c9b966860cd..2019e5afdaf7fd0ad21607848710348bbc3be256:/FunctionalBlock.cpp diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index 23d43b9..ac27de4 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -117,10 +117,10 @@ bool FunctionalBlock::createPatterns() { cout << "create patterns for block " << qPrintable(name) << endl; evaluator = new ArithmeticEvaluator(); - bool ok = true; - ok = ok & createDelta(); + bool ok = true; if (! isGeneratorBlock()) { - if (ok) ok = ok & createConsumptionPattern(); + ok = ok & createDelta(); + if (ok) ok = ok & createConsumptionPattern(); if (ok) ok = ok & createProductionCounter(); } if (ok) ok = ok & createProductionPattern(); @@ -134,8 +134,12 @@ bool FunctionalBlock::createDelta() { cout << "call to " << qPrintable(fctName) << endl; #endif - QString deltaStr = implementation->getDelta(); + QString deltaStr = implementation->getDelta(); cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl; + if (deltaStr.isEmpty()) { + delta = -1; + return true; + } // look for parameter names bool ok = true; @@ -154,6 +158,7 @@ bool FunctionalBlock::createConsumptionPattern() { cout << "call to " << qPrintable(fctName) << endl; #endif + lengthCP = -1; bool ok = true; QHash consPattern = implementation->getConsumptionPattern(); @@ -164,10 +169,15 @@ bool FunctionalBlock::createConsumptionPattern() { cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl; return false; } - QList* pattern = expandPattern(consPattern.value(refName),&ok); - + QList* pattern = expandPattern(consPattern.value(refName),&ok); if (!ok) return false; - consumptionPattern.insert(connIface,pattern); + consumptionPattern.insert(connIface,pattern); + if (lengthCP == -1) { + lengthCP = pattern->size(); + } + else { + if (pattern->size() != lengthCP) return false; + } } return true; } @@ -178,6 +188,7 @@ bool FunctionalBlock::createProductionPattern() { cout << "call to " << qPrintable(fctName) << endl; #endif + lengthPP = -1; bool ok = true; QHash prodPattern = implementation->getProductionPattern(); @@ -190,7 +201,13 @@ bool FunctionalBlock::createProductionPattern() { } QList* pattern = expandPattern(prodPattern.value(refName),&ok); if (!ok) return false; - productionPattern.insert(connIface,pattern); + productionPattern.insert(connIface,pattern); + if (lengthPP == -1) { + lengthPP = pattern->size(); + } + else { + if (pattern->size() != lengthPP) return false; + } } return true; } @@ -379,6 +396,121 @@ double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) return result; } +void FunctionalBlock::createInputPattern() { + lengthIP = -1; + foreach(AbstractInterface* iface, getControlInputs()) { + ConnectedInterface* connIface = AI_TO_CON(iface); + QList* out = connIface->getConnectedFrom()->getOutputPattern(); + if (lengthIP == -1) { + lengthIP = out->size(); + } + else { + if (out->size() < lengthIP) lengthIP = out->size(); + } + if (out->size() > 0) { + QList* in = new QList(*out); + foreach(char c, *in) { + cout << (int)c; + } + cout << endl; + + inputPattern.insert(connIface,in); + } + else { + inputPattern.insert(connIface,NULL); + } + } +} + +bool FunctionalBlock::createAdmittance(int nbExec) { + static QString fctName = "FunctionalBlock::createAdmittance()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + bool ok = true; + // firstly, copy CP in AP + QMapIterator* > iterC(consumptionPattern); + while (iterC.hasNext()) { + iterC.next(); + QList* pattern = new QList(*(iterC.value())); + admittance.insert(iterC.key(), pattern); + } + lengthAP = lengthCP; + int clock = 0; + cout << "trigger 1 at c.c. 0" << endl; + for(int i=1;i* > inputPattern; - int minLen = -1; - foreach(AbstractInterface* iface, getControlInputs()) { - ConnectedInterface* connIface = AI_TO_CON(iface); - QList* out = connIface->getConnectedFrom()->getOutputPattern(); - if (minLen == -1) { - minLen = out->size(); - } - else { - if (out->size() < minLen) minLen = out->size(); + // in case of inputPattern not created, do it + if (lengthIP <= 0) { + // collect the input patterns for each input + createInputPattern(); + // if some patterns are not available, end now, returning false + if (lengthIP == 0) { + clearInputPattern(); + return false; } - if (out->size() > 0) { - QList* in = new QList(*out); - foreach(char c, *in) { - cout << (int)c; - } - cout << endl; - - inputPattern.insert(connIface,in); - } - else { - inputPattern.insert(connIface,NULL); - } - } - // if some patterns are not available, end now, returning false - if (minLen == 0) { - QMapIterator* > iterI(inputPattern); - while (iterI.hasNext()) { - iterI.next(); - QList* pattern = iterI.value(); - if (pattern != NULL) delete pattern; - } - return false; + cout << "input pattern array initialized with min. len " << lengthIP << endl; } - cout << "input pattern array initialized with min. len " << minLen << endl; // initialize the output pattern - int lengthOP = 0; + lengthOP = 0; foreach(AbstractInterface* iface, getControlOutputs()) { FunctionalInterface* connIface = AI_TO_FUN(iface); - lengthOP = minLen+productionPattern.value(connIface)->size(); + lengthOP = lengthIP+productionPattern.value(connIface)->size(); QList* pattern = new QList(); for(int i=0;iappend(0); connIface->setOutputPattern(pattern); @@ -459,10 +566,10 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { int clock = 0; nbExec = 0; // search for the beginning of the first execution. - while ((clock < minLen) && (! isValidDataGroup(inputPattern,clock))) clock++; + while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++; cout << "found 1st exec clock: " << clock << endl; - while (clock < minLen) { + while (clock < lengthIP) { // initialize counters for current execution. int p = 0; // index in production pattern int o = 0; // clock+o will give the clock cycle of each output group @@ -480,7 +587,7 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { int gap = 0; // count the number of extra null columns // search for PC(m) valid input group in IP while (nip < productionCounter.at(m)) { - if (clock+cip < minLen) { + if (clock+cip < lengthIP) { if (isValidDataGroup(inputPattern,clock+cip)) nip += 1; cip += 1; gap += 1; @@ -513,7 +620,7 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { // search for the next exec. clock += 1; nip = 0; - while ((clock < minLen) && (nip < delta)) { + while ((clock < lengthIP) && (nip < delta)) { if (isValidDataGroup(inputPattern,clock)) nip += 1; if (nip < delta) clock += 1; } @@ -525,13 +632,8 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { lengthOP -= 1; } - // clear input pattern - QMapIterator* > iterI(inputPattern); - while (iterI.hasNext()) { - iterI.next(); - QList* pattern = iterI.value(); - if (pattern != NULL) delete pattern; - } + // clear input pattern + clearInputPattern(); } return true; } @@ -598,6 +700,17 @@ void FunctionalBlock::removeDataGroup(QMap *> & } } +void FunctionalBlock::shiftRightPattern(const QMap *> &pattern, int offset) { + QMapIterator* > iterSrc(pattern); + while (iterSrc.hasNext()) { + iterSrc.next(); + QList* srcPat = iterSrc.value(); + if (offset < srcPat->size()) { + srcPat->insert(offset,0); + } + } +} + bool FunctionalBlock::isValidDataGroup(const QMap *> &pattern, int offset) { QMapIterator* > iterSrc(pattern); while (iterSrc.hasNext()) { @@ -627,6 +740,8 @@ void FunctionalBlock::clearConsumptionPattern() { QList* pattern = iterP.value(); if (pattern != NULL) delete pattern; } + consumptionPattern.clear(); + lengthCP = -1; } void FunctionalBlock::clearProductionPattern() { @@ -636,4 +751,40 @@ void FunctionalBlock::clearProductionPattern() { QList* pattern = iterP.value(); if (pattern != NULL) delete pattern; } + productionPattern.clear(); + lengthPP = -1; } + +void FunctionalBlock::clearInputPattern() { + + QMapIterator* > iterI(inputPattern); + while (iterI.hasNext()) { + iterI.next(); + QList* pattern = iterI.value(); + if (pattern != NULL) delete pattern; + } + inputPattern.clear(); + lengthIP = -1; +} + +int FunctionalBlock::getNumberOfExecution() { + /* NB: this method returns the number of executions that have been started + but not necessary completed. + */ + if (delta <= 0) return 0; + int nbExec = 0; + int offset = 0; + // search for the first exec. + while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++; + if (offset == lengthIP) return 0; + nbExec = 1; + int nbGroup = 0; + for(int i = offset;i