-#include "BlockWidget.h"\r
+#include "VHDLConverter.h"\r
\r
using namespace std;\r
using namespace Qt;\r
\r
-BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent)\r
-{\r
+VHDLConverter::VHDLConverter(QWidget *parent) : QWidget(parent) {\r
\r
rxComment = new QRegExp("(.*)--.*");\r
rxComma = new QRegExp("(.*)[;]");\r
rxGen = new QRegExp("[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(.*)[\\s\\t]*:=[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp);\r
rxConst = new QRegExp("[\\s\\t]*constant[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(.)*[\\s\\t]*:=[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp);\r
rxWidth = new QRegExp(".*[(](.*)(downto|to)(.*)[)]",CaseInsensitive,QRegExp::RegExp);\r
+ \r
+ QLabel *labelAppli, *lblBrief, *lblDesc, *lblName, *lblPort, *lblGen;\r
\r
- loadBt = new QPushButton("load VHDL");\r
- genBt = new QPushButton("generate XML");\r
+ loadBut = new QPushButton("load VHDL");\r
+ genBut = new QPushButton("generate XML");\r
QHBoxLayout *widgetLayout = new QHBoxLayout;\r
QVBoxLayout *left = new QVBoxLayout;\r
QVBoxLayout *right = new QVBoxLayout;\r
\r
- scrollPort = new QScrollArea;\r
- scrollPort->setWidgetResizable(true);\r
- twPort = new QTableWidget(this);\r
- scrollPort->setWidget(twPort);\r
- scrollGen = new QScrollArea;\r
- scrollGen->setWidgetResizable(true);\r
- twGen = new QTableWidget(this);\r
- scrollGen->setWidget(twGen);\r
+ scrollDataPort = new QScrollArea;\r
+ scrollDataPort->setWidgetResizable(true);\r
+ twDataPort = new QTableWidget(this);\r
+ scrollDataPort->setWidget(twDataPort);\r
+ scrollGenerics = new QScrollArea;\r
+ scrollGenerics->setWidgetResizable(true);\r
+ twGenerics = new QTableWidget(this);\r
+ scrollGenerics->setWidget(twGenerics);\r
teName = new QTextEdit;\r
teBrief = new QTextEdit;\r
teDesc = new QTextEdit;\r
lblPort = new QLabel("Ports :");\r
lblGen = new QLabel("Generics :");\r
\r
- connect(loadBt, SIGNAL(clicked()),this, SLOT(loadCode()));\r
- connect(genBt, SIGNAL(clicked()), this, SLOT(generateXml()));\r
+ connect(loadBut, SIGNAL(clicked()),this, SLOT(loadVHDLFile()));\r
+ connect(genBut, SIGNAL(clicked()), this, SLOT(generateXml()));\r
\r
- left->addWidget(loadBt);\r
+ left->addWidget(loadBut);\r
left->addWidget(lblPort);\r
- left->addWidget(scrollPort);\r
+ left->addWidget(scrollDataPort);\r
left->addWidget(lblGen);\r
- left->addWidget(scrollGen);\r
+ left->addWidget(scrollGenerics);\r
\r
right->addWidget(lblName);\r
right->addWidget(teName);\r
right->addWidget(teBrief);\r
right->addWidget(lblDesc);\r
right->addWidget(teDesc);\r
- right->addWidget(genBt);\r
+ right->addWidget(genBut);\r
\r
widgetLayout->addLayout(left);\r
widgetLayout->addLayout(right);\r
show();\r
}\r
\r
-BlockWidget::~BlockWidget()\r
-{\r
+VHDLConverter::~VHDLConverter() {\r
\r
}\r
\r
+QString VHDLConverter::skipBlankAndComments(QTextStream &in) {\r
+ \r
+ QString line = "";\r
+ \r
+ // skipping blank/comment lines \r
+ while ( (line.isEmpty()) || ((line.at(0) == '-') && (line.at(1) == '-')) ) {\r
+ if (in.atEnd()) {\r
+ return "";\r
+ }\r
+ line = in.readLine();\r
+ if (!line.isEmpty()) line = line.trimmed();\r
+ } \r
+ return line;\r
+}\r
+\r
+void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) {\r
+ \r
+ QRegularExpression rxLib("^library[\\s\\t]*(.+);$",QRegularExpression::CaseInsensitiveOption);\r
+ QRegularExpression rxPack("^use[\\s\\t]*([^.]+)[.](.+);$",QRegularExpression::CaseInsensitiveOption);\r
+ QString line = "";\r
+ \r
+ line = skipBlankAndComments(in);\r
+ if (line == "") {\r
+ throw(Exception(VHDLFILE_CORRUPTED));\r
+ } \r
+ \r
+ while (! line.contains("entity",Qt::CaseInsensitive)) {\r
+ \r
+ QRegularExpressionMatch matchLib = rxLib.match(line);\r
+ QRegularExpressionMatch matchPack = rxPack.match(line);\r
+ \r
+ if (matchLib.hasMatch()) {\r
+ \r
+ QString libName = matchLib.captured(1);\r
+ libName = libName.toLower();\r
+ \r
+ cout << "matching library: " << qPrintable(libName) << endl; \r
+ \r
+ if (!packages.contains(libName)) { \r
+ packages.insert(libName,new QList<QString>()); \r
+ } \r
+ }\r
+ else if (matchPack.hasMatch()) {\r
+ cout << "matching packages" << endl;\r
+ \r
+ QString libName = matchPack.captured(1);\r
+ QString packName = matchPack.captured(2); \r
+ \r
+ libName = libName.toLower();\r
+ packName = packName.toLower(); \r
+ \r
+ if (libName == "work") {\r
+ if (!packages.contains("work")) {\r
+ packages.insert("work",new QList<QString>());\r
+ }\r
+ }\r
+ else if (libName == "std") {\r
+ if (!packages.contains("std")) {\r
+ packages.insert("std",new QList<QString>());\r
+ }\r
+ }\r
+ else if (!packages.contains(libName)) throw(Exception(VHDLFILE_CORRUPTED));\r
+ \r
+ QList<QString>* lstPack = packages.value(libName);\r
+ QString s = libName + "." + packName; \r
+ lstPack->append(s);\r
+ cout << qPrintable(s) << endl;\r
+ \r
+ }\r
+ \r
+ line = skipBlankAndComments(in);\r
+ if (line == "") {\r
+ throw(Exception(VHDLFILE_CORRUPTED));\r
+ }\r
+ cout << "read line = " << qPrintable(line) << endl;\r
+ }\r
+}\r
+\r
+void VHDLConverter::readEntity(QTextStream &in) throw(Exception) {\r
+ \r
+}\r
+\r
+void VHDLConverter::readGenerics(QTextStream &in) throw(Exception) {\r
+ \r
+}\r
+\r
+void VHDLConverter::readPorts(QTextStream &in) throw(Exception) {\r
+ \r
+}\r
+\r
+void VHDLConverter::readArchitecture(QTextStream &in) throw(Exception) {\r
+ \r
+}\r
+\r
// This function opens a VHDL file and get the informations about the entity :\r
// First the generics, then the signals.\r
// You can edit the descriptions in the right, one for the brief description, the other for the detailled.\r
-void BlockWidget::loadCode() {\r
+void VHDLConverter::loadVHDLFile() {\r
\r
QString line, portName, portType, portId, genName, genType, genValue;\r
QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList;\r
cpt = 0;\r
- twPort->setColumnCount(3);\r
- twPort->setRowCount(cpt);\r
- twGen->setColumnCount(3);\r
- twGen->setRowCount(cpt);\r
+ twDataPort->setColumnCount(3);\r
+ twDataPort->setRowCount(cpt);\r
+ twGenerics->setColumnCount(3);\r
+ twGenerics->setRowCount(cpt);\r
portNameList = new QStringList;\r
portTypeList = new QStringList;\r
portIdList = new QStringList;\r
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))\r
return;\r
QTextStream ts(&file);\r
+ \r
+ readLibraries(ts);\r
+ \r
+ /*\r
while (!ts.atEnd())\r
{\r
line = ts.readLine();\r
}\r
}\r
}\r
+ */\r
\r
- twGen->setRowCount(genNameList->size());\r
+ twGenerics->setRowCount(genNameList->size());\r
for(int i = 0; i < genNameList->size(); i++) {\r
- twGen->setItem(i, 0, new QTableWidgetItem(genNameList->at(i)));\r
- twGen->setItem(i, 1, new QTableWidgetItem(genTypeList->at(i)));\r
- twGen->setItem(i, 2, new QTableWidgetItem(genValueList->at(i)));\r
+ twGenerics->setItem(i, 0, new QTableWidgetItem(genNameList->at(i)));\r
+ twGenerics->setItem(i, 1, new QTableWidgetItem(genTypeList->at(i)));\r
+ twGenerics->setItem(i, 2, new QTableWidgetItem(genValueList->at(i)));\r
}\r
- twPort->setRowCount(portNameList->size());\r
+ twDataPort->setRowCount(portNameList->size());\r
for(int i = 0; i < portNameList->size(); i++) {\r
- twPort->setItem(i, 0, new QTableWidgetItem(portIdList->at(i)));\r
- twPort->setItem(i, 1, new QTableWidgetItem(portNameList->at(i)));\r
- twPort->setItem(i, 2, new QTableWidgetItem(portTypeList->at(i)));\r
+ twDataPort->setItem(i, 0, new QTableWidgetItem(portIdList->at(i)));\r
+ twDataPort->setItem(i, 1, new QTableWidgetItem(portNameList->at(i)));\r
+ twDataPort->setItem(i, 2, new QTableWidgetItem(portTypeList->at(i)));\r
}\r
\r
file.close();\r
- scrollPort->setWidget(twPort);\r
+ scrollDataPort->setWidget(twDataPort);\r
return;\r
}\r
\r
// This function gets the informations in the table and the descriptions, and creates a XML file with this content\r
-void BlockWidget::generateXml() {\r
+void VHDLConverter::generateXml() {\r
\r
QString portName, portType, portId, genName, genType, genValue;\r
QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList;\r
genNameList = new QStringList;\r
genTypeList = new QStringList;\r
genValueList = new QStringList;\r
- for(int i = 0; i < twGen->rowCount(); i++) {\r
- genNameList->append(twGen->item(i,0)->text());\r
- genTypeList->append(twGen->item(i,1)->text());\r
- genValueList->append(twGen->item(i,2)->text());\r
+ for(int i = 0; i < twGenerics->rowCount(); i++) {\r
+ genNameList->append(twGenerics->item(i,0)->text());\r
+ genTypeList->append(twGenerics->item(i,1)->text());\r
+ genValueList->append(twGenerics->item(i,2)->text());\r
}\r
\r
- for(int i = 0; i < twPort->rowCount(); i++) {\r
- portIdList->append(twPort->item(i,0)->text());\r
- portNameList->append(twPort->item(i,1)->text());\r
- portTypeList->append(twPort->item(i,2)->text());\r
+ for(int i = 0; i < twDataPort->rowCount(); i++) {\r
+ portIdList->append(twDataPort->item(i,0)->text());\r
+ portNameList->append(twDataPort->item(i,1)->text());\r
+ portTypeList->append(twDataPort->item(i,2)->text());\r
}\r
\r
QDomDocument doc (entName);\r
interfaces.appendChild(outputs);\r
interfaces.appendChild(bidirs);\r
\r
- for(int i = 0; i < twGen->rowCount(); i++) {\r
+ for(int i = 0; i < twGenerics->rowCount(); i++) {\r
genName = genNameList->at(i);\r
genType = genTypeList->at(i);\r
genValue = genValueList->at(i);\r