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
444 // repeat just the last value in currentGroup
\r
445 char last = patternOut.last();
\r
446 //cout << "repeat last char " << repeat << " times : " << (int)last << endl;
\r
448 for(int i=1;i<(int)repeat;i++) {
\r
449 patternOut.append(last);
\r
455 // must check if after ), there is a {
\r
456 if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {
\r
458 QString expr = "";
\r
459 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
460 expr += patternIn.at(*offset);
\r
463 if (*offset == patternIn.size()) {
\r
464 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
468 repeat = evaluateExpression(expr);
\r
470 catch(Exception e) {
\r
474 cout << "repeat last group " << repeat << " times : ";
\r
475 foreach (char c, currentGroup) cout <<(int)c;
\r
478 QList<char> single = patternOut;
\r
479 for(int i=1;i<(int)repeat;i++) {
\r
480 patternOut.append(single);
\r
486 double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {
\r
487 static QString fctName = "FunctionalBlock::evaluateExpression()";
\r
488 #ifdef DEBUG_FCTNAME
\r
489 cout << "call to " << qPrintable(fctName) << endl;
\r
492 QHash<QString,double> vars;
\r
493 evaluator->setExpression(expression);
\r
494 QList<QString> varNames = evaluator->getVariableNames();
\r
495 foreach (QString name, varNames) {
\r
496 QString paramName = name;
\r
497 paramName.remove(0,1);
\r
498 BlockParameter* param = getParameterFromName(paramName);
\r
499 if (param == NULL) {
\r
500 throw(Exception(EVAL_PARAM_UNKNOWN,this));
\r
503 int val = param->getDoubleValue(&okVal);
\r
505 throw(Exception(EVAL_PARAM_NOVALUE,this));
\r
507 vars.insert(name,(double)val);
\r
510 evaluator->setVariablesValue(vars);
\r
511 double result = 0.0;
\r
513 result = evaluator->evaluate();
\r
516 cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;
\r
517 throw(Exception(EVAL_INVALID_EXPR,this));
\r
522 void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {
\r
523 static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";
\r
524 #ifdef DEBUG_FCTNAME
\r
525 cout << "call to " << qPrintable(fctName) << endl;
\r
527 QList<int> inClock;
\r
530 clearAdmittanceDelays();
\r
532 // trying to synchronize the first one in AP
\r
533 QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);
\r
534 QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);
\r
536 while (iterAP.hasNext()) {
\r
539 QList<char>* ap = iterAP.value();
\r
540 QList<char>* ip = iterIP.value();
\r
542 while ((first < lengthIP) && (ip->at(first) == 0)) first++;
\r
543 while ((first < lengthAP) && (ap->at(first) == 0)) first--;
\r
544 delays.append(first);
\r
546 QList<int>* delays = new QList<int>();
\r
547 admittanceDelays.insert(iterAP.key(), delays);
\r
550 QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);
\r
552 // get the delay to apply
\r
554 for(int i=0;i<delays.size();i++) {
\r
555 if (delays[i] > maxDelay) maxDelay = delays[i];
\r
557 // adding the delays to IP
\r
560 while (iterIP.hasNext()) {
\r
563 QList<char>* ip = iterIP.value();
\r
564 QList<int>* d = iterDelays.value();
\r
565 d->append(maxDelay-delays[i]);
\r
566 cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;
\r
567 for(int j=0;j<maxDelay-delays[i];j++) {
\r
570 for(int j=0;j<delays[i];j++) {
\r
575 lengthIP += maxDelay;
\r
577 cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;
\r
583 // if AP is a valid group, search for the next valid group in IP
\r
584 if (isValidDataGroup(admittance,apIndex)) {
\r
586 while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;
\r
587 if (ipIndex == lengthIP) {
\r
595 iterDelays.toFront();
\r
597 if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {
\r
598 while (iterAP.hasNext()) {
\r
601 QList<char>* ap = iterAP.value();
\r
602 if (ap->at(apIndex) == 1) {
\r
603 QList<int>* d = iterDelays.value();
\r
604 d->append(0); // the 1 is at its good place, so no delay
\r
609 cout << "diff between IP and AP at " << apIndex << endl;
\r
610 // search for the next 1 in IP for every input that has a 1 in AP
\r
612 while (iterAP.hasNext()) {
\r
616 QList<char>* ap = iterAP.value();
\r
617 QList<char>* ip = iterIP.value();
\r
618 QList<int>* d = iterDelays.value();
\r
619 // case 1: 1 in IP is too late
\r
620 if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {
\r
622 while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;
\r
623 cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
624 // moving the 1 to its normal pos.
\r
625 ip->replace(ipIndex,1);
\r
626 ip->replace(ipIndex+delay,0);
\r
629 // case 2: 1 in IP is too soon
\r
630 else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {
\r
632 while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;
\r
633 cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
634 // search for next 0 in IP to put the 1
\r
635 int k = ipIndex+delay;
\r
636 while ((k < lengthIP) && (ip->at(k) == 1)) k++;
\r
637 ip->replace(ipIndex,0);
\r
642 if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {
\r
643 cout << "Abnormal case while searching for delays" << endl;
\r
649 if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;
\r
651 iterDelays.toFront();
\r
652 while (iterDelays.hasNext()) {
\r
654 QList<int>* d = iterDelays.value();
\r
655 foreach(int v, *d) {
\r
663 void FunctionalBlock::createInputPattern() throw(Exception) {
\r
664 static QString fctName = "FunctionalBlock::createInputPattern())";
\r
665 #ifdef DEBUG_FCTNAME
\r
666 cout << "call to " << qPrintable(fctName) << endl;
\r
670 foreach(AbstractInterface* iface, getControlInputs()) {
\r
672 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
673 // check if it is connected
\r
674 if (connIface->getConnectedFrom() == NULL) {
\r
675 throw(Exception(IFACE_NOT_CONNECTED,this));
\r
677 // get the precursor output pattern
\r
678 QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
\r
679 AbstractInputModifier* modifier = connIface->getInputModifier();
\r
680 // check if the input is modified
\r
681 if (modifier != NULL) {
\r
683 out = modifier->getModifiedInput(out);
\r
686 if (out->size() == 0) {
\r
687 clearInputPattern();
\r
688 throw(Exception(NO_IFACE_IP,this));
\r
690 if (lengthIP == -1) {
\r
691 lengthIP = out->size();
\r
694 if (out->size() < lengthIP) lengthIP = out->size();
\r
697 QList<char>* in = new QList<char>(*out);
\r
698 foreach(char c, *in) {
\r
702 inputPattern.insert(connIface,in);
\r
704 // search the last valid group in IP,
\r
705 while(! isValidDataGroup(inputPattern,lengthIP-1)) {
\r
706 //removeDataGroup(inputPattern,lengthIP-1);
\r
711 void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {
\r
712 static QString fctName = "FunctionalBlock::createAdmittance()";
\r
713 #ifdef DEBUG_FCTNAME
\r
714 cout << "call to " << qPrintable(fctName) << endl;
\r
716 // firstly, copy CP in AP
\r
717 QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);
\r
718 while (iterC.hasNext()) {
\r
720 QList<char>* pattern = new QList<char>(*(iterC.value()));
\r
721 admittance.insert(iterC.key(), pattern);
\r
723 lengthAP = lengthCP;
\r
725 cout << "trigger 1 at c.c. 0" << endl;
\r
726 for(int i=1;i<nbExec;i++) {
\r
727 // searching for the clock cycle for which a new exec starts
\r
729 while ((clock < lengthAP) && (nbGroup < delta)) {
\r
730 if (isValidDataGroup(admittance,clock)) nbGroup+=1;
\r
733 while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;
\r
734 cout << "trigger " << (i+1) << " at c.c. " << clock << endl;
\r
736 // combine CP with AP at sc
\r
737 for(int j=0;j<lengthCP;j++) {
\r
738 // first case : column of CP must be placed beyond AP's end.
\r
739 if (sc == lengthAP) {
\r
740 cout << i << "," << j << " append in AP at " << sc << endl;
\r
741 appendToPattern(consumptionPattern,j,admittance,1);
\r
745 // second case : CP and AP can be combined directly (i.e. no X | 1 to do)
\r
746 else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
747 cout << i << "," << j << " combine at " << sc << endl;
\r
748 combinePatterns(consumptionPattern,j,admittance,sc);
\r
751 // third case : CP has an X column
\r
752 else if (isOnlyXDataGroup(consumptionPattern,j)) {
\r
753 cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;
\r
754 shiftRightPattern(admittance,sc);
\r
756 if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
757 cerr << "Abnormal case when combining AP and CP" << endl;
\r
759 combinePatterns(consumptionPattern,j,admittance,sc);
\r
762 // fourth case : AP has an X column
\r
763 else if (isOnlyXDataGroup(admittance,sc)) {
\r
764 cout << i << "," << j << " jump c.c. for CP at " << sc << endl;
\r
769 throw(INVALID_DELTA_CP);
\r
773 // turn all X into 0
\r
774 QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);
\r
775 while (iterA.hasNext()) {
\r
777 QList<char>* pattern = iterA.value();
\r
778 for(int i=0;i<pattern->size();i++) {
\r
779 if (pattern->at(i) == -1) pattern->replace(i,0);
\r
780 cout << (int)(pattern->at(i));
\r
786 void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {
\r
787 static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";
\r
788 #ifdef DEBUG_FCTNAME
\r
789 cout << "call to " << qPrintable(fctName) << endl;
\r
792 // firstly, create input pattern
\r
794 createInputPattern();
\r
796 catch(Exception e) {
\r
799 int nbExec = createTriggers();
\r
800 cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;
\r
803 createAdmittance(nbExec);
\r
805 catch(Exception e) {
\r
806 cout << "cannot create admittance" << endl;
\r
810 int clock = 0; // index in IP
\r
811 int i = 0; // index in AP
\r
812 while ((clock < lengthIP) && (i < lengthAP)) {
\r
814 // if AP is a valid group, search for the next valid group in IP
\r
815 if (isValidDataGroup(admittance,i)) {
\r
816 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
817 if (clock == lengthIP) {
\r
818 cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;
\r
819 throw(Exception(IP_END_NULLCOL,this));
\r
822 /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or
\r
823 are both null columns
\r
825 if (! samePatterns(inputPattern,clock,admittance,i)) {
\r
826 cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;
\r
827 throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible
\r
832 if (clock < lengthIP) {
\r
833 throw(Exception(AP_TOO_SHORT,this));
\r
834 cerr << "Abnormal case: AP is to short" << endl;
\r
838 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
839 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
840 #ifdef DEBUG_FCTNAME
\r
841 cout << "call to " << qPrintable(fctName) << endl;
\r
844 clearOutputPattern();
\r
846 /* case 1: the block is a generator for which output pattern
\r
847 must be computed for a nbExec following executions
\r
851 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
852 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
853 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
854 // create output pattern
\r
855 QList<char>* pp = productionPattern.value(connIface);
\r
856 QList<char>* pattern = new QList<char>(*pp);
\r
857 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
858 // assign pattern to interface
\r
859 connIface->setOutputPattern(pattern);
\r
860 // store it in QMap
\r
861 outputPattern.insert(connIface,pattern);
\r
865 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
867 // in case of inputPattern not created, do it
\r
868 if (lengthIP <= 0) {
\r
870 cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl;
\r
871 // collect the input patterns for each input
\r
873 createInputPattern();
\r
875 catch(Exception e) {
\r
878 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
881 // initialize the output pattern
\r
883 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
884 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
885 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
886 QList<char>* pattern = new QList<char>();
\r
887 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
888 connIface->setOutputPattern(pattern);
\r
889 outputPattern.insert(connIface,pattern);
\r
891 cout << "output pattern array initialized" << endl;
\r
895 // search for the beginning of the first execution.
\r
896 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
897 cout << "found 1st exec clock: " << clock << endl;
\r
899 while (clock < lengthIP) {
\r
900 // initialize counters for current execution.
\r
901 int p = 0; // index in production pattern
\r
902 int o = 0; // clock+o will give the clock cycle of each output group
\r
903 int cip = 0; // clock+cip give the clock cycle of an input group
\r
904 int ccp = 0; // ccp give a column in the consumptio pattern
\r
905 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
906 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
907 bool cannotCompleteExec = false;
\r
908 for(int m=0;m<productionCounter.size();m++) {
\r
909 // search for the first production in PP
\r
910 while (!isValidDataGroup(productionPattern,p)) {
\r
914 int gap = 0; // count the number of extra null columns
\r
915 // search for PC(m) valid input group in IP
\r
916 while (nip < productionCounter.at(m)) {
\r
917 if (clock+cip < lengthIP) {
\r
918 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
923 cannotCompleteExec = true;
\r
928 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
930 // search for PC(m) valid input group in IP
\r
931 while (ncp < productionCounter.at(m)) {
\r
932 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
936 o += gap; // to take into acocunt of extra null columns
\r
937 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
942 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
944 // current exec. taken into accunt
\r
947 // search for the next exec.
\r
950 while ((clock < lengthIP) && (nip < delta)) {
\r
951 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
952 if (nip < delta) clock += 1;
\r
954 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
956 // find the last valid output data group
\r
957 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
958 removeDataGroup(outputPattern,lengthOP-1);
\r
962 // clear input pattern
\r
963 clearInputPattern();
\r
969 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
970 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
971 #ifdef DEBUG_FCTNAME
\r
972 cout << "call to " << qPrintable(fctName) << endl;
\r
975 // case 1: the block is a generator for which output pattern
\r
976 // must be computed for a nbExec following executions
\r
979 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
980 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
981 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
982 // create output pattern
\r
983 QList<char>* pp = productionPattern.value(connIface);
\r
984 QList<char>* pattern = new QList<char>(*pp);
\r
985 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
986 // assign pattern to interface
\r
987 connIface->setOutputPattern(pattern);
\r
988 // store it in QMap
\r
989 outputPattern.insert(connIface,pattern);
\r
993 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
995 // in case of inputPattern not created, do it
\r
996 if (lengthIP <= 0) {
\r
997 // collect the input patterns for each input
\r
999 createInputPattern();
\r
1001 catch(Exception e) {
\r
1004 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
1007 // initialize the output pattern
\r
1009 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
1010 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
1011 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
1012 QList<char>* pattern = new QList<char>();
\r
1013 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
1014 connIface->setOutputPattern(pattern);
\r
1015 outputPattern.insert(connIface,pattern);
\r
1017 cout << "output pattern array initialized" << endl;
\r
1021 // search for the beginning of the first execution.
\r
1022 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
1023 cout << "found 1st exec clock: " << clock << endl;
\r
1025 while (clock < lengthIP) {
\r
1026 // initialize counters for current execution.
\r
1027 int p = 0; // index in production pattern
\r
1028 int o = 0; // clock+o will give the clock cycle of each output group
\r
1029 int cip = 0; // clock+cip give the clock cycle of an input group
\r
1030 int ccp = 0; // ccp give a column in the consumptio pattern
\r
1031 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
1032 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
1033 bool cannotCompleteExec = false;
\r
1034 for(int m=0;m<productionCounter.size();m++) {
\r
1035 // search for the first production in PP
\r
1036 while (!isValidDataGroup(productionPattern,p)) {
\r
1040 int gap = 0; // count the number of extra null columns
\r
1041 // search for PC(m) valid input group in IP
\r
1042 while (nip < productionCounter.at(m)) {
\r
1043 if (clock+cip < lengthIP) {
\r
1044 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
1049 cannotCompleteExec = true;
\r
1054 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1056 // search for PC(m) valid input group in IP
\r
1057 while (ncp < productionCounter.at(m)) {
\r
1058 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
1062 o += gap; // to take into acocunt of extra null columns
\r
1063 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
1068 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1070 // current exec. taken into accunt
\r
1073 // search for the next exec.
\r
1076 while ((clock < lengthIP) && (nip < delta)) {
\r
1077 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
1078 if (nip < delta) clock += 1;
\r
1080 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
1082 // find the last valid output data group
\r
1083 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
1084 removeDataGroup(outputPattern,lengthOP-1);
\r
1088 // clear input pattern
\r
1089 clearInputPattern();
\r
1093 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1095 if (patternSrc.size() != patternDest.size()) return false;
\r
1096 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1097 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1098 while (iterSrc.hasNext()) {
\r
1101 QList<char>* srcPat = iterSrc.value();
\r
1102 QList<char>* destPat = iterDest.value();
\r
1103 if (srcCol >= srcPat->size()) return false;
\r
1104 if (destCol >= destPat->size()) return false;
\r
1105 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1110 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int> &srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1111 if (patternSrc.size() != srcCols.size()) return false;
\r
1112 if (patternSrc.size() != patternDest.size()) return false;
\r
1114 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1115 QListIterator<int> iterSrcCol(srcCols);
\r
1116 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1117 while (iterSrc.hasNext()) {
\r
1119 int srcCol = iterSrcCol.next();
\r
1121 QList<char>* srcPat = iterSrc.value();
\r
1122 QList<char>* destPat = iterDest.value();
\r
1123 if (srcCol >= srcPat->size()) return false;
\r
1124 if (destCol >= destPat->size()) return false;
\r
1125 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1130 bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1131 if (patternSrc.size() != patternDest.size()) return false;
\r
1132 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1133 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1134 while (iterSrc.hasNext()) {
\r
1137 QList<char>* srcPat = iterSrc.value();
\r
1138 QList<char>* destPat = iterDest.value();
\r
1139 if (srcCol >= srcPat->size()) return false;
\r
1140 if (destCol >= destPat->size()) return false;
\r
1141 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return false;
\r
1142 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;
\r
1147 void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1148 if (patternSrc.size() != patternDest.size()) return;
\r
1149 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1150 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1151 while (iterSrc.hasNext()) {
\r
1154 QList<char>* srcPat = iterSrc.value();
\r
1155 QList<char>* destPat = iterDest.value();
\r
1156 if (srcCol >= srcPat->size()) return;
\r
1157 if (destCol >= destPat->size()) return;
\r
1158 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;
\r
1159 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return;
\r
1160 destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));
\r
1164 void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {
\r
1165 if (patternSrc.size() != patternDest.size()) return;
\r
1166 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1167 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1168 while (iterSrc.hasNext()) {
\r
1171 QList<char>* srcPat = iterSrc.value();
\r
1172 QList<char>* destPat = iterDest.value();
\r
1174 while ((srcCol+i < srcPat->size()) && (i<nbCols)) {
\r
1175 destPat->append(srcPat->at(srcCol+i));
\r
1181 void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1182 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1183 while (iterSrc.hasNext()) {
\r
1185 QList<char>* srcPat = iterSrc.value();
\r
1186 if (offset < srcPat->size()) {
\r
1187 srcPat->removeAt(offset);
\r
1192 void FunctionalBlock::shiftRightPattern(const 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->insert(offset,0);
\r
1203 bool FunctionalBlock::isValidDataGroup(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()) return false;
\r
1209 if (srcPat->at(offset) == 1) return true;
\r
1214 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets) {
\r
1215 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1216 QListIterator<int> iterOffsets(offsets);
\r
1217 while (iterSrc.hasNext()) {
\r
1219 int offset = iterOffsets.next();
\r
1220 QList<char>* srcPat = iterSrc.value();
\r
1221 if (offset >= srcPat->size()) return false;
\r
1222 if (srcPat->at(offset) == 1) return true;
\r
1227 bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1228 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1229 while (iterSrc.hasNext()) {
\r
1231 QList<char>* srcPat = iterSrc.value();
\r
1232 if (offset >= srcPat->size()) return false;
\r
1233 if (srcPat->at(offset) != -1) return false;
\r
1238 void FunctionalBlock::clearConsumptionPattern() {
\r
1239 QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern);
\r
1240 while (iterP.hasNext()) {
\r
1242 QList<char>* pattern = iterP.value();
\r
1243 if (pattern != NULL) delete pattern;
\r
1245 consumptionPattern.clear();
\r
1249 void FunctionalBlock::clearProductionPattern() {
\r
1250 QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern);
\r
1251 while (iterP.hasNext()) {
\r
1253 QList<char>* pattern = iterP.value();
\r
1254 if (pattern != NULL) delete pattern;
\r
1256 productionPattern.clear();
\r
1260 void FunctionalBlock::clearInputPattern() {
\r
1262 QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);
\r
1263 while (iterI.hasNext()) {
\r
1265 QList<char>* pattern = iterI.value();
\r
1266 if (pattern != NULL) delete pattern;
\r
1268 inputPattern.clear();
\r
1272 void FunctionalBlock::clearOutputPattern() {
\r
1274 QMapIterator<AbstractInterface*,QList<char>* > iterO(outputPattern);
\r
1275 while (iterO.hasNext()) {
\r
1277 ConnectedInterface* connIface = AI_TO_CON(iterO.key());
\r
1278 connIface->resetOutputPattern();
\r
1279 QList<char>* pattern = iterO.value();
\r
1280 if (pattern != NULL) delete pattern;
\r
1282 outputPattern.clear();
\r
1286 void FunctionalBlock::clearAdmittanceDelays() {
\r
1287 QMapIterator<AbstractInterface*, QList<int>* > iterA(admittanceDelays);
\r
1288 while (iterA.hasNext()) {
\r
1290 QList<int>* d = iterA.value();
\r
1291 if (d != NULL) delete d;
\r
1293 admittanceDelays.clear();
\r
1296 int FunctionalBlock::createTriggers() {
\r
1298 /* NB: this method returns the number of executions that have been started
\r
1299 but not necessary completed.
\r
1301 if (delta <= 0) return 0;
\r
1303 // search for the first exec.
\r
1304 while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;
\r
1305 if (offset == lengthIP) return 0;
\r
1306 triggers.append(offset);
\r
1308 for(int i = offset;i<lengthIP;i++) {
\r
1309 if (isValidDataGroup(inputPattern,i)) nbGroup++;
\r
1310 if (nbGroup == delta+1) {
\r
1311 triggers.append(i);
\r
1315 return triggers.size();
\r
1318 void FunctionalBlock::generateVHDL(const QString& path) throw(Exception){
\r
1320 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1321 QFile implFile(impl->getXmlFile());
\r
1323 // reading in into QDomDocument
\r
1324 QDomDocument document("implFile");
\r
1326 if (!implFile.open(QIODevice::ReadOnly)) {
\r
1327 throw(Exception(IMPLFILE_NOACCESS));
\r
1329 if (!document.setContent(&implFile)) {
\r
1331 throw(Exception(IMPLFILE_NOACCESS));
\r
1335 bool genController = false;
\r
1336 QString coreFile = "";
\r
1337 QString controllerFile = "";
\r
1339 if (reference->isWBConfigurable()) {
\r
1340 genController = true;
\r
1341 controllerFile = path;
\r
1342 controllerFile += "/";
\r
1343 controllerFile.append(name);
\r
1344 controllerFile.append("_ctrl.vhd");
\r
1347 controllerFile = "nofile.vhd";
\r
1351 coreFile.append(name);
\r
1352 coreFile.append(".vhd");
\r
1354 QFile vhdlCore(coreFile);
\r
1355 QFile vhdlController(controllerFile);
\r
1357 if (!vhdlCore.open(QIODevice::WriteOnly)) {
\r
1358 throw(Exception(VHDLFILE_NOACCESS));
\r
1361 if (genController) {
\r
1362 if (!vhdlController.open(QIODevice::WriteOnly)) {
\r
1363 throw(Exception(VHDLFILE_NOACCESS));
\r
1366 QTextStream outCore(&vhdlCore);
\r
1367 QTextStream outController;
\r
1368 if (genController) {
\r
1369 outController.setDevice(&vhdlController);
\r
1373 //Get the root element
\r
1374 QDomElement impl = document.documentElement();
\r
1375 QDomElement eltComments = impl.firstChildElement("comments");
\r
1376 generateComments(outCore,eltComments, coreFile);
\r
1377 QDomElement eltLibs = eltComments.nextSiblingElement("libraries");
\r
1378 generateLibraries(outCore, eltLibs);
\r
1379 generateEntity(outCore, genController);
\r
1380 QDomElement eltArch = eltLibs.nextSiblingElement("architecture");
\r
1381 generateArchitecture(outCore, eltArch );
\r
1382 if (genController) {
\r
1383 generateController(outController);
\r
1386 catch(Exception err) {
\r
1391 vhdlController.close();
\r
1395 void FunctionalBlock::generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) {
\r
1397 for(int i = 0; i < 50; i++) {
\r
1400 out << "\n--" << endl;
\r
1401 QString fileName = coreFile;
\r
1402 out << "-- File : " << fileName << endl;
\r
1403 out << "--" << endl;
\r
1404 QDomElement eltAuthor = elt.firstChildElement("author");
\r
1405 QString firstName = eltAuthor.attribute("firstname","");
\r
1406 QString lastName = eltAuthor.attribute("lastname","");
\r
1407 QString mail = eltAuthor.attribute("mail","");
\r
1408 out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")" << endl;
\r
1409 out << "--" << endl;
\r
1410 QDomElement eltDate = eltAuthor.nextSiblingElement("date");
\r
1411 QString crea = eltDate.attribute("creation","");
\r
1412 out << "-- Creation Date : "<<crea<< endl;
\r
1413 out << "--" << endl;
\r
1414 QDomElement eltRelated = eltDate.nextSiblingElement("related_files");
\r
1415 QString relateds = eltRelated.attribute("list","");
\r
1416 out << "-- Related files :\n"<<relateds<<endl;
\r
1417 out << "--" << endl;
\r
1418 QDomElement eltDesc = eltRelated.nextSiblingElement("description");
\r
1419 QDomElement desc = eltDesc.firstChildElement();
\r
1420 QString descTxt = desc.text();
\r
1421 out << "-- Decription :\n"<<descTxt<<endl;
\r
1422 out << "--" << endl;
\r
1423 QDomElement eltNote = eltDesc.nextSiblingElement("description");
\r
1424 QDomElement note = eltNote.firstChildElement();
\r
1425 QString noteTxt = note.text();
\r
1426 out << "-- Note :\n"<<noteTxt<<endl;
\r
1427 out << "--" << endl;
\r
1428 for(int i = 0; i < 50; i++) {
\r
1431 out << endl << endl;
\r
1434 void FunctionalBlock::generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) {
\r
1436 QDomNodeList listLib = elt.elementsByTagName("library");
\r
1437 for(int i = 0; i < listLib.length(); i++) {
\r
1438 QDomNode nodeLib = listLib.item(i);
\r
1439 QDomElement eltLib = nodeLib.toElement();
\r
1440 QString nameLib = eltLib.attribute("name","none");
\r
1441 out << "library " << nameLib << ";" << endl;
\r
1442 QDomNodeList listPack = eltLib.elementsByTagName("package");
\r
1443 for(int j = 0; j < listPack.length(); j++) {
\r
1444 QDomNode nodePack = listPack.item(j);
\r
1445 QDomElement eltPack = nodePack.toElement();
\r
1446 QString namePack = eltPack.attribute("name","none");
\r
1447 QString usePack = eltPack.attribute("use","none");
\r
1448 out << "use " << nameLib << "." << namePack << "." << usePack << endl;
\r
1454 void FunctionalBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {
\r
1458 //QList<BlockParameter*> listParams = reference->getParameters();
\r
1459 QList<AbstractInterface*> listInputs = getInputs();
\r
1460 QList<AbstractInterface*> listOutputs = getOutputs();
\r
1461 QList<AbstractInterface*> listBidirs = getBidirs();
\r
1462 QString typePort, namePort;
\r
1464 out << "entity " << name << " is" << endl;
\r
1467 /* TODO : rewrite the generation to take into acocunt the new object hierarchy */
\r
1469 // Generation of the generics
\r
1470 QList<BlockParameter*> listGenerics = getGenericParameters();
\r
1471 if ((!listGenerics.isEmpty()) || (hasController)) {
\r
1472 out << " generic (" << endl;
\r
1473 if (hasController) {
\r
1474 out << " wb_data_width : integer = 16;" << endl;
\r
1475 out << " wb_addr_width : integer = 12";
\r
1476 if (!listGenerics.isEmpty()) out << ";";
\r
1479 for(i=0;i<listGenerics.size()-1;i++) {
\r
1480 out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1482 out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1484 out << " );" << endl;
\r
1487 out << " port (" << endl;
\r
1489 // Generation of the clk & rst signals
\r
1490 out << " -- clk/rst" << endl;
\r
1491 foreach(AbstractInterface* iface, listInputs) {
\r
1492 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1493 out << " " << iface->getName() << " : in std_logic;" << endl;
\r
1497 if (hasController) {
\r
1498 // Generation of the wishbone signals
\r
1499 out << " -- registers r/w via wishbone" << endl;
\r
1500 QList<BlockParameter*> listWB = reference->getWishboneParameters();
\r
1501 for(i=0;i<listWB.size()-1;i++) {
\r
1502 out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1504 out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1509 foreach(AbstractInterface* iface, getInterfaces()) {
\r
1510 if((iface->getPurpose() == AbstractInterface::Data)||(iface->getPurpose() == AbstractInterface::Control)) count++;
\r
1512 // Generation of the data/control signals
\r
1515 bool first = true;
\r
1517 foreach(AbstractInterface* iface, listInputs) {
\r
1518 if(iface->getPurpose() == AbstractInterface::Data) {
\r
1520 out << " -- input data ports" << endl;
\r
1524 if (count == 0) flag = AbstractInterface::NoComma;
\r
1525 out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;
\r
1529 foreach(AbstractInterface* iface, listInputs) {
\r
1530 if(iface->getPurpose() == AbstractInterface::Control) {
\r
1532 out << " -- input control ports" << endl;
\r
1536 if (count == 0) flag = AbstractInterface::NoComma;
\r
1537 out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;
\r
1541 foreach(AbstractInterface* iface, listOutputs) {
\r
1542 if(iface->getPurpose() == AbstractInterface::Data) {
\r
1544 out << " -- output data ports" << endl;
\r
1548 if (count == 0) flag = AbstractInterface::NoComma;
\r
1549 out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;
\r
1553 foreach(AbstractInterface* iface, listOutputs) {
\r
1554 if(iface->getPurpose() == AbstractInterface::Control) {
\r
1556 out << " -- output control ports" << endl;
\r
1560 if (count == 0) flag = AbstractInterface::NoComma;
\r
1561 out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;
\r
1565 foreach(AbstractInterface* iface, listBidirs) {
\r
1566 if(iface->getPurpose() == AbstractInterface::Data) {
\r
1568 out << " -- bidirs data ports" << endl;
\r
1572 if (count == 0) flag = AbstractInterface::NoComma;
\r
1573 out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;
\r
1576 out << " );" << endl << endl;
\r
1577 out << "end " << name << ";" << endl << endl;
\r
1580 void FunctionalBlock::generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) {
\r
1582 QString code = elt.text();
\r
1583 cout << qPrintable(code) << endl;
\r
1584 out << "architecture rtl of " << name << " is" << endl;
\r
1586 QStringList listLine = code.split("\n");
\r
1587 for(int i =0; i < listLine.size(); i++) {
\r
1588 QString line = listLine.at(i).simplified();
\r
1591 if(listLine.at(i).contains(QRegularExpression("@foreach{"))) {
\r
1592 while(listLine.at(i).compare("@endforeach") != -1) {
\r
1593 expr = expr + listLine.at(i) + '\n';
\r
1596 expr = expr + listLine.at(i);
\r
1597 out << evalComplex(expr, 1) << '\n';
\r
1599 if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) {
\r
1600 while(listLine.at(i).compare("@endcaseeach") != -1) {
\r
1601 expr = expr + listLine.at(i) + '\n';
\r
1604 expr = expr + listLine.at(i);
\r
1605 out << evalComplex(expr, 2) << '\n';
\r
1608 if(line.contains("@{")) {
\r
1609 out << line << endl;
\r
1614 void FunctionalBlock::generateController(QTextStream &out) throw(Exception) {
\r