X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/84eeae848c9d322ea4c935b8ec7338f69becbc10..c85843afb9bd492b46d6fe87a8287157097483f5:/FunctionalBlock.cpp?ds=sidebyside diff --git a/FunctionalBlock.cpp b/FunctionalBlock.cpp index 66e89b4..8ecd6a3 100644 --- a/FunctionalBlock.cpp +++ b/FunctionalBlock.cpp @@ -28,8 +28,13 @@ FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference lengthOP = -1; lengthPP = -1; delta = -1; + evaluator = NULL; + } +FunctionalBlock::~FunctionalBlock() { + if (evaluator != NULL) delete evaluator; +} void FunctionalBlock::parametersValidation(QList* checkedBlocks, QList *blocksToConfigure) { /* @@ -73,6 +78,8 @@ void FunctionalBlock::populate() { addParameter(p); } + ConnectedInterface* toClk = NULL; + ConnectedInterface* toRst = NULL; // create interfaces from reference block QList lstRef = reference->getInterfaces(); // store relation between functional and reference @@ -86,8 +93,19 @@ void FunctionalBlock::populate() { exit(1); } hashIface.insert(lstRef.at(i),inter); - addInterface(inter); + /* WARNING FOR THE FUTURE : + in case of there are several clock interfaces ofr that block + it would be a godd idea to make the user choose which one + must be connected to defautl clk. + Presently, the first encountered is chosen + */ + if ((toClk == NULL) && (inter->getPurpose() == AbstractInterface::Clock)) { + toClk = AI_TO_CON(inter); + } + if ((toRst == NULL) && (inter->getPurpose() == AbstractInterface::Reset)) { + toRst = AI_TO_CON(inter); + } } AbstractInterface* funCtlIface = NULL; @@ -104,8 +122,19 @@ void FunctionalBlock::populate() { } } } -} + // connect clk and rst to group clk/rst or to clkrstgen + if ((name != "clkrstgen") && (parent != NULL)) { + try { + connectClkReset(); + } + catch(Exception e) { + AbstractBlock* source = (AbstractBlock *)(e.getSource()); + cerr << qPrintable(source->getName()) << ":" << qPrintable(e.getMessage()) << endl; + throw(e); + } + } +} QString FunctionalBlock::getReferenceXmlFile() { return ((ReferenceBlock *)reference)->getXmlFile(); @@ -115,26 +144,41 @@ QString FunctionalBlock::getReferenceHashMd5() { return ((ReferenceBlock *)reference)->getHashMd5(); } -bool FunctionalBlock::createPatterns() { +void FunctionalBlock::createPatterns() throw(Exception) { static QString fctName = "FunctionalBlock::createPatterns()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif cout << "create patterns for block " << qPrintable(name) << endl; - evaluator = new ArithmeticEvaluator(); - bool ok = true; + if (evaluator == NULL) evaluator = new ArithmeticEvaluator(); if (! isGeneratorBlock()) { - ok = ok & createDelta(); - if (ok) ok = ok & createConsumptionPattern(); - if (ok) ok = ok & createProductionCounter(); + try { + createDelta(); + createConsumptionPattern(); + createProductionCounter(); + } + catch(Exception e) { + throw(e); // rethrow e + } + } + try { + createProductionPattern(); + } + 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; } - if (ok) ok = ok & createProductionPattern(); - delete evaluator; - return ok; } -bool FunctionalBlock::createDelta() { +void FunctionalBlock::createDelta() throw(Exception) { static QString fctName = "FunctionalBlock::createDelta()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; @@ -144,85 +188,105 @@ bool FunctionalBlock::createDelta() { cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl; if (deltaStr.isEmpty()) { delta = -1; - return true; + return; } - // look for parameter names - bool ok = true; - double result = evaluateExpression(deltaStr, &ok); - if (!ok) return false; - + // look for parameter names + double result = 0; + try { + result = evaluateExpression(deltaStr); + } + catch(Exception e) { + throw(e); + } delta = result; cout << "delta = " << delta << endl; - - return true; } -bool FunctionalBlock::createConsumptionPattern() { +void FunctionalBlock::createConsumptionPattern() throw(Exception) { static QString fctName = "FunctionalBlock::createConsumptionPattern()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - lengthCP = -1; - bool ok = true; + // first clear if already exists + clearConsumptionPattern(); + + lengthCP = -1; QHash consPattern = implementation->getConsumptionPattern(); foreach(AbstractInterface* iface, getControlInputs()) { FunctionalInterface* connIface = AI_TO_FUN(iface); QString refName = connIface->getReference()->getName(); if (! consPattern.contains(refName)) { + throw(Exception(NO_IFACE_CP,this)); cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl; - return false; } - QList* pattern = expandPattern(consPattern.value(refName),&ok); - if (!ok) return false; + QList* pattern = NULL; + try { + pattern = expandPattern(consPattern.value(refName)); + } + catch(Exception e) { + throw(e); + } consumptionPattern.insert(connIface,pattern); if (lengthCP == -1) { lengthCP = pattern->size(); } else { - if (pattern->size() != lengthCP) return false; + if (pattern->size() != lengthCP) { + throw(Exception(INVALID_IFACE_CP_LENGTH,this)); + } } - } - return true; + } } -bool FunctionalBlock::createProductionPattern() { +void FunctionalBlock::createProductionPattern() throw(Exception){ static QString fctName = "FunctionalBlock::createProductionPattern()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif + + // first clear if already exists + clearProductionPattern(); - lengthPP = -1; - bool ok = true; + lengthPP = -1; QHash prodPattern = implementation->getProductionPattern(); foreach(AbstractInterface* iface, getControlOutputs()) { FunctionalInterface* connIface = AI_TO_FUN(iface); QString refName = connIface->getReference()->getName(); if (! prodPattern.contains(refName)) { - cerr << "no production pattern for reference interface " << qPrintable(refName) << endl; - return false; + throw(Exception(NO_IFACE_PP,this)); + } + QList* pattern = NULL; + try { + pattern = expandPattern(prodPattern.value(refName)); + } + catch(Exception e) { + throw(e); } - QList* pattern = expandPattern(prodPattern.value(refName),&ok); - if (!ok) return false; productionPattern.insert(connIface,pattern); if (lengthPP == -1) { lengthPP = pattern->size(); } else { - if (pattern->size() != lengthPP) return false; + if (pattern->size() != lengthPP) { + throw(Exception(INVALID_IFACE_PP_LENGTH,this)); + } } - } - return true; + } } -bool FunctionalBlock::createProductionCounter() { +void FunctionalBlock::createProductionCounter() throw(Exception) { static QString fctName = "FunctionalBlock::createProductionCounter()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif + + // first clear if already exists + productionCounter.clear(); + QStringList counterParts = implementation->getProductionCounter().split(","); foreach(QString s, counterParts) { @@ -236,14 +300,20 @@ bool FunctionalBlock::createProductionCounter() { s.remove(0,1); s.chop(1); QStringList gen = s.split(":"); - if (gen.size() != 3) return false; + if (gen.size() != 3) { + throw(Exception(INVALID_IFACE_PC,this)); + } int start = 0; int nb = 0; int step = 0; - for(int i=0;i<3;i++) { - bool okVal; - double result = evaluateExpression(gen.at(i),&okVal); - if (!okVal) return false; + for(int i=0;i<3;i++) { + double result = 0.0; + try { + result = evaluateExpression(gen.at(i)); + } + catch(Exception e) { + throw(e); + } if (i==0) start = result; else if (i==1) nb = result; else if (i==2) step = result; @@ -252,11 +322,14 @@ bool FunctionalBlock::createProductionCounter() { productionCounter.append(start+j*step); } } - else { - bool okVal; - double result = evaluateExpression(s,&okVal); - - if (!okVal) return false; + else { + double result = 0.0; + try { + result = evaluateExpression(s); + } + catch(Exception e) { + throw(e); + } productionCounter.append(result); } } @@ -264,45 +337,90 @@ bool FunctionalBlock::createProductionCounter() { cout << val << ","; } cout << endl; - - return true; } -QList* FunctionalBlock::expandPattern(const QString& patternIn, bool* ok) { +QList* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) { static QString fctName = "FunctionalBlock::expandPattern()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - - QList lst; - QString p = patternIn; + /* expanding a pattern is done in two steps : + - 1 : finding all variables that correspond to an expression + and copy them in the pattern + - 2 : parsing the result + + Note that the result MUST contain only variables that have a + integer/double value. Otherwise, expanding will fail. + + */ + + // first step. + + QString p = replaceExpressions(patternIn); + + QList lst; p.append(')'); - int offset = 0; + int offset = 0; QList* patternOut = new QList(); - expandPatternRecur(p,&offset,ok,patternOut); + try { + patternOut->append(expandPatternRecur(p,&offset)); + } + catch(Exception e) { + throw(e); + } + return patternOut; } -void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, bool *ok, QList* patternOut) { +QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) { + + QString res = patternIn; + bool stop = false; + QRegularExpression re("[$][a-zA-Z0-9_]+"); + + while (!stop) { + stop = true; + QRegularExpressionMatchIterator matcher = re.globalMatch(res); + while(matcher.hasNext()) { + QRegularExpressionMatch m = matcher.next(); + QString param = m.captured(0); + QString paramName = param; + paramName.remove(0,1); + BlockParameter* p = getParameterFromName(paramName); + if ((p != NULL) && (p->getType() == BlockParameter::Expression)) { + res.replace(param,p->getStringValue()); + stop = false; + cout << "found an expr: " << qPrintable(paramName) << ", patern => " << qPrintable(res) << endl; + } + } + } + return res; +} + +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; - expandPatternRecur(patternIn,offset, ok, patternOut); - if (!ok) { - return; + try { + 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; @@ -312,19 +430,21 @@ void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, *offset += 1; } if (*offset == patternIn.size()) { - *ok = false; - return; + throw(Exception(INVALID_IFACE_PATTERN,this)); + } + double repeat = 0; + try { + repeat = evaluateExpression(expr); + } + catch(Exception e) { + throw(e); } - double repeat = evaluateExpression(expr,ok); - if (!ok) { - return; - } // 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; @@ -339,106 +459,258 @@ void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, *offset += 1; } if (*offset == patternIn.size()) { - *ok = false; - return; + throw(Exception(INVALID_IFACE_PATTERN,this)); } - double repeat = evaluateExpression(expr,ok); - if (!ok) { - return; + double repeat = 0; + try { + repeat = evaluateExpression(expr); + } + catch(Exception e) { + throw(e); } /* cout << "repeat last group " << repeat << " times : "; 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); } - } - //*offset += 1; - return; + } + return patternOut; } -double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) { +double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) { static QString fctName = "FunctionalBlock::evaluateExpression()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - - *ok = true; + QHash vars; evaluator->setExpression(expression); QList varNames = evaluator->getVariableNames(); foreach (QString name, varNames) { QString paramName = name; paramName.remove(0,1); - BlockParameter* param = reference->getParameterFromName(paramName); + BlockParameter* param = getParameterFromName(paramName); if (param == NULL) { - cerr << "found an unknown parameter in delta"<< endl; - *ok = false; - return 0.0; + throw(Exception(EVAL_PARAM_UNKNOWN,this)); } bool okVal; - int val = param->getDoubleValue(&okVal); + int val = param->getDoubleValue(&okVal); if (!okVal) { - cerr << "cannot obtain double value of paramter " << qPrintable(paramName) << endl; - *ok = false; - return 0.0; + throw(Exception(EVAL_PARAM_NOVALUE,this)); } vars.insert(name,(double)val); } evaluator->setVariablesValue(vars); - double result; + double result = 0.0; try { result = evaluator->evaluate(); } catch(int index) { cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl; - *ok = false; - return 0.0; + throw(Exception(EVAL_INVALID_EXPR,this)); } return result; } -void FunctionalBlock::createInputPattern() { +void FunctionalBlock::computeAdmittanceDelays() throw(Exception) { + static QString fctName = "FunctionalBlock::computeAdmittanceDelays()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + QList inClock; + QList delays; + + clearAdmittanceDelays(); + + // trying to synchronize the first one in AP + QMapIterator* > iterAP(admittance); + QMapIterator* > iterIP(inputPattern); + + while (iterAP.hasNext()) { + iterAP.next(); + iterIP.next(); + QList* ap = iterAP.value(); + QList* ip = iterIP.value(); + int first = 0; + while ((first < lengthIP) && (ip->at(first) == 0)) first++; + while ((first < lengthAP) && (ap->at(first) == 0)) first--; + delays.append(first); + inClock.append(0); + QList* delays = new QList(); + admittanceDelays.insert(iterAP.key(), delays); + } + + QMapIterator* > iterDelays(admittanceDelays); + + // get the delay to apply + int maxDelay = 0; + for(int i=0;i maxDelay) maxDelay = delays[i]; + } + // adding the delays to IP + iterIP.toFront(); + int i = 0; + while (iterIP.hasNext()) { + iterIP.next(); + iterDelays.next(); + QList* ip = iterIP.value(); + QList* d = iterDelays.value(); + d->append(maxDelay-delays[i]); + cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl; + for(int j=0;jprepend(0); + } + for(int j=0;jappend(0); + } + i++; + } + lengthIP += maxDelay; + + cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl; + bool stop = false; + int apIndex = 0; + int ipIndex = 0; + while (!stop) { + + // if AP is a valid group, search for the next valid group in IP + if (isValidDataGroup(admittance,apIndex)) { + + while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++; + if (ipIndex == lengthIP) { + stop = true; + continue; + } + } + + iterAP.toFront(); + iterIP.toFront(); + iterDelays.toFront(); + + if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) { + while (iterAP.hasNext()) { + iterAP.next(); + iterDelays.next(); + QList* ap = iterAP.value(); + if (ap->at(apIndex) == 1) { + QList* d = iterDelays.value(); + d->append(0); // the 1 is at its good place, so no delay + } + } + } + else { + cout << "diff between IP and AP at " << apIndex << endl; + // search for the next 1 in IP for every input that has a 1 in AP + + while (iterAP.hasNext()) { + iterAP.next(); + iterIP.next(); + iterDelays.next(); + QList* ap = iterAP.value(); + QList* ip = iterIP.value(); + QList* d = iterDelays.value(); + // case 1: 1 in IP is too late + if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) { + int delay = 1; + while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++; + cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl; + // moving the 1 to its normal pos. + ip->replace(ipIndex,1); + ip->replace(ipIndex+delay,0); + d->append(-delay); + } + // case 2: 1 in IP is too soon + else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) { + int delay = 1; + while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++; + cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl; + // search for next 0 in IP to put the 1 + int k = ipIndex+delay; + while ((k < lengthIP) && (ip->at(k) == 1)) k++; + ip->replace(ipIndex,0); + ip->replace(k,1); + d->append(delay); + } + } + if (! samePatterns(inputPattern,inClock,admittance,apIndex)) { + cout << "Abnormal case while searching for delays" << endl; + } + } + + apIndex++; + ipIndex++; + if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true; + } + iterDelays.toFront(); + while (iterDelays.hasNext()) { + iterDelays.next(); + QList* d = iterDelays.value(); + foreach(int v, *d) { + cout << v << " "; + } + cout << endl; + } + +} + +void FunctionalBlock::createInputPattern() throw(Exception) { static QString fctName = "FunctionalBlock::createInputPattern())"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif lengthIP = -1; - foreach(AbstractInterface* iface, getControlInputs()) { + foreach(AbstractInterface* iface, getControlInputs()) { + ConnectedInterface* connIface = AI_TO_CON(iface); + // check if it is connected + if (connIface->getConnectedFrom() == NULL) { + throw(Exception(IFACE_NOT_CONNECTED,this)); + } + // get the precursor output pattern QList* out = connIface->getConnectedFrom()->getOutputPattern(); + AbstractInputModifier* modifier = connIface->getInputModifier(); + // check if the input is modified + if (modifier != NULL) { + + out = modifier->getModifiedInput(out); + } + + if (out->size() == 0) { + clearInputPattern(); + throw(Exception(NO_IFACE_IP,this)); + } 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); + + QList* in = new QList(*out); + foreach(char c, *in) { + cout << (int)c; } - else { - inputPattern.insert(connIface,NULL); - } - } + cout << endl; + inputPattern.insert(connIface,in); + } + // search the last valid group in IP, + while(! isValidDataGroup(inputPattern,lengthIP-1)) { + //removeDataGroup(inputPattern,lengthIP-1); + lengthIP -= 1; + } } -bool FunctionalBlock::createAdmittance(int nbExec) { +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()) { @@ -492,8 +764,7 @@ bool FunctionalBlock::createAdmittance(int nbExec) { j -= 1; } else { - cout << "AP and CP are not consistent" << endl; - return false; + throw(INVALID_DELTA_CP); } } } @@ -504,61 +775,76 @@ bool FunctionalBlock::createAdmittance(int nbExec) { QList* pattern = iterA.value(); for(int i=0;isize();i++) { if (pattern->at(i) == -1) pattern->replace(i,0); + cout << (int)(pattern->at(i)); } - } - return true; + cout << endl; + } } -bool FunctionalBlock::checkInputPatternCompatibility() { +void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) { 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; + try { + createInputPattern(); + } + catch(Exception e) { + throw(e); + } + int nbExec = createTriggers(); + cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl; + + try { + createAdmittance(nbExec); + } + catch(Exception e) { + cout << "cannot create admittance" << endl; + throw(e); } - 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)) { - + int i = 0; // index in AP + while ((clock < lengthIP) && (i < lengthAP)) { + + // if AP is a valid group, search for the next valid group in IP + if (isValidDataGroup(admittance,i)) { + while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++; + if (clock == lengthIP) { + cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl; + throw(Exception(IP_END_NULLCOL,this)); } - else { - // IP and AP are not equal and AP is a valid group -> not compatible - return false; - } - } + /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or + are both null columns + */ + if (! samePatterns(inputPattern,clock,admittance,i)) { + cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl; + throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible + } + clock++; + i++; } - return true; + if (clock < lengthIP) { + throw(Exception(AP_TOO_SHORT,this)); + cerr << "Abnormal case: AP is to short" << endl; + } } -bool FunctionalBlock::computeOutputPattern(int nbExec) { +void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) { static QString fctName = "FunctionalBlock::computeOutputPattern()"; #ifdef DEBUG_FCTNAME cout << "call to " << qPrintable(fctName) << endl; #endif - + + clearOutputPattern(); + /* 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()) { @@ -578,12 +864,14 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { // in case of inputPattern not created, do it if (lengthIP <= 0) { + + cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl; // collect the input patterns for each input - createInputPattern(); - // if some patterns are not available, end now, returning false - if (lengthIP == 0) { - clearInputPattern(); - return false; + try { + createInputPattern(); + } + catch(Exception e) { + throw(e); } cout << "input pattern array initialized with min. len " << lengthIP << endl; } @@ -671,10 +959,135 @@ bool FunctionalBlock::computeOutputPattern(int nbExec) { // clear input pattern clearInputPattern(); - } - return true; + } } +/* + +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; @@ -692,6 +1105,26 @@ bool FunctionalBlock::samePatterns(const QMap* > return true; } +bool FunctionalBlock::samePatterns(const QMap* >& patternSrc, const QList &srcCols, const QMap* >& patternDest, int destCol) { + if (patternSrc.size() != srcCols.size()) return false; + if (patternSrc.size() != patternDest.size()) return false; + + QMapIterator* > iterSrc(patternSrc); + QListIterator iterSrcCol(srcCols); + QMapIterator* > iterDest(patternDest); + while (iterSrc.hasNext()) { + iterSrc.next(); + int srcCol = iterSrcCol.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; +} + bool FunctionalBlock::canCombinePatterns(const QMap* >& patternSrc, int srcCol, QMap* > patternDest, int destCol) { if (patternSrc.size() != patternDest.size()) return false; QMapIterator* > iterSrc(patternSrc); @@ -776,6 +1209,19 @@ bool FunctionalBlock::isValidDataGroup(const QMap* >& pattern, const QList offsets) { + QMapIterator* > iterSrc(pattern); + QListIterator iterOffsets(offsets); + while (iterSrc.hasNext()) { + iterSrc.next(); + int offset = iterOffsets.next(); + QList* srcPat = iterSrc.value(); + if (offset >= srcPat->size()) return false; + if (srcPat->at(offset) == 1) return true; + } + return false; +} + bool FunctionalBlock::isOnlyXDataGroup(const QMap *> &pattern, int offset) { QMapIterator* > iterSrc(pattern); while (iterSrc.hasNext()) { @@ -821,24 +1267,48 @@ void FunctionalBlock::clearInputPattern() { lengthIP = -1; } -int FunctionalBlock::getNumberOfExecution() { +void FunctionalBlock::clearOutputPattern() { + + QMapIterator* > iterO(outputPattern); + while (iterO.hasNext()) { + iterO.next(); + ConnectedInterface* connIface = AI_TO_CON(iterO.key()); + connIface->resetOutputPattern(); + QList* pattern = iterO.value(); + if (pattern != NULL) delete pattern; + } + outputPattern.clear(); + lengthOP = -1; +} + +void FunctionalBlock::clearAdmittanceDelays() { + QMapIterator* > iterA(admittanceDelays); + while (iterA.hasNext()) { + iterA.next(); + QList* d = iterA.value(); + if (d != NULL) delete d; + } + admittanceDelays.clear(); +} + +int FunctionalBlock::createTriggers() { + triggers.clear(); /* NB: this method returns the number of executions that have been started but not necessary completed. */ - if (delta <= 0) return 0; - int nbExec = 0; + if (delta <= 0) return 0; int offset = 0; // search for the first exec. while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++; if (offset == lengthIP) return 0; - nbExec = 1; + triggers.append(offset); int nbGroup = 0; for(int i = offset;i