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, bool createIfaces) 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
39 FunctionalBlock::~FunctionalBlock() {
\r
40 if (evaluator != NULL) delete evaluator;
\r
43 void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
\r
45 checkedBlocks->append(this);
\r
47 foreach(BlockParameter* param, params){
\r
48 if(param->isUserParameter() && !param->isValueSet()){
\r
49 if(!blocksToConfigure->contains(param->getOwner())){
\r
50 blocksToConfigure->append(param->getOwner());
\r
54 foreach(AbstractInterface *inter, outputs){
\r
55 foreach(AbstractInterface *connectedInter, inter->getConnectedTo()){
\r
56 if(!checkedBlocks->contains(connectedInter->getOwner())){
\r
57 connectedInter->getOwner()->parametersValidation(checkedBlocks, blocksToConfigure);
\r
64 bool FunctionalBlock::isFunctionalBlock() {
\r
68 bool FunctionalBlock::isSourceBlock() {
\r
69 if (parent == NULL) return true;
\r
73 void FunctionalBlock::populate() {
\r
76 AbstractInterface* inter;
\r
78 // create parameters from reference block
\r
79 QList<BlockParameter*> lstParam = reference->getParameters();
\r
80 for(i=0;i<lstParam.size();i++) {
\r
81 p = lstParam.at(i)->clone();
\r
85 ConnectedInterface* toClk = NULL;
\r
86 ConnectedInterface* toRst = NULL;
\r
87 // create interfaces from reference block
\r
88 QList<AbstractInterface *> lstRef = reference->getInterfaces();
\r
89 // store relation between functional and reference
\r
90 QHash<AbstractInterface *, AbstractInterface *> hashIface;
\r
91 for(i=0;i<lstRef.size();i++) {
\r
93 inter = new FunctionalInterface(this, AI_TO_REF(lstRef.at(i)));
\r
95 catch(Exception e) {
\r
96 cerr << "Abnormal case: " << qPrintable(e.getDefaultMessage()) << endl << "Aborting execution." << endl;
\r
99 hashIface.insert(lstRef.at(i),inter);
\r
100 addInterface(inter);
\r
101 /* WARNING FOR THE FUTURE :
\r
102 in case of there are several clock interfaces ofr that block
\r
103 it would be a godd idea to make the user choose which one
\r
104 must be connected to defautl clk.
\r
105 Presently, the first encountered is chosen
\r
107 if ((toClk == NULL) && (inter->getPurpose() == AbstractInterface::Clock)) {
\r
108 toClk = AI_TO_CON(inter);
\r
110 if ((toRst == NULL) && (inter->getPurpose() == AbstractInterface::Reset)) {
\r
111 toRst = AI_TO_CON(inter);
\r
115 AbstractInterface* funCtlIface = NULL;
\r
116 AbstractInterface* funDataIface = NULL;
\r
118 for(i=0;i<lstRef.size();i++) {
\r
119 AbstractInterface* refIface = lstRef.at(i);
\r
120 if (refIface->getPurpose() == AbstractInterface::Control) {
\r
121 funCtlIface = hashIface.value(refIface);
\r
122 funDataIface = hashIface.value(refIface->getAssociatedIface());
\r
123 if (! funCtlIface->setAssociatedIface(funDataIface)) {
\r
124 cerr << "Abnormal case when associating a control interface to data" << endl << "Aborting execution." << endl;
\r
130 // connect clk and rst to group clk/rst or to clkrstgen
\r
131 if ((name != "clkrstgen") && (parent != NULL)) {
\r
135 catch(Exception e) {
\r
136 AbstractBlock* source = (AbstractBlock *)(e.getSource());
\r
137 cerr << qPrintable(source->getName()) << ":" << qPrintable(e.getMessage()) << endl;
\r
143 QString FunctionalBlock::getReferenceXmlFile() {
\r
144 return ((ReferenceBlock *)reference)->getXmlFile();
\r
147 QString FunctionalBlock::getReferenceHashMd5() {
\r
148 return ((ReferenceBlock *)reference)->getHashMd5();
\r
151 void FunctionalBlock::createPatterns() throw(Exception) {
\r
152 static QString fctName = "FunctionalBlock::createPatterns()";
\r
153 #ifdef DEBUG_FCTNAME
\r
154 cout << "call to " << qPrintable(fctName) << endl;
\r
157 if (implementation->hasNoPatterns()) return;
\r
159 cout << "create patterns for block " << qPrintable(name) << endl;
\r
160 if (evaluator == NULL) evaluator = new ArithmeticEvaluator();
\r
161 if (! isGeneratorBlock()) {
\r
164 createConsumptionPattern();
\r
165 createProductionCounter();
\r
167 catch(Exception e) {
\r
168 throw(e); // rethrow e
\r
172 createProductionPattern();
\r
174 catch(Exception e) {
\r
177 cout << "PP of " << qPrintable(name) << endl;
\r
178 QMapIterator<AbstractInterface*,QList<char>* > it(productionPattern);
\r
179 while (it.hasNext()) {
\r
181 QList<char>* pat = it.value();
\r
182 foreach(char c, *pat) cout << (int)c;
\r
187 void FunctionalBlock::createDelta() throw(Exception) {
\r
188 static QString fctName = "FunctionalBlock::createDelta()";
\r
189 #ifdef DEBUG_FCTNAME
\r
190 cout << "call to " << qPrintable(fctName) << endl;
\r
193 QString deltaStr = implementation->getDelta();
\r
194 cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;
\r
195 if (deltaStr.isEmpty()) {
\r
200 // look for parameter names
\r
203 result = evaluateExpression(deltaStr);
\r
205 catch(Exception e) {
\r
209 cout << "delta = " << delta << endl;
\r
212 void FunctionalBlock::createConsumptionPattern() throw(Exception) {
\r
213 static QString fctName = "FunctionalBlock::createConsumptionPattern()";
\r
214 #ifdef DEBUG_FCTNAME
\r
215 cout << "call to " << qPrintable(fctName) << endl;
\r
218 // first clear if already exists
\r
219 clearConsumptionPattern();
\r
222 QHash<QString,QString> consPattern = implementation->getConsumptionPattern();
\r
224 foreach(AbstractInterface* iface, getControlInputs()) {
\r
225 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
226 QString refName = connIface->getReference()->getName();
\r
227 if (! consPattern.contains(refName)) {
\r
228 throw(Exception(NO_IFACE_CP,this));
\r
229 cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;
\r
231 QList<char>* pattern = NULL;
\r
233 pattern = expandPattern(consPattern.value(refName));
\r
235 catch(Exception e) {
\r
238 consumptionPattern.insert(connIface,pattern);
\r
239 if (lengthCP == -1) {
\r
240 lengthCP = pattern->size();
\r
243 if (pattern->size() != lengthCP) {
\r
244 throw(Exception(INVALID_IFACE_CP_LENGTH,this));
\r
250 void FunctionalBlock::createProductionPattern() throw(Exception){
\r
251 static QString fctName = "FunctionalBlock::createProductionPattern()";
\r
252 #ifdef DEBUG_FCTNAME
\r
253 cout << "call to " << qPrintable(fctName) << endl;
\r
256 // first clear if already exists
\r
257 clearProductionPattern();
\r
260 QHash<QString,QString> prodPattern = implementation->getProductionPattern();
\r
262 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
263 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
264 QString refName = connIface->getReference()->getName();
\r
265 if (! prodPattern.contains(refName)) {
\r
266 throw(Exception(NO_IFACE_PP,this));
\r
268 QList<char>* pattern = NULL;
\r
270 pattern = expandPattern(prodPattern.value(refName));
\r
272 catch(Exception e) {
\r
275 productionPattern.insert(connIface,pattern);
\r
276 if (lengthPP == -1) {
\r
277 lengthPP = pattern->size();
\r
280 if (pattern->size() != lengthPP) {
\r
281 throw(Exception(INVALID_IFACE_PP_LENGTH,this));
\r
287 void FunctionalBlock::createProductionCounter() throw(Exception) {
\r
288 static QString fctName = "FunctionalBlock::createProductionCounter()";
\r
289 #ifdef DEBUG_FCTNAME
\r
290 cout << "call to " << qPrintable(fctName) << endl;
\r
293 // first clear if already exists
\r
294 productionCounter.clear();
\r
297 QStringList counterParts = implementation->getProductionCounter().split(",");
\r
298 foreach(QString s, counterParts) {
\r
299 cout << "cont part = " << qPrintable(s) << endl;
\r
301 double val = s.toDouble(&ok);
\r
303 productionCounter.append(val);
\r
305 else if (s.at(0) == '{') {
\r
308 QStringList gen = s.split(":");
\r
309 if (gen.size() != 3) {
\r
310 throw(Exception(INVALID_IFACE_PC,this));
\r
315 for(int i=0;i<3;i++) {
\r
316 double result = 0.0;
\r
318 result = evaluateExpression(gen.at(i));
\r
320 catch(Exception e) {
\r
323 if (i==0) start = result;
\r
324 else if (i==1) nb = result;
\r
325 else if (i==2) step = result;
\r
327 for(int j=0;j<nb;j++) {
\r
328 productionCounter.append(start+j*step);
\r
332 double result = 0.0;
\r
334 result = evaluateExpression(s);
\r
336 catch(Exception e) {
\r
339 productionCounter.append(result);
\r
342 foreach(int val, productionCounter) {
\r
343 cout << val << ",";
\r
348 QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {
\r
349 static QString fctName = "FunctionalBlock::expandPattern()";
\r
350 #ifdef DEBUG_FCTNAME
\r
351 cout << "call to " << qPrintable(fctName) << endl;
\r
353 /* expanding a pattern is done in two steps :
\r
354 - 1 : finding all variables that correspond to an expression
\r
355 and copy them in the pattern
\r
356 - 2 : parsing the result
\r
358 Note that the result MUST contain only variables that have a
\r
359 integer/double value. Otherwise, expanding will fail.
\r
365 QString p = replaceExpressions(patternIn);
\r
370 QList<char>* patternOut = new QList<char>();
\r
372 patternOut->append(expandPatternRecur(p,&offset));
\r
374 catch(Exception e) {
\r
381 QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) {
\r
383 QString res = patternIn;
\r
385 QRegularExpression re("[$][a-zA-Z0-9_]+");
\r
389 QRegularExpressionMatchIterator matcher = re.globalMatch(res);
\r
390 while(matcher.hasNext()) {
\r
391 QRegularExpressionMatch m = matcher.next();
\r
392 QString param = m.captured(0);
\r
393 QString paramName = param;
\r
394 paramName.remove(0,1);
\r
395 BlockParameter* p = getParameterFromName(paramName);
\r
396 if ((p != NULL) && (p->getType() == BlockParameter::Expression)) {
\r
397 res.replace(param,p->getStringValue());
\r
399 cout << "found an expr: " << qPrintable(paramName) << ", patern => " << qPrintable(res) << endl;
\r
406 QList<char> FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset) throw(Exception) {
\r
408 QList<char> patternOut;
\r
410 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {
\r
412 QChar c = patternIn.at(*offset);
\r
416 patternOut.append(expandPatternRecur(patternIn,offset));
\r
418 catch(Exception e) {
\r
422 else if (c == '0') {
\r
423 patternOut.append(0);
\r
425 else if (c == '1') {
\r
426 patternOut.append(1);
\r
428 else if (c == 'X') {
\r
429 patternOut.append(-1);
\r
431 else if (c == '{') {
\r
433 QString expr = "";
\r
434 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
435 expr += patternIn.at(*offset);
\r
438 if (*offset == patternIn.size()) {
\r
439 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
443 repeat = evaluateExpression(expr);
\r
445 catch(Exception e) {
\r
450 patternOut.removeLast();
\r
453 // repeat just the last value in currentGroup
\r
454 char last = patternOut.last();
\r
455 //cout << "repeat last char " << repeat << " times : " << (int)last << endl;
\r
456 for(int i=1;i<(int)repeat;i++) {
\r
457 patternOut.append(last);
\r
464 // must check if after ), there is a {
\r
465 if ((*offset < patternIn.size()-1) && (patternIn.at(*offset+1) == '{')) {
\r
467 QString expr = "";
\r
468 while ((*offset < patternIn.size()) && (patternIn.at(*offset) != '}')) {
\r
469 expr += patternIn.at(*offset);
\r
472 if (*offset == patternIn.size()) {
\r
473 throw(Exception(INVALID_IFACE_PATTERN,this));
\r
477 repeat = evaluateExpression(expr);
\r
479 catch(Exception e) {
\r
483 QList<char> voidList;
\r
488 cout << "repeat last group " << repeat << " times : ";
\r
489 foreach (char c, currentGroup) cout <<(int)c;
\r
492 QList<char> single = patternOut;
\r
493 for(int i=1;i<(int)repeat;i++) {
\r
494 patternOut.append(single);
\r
501 double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {
\r
502 static QString fctName = "FunctionalBlock::evaluateExpression()";
\r
503 #ifdef DEBUG_FCTNAME
\r
504 cout << "call to " << qPrintable(fctName) << endl;
\r
507 QHash<QString,double> vars;
\r
508 evaluator->setExpression(expression);
\r
509 QList<QString> varNames = evaluator->getVariableNames();
\r
510 foreach (QString name, varNames) {
\r
511 QString paramName = name;
\r
512 paramName.remove(0,1);
\r
513 BlockParameter* param = getParameterFromName(paramName);
\r
514 if (param == NULL) {
\r
515 throw(Exception(EVAL_PARAM_UNKNOWN,this));
\r
518 int val = param->getDoubleValue(&okVal);
\r
520 throw(Exception(EVAL_PARAM_NOVALUE,this));
\r
522 vars.insert(name,(double)val);
\r
525 evaluator->setVariablesValue(vars);
\r
526 double result = 0.0;
\r
528 result = evaluator->evaluate();
\r
531 cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;
\r
532 throw(Exception(EVAL_INVALID_EXPR,this));
\r
537 void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {
\r
538 static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";
\r
539 #ifdef DEBUG_FCTNAME
\r
540 cout << "call to " << qPrintable(fctName) << endl;
\r
542 QList<int> inClock;
\r
545 clearAdmittanceDelays();
\r
547 // trying to synchronize the first one in AP
\r
548 QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);
\r
549 QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);
\r
551 while (iterAP.hasNext()) {
\r
554 QList<char>* ap = iterAP.value();
\r
555 QList<char>* ip = iterIP.value();
\r
557 while ((first < lengthIP) && (ip->at(first) == 0)) first++;
\r
558 while ((first < lengthAP) && (ap->at(first) == 0)) first--;
\r
559 delays.append(first);
\r
561 QList<int>* delays = new QList<int>();
\r
562 admittanceDelays.insert(iterAP.key(), delays);
\r
565 QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);
\r
567 // get the delay to apply
\r
569 for(int i=0;i<delays.size();i++) {
\r
570 if (delays[i] > maxDelay) maxDelay = delays[i];
\r
572 // adding the delays to IP
\r
575 while (iterIP.hasNext()) {
\r
578 QList<char>* ip = iterIP.value();
\r
579 QList<int>* d = iterDelays.value();
\r
580 d->append(maxDelay-delays[i]);
\r
581 cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;
\r
582 for(int j=0;j<maxDelay-delays[i];j++) {
\r
585 for(int j=0;j<delays[i];j++) {
\r
590 lengthIP += maxDelay;
\r
592 cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;
\r
598 // if AP is a valid group, search for the next valid group in IP
\r
599 if (isValidDataGroup(admittance,apIndex)) {
\r
601 while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;
\r
602 if (ipIndex == lengthIP) {
\r
610 iterDelays.toFront();
\r
612 if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {
\r
613 while (iterAP.hasNext()) {
\r
616 QList<char>* ap = iterAP.value();
\r
617 if (ap->at(apIndex) == 1) {
\r
618 QList<int>* d = iterDelays.value();
\r
619 d->append(0); // the 1 is at its good place, so no delay
\r
624 cout << "diff between IP and AP at " << apIndex << endl;
\r
625 // search for the next 1 in IP for every input that has a 1 in AP
\r
627 while (iterAP.hasNext()) {
\r
631 QList<char>* ap = iterAP.value();
\r
632 QList<char>* ip = iterIP.value();
\r
633 QList<int>* d = iterDelays.value();
\r
634 // case 1: 1 in IP is too late
\r
635 if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {
\r
637 while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;
\r
638 cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
639 // moving the 1 to its normal pos.
\r
640 ip->replace(ipIndex,1);
\r
641 ip->replace(ipIndex+delay,0);
\r
644 // case 2: 1 in IP is too soon
\r
645 else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {
\r
647 while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;
\r
648 cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;
\r
649 // search for next 0 in IP to put the 1
\r
650 int k = ipIndex+delay;
\r
651 while ((k < lengthIP) && (ip->at(k) == 1)) k++;
\r
652 ip->replace(ipIndex,0);
\r
657 if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {
\r
658 cout << "Abnormal case while searching for delays" << endl;
\r
664 if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;
\r
666 iterDelays.toFront();
\r
667 while (iterDelays.hasNext()) {
\r
669 QList<int>* d = iterDelays.value();
\r
670 foreach(int v, *d) {
\r
678 void FunctionalBlock::createInputPattern() throw(Exception) {
\r
679 static QString fctName = "FunctionalBlock::createInputPattern())";
\r
680 #ifdef DEBUG_FCTNAME
\r
681 cout << "call to " << qPrintable(fctName) << endl;
\r
685 foreach(AbstractInterface* iface, getControlInputs()) {
\r
687 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
688 // check if it is connected
\r
689 if (connIface->getConnectedFrom() == NULL) {
\r
690 throw(Exception(IFACE_NOT_CONNECTED,this));
\r
692 // get the precursor output pattern
\r
693 QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();
\r
694 AbstractInputModifier* modifier = connIface->getInputModifier();
\r
695 // check if the input is modified
\r
696 if (modifier != NULL) {
\r
698 out = modifier->getModifiedInput(out);
\r
701 if (out->size() == 0) {
\r
702 clearInputPattern();
\r
703 throw(Exception(NO_IFACE_IP,this));
\r
705 if (lengthIP == -1) {
\r
706 lengthIP = out->size();
\r
709 if (out->size() < lengthIP) lengthIP = out->size();
\r
712 QList<char>* in = new QList<char>(*out);
\r
713 foreach(char c, *in) {
\r
717 inputPattern.insert(connIface,in);
\r
719 // search the last valid group in IP,
\r
720 while(! isValidDataGroup(inputPattern,lengthIP-1)) {
\r
721 //removeDataGroup(inputPattern,lengthIP-1);
\r
726 void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {
\r
727 static QString fctName = "FunctionalBlock::createAdmittance()";
\r
728 #ifdef DEBUG_FCTNAME
\r
729 cout << "call to " << qPrintable(fctName) << endl;
\r
731 // firstly, copy CP in AP
\r
732 QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);
\r
733 while (iterC.hasNext()) {
\r
735 QList<char>* pattern = new QList<char>(*(iterC.value()));
\r
736 admittance.insert(iterC.key(), pattern);
\r
738 lengthAP = lengthCP;
\r
740 cout << "trigger 1 at c.c. 0" << endl;
\r
741 for(int i=1;i<nbExec;i++) {
\r
742 // searching for the clock cycle for which a new exec starts
\r
744 while ((clock < lengthAP) && (nbGroup < delta)) {
\r
745 if (isValidDataGroup(admittance,clock)) nbGroup+=1;
\r
748 while ((clock < lengthAP) && (! isValidDataGroup(admittance,clock))) clock+=1;
\r
749 cout << "trigger " << (i+1) << " at c.c. " << clock << endl;
\r
751 // combine CP with AP at sc
\r
752 for(int j=0;j<lengthCP;j++) {
\r
753 // first case : column of CP must be placed beyond AP's end.
\r
754 if (sc == lengthAP) {
\r
755 cout << i << "," << j << " append in AP at " << sc << endl;
\r
756 appendToPattern(consumptionPattern,j,admittance,1);
\r
760 // second case : CP and AP can be combined directly (i.e. no X | 1 to do)
\r
761 else if (canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
762 cout << i << "," << j << " combine at " << sc << endl;
\r
763 combinePatterns(consumptionPattern,j,admittance,sc);
\r
766 // third case : CP has an X column
\r
767 else if (isOnlyXDataGroup(consumptionPattern,j)) {
\r
768 cout << i << "," << j << " shift rigth AP to combine at " << sc << endl;
\r
769 shiftRightPattern(admittance,sc);
\r
771 if (! canCombinePatterns(consumptionPattern,j,admittance,sc)) {
\r
772 cerr << "Abnormal case when combining AP and CP" << endl;
\r
774 combinePatterns(consumptionPattern,j,admittance,sc);
\r
777 // fourth case : AP has an X column
\r
778 else if (isOnlyXDataGroup(admittance,sc)) {
\r
779 cout << i << "," << j << " jump c.c. for CP at " << sc << endl;
\r
784 throw(INVALID_DELTA_CP);
\r
788 // turn all X into 0
\r
789 QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);
\r
790 while (iterA.hasNext()) {
\r
792 QList<char>* pattern = iterA.value();
\r
793 for(int i=0;i<pattern->size();i++) {
\r
794 if (pattern->at(i) == -1) pattern->replace(i,0);
\r
795 cout << (int)(pattern->at(i));
\r
801 void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {
\r
802 static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";
\r
803 #ifdef DEBUG_FCTNAME
\r
804 cout << "call to " << qPrintable(fctName) << endl;
\r
807 // firstly, create input pattern
\r
809 createInputPattern();
\r
811 catch(Exception e) {
\r
814 int nbExec = createTriggers();
\r
815 cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;
\r
818 createAdmittance(nbExec);
\r
820 catch(Exception e) {
\r
821 cout << "cannot create admittance" << endl;
\r
825 int clock = 0; // index in IP
\r
826 int i = 0; // index in AP
\r
827 while ((clock < lengthIP) && (i < lengthAP)) {
\r
829 // if AP is a valid group, search for the next valid group in IP
\r
830 if (isValidDataGroup(admittance,i)) {
\r
831 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
832 if (clock == lengthIP) {
\r
833 cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;
\r
834 throw(Exception(IP_END_NULLCOL,this));
\r
837 /* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or
\r
838 are both null columns
\r
840 if (! samePatterns(inputPattern,clock,admittance,i)) {
\r
841 cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;
\r
842 throw(Exception(IP_AP_NOTCOMPAT,this)); // IP and AP not compatible
\r
847 if (clock < lengthIP) {
\r
848 throw(Exception(AP_TOO_SHORT,this));
\r
849 cerr << "Abnormal case: AP is to short" << endl;
\r
853 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
854 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
855 #ifdef DEBUG_FCTNAME
\r
856 cout << "call to " << qPrintable(fctName) << endl;
\r
859 clearOutputPattern();
\r
861 /* case 1: the block is a generator for which output pattern
\r
862 must be computed for a nbExec following executions
\r
866 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
867 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
868 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
869 // create output pattern
\r
870 QList<char>* pp = productionPattern.value(connIface);
\r
871 QList<char>* pattern = new QList<char>(*pp);
\r
872 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
873 // assign pattern to interface
\r
874 connIface->setOutputPattern(pattern);
\r
875 // store it in QMap
\r
876 outputPattern.insert(connIface,pattern);
\r
880 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
882 // in case of inputPattern not created, do it
\r
883 if (lengthIP <= 0) {
\r
885 cout << "Strange case: input pattern is not created while it is time to compute output pattern !" << endl;
\r
886 // collect the input patterns for each input
\r
888 createInputPattern();
\r
890 catch(Exception e) {
\r
893 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
896 // initialize the output pattern
\r
898 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
899 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
900 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
901 QList<char>* pattern = new QList<char>();
\r
902 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
903 connIface->setOutputPattern(pattern);
\r
904 outputPattern.insert(connIface,pattern);
\r
906 cout << "output pattern array initialized" << endl;
\r
910 // search for the beginning of the first execution.
\r
911 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
912 cout << "found 1st exec clock: " << clock << endl;
\r
914 while (clock < lengthIP) {
\r
915 // initialize counters for current execution.
\r
916 int p = 0; // index in production pattern
\r
917 int o = 0; // clock+o will give the clock cycle of each output group
\r
918 int cip = 0; // clock+cip give the clock cycle of an input group
\r
919 int ccp = 0; // ccp give a column in the consumptio pattern
\r
920 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
921 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
922 bool cannotCompleteExec = false;
\r
923 for(int m=0;m<productionCounter.size();m++) {
\r
924 // search for the first production in PP
\r
925 while (!isValidDataGroup(productionPattern,p)) {
\r
929 int gap = 0; // count the number of extra null columns
\r
930 // search for PC(m) valid input group in IP
\r
931 while (nip < productionCounter.at(m)) {
\r
932 if (clock+cip < lengthIP) {
\r
933 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
938 cannotCompleteExec = true;
\r
943 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
945 // search for PC(m) valid input group in IP
\r
946 while (ncp < productionCounter.at(m)) {
\r
947 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
951 o += gap; // to take into acocunt of extra null columns
\r
952 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
957 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
959 // current exec. taken into accunt
\r
962 // search for the next exec.
\r
965 while ((clock < lengthIP) && (nip < delta)) {
\r
966 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
967 if (nip < delta) clock += 1;
\r
969 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
971 // find the last valid output data group
\r
972 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
973 removeDataGroup(outputPattern,lengthOP-1);
\r
977 // clear input pattern
\r
978 clearInputPattern();
\r
984 void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
985 static QString fctName = "FunctionalBlock::computeOutputPattern()";
\r
986 #ifdef DEBUG_FCTNAME
\r
987 cout << "call to " << qPrintable(fctName) << endl;
\r
990 // case 1: the block is a generator for which output pattern
\r
991 // must be computed for a nbExec following executions
\r
994 cout << "computing output pattern of " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
995 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
996 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
997 // create output pattern
\r
998 QList<char>* pp = productionPattern.value(connIface);
\r
999 QList<char>* pattern = new QList<char>(*pp);
\r
1000 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
1001 // assign pattern to interface
\r
1002 connIface->setOutputPattern(pattern);
\r
1003 // store it in QMap
\r
1004 outputPattern.insert(connIface,pattern);
\r
1008 cout << "computing output pattern of " << qPrintable(name) << endl;
\r
1010 // in case of inputPattern not created, do it
\r
1011 if (lengthIP <= 0) {
\r
1012 // collect the input patterns for each input
\r
1014 createInputPattern();
\r
1016 catch(Exception e) {
\r
1019 cout << "input pattern array initialized with min. len " << lengthIP << endl;
\r
1022 // initialize the output pattern
\r
1024 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
1025 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
1026 lengthOP = lengthIP+productionPattern.value(connIface)->size();
\r
1027 QList<char>* pattern = new QList<char>();
\r
1028 for(int i=0;i<lengthOP;i++) pattern->append(0);
\r
1029 connIface->setOutputPattern(pattern);
\r
1030 outputPattern.insert(connIface,pattern);
\r
1032 cout << "output pattern array initialized" << endl;
\r
1036 // search for the beginning of the first execution.
\r
1037 while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;
\r
1038 cout << "found 1st exec clock: " << clock << endl;
\r
1040 while (clock < lengthIP) {
\r
1041 // initialize counters for current execution.
\r
1042 int p = 0; // index in production pattern
\r
1043 int o = 0; // clock+o will give the clock cycle of each output group
\r
1044 int cip = 0; // clock+cip give the clock cycle of an input group
\r
1045 int ccp = 0; // ccp give a column in the consumptio pattern
\r
1046 int nip = 0; // number of input data groups already consumed during the current execution, used while exploring IP
\r
1047 int ncp = 0; // number of input data groups already consumed during the current execution, used while exploring CP
\r
1048 bool cannotCompleteExec = false;
\r
1049 for(int m=0;m<productionCounter.size();m++) {
\r
1050 // search for the first production in PP
\r
1051 while (!isValidDataGroup(productionPattern,p)) {
\r
1055 int gap = 0; // count the number of extra null columns
\r
1056 // search for PC(m) valid input group in IP
\r
1057 while (nip < productionCounter.at(m)) {
\r
1058 if (clock+cip < lengthIP) {
\r
1059 if (isValidDataGroup(inputPattern,clock+cip)) nip += 1;
\r
1064 cannotCompleteExec = true;
\r
1069 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1071 // search for PC(m) valid input group in IP
\r
1072 while (ncp < productionCounter.at(m)) {
\r
1073 if (isValidDataGroup(consumptionPattern,ccp)) ncp += 1;
\r
1077 o += gap; // to take into acocunt of extra null columns
\r
1078 combinePatterns(productionPattern,p,outputPattern,clock+o);
\r
1083 if (cannotCompleteExec) break; // no need to go further since the next search of input data group will lead to go outside inputPattern
\r
1085 // current exec. taken into accunt
\r
1088 // search for the next exec.
\r
1091 while ((clock < lengthIP) && (nip < delta)) {
\r
1092 if (isValidDataGroup(inputPattern,clock)) nip += 1;
\r
1093 if (nip < delta) clock += 1;
\r
1095 cout << "found exec " << nbExec << " at clock: " << clock << endl;
\r
1097 // find the last valid output data group
\r
1098 while(! isValidDataGroup(outputPattern,lengthOP-1)) {
\r
1099 removeDataGroup(outputPattern,lengthOP-1);
\r
1103 // clear input pattern
\r
1104 clearInputPattern();
\r
1108 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1110 if (patternSrc.size() != patternDest.size()) return false;
\r
1111 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1112 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1113 while (iterSrc.hasNext()) {
\r
1116 QList<char>* srcPat = iterSrc.value();
\r
1117 QList<char>* destPat = iterDest.value();
\r
1118 if (srcCol >= srcPat->size()) return false;
\r
1119 if (destCol >= destPat->size()) return false;
\r
1120 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1125 bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int> &srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {
\r
1126 if (patternSrc.size() != srcCols.size()) return false;
\r
1127 if (patternSrc.size() != patternDest.size()) return false;
\r
1129 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1130 QListIterator<int> iterSrcCol(srcCols);
\r
1131 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1132 while (iterSrc.hasNext()) {
\r
1134 int srcCol = iterSrcCol.next();
\r
1136 QList<char>* srcPat = iterSrc.value();
\r
1137 QList<char>* destPat = iterDest.value();
\r
1138 if (srcCol >= srcPat->size()) return false;
\r
1139 if (destCol >= destPat->size()) return false;
\r
1140 if (srcPat->at(srcCol) != destPat->at(destCol)) return false;
\r
1145 bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1146 if (patternSrc.size() != patternDest.size()) return false;
\r
1147 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1148 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1149 while (iterSrc.hasNext()) {
\r
1152 QList<char>* srcPat = iterSrc.value();
\r
1153 QList<char>* destPat = iterDest.value();
\r
1154 if (srcCol >= srcPat->size()) return false;
\r
1155 if (destCol >= destPat->size()) return false;
\r
1156 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return false;
\r
1157 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return false;
\r
1162 void FunctionalBlock::combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {
\r
1163 if (patternSrc.size() != patternDest.size()) return;
\r
1164 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1165 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1166 while (iterSrc.hasNext()) {
\r
1169 QList<char>* srcPat = iterSrc.value();
\r
1170 QList<char>* destPat = iterDest.value();
\r
1171 if (srcCol >= srcPat->size()) return;
\r
1172 if (destCol >= destPat->size()) return;
\r
1173 if ((srcPat->at(srcCol) == -1) && (destPat->at(destCol) == 1)) return;
\r
1174 if ((srcPat->at(srcCol) == 1) && (destPat->at(destCol) == -1)) return;
\r
1175 destPat->replace(destCol,destPat->at(destCol) | srcPat->at(srcCol));
\r
1179 void FunctionalBlock::appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols) {
\r
1180 if (patternSrc.size() != patternDest.size()) return;
\r
1181 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);
\r
1182 QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);
\r
1183 while (iterSrc.hasNext()) {
\r
1186 QList<char>* srcPat = iterSrc.value();
\r
1187 QList<char>* destPat = iterDest.value();
\r
1189 while ((srcCol+i < srcPat->size()) && (i<nbCols)) {
\r
1190 destPat->append(srcPat->at(srcCol+i));
\r
1196 void FunctionalBlock::removeDataGroup(QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1197 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1198 while (iterSrc.hasNext()) {
\r
1200 QList<char>* srcPat = iterSrc.value();
\r
1201 if (offset < srcPat->size()) {
\r
1202 srcPat->removeAt(offset);
\r
1207 void FunctionalBlock::shiftRightPattern(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1208 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1209 while (iterSrc.hasNext()) {
\r
1211 QList<char>* srcPat = iterSrc.value();
\r
1212 if (offset < srcPat->size()) {
\r
1213 srcPat->insert(offset,0);
\r
1218 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1219 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1220 while (iterSrc.hasNext()) {
\r
1222 QList<char>* srcPat = iterSrc.value();
\r
1223 if (offset >= srcPat->size()) return false;
\r
1224 if (srcPat->at(offset) == 1) return true;
\r
1229 bool FunctionalBlock::isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets) {
\r
1230 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1231 QListIterator<int> iterOffsets(offsets);
\r
1232 while (iterSrc.hasNext()) {
\r
1234 int offset = iterOffsets.next();
\r
1235 QList<char>* srcPat = iterSrc.value();
\r
1236 if (offset >= srcPat->size()) return false;
\r
1237 if (srcPat->at(offset) == 1) return true;
\r
1242 bool FunctionalBlock::isOnlyXDataGroup(const QMap<AbstractInterface *, QList<char> *> &pattern, int offset) {
\r
1243 QMapIterator<AbstractInterface*, QList<char>* > iterSrc(pattern);
\r
1244 while (iterSrc.hasNext()) {
\r
1246 QList<char>* srcPat = iterSrc.value();
\r
1247 if (offset >= srcPat->size()) return false;
\r
1248 if (srcPat->at(offset) != -1) return false;
\r
1253 void FunctionalBlock::clearConsumptionPattern() {
\r
1254 QMapIterator<AbstractInterface*, QList<char>* > iterP(consumptionPattern);
\r
1255 while (iterP.hasNext()) {
\r
1257 QList<char>* pattern = iterP.value();
\r
1258 if (pattern != NULL) delete pattern;
\r
1260 consumptionPattern.clear();
\r
1264 void FunctionalBlock::clearProductionPattern() {
\r
1265 QMapIterator<AbstractInterface*, QList<char>* > iterP(productionPattern);
\r
1266 while (iterP.hasNext()) {
\r
1268 QList<char>* pattern = iterP.value();
\r
1269 if (pattern != NULL) delete pattern;
\r
1271 productionPattern.clear();
\r
1275 void FunctionalBlock::clearInputPattern() {
\r
1277 QMapIterator<AbstractInterface*,QList<char>* > iterI(inputPattern);
\r
1278 while (iterI.hasNext()) {
\r
1280 QList<char>* pattern = iterI.value();
\r
1281 if (pattern != NULL) delete pattern;
\r
1283 inputPattern.clear();
\r
1287 void FunctionalBlock::clearOutputPattern() {
\r
1289 QMapIterator<AbstractInterface*,QList<char>* > iterO(outputPattern);
\r
1290 while (iterO.hasNext()) {
\r
1292 ConnectedInterface* connIface = AI_TO_CON(iterO.key());
\r
1293 connIface->resetOutputPattern();
\r
1294 QList<char>* pattern = iterO.value();
\r
1295 if (pattern != NULL) delete pattern;
\r
1297 outputPattern.clear();
\r
1301 void FunctionalBlock::clearAdmittanceDelays() {
\r
1302 QMapIterator<AbstractInterface*, QList<int>* > iterA(admittanceDelays);
\r
1303 while (iterA.hasNext()) {
\r
1305 QList<int>* d = iterA.value();
\r
1306 if (d != NULL) delete d;
\r
1308 admittanceDelays.clear();
\r
1311 int FunctionalBlock::createTriggers() {
\r
1313 /* NB: this method returns the number of executions that have been started
\r
1314 but not necessary completed.
\r
1316 if (delta <= 0) return 0;
\r
1318 // search for the first exec.
\r
1319 while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;
\r
1320 if (offset == lengthIP) return 0;
\r
1321 triggers.append(offset);
\r
1323 for(int i = offset;i<lengthIP;i++) {
\r
1324 if (isValidDataGroup(inputPattern,i)) nbGroup++;
\r
1325 if (nbGroup == delta+1) {
\r
1326 triggers.append(i);
\r
1330 return triggers.size();
\r
1333 QList<QString> FunctionalBlock::getExternalResources() {
\r
1335 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1336 QList<QString> list = impl->getResources();
\r
1337 foreach(QString s, list) {
\r
1338 cout << qPrintable(s) << " ";
\r
1346 void FunctionalBlock::generateVHDL(const QString& path) throw(Exception){
\r
1348 BlockImplementation* impl = reference->getImplementations().at(0); // for now only take first impl available
\r
1350 QFile implFile(impl->getXmlFile());
\r
1352 // reading in into QDomDocument
\r
1353 QDomDocument document("implFile");
\r
1355 if (!implFile.open(QIODevice::ReadOnly)) {
\r
1356 throw(Exception(IMPLFILE_NOACCESS));
\r
1358 if (!document.setContent(&implFile)) {
\r
1360 throw(Exception(IMPLFILE_NOACCESS));
\r
1364 bool genController = false;
\r
1365 QString coreFile = "";
\r
1366 QString controllerFile = "";
\r
1368 if (reference->isWBConfigurable()) {
\r
1369 genController = true;
\r
1370 controllerFile = path;
\r
1371 controllerFile += "/";
\r
1372 controllerFile.append(name);
\r
1373 controllerFile.append("_ctrl.vhd");
\r
1376 controllerFile = "nofile.vhd";
\r
1380 coreFile.append(name);
\r
1381 coreFile.append(".vhd");
\r
1383 QFile vhdlCore(coreFile);
\r
1384 QFile vhdlController(controllerFile);
\r
1386 if (!vhdlCore.open(QIODevice::WriteOnly)) {
\r
1387 throw(Exception(VHDLFILE_NOACCESS));
\r
1390 if (genController) {
\r
1391 if (!vhdlController.open(QIODevice::WriteOnly)) {
\r
1392 throw(Exception(VHDLFILE_NOACCESS));
\r
1395 QTextStream outCore(&vhdlCore);
\r
1396 QTextStream outController;
\r
1397 if (genController) {
\r
1398 outController.setDevice(&vhdlController);
\r
1402 //Get the root element
\r
1403 QDomElement impl = document.documentElement();
\r
1404 QDomElement eltComments = impl.firstChildElement("comments");
\r
1405 generateComments(outCore,eltComments, coreFile);
\r
1406 QDomElement eltLibs = eltComments.nextSiblingElement("libraries");
\r
1407 generateLibraries(outCore, eltLibs);
\r
1408 generateEntity(outCore, genController);
\r
1409 QDomElement eltArch = eltLibs.nextSiblingElement("architecture");
\r
1410 generateArchitecture(outCore, eltArch );
\r
1411 if (genController) {
\r
1412 generateController(outController);
\r
1415 catch(Exception err) {
\r
1420 vhdlController.close();
\r
1424 void FunctionalBlock::generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) {
\r
1426 for(int i = 0; i < 50; i++) {
\r
1429 out << "\n--" << endl;
\r
1430 QString fileName = coreFile;
\r
1431 out << "-- File : " << fileName << endl;
\r
1432 out << "--" << endl;
\r
1433 QDomElement eltAuthor = elt.firstChildElement("author");
\r
1434 QString firstName = eltAuthor.attribute("firstname","");
\r
1435 QString lastName = eltAuthor.attribute("lastname","");
\r
1436 QString mail = eltAuthor.attribute("mail","");
\r
1437 out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")" << endl;
\r
1438 out << "--" << endl;
\r
1439 QDomElement eltDate = eltAuthor.nextSiblingElement("date");
\r
1440 QString crea = eltDate.attribute("creation","");
\r
1441 out << "-- Creation Date : "<<crea<< endl;
\r
1442 out << "--" << endl;
\r
1443 QDomElement eltRelated = eltDate.nextSiblingElement("related_files");
\r
1444 QString relateds = eltRelated.attribute("list","");
\r
1445 out << "-- Related files :\n"<<relateds<<endl;
\r
1446 out << "--" << endl;
\r
1447 QDomElement eltDesc = eltRelated.nextSiblingElement("description");
\r
1448 QDomElement desc = eltDesc.firstChildElement();
\r
1449 QString descTxt = desc.text();
\r
1450 out << "-- Decription :\n"<<descTxt<<endl;
\r
1451 out << "--" << endl;
\r
1452 QDomElement eltNote = eltDesc.nextSiblingElement("description");
\r
1453 QDomElement note = eltNote.firstChildElement();
\r
1454 QString noteTxt = note.text();
\r
1455 out << "-- Note :\n"<<noteTxt<<endl;
\r
1456 out << "--" << endl;
\r
1457 for(int i = 0; i < 50; i++) {
\r
1460 out << endl << endl;
\r
1463 void FunctionalBlock::generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) {
\r
1465 QDomNodeList listLib = elt.elementsByTagName("library");
\r
1466 for(int i = 0; i < listLib.length(); i++) {
\r
1467 QDomNode nodeLib = listLib.item(i);
\r
1468 QDomElement eltLib = nodeLib.toElement();
\r
1469 QString nameLib = eltLib.attribute("name","none");
\r
1470 out << "library " << nameLib << ";" << endl;
\r
1471 QDomNodeList listPack = eltLib.elementsByTagName("package");
\r
1472 for(int j = 0; j < listPack.length(); j++) {
\r
1473 QDomNode nodePack = listPack.item(j);
\r
1474 QDomElement eltPack = nodePack.toElement();
\r
1475 QString namePack = eltPack.attribute("name","none");
\r
1476 QString usePack = eltPack.attribute("use","none");
\r
1477 out << "use " << nameLib << "." << namePack << "." << usePack << ";" << endl;
\r
1484 void FunctionalBlock::generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController) throw(Exception) {
\r
1487 QString indent = "";
\r
1488 for(i=0;i<indentLevel;i++) {
\r
1492 //QList<BlockParameter*> listParams = reference->getParameters();
\r
1493 QList<AbstractInterface*> listInputs = getInputs();
\r
1494 QList<AbstractInterface*> listOutputs = getOutputs();
\r
1495 QList<AbstractInterface*> listBidirs = getBidirs();
\r
1497 // Generation of the generics
\r
1498 QList<BlockParameter*> listGenerics = getGenericParameters();
\r
1499 if ((!listGenerics.isEmpty()) || (hasController)) {
\r
1500 out << indent << " generic (" << endl;
\r
1501 if (hasController) {
\r
1502 out << indent << " wb_data_width : integer = 16;" << endl;
\r
1503 out << indent << " wb_addr_width : integer = 12";
\r
1504 if (!listGenerics.isEmpty()) out << indent << ";";
\r
1507 for(i=0;i<listGenerics.size()-1;i++) {
\r
1508 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1510 out << indent << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1512 out << indent << " );" << endl;
\r
1515 out << indent << " port (" << endl;
\r
1517 QString ports = "";
\r
1518 QTextStream outPorts(&ports);
\r
1520 // Generation of the clk & rst signals
\r
1521 outPorts << indent << " -- clk/rst" << endl;
\r
1522 foreach(AbstractInterface* iface, listInputs) {
\r
1523 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1524 outPorts << indent << " " << iface->getName() << " : in std_logic;" << endl;
\r
1527 foreach(AbstractInterface* iface, listOutputs) {
\r
1528 if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {
\r
1529 outPorts << indent << " " << iface->getName() << " : out std_logic;" << endl;
\r
1533 if (hasController) {
\r
1534 // Generation of the wishbone signals
\r
1535 outPorts << indent << " -- registers r/w via wishbone" << endl;
\r
1536 QList<BlockParameter*> listWB = reference->getWishboneParameters();
\r
1537 for(i=0;i<listWB.size()-1;i++) {
\r
1538 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;
\r
1540 outPorts << indent << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;
\r
1543 // Generation of the data/control signals
\r
1545 QList<AbstractInterface*> listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
1546 if (listIface.size()>0) {
\r
1547 outPorts << indent << " -- input data ports" << endl;
\r
1548 foreach(AbstractInterface* iface, listIface) {
\r
1549 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1552 listIface = getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
1553 if (listIface.size()>0) {
\r
1554 outPorts << indent << " -- input control ports" << endl;
\r
1555 foreach(AbstractInterface* iface, listIface) {
\r
1556 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1559 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
1560 if (listIface.size()>0) {
\r
1561 outPorts << indent << " -- output data ports" << endl;
\r
1562 foreach(AbstractInterface* iface, listIface) {
\r
1563 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1566 listIface = getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
1567 if (listIface.size()>0) {
\r
1568 outPorts << indent << " -- output control ports" << endl;
\r
1569 foreach(AbstractInterface* iface, listIface) {
\r
1570 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1573 listIface = getInterfaces(AbstractInterface::InOut, AbstractInterface::Data);
\r
1574 if (listIface.size()>0) {
\r
1575 outPorts << indent << " -- bidirs data ports" << endl;
\r
1576 foreach(AbstractInterface* iface, listIface) {
\r
1577 outPorts << indent << " " << iface->toVHDL(AbstractInterface::Entity, 0) << endl;
\r
1584 out << indent << " );" << endl << endl;
\r
1588 void FunctionalBlock::generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) {
\r
1589 QRegularExpression rxPort("@\\{([a-zA-Z0-9_]+)\\}");
\r
1591 QString code = elt.text();
\r
1592 //cout << qPrintable(code) << endl;
\r
1593 out << "architecture rtl of " << name << " is" << endl;
\r
1595 QStringList listLine = code.split("\n");
\r
1596 for(int i =0; i < listLine.size(); i++) {
\r
1597 QString line = listLine.at(i).simplified();
\r
1600 if(listLine.at(i).contains(QRegularExpression("@foreach{"))) {
\r
1601 while(listLine.at(i).compare("@endforeach") != -1) {
\r
1602 expr = expr + listLine.at(i) + '\n';
\r
1605 expr = expr + listLine.at(i);
\r
1606 out << evalComplex(expr, 1) << '\n';
\r
1608 if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) {
\r
1609 while(listLine.at(i).compare("@endcaseeach") != -1) {
\r
1610 expr = expr + listLine.at(i) + '\n';
\r
1613 expr = expr + listLine.at(i);
\r
1614 out << evalComplex(expr, 2) << '\n';
\r
1617 if(line.contains("@{")) {
\r
1618 QMap<QString,QString> modifs;
\r
1619 //cout << qPrintable(line) << endl;
\r
1620 QRegularExpressionMatchIterator matchPort = rxPort.globalMatch(line);
\r
1621 while(matchPort.hasNext()) {
\r
1622 QRegularExpressionMatch m = matchPort.next();
\r
1623 QString refName = m.captured(1);
\r
1624 AbstractInterface* refIface = reference->getIfaceFromName(refName);
\r
1625 QString funName = getIfaceUserName(refIface);
\r
1626 if (!funName.isEmpty()) {
\r
1627 modifs.insert(m.captured(0),funName);
\r
1628 //cout << "replace " << qPrintable(refIface->getName()) << " by " << qPrintable(funIface->getName()) << endl;
\r
1631 QMapIterator<QString,QString> iterM(modifs);
\r
1632 while(iterM.hasNext()) {
\r
1634 QString oldName = iterM.key();
\r
1635 QString newName = iterM.value();
\r
1636 line.replace(oldName,newName);
\r
1639 out << line << endl;
\r
1642 out << "end rtl;" << endl;
\r
1645 void FunctionalBlock::generateController(QTextStream &out) throw(Exception) {
\r
1649 QString FunctionalBlock::getIfaceUserName(AbstractInterface* refIface) {
\r
1651 if (! refIface->isReferenceInterface()) return "";
\r
1653 AbstractInterface* funcIface = NULL;
\r
1655 if (refIface->getDirection() == AbstractInterface::Input) {
\r
1656 foreach(AbstractInterface* iface, getInputs()) {
\r
1657 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1658 if (fi->getReference() == refIface) {
\r
1659 funcIface = iface;
\r
1664 else if (refIface->getDirection() == AbstractInterface::Output) {
\r
1665 foreach(AbstractInterface* iface, getOutputs()) {
\r
1666 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1667 if (fi->getReference() == refIface) {
\r
1668 funcIface = iface;
\r
1673 else if (refIface->getDirection() == AbstractInterface::InOut) {
\r
1674 foreach(AbstractInterface* iface, getBidirs()) {
\r
1675 FunctionalInterface* fi = AI_TO_FUN(iface);
\r
1676 if (fi->getReference() == refIface) {
\r
1677 funcIface = iface;
\r
1682 if (funcIface == NULL) return "";
\r
1684 return funcIface->getName();
\r