reference = _reference;\r
parent = _parent;\r
name = reference->getName();\r
- consumptionPattern = NULL;\r
- lengthCP = 0;\r
- nbConsumingPorts = 0;\r
- productionPattern = NULL;\r
- lengthPP = 0;\r
- nbProducingPorts = 0;\r
+\r
if (reference->getImplementations().isEmpty()) {\r
implementation = NULL;\r
cout << "block has no implementation" << endl;\r
else {\r
implementation = reference->getImplementations().at(0);\r
}\r
+ lengthAP = -1;\r
+ lengthCP = -1;\r
+ lengthIP = -1;\r
+ lengthOP = -1;\r
+ lengthPP = -1;\r
+ delta = -1;\r
+ evaluator = NULL;\r
}\r
\r
+FunctionalBlock::~FunctionalBlock() {\r
+ if (evaluator != NULL) delete evaluator;\r
+}\r
\r
void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {\r
/*\r
return ((ReferenceBlock *)reference)->getHashMd5();\r
}\r
\r
-bool FunctionalBlock::createPatterns() {\r
+void FunctionalBlock::createPatterns() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createPatterns()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
cout << "create patterns for block " << qPrintable(name) << endl;\r
- evaluator = new ArithmeticEvaluator();\r
- bool ok = true;\r
- ok = ok & createDelta();\r
+ if (evaluator == NULL) evaluator = new ArithmeticEvaluator();\r
if (! isGeneratorBlock()) {\r
- if (ok) ok = ok & createConsumptionPattern();\r
- if (ok) ok = ok & createProductionCounter();\r
+ try {\r
+ createDelta();\r
+ createConsumptionPattern(); \r
+ createProductionCounter();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e); // rethrow e\r
+ }\r
}\r
- if (ok) ok = ok & createProductionPattern();\r
- delete evaluator;\r
- return ok;\r
+ try {\r
+ createProductionPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ } \r
}\r
\r
-bool FunctionalBlock::createDelta() {\r
+void FunctionalBlock::createDelta() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createDelta()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif \r
\r
- QString deltaStr = implementation->getDelta();\r
+ QString deltaStr = implementation->getDelta(); \r
cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;\r
+ if (deltaStr.isEmpty()) {\r
+ delta = -1;\r
+ return;\r
+ }\r
\r
- // look for parameter names\r
- bool ok = true;\r
- double result = evaluateExpression(deltaStr, &ok);\r
- if (!ok) return false;\r
- \r
+ // look for parameter names \r
+ double result = 0;\r
+ try {\r
+ result = evaluateExpression(deltaStr);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
delta = result;\r
cout << "delta = " << delta << endl;\r
- \r
- return true;\r
}\r
\r
-bool FunctionalBlock::createConsumptionPattern() {\r
+void FunctionalBlock::createConsumptionPattern() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createConsumptionPattern()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
- bool ok = true; \r
+ lengthCP = -1; \r
QHash<QString,QString> consPattern = implementation->getConsumptionPattern(); \r
\r
foreach(AbstractInterface* iface, getControlInputs()) { \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
cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;\r
- return false;\r
}\r
- QList<char> pattern = expandPattern(consPattern.value(refName),&ok); \r
- \r
- if (!ok) return false;\r
- connIface->setConsumptionPattern(pattern);\r
- cout << qPrintable(refName) << " consumption pattern = ";\r
- foreach(char c, pattern) {\r
- cout << (int)c << " ";\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(consPattern.value(refName));\r
}\r
- cout << endl;\r
- \r
- } \r
- return true;\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ consumptionPattern.insert(connIface,pattern);\r
+ if (lengthCP == -1) {\r
+ lengthCP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthCP) {\r
+ throw(Exception(INVALID_IFACE_CP_LENGTH));\r
+ }\r
+ }\r
+ } \r
}\r
\r
-bool FunctionalBlock::createProductionPattern() { \r
+void FunctionalBlock::createProductionPattern() throw(Exception){ \r
static QString fctName = "FunctionalBlock::createProductionPattern()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
- bool ok = true; \r
+ lengthPP = -1; \r
QHash<QString,QString> prodPattern = implementation->getProductionPattern(); \r
\r
foreach(AbstractInterface* iface, getControlOutputs()) { \r
FunctionalInterface* connIface = AI_TO_FUN(iface);\r
QString refName = connIface->getReference()->getName(); \r
if (! prodPattern.contains(refName)) {\r
- cerr << "no production pattern for reference interface " << qPrintable(refName) << endl;\r
- return false;\r
+ throw(Exception(NO_IFACE_PP)); \r
}\r
- QList<char> pattern = expandPattern(prodPattern.value(refName),&ok);\r
- if (!ok) return false;\r
- connIface->setProductionPattern(pattern);\r
- cout << qPrintable(refName) << " production pattern = ";\r
- foreach(char c, pattern) {\r
- cout << (int)c << " ";\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(prodPattern.value(refName));\r
}\r
- cout << endl;\r
- \r
- } \r
- return true;\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ productionPattern.insert(connIface,pattern);\r
+ if (lengthPP == -1) {\r
+ lengthPP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthPP) {\r
+ throw(Exception(INVALID_IFACE_PP_LENGTH));\r
+ }\r
+ }\r
+ } \r
}\r
\r
-bool FunctionalBlock::createProductionCounter() {\r
+void FunctionalBlock::createProductionCounter() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createProductionCounter()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
s.remove(0,1);\r
s.chop(1);\r
QStringList gen = s.split(":");\r
- if (gen.size() != 3) return false;\r
+ if (gen.size() != 3) {\r
+ throw(Exception(INVALID_IFACE_PC));\r
+ }\r
int start = 0;\r
int nb = 0;\r
int step = 0;\r
- for(int i=0;i<3;i++) {\r
- bool okVal;\r
- double result = evaluateExpression(gen.at(i),&okVal);\r
- if (!okVal) return false;\r
+ for(int i=0;i<3;i++) { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(gen.at(i));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
if (i==0) start = result;\r
else if (i==1) nb = result;\r
else if (i==2) step = result;\r
productionCounter.append(start+j*step);\r
}\r
}\r
- else {\r
- bool okVal;\r
- double result = evaluateExpression(s,&okVal);\r
- \r
- if (!okVal) return false;\r
+ else { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(s);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
productionCounter.append(result); \r
}\r
}\r
cout << val << ",";\r
}\r
cout << endl;\r
- \r
- return true;\r
}\r
\r
-QList<char> FunctionalBlock::expandPattern(const QString& pattern, bool* ok) {\r
+QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {\r
static QString fctName = "FunctionalBlock::expandPattern()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
\r
QList<char> lst;\r
- QString p = pattern;\r
+ QString p = patternIn;\r
p.append(')');\r
- int offset = 0;\r
- lst = expandPatternRecur(p,&offset,ok); \r
- return lst;\r
+ int offset = 0; \r
+ QList<char>* patternOut = new QList<char>();\r
+ try {\r
+ expandPatternRecur(p,&offset, patternOut); \r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+\r
+ return patternOut;\r
}\r
\r
-QList<char> FunctionalBlock::expandPatternRecur(const QString& pattern, int *offset, bool *ok) {\r
- \r
- QList<char> currentGroup; \r
+void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, QList<char>* patternOut) throw(Exception) { \r
\r
- while ((*offset < pattern.size()) && (pattern.at(*offset) != ')')) {\r
+ while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {\r
\r
- QChar c = pattern.at(*offset);\r
+ QChar c = patternIn.at(*offset);\r
if (c == '(') {\r
*offset += 1;\r
- currentGroup += expandPatternRecur(pattern,offset, ok);\r
- if (!ok) {\r
- return currentGroup;\r
+ try {\r
+ expandPatternRecur(patternIn,offset, patternOut);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
}\r
else if (c == '0') {\r
- currentGroup.append(0);\r
+ patternOut->append(0);\r
}\r
else if (c == '1') {\r
- currentGroup.append(1);\r
+ patternOut->append(1);\r
}\r
else if (c == 'X') {\r
- currentGroup.append(-1);\r
+ patternOut->append(-1);\r
}\r
else if (c == '{') {\r
*offset += 1;\r
QString expr = ""; \r
- while ((*offset < pattern.size()) && (pattern.at(*offset) != '}')) {\r
- expr += pattern.at(*offset); \r
+ while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {\r
+ expr += patternIn.at(*offset); \r
*offset += 1;\r
}\r
- if (*offset == pattern.size()) {\r
- *ok = false;\r
- return currentGroup;\r
+ if (*offset == patternIn.size()) {\r
+ throw(Exception(INVALID_IFACE_PATTERN));\r
+ }\r
+ double repeat = 0;\r
+ try {\r
+ repeat = evaluateExpression(expr);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
- double repeat = evaluateExpression(expr,ok);\r
- if (!ok) {\r
- return currentGroup; \r
- } \r
// repeat just the last value in currentGroup\r
- char last = currentGroup.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
- currentGroup += last;\r
+ patternOut->append(last);\r
}\r
} \r
*offset += 1;\r
}\r
\r
// must check if after ), there is a {\r
- if ((*offset < pattern.size()-1) && (pattern.at(*offset+1) == '{')) {\r
+ if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {\r
*offset += 2;\r
QString expr = ""; \r
- while ((*offset < pattern.size()) && (pattern.at(*offset) != '}')) {\r
- expr += pattern.at(*offset); \r
+ while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {\r
+ expr += patternIn.at(*offset); \r
*offset += 1;\r
}\r
- if (*offset == pattern.size()) {\r
- *ok = false;\r
- return currentGroup;\r
+ if (*offset == patternIn.size()) {\r
+ throw(Exception(INVALID_IFACE_PATTERN));\r
+ }\r
+ double repeat = 0;\r
+ try {\r
+ repeat = evaluateExpression(expr);\r
}\r
- double repeat = evaluateExpression(expr,ok);\r
- if (!ok) {\r
- return currentGroup; \r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
/*\r
cout << "repeat last group " << repeat << " times : ";\r
foreach (char c, currentGroup) cout <<(int)c;\r
cout << endl; \r
*/\r
- QList<char> single = currentGroup;\r
+ QList<char> single = *patternOut;\r
for(int i=1;i<(int)repeat;i++) {\r
- currentGroup += single;\r
+ patternOut->append(single);\r
} \r
- }\r
- //*offset += 1;\r
- return currentGroup;\r
+ } \r
}\r
\r
-double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) {\r
+double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {\r
static QString fctName = "FunctionalBlock::evaluateExpression()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
- \r
- *ok = true;\r
+ \r
QHash<QString,double> vars;\r
evaluator->setExpression(expression);\r
QList<QString> varNames = evaluator->getVariableNames();\r
paramName.remove(0,1);\r
BlockParameter* param = reference->getParameterFromName(paramName); \r
if (param == NULL) {\r
- cerr << "found an unknown parameter in delta"<< endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_PARAM_UNKNOWN));\r
}\r
bool okVal;\r
int val = param->getDoubleValue(&okVal);\r
if (!okVal) {\r
- cerr << "cannot obtain double value of paramter " << qPrintable(paramName) << endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_PARAM_NOVALUE)); \r
}\r
vars.insert(name,(double)val); \r
- } \r
+ }\r
+ \r
evaluator->setVariablesValue(vars);\r
- double result;\r
+ double result = 0.0;\r
try {\r
result = evaluator->evaluate();\r
}\r
catch(int index) {\r
cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_INVALID_EXPR));\r
}\r
return result;\r
}\r
\r
-bool FunctionalBlock::computeOutputPattern(int nbExec) {\r
+void FunctionalBlock::createInputPattern() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createInputPattern())";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ lengthIP = -1;\r
+ foreach(AbstractInterface* iface, getControlInputs()) { \r
+ ConnectedInterface* connIface = AI_TO_CON(iface);\r
+ QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();\r
+ if (out->size() == 0) {\r
+ clearInputPattern();\r
+ throw(Exception(NO_IFACE_IP));\r
+ }\r
+ if (lengthIP == -1) {\r
+ lengthIP = out->size();\r
+ }\r
+ else {\r
+ if (out->size() < lengthIP) lengthIP = out->size();\r
+ }\r
+ \r
+ QList<char>* in = new QList<char>(*out);\r
+ foreach(char c, *in) {\r
+ cout << (int)c;\r
+ }\r
+ cout << endl; \r
+ inputPattern.insert(connIface,in); \r
+ }\r
+ // search the last valid group in IP,\r
+ while(! isValidDataGroup(inputPattern,lengthIP-1)) {\r
+ //removeDataGroup(inputPattern,lengthIP-1);\r
+ lengthIP -= 1;\r
+ }\r
+}\r
+\r
+void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createAdmittance()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif \r
+ // firstly, copy CP in AP\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);\r
+ while (iterC.hasNext()) {\r
+ iterC.next();\r
+ QList<char>* pattern = new QList<char>(*(iterC.value()));\r
+ admittance.insert(iterC.key(), pattern); \r
+ }\r
+ lengthAP = lengthCP;\r
+ int clock = 0; \r
+ cout << "trigger 1 at c.c. 0" << endl;\r
+ for(int i=1;i<nbExec;i++) {\r
+ // searching for the clock cycle for which a new exec starts\r
+ int nbGroup = 0;\r
+ while ((clock < lengthAP) && (nbGroup < delta)) {\r
+ if (isValidDataGroup(admittance,clock)) nbGroup+=1;\r
+ clock += 1;\r
+ }\r
+ while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;\r
+ cout << "trigger " << (i+1) << " at c.c. " << clock << endl;\r
+ int sc = clock;\r
+ // combine CP with AP at sc\r
+ for(int j=0;j<lengthCP;j++) {\r
+ // first case : column of CP must be placed beyond AP's end.\r
+ if (sc == lengthAP) {\r
+ cout << i << "," << j << " append in AP at " << sc << endl;\r
+ appendToPattern(consumptionPattern,j,admittance,1);\r
+ lengthAP += 1;\r
+ sc += 1; \r
+ }\r
+ // second case : CP and AP can be combined directly (i.e. no X | 1 to do)\r
+ else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {\r
+ cout << i << "," << j << " combine at " << sc << endl;\r
+ combinePatterns(consumptionPattern,j,admittance,sc);\r
+ sc += 1;\r
+ }\r
+ // third case : CP has an X column\r
+ else if (isOnlyXDataGroup(consumptionPattern,j)) {\r
+ cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;\r
+ shiftRightPattern(admittance,sc);\r
+ lengthAP += 1;\r
+ if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {\r
+ cerr << "Abnormal case when combining AP and CP" << endl;\r
+ }\r
+ combinePatterns(consumptionPattern,j,admittance,sc); \r
+ sc += 1;\r
+ }\r
+ // fourth case : AP has an X column\r
+ else if (isOnlyXDataGroup(admittance,sc)) {\r
+ cout << i << "," << j << " jump c.c. for CP at " << sc << endl; \r
+ sc += 1;\r
+ j -= 1;\r
+ }\r
+ else {\r
+ throw(INVALID_DELTA_CP); \r
+ }\r
+ }\r
+ }\r
+ // turn all X into 0\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);\r
+ while (iterA.hasNext()) {\r
+ iterA.next();\r
+ QList<char>* pattern = iterA.value();\r
+ for(int i=0;i<pattern->size();i++) {\r
+ if (pattern->at(i) == -1) pattern->replace(i,0);\r
+ cout << (int)(pattern->at(i));\r
+ }\r
+ cout << endl;\r
+ } \r
+}\r
+\r
+void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ // firstly, create input pattern\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ int nbExec = createTriggers();\r
+ cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;\r
+ \r
+ try {\r
+ createAdmittance(nbExec);\r
+ }\r
+ catch(Exception e) {\r
+ cout << "cannot create admittance" << endl;\r
+ throw(e);\r
+ }\r
+ \r
+ int clock = 0; // index in IP \r
+ int i = 0; // index in AP \r
+ while ((clock < lengthIP) && (i < lengthAP)) {\r
+ \r
+ // if AP is a valid group, search for the next valid group in IP\r
+ if (isValidDataGroup(admittance,i)) {\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
+ }\r
+ } \r
+ /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or\r
+ are both null columns\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
+ }\r
+ clock++;\r
+ i++;\r
+ }\r
+ if (clock < lengthIP) {\r
+ throw(Exception(AP_TOO_SHORT));\r
+ cerr << "Abnormal case: AP is to short" << endl; \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
cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;\r
foreach(AbstractInterface* iface, getControlOutputs()) {\r
FunctionalInterface* connIface = AI_TO_FUN(iface);\r
- QList<char> pattern;\r
- for(int i=0;i<nbExec;i++) pattern += connIface->getProductionPattern();\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
- } \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
- // initialize consumption and production patterns \r
- initConsumptionPattern();\r
- initProductionPattern();\r
- \r
- // collect the input patterns for each input \r
- char** inputPattern = NULL;\r
- int idIface = 0;\r
- inputPattern = new char*[nbConsumingPorts];\r
- int minLen = -1;\r
- foreach(AbstractInterface* iface, getControlInputs()) { \r
- ConnectedInterface* connIface = AI_TO_CON(iface);\r
- QList<char> in = connIface->getConnectedFrom()->getOutputPattern();\r
- if (minLen == -1) {\r
- minLen = in.size();\r
- }\r
- else {\r
- if (in.size() < minLen) minLen = in.size();\r
- }\r
- if (in.size() > 0) {\r
- inputPattern[idIface] = new char[in.size()];\r
- int i = 0;\r
- foreach(char c, in) inputPattern[idIface][i++] = c;\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
- else {\r
- inputPattern[idIface] = NULL;\r
- }\r
- idIface += 1; \r
- }\r
- // if some patterns are not available, ens now, returning false\r
- if (minLen == 0) {\r
- for(int i=0;i<nbConsumingPorts; i++) {\r
- if (inputPattern[i] != NULL) delete [] inputPattern[i];\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
- delete [] inputPattern;\r
- return false;\r
+ cout << "input pattern array initialized with min. len " << lengthIP << endl;\r
}\r
- cout << "input pattern array initialized with min. len " << minLen << endl;\r
+ \r
// initialize the output pattern \r
- char** outputPattern = NULL;\r
- outputPattern = new char*[nbProducingPorts];\r
- int lengthOP = 0;\r
- idIface = 0;\r
+ lengthOP = 0;\r
foreach(AbstractInterface* iface, getControlOutputs()) {\r
- FunctionalInterface* connIface = AI_TO_FUN(iface);\r
- lengthOP = minLen+connIface->getProductionPattern().size();\r
- outputPattern[idIface] = new char[lengthOP];\r
- memset(outputPattern[idIface],0,lengthOP);\r
- idIface += 1;\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 < minLen) && (! isValidDataGroup(inputPattern,nbConsumingPorts,clock))) clock++;\r
+ while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;\r
cout << "found 1st exec clock: " << clock << endl;\r
\r
- while (clock < minLen) {\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
bool cannotCompleteExec = false;\r
for(int m=0;m<productionCounter.size();m++) {\r
// search for the first production in PP\r
- while (!isValidDataGroup(productionPattern,nbProducingPorts,p)) {\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 < minLen) {\r
- if (isValidDataGroup(inputPattern,nbConsumingPorts,clock+cip)) nip += 1;\r
+ if (clock+cip < lengthIP) {\r
+ if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;\r
cip += 1;\r
gap += 1;\r
}\r
cannotCompleteExec = true;\r
break;\r
} \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,nbConsumingPorts,ccp)) ncp += 1;\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,1,nbProducingPorts);\r
+ combinePatterns(productionPattern,p,outputPattern,clock+o);\r
p += 1;\r
o += 1;\r
}\r
// search for the next exec.\r
clock += 1; \r
nip = 0;\r
- while ((clock < minLen) && (nip < delta)) {\r
- if (isValidDataGroup(inputPattern,nbConsumingPorts,clock)) nip += 1;\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,nbProducingPorts,lengthOP-1)) lengthOP -= 1;\r
- \r
- //for(int i=0;i<lengthOP;i++) cout << (int)(outputPattern[0][i]);\r
- //cout << endl;\r
- // copy back outputPattern info each interface\r
- idIface = 0;\r
- foreach(AbstractInterface* iface, getControlOutputs()) {\r
- ConnectedInterface* connIface = AI_TO_CON(iface);\r
- QList<char> pattern;\r
- for(int i=0;i<lengthOP;i++) pattern.append(outputPattern[idIface][i]);\r
- connIface->setOutputPattern(pattern); \r
- idIface += 1;\r
- }\r
- \r
- // clear inputPattern and outputPattern\r
- for(int i=0;i<nbConsumingPorts; i++) {\r
- delete [] inputPattern[i];\r
+ while(! isValidDataGroup(outputPattern,lengthOP-1)) {\r
+ removeDataGroup(outputPattern,lengthOP-1);\r
+ lengthOP -= 1;\r
}\r
- delete [] inputPattern;\r
- for(int i=0;i<nbProducingPorts; i++) {\r
- delete [] outputPattern[i];\r
- }\r
- delete [] outputPattern;\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
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.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::isValidDataGroup(char** pattern, int nbPorts, int clock) {\r
- \r
- for(int i=0;i<nbPorts;i++) {\r
- if (pattern[i][clock] == 1) return true;\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
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.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) == -1) && (destPat->at(destCol) == 1)) return false;\r
+ if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;\r
}\r
- return false; \r
+ return true;\r
}\r
\r
-void FunctionalBlock::combinePatterns(char** patternSrc, int srcCol, char** patternDest, int destCol, int nbCols, int nbPorts ) {\r
- \r
- for (int i=0;i<nbCols;i++) {\r
- for(int j=0;j<nbPorts;j++) {\r
- patternDest[j][destCol+i] = patternDest[j][destCol+i] | patternSrc[j][srcCol+i];\r
+void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {\r
+ if (patternSrc.size() != patternDest.size()) return;\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next();\r
+ iterDest.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ QList<char>* destPat = iterDest.value();\r
+ if (srcCol >= srcPat->size()) return;\r
+ if (destCol >= destPat->size()) return;\r
+ if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;\r
+ if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return; \r
+ destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));\r
+ } \r
+}\r
+\r
+void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {\r
+ if (patternSrc.size() != patternDest.size()) return;\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next();\r
+ iterDest.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ QList<char>* destPat = iterDest.value(); \r
+ int i=0;\r
+ while ((srcCol+i < srcPat->size()) && (i<nbCols)) {\r
+ destPat->append(srcPat->at(srcCol+i));\r
+ i++;\r
+ }\r
+ } \r
+}\r
+\r
+void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern); \r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ if (offset < srcPat->size()) {\r
+ srcPat->removeAt(offset);\r
}\r
}\r
- \r
}\r
\r
-void FunctionalBlock::clearConsumptionPattern() {\r
- if (consumptionPattern == NULL) return;\r
- \r
- for(int i=0;i<nbConsumingPorts; i++) {\r
- delete [] consumptionPattern[i];\r
+void FunctionalBlock::shiftRightPattern(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern); \r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ if (offset < srcPat->size()) {\r
+ srcPat->insert(offset,0);\r
+ }\r
}\r
- delete [] consumptionPattern; \r
}\r
\r
-void FunctionalBlock::clearProductionPattern() {\r
- if (productionPattern == NULL) return;\r
- for(int i=0;i<nbProducingPorts;i++) {\r
- delete [] productionPattern[i];\r
+bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern); \r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ if (offset >= srcPat->size()) return false;\r
+ if (srcPat->at(offset) == 1) return true;\r
}\r
- delete [] productionPattern;\r
+ return false;\r
}\r
\r
-void FunctionalBlock::initConsumptionPattern() {\r
- static QString fctName = "FunctionalBlock::initConsumptionPattern()";\r
-#ifdef DEBUG_FCTNAME\r
- cout << "call to " << qPrintable(fctName) << endl;\r
-#endif\r
- \r
- if (consumptionPattern != NULL) clearConsumptionPattern();\r
- \r
- nbConsumingPorts = getControlInputs().size(); \r
- int idIface = 0;\r
- consumptionPattern = new char*[nbConsumingPorts]; \r
- foreach(AbstractInterface* iface, getControlInputs()) {\r
- FunctionalInterface* connIface = AI_TO_FUN(iface);\r
- QList<char> in = connIface->getConsumptionPattern();\r
- lengthCP = in.size(); // normally, all inputs have the same lenght for CP\r
- consumptionPattern[idIface] = new char[lengthCP];\r
- int i = 0;\r
- foreach(char c, in) consumptionPattern[idIface][i++] = c;\r
- idIface += 1; \r
+bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern); \r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ if (offset >= srcPat->size()) return false;\r
+ if (srcPat->at(offset) != -1) return false;\r
}\r
+ return true; \r
}\r
\r
-void FunctionalBlock::initProductionPattern() {\r
- static QString fctName = "FunctionalBlock::initProductionPattern()";\r
-#ifdef DEBUG_FCTNAME\r
- cout << "call to " << qPrintable(fctName) << endl;\r
-#endif\r
- \r
- if (productionPattern != NULL) clearProductionPattern();\r
+void FunctionalBlock::clearConsumptionPattern() {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern); \r
+ while (iterP.hasNext()) {\r
+ iterP.next();\r
+ QList<char>* pattern = iterP.value();\r
+ if (pattern != NULL) delete pattern;\r
+ }\r
+ consumptionPattern.clear();\r
+ lengthCP = -1; \r
+} \r
+\r
+void FunctionalBlock::clearProductionPattern() {\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern); \r
+ while (iterP.hasNext()) {\r
+ iterP.next();\r
+ QList<char>* pattern = iterP.value();\r
+ if (pattern != NULL) delete pattern;\r
+ }\r
+ productionPattern.clear();\r
+ lengthPP = -1;\r
+} \r
+\r
+void FunctionalBlock::clearInputPattern() {\r
\r
- nbProducingPorts = getControlOutputs().size(); \r
- int idIface = 0;\r
- productionPattern = new char*[nbProducingPorts]; \r
- foreach(AbstractInterface* iface, getControlOutputs()) {\r
- FunctionalInterface* connIface = AI_TO_FUN(iface);\r
- QList<char> in = connIface->getProductionPattern();\r
- lengthPP = in.size(); // normally, all inputs have the same lenght for PP\r
- productionPattern[idIface] = new char[lengthPP];\r
- int i = 0;\r
- foreach(char c, in) productionPattern[idIface][i++] = c;\r
- idIface += 1; \r
+ QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);\r
+ while (iterI.hasNext()) {\r
+ iterI.next();\r
+ QList<char>* pattern = iterI.value();\r
+ if (pattern != NULL) delete pattern;\r
}\r
+ inputPattern.clear();\r
+ lengthIP = -1;\r
+}\r
+\r
+int FunctionalBlock::createTriggers() {\r
+ triggers.clear();\r
+ /* NB: this method returns the number of executions that have been started\r
+ but not necessary completed.\r
+ */\r
+ if (delta <= 0) return 0; \r
+ int offset = 0;\r
+ // search for the first exec.\r
+ while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;\r
+ if (offset == lengthIP) return 0;\r
+ triggers.append(offset); \r
+ int nbGroup = 0;\r
+ for(int i = offset;i<lengthIP;i++) {\r
+ if (isValidDataGroup(inputPattern,i)) nbGroup++;\r
+ if (nbGroup == delta+1) {\r
+ triggers.append(i);\r
+ nbGroup = 1;\r
+ }\r
+ } \r
+ return triggers.size();\r
}\r