X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/7b1c7e44123b9b2626205a89e27b2a4712ea30c6..df84660fd98b39737692d57b68c8b2c2d34af0f1:/FunctionalBlock.cpp?ds=inline diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index e7239e0..7be000a 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -127,7 +127,6 @@ void FunctionalBlock::createPatterns() throw(Exception) { cout << "create patterns for block " << qPrintable(name) << endl; if (evaluator == NULL) evaluator = new ArithmeticEvaluator(); - bool ok = true; if (! isGeneratorBlock()) { try { createDelta(); @@ -143,7 +142,15 @@ void FunctionalBlock::createPatterns() throw(Exception) { } catch(Exception e) { throw(e); - } + } + cout << "PP of " << qPrintable(name) << endl; + QMapIterator* > it(productionPattern); + while (it.hasNext()) { + it.next(); + QList* pat = it.value(); + foreach(char c, *pat) cout << (int)c; + cout << endl; + } } void FunctionalBlock::createDelta() throw(Exception) { @@ -159,8 +166,7 @@ void FunctionalBlock::createDelta() throw(Exception) { return; } - // look for parameter names - bool ok = true; + // look for parameter names double result = 0; try { result = evaluateExpression(deltaStr); @@ -178,8 +184,7 @@ void FunctionalBlock::createConsumptionPattern() throw(Exception) { cout << "call to " << qPrintable(fctName) << endl; #endif - lengthCP = -1; - bool ok = true; + lengthCP = -1; QHash consPattern = implementation->getConsumptionPattern(); foreach(AbstractInterface* iface, getControlInputs()) { @@ -311,7 +316,7 @@ QList* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exce int offset = 0; QList* patternOut = new QList(); try { - expandPatternRecur(p,&offset, patternOut); + patternOut->append(expandPatternRecur(p,&offset)); } catch(Exception e) { throw(e); @@ -320,28 +325,30 @@ QList* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exce return patternOut; } -void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, QList* patternOut) throw(Exception) { +QList FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) { + QList patternOut; + while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) { QChar c = patternIn.at(*offset); if (c == '(') { *offset += 1; try { - expandPatternRecur(patternIn,offset, patternOut); + patternOut.append(expandPatternRecur(patternIn,offset)); } catch(Exception e) { throw(e); } } else if (c == '0') { - patternOut->append(0); + patternOut.append(0); } else if (c == '1') { - patternOut->append(1); + patternOut.append(1); } else if (c == 'X') { - patternOut->append(-1); + patternOut.append(-1); } else if (c == '{') { *offset += 1; @@ -361,11 +368,11 @@ void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, throw(e); } // repeat just the last value in currentGroup - char last = patternOut->last(); + char last = patternOut.last(); //cout << "repeat last char " << repeat << " times : " << (int)last << endl; for(int i=1;i<(int)repeat;i++) { - patternOut->append(last); + patternOut.append(last); } } *offset += 1; @@ -394,11 +401,12 @@ void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, foreach (char c, currentGroup) cout <<(int)c; cout << endl; */ - QList single = *patternOut; + QList single = patternOut; for(int i=1;i<(int)repeat;i++) { - patternOut->append(single); + patternOut.append(single); } } + return patternOut; } double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) { @@ -476,8 +484,7 @@ void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) { static QString fctName = "FunctionalBlock::createAdmittance()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; -#endif - bool ok = true; +#endif // firstly, copy CP in AP QMapIterator* > iterC(consumptionPattern); while (iterC.hasNext()) { @@ -553,8 +560,7 @@ void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) { #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - - bool ok = true; + // firstly, create input pattern try { createInputPattern(); @@ -727,6 +733,132 @@ void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) { } } +/* + +void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) { + static QString fctName = "FunctionalBlock::computeOutputPattern()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + + // case 1: the block is a generator for which output pattern + // must be computed for a nbExec following executions + + if (nbExec > 0) { + cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl; + foreach(AbstractInterface* iface, getControlOutputs()) { + FunctionalInterface* connIface = AI_TO_FUN(iface); + // create output pattern + QList* pp = productionPattern.value(connIface); + QList* pattern = new QList(*pp); + for(int i=1;iappend(*pp); + // assign pattern to interface + connIface->setOutputPattern(pattern); + // store it in QMap + outputPattern.insert(connIface,pattern); + } + } + else { + cout << "computing output pattern of " << qPrintable(name) << endl; + + // in case of inputPattern not created, do it + if (lengthIP <= 0) { + // collect the input patterns for each input + try { + createInputPattern(); + } + catch(Exception e) { + throw(e); + } + cout << "input pattern array initialized with min. len " << lengthIP << endl; + } + + // initialize the output pattern + lengthOP = 0; + foreach(AbstractInterface* iface, getControlOutputs()) { + FunctionalInterface* connIface = AI_TO_FUN(iface); + lengthOP = lengthIP+productionPattern.value(connIface)->size(); + QList* pattern = new QList(); + for(int i=0;iappend(0); + connIface->setOutputPattern(pattern); + outputPattern.insert(connIface,pattern); + } + cout << "output pattern array initialized" << endl; + + int clock = 0; + nbExec = 0; + // search for the beginning of the first execution. + while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++; + cout << "found 1st exec clock: " << clock << endl; + + 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 + int cip = 0; // clock+cip give the clock cycle of an input group + int ccp = 0; // ccp give a column in the consumptio pattern + int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP + int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP + bool cannotCompleteExec = false; + for(int m=0;m* >& patternSrc, int srcCol, const QMap* >& patternDest, int destCol) { if (patternSrc.size() != patternDest.size()) return false;