1 #include "FunctionalBlock.h"
\r
2 #include "ReferenceBlock.h"
\r
3 #include "GroupBlock.h"
\r
4 #include "AbstractInterface.h"
\r
5 #include "FunctionalInterface.h"
\r
6 #include "ReferenceInterface.h"
\r
7 #include "BlockParameter.h"
\r
8 #include "ArithmeticEvaluator.h"
\r
11 FunctionalBlock::FunctionalBlock(GroupBlock *_parent, ReferenceBlock *_reference) throw(Exception) : AbstractBlock() {
\r
12 //if (! _reference->isReferenceBlock()) throw(Exception(BLOCK_INVALID_TYPE));
\r
13 //if (! _group->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE));
\r
14 reference = _reference;
\r
16 name = reference->getName();
\r
18 if (reference->getImplementations().isEmpty()) {
\r
19 implementation = NULL;
\r
20 cout << "block has no implementation" << endl;
\r
23 implementation = reference->getImplementations().at(0);
\r
34 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
\r
36 checkedBlocks->append(this);
\r
38 foreach(BlockParameter* param, params){
\r
39 if(param->isUserParameter() && !param->isValueSet()){
\r
40 if(!blocksToConfigure->contains(param->getOwner())){
\r
41 blocksToConfigure->append(param->getOwner());
\r
45 foreach(AbstractInterface *inter, outputs){
\r
46 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
47 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
48 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
55 bool FunctionalBlock::isFunctionalBlock() {
\r
59 bool FunctionalBlock::isSourceBlock() {
\r
60 if (parent == NULL) return true;
\r
64 void FunctionalBlock::populate() {
\r
67 AbstractInterface* inter;
\r
69 // create parameters from reference block
\r
70 QList<BlockParameter*> lstParam = reference->getParameters();
\r
71 for(i=0;i<lstParam.size();i++) {
\r
72 p = lstParam.at(i)->clone();
\r
76 // create interfaces from reference block
\r
77 QList<AbstractInterface *> lstRef = reference->getInterfaces();
\r
78 // store relation between functional and reference
\r
79 QHash<AbstractInterface *, AbstractInterface *> hashIface;
\r
80 for(i=0;i<lstRef.size();i++) {
\r
82 inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));
\r
84 catch(Exception e) {
\r
85 cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;
\r
88 hashIface.insert(lstRef.at(i),inter);
\r
90 addInterface(inter);
\r
93 AbstractInterface* funCtlIface = NULL;
\r
94 AbstractInterface* funDataIface = NULL;
\r
96 for(i=0;i<lstRef.size();i++) {
\r
97 AbstractInterface* refIface = lstRef.at(i);
\r
98 if (refIface->getPurpose() == AbstractInterface::Control) {
\r
99 funCtlIface = hashIface.value(refIface);
\r
100 funDataIface = hashIface.value(refIface->getAssociatedIface());
\r
101 if (! funCtlIface->setAssociatedIface(funDataIface)) {
\r
102 cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;
\r
110 QString FunctionalBlock::getReferenceXmlFile() {
\r
111 return ((ReferenceBlock *)reference)->getXmlFile();
\r
114 QString FunctionalBlock::getReferenceHashMd5() {
\r
115 return ((ReferenceBlock *)reference)->getHashMd5();
\r
118 bool FunctionalBlock::createPatterns() {
\r
119 static QString fctName = "FunctionalBlock::createPatterns()";
\r
120 #ifdef DEBUG_FCTNAME
\r
121 cout << "call to " << qPrintable(fctName) << endl;
\r
124 cout << "create patterns for block " << qPrintable(name) << endl;
\r
125 evaluator = new ArithmeticEvaluator();
\r
127 if (! isGeneratorBlock()) {
\r
128 ok = ok & createDelta();
\r
129 if (ok) ok = ok & createConsumptionPattern();
\r
130 if (ok) ok = ok & createProductionCounter();
\r
132 if (ok) ok = ok & createProductionPattern();
\r
137 bool FunctionalBlock::createDelta() {
\r
138 static QString fctName = "FunctionalBlock::createDelta()";
\r
139 #ifdef DEBUG_FCTNAME
\r
140 cout << "call to " << qPrintable(fctName) << endl;
\r
143 QString deltaStr = implementation->getDelta();
\r
144 cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;
\r
145 if (deltaStr.isEmpty()) {
\r
150 // look for parameter names
\r
152 double result = evaluateExpression(deltaStr, &ok);
\r
153 if (!ok) return false;
\r
156 cout << "delta = " << delta << endl;
\r
161 bool FunctionalBlock::createConsumptionPattern() {
\r
162 static QString fctName = "FunctionalBlock::createConsumptionPattern()";
\r
163 #ifdef DEBUG_FCTNAME
\r
164 cout << "call to " << qPrintable(fctName) << endl;
\r
169 QHash<QString,QString> consPattern = implementation->getConsumptionPattern();
\r
171 foreach(AbstractInterface* iface, getControlInputs()) {
\r
172 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
173 QString refName = connIface->getReference()->getName();
\r
174 if (! consPattern.contains(refName)) {
\r
175 cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;
\r
178 QList<char>* pattern = expandPattern(consPattern.value(refName),&ok);
\r
179 if (!ok) return false;
\r
180 consumptionPattern.insert(connIface,pattern);
\r
181 if (lengthCP == -1) {
\r
182 lengthCP = pattern->size();
\r
185 if (pattern->size() != lengthCP) return false;
\r
191 bool FunctionalBlock::createProductionPattern() {
\r
192 static QString fctName = "FunctionalBlock::createProductionPattern()";
\r
193 #ifdef DEBUG_FCTNAME
\r
194 cout << "call to " << qPrintable(fctName) << endl;
\r
199 QHash<QString,QString> prodPattern = implementation->getProductionPattern();
\r
201 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
202 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
203 QString refName = connIface->getReference()->getName();
\r
204 if (! prodPattern.contains(refName)) {
\r
205 cerr << "no production pattern for reference interface " << qPrintable(refName) << endl;
\r
208 QList<char>* pattern = expandPattern(prodPattern.value(refName),&ok);
\r
209 if (!ok) return false;
\r
210 productionPattern.insert(connIface,pattern);
\r
211 if (lengthPP == -1) {
\r
212 lengthPP = pattern->size();
\r
215 if (pattern->size() != lengthPP) return false;
\r
221 bool FunctionalBlock::createProductionCounter() {
\r
222 static QString fctName = "FunctionalBlock::createProductionCounter()";
\r
223 #ifdef DEBUG_FCTNAME
\r
224 cout << "call to " << qPrintable(fctName) << endl;
\r
227 QStringList counterParts = implementation->getProductionCounter().split(",");
\r
228 foreach(QString s, counterParts) {
\r
229 cout << "cont part = " << qPrintable(s) << endl;
\r
231 double val = s.toDouble(&ok);
\r
233 productionCounter.append(val);
\r
235 else if (s.at(0) == '{') {
\r
238 QStringList gen = s.split(":");
\r
239 if (gen.size() != 3) return false;
\r
243 for(int i=0;i<3;i++) {
\r
245 double result = evaluateExpression(gen.at(i),&okVal);
\r
246 if (!okVal) return false;
\r
247 if (i==0) start = result;
\r
248 else if (i==1) nb = result;
\r
249 else if (i==2) step = result;
\r
251 for(int j=0;j<nb;j++) {
\r
252 productionCounter.append(start+j*step);
\r
257 double result = evaluateExpression(s,&okVal);
\r
259 if (!okVal) return false;
\r
260 productionCounter.append(result);
\r
263 foreach(int val, productionCounter) {
\r
264 cout << val << ",";
\r
271 QList<char>* FunctionalBlock::expandPattern(const QString& patternIn, bool* ok) {
\r
272 static QString fctName = "FunctionalBlock::expandPattern()";
\r
273 #ifdef DEBUG_FCTNAME
\r
274 cout << "call to " << qPrintable(fctName) << endl;
\r
278 QString p = patternIn;
\r
281 QList<char>* patternOut = new QList<char>();
\r
282 expandPatternRecur(p,&offset,ok,patternOut);
\r
286 void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, bool *ok, QList<char>* patternOut) {
\r
288 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {
\r
290 QChar c = patternIn.at(*offset);
\r
293 expandPatternRecur(patternIn,offset, ok, patternOut);
\r
298 else if (c == '0') {
\r
299 patternOut->append(0);
\r
301 else if (c == '1') {
\r
302 patternOut->append(1);
\r
304 else if (c == 'X') {
\r
305 patternOut->append(-1);
\r
307 else if (c == '{') {
\r
309 QString expr = "";
\r
310 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
311 expr += patternIn.at(*offset);
\r
314 if (*offset == patternIn.size()) {
\r
318 double repeat = evaluateExpression(expr,ok);
\r
322 // repeat just the last value in currentGroup
\r
323 char last = patternOut->last();
\r
324 //cout << "repeat last char " << repeat << " times : " << (int)last << endl;
\r
326 for(int i=1;i<(int)repeat;i++) {
\r
327 patternOut->append(last);
\r
333 // must check if after ), there is a {
\r
334 if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {
\r
336 QString expr = "";
\r
337 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
338 expr += patternIn.at(*offset);
\r
341 if (*offset == patternIn.size()) {
\r
345 double repeat = evaluateExpression(expr,ok);
\r
350 cout << "repeat last group " << repeat << " times : ";
\r
351 foreach (char c, currentGroup) cout <<(int)c;
\r
354 QList<char> single = *patternOut;
\r
355 for(int i=1;i<(int)repeat;i++) {
\r
356 patternOut->append(single);
\r
363 double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) {
\r
364 static QString fctName = "FunctionalBlock::evaluateExpression()";
\r
365 #ifdef DEBUG_FCTNAME
\r
366 cout << "call to " << qPrintable(fctName) << endl;
\r
370 QHash<QString,double> vars;
\r
371 evaluator->setExpression(expression);
\r
372 QList<QString> varNames = evaluator->getVariableNames();
\r
373 foreach (QString name, varNames) {
\r
374 QString paramName = name;
\r
375 paramName.remove(0,1);
\r
376 BlockParameter* param = reference->getParameterFromName(paramName);
\r
377 if (param == NULL) {
\r
378 cerr << "found an unknown parameter in delta"<< endl;
\r
383 int val = param->getDoubleValue(&okVal);
\r
385 cerr << "cannot obtain double value of paramter " << qPrintable(paramName) << endl;
\r
389 vars.insert(name,(double)val);
\r
392 evaluator->setVariablesValue(vars);
\r
395 result = evaluator->evaluate();
\r
398 cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;
\r
405 void FunctionalBlock::createInputPattern() {
\r
406 static QString fctName = "FunctionalBlock::createInputPattern())";
\r
407 #ifdef DEBUG_FCTNAME
\r
408 cout << "call to " << qPrintable(fctName) << endl;
\r
412 foreach(AbstractInterface* iface, getControlInputs()) {
\r
413 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
414 QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
\r
415 if (lengthIP == -1) {
\r
416 lengthIP = out->size();
\r
419 if (out->size() < lengthIP) lengthIP = out->size();
\r
421 if (out->size() > 0) {
\r
422 QList<char>* in = new QList<char>(*out);
\r
423 foreach(char c, *in) {
\r
428 inputPattern.insert(connIface,in);
\r
431 inputPattern.insert(connIface,NULL);
\r
436 bool FunctionalBlock::createAdmittance(int nbExec) {
\r
437 static QString fctName = "FunctionalBlock::createAdmittance()";
\r
438 #ifdef DEBUG_FCTNAME
\r
439 cout << "call to " << qPrintable(fctName) << endl;
\r
442 // firstly, copy CP in AP
\r
443 QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);
\r
444 while (iterC.hasNext()) {
\r
446 QList<char>* pattern = new QList<char>(*(iterC.value()));
\r
447 admittance.insert(iterC.key(), pattern);
\r
449 lengthAP = lengthCP;
\r
451 cout << "trigger 1 at c.c. 0" << endl;
\r
452 for(int i=1;i<nbExec;i++) {
\r
453 // searching for the clock cycle for which a new exec starts
\r
455 while ((clock < lengthAP) && (nbGroup < delta)) {
\r
456 if (isValidDataGroup(admittance,clock)) nbGroup+=1;
\r
459 while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;
\r
460 cout << "trigger " << (i+1) << " at c.c. " << clock << endl;
\r
462 // combine CP with AP at sc
\r
463 for(int j=0;j<lengthCP;j++) {
\r
464 // first case : column of CP must be placed beyond AP's end.
\r
465 if (sc == lengthAP) {
\r
466 cout << i << "," << j << " append in AP at " << sc << endl;
\r
467 appendToPattern(consumptionPattern,j,admittance,1);
\r
471 // second case : CP and AP can be combined directly (i.e. no X | 1 to do)
\r
472 else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
473 cout << i << "," << j << " combine at " << sc << endl;
\r
474 combinePatterns(consumptionPattern,j,admittance,sc);
\r
477 // third case : CP has an X column
\r
478 else if (isOnlyXDataGroup(consumptionPattern,j)) {
\r
479 cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;
\r
480 shiftRightPattern(admittance,sc);
\r
482 if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
483 cerr << "Abnormal case when combining AP and CP" << endl;
\r
485 combinePatterns(consumptionPattern,j,admittance,sc);
\r
488 // fourth case : AP has an X column
\r
489 else if (isOnlyXDataGroup(admittance,sc)) {
\r
490 cout << i << "," << j << " jump c.c. for CP at " << sc << endl;
\r
495 cout << "AP and CP are not consistent" << endl;
\r
500 // turn all X into 0
\r
501 QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);
\r
502 while (iterA.hasNext()) {
\r
504 QList<char>* pattern = iterA.value();
\r
505 for(int i=0;i<pattern->size();i++) {
\r
506 if (pattern->at(i) == -1) pattern->replace(i,0);
\r
512 bool FunctionalBlock::checkInputPatternCompatibility() {
\r
513 static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";
\r
514 #ifdef DEBUG_FCTNAME
\r
515 cout << "call to " << qPrintable(fctName) << endl;
\r
519 // firstly, create input pattern
\r
520 createInputPattern();
\r
521 // if some patterns are not available, end now, returning false
\r
522 if (lengthIP == 0) {
\r
523 clearInputPattern();
\r
526 int nbExec = getNumberOfExecution();
\r
527 ok = createAdmittance(nbExec);
\r
528 if (!ok) return false;
\r
530 int clock = 0; // index in IP
\r
531 int i = 0; // index in AP
\r
532 while (clock < lengthIP) {
\r
533 if (samePatterns(inputPattern,clock,admittance,i)) {
\r
538 if (isValidDataGroup(admittance,i)) {
\r
542 // IP and AP are not equal and AP is a valid group -> not compatible
\r
551 bool FunctionalBlock::computeOutputPattern(int nbExec) {
\r
552 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
553 #ifdef DEBUG_FCTNAME
\r
554 cout << "call to " << qPrintable(fctName) << endl;
\r
557 /* case 1: the block is a generator for which output pattern
\r
558 must be computed for a nbExec following executions
\r
563 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
564 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
565 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
566 // create output pattern
\r
567 QList<char>* pp = productionPattern.value(connIface);
\r
568 QList<char>* pattern = new QList<char>(*pp);
\r
569 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
570 // assign pattern to interface
\r
571 connIface->setOutputPattern(pattern);
\r
572 // store it in QMap
\r
573 outputPattern.insert(connIface,pattern);
\r
577 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
579 // in case of inputPattern not created, do it
\r
580 if (lengthIP <= 0) {
\r
581 // collect the input patterns for each input
\r
582 createInputPattern();
\r
583 // if some patterns are not available, end now, returning false
\r
584 if (lengthIP == 0) {
\r
585 clearInputPattern();
\r
588 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
591 // initialize the output pattern
\r
593 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
594 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
595 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
596 QList<char>* pattern = new QList<char>();
\r
597 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
598 connIface->setOutputPattern(pattern);
\r
599 outputPattern.insert(connIface,pattern);
\r
601 cout << "output pattern array initialized" << endl;
\r
605 // search for the beginning of the first execution.
\r
606 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
607 cout << "found 1st exec clock: " << clock << endl;
\r
609 while (clock < lengthIP) {
\r
610 // initialize counters for current execution.
\r
611 int p = 0; // index in production pattern
\r
612 int o = 0; // clock+o will give the clock cycle of each output group
\r
613 int cip = 0; // clock+cip give the clock cycle of an input group
\r
614 int ccp = 0; // ccp give a column in the consumptio pattern
\r
615 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
616 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
617 bool cannotCompleteExec = false;
\r
618 for(int m=0;m<productionCounter.size();m++) {
\r
619 // search for the first production in PP
\r
620 while (!isValidDataGroup(productionPattern,p)) {
\r
624 int gap = 0; // count the number of extra null columns
\r
625 // search for PC(m) valid input group in IP
\r
626 while (nip < productionCounter.at(m)) {
\r
627 if (clock+cip < lengthIP) {
\r
628 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
633 cannotCompleteExec = true;
\r
638 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
640 // search for PC(m) valid input group in IP
\r
641 while (ncp < productionCounter.at(m)) {
\r
642 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
646 o += gap; // to take into acocunt of extra null columns
\r
647 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
652 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
654 // current exec. taken into accunt
\r
657 // search for the next exec.
\r
660 while ((clock < lengthIP) && (nip < delta)) {
\r
661 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
662 if (nip < delta) clock += 1;
\r
664 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
666 // find the last valid output data group
\r
667 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
668 removeDataGroup(outputPattern,lengthOP-1);
\r
672 // clear input pattern
\r
673 clearInputPattern();
\r
678 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
680 if (patternSrc.size() != patternDest.size()) return false;
\r
681 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
682 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
683 while (iterSrc.hasNext()) {
\r
686 QList<char>* srcPat = iterSrc.value();
\r
687 QList<char>* destPat = iterDest.value();
\r
688 if (srcCol >= srcPat->size()) return false;
\r
689 if (destCol >= destPat->size()) return false;
\r
690 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
695 bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
696 if (patternSrc.size() != patternDest.size()) return false;
\r
697 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
698 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
699 while (iterSrc.hasNext()) {
\r
702 QList<char>* srcPat = iterSrc.value();
\r
703 QList<char>* destPat = iterDest.value();
\r
704 if (srcCol >= srcPat->size()) return false;
\r
705 if (destCol >= destPat->size()) return false;
\r
706 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return false;
\r
707 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;
\r
712 void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
713 if (patternSrc.size() != patternDest.size()) return;
\r
714 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
715 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
716 while (iterSrc.hasNext()) {
\r
719 QList<char>* srcPat = iterSrc.value();
\r
720 QList<char>* destPat = iterDest.value();
\r
721 if (srcCol >= srcPat->size()) return;
\r
722 if (destCol >= destPat->size()) return;
\r
723 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;
\r
724 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return;
\r
725 destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));
\r
729 void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {
\r
730 if (patternSrc.size() != patternDest.size()) return;
\r
731 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
732 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
733 while (iterSrc.hasNext()) {
\r
736 QList<char>* srcPat = iterSrc.value();
\r
737 QList<char>* destPat = iterDest.value();
\r
739 while ((srcCol+i < srcPat->size()) && (i<nbCols)) {
\r
740 destPat->append(srcPat->at(srcCol+i));
\r
746 void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
747 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
748 while (iterSrc.hasNext()) {
\r
750 QList<char>* srcPat = iterSrc.value();
\r
751 if (offset < srcPat->size()) {
\r
752 srcPat->removeAt(offset);
\r
757 void FunctionalBlock::shiftRightPattern(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
758 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
759 while (iterSrc.hasNext()) {
\r
761 QList<char>* srcPat = iterSrc.value();
\r
762 if (offset < srcPat->size()) {
\r
763 srcPat->insert(offset,0);
\r
768 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
769 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
770 while (iterSrc.hasNext()) {
\r
772 QList<char>* srcPat = iterSrc.value();
\r
773 if (offset >= srcPat->size()) return false;
\r
774 if (srcPat->at(offset) == 1) return true;
\r
779 bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
780 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
781 while (iterSrc.hasNext()) {
\r
783 QList<char>* srcPat = iterSrc.value();
\r
784 if (offset >= srcPat->size()) return false;
\r
785 if (srcPat->at(offset) != -1) return false;
\r
790 void FunctionalBlock::clearConsumptionPattern() {
\r
791 QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern);
\r
792 while (iterP.hasNext()) {
\r
794 QList<char>* pattern = iterP.value();
\r
795 if (pattern != NULL) delete pattern;
\r
797 consumptionPattern.clear();
\r
801 void FunctionalBlock::clearProductionPattern() {
\r
802 QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern);
\r
803 while (iterP.hasNext()) {
\r
805 QList<char>* pattern = iterP.value();
\r
806 if (pattern != NULL) delete pattern;
\r
808 productionPattern.clear();
\r
812 void FunctionalBlock::clearInputPattern() {
\r
814 QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);
\r
815 while (iterI.hasNext()) {
\r
817 QList<char>* pattern = iterI.value();
\r
818 if (pattern != NULL) delete pattern;
\r
820 inputPattern.clear();
\r
824 int FunctionalBlock::getNumberOfExecution() {
\r
825 /* NB: this method returns the number of executions that have been started
\r
826 but not necessary completed.
\r
828 if (delta <= 0) return 0;
\r
831 // search for the first exec.
\r
832 while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;
\r
833 if (offset == lengthIP) return 0;
\r
836 for(int i = offset;i<lengthIP;i++) {
\r
837 if (isValidDataGroup(inputPattern,offset)) nbGroup++;
\r
838 if (nbGroup == delta+1) {
\r