cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
+ // first clear if already exists\r
+ clearConsumptionPattern();\r
+\r
lengthCP = -1; \r
QHash<QString,QString> consPattern = implementation->getConsumptionPattern(); \r
\r
FunctionalInterface* connIface = AI_TO_FUN(iface);\r
QString refName = connIface->getReference()->getName(); \r
if (! consPattern.contains(refName)) {\r
- throw(Exception(NO_IFACE_CP));\r
+ throw(Exception(NO_IFACE_CP,this));\r
cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;\r
}\r
QList<char>* pattern = NULL;\r
}\r
else {\r
if (pattern->size() != lengthCP) {\r
- throw(Exception(INVALID_IFACE_CP_LENGTH));\r
+ throw(Exception(INVALID_IFACE_CP_LENGTH,this));\r
}\r
}\r
} \r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
+\r
+ // first clear if already exists\r
+ clearProductionPattern();\r
\r
lengthPP = -1; \r
QHash<QString,QString> prodPattern = implementation->getProductionPattern(); \r
FunctionalInterface* connIface = AI_TO_FUN(iface);\r
QString refName = connIface->getReference()->getName(); \r
if (! prodPattern.contains(refName)) {\r
- throw(Exception(NO_IFACE_PP)); \r
+ throw(Exception(NO_IFACE_PP,this));\r
}\r
QList<char>* pattern = NULL;\r
try {\r
}\r
else {\r
if (pattern->size() != lengthPP) {\r
- throw(Exception(INVALID_IFACE_PP_LENGTH));\r
+ throw(Exception(INVALID_IFACE_PP_LENGTH,this));\r
}\r
}\r
} \r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
+\r
+ // first clear if already exists\r
+ productionCounter.clear();\r
+\r
\r
QStringList counterParts = implementation->getProductionCounter().split(",");\r
foreach(QString s, counterParts) {\r
s.chop(1);\r
QStringList gen = s.split(":");\r
if (gen.size() != 3) {\r
- throw(Exception(INVALID_IFACE_PC));\r
+ throw(Exception(INVALID_IFACE_PC,this));\r
}\r
int start = 0;\r
int nb = 0;\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
- \r
- QList<char> lst;\r
- QString p = patternIn;\r
+ /* expanding a pattern is done in two steps :\r
+ - 1 : finding all variables that correspond to an expression\r
+ and copy them in the pattern\r
+ - 2 : parsing the result\r
+\r
+ Note that the result MUST contain only variables that have a\r
+ integer/double value. Otherwise, expanding will fail.\r
+\r
+ */\r
+\r
+ // first step.\r
+\r
+ QString p = replaceExpressions(patternIn);\r
+\r
+ QList<char> lst; \r
p.append(')');\r
int offset = 0; \r
QList<char>* patternOut = new QList<char>();\r
return patternOut;\r
}\r
\r
+QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) {\r
+\r
+ QString res = patternIn;\r
+ bool stop = false;\r
+ QRegularExpression re("[$][a-zA-Z0-9_]+");\r
+\r
+ while (!stop) {\r
+ stop = true;\r
+ QRegularExpressionMatchIterator matcher = re.globalMatch(res);\r
+ while(matcher.hasNext()) {\r
+ QRegularExpressionMatch m = matcher.next();\r
+ QString param = m.captured(0);\r
+ QString paramName = param;\r
+ paramName.remove(0,1);\r
+ BlockParameter* p = getParameterFromName(paramName);\r
+ if ((p != NULL) && (p->getType() == BlockParameter::Expression)) {\r
+ res.replace(param,p->getStringValue());\r
+ stop = false;\r
+ cout << "found an expr: " << qPrintable(paramName) << ", patern => " << qPrintable(res) << endl;\r
+ }\r
+ }\r
+ }\r
+ return res;\r
+}\r
+\r
QList<char> FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) {\r
\r
QList<char> patternOut;\r
*offset += 1;\r
}\r
if (*offset == patternIn.size()) {\r
- throw(Exception(INVALID_IFACE_PATTERN));\r
+ throw(Exception(INVALID_IFACE_PATTERN,this));\r
}\r
double repeat = 0;\r
try {\r
*offset += 1;\r
}\r
if (*offset == patternIn.size()) {\r
- throw(Exception(INVALID_IFACE_PATTERN));\r
+ throw(Exception(INVALID_IFACE_PATTERN,this));\r
}\r
double repeat = 0;\r
try {\r
foreach (QString name, varNames) {\r
QString paramName = name;\r
paramName.remove(0,1);\r
- BlockParameter* param = reference->getParameterFromName(paramName); \r
+ BlockParameter* param = getParameterFromName(paramName);\r
if (param == NULL) {\r
- throw(Exception(EVAL_PARAM_UNKNOWN));\r
+ throw(Exception(EVAL_PARAM_UNKNOWN,this));\r
}\r
bool okVal;\r
- int val = param->getDoubleValue(&okVal);\r
+ int val = param->getDoubleValue(&okVal); \r
if (!okVal) {\r
- throw(Exception(EVAL_PARAM_NOVALUE)); \r
+ throw(Exception(EVAL_PARAM_NOVALUE,this));\r
}\r
vars.insert(name,(double)val); \r
}\r
}\r
catch(int index) {\r
cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;\r
- throw(Exception(EVAL_INVALID_EXPR));\r
+ throw(Exception(EVAL_INVALID_EXPR,this));\r
}\r
return result;\r
}\r
\r
+void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ QList<int> inClock;\r
+ QList<int> delays;\r
+\r
+ clearAdmittanceDelays();\r
+\r
+ // trying to synchronize the first one in AP\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);\r
+\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterIP.next();\r
+ QList<char>* ap = iterAP.value();\r
+ QList<char>* ip = iterIP.value();\r
+ int first = 0;\r
+ while ((first < lengthIP) && (ip->at(first) == 0)) first++;\r
+ while ((first < lengthAP) && (ap->at(first) == 0)) first--;\r
+ delays.append(first);\r
+ inClock.append(0);\r
+ QList<int>* delays = new QList<int>();\r
+ admittanceDelays.insert(iterAP.key(), delays);\r
+ }\r
+\r
+ QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);\r
+\r
+ // get the delay to apply\r
+ int maxDelay = 0;\r
+ for(int i=0;i<delays.size();i++) {\r
+ if (delays[i] > maxDelay) maxDelay = delays[i];\r
+ }\r
+ // adding the delays to IP\r
+ iterIP.toFront();\r
+ int i = 0;\r
+ while (iterIP.hasNext()) {\r
+ iterIP.next();\r
+ iterDelays.next();\r
+ QList<char>* ip = iterIP.value();\r
+ QList<int>* d = iterDelays.value();\r
+ d->append(maxDelay-delays[i]);\r
+ cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;\r
+ for(int j=0;j<maxDelay-delays[i];j++) {\r
+ ip->prepend(0);\r
+ }\r
+ for(int j=0;j<delays[i];j++) {\r
+ ip->append(0);\r
+ }\r
+ i++;\r
+ }\r
+ lengthIP += maxDelay;\r
+\r
+ cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;\r
+ bool stop = false;\r
+ int apIndex = 0;\r
+ int ipIndex = 0;\r
+ while (!stop) {\r
+\r
+ // if AP is a valid group, search for the next valid group in IP\r
+ if (isValidDataGroup(admittance,apIndex)) {\r
+\r
+ while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;\r
+ if (ipIndex == lengthIP) {\r
+ stop = true;\r
+ continue;\r
+ }\r
+ }\r
+\r
+ iterAP.toFront();\r
+ iterIP.toFront();\r
+ iterDelays.toFront();\r
+\r
+ if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterDelays.next();\r
+ QList<char>* ap = iterAP.value();\r
+ if (ap->at(apIndex) == 1) {\r
+ QList<int>* d = iterDelays.value();\r
+ d->append(0); // the 1 is at its good place, so no delay\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ cout << "diff between IP and AP at " << apIndex << endl;\r
+ // search for the next 1 in IP for every input that has a 1 in AP\r
+\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterIP.next();\r
+ iterDelays.next();\r
+ QList<char>* ap = iterAP.value();\r
+ QList<char>* ip = iterIP.value();\r
+ QList<int>* d = iterDelays.value();\r
+ // case 1: 1 in IP is too late\r
+ if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {\r
+ int delay = 1;\r
+ while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;\r
+ cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;\r
+ // moving the 1 to its normal pos.\r
+ ip->replace(ipIndex,1);\r
+ ip->replace(ipIndex+delay,0);\r
+ d->append(-delay);\r
+ }\r
+ // case 2: 1 in IP is too soon\r
+ else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {\r
+ int delay = 1;\r
+ while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;\r
+ cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;\r
+ // search for next 0 in IP to put the 1\r
+ int k = ipIndex+delay;\r
+ while ((k < lengthIP) && (ip->at(k) == 1)) k++;\r
+ ip->replace(ipIndex,0);\r
+ ip->replace(k,1);\r
+ d->append(delay);\r
+ }\r
+ }\r
+ if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {\r
+ cout << "Abnormal case while searching for delays" << endl;\r
+ }\r
+ }\r
+\r
+ apIndex++;\r
+ ipIndex++;\r
+ if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;\r
+ }\r
+ iterDelays.toFront();\r
+ while (iterDelays.hasNext()) {\r
+ iterDelays.next();\r
+ QList<int>* d = iterDelays.value();\r
+ foreach(int v, *d) {\r
+ cout << v << " ";\r
+ }\r
+ cout << endl;\r
+ }\r
+\r
+}\r
+\r
void FunctionalBlock::createInputPattern() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createInputPattern())";\r
#ifdef DEBUG_FCTNAME\r
#endif\r
\r
lengthIP = -1;\r
- foreach(AbstractInterface* iface, getControlInputs()) { \r
+ foreach(AbstractInterface* iface, getControlInputs()) {\r
+\r
ConnectedInterface* connIface = AI_TO_CON(iface);\r
+ // check if it is connected\r
+ if (connIface->getConnectedFrom() == NULL) {\r
+ throw(Exception(IFACE_NOT_CONNECTED,this));\r
+ }\r
+ // get the precursor output pattern\r
QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();\r
+\r
+ ConnectedInterface* assoIface = AI_TO_CON(connIface->getAssociatedIface());\r
+ AbstractInputModifier* modifier = assoIface->getInputModifier();\r
+ // check if the input is modified\r
+ if (modifier != NULL) {\r
+\r
+ out = modifier->getModifiedInput(out);\r
+ }\r
+\r
if (out->size() == 0) {\r
clearInputPattern();\r
- throw(Exception(NO_IFACE_IP));\r
+ throw(Exception(NO_IFACE_IP,this));\r
}\r
if (lengthIP == -1) {\r
lengthIP = out->size();\r
while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;\r
if (clock == lengthIP) {\r
cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;\r
- throw(Exception(IP_END_NULLCOL)); \r
+ throw(Exception(IP_END_NULLCOL,this));\r
}\r
} \r
/* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or\r
*/\r
if (! samePatterns(inputPattern,clock,admittance,i)) {\r
cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;\r
- throw(Exception(IP_AP_NOTCOMPAT)); // IP and AP not compatible\r
+ throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible\r
}\r
clock++;\r
i++;\r
}\r
if (clock < lengthIP) {\r
- throw(Exception(AP_TOO_SHORT));\r
+ throw(Exception(AP_TOO_SHORT,this));\r
cerr << "Abnormal case: AP is to short" << endl; \r
} \r
}\r
\r
// in case of inputPattern not created, do it\r
if (lengthIP <= 0) {\r
+\r
+ cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl;\r
// collect the input patterns for each input \r
try {\r
createInputPattern();\r
return true;\r
}\r
\r
+bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int> &srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {\r
+ if (patternSrc.size() != srcCols.size()) return false;\r
+ if (patternSrc.size() != patternDest.size()) return false;\r
+\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
+ QListIterator<int> iterSrcCol(srcCols);\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next();\r
+ int srcCol = iterSrcCol.next();\r
+ iterDest.next();\r
+ QList<char>* srcPat = iterSrc.value();\r
+ QList<char>* destPat = iterDest.value();\r
+ if (srcCol >= srcPat->size()) return false;\r
+ if (destCol >= destPat->size()) return false;\r
+ if (srcPat->at(srcCol) != destPat->at(destCol)) return false;\r
+ }\r
+ return true;\r
+}\r
+\r
bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {\r
if (patternSrc.size() != patternDest.size()) return false;\r
QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
return false;\r
}\r
\r
+bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets) {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);\r
+ QListIterator<int> iterOffsets(offsets);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next();\r
+ int offset = iterOffsets.next();\r
+ QList<char>* srcPat = iterSrc.value();\r
+ if (offset >= srcPat->size()) return false;\r
+ if (srcPat->at(offset) == 1) return true;\r
+ }\r
+ return false;\r
+}\r
+\r
bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {\r
QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern); \r
while (iterSrc.hasNext()) {\r
lengthIP = -1;\r
}\r
\r
+void FunctionalBlock::clearAdmittanceDelays() {\r
+ QMapIterator<AbstractInterface*, QList<int>* > iterA(admittanceDelays);\r
+ while (iterA.hasNext()) {\r
+ iterA.next();\r
+ QList<int>* d = iterA.value();\r
+ if (d != NULL) delete d;\r
+ }\r
+ admittanceDelays.clear();\r
+}\r
+\r
int FunctionalBlock::createTriggers() {\r
triggers.clear();\r
/* NB: this method returns the number of executions that have been started\r