X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/7af5c69c22148510cf8f042552018c9b966860cd..84eeae848c9d322ea4c935b8ec7338f69becbc10:/FunctionalBlock.cpp?ds=sidebyside diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index 23d43b9..66e89b4 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -22,6 +22,12 @@ FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference else { implementation = reference->getImplementations().at(0); } + lengthAP = -1; + lengthCP = -1; + lengthIP = -1; + lengthOP = -1; + lengthPP = -1; + delta = -1; } @@ -117,10 +123,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 +140,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 +164,7 @@ bool FunctionalBlock::createConsumptionPattern() { cout << "call to " << qPrintable(fctName) << endl; #endif + lengthCP = -1; bool ok = true; QHash consPattern = implementation->getConsumptionPattern(); @@ -164,10 +175,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 +194,7 @@ bool FunctionalBlock::createProductionPattern() { cout << "call to " << qPrintable(fctName) << endl; #endif + lengthPP = -1; bool ok = true; QHash prodPattern = implementation->getProductionPattern(); @@ -190,7 +207,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 +402,152 @@ double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) return result; } +void FunctionalBlock::createInputPattern() { + static QString fctName = "FunctionalBlock::createInputPattern())"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + + 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* > iterA(admittance); + while (iterA.hasNext()) { + iterA.next(); + QList* pattern = iterA.value(); + for(int i=0;isize();i++) { + if (pattern->at(i) == -1) pattern->replace(i,0); + } + } + return true; +} + +bool FunctionalBlock::checkInputPatternCompatibility() { + static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + + bool ok = true; + // firstly, create input pattern + createInputPattern(); + // if some patterns are not available, end now, returning false + if (lengthIP == 0) { + clearInputPattern(); + return false; + } + int nbExec = getNumberOfExecution(); + ok = createAdmittance(nbExec); + if (!ok) return false; + + int clock = 0; // index in IP + int i = 0; // index in AP + while (clock < lengthIP) { + if (samePatterns(inputPattern,clock,admittance,i)) { + clock++; + i++; + } + else { + if (isValidDataGroup(admittance,i)) { + + } + else { + // IP and AP are not equal and AP is a valid group -> not compatible + return false; + } + + } + } + return true; +} + bool FunctionalBlock::computeOutputPattern(int nbExec) { static QString fctName = "FunctionalBlock::computeOutputPattern()"; #ifdef DEBUG_FCTNAME @@ -407,48 +576,23 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { else { cout << "computing output pattern of " << qPrintable(name) << endl; - // collect the input patterns for each input - QMap* > 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(); + // 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; } - else { - if (out->size() < minLen) minLen = 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); - } - } - // 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 +603,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 +624,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 +657,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 +669,25 @@ 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; +} + +bool FunctionalBlock::samePatterns(const QMap* >& patternSrc, int srcCol, const QMap* >& patternDest, int destCol) { + + if (patternSrc.size() != patternDest.size()) return false; + QMapIterator* > iterSrc(patternSrc); + QMapIterator* > iterDest(patternDest); + while (iterSrc.hasNext()) { + iterSrc.next(); + iterDest.next(); + QList* srcPat = iterSrc.value(); + QList* destPat = iterDest.value(); + if (srcCol >= srcPat->size()) return false; + if (destCol >= destPat->size()) return false; + if (srcPat->at(srcCol) != destPat->at(destCol)) return false; } return true; } @@ -598,6 +754,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 +794,8 @@ void FunctionalBlock::clearConsumptionPattern() { QList* pattern = iterP.value(); if (pattern != NULL) delete pattern; } + consumptionPattern.clear(); + lengthCP = -1; } void FunctionalBlock::clearProductionPattern() { @@ -636,4 +805,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