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(Graph *_graph, GroupBlock *_parent, ReferenceBlock *_reference, bool createIfaces) throw(Exception) : AbstractBlock(_graph) {
\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 // create parameters from reference block
\r
35 QList<BlockParameter*> lstParam = reference->getParameters();
\r
36 for(int i=0;i<lstParam.size();i++) {
\r
37 p = lstParam.at(i)->clone();
\r
46 FunctionalBlock::~FunctionalBlock() {
\r
47 if (evaluator != NULL) delete evaluator;
\r
50 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
\r
52 checkedBlocks->append(this);
\r
54 foreach(BlockParameter* param, params){
\r
55 if(param->isUserParameter() && !param->isValueSet()){
\r
56 if(!blocksToConfigure->contains(param->getOwner())){
\r
57 blocksToConfigure->append(param->getOwner());
\r
61 foreach(AbstractInterface *inter, outputs){
\r
62 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
63 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
64 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
71 bool FunctionalBlock::isFunctionalBlock() {
\r
75 bool FunctionalBlock::isStimuliBlock() {
\r
76 if (parent == NULL) return true;
\r
80 void FunctionalBlock::populate() {
\r
83 AbstractInterface* inter;
\r
84 ConnectedInterface* toClk = NULL;
\r
85 ConnectedInterface* toRst = NULL;
\r
86 // create interfaces from reference block
\r
87 QList<AbstractInterface *> lstRef = reference->getInterfaces();
\r
88 // store relation between functional and reference
\r
89 QHash<AbstractInterface *, AbstractInterface *> hashIface;
\r
90 for(i=0;i<lstRef.size();i++) {
\r
92 inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));
\r
94 catch(Exception e) {
\r
95 cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;
\r
98 hashIface.insert(lstRef.at(i),inter);
\r
99 addInterface(inter);
\r
100 /* WARNING FOR THE FUTURE :
\r
101 in case of there are several clock interfaces ofr that block
\r
102 it would be a good idea to make the user choose which one
\r
103 must be connected to defautl clk.
\r
104 Presently, the first encountered is chosen
\r
106 if ((toClk == NULL) && (inter->getPurpose() == AbstractInterface::Clock)) {
\r
107 toClk = AI_TO_CON(inter);
\r
109 if ((toRst == NULL) && (inter->getPurpose() == AbstractInterface::Reset)) {
\r
110 toRst = AI_TO_CON(inter);
\r
114 AbstractInterface* funCtlIface = NULL;
\r
115 AbstractInterface* funDataIface = NULL;
\r
117 for(i=0;i<lstRef.size();i++) {
\r
118 AbstractInterface* refIface = lstRef.at(i);
\r
119 if (refIface->getPurpose() == AbstractInterface::Control) {
\r
120 funCtlIface = hashIface.value(refIface);
\r
121 funDataIface = hashIface.value(refIface->getAssociatedIface());
\r
122 if (! funCtlIface->setAssociatedIface(funDataIface)) {
\r
123 cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;
\r
130 QString FunctionalBlock::getReferenceXmlFile() {
\r
131 return ((ReferenceBlock *)reference)->getXmlFile();
\r
134 QString FunctionalBlock::getReferenceHashMd5() {
\r
135 return ((ReferenceBlock *)reference)->getHashMd5();
\r
138 void FunctionalBlock::createPatterns() throw(Exception) {
\r
139 static QString fctName = "FunctionalBlock::createPatterns()";
\r
140 #ifdef DEBUG_FCTNAME
\r
141 cout << "call to " << qPrintable(fctName) << endl;
\r
144 if (implementation->hasNoPatterns()) return;
\r
146 cout << "create patterns for block " << qPrintable(name) << endl;
\r
147 if (evaluator == NULL) evaluator = new ArithmeticEvaluator();
\r
148 if (! isSourceBlock()) {
\r
151 createConsumptionPattern();
\r
152 createProductionCounter();
\r
154 catch(Exception e) {
\r
155 throw(e); // rethrow e
\r
159 createProductionPattern();
\r
161 catch(Exception e) {
\r
164 cout << "PP of " << qPrintable(name) << endl;
\r
165 QMapIterator<AbstractInterface*,QList<char>* > it(productionPattern);
\r
166 while (it.hasNext()) {
\r
168 QList<char>* pat = it.value();
\r
169 foreach(char c, *pat) cout << (int)c;
\r
174 void FunctionalBlock::createDelta() throw(Exception) {
\r
175 static QString fctName = "FunctionalBlock::createDelta()";
\r
176 #ifdef DEBUG_FCTNAME
\r
177 cout << "call to " << qPrintable(fctName) << endl;
\r
180 QString deltaStr = implementation->getDelta();
\r
181 cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;
\r
182 if (deltaStr.isEmpty()) {
\r
187 // look for parameter names
\r
190 result = evaluateExpression(deltaStr);
\r
192 catch(Exception e) {
\r
196 cout << "delta = " << delta << endl;
\r
199 void FunctionalBlock::createConsumptionPattern() throw(Exception) {
\r
200 static QString fctName = "FunctionalBlock::createConsumptionPattern()";
\r
201 #ifdef DEBUG_FCTNAME
\r
202 cout << "call to " << qPrintable(fctName) << endl;
\r
205 // first clear if already exists
\r
206 clearConsumptionPattern();
\r
209 QHash<QString,QString> consPattern = implementation->getConsumptionPattern();
\r
211 foreach(AbstractInterface* iface, getControlInputs()) {
\r
212 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
213 QString refName = connIface->getReference()->getName();
\r
214 if (! consPattern.contains(refName)) {
\r
215 throw(Exception(NO_IFACE_CP,this));
\r
216 cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;
\r
218 QList<char>* pattern = NULL;
\r
220 pattern = expandPattern(consPattern.value(refName));
\r
222 catch(Exception e) {
\r
225 consumptionPattern.insert(connIface,pattern);
\r
226 if (lengthCP == -1) {
\r
227 lengthCP = pattern->size();
\r
230 if (pattern->size() != lengthCP) {
\r
231 throw(Exception(INVALID_IFACE_CP_LENGTH,this));
\r
237 void FunctionalBlock::createProductionPattern() throw(Exception){
\r
238 static QString fctName = "FunctionalBlock::createProductionPattern()";
\r
239 #ifdef DEBUG_FCTNAME
\r
240 cout << "call to " << qPrintable(fctName) << endl;
\r
243 // first clear if already exists
\r
244 clearProductionPattern();
\r
247 QHash<QString,QString> prodPattern = implementation->getProductionPattern();
\r
249 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
250 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
251 QString refName = connIface->getReference()->getName();
\r
252 if (! prodPattern.contains(refName)) {
\r
253 throw(Exception(NO_IFACE_PP,this));
\r
255 QList<char>* pattern = NULL;
\r
257 pattern = expandPattern(prodPattern.value(refName));
\r
259 catch(Exception e) {
\r
262 productionPattern.insert(connIface,pattern);
\r
263 if (lengthPP == -1) {
\r
264 lengthPP = pattern->size();
\r
267 if (pattern->size() != lengthPP) {
\r
268 throw(Exception(INVALID_IFACE_PP_LENGTH,this));
\r
274 void FunctionalBlock::createProductionCounter() throw(Exception) {
\r
275 static QString fctName = "FunctionalBlock::createProductionCounter()";
\r
276 #ifdef DEBUG_FCTNAME
\r
277 cout << "call to " << qPrintable(fctName) << endl;
\r
280 // first clear if already exists
\r
281 productionCounter.clear();
\r
284 QStringList counterParts = implementation->getProductionCounter().split(",");
\r
285 foreach(QString s, counterParts) {
\r
286 cout << "cont part = " << qPrintable(s) << endl;
\r
288 double val = s.toDouble(&ok);
\r
290 productionCounter.append(val);
\r
292 else if (s.at(0) == '{') {
\r
295 QStringList gen = s.split(":");
\r
296 if (gen.size() != 3) {
\r
297 throw(Exception(INVALID_IFACE_PC,this));
\r
302 for(int i=0;i<3;i++) {
\r
303 double result = 0.0;
\r
305 result = evaluateExpression(gen.at(i));
\r
307 catch(Exception e) {
\r
310 if (i==0) start = result;
\r
311 else if (i==1) nb = result;
\r
312 else if (i==2) step = result;
\r
314 for(int j=0;j<nb;j++) {
\r
315 productionCounter.append(start+j*step);
\r
319 double result = 0.0;
\r
321 result = evaluateExpression(s);
\r
323 catch(Exception e) {
\r
326 productionCounter.append(result);
\r
329 foreach(int val, productionCounter) {
\r
330 cout << val << ",";
\r
335 QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {
\r
336 static QString fctName = "FunctionalBlock::expandPattern()";
\r
337 #ifdef DEBUG_FCTNAME
\r
338 cout << "call to " << qPrintable(fctName) << endl;
\r
340 /* expanding a pattern is done in two steps :
\r
341 - 1 : finding all variables that correspond to an expression
\r
342 and copy them in the pattern
\r
343 - 2 : parsing the result
\r
345 Note that the result MUST contain only variables that have a
\r
346 integer/double value. Otherwise, expanding will fail.
\r
352 QString p = replaceExpressions(patternIn);
\r
357 QList<char>* patternOut = new QList<char>();
\r
359 patternOut->append(expandPatternRecur(p,&offset));
\r
361 catch(Exception e) {
\r
368 QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) {
\r
370 QString res = patternIn;
\r
372 QRegularExpression re("[$][a-zA-Z0-9_]+");
\r
376 QRegularExpressionMatchIterator matcher = re.globalMatch(res);
\r
377 while(matcher.hasNext()) {
\r
378 QRegularExpressionMatch m = matcher.next();
\r
379 QString param = m.captured(0);
\r
380 QString paramName = param;
\r
381 paramName.remove(0,1);
\r
382 BlockParameter* p = getParameterFromName(paramName);
\r
383 if ((p != NULL) && (p->getType() == BlockParameter::Expression)) {
\r
384 res.replace(param,p->getStringValue());
\r
386 cout << "found an expr: " << qPrintable(paramName) << ", patern => " << qPrintable(res) << endl;
\r
393 QList<char> FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) {
\r
395 QList<char> patternOut;
\r
397 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {
\r
399 QChar c = patternIn.at(*offset);
\r
403 patternOut.append(expandPatternRecur(patternIn,offset));
\r
405 catch(Exception e) {
\r
409 else if (c == '0') {
\r
410 patternOut.append(0);
\r
412 else if (c == '1') {
\r
413 patternOut.append(1);
\r
415 else if (c == 'X') {
\r
416 patternOut.append(-1);
\r
418 else if (c == '{') {
\r
420 QString expr = "";
\r
421 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
422 expr += patternIn.at(*offset);
\r
425 if (*offset == patternIn.size()) {
\r
426 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
430 repeat = evaluateExpression(expr);
\r
432 catch(Exception e) {
\r
437 patternOut.removeLast();
\r
440 // repeat just the last value in currentGroup
\r
441 char last = patternOut.last();
\r
442 //cout << "repeat last char " << repeat << " times : " << (int)last << endl;
\r
443 for(int i=1;i<(int)repeat;i++) {
\r
444 patternOut.append(last);
\r
451 // must check if after ), there is a {
\r
452 if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {
\r
454 QString expr = "";
\r
455 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
456 expr += patternIn.at(*offset);
\r
459 if (*offset == patternIn.size()) {
\r
460 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
464 repeat = evaluateExpression(expr);
\r
466 catch(Exception e) {
\r
470 QList<char> voidList;
\r
475 cout << "repeat last group " << repeat << " times : ";
\r
476 foreach (char c, currentGroup) cout <<(int)c;
\r
479 QList<char> single = patternOut;
\r
480 for(int i=1;i<(int)repeat;i++) {
\r
481 patternOut.append(single);
\r
488 double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {
\r
489 static QString fctName = "FunctionalBlock::evaluateExpression()";
\r
490 #ifdef DEBUG_FCTNAME
\r
491 cout << "call to " << qPrintable(fctName) << endl;
\r
494 QHash<QString,double> vars;
\r
495 evaluator->setExpression(expression);
\r
496 QList<QString> varNames = evaluator->getVariableNames();
\r
497 foreach (QString name, varNames) {
\r
498 QString paramName = name;
\r
499 paramName.remove(0,1);
\r
500 BlockParameter* param = getParameterFromName(paramName);
\r
501 if (param == NULL) {
\r
502 throw(Exception(EVAL_PARAM_UNKNOWN,this));
\r
505 int val = param->getDoubleValue(&okVal);
\r
507 throw(Exception(EVAL_PARAM_NOVALUE,this));
\r
509 vars.insert(name,(double)val);
\r
512 evaluator->setVariablesValue(vars);
\r
513 double result = 0.0;
\r
515 result = evaluator->evaluate();
\r
518 cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;
\r
519 throw(Exception(EVAL_INVALID_EXPR,this));
\r
524 void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {
\r
525 static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";
\r
526 #ifdef DEBUG_FCTNAME
\r
527 cout << "call to " << qPrintable(fctName) << endl;
\r
529 QList<int> inClock;
\r
532 clearAdmittanceDelays();
\r
534 // trying to synchronize the first one in AP
\r
535 QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);
\r
536 QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);
\r
538 while (iterAP.hasNext()) {
\r
541 QList<char>* ap = iterAP.value();
\r
542 QList<char>* ip = iterIP.value();
\r
544 while ((first < lengthIP) && (ip->at(first) == 0)) first++;
\r
545 while ((first < lengthAP) && (ap->at(first) == 0)) first--;
\r
546 delays.append(first);
\r
548 QList<int>* delays = new QList<int>();
\r
549 admittanceDelays.insert(iterAP.key(), delays);
\r
552 QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);
\r
554 // get the delay to apply
\r
556 for(int i=0;i<delays.size();i++) {
\r
557 if (delays[i] > maxDelay) maxDelay = delays[i];
\r
559 // adding the delays to IP
\r
562 while (iterIP.hasNext()) {
\r
565 QList<char>* ip = iterIP.value();
\r
566 QList<int>* d = iterDelays.value();
\r
567 d->append(maxDelay-delays[i]);
\r
568 cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;
\r
569 for(int j=0;j<maxDelay-delays[i];j++) {
\r
572 for(int j=0;j<delays[i];j++) {
\r
577 lengthIP += maxDelay;
\r
579 cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;
\r
585 // if AP is a valid group, search for the next valid group in IP
\r
586 if (isValidDataGroup(admittance,apIndex)) {
\r
588 while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;
\r
589 if (ipIndex == lengthIP) {
\r
597 iterDelays.toFront();
\r
599 if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {
\r
600 while (iterAP.hasNext()) {
\r
603 QList<char>* ap = iterAP.value();
\r
604 if (ap->at(apIndex) == 1) {
\r
605 QList<int>* d = iterDelays.value();
\r
606 d->append(0); // the 1 is at its good place, so no delay
\r
611 cout << "diff between IP and AP at " << apIndex << endl;
\r
612 // search for the next 1 in IP for every input that has a 1 in AP
\r
614 while (iterAP.hasNext()) {
\r
618 QList<char>* ap = iterAP.value();
\r
619 QList<char>* ip = iterIP.value();
\r
620 QList<int>* d = iterDelays.value();
\r
621 // case 1: 1 in IP is too late
\r
622 if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {
\r
624 while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;
\r
625 cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
626 // moving the 1 to its normal pos.
\r
627 ip->replace(ipIndex,1);
\r
628 ip->replace(ipIndex+delay,0);
\r
631 // case 2: 1 in IP is too soon
\r
632 else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {
\r
634 while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;
\r
635 cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
636 // search for next 0 in IP to put the 1
\r
637 int k = ipIndex+delay;
\r
638 while ((k < lengthIP) && (ip->at(k) == 1)) k++;
\r
639 ip->replace(ipIndex,0);
\r
644 if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {
\r
645 cout << "Abnormal case while searching for delays" << endl;
\r
651 if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;
\r
653 iterDelays.toFront();
\r
654 while (iterDelays.hasNext()) {
\r
656 QList<int>* d = iterDelays.value();
\r
657 foreach(int v, *d) {
\r
665 void FunctionalBlock::createInputPattern() throw(Exception) {
\r
666 static QString fctName = "FunctionalBlock::createInputPattern())";
\r
667 #ifdef DEBUG_FCTNAME
\r
668 cout << "call to " << qPrintable(fctName) << endl;
\r
672 foreach(AbstractInterface* iface, getControlInputs()) {
\r
674 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
675 // check if it is connected
\r
676 if (connIface->getConnectedFrom() == NULL) {
\r
677 throw(Exception(IFACE_NOT_CONNECTED,this));
\r
679 // get the precursor output pattern
\r
680 QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
\r
681 AbstractInputModifier* modifier = connIface->getInputModifier();
\r
682 // check if the input is modified
\r
683 if (modifier != NULL) {
\r
685 out = modifier->getModifiedInput(out);
\r
688 if (out->size() == 0) {
\r
689 clearInputPattern();
\r
690 throw(Exception(NO_IFACE_IP,this));
\r
692 if (lengthIP == -1) {
\r
693 lengthIP = out->size();
\r
696 if (out->size() < lengthIP) lengthIP = out->size();
\r
699 QList<char>* in = new QList<char>(*out);
\r
700 foreach(char c, *in) {
\r
704 inputPattern.insert(connIface,in);
\r
706 // search the last valid group in IP,
\r
707 while(! isValidDataGroup(inputPattern,lengthIP-1)) {
\r
708 //removeDataGroup(inputPattern,lengthIP-1);
\r
713 void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {
\r
714 static QString fctName = "FunctionalBlock::createAdmittance()";
\r
715 #ifdef DEBUG_FCTNAME
\r
716 cout << "call to " << qPrintable(fctName) << endl;
\r
718 // firstly, copy CP in AP
\r
719 QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);
\r
720 while (iterC.hasNext()) {
\r
722 QList<char>* pattern = new QList<char>(*(iterC.value()));
\r
723 admittance.insert(iterC.key(), pattern);
\r
725 lengthAP = lengthCP;
\r
727 cout << "trigger 1 at c.c. 0" << endl;
\r
728 for(int i=1;i<nbExec;i++) {
\r
729 // searching for the clock cycle for which a new exec starts
\r
731 while ((clock < lengthAP) && (nbGroup < delta)) {
\r
732 if (isValidDataGroup(admittance,clock)) nbGroup+=1;
\r
735 while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;
\r
736 cout << "trigger " << (i+1) << " at c.c. " << clock << endl;
\r
738 // combine CP with AP at sc
\r
739 for(int j=0;j<lengthCP;j++) {
\r
740 // first case : column of CP must be placed beyond AP's end.
\r
741 if (sc == lengthAP) {
\r
742 cout << i << "," << j << " append in AP at " << sc << endl;
\r
743 appendToPattern(consumptionPattern,j,admittance,1);
\r
747 // second case : CP and AP can be combined directly (i.e. no X | 1 to do)
\r
748 else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
749 cout << i << "," << j << " combine at " << sc << endl;
\r
750 combinePatterns(consumptionPattern,j,admittance,sc);
\r
753 // third case : CP has an X column
\r
754 else if (isOnlyXDataGroup(consumptionPattern,j)) {
\r
755 cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;
\r
756 shiftRightPattern(admittance,sc);
\r
758 if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
759 cerr << "Abnormal case when combining AP and CP" << endl;
\r
761 combinePatterns(consumptionPattern,j,admittance,sc);
\r
764 // fourth case : AP has an X column
\r
765 else if (isOnlyXDataGroup(admittance,sc)) {
\r
766 cout << i << "," << j << " jump c.c. for CP at " << sc << endl;
\r
771 throw(INVALID_DELTA_CP);
\r
775 // turn all X into 0
\r
776 QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);
\r
777 while (iterA.hasNext()) {
\r
779 QList<char>* pattern = iterA.value();
\r
780 for(int i=0;i<pattern->size();i++) {
\r
781 if (pattern->at(i) == -1) pattern->replace(i,0);
\r
782 cout << (int)(pattern->at(i));
\r
788 void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {
\r
789 static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";
\r
790 #ifdef DEBUG_FCTNAME
\r
791 cout << "call to " << qPrintable(fctName) << endl;
\r
794 // firstly, create input pattern
\r
796 createInputPattern();
\r
798 catch(Exception e) {
\r
801 int nbExec = createTriggers();
\r
802 cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;
\r
805 createAdmittance(nbExec);
\r
807 catch(Exception e) {
\r
808 cout << "cannot create admittance" << endl;
\r
812 int clock = 0; // index in IP
\r
813 int i = 0; // index in AP
\r
814 while ((clock < lengthIP) && (i < lengthAP)) {
\r
816 // if AP is a valid group, search for the next valid group in IP
\r
817 if (isValidDataGroup(admittance,i)) {
\r
818 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
819 if (clock == lengthIP) {
\r
820 cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;
\r
821 throw(Exception(IP_END_NULLCOL,this));
\r
824 /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or
\r
825 are both null columns
\r
827 if (! samePatterns(inputPattern,clock,admittance,i)) {
\r
828 cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;
\r
829 throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible
\r
834 if (clock < lengthIP) {
\r
835 throw(Exception(AP_TOO_SHORT,this));
\r
836 cerr << "Abnormal case: AP is to short" << endl;
\r
840 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
841 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
842 #ifdef DEBUG_FCTNAME
\r
843 cout << "call to " << qPrintable(fctName) << endl;
\r
846 clearOutputPattern();
\r
848 if (specialType != NotSpecial) {
\r
849 cerr << "Abnormal case: the block is special and output pattern is computed normally" << endl;
\r
850 throw(Exception(INVALID_FUNBLOCK_USE,this));
\r
853 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
855 // in case of inputPattern not created, do it
\r
856 if (lengthIP <= 0) {
\r
858 cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl;
\r
859 // collect the input patterns for each input
\r
861 createInputPattern();
\r
863 catch(Exception e) {
\r
866 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
869 // initialize the output pattern
\r
871 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
872 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
873 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
874 QList<char>* pattern = new QList<char>();
\r
875 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
876 connIface->setOutputPattern(pattern);
\r
877 outputPattern.insert(connIface,pattern);
\r
879 cout << "output pattern array initialized" << endl;
\r
883 // search for the beginning of the first execution.
\r
884 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
885 cout << "found 1st exec clock: " << clock << endl;
\r
887 while (clock < lengthIP) {
\r
888 // initialize counters for current execution.
\r
889 int p = 0; // index in production pattern
\r
890 int o = 0; // clock+o will give the clock cycle of each output group
\r
891 int cip = 0; // clock+cip give the clock cycle of an input group
\r
892 int ccp = 0; // ccp give a column in the consumptio pattern
\r
893 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
894 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
895 bool cannotCompleteExec = false;
\r
896 for(int m=0;m<productionCounter.size();m++) {
\r
897 // search for the first production in PP
\r
898 while (!isValidDataGroup(productionPattern,p)) {
\r
902 int gap = 0; // count the number of extra null columns
\r
903 // search for PC(m) valid input group in IP
\r
904 while (nip < productionCounter.at(m)) {
\r
905 if (clock+cip < lengthIP) {
\r
906 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
911 cannotCompleteExec = true;
\r
916 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
918 // search for PC(m) valid input group in IP
\r
919 while (ncp < productionCounter.at(m)) {
\r
920 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
924 o += gap; // to take into acocunt of extra null columns
\r
925 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
930 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
932 // current exec. taken into accunt
\r
935 // search for the next exec.
\r
938 while ((clock < lengthIP) && (nip < delta)) {
\r
939 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
940 if (nip < delta) clock += 1;
\r
942 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
944 // find the last valid output data group
\r
945 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
946 removeDataGroup(outputPattern,lengthOP-1);
\r
950 // clear input pattern
\r
951 clearInputPattern();
\r
953 setOutputPatternComputed(true);
\r
959 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
960 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
961 #ifdef DEBUG_FCTNAME
\r
962 cout << "call to " << qPrintable(fctName) << endl;
\r
965 // case 1: the block is a generator for which output pattern
\r
966 // must be computed for a nbExec following executions
\r
969 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
970 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
971 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
972 // create output pattern
\r
973 QList<char>* pp = productionPattern.value(connIface);
\r
974 QList<char>* pattern = new QList<char>(*pp);
\r
975 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
976 // assign pattern to interface
\r
977 connIface->setOutputPattern(pattern);
\r
978 // store it in QMap
\r
979 outputPattern.insert(connIface,pattern);
\r
983 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
985 // in case of inputPattern not created, do it
\r
986 if (lengthIP <= 0) {
\r
987 // collect the input patterns for each input
\r
989 createInputPattern();
\r
991 catch(Exception e) {
\r
994 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
997 // initialize the output pattern
\r
999 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
1000 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
1001 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
1002 QList<char>* pattern = new QList<char>();
\r
1003 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
1004 connIface->setOutputPattern(pattern);
\r
1005 outputPattern.insert(connIface,pattern);
\r
1007 cout << "output pattern array initialized" << endl;
\r
1011 // search for the beginning of the first execution.
\r
1012 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
1013 cout << "found 1st exec clock: " << clock << endl;
\r
1015 while (clock < lengthIP) {
\r
1016 // initialize counters for current execution.
\r
1017 int p = 0; // index in production pattern
\r
1018 int o = 0; // clock+o will give the clock cycle of each output group
\r
1019 int cip = 0; // clock+cip give the clock cycle of an input group
\r
1020 int ccp = 0; // ccp give a column in the consumptio pattern
\r
1021 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
1022 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
1023 bool cannotCompleteExec = false;
\r
1024 for(int m=0;m<productionCounter.size();m++) {
\r
1025 // search for the first production in PP
\r
1026 while (!isValidDataGroup(productionPattern,p)) {
\r
1030 int gap = 0; // count the number of extra null columns
\r
1031 // search for PC(m) valid input group in IP
\r
1032 while (nip < productionCounter.at(m)) {
\r
1033 if (clock+cip < lengthIP) {
\r
1034 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
1039 cannotCompleteExec = true;
\r
1044 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1046 // search for PC(m) valid input group in IP
\r
1047 while (ncp < productionCounter.at(m)) {
\r
1048 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
1052 o += gap; // to take into acocunt of extra null columns
\r
1053 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
1058 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1060 // current exec. taken into accunt
\r
1063 // search for the next exec.
\r
1066 while ((clock < lengthIP) && (nip < delta)) {
\r
1067 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
1068 if (nip < delta) clock += 1;
\r
1070 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
1072 // find the last valid output data group
\r
1073 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
1074 removeDataGroup(outputPattern,lengthOP-1);
\r
1078 // clear input pattern
\r
1079 clearInputPattern();
\r
1083 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1085 if (patternSrc.size() != patternDest.size()) return false;
\r
1086 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1087 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1088 while (iterSrc.hasNext()) {
\r
1091 QList<char>* srcPat = iterSrc.value();
\r
1092 QList<char>* destPat = iterDest.value();
\r
1093 if (srcCol >= srcPat->size()) return false;
\r
1094 if (destCol >= destPat->size()) return false;
\r
1095 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1100 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int> &srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1101 if (patternSrc.size() != srcCols.size()) return false;
\r
1102 if (patternSrc.size() != patternDest.size()) return false;
\r
1104 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1105 QListIterator<int> iterSrcCol(srcCols);
\r
1106 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1107 while (iterSrc.hasNext()) {
\r
1109 int srcCol = iterSrcCol.next();
\r
1111 QList<char>* srcPat = iterSrc.value();
\r
1112 QList<char>* destPat = iterDest.value();
\r
1113 if (srcCol >= srcPat->size()) return false;
\r
1114 if (destCol >= destPat->size()) return false;
\r
1115 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1120 bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1121 if (patternSrc.size() != patternDest.size()) return false;
\r
1122 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1123 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1124 while (iterSrc.hasNext()) {
\r
1127 QList<char>* srcPat = iterSrc.value();
\r
1128 QList<char>* destPat = iterDest.value();
\r
1129 if (srcCol >= srcPat->size()) return false;
\r
1130 if (destCol >= destPat->size()) return false;
\r
1131 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return false;
\r
1132 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;
\r
1137 void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1138 if (patternSrc.size() != patternDest.size()) return;
\r
1139 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1140 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1141 while (iterSrc.hasNext()) {
\r
1144 QList<char>* srcPat = iterSrc.value();
\r
1145 QList<char>* destPat = iterDest.value();
\r
1146 if (srcCol >= srcPat->size()) return;
\r
1147 if (destCol >= destPat->size()) return;
\r
1148 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;
\r
1149 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return;
\r
1150 destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));
\r
1154 void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {
\r
1155 if (patternSrc.size() != patternDest.size()) return;
\r
1156 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1157 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1158 while (iterSrc.hasNext()) {
\r
1161 QList<char>* srcPat = iterSrc.value();
\r
1162 QList<char>* destPat = iterDest.value();
\r
1164 while ((srcCol+i < srcPat->size()) && (i<nbCols)) {
\r
1165 destPat->append(srcPat->at(srcCol+i));
\r
1171 void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1172 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1173 while (iterSrc.hasNext()) {
\r
1175 QList<char>* srcPat = iterSrc.value();
\r
1176 if (offset < srcPat->size()) {
\r
1177 srcPat->removeAt(offset);
\r
1182 void FunctionalBlock::shiftRightPattern(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1183 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1184 while (iterSrc.hasNext()) {
\r
1186 QList<char>* srcPat = iterSrc.value();
\r
1187 if (offset < srcPat->size()) {
\r
1188 srcPat->insert(offset,0);
\r
1193 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1194 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1195 while (iterSrc.hasNext()) {
\r
1197 QList<char>* srcPat = iterSrc.value();
\r
1198 if (offset >= srcPat->size()) return false;
\r
1199 if (srcPat->at(offset) == 1) return true;
\r
1204 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets) {
\r
1205 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1206 QListIterator<int> iterOffsets(offsets);
\r
1207 while (iterSrc.hasNext()) {
\r
1209 int offset = iterOffsets.next();
\r
1210 QList<char>* srcPat = iterSrc.value();
\r
1211 if (offset >= srcPat->size()) return false;
\r
1212 if (srcPat->at(offset) == 1) return true;
\r
1217 bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1218 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1219 while (iterSrc.hasNext()) {
\r
1221 QList<char>* srcPat = iterSrc.value();
\r
1222 if (offset >= srcPat->size()) return false;
\r
1223 if (srcPat->at(offset) != -1) return false;
\r
1228 void FunctionalBlock::clearConsumptionPattern() {
\r
1229 QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern);
\r
1230 while (iterP.hasNext()) {
\r
1232 QList<char>* pattern = iterP.value();
\r
1233 if (pattern != NULL) delete pattern;
\r
1235 consumptionPattern.clear();
\r
1239 void FunctionalBlock::clearProductionPattern() {
\r
1240 QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern);
\r
1241 while (iterP.hasNext()) {
\r
1243 QList<char>* pattern = iterP.value();
\r
1244 if (pattern != NULL) delete pattern;
\r
1246 productionPattern.clear();
\r
1250 void FunctionalBlock::clearInputPattern() {
\r
1252 QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);
\r
1253 while (iterI.hasNext()) {
\r
1255 QList<char>* pattern = iterI.value();
\r
1256 if (pattern != NULL) delete pattern;
\r
1258 inputPattern.clear();
\r
1262 void FunctionalBlock::clearOutputPattern() {
\r
1264 QMapIterator<AbstractInterface*,QList<char>* > iterO(outputPattern);
\r
1265 while (iterO.hasNext()) {
\r
1267 ConnectedInterface* connIface = AI_TO_CON(iterO.key());
\r
1268 connIface->resetOutputPattern();
\r
1269 QList<char>* pattern = iterO.value();
\r
1270 if (pattern != NULL) delete pattern;
\r
1272 outputPattern.clear();
\r
1276 void FunctionalBlock::clearAdmittanceDelays() {
\r
1277 QMapIterator<AbstractInterface*, QList<int>* > iterA(admittanceDelays);
\r
1278 while (iterA.hasNext()) {
\r
1280 QList<int>* d = iterA.value();
\r
1281 if (d != NULL) delete d;
\r
1283 admittanceDelays.clear();
\r
1286 int FunctionalBlock::createTriggers() {
\r
1288 /* NB: this method returns the number of executions that have been started
\r
1289 but not necessary completed.
\r
1291 if (delta <= 0) return 0;
\r
1293 // search for the first exec.
\r
1294 while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;
\r
1295 if (offset == lengthIP) return 0;
\r
1296 triggers.append(offset);
\r
1298 for(int i = offset;i<lengthIP;i++) {
\r
1299 if (isValidDataGroup(inputPattern,i)) nbGroup++;
\r
1300 if (nbGroup == delta+1) {
\r
1301 triggers.append(i);
\r
1305 return triggers.size();
\r
1308 QList<QString> FunctionalBlock::getExternalResources() {
\r
1310 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1311 QList<QString> list = impl->getResources();
\r
1312 foreach(QString s, list) {
\r
1313 cout << qPrintable(s) << " ";
\r
1321 void FunctionalBlock::generateVHDL(const QString& path) throw(Exception){
\r
1323 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1325 QFile implFile(impl->getXmlFile());
\r
1327 // reading in into QDomDocument
\r
1328 QDomDocument document("implFile");
\r
1330 if (!implFile.open(QIODevice::ReadOnly)) {
\r
1331 throw(Exception(IMPLFILE_NOACCESS));
\r
1333 if (!document.setContent(&implFile)) {
\r
1335 throw(Exception(IMPLFILE_NOACCESS));
\r
1339 bool genController = false;
\r
1340 QString coreFile = "";
\r
1341 QString controllerFile = "";
\r
1343 if (reference->isWBConfigurable()) {
\r
1344 genController = true;
\r
1345 controllerFile = path;
\r
1346 controllerFile += "/";
\r
1347 controllerFile.append(name);
\r
1348 controllerFile.append("_ctrl.vhd");
\r
1351 controllerFile = "nofile.vhd";
\r
1355 coreFile.append(name);
\r
1356 coreFile.append(".vhd");
\r
1358 QFile vhdlCore(coreFile);
\r
1359 QFile vhdlController(controllerFile);
\r
1361 if (!vhdlCore.open(QIODevice::WriteOnly)) {
\r
1362 throw(Exception(VHDLFILE_NOACCESS));
\r
1365 if (genController) {
\r
1366 if (!vhdlController.open(QIODevice::WriteOnly)) {
\r
1367 throw(Exception(VHDLFILE_NOACCESS));
\r
1370 QTextStream outCore(&vhdlCore);
\r
1371 QTextStream outController;
\r
1372 if (genController) {
\r
1373 outController.setDevice(&vhdlController);
\r
1377 //Get the root element
\r
1378 QDomElement impl = document.documentElement();
\r
1379 QDomElement eltComments = impl.firstChildElement("comments");
\r
1380 generateComments(outCore,eltComments, coreFile);
\r
1381 QDomElement eltLibs = eltComments.nextSiblingElement("libraries");
\r
1382 generateLibraries(outCore, eltLibs);
\r
1383 generateEntity(outCore, genController);
\r
1384 QDomElement eltArch = eltLibs.nextSiblingElement("architecture");
\r
1385 generateArchitecture(outCore, eltArch );
\r
1386 if (genController) {
\r
1387 generateController(outController);
\r
1390 catch(Exception err) {
\r
1395 vhdlController.close();
\r
1399 void FunctionalBlock::generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) {
\r
1401 for(int i = 0; i < 50; i++) {
\r
1404 out << "\n--" << endl;
\r
1405 QString fileName = coreFile;
\r
1406 out << "-- File : " << fileName << endl;
\r
1407 out << "--" << endl;
\r
1408 QDomElement eltAuthor = elt.firstChildElement("author");
\r
1409 QString firstName = eltAuthor.attribute("firstname","");
\r
1410 QString lastName = eltAuthor.attribute("lastname","");
\r
1411 QString mail = eltAuthor.attribute("mail","");
\r
1412 out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")" << endl;
\r
1413 out << "--" << endl;
\r
1414 QDomElement eltLog = eltAuthor.nextSiblingElement("log");
\r
1415 QString crea = eltLog.attribute("creation","");
\r
1416 out << "-- Creation Date : "<<crea<< endl;
\r
1417 out << "--" << endl;
\r
1418 QDomNodeList listModifs = eltLog.elementsByTagName("modification");
\r
1419 for(int j=0;j<listModifs.length();j++) {
\r
1420 QDomNode nodeModif = listModifs.at(j);
\r
1421 QDomElement eltModif = nodeModif.toElement();
\r
1423 out << "-- Description : " << endl;
\r
1424 out << reference->getDescription() << endl;
\r
1425 out << "--" << endl;
\r
1426 QDomElement eltNote = eltLog.nextSiblingElement("notes");
\r
1427 QDomElement note = eltNote.firstChildElement();
\r
1428 QString noteTxt = note.text();
\r
1429 out << "-- Notes :\n"<<noteTxt<<endl;
\r
1430 out << "--" << endl;
\r
1431 for(int i = 0; i < 50; i++) {
\r
1434 out << endl << endl;
\r
1437 void FunctionalBlock::generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) {
\r
1439 QDomNodeList listLib = elt.elementsByTagName("library");
\r
1440 for(int i = 0; i < listLib.length(); i++) {
\r
1441 QDomNode nodeLib = listLib.item(i);
\r
1442 QDomElement eltLib = nodeLib.toElement();
\r
1443 QString nameLib = eltLib.attribute("name","none");
\r
1444 out << "library " << nameLib << ";" << endl;
\r
1445 QDomNodeList listPack = eltLib.elementsByTagName("package");
\r
1446 for(int j = 0; j < listPack.length(); j++) {
\r
1447 QDomNode nodePack = listPack.item(j);
\r
1448 QDomElement eltPack = nodePack.toElement();
\r
1449 QString namePack = eltPack.attribute("name","none");
\r
1450 QString usePack = eltPack.attribute("use","none");
\r
1451 out << "use " << nameLib << "." << namePack << "." << usePack << ";" << endl;
\r
1458 void FunctionalBlock::generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController) throw(Exception) {
\r
1461 QString indent = "";
\r
1462 for(i=0;i<indentLevel;i++) {
\r
1466 //QList<BlockParameter*> listParams = reference->getParameters();
\r
1467 QList<AbstractInterface*> listInputs = getInputs();
\r
1468 QList<AbstractInterface*> listOutputs = getOutputs();
\r
1469 QList<AbstractInterface*> listBidirs = getBidirs();
\r
1471 // Generation of the generics
\r
1472 QList<BlockParameter*> listGenerics = getGenericParameters();
\r
1473 if ((!listGenerics.isEmpty()) || (hasController)) {
\r
1474 out << indent << " generic (" << endl;
\r
1475 if (hasController) {
\r
1476 out << indent << " wb_data_width : integer = 16;" << endl;
\r
1477 out << indent << " wb_addr_width : integer = 12";
\r
1478 if (!listGenerics.isEmpty()) out << indent << ";";
\r
1481 for(i=0;i<listGenerics.size()-1;i++) {
\r
1482 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1484 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1486 out << indent << " );" << endl;
\r
1489 out << indent << " port (" << endl;
\r
1491 QString ports = "";
\r
1492 QTextStream outPorts(&ports);
\r
1494 // Generation of the clk & rst signals
\r
1495 outPorts << indent << " -- clk/rst" << endl;
\r
1496 foreach(AbstractInterface* iface, listInputs) {
\r
1497 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1498 outPorts << indent << " " << iface->getName() << " : in std_logic;" << endl;
\r
1501 foreach(AbstractInterface* iface, listOutputs) {
\r
1502 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1503 outPorts << indent << " " << iface->getName() << " : out std_logic;" << endl;
\r
1507 if (hasController) {
\r
1508 // Generation of the wishbone signals
\r
1509 outPorts << indent << " -- registers r/w via wishbone" << endl;
\r
1510 QList<BlockParameter*> listWB = reference->getWishboneParameters();
\r
1511 for(i=0;i<listWB.size()-1;i++) {
\r
1512 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1514 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1517 // Generation of the data/control signals
\r
1519 QList<AbstractInterface*> listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
1520 if (listIface.size()>0) {
\r
1521 outPorts << indent << " -- input data ports" << endl;
\r
1522 foreach(AbstractInterface* iface, listIface) {
\r
1523 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1526 listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
1527 if (listIface.size()>0) {
\r
1528 outPorts << indent << " -- input control ports" << endl;
\r
1529 foreach(AbstractInterface* iface, listIface) {
\r
1530 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1533 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
1534 if (listIface.size()>0) {
\r
1535 outPorts << indent << " -- output data ports" << endl;
\r
1536 foreach(AbstractInterface* iface, listIface) {
\r
1537 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1540 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
1541 if (listIface.size()>0) {
\r
1542 outPorts << indent << " -- output control ports" << endl;
\r
1543 foreach(AbstractInterface* iface, listIface) {
\r
1544 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1547 listIface = getInterfaces(AbstractInterface::InOut, AbstractInterface::Data);
\r
1548 if (listIface.size()>0) {
\r
1549 outPorts << indent << " -- bidirs data ports" << endl;
\r
1550 foreach(AbstractInterface* iface, listIface) {
\r
1551 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1558 out << indent << " );" << endl << endl;
\r
1562 void FunctionalBlock::generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) {
\r
1563 QRegularExpression rxPort("@\\{([a-zA-Z0-9_]+)\\}");
\r
1565 QString code = elt.text();
\r
1566 //cout << qPrintable(code) << endl;
\r
1567 out << "architecture rtl of " << name << " is" << endl;
\r
1569 QStringList listLine = code.split("\n");
\r
1570 for(int i =0; i < listLine.size(); i++) {
\r
1571 QString line = listLine.at(i).simplified();
\r
1574 if(listLine.at(i).contains(QRegularExpression("@foreach{"))) {
\r
1575 while(listLine.at(i).compare("@endforeach") != -1) {
\r
1576 expr = expr + listLine.at(i) + '\n';
\r
1579 expr = expr + listLine.at(i);
\r
1580 out << evalComplex(expr, 1) << '\n';
\r
1582 if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) {
\r
1583 while(listLine.at(i).compare("@endcaseeach") != -1) {
\r
1584 expr = expr + listLine.at(i) + '\n';
\r
1587 expr = expr + listLine.at(i);
\r
1588 out << evalComplex(expr, 2) << '\n';
\r
1591 if(line.contains("@{")) {
\r
1592 QMap<QString,QString> modifs;
\r
1593 //cout << qPrintable(line) << endl;
\r
1594 QRegularExpressionMatchIterator matchPort = rxPort.globalMatch(line);
\r
1595 while(matchPort.hasNext()) {
\r
1596 QRegularExpressionMatch m = matchPort.next();
\r
1597 QString refName = m.captured(1);
\r
1598 AbstractInterface* refIface = reference->getIfaceFromName(refName);
\r
1599 QString funName = getIfaceUserName(refIface);
\r
1600 if (!funName.isEmpty()) {
\r
1601 modifs.insert(m.captured(0),funName);
\r
1602 //cout << "replace " << qPrintable(refIface->getName()) << " by " << qPrintable(funIface->getName()) << endl;
\r
1605 QMapIterator<QString,QString> iterM(modifs);
\r
1606 while(iterM.hasNext()) {
\r
1608 QString oldName = iterM.key();
\r
1609 QString newName = iterM.value();
\r
1610 line.replace(oldName,newName);
\r
1613 out << line << endl;
\r
1616 out << "end rtl;" << endl;
\r
1619 void FunctionalBlock::generateController(QTextStream &out) throw(Exception) {
\r
1623 QString FunctionalBlock::getIfaceUserName(AbstractInterface* refIface) {
\r
1625 if (! refIface->isReferenceInterface()) return "";
\r
1627 AbstractInterface* funcIface = NULL;
\r
1629 if (refIface->getDirection() == AbstractInterface::Input) {
\r
1630 foreach(AbstractInterface* iface, getInputs()) {
\r
1631 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1632 if (fi->getReference() == refIface) {
\r
1633 funcIface = iface;
\r
1638 else if (refIface->getDirection() == AbstractInterface::Output) {
\r
1639 foreach(AbstractInterface* iface, getOutputs()) {
\r
1640 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1641 if (fi->getReference() == refIface) {
\r
1642 funcIface = iface;
\r
1647 else if (refIface->getDirection() == AbstractInterface::InOut) {
\r
1648 foreach(AbstractInterface* iface, getBidirs()) {
\r
1649 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1650 if (fi->getReference() == refIface) {
\r
1651 funcIface = iface;
\r
1656 if (funcIface == NULL) return "";
\r
1658 return funcIface->getName();
\r