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
35 FunctionalBlock::~FunctionalBlock() {
\r
36 if (evaluator != NULL) delete evaluator;
\r
39 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
\r
41 checkedBlocks->append(this);
\r
43 foreach(BlockParameter* param, params){
\r
44 if(param->isUserParameter() && !param->isValueSet()){
\r
45 if(!blocksToConfigure->contains(param->getOwner())){
\r
46 blocksToConfigure->append(param->getOwner());
\r
50 foreach(AbstractInterface *inter, outputs){
\r
51 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
52 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
53 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
60 bool FunctionalBlock::isFunctionalBlock() {
\r
64 bool FunctionalBlock::isSourceBlock() {
\r
65 if (parent == NULL) return true;
\r
69 void FunctionalBlock::populate() {
\r
72 AbstractInterface* inter;
\r
74 // create parameters from reference block
\r
75 QList<BlockParameter*> lstParam = reference->getParameters();
\r
76 for(i=0;i<lstParam.size();i++) {
\r
77 p = lstParam.at(i)->clone();
\r
81 ConnectedInterface* toClk = NULL;
\r
82 ConnectedInterface* toRst = NULL;
\r
83 // create interfaces from reference block
\r
84 QList<AbstractInterface *> lstRef = reference->getInterfaces();
\r
85 // store relation between functional and reference
\r
86 QHash<AbstractInterface *, AbstractInterface *> hashIface;
\r
87 for(i=0;i<lstRef.size();i++) {
\r
89 inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));
\r
91 catch(Exception e) {
\r
92 cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;
\r
95 hashIface.insert(lstRef.at(i),inter);
\r
96 addInterface(inter);
\r
97 /* WARNING FOR THE FUTURE :
\r
98 in case of there are several clock interfaces ofr that block
\r
99 it would be a godd idea to make the user choose which one
\r
100 must be connected to defautl clk.
\r
101 Presently, the first encountered is chosen
\r
103 if ((toClk == NULL) && (inter->getPurpose() == AbstractInterface::Clock)) {
\r
104 toClk = AI_TO_CON(inter);
\r
106 if ((toRst == NULL) && (inter->getPurpose() == AbstractInterface::Reset)) {
\r
107 toRst = AI_TO_CON(inter);
\r
111 AbstractInterface* funCtlIface = NULL;
\r
112 AbstractInterface* funDataIface = NULL;
\r
114 for(i=0;i<lstRef.size();i++) {
\r
115 AbstractInterface* refIface = lstRef.at(i);
\r
116 if (refIface->getPurpose() == AbstractInterface::Control) {
\r
117 funCtlIface = hashIface.value(refIface);
\r
118 funDataIface = hashIface.value(refIface->getAssociatedIface());
\r
119 if (! funCtlIface->setAssociatedIface(funDataIface)) {
\r
120 cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;
\r
126 // connect clk and rst to group clk/rst or to clkrstgen
\r
127 if ((name != "clkrstgen") && (parent != NULL)) {
\r
131 catch(Exception e) {
\r
132 AbstractBlock* source = (AbstractBlock *)(e.getSource());
\r
133 cerr << qPrintable(source->getName()) << ":" << qPrintable(e.getMessage()) << endl;
\r
139 QString FunctionalBlock::getReferenceXmlFile() {
\r
140 return ((ReferenceBlock *)reference)->getXmlFile();
\r
143 QString FunctionalBlock::getReferenceHashMd5() {
\r
144 return ((ReferenceBlock *)reference)->getHashMd5();
\r
147 void FunctionalBlock::createPatterns() throw(Exception) {
\r
148 static QString fctName = "FunctionalBlock::createPatterns()";
\r
149 #ifdef DEBUG_FCTNAME
\r
150 cout << "call to " << qPrintable(fctName) << endl;
\r
153 if (implementation->hasNoPatterns()) return;
\r
155 cout << "create patterns for block " << qPrintable(name) << endl;
\r
156 if (evaluator == NULL) evaluator = new ArithmeticEvaluator();
\r
157 if (! isGeneratorBlock()) {
\r
160 createConsumptionPattern();
\r
161 createProductionCounter();
\r
163 catch(Exception e) {
\r
164 throw(e); // rethrow e
\r
168 createProductionPattern();
\r
170 catch(Exception e) {
\r
173 cout << "PP of " << qPrintable(name) << endl;
\r
174 QMapIterator<AbstractInterface*,QList<char>* > it(productionPattern);
\r
175 while (it.hasNext()) {
\r
177 QList<char>* pat = it.value();
\r
178 foreach(char c, *pat) cout << (int)c;
\r
183 void FunctionalBlock::createDelta() throw(Exception) {
\r
184 static QString fctName = "FunctionalBlock::createDelta()";
\r
185 #ifdef DEBUG_FCTNAME
\r
186 cout << "call to " << qPrintable(fctName) << endl;
\r
189 QString deltaStr = implementation->getDelta();
\r
190 cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;
\r
191 if (deltaStr.isEmpty()) {
\r
196 // look for parameter names
\r
199 result = evaluateExpression(deltaStr);
\r
201 catch(Exception e) {
\r
205 cout << "delta = " << delta << endl;
\r
208 void FunctionalBlock::createConsumptionPattern() throw(Exception) {
\r
209 static QString fctName = "FunctionalBlock::createConsumptionPattern()";
\r
210 #ifdef DEBUG_FCTNAME
\r
211 cout << "call to " << qPrintable(fctName) << endl;
\r
214 // first clear if already exists
\r
215 clearConsumptionPattern();
\r
218 QHash<QString,QString> consPattern = implementation->getConsumptionPattern();
\r
220 foreach(AbstractInterface* iface, getControlInputs()) {
\r
221 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
222 QString refName = connIface->getReference()->getName();
\r
223 if (! consPattern.contains(refName)) {
\r
224 throw(Exception(NO_IFACE_CP,this));
\r
225 cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;
\r
227 QList<char>* pattern = NULL;
\r
229 pattern = expandPattern(consPattern.value(refName));
\r
231 catch(Exception e) {
\r
234 consumptionPattern.insert(connIface,pattern);
\r
235 if (lengthCP == -1) {
\r
236 lengthCP = pattern->size();
\r
239 if (pattern->size() != lengthCP) {
\r
240 throw(Exception(INVALID_IFACE_CP_LENGTH,this));
\r
246 void FunctionalBlock::createProductionPattern() throw(Exception){
\r
247 static QString fctName = "FunctionalBlock::createProductionPattern()";
\r
248 #ifdef DEBUG_FCTNAME
\r
249 cout << "call to " << qPrintable(fctName) << endl;
\r
252 // first clear if already exists
\r
253 clearProductionPattern();
\r
256 QHash<QString,QString> prodPattern = implementation->getProductionPattern();
\r
258 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
259 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
260 QString refName = connIface->getReference()->getName();
\r
261 if (! prodPattern.contains(refName)) {
\r
262 throw(Exception(NO_IFACE_PP,this));
\r
264 QList<char>* pattern = NULL;
\r
266 pattern = expandPattern(prodPattern.value(refName));
\r
268 catch(Exception e) {
\r
271 productionPattern.insert(connIface,pattern);
\r
272 if (lengthPP == -1) {
\r
273 lengthPP = pattern->size();
\r
276 if (pattern->size() != lengthPP) {
\r
277 throw(Exception(INVALID_IFACE_PP_LENGTH,this));
\r
283 void FunctionalBlock::createProductionCounter() throw(Exception) {
\r
284 static QString fctName = "FunctionalBlock::createProductionCounter()";
\r
285 #ifdef DEBUG_FCTNAME
\r
286 cout << "call to " << qPrintable(fctName) << endl;
\r
289 // first clear if already exists
\r
290 productionCounter.clear();
\r
293 QStringList counterParts = implementation->getProductionCounter().split(",");
\r
294 foreach(QString s, counterParts) {
\r
295 cout << "cont part = " << qPrintable(s) << endl;
\r
297 double val = s.toDouble(&ok);
\r
299 productionCounter.append(val);
\r
301 else if (s.at(0) == '{') {
\r
304 QStringList gen = s.split(":");
\r
305 if (gen.size() != 3) {
\r
306 throw(Exception(INVALID_IFACE_PC,this));
\r
311 for(int i=0;i<3;i++) {
\r
312 double result = 0.0;
\r
314 result = evaluateExpression(gen.at(i));
\r
316 catch(Exception e) {
\r
319 if (i==0) start = result;
\r
320 else if (i==1) nb = result;
\r
321 else if (i==2) step = result;
\r
323 for(int j=0;j<nb;j++) {
\r
324 productionCounter.append(start+j*step);
\r
328 double result = 0.0;
\r
330 result = evaluateExpression(s);
\r
332 catch(Exception e) {
\r
335 productionCounter.append(result);
\r
338 foreach(int val, productionCounter) {
\r
339 cout << val << ",";
\r
344 QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {
\r
345 static QString fctName = "FunctionalBlock::expandPattern()";
\r
346 #ifdef DEBUG_FCTNAME
\r
347 cout << "call to " << qPrintable(fctName) << endl;
\r
349 /* expanding a pattern is done in two steps :
\r
350 - 1 : finding all variables that correspond to an expression
\r
351 and copy them in the pattern
\r
352 - 2 : parsing the result
\r
354 Note that the result MUST contain only variables that have a
\r
355 integer/double value. Otherwise, expanding will fail.
\r
361 QString p = replaceExpressions(patternIn);
\r
366 QList<char>* patternOut = new QList<char>();
\r
368 patternOut->append(expandPatternRecur(p,&offset));
\r
370 catch(Exception e) {
\r
377 QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) {
\r
379 QString res = patternIn;
\r
381 QRegularExpression re("[$][a-zA-Z0-9_]+");
\r
385 QRegularExpressionMatchIterator matcher = re.globalMatch(res);
\r
386 while(matcher.hasNext()) {
\r
387 QRegularExpressionMatch m = matcher.next();
\r
388 QString param = m.captured(0);
\r
389 QString paramName = param;
\r
390 paramName.remove(0,1);
\r
391 BlockParameter* p = getParameterFromName(paramName);
\r
392 if ((p != NULL) && (p->getType() == BlockParameter::Expression)) {
\r
393 res.replace(param,p->getStringValue());
\r
395 cout << "found an expr: " << qPrintable(paramName) << ", patern => " << qPrintable(res) << endl;
\r
402 QList<char> FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) {
\r
404 QList<char> patternOut;
\r
406 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {
\r
408 QChar c = patternIn.at(*offset);
\r
412 patternOut.append(expandPatternRecur(patternIn,offset));
\r
414 catch(Exception e) {
\r
418 else if (c == '0') {
\r
419 patternOut.append(0);
\r
421 else if (c == '1') {
\r
422 patternOut.append(1);
\r
424 else if (c == 'X') {
\r
425 patternOut.append(-1);
\r
427 else if (c == '{') {
\r
429 QString expr = "";
\r
430 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
431 expr += patternIn.at(*offset);
\r
434 if (*offset == patternIn.size()) {
\r
435 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
439 repeat = evaluateExpression(expr);
\r
441 catch(Exception e) {
\r
446 patternOut.removeLast();
\r
449 // repeat just the last value in currentGroup
\r
450 char last = patternOut.last();
\r
451 //cout << "repeat last char " << repeat << " times : " << (int)last << endl;
\r
452 for(int i=1;i<(int)repeat;i++) {
\r
453 patternOut.append(last);
\r
460 // must check if after ), there is a {
\r
461 if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {
\r
463 QString expr = "";
\r
464 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
465 expr += patternIn.at(*offset);
\r
468 if (*offset == patternIn.size()) {
\r
469 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
473 repeat = evaluateExpression(expr);
\r
475 catch(Exception e) {
\r
479 QList<char> voidList;
\r
484 cout << "repeat last group " << repeat << " times : ";
\r
485 foreach (char c, currentGroup) cout <<(int)c;
\r
488 QList<char> single = patternOut;
\r
489 for(int i=1;i<(int)repeat;i++) {
\r
490 patternOut.append(single);
\r
497 double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {
\r
498 static QString fctName = "FunctionalBlock::evaluateExpression()";
\r
499 #ifdef DEBUG_FCTNAME
\r
500 cout << "call to " << qPrintable(fctName) << endl;
\r
503 QHash<QString,double> vars;
\r
504 evaluator->setExpression(expression);
\r
505 QList<QString> varNames = evaluator->getVariableNames();
\r
506 foreach (QString name, varNames) {
\r
507 QString paramName = name;
\r
508 paramName.remove(0,1);
\r
509 BlockParameter* param = getParameterFromName(paramName);
\r
510 if (param == NULL) {
\r
511 throw(Exception(EVAL_PARAM_UNKNOWN,this));
\r
514 int val = param->getDoubleValue(&okVal);
\r
516 throw(Exception(EVAL_PARAM_NOVALUE,this));
\r
518 vars.insert(name,(double)val);
\r
521 evaluator->setVariablesValue(vars);
\r
522 double result = 0.0;
\r
524 result = evaluator->evaluate();
\r
527 cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;
\r
528 throw(Exception(EVAL_INVALID_EXPR,this));
\r
533 void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {
\r
534 static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";
\r
535 #ifdef DEBUG_FCTNAME
\r
536 cout << "call to " << qPrintable(fctName) << endl;
\r
538 QList<int> inClock;
\r
541 clearAdmittanceDelays();
\r
543 // trying to synchronize the first one in AP
\r
544 QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);
\r
545 QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);
\r
547 while (iterAP.hasNext()) {
\r
550 QList<char>* ap = iterAP.value();
\r
551 QList<char>* ip = iterIP.value();
\r
553 while ((first < lengthIP) && (ip->at(first) == 0)) first++;
\r
554 while ((first < lengthAP) && (ap->at(first) == 0)) first--;
\r
555 delays.append(first);
\r
557 QList<int>* delays = new QList<int>();
\r
558 admittanceDelays.insert(iterAP.key(), delays);
\r
561 QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);
\r
563 // get the delay to apply
\r
565 for(int i=0;i<delays.size();i++) {
\r
566 if (delays[i] > maxDelay) maxDelay = delays[i];
\r
568 // adding the delays to IP
\r
571 while (iterIP.hasNext()) {
\r
574 QList<char>* ip = iterIP.value();
\r
575 QList<int>* d = iterDelays.value();
\r
576 d->append(maxDelay-delays[i]);
\r
577 cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;
\r
578 for(int j=0;j<maxDelay-delays[i];j++) {
\r
581 for(int j=0;j<delays[i];j++) {
\r
586 lengthIP += maxDelay;
\r
588 cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;
\r
594 // if AP is a valid group, search for the next valid group in IP
\r
595 if (isValidDataGroup(admittance,apIndex)) {
\r
597 while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;
\r
598 if (ipIndex == lengthIP) {
\r
606 iterDelays.toFront();
\r
608 if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {
\r
609 while (iterAP.hasNext()) {
\r
612 QList<char>* ap = iterAP.value();
\r
613 if (ap->at(apIndex) == 1) {
\r
614 QList<int>* d = iterDelays.value();
\r
615 d->append(0); // the 1 is at its good place, so no delay
\r
620 cout << "diff between IP and AP at " << apIndex << endl;
\r
621 // search for the next 1 in IP for every input that has a 1 in AP
\r
623 while (iterAP.hasNext()) {
\r
627 QList<char>* ap = iterAP.value();
\r
628 QList<char>* ip = iterIP.value();
\r
629 QList<int>* d = iterDelays.value();
\r
630 // case 1: 1 in IP is too late
\r
631 if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {
\r
633 while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;
\r
634 cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
635 // moving the 1 to its normal pos.
\r
636 ip->replace(ipIndex,1);
\r
637 ip->replace(ipIndex+delay,0);
\r
640 // case 2: 1 in IP is too soon
\r
641 else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {
\r
643 while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;
\r
644 cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
645 // search for next 0 in IP to put the 1
\r
646 int k = ipIndex+delay;
\r
647 while ((k < lengthIP) && (ip->at(k) == 1)) k++;
\r
648 ip->replace(ipIndex,0);
\r
653 if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {
\r
654 cout << "Abnormal case while searching for delays" << endl;
\r
660 if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;
\r
662 iterDelays.toFront();
\r
663 while (iterDelays.hasNext()) {
\r
665 QList<int>* d = iterDelays.value();
\r
666 foreach(int v, *d) {
\r
674 void FunctionalBlock::createInputPattern() throw(Exception) {
\r
675 static QString fctName = "FunctionalBlock::createInputPattern())";
\r
676 #ifdef DEBUG_FCTNAME
\r
677 cout << "call to " << qPrintable(fctName) << endl;
\r
681 foreach(AbstractInterface* iface, getControlInputs()) {
\r
683 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
684 // check if it is connected
\r
685 if (connIface->getConnectedFrom() == NULL) {
\r
686 throw(Exception(IFACE_NOT_CONNECTED,this));
\r
688 // get the precursor output pattern
\r
689 QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
\r
690 AbstractInputModifier* modifier = connIface->getInputModifier();
\r
691 // check if the input is modified
\r
692 if (modifier != NULL) {
\r
694 out = modifier->getModifiedInput(out);
\r
697 if (out->size() == 0) {
\r
698 clearInputPattern();
\r
699 throw(Exception(NO_IFACE_IP,this));
\r
701 if (lengthIP == -1) {
\r
702 lengthIP = out->size();
\r
705 if (out->size() < lengthIP) lengthIP = out->size();
\r
708 QList<char>* in = new QList<char>(*out);
\r
709 foreach(char c, *in) {
\r
713 inputPattern.insert(connIface,in);
\r
715 // search the last valid group in IP,
\r
716 while(! isValidDataGroup(inputPattern,lengthIP-1)) {
\r
717 //removeDataGroup(inputPattern,lengthIP-1);
\r
722 void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {
\r
723 static QString fctName = "FunctionalBlock::createAdmittance()";
\r
724 #ifdef DEBUG_FCTNAME
\r
725 cout << "call to " << qPrintable(fctName) << endl;
\r
727 // firstly, copy CP in AP
\r
728 QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);
\r
729 while (iterC.hasNext()) {
\r
731 QList<char>* pattern = new QList<char>(*(iterC.value()));
\r
732 admittance.insert(iterC.key(), pattern);
\r
734 lengthAP = lengthCP;
\r
736 cout << "trigger 1 at c.c. 0" << endl;
\r
737 for(int i=1;i<nbExec;i++) {
\r
738 // searching for the clock cycle for which a new exec starts
\r
740 while ((clock < lengthAP) && (nbGroup < delta)) {
\r
741 if (isValidDataGroup(admittance,clock)) nbGroup+=1;
\r
744 while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;
\r
745 cout << "trigger " << (i+1) << " at c.c. " << clock << endl;
\r
747 // combine CP with AP at sc
\r
748 for(int j=0;j<lengthCP;j++) {
\r
749 // first case : column of CP must be placed beyond AP's end.
\r
750 if (sc == lengthAP) {
\r
751 cout << i << "," << j << " append in AP at " << sc << endl;
\r
752 appendToPattern(consumptionPattern,j,admittance,1);
\r
756 // second case : CP and AP can be combined directly (i.e. no X | 1 to do)
\r
757 else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
758 cout << i << "," << j << " combine at " << sc << endl;
\r
759 combinePatterns(consumptionPattern,j,admittance,sc);
\r
762 // third case : CP has an X column
\r
763 else if (isOnlyXDataGroup(consumptionPattern,j)) {
\r
764 cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;
\r
765 shiftRightPattern(admittance,sc);
\r
767 if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
768 cerr << "Abnormal case when combining AP and CP" << endl;
\r
770 combinePatterns(consumptionPattern,j,admittance,sc);
\r
773 // fourth case : AP has an X column
\r
774 else if (isOnlyXDataGroup(admittance,sc)) {
\r
775 cout << i << "," << j << " jump c.c. for CP at " << sc << endl;
\r
780 throw(INVALID_DELTA_CP);
\r
784 // turn all X into 0
\r
785 QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);
\r
786 while (iterA.hasNext()) {
\r
788 QList<char>* pattern = iterA.value();
\r
789 for(int i=0;i<pattern->size();i++) {
\r
790 if (pattern->at(i) == -1) pattern->replace(i,0);
\r
791 cout << (int)(pattern->at(i));
\r
797 void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {
\r
798 static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";
\r
799 #ifdef DEBUG_FCTNAME
\r
800 cout << "call to " << qPrintable(fctName) << endl;
\r
803 // firstly, create input pattern
\r
805 createInputPattern();
\r
807 catch(Exception e) {
\r
810 int nbExec = createTriggers();
\r
811 cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;
\r
814 createAdmittance(nbExec);
\r
816 catch(Exception e) {
\r
817 cout << "cannot create admittance" << endl;
\r
821 int clock = 0; // index in IP
\r
822 int i = 0; // index in AP
\r
823 while ((clock < lengthIP) && (i < lengthAP)) {
\r
825 // if AP is a valid group, search for the next valid group in IP
\r
826 if (isValidDataGroup(admittance,i)) {
\r
827 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
828 if (clock == lengthIP) {
\r
829 cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;
\r
830 throw(Exception(IP_END_NULLCOL,this));
\r
833 /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or
\r
834 are both null columns
\r
836 if (! samePatterns(inputPattern,clock,admittance,i)) {
\r
837 cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;
\r
838 throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible
\r
843 if (clock < lengthIP) {
\r
844 throw(Exception(AP_TOO_SHORT,this));
\r
845 cerr << "Abnormal case: AP is to short" << endl;
\r
849 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
850 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
851 #ifdef DEBUG_FCTNAME
\r
852 cout << "call to " << qPrintable(fctName) << endl;
\r
855 clearOutputPattern();
\r
857 /* case 1: the block is a generator for which output pattern
\r
858 must be computed for a nbExec following executions
\r
862 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
863 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
864 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
865 // create output pattern
\r
866 QList<char>* pp = productionPattern.value(connIface);
\r
867 QList<char>* pattern = new QList<char>(*pp);
\r
868 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
869 // assign pattern to interface
\r
870 connIface->setOutputPattern(pattern);
\r
871 // store it in QMap
\r
872 outputPattern.insert(connIface,pattern);
\r
876 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
878 // in case of inputPattern not created, do it
\r
879 if (lengthIP <= 0) {
\r
881 cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl;
\r
882 // collect the input patterns for each input
\r
884 createInputPattern();
\r
886 catch(Exception e) {
\r
889 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
892 // initialize the output pattern
\r
894 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
895 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
896 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
897 QList<char>* pattern = new QList<char>();
\r
898 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
899 connIface->setOutputPattern(pattern);
\r
900 outputPattern.insert(connIface,pattern);
\r
902 cout << "output pattern array initialized" << endl;
\r
906 // search for the beginning of the first execution.
\r
907 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
908 cout << "found 1st exec clock: " << clock << endl;
\r
910 while (clock < lengthIP) {
\r
911 // initialize counters for current execution.
\r
912 int p = 0; // index in production pattern
\r
913 int o = 0; // clock+o will give the clock cycle of each output group
\r
914 int cip = 0; // clock+cip give the clock cycle of an input group
\r
915 int ccp = 0; // ccp give a column in the consumptio pattern
\r
916 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
917 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
918 bool cannotCompleteExec = false;
\r
919 for(int m=0;m<productionCounter.size();m++) {
\r
920 // search for the first production in PP
\r
921 while (!isValidDataGroup(productionPattern,p)) {
\r
925 int gap = 0; // count the number of extra null columns
\r
926 // search for PC(m) valid input group in IP
\r
927 while (nip < productionCounter.at(m)) {
\r
928 if (clock+cip < lengthIP) {
\r
929 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
934 cannotCompleteExec = true;
\r
939 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
941 // search for PC(m) valid input group in IP
\r
942 while (ncp < productionCounter.at(m)) {
\r
943 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
947 o += gap; // to take into acocunt of extra null columns
\r
948 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
953 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
955 // current exec. taken into accunt
\r
958 // search for the next exec.
\r
961 while ((clock < lengthIP) && (nip < delta)) {
\r
962 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
963 if (nip < delta) clock += 1;
\r
965 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
967 // find the last valid output data group
\r
968 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
969 removeDataGroup(outputPattern,lengthOP-1);
\r
973 // clear input pattern
\r
974 clearInputPattern();
\r
980 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
981 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
982 #ifdef DEBUG_FCTNAME
\r
983 cout << "call to " << qPrintable(fctName) << endl;
\r
986 // case 1: the block is a generator for which output pattern
\r
987 // must be computed for a nbExec following executions
\r
990 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
991 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
992 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
993 // create output pattern
\r
994 QList<char>* pp = productionPattern.value(connIface);
\r
995 QList<char>* pattern = new QList<char>(*pp);
\r
996 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
997 // assign pattern to interface
\r
998 connIface->setOutputPattern(pattern);
\r
999 // store it in QMap
\r
1000 outputPattern.insert(connIface,pattern);
\r
1004 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
1006 // in case of inputPattern not created, do it
\r
1007 if (lengthIP <= 0) {
\r
1008 // collect the input patterns for each input
\r
1010 createInputPattern();
\r
1012 catch(Exception e) {
\r
1015 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
1018 // initialize the output pattern
\r
1020 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
1021 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
1022 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
1023 QList<char>* pattern = new QList<char>();
\r
1024 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
1025 connIface->setOutputPattern(pattern);
\r
1026 outputPattern.insert(connIface,pattern);
\r
1028 cout << "output pattern array initialized" << endl;
\r
1032 // search for the beginning of the first execution.
\r
1033 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
1034 cout << "found 1st exec clock: " << clock << endl;
\r
1036 while (clock < lengthIP) {
\r
1037 // initialize counters for current execution.
\r
1038 int p = 0; // index in production pattern
\r
1039 int o = 0; // clock+o will give the clock cycle of each output group
\r
1040 int cip = 0; // clock+cip give the clock cycle of an input group
\r
1041 int ccp = 0; // ccp give a column in the consumptio pattern
\r
1042 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
1043 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
1044 bool cannotCompleteExec = false;
\r
1045 for(int m=0;m<productionCounter.size();m++) {
\r
1046 // search for the first production in PP
\r
1047 while (!isValidDataGroup(productionPattern,p)) {
\r
1051 int gap = 0; // count the number of extra null columns
\r
1052 // search for PC(m) valid input group in IP
\r
1053 while (nip < productionCounter.at(m)) {
\r
1054 if (clock+cip < lengthIP) {
\r
1055 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
1060 cannotCompleteExec = true;
\r
1065 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1067 // search for PC(m) valid input group in IP
\r
1068 while (ncp < productionCounter.at(m)) {
\r
1069 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
1073 o += gap; // to take into acocunt of extra null columns
\r
1074 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
1079 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1081 // current exec. taken into accunt
\r
1084 // search for the next exec.
\r
1087 while ((clock < lengthIP) && (nip < delta)) {
\r
1088 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
1089 if (nip < delta) clock += 1;
\r
1091 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
1093 // find the last valid output data group
\r
1094 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
1095 removeDataGroup(outputPattern,lengthOP-1);
\r
1099 // clear input pattern
\r
1100 clearInputPattern();
\r
1104 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1106 if (patternSrc.size() != patternDest.size()) return false;
\r
1107 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1108 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1109 while (iterSrc.hasNext()) {
\r
1112 QList<char>* srcPat = iterSrc.value();
\r
1113 QList<char>* destPat = iterDest.value();
\r
1114 if (srcCol >= srcPat->size()) return false;
\r
1115 if (destCol >= destPat->size()) return false;
\r
1116 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1121 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int> &srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1122 if (patternSrc.size() != srcCols.size()) return false;
\r
1123 if (patternSrc.size() != patternDest.size()) return false;
\r
1125 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1126 QListIterator<int> iterSrcCol(srcCols);
\r
1127 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1128 while (iterSrc.hasNext()) {
\r
1130 int srcCol = iterSrcCol.next();
\r
1132 QList<char>* srcPat = iterSrc.value();
\r
1133 QList<char>* destPat = iterDest.value();
\r
1134 if (srcCol >= srcPat->size()) return false;
\r
1135 if (destCol >= destPat->size()) return false;
\r
1136 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1141 bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1142 if (patternSrc.size() != patternDest.size()) return false;
\r
1143 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1144 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1145 while (iterSrc.hasNext()) {
\r
1148 QList<char>* srcPat = iterSrc.value();
\r
1149 QList<char>* destPat = iterDest.value();
\r
1150 if (srcCol >= srcPat->size()) return false;
\r
1151 if (destCol >= destPat->size()) return false;
\r
1152 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return false;
\r
1153 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;
\r
1158 void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1159 if (patternSrc.size() != patternDest.size()) return;
\r
1160 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1161 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1162 while (iterSrc.hasNext()) {
\r
1165 QList<char>* srcPat = iterSrc.value();
\r
1166 QList<char>* destPat = iterDest.value();
\r
1167 if (srcCol >= srcPat->size()) return;
\r
1168 if (destCol >= destPat->size()) return;
\r
1169 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;
\r
1170 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return;
\r
1171 destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));
\r
1175 void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {
\r
1176 if (patternSrc.size() != patternDest.size()) return;
\r
1177 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1178 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1179 while (iterSrc.hasNext()) {
\r
1182 QList<char>* srcPat = iterSrc.value();
\r
1183 QList<char>* destPat = iterDest.value();
\r
1185 while ((srcCol+i < srcPat->size()) && (i<nbCols)) {
\r
1186 destPat->append(srcPat->at(srcCol+i));
\r
1192 void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1193 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1194 while (iterSrc.hasNext()) {
\r
1196 QList<char>* srcPat = iterSrc.value();
\r
1197 if (offset < srcPat->size()) {
\r
1198 srcPat->removeAt(offset);
\r
1203 void FunctionalBlock::shiftRightPattern(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1204 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1205 while (iterSrc.hasNext()) {
\r
1207 QList<char>* srcPat = iterSrc.value();
\r
1208 if (offset < srcPat->size()) {
\r
1209 srcPat->insert(offset,0);
\r
1214 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1215 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1216 while (iterSrc.hasNext()) {
\r
1218 QList<char>* srcPat = iterSrc.value();
\r
1219 if (offset >= srcPat->size()) return false;
\r
1220 if (srcPat->at(offset) == 1) return true;
\r
1225 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets) {
\r
1226 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1227 QListIterator<int> iterOffsets(offsets);
\r
1228 while (iterSrc.hasNext()) {
\r
1230 int offset = iterOffsets.next();
\r
1231 QList<char>* srcPat = iterSrc.value();
\r
1232 if (offset >= srcPat->size()) return false;
\r
1233 if (srcPat->at(offset) == 1) return true;
\r
1238 bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1239 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1240 while (iterSrc.hasNext()) {
\r
1242 QList<char>* srcPat = iterSrc.value();
\r
1243 if (offset >= srcPat->size()) return false;
\r
1244 if (srcPat->at(offset) != -1) return false;
\r
1249 void FunctionalBlock::clearConsumptionPattern() {
\r
1250 QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern);
\r
1251 while (iterP.hasNext()) {
\r
1253 QList<char>* pattern = iterP.value();
\r
1254 if (pattern != NULL) delete pattern;
\r
1256 consumptionPattern.clear();
\r
1260 void FunctionalBlock::clearProductionPattern() {
\r
1261 QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern);
\r
1262 while (iterP.hasNext()) {
\r
1264 QList<char>* pattern = iterP.value();
\r
1265 if (pattern != NULL) delete pattern;
\r
1267 productionPattern.clear();
\r
1271 void FunctionalBlock::clearInputPattern() {
\r
1273 QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);
\r
1274 while (iterI.hasNext()) {
\r
1276 QList<char>* pattern = iterI.value();
\r
1277 if (pattern != NULL) delete pattern;
\r
1279 inputPattern.clear();
\r
1283 void FunctionalBlock::clearOutputPattern() {
\r
1285 QMapIterator<AbstractInterface*,QList<char>* > iterO(outputPattern);
\r
1286 while (iterO.hasNext()) {
\r
1288 ConnectedInterface* connIface = AI_TO_CON(iterO.key());
\r
1289 connIface->resetOutputPattern();
\r
1290 QList<char>* pattern = iterO.value();
\r
1291 if (pattern != NULL) delete pattern;
\r
1293 outputPattern.clear();
\r
1297 void FunctionalBlock::clearAdmittanceDelays() {
\r
1298 QMapIterator<AbstractInterface*, QList<int>* > iterA(admittanceDelays);
\r
1299 while (iterA.hasNext()) {
\r
1301 QList<int>* d = iterA.value();
\r
1302 if (d != NULL) delete d;
\r
1304 admittanceDelays.clear();
\r
1307 int FunctionalBlock::createTriggers() {
\r
1309 /* NB: this method returns the number of executions that have been started
\r
1310 but not necessary completed.
\r
1312 if (delta <= 0) return 0;
\r
1314 // search for the first exec.
\r
1315 while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;
\r
1316 if (offset == lengthIP) return 0;
\r
1317 triggers.append(offset);
\r
1319 for(int i = offset;i<lengthIP;i++) {
\r
1320 if (isValidDataGroup(inputPattern,i)) nbGroup++;
\r
1321 if (nbGroup == delta+1) {
\r
1322 triggers.append(i);
\r
1326 return triggers.size();
\r
1329 QList<QString> FunctionalBlock::getExternalResources() {
\r
1331 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1332 QList<QString> list = impl->getResources();
\r
1333 foreach(QString s, list) {
\r
1334 cout << qPrintable(s) << " ";
\r
1342 void FunctionalBlock::generateVHDL(const QString& path) throw(Exception){
\r
1344 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1346 QFile implFile(impl->getXmlFile());
\r
1348 // reading in into QDomDocument
\r
1349 QDomDocument document("implFile");
\r
1351 if (!implFile.open(QIODevice::ReadOnly)) {
\r
1352 throw(Exception(IMPLFILE_NOACCESS));
\r
1354 if (!document.setContent(&implFile)) {
\r
1356 throw(Exception(IMPLFILE_NOACCESS));
\r
1360 bool genController = false;
\r
1361 QString coreFile = "";
\r
1362 QString controllerFile = "";
\r
1364 if (reference->isWBConfigurable()) {
\r
1365 genController = true;
\r
1366 controllerFile = path;
\r
1367 controllerFile += "/";
\r
1368 controllerFile.append(name);
\r
1369 controllerFile.append("_ctrl.vhd");
\r
1372 controllerFile = "nofile.vhd";
\r
1376 coreFile.append(name);
\r
1377 coreFile.append(".vhd");
\r
1379 QFile vhdlCore(coreFile);
\r
1380 QFile vhdlController(controllerFile);
\r
1382 if (!vhdlCore.open(QIODevice::WriteOnly)) {
\r
1383 throw(Exception(VHDLFILE_NOACCESS));
\r
1386 if (genController) {
\r
1387 if (!vhdlController.open(QIODevice::WriteOnly)) {
\r
1388 throw(Exception(VHDLFILE_NOACCESS));
\r
1391 QTextStream outCore(&vhdlCore);
\r
1392 QTextStream outController;
\r
1393 if (genController) {
\r
1394 outController.setDevice(&vhdlController);
\r
1398 //Get the root element
\r
1399 QDomElement impl = document.documentElement();
\r
1400 QDomElement eltComments = impl.firstChildElement("comments");
\r
1401 generateComments(outCore,eltComments, coreFile);
\r
1402 QDomElement eltLibs = eltComments.nextSiblingElement("libraries");
\r
1403 generateLibraries(outCore, eltLibs);
\r
1404 generateEntity(outCore, genController);
\r
1405 QDomElement eltArch = eltLibs.nextSiblingElement("architecture");
\r
1406 generateArchitecture(outCore, eltArch );
\r
1407 if (genController) {
\r
1408 generateController(outController);
\r
1411 catch(Exception err) {
\r
1416 vhdlController.close();
\r
1420 void FunctionalBlock::generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) {
\r
1422 for(int i = 0; i < 50; i++) {
\r
1425 out << "\n--" << endl;
\r
1426 QString fileName = coreFile;
\r
1427 out << "-- File : " << fileName << endl;
\r
1428 out << "--" << endl;
\r
1429 QDomElement eltAuthor = elt.firstChildElement("author");
\r
1430 QString firstName = eltAuthor.attribute("firstname","");
\r
1431 QString lastName = eltAuthor.attribute("lastname","");
\r
1432 QString mail = eltAuthor.attribute("mail","");
\r
1433 out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")" << endl;
\r
1434 out << "--" << endl;
\r
1435 QDomElement eltDate = eltAuthor.nextSiblingElement("date");
\r
1436 QString crea = eltDate.attribute("creation","");
\r
1437 out << "-- Creation Date : "<<crea<< endl;
\r
1438 out << "--" << endl;
\r
1439 QDomElement eltRelated = eltDate.nextSiblingElement("related_files");
\r
1440 QString relateds = eltRelated.attribute("list","");
\r
1441 out << "-- Related files :\n"<<relateds<<endl;
\r
1442 out << "--" << endl;
\r
1443 QDomElement eltDesc = eltRelated.nextSiblingElement("description");
\r
1444 QDomElement desc = eltDesc.firstChildElement();
\r
1445 QString descTxt = desc.text();
\r
1446 out << "-- Decription :\n"<<descTxt<<endl;
\r
1447 out << "--" << endl;
\r
1448 QDomElement eltNote = eltDesc.nextSiblingElement("description");
\r
1449 QDomElement note = eltNote.firstChildElement();
\r
1450 QString noteTxt = note.text();
\r
1451 out << "-- Note :\n"<<noteTxt<<endl;
\r
1452 out << "--" << endl;
\r
1453 for(int i = 0; i < 50; i++) {
\r
1456 out << endl << endl;
\r
1459 void FunctionalBlock::generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) {
\r
1461 QDomNodeList listLib = elt.elementsByTagName("library");
\r
1462 for(int i = 0; i < listLib.length(); i++) {
\r
1463 QDomNode nodeLib = listLib.item(i);
\r
1464 QDomElement eltLib = nodeLib.toElement();
\r
1465 QString nameLib = eltLib.attribute("name","none");
\r
1466 out << "library " << nameLib << ";" << endl;
\r
1467 QDomNodeList listPack = eltLib.elementsByTagName("package");
\r
1468 for(int j = 0; j < listPack.length(); j++) {
\r
1469 QDomNode nodePack = listPack.item(j);
\r
1470 QDomElement eltPack = nodePack.toElement();
\r
1471 QString namePack = eltPack.attribute("name","none");
\r
1472 QString usePack = eltPack.attribute("use","none");
\r
1473 out << "use " << nameLib << "." << namePack << "." << usePack << ";" << endl;
\r
1480 void FunctionalBlock::generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController) throw(Exception) {
\r
1483 QString indent = "";
\r
1484 for(i=0;i<indentLevel;i++) {
\r
1488 //QList<BlockParameter*> listParams = reference->getParameters();
\r
1489 QList<AbstractInterface*> listInputs = getInputs();
\r
1490 QList<AbstractInterface*> listOutputs = getOutputs();
\r
1491 QList<AbstractInterface*> listBidirs = getBidirs();
\r
1493 // Generation of the generics
\r
1494 QList<BlockParameter*> listGenerics = getGenericParameters();
\r
1495 if ((!listGenerics.isEmpty()) || (hasController)) {
\r
1496 out << indent << " generic (" << endl;
\r
1497 if (hasController) {
\r
1498 out << indent << " wb_data_width : integer = 16;" << endl;
\r
1499 out << indent << " wb_addr_width : integer = 12";
\r
1500 if (!listGenerics.isEmpty()) out << indent << ";";
\r
1503 for(i=0;i<listGenerics.size()-1;i++) {
\r
1504 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1506 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1508 out << indent << " );" << endl;
\r
1511 out << indent << " port (" << endl;
\r
1513 QString ports = "";
\r
1514 QTextStream outPorts(&ports);
\r
1516 // Generation of the clk & rst signals
\r
1517 outPorts << indent << " -- clk/rst" << endl;
\r
1518 foreach(AbstractInterface* iface, listInputs) {
\r
1519 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1520 outPorts << indent << " " << iface->getName() << " : in std_logic;" << endl;
\r
1523 foreach(AbstractInterface* iface, listOutputs) {
\r
1524 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1525 outPorts << indent << " " << iface->getName() << " : out std_logic;" << endl;
\r
1529 if (hasController) {
\r
1530 // Generation of the wishbone signals
\r
1531 outPorts << indent << " -- registers r/w via wishbone" << endl;
\r
1532 QList<BlockParameter*> listWB = reference->getWishboneParameters();
\r
1533 for(i=0;i<listWB.size()-1;i++) {
\r
1534 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1536 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1539 // Generation of the data/control signals
\r
1541 QList<AbstractInterface*> listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
1542 if (listIface.size()>0) {
\r
1543 outPorts << indent << " -- input data ports" << endl;
\r
1544 foreach(AbstractInterface* iface, listIface) {
\r
1545 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1548 listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
1549 if (listIface.size()>0) {
\r
1550 outPorts << indent << " -- input control ports" << endl;
\r
1551 foreach(AbstractInterface* iface, listIface) {
\r
1552 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1555 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
1556 if (listIface.size()>0) {
\r
1557 outPorts << indent << " -- output data ports" << endl;
\r
1558 foreach(AbstractInterface* iface, listIface) {
\r
1559 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1562 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
1563 if (listIface.size()>0) {
\r
1564 outPorts << indent << " -- output control ports" << endl;
\r
1565 foreach(AbstractInterface* iface, listIface) {
\r
1566 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1569 listIface = getInterfaces(AbstractInterface::InOut, AbstractInterface::Data);
\r
1570 if (listIface.size()>0) {
\r
1571 outPorts << indent << " -- bidirs data ports" << endl;
\r
1572 foreach(AbstractInterface* iface, listIface) {
\r
1573 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1580 out << indent << " );" << endl << endl;
\r
1584 void FunctionalBlock::generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) {
\r
1585 QRegularExpression rxPort("@\\{([a-zA-Z0-9_]+)\\}");
\r
1587 QString code = elt.text();
\r
1588 //cout << qPrintable(code) << endl;
\r
1589 out << "architecture rtl of " << name << " is" << endl;
\r
1591 QStringList listLine = code.split("\n");
\r
1592 for(int i =0; i < listLine.size(); i++) {
\r
1593 QString line = listLine.at(i).simplified();
\r
1596 if(listLine.at(i).contains(QRegularExpression("@foreach{"))) {
\r
1597 while(listLine.at(i).compare("@endforeach") != -1) {
\r
1598 expr = expr + listLine.at(i) + '\n';
\r
1601 expr = expr + listLine.at(i);
\r
1602 out << evalComplex(expr, 1) << '\n';
\r
1604 if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) {
\r
1605 while(listLine.at(i).compare("@endcaseeach") != -1) {
\r
1606 expr = expr + listLine.at(i) + '\n';
\r
1609 expr = expr + listLine.at(i);
\r
1610 out << evalComplex(expr, 2) << '\n';
\r
1613 if(line.contains("@{")) {
\r
1614 QMap<QString,QString> modifs;
\r
1615 //cout << qPrintable(line) << endl;
\r
1616 QRegularExpressionMatchIterator matchPort = rxPort.globalMatch(line);
\r
1617 while(matchPort.hasNext()) {
\r
1618 QRegularExpressionMatch m = matchPort.next();
\r
1619 QString refName = m.captured(1);
\r
1620 AbstractInterface* refIface = reference->getIfaceFromName(refName);
\r
1621 QString funName = getIfaceUserName(refIface);
\r
1622 if (!funName.isEmpty()) {
\r
1623 modifs.insert(m.captured(0),funName);
\r
1624 //cout << "replace " << qPrintable(refIface->getName()) << " by " << qPrintable(funIface->getName()) << endl;
\r
1627 QMapIterator<QString,QString> iterM(modifs);
\r
1628 while(iterM.hasNext()) {
\r
1630 QString oldName = iterM.key();
\r
1631 QString newName = iterM.value();
\r
1632 line.replace(oldName,newName);
\r
1635 out << line << endl;
\r
1638 out << "end rtl;" << endl;
\r
1641 void FunctionalBlock::generateController(QTextStream &out) throw(Exception) {
\r
1645 QString FunctionalBlock::getIfaceUserName(AbstractInterface* refIface) {
\r
1647 if (! refIface->isReferenceInterface()) return "";
\r
1649 AbstractInterface* funcIface = NULL;
\r
1651 if (refIface->getDirection() == AbstractInterface::Input) {
\r
1652 foreach(AbstractInterface* iface, getInputs()) {
\r
1653 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1654 if (fi->getReference() == refIface) {
\r
1655 funcIface = iface;
\r
1660 else if (refIface->getDirection() == AbstractInterface::Output) {
\r
1661 foreach(AbstractInterface* iface, getOutputs()) {
\r
1662 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1663 if (fi->getReference() == refIface) {
\r
1664 funcIface = iface;
\r
1669 else if (refIface->getDirection() == AbstractInterface::InOut) {
\r
1670 foreach(AbstractInterface* iface, getBidirs()) {
\r
1671 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1672 if (fi->getReference() == refIface) {
\r
1673 funcIface = iface;
\r
1678 if (funcIface == NULL) return "";
\r
1680 return funcIface->getName();
\r