-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.append(block->getName());\r
- controllerFile.append("_ctrl.vhd"); \r
- }\r
- else {\r
- controllerFile = "nofile.vhd"; \r
- }\r
- coreFile = path;\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--\n";\r
- QString fileName = coreFile;\r
- out << "-- File : " << fileName << "\n";\r
- out << "--\n";\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<<")\n";\r
- out << "--\n";\r
- QDomElement eltDate = eltAuthor.nextSiblingElement("date");\r
- QString crea = eltDate.attribute("creation","");\r
- out << "-- Creation Date : "<<crea<<"\n";\r
- out << "--\n";\r
- QDomElement eltRelated = eltDate.nextSiblingElement("related_files");\r
- QString relateds = eltRelated.attribute("list","");\r
- out << "-- Related files :\n"<<relateds<<"\n";\r
- out << "--\n";\r
- QDomElement eltDesc = eltRelated.nextSiblingElement("description");\r
- QDomElement desc = eltDesc.firstChildElement();\r
- QString descTxt = desc.text();\r
- out << "-- Decription :\n"<<descTxt<<"\n";\r
- out << "--\n";\r
- QDomElement eltNote = eltDesc.nextSiblingElement("description");\r
- QDomElement note = eltNote.firstChildElement();\r
- QString noteTxt = note.text();\r
- out << "-- Note :\n"<<noteTxt<<"\n";\r
- out << "--\n";\r
- for(int i = 0; i < 50; i++) {\r
- out << "--";\r
- }\r
- out << "\n\n";\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", "");\r
- out << "library " << nameLib << ";\n";\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", "");\r
- QString usePack = elt.attribute("use","");\r
- out << "use " << nameLib << "." << namePack << "." << usePack << ";\n";\r
- }\r
- out << "\n";\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 = reference->getName();\r
- //QList<BlockParameter*> listParams = reference->getParameters();\r
- QList<AbstractInterface*> listInputs = reference->getInputs();\r
- QList<AbstractInterface*> listOutputs = reference->getOutputs();\r
- QList<AbstractInterface*> listBidirs = reference->getBidirs();\r
- QString typePort, namePort;\r
-\r
- out << "entity " << nameEnt << " is\n";\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 = reference->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);\r
- }\r
- out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma);\r
-\r
- out << " );" << endl;\r
- }\r
-\r
- out << " port (" << endl;\r
-\r
- // Generation of the clk & rst signals\r
- out << " -- clk/rst" << endl;\r
- for(int i = 0; i < listInputs.size(); i++) {\r
- if(listInputs.at(i)->getPurpose() == AbstractInterface::Clock || listInputs.at(i)->getPurpose() == AbstractInterface::Reset) {\r
- out << " " << listInputs.at(i)->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);\r
- }\r
- out << " " << listWB.at(i)->toVHDL(BlockParameter::Entity,BlockParameter::NoComma);\r
- }\r
-\r
-\r
- // Generation of the data signals\r
- out << "-- data ports\n";\r
- for(int i = 0; i < listInputs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listInputs.at(i)->getName()));\r
- if(listInputs.at(i)->getWidth().compare("1"))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth(listInputs.at(i)->getWidth());\r
- if(listInputs.at(i)->getPurpose() == 1)\r
- out << namePort << " : in std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\r
-\r
- for(int i = 0; i < listOutputs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listOutputs.at(i)->getName()));\r
- if(listOutputs.at(i)->getWidth().compare("1"))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth(listOutputs.at(i)->getWidth());\r
- if(listOutputs.at(i)->getPurpose() == 1)\r
- out << namePort << " : out std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\r
-\r
- for(int i = 0; i < listBidirs.size(); i++) {\r
- namePort = getIfaceUserName(reference->AbstractBlock::getIfaceFromName(listBidirs.at(i)->getName()));\r
- if(listBidirs.at(i)->getWidth().compare(("1")))\r
- typePort = "std_logic";\r
- else\r
- typePort = calculateWidth((listBidirs.at(i)->getWidth()));\r
- if(listBidirs.at(i)->getPurpose() == 1)\r
- out << namePort << " : inout std_logic_vector(" << typePort << " -1 downto 0) ;\n";\r
- }\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
- QDomElement eltArch = elt.nextSiblingElement("architecture");\r
- out << "architecture " << nameEnt <<"_1 of " << nameEnt << "is\n";\r
- QString implText = eltArch.text();\r
- QStringList listLine = implText.split("\n");\r
- for(int i =0; i < listLine.size(); i++) {\r
- if(listLine.at(i).contains(QRegularExpression("@foreach{")) != -1) {\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{")) != -1) {\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(listLine.at(i).contains('@') == -1)\r
- out << listLine.at(i) << "\n";\r
- else\r
- out << eval(listLine.at(i), out) << "\n";\r
- }\r
-}\r
-\r
-void BlockImplementation::generateController(QTextStream &out) throw(Exception) {\r
-}\r
-\r