-void BlockImplementation::generateVHDL(FunctionalBlock* _block, const QString &path) throw(Exception) {\r
-\r
- block = _block;\r
-\r
- QFile implFile(xmlFile);\r
-\r
- // reading in into QDomDocument\r
- QDomDocument document("implFile");\r
-\r
- if (!implFile.open(QIODevice::ReadOnly)) {\r
- throw(Exception(IMPLFILE_NOACCESS));\r
- }\r
- if (!document.setContent(&implFile)) {\r
- implFile.close();\r
- throw(Exception(IMPLFILE_NOACCESS));\r
- }\r
- implFile.close();\r
-\r
- bool genController = false;\r
- QString coreFile = "";\r
- QString controllerFile = "";\r
-\r
- if (reference->isWBConfigurable()) {\r
- genController = true;\r
- controllerFile = path;\r
- controllerFile += "/";\r
- controllerFile.append(block->getName());\r
- controllerFile.append("_ctrl.vhd"); \r
- }\r
- else {\r
- controllerFile = "nofile.vhd"; \r
- }\r
- coreFile = path;\r
- coreFile += "/";\r
- coreFile.append(block->getName());\r
- coreFile.append(".vhd");\r
-\r
- QFile vhdlCore(coreFile);\r
- QFile vhdlController(controllerFile);\r
-\r
- if (!vhdlCore.open(QIODevice::WriteOnly)) {\r
- throw(Exception(VHDLFILE_NOACCESS));\r
- }\r
-\r
- if (genController) {\r
- if (!vhdlController.open(QIODevice::WriteOnly)) {\r
- throw(Exception(VHDLFILE_NOACCESS));\r
- }\r
- }\r
- QTextStream outCore(&vhdlCore);\r
- QTextStream outController;\r
- if (genController) {\r
- outController.setDevice(&vhdlController);\r
- }\r
-\r
- try {\r
-\r
-\r
- //Get the root element\r
- QDomElement impl = document.documentElement();\r
- QDomElement eltComments = impl.firstChildElement("comments");\r
- generateComments(eltComments, coreFile, outCore);\r
- QDomElement eltLibs = eltComments.nextSiblingElement("libraries");\r
- generateLibraries(eltLibs, outCore);\r
- generateEntity(outCore, genController);\r
- QDomElement eltArch = eltLibs.nextSiblingElement("architecture");\r
- generateArchitecture(eltArch, outCore);\r
- if (genController) {\r
- generateController(outController);\r
- }\r
- }\r
- catch(Exception err) {\r
- throw(err);\r
- }\r
-\r
- vhdlCore.close();\r
- vhdlController.close();\r
-}\r
-\r
-// This function generates the comments part of the VHDL document\r
-void BlockImplementation::generateComments(QDomElement &elt, QString coreFile, QTextStream& out) throw(Exception) {\r
-\r
- for(int i = 0; i < 50; i++) {\r
- out << "--";\r
- }\r
- out << "\n--" << endl;\r
- QString fileName = coreFile;\r
- out << "-- File : " << fileName << endl;\r
- out << "--" << endl;\r
- QDomElement eltAuthor = elt.firstChildElement("author");\r
- QString firstName = eltAuthor.attribute("firstname","");\r
- QString lastName = eltAuthor.attribute("lastname","");\r
- QString mail = eltAuthor.attribute("mail","");\r
- out << "-- Author(s) : "<<firstName+" "<<lastName<<" ("<<mail<<")" << endl;\r
- out << "--" << endl;\r
- QDomElement eltDate = eltAuthor.nextSiblingElement("date");\r
- QString crea = eltDate.attribute("creation","");\r
- out << "-- Creation Date : "<<crea<< endl;\r
- out << "--" << endl;\r
- QDomElement eltRelated = eltDate.nextSiblingElement("related_files");\r
- QString relateds = eltRelated.attribute("list","");\r
- out << "-- Related files :\n"<<relateds<<endl;\r
- out << "--" << endl;\r
- QDomElement eltDesc = eltRelated.nextSiblingElement("description");\r
- QDomElement desc = eltDesc.firstChildElement();\r
- QString descTxt = desc.text();\r
- out << "-- Decription :\n"<<descTxt<<endl;\r
- out << "--" << endl;\r
- QDomElement eltNote = eltDesc.nextSiblingElement("description");\r
- QDomElement note = eltNote.firstChildElement();\r
- QString noteTxt = note.text();\r
- out << "-- Note :\n"<<noteTxt<<endl;\r
- out << "--" << endl;\r
- for(int i = 0; i < 50; i++) {\r
- out << "--";\r
- }\r
- out << endl << endl;\r
-}\r
-\r
-// This function generates the library part of the VHDL document\r
-void BlockImplementation::generateLibraries(QDomElement &elt, QTextStream& out) throw(Exception) {\r
-\r
- QDomNodeList listLib = elt.elementsByTagName("library");\r
- for(int i = 0; i < listLib.length(); i++) {\r
- QDomNode nodeLib = listLib.item(i);\r
- QDomElement eltLib = nodeLib.toElement();\r
- QString nameLib = eltLib.attribute("name","none");\r
- out << "library " << nameLib << ";" << endl;\r
- QDomNodeList listPack = eltLib.elementsByTagName("package");\r
- for(int j = 0; j < listPack.length(); j++) {\r
- QDomNode nodePack = listPack.item(j);\r
- QDomElement eltPack = nodePack.toElement();\r
- QString namePack = eltPack.attribute("name","none");\r
- QString usePack = eltPack.attribute("use","none");\r
- out << "use " << nameLib << "." << namePack << "." << usePack << endl;\r
- }\r
- out << endl;\r
- }\r
-}\r
-\r
-// This function generates the entity part of the VHDL document\r
-void BlockImplementation::generateEntity(QTextStream& out, bool hasController) throw(Exception) {\r
-\r
- int i=0;\r
- nameEnt = block->getName();\r
- //QList<BlockParameter*> listParams = reference->getParameters();\r
- QList<AbstractInterface*> listInputs = block->getInputs();\r
- QList<AbstractInterface*> listOutputs = block->getOutputs();\r
- QList<AbstractInterface*> listBidirs = block->getBidirs();\r
- QString typePort, namePort;\r
-\r
- out << "entity " << nameEnt << " is" << endl;\r
-\r
-\r
- /* TODO : rewrite the generation to take into acocunt the new object hierarchy */\r
-\r
- // Generation of the generics\r
- QList<BlockParameter*> listGenerics = block->getGenericParameters();\r
- if ((!listGenerics.isEmpty()) || (hasController)) {\r
- out << " generic (" << endl;\r
- if (hasController) {\r
- out << " wb_data_width : integer = 16;" << endl;\r
- out << " wb_addr_width : integer = 12";\r
- if (!listGenerics.isEmpty()) out << ";";\r
- out << endl;\r
- }\r
- for(i=0;i<listGenerics.size()-1;i++) {\r
- out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;\r
- }\r
- out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;\r
-\r
- out << " );" << endl;\r
- }\r
-\r
- out << " port (" << endl;\r
-\r
- // Generation of the clk & rst signals\r
- out << " -- clk/rst" << endl;\r
- foreach(AbstractInterface* iface, listInputs) {\r
- if(iface->getPurpose() == AbstractInterface::Clock || iface->getPurpose() == AbstractInterface::Reset) {\r
- out << " " << iface->getName() << " : in std_logic;" << endl;\r
- }\r
- }\r
-\r
- if (hasController) {\r
- // Generation of the wishbone signals\r
- out << " -- registers r/w via wishbone" << endl;\r
- QList<BlockParameter*> listWB = reference->getWishboneParameters();\r
- for(i=0;i<listWB.size()-1;i++) {\r
- out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity, 0) << endl;\r
- }\r
- out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma) << endl;\r
- }\r
-\r
-\r
- int count = 0;\r
- foreach(AbstractInterface* iface, block->getInterfaces()) {\r
- if((iface->getPurpose() == AbstractInterface::Data)||(iface->getPurpose() == AbstractInterface::Control)) count++;\r
- }\r
- // Generation of the data/control signals\r
-\r
- int flag = 0;\r
- bool first = true;\r
-\r
- foreach(AbstractInterface* iface, listInputs) {\r
- if(iface->getPurpose() == AbstractInterface::Data) {\r
- if (first) {\r
- out << " -- input data ports" << endl;\r
- first = false;\r
- }\r
- count--;\r
- if (count == 0) flag = AbstractInterface::NoComma;\r
- out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;\r
- }\r
- }\r
- first = true;\r
- foreach(AbstractInterface* iface, listInputs) {\r
- if(iface->getPurpose() == AbstractInterface::Control) {\r
- if (first) {\r
- out << " -- input control ports" << endl;\r
- first = false;\r
- }\r
- count--;\r
- if (count == 0) flag = AbstractInterface::NoComma;\r
- out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;\r
- }\r
- }\r
- first = true;\r
- foreach(AbstractInterface* iface, listOutputs) {\r
- if(iface->getPurpose() == AbstractInterface::Data) {\r
- if (first) {\r
- out << " -- output data ports" << endl;\r
- first = false;\r
- }\r
- count--;\r
- if (count == 0) flag = AbstractInterface::NoComma;\r
- out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;\r
- }\r
- }\r
- first = true;\r
- foreach(AbstractInterface* iface, listOutputs) {\r
- if(iface->getPurpose() == AbstractInterface::Control) {\r
- if (first) {\r
- out << " -- output control ports" << endl;\r
- first = false;\r
- }\r
- count--;\r
- if (count == 0) flag = AbstractInterface::NoComma;\r
- out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;\r
- }\r
- }\r
- first = true;\r
- foreach(AbstractInterface* iface, listBidirs) {\r
- if(iface->getPurpose() == AbstractInterface::Data) {\r
- if (first) {\r
- out << " -- bidirs data ports" << endl;\r
- first = false;\r
- }\r
- count--;\r
- if (count == 0) flag = AbstractInterface::NoComma;\r
- out << " " << iface->toVHDL(AbstractInterface::Entity, flag) << endl;\r
- }\r
- }\r
- out << " );" << endl << endl;\r
- out << "end " << nameEnt << ";" << endl << endl;\r
-}\r
-\r
-// This function generates the architecture part of the VHDL document\r
-void BlockImplementation::generateArchitecture(QDomElement &elt, QTextStream& out) throw(Exception) {\r
-\r
- QString expr;\r
- QString code = elt.text();\r
- cout << qPrintable(code) << endl;\r
- out << "architecture rtl of " << nameEnt << " is" << endl;\r
-\r
- QStringList listLine = code.split("\n");\r
- for(int i =0; i < listLine.size(); i++) {\r
- QString line = listLine.at(i).simplified();\r
-\r
- /*\r
- if(listLine.at(i).contains(QRegularExpression("@foreach{"))) {\r
- while(listLine.at(i).compare("@endforeach") != -1) {\r
- expr = expr + listLine.at(i) + '\n';\r
- i++;\r
- }\r
- expr = expr + listLine.at(i);\r
- out << evalComplex(expr, 1) << '\n';\r
- }\r
- if(listLine.at(i).contains(QRegularExpression("@caseeach{"))) {\r
- while(listLine.at(i).compare("@endcaseeach") != -1) {\r
- expr = expr + listLine.at(i) + '\n';\r
- i++;\r
- }\r
- expr = expr + listLine.at(i);\r
- out << evalComplex(expr, 2) << '\n';\r
- }\r
-*/\r
- if(line.contains("@{")) {\r
- out << line << endl;\r
- }\r
- }\r
-}\r
-\r
-void BlockImplementation::generateController(QTextStream &out) throw(Exception) {\r
-}\r
-\r
-QString BlockImplementation::eval(QString line, QTextStream& out) {\r
- QString res, s, begLine, endLine, expr;\r
- evaluator->setExpression(line);\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
-\r
- int nbAt = line.count('@');\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- res = begLine + evalString(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- res = begLine + evalValue(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalComplex(QString line, int id) {\r
- QString res, s, begLine, endLine, expr;\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
- QRegExp *rxFor = new QRegExp("@foreach{.*}(@{.*})(.*)@endforeach");\r
- QRegExp *rxCase = new QRegExp("@caseeach{.*,(.*),(.*)}(@{.*})(.*)@endcaseeach");\r
- QRegExp *rxCaseDown = new QRegExp("@#-:(.*)");\r
- QRegExp *rxCaseUp = new QRegExp("@#:(.*)");\r
- evaluator->setExpression(line);\r
-\r
- int nbAt = line.count('@') - 2;\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- if(evalStringComplex(s)->size() == 0)\r
- line = begLine + evalString(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- line = begLine + evalValue(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
-\r
- if(id == 1) {\r
- if(rxFor->indexIn(line)) {\r
- QString intName, instruc;\r
- intName = rxFor->cap(1);\r
- instruc = rxFor->cap(2);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- if(intList->size() != 0) {\r
- for(int i = 0; i < intList->size(); i++) {\r
- res = intList->at(i)->getName() + instruc + '\n';\r
- }\r
- }\r
- }\r
- }\r
-\r
- else if(id == 2) {\r
- if(rxCase->indexIn(line)) {\r
- QString intName, sigName, cases, instruc;\r
- int number;\r
- sigName = rxCase->cap(1);\r
- cases = rxCase->cap(2);\r
- intName = rxCase->cap(3);\r
- instruc = rxCase->cap(4);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- int listSize = intList->count();\r
- res = "case " + sigName + " is\n";\r
- if(rxCaseUp->indexIn(cases)) {\r
- number = rxCaseUp->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number++;\r
- }\r
- }\r
- if(rxCaseDown->indexIn(cases)) {\r
- number = rxCaseDown->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number--;\r
- }\r
- res += "end case ;\n";\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalString(QString s) {\r
-\r
- QString name = getIfaceUserName(block->AbstractBlock::getIfaceFromName(s));\r
- return name;\r
-}\r
-\r
-QList<AbstractInterface*>* BlockImplementation::evalStringComplex(QString s) {\r
-\r
- int j = 0;\r
- QList<AbstractInterface*> *listInterfaces = new QList<AbstractInterface*>();\r
- AbstractInterface *inter = block->AbstractBlock::getIfaceFromName(s);\r
- QList<AbstractInterface*> listIntBlock = block->getInterfaces();\r
- for(int i = 0; i < listIntBlock.size(); i++) {\r
- if(inter->getName().compare(listIntBlock.at(i)->getName()) < -1) {\r
- listInterfaces->insert(j, inter);\r
- j ++;\r
- }\r
- }\r
- return listInterfaces;\r
-}\r
-\r
-QString BlockImplementation::evalValue(QString s) {\r
-\r
- QString val = "";\r
- if(paramMap.contains(s))\r
- val = paramMap.value(s);\r
- return val;\r
-}\r
-\r
-QString BlockImplementation::getIfaceUserName(AbstractInterface* refIface) {\r
-\r
- if (! refIface->isReferenceInterface()) return "";\r
-\r
- AbstractInterface* funcIface = NULL;\r
-\r
- if (refIface->getDirection() == AbstractInterface::Input) {\r
- foreach(AbstractInterface* iface, block->getInputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::Output) {\r
- foreach(AbstractInterface* iface, block->getOutputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::InOut) {\r
- foreach(AbstractInterface* iface, block->getBidirs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- if (funcIface == NULL) return "";\r
-\r
- return funcIface->getName();\r
-}\r
-\r