\r
cout << "create patterns for block " << qPrintable(name) << endl;\r
if (evaluator == NULL) evaluator = new ArithmeticEvaluator();\r
- bool ok = true; \r
if (! isGeneratorBlock()) {\r
try {\r
createDelta();\r
}\r
catch(Exception e) {\r
throw(e);\r
- } \r
+ }\r
+ cout << "PP of " << qPrintable(name) << endl;\r
+ QMapIterator<AbstractInterface*,QList<char>* > it(productionPattern);\r
+ while (it.hasNext()) {\r
+ it.next();\r
+ QList<char>* pat = it.value();\r
+ foreach(char c, *pat) cout << (int)c;\r
+ cout << endl;\r
+ }\r
}\r
\r
void FunctionalBlock::createDelta() throw(Exception) {\r
return;\r
}\r
\r
- // look for parameter names\r
- bool ok = true;\r
+ // look for parameter names \r
double result = 0;\r
try {\r
result = evaluateExpression(deltaStr);\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
- lengthCP = -1;\r
- bool ok = true; \r
+ lengthCP = -1; \r
QHash<QString,QString> consPattern = implementation->getConsumptionPattern(); \r
\r
foreach(AbstractInterface* iface, getControlInputs()) { \r
int offset = 0; \r
QList<char>* patternOut = new QList<char>();\r
try {\r
- expandPatternRecur(p,&offset, patternOut); \r
+ patternOut->append(expandPatternRecur(p,&offset));\r
}\r
catch(Exception e) {\r
throw(e);\r
return patternOut;\r
}\r
\r
-void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, QList<char>* patternOut) throw(Exception) { \r
+QList<char> FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) {\r
\r
+ QList<char> patternOut;\r
+\r
while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {\r
\r
QChar c = patternIn.at(*offset);\r
if (c == '(') {\r
*offset += 1;\r
try {\r
- expandPatternRecur(patternIn,offset, patternOut);\r
+ patternOut.append(expandPatternRecur(patternIn,offset));\r
}\r
catch(Exception e) {\r
throw(e);\r
}\r
}\r
else if (c == '0') {\r
- patternOut->append(0);\r
+ patternOut.append(0);\r
}\r
else if (c == '1') {\r
- patternOut->append(1);\r
+ patternOut.append(1);\r
}\r
else if (c == 'X') {\r
- patternOut->append(-1);\r
+ patternOut.append(-1);\r
}\r
else if (c == '{') {\r
*offset += 1;\r
throw(e);\r
}\r
// repeat just the last value in currentGroup\r
- char last = patternOut->last(); \r
+ char last = patternOut.last();\r
//cout << "repeat last char " << repeat << " times : " << (int)last << endl;\r
\r
for(int i=1;i<(int)repeat;i++) {\r
- patternOut->append(last);\r
+ patternOut.append(last);\r
}\r
} \r
*offset += 1;\r
foreach (char c, currentGroup) cout <<(int)c;\r
cout << endl; \r
*/\r
- QList<char> single = *patternOut;\r
+ QList<char> single = patternOut;\r
for(int i=1;i<(int)repeat;i++) {\r
- patternOut->append(single);\r
+ patternOut.append(single);\r
} \r
} \r
+ return patternOut;\r
}\r
\r
double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {\r
static QString fctName = "FunctionalBlock::createAdmittance()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
-#endif\r
- bool ok = true;\r
+#endif \r
// firstly, copy CP in AP\r
QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);\r
while (iterC.hasNext()) {\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
- \r
- bool ok = true;\r
+ \r
// firstly, create input pattern\r
try {\r
createInputPattern();\r
} \r
}\r
\r
+/*\r
+\r
+void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::computeOutputPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+\r
+ // case 1: the block is a generator for which output pattern\r
+ // must be computed for a nbExec following executions\r
+\r
+ if (nbExec > 0) {\r
+ cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;\r
+ foreach(AbstractInterface* iface, getControlOutputs()) {\r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ // create output pattern\r
+ QList<char>* pp = productionPattern.value(connIface);\r
+ QList<char>* pattern = new QList<char>(*pp);\r
+ for(int i=1;i<nbExec;i++) pattern->append(*pp);\r
+ // assign pattern to interface\r
+ connIface->setOutputPattern(pattern);\r
+ // store it in QMap\r
+ outputPattern.insert(connIface,pattern);\r
+ }\r
+ }\r
+ else {\r
+ cout << "computing output pattern of " << qPrintable(name) << endl;\r
+\r
+ // in case of inputPattern not created, do it\r
+ if (lengthIP <= 0) {\r
+ // collect the input patterns for each input\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ cout << "input pattern array initialized with min. len " << lengthIP << endl;\r
+ }\r
+\r
+ // initialize the output pattern\r
+ lengthOP = 0;\r
+ foreach(AbstractInterface* iface, getControlOutputs()) {\r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ lengthOP = lengthIP+productionPattern.value(connIface)->size();\r
+ QList<char>* pattern = new QList<char>();\r
+ for(int i=0;i<lengthOP;i++) pattern->append(0);\r
+ connIface->setOutputPattern(pattern);\r
+ outputPattern.insert(connIface,pattern);\r
+ }\r
+ cout << "output pattern array initialized" << endl;\r
+\r
+ int clock = 0;\r
+ nbExec = 0;\r
+ // search for the beginning of the first execution.\r
+ while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;\r
+ cout << "found 1st exec clock: " << clock << endl;\r
+\r
+ while (clock < lengthIP) {\r
+ // initialize counters for current execution.\r
+ int p = 0; // index in production pattern\r
+ int o = 0; // clock+o will give the clock cycle of each output group\r
+ int cip = 0; // clock+cip give the clock cycle of an input group\r
+ int ccp = 0; // ccp give a column in the consumptio pattern\r
+ int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP\r
+ int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP\r
+ bool cannotCompleteExec = false;\r
+ for(int m=0;m<productionCounter.size();m++) {\r
+ // search for the first production in PP\r
+ while (!isValidDataGroup(productionPattern,p)) {\r
+ p += 1;\r
+ o += 1;\r
+ }\r
+ int gap = 0; // count the number of extra null columns\r
+ // search for PC(m) valid input group in IP\r
+ while (nip < productionCounter.at(m)) {\r
+ if (clock+cip < lengthIP) {\r
+ if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;\r
+ cip += 1;\r
+ gap += 1;\r
+ }\r
+ else {\r
+ cannotCompleteExec = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern\r
+\r
+ // search for PC(m) valid input group in IP\r
+ while (ncp < productionCounter.at(m)) {\r
+ if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;\r
+ ccp += 1;\r
+ gap -= 1;\r
+ }\r
+ o += gap; // to take into acocunt of extra null columns\r
+ combinePatterns(productionPattern,p,outputPattern,clock+o);\r
+ p += 1;\r
+ o += 1;\r
+ }\r
+\r
+ if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern\r
+\r
+ // current exec. taken into accunt\r
+ nbExec += 1;\r
+\r
+ // search for the next exec.\r
+ clock += 1;\r
+ nip = 0;\r
+ while ((clock < lengthIP) && (nip < delta)) {\r
+ if (isValidDataGroup(inputPattern,clock)) nip += 1;\r
+ if (nip < delta) clock += 1;\r
+ }\r
+ cout << "found exec " << nbExec << " at clock: " << clock << endl;\r
+ }\r
+ // find the last valid output data group\r
+ while(! isValidDataGroup(outputPattern,lengthOP-1)) {\r
+ removeDataGroup(outputPattern,lengthOP-1);\r
+ lengthOP -= 1;\r
+ }\r
+\r
+ // clear input pattern\r
+ clearInputPattern();\r
+ }\r
+}\r
+*/\r
bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {\r
\r
if (patternSrc.size() != patternDest.size()) return false;\r