From: stephane Domas Date: Fri, 13 Oct 2017 14:26:10 +0000 (+0200) Subject: changed name of the class that converts VHDL -> XML X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/commitdiff_plain/fc9f5b8b77edda9e49a35d8ef75c4d71caf1c832 changed name of the class that converts VHDL -> XML --- diff --git a/BlockWidget.h b/BlockWidget.h deleted file mode 100644 index 9150928..0000000 --- a/BlockWidget.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef ENTITYWIDGET_H -#define ENTITYWIDGET_H - -#include -#include -#include -#include -#include -#include -#include - -#include "Parameters.h" -#include "BlockParameter.h" -#include "Graph.h" - -class BlockWidget : public QWidget -{ - Q_OBJECT -public: - explicit BlockWidget(QWidget *parent = 0); - ~BlockWidget(); - -private: - QPushButton *loadBt, *genBt; - int cptIn, cptOut, cptInout, cpt; - QRegExp *rxPort, *rxEnt, *rxArch, *rxComp, *rxComment, *rxComma, - *rxEndComp, *rxEnd, *rxGeneric, *rxEndGen, *rxGen, *rxConst, *rxWidth; - QString fileName, txt, s, entName, brief, desc; - QScrollArea *scrollPort, *scrollGen; - QWidget *wid; - QLabel *labelAppli, *lblBrief, *lblDesc, *lblName, *lblPort, *lblGen; - QTableWidget *twPort, *twGen; - QTextEdit *teBrief, *teDesc, *teName; - -signals: - -public slots: - void loadCode(); - void generateXml(); -}; - -#endif // ENTITYWIDGET_H diff --git a/Exception.cpp b/Exception.cpp index a051e7a..4036dac 100644 --- a/Exception.cpp +++ b/Exception.cpp @@ -27,6 +27,8 @@ QString Exception::getDefaultMessage() { case IMPLFILE_NOPATTERN : ret = tr("Implementation file does not contains pattern definitions"); break; case BLOCK_NULL : ret = tr("A parameter of type AbstractBlock* has been provided with NULL value."); break; case BLOCK_INVALID_TYPE : ret = tr("A parameter of type AbstractBlock* is used with an incorrect instance type."); break; + case VHDLFILE_NOACCESS : ret = tr("VHDL file cannot be read"); break; + case VHDLFILE_CORRUPTED : ret = tr("VHDL file is corrupted"); break; case IFACE_NULL : ret = tr("A parameter of type AbstractInterface* has been provided with NULL value."); break; case IFACE_INVALID_TYPE : ret = tr("A parameter of type AbstractInterface* is used with an incorrect instance type."); break; case IFACE_MULTIPLICITY_REACHED : ret = tr("Impossible to create another instance of a GraphInterface: the maximum multiplicity is reached."); break; diff --git a/Exception.h b/Exception.h index 3972d4e..ce2ea72 100644 --- a/Exception.h +++ b/Exception.h @@ -34,6 +34,7 @@ supp. infos : saved in UTF-8 [éè] #define IMPLFILE_NOPATTERN 403 #define VHDLFILE_NOACCESS 501 +#define VHDLFILE_CORRUPTED 502 #define BLOCKPATH_NOACCESS 601 diff --git a/MainWindow.cpp b/MainWindow.cpp index e772425..38ec48a 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -4,7 +4,7 @@ #include "BlockLibraryWidget.h" #include "GroupWidget.h" #include "GroupScene.h" -#include "BlockWidget.h" +#include "VHDLConverter.h" #include "AbstractBoxItem.h" #include "Graph.h" #include "GroupItem.h" @@ -343,7 +343,7 @@ bool MainWindow::slotCloseProject(){ void MainWindow::slotNewBlockWidget() { - new BlockWidget(); + new VHDLConverter(); } void MainWindow::slotSaveProject(){ diff --git a/MainWindow.h b/MainWindow.h index 2dee56c..99858c8 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -12,7 +12,7 @@ class Dispatcher; class Parameters; class BlockLibraryWidget; class GroupWidget; -class BlockWidget; +class VHDLConverter; class Graph; // versioning related diff --git a/Makefile.in b/Makefile.in index 0801e93..ab2cc12 100644 --- a/Makefile.in +++ b/Makefile.in @@ -58,7 +58,7 @@ CXXFLAGS = $(CXXFLAGS-$(OS)$(ARCH)) INCPATH-lin64-qt4 = -I/usr/share/qt4/mkspecs/linux-g++ -I$(QTPATH)/QtCore -I$(QTPATH)/QtGui -I$(QTPATH)/QtNetwork -I$(QTPATH)/QtXml -I$(QTPATH)/QtXmlPatterns -I$(QTPATH) INCPATH-lin64-qt5 = -I$(QTPATH)/mkspecs/linux-g++-64 -I$(QTPATH) -I$(QTPATH)/QtWidgets -I$(QTPATH)/QtCore -I$(QTPATH)/QtGui -I$(QTPATH)/QtPrintSupport -I$(QTPATH)/QtNetwork -I$(QTPATH)/QtXml -I$(QTPATH)/QtXmlPatterns -INCPATH-win32-qt5 = -I$(QTPATH)/mkspecs/win32-g++ -I$(QTPATH)/include -I$(QTPATH)/include/ActiveQt -I$(QTPATH)/include/QtWidgets -I$(QTPATH)/include/QtGui -I$(QTPATH)/include/QtCore -I$(QTPATH)/include/QtXml -I$(QTPATH)/include/QtXmlPatterns -I$(QTPATH)/include/QtPrintSupport +INCPATH-win32-qt5 = -I$(QTPATH)/mkspecs/win32-g++ -I$(QTPATH)/include -I$(QTPATH)/include/ActiveQt -I$(QTPATH)/include/QtWidgets -I$(QTPATH)/include/QtGui -I$(QTPATH)/include/QtCore -I$(QTPATH)/inlucde/QtNetwork -I$(QTPATH)/include/QtXml -I$(QTPATH)/include/QtXmlPatterns -I$(QTPATH)/include/QtPrintSupport INCPATH = $(INCPATH-$(OS)$(ARCH)-qt$(QTVER)) -I. diff --git a/BlockWidget.cpp b/VHDLConverter.cpp similarity index 64% rename from BlockWidget.cpp rename to VHDLConverter.cpp index 3b8a658..d32ab15 100644 --- a/BlockWidget.cpp +++ b/VHDLConverter.cpp @@ -1,10 +1,9 @@ -#include "BlockWidget.h" +#include "VHDLConverter.h" using namespace std; using namespace Qt; -BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent) -{ +VHDLConverter::VHDLConverter(QWidget *parent) : QWidget(parent) { rxComment = new QRegExp("(.*)--.*"); rxComma = new QRegExp("(.*)[;]"); @@ -19,21 +18,23 @@ BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent) rxGen = new QRegExp("[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(.*)[\\s\\t]*:=[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp); rxConst = new QRegExp("[\\s\\t]*constant[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(.)*[\\s\\t]*:=[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp); rxWidth = new QRegExp(".*[(](.*)(downto|to)(.*)[)]",CaseInsensitive,QRegExp::RegExp); + + QLabel *labelAppli, *lblBrief, *lblDesc, *lblName, *lblPort, *lblGen; - loadBt = new QPushButton("load VHDL"); - genBt = new QPushButton("generate XML"); + loadBut = new QPushButton("load VHDL"); + genBut = new QPushButton("generate XML"); QHBoxLayout *widgetLayout = new QHBoxLayout; QVBoxLayout *left = new QVBoxLayout; QVBoxLayout *right = new QVBoxLayout; - scrollPort = new QScrollArea; - scrollPort->setWidgetResizable(true); - twPort = new QTableWidget(this); - scrollPort->setWidget(twPort); - scrollGen = new QScrollArea; - scrollGen->setWidgetResizable(true); - twGen = new QTableWidget(this); - scrollGen->setWidget(twGen); + scrollDataPort = new QScrollArea; + scrollDataPort->setWidgetResizable(true); + twDataPort = new QTableWidget(this); + scrollDataPort->setWidget(twDataPort); + scrollGenerics = new QScrollArea; + scrollGenerics->setWidgetResizable(true); + twGenerics = new QTableWidget(this); + scrollGenerics->setWidget(twGenerics); teName = new QTextEdit; teBrief = new QTextEdit; teDesc = new QTextEdit; @@ -43,14 +44,14 @@ BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent) lblPort = new QLabel("Ports :"); lblGen = new QLabel("Generics :"); - connect(loadBt, SIGNAL(clicked()),this, SLOT(loadCode())); - connect(genBt, SIGNAL(clicked()), this, SLOT(generateXml())); + connect(loadBut, SIGNAL(clicked()),this, SLOT(loadVHDLFile())); + connect(genBut, SIGNAL(clicked()), this, SLOT(generateXml())); - left->addWidget(loadBt); + left->addWidget(loadBut); left->addWidget(lblPort); - left->addWidget(scrollPort); + left->addWidget(scrollDataPort); left->addWidget(lblGen); - left->addWidget(scrollGen); + left->addWidget(scrollGenerics); right->addWidget(lblName); right->addWidget(teName); @@ -58,7 +59,7 @@ BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent) right->addWidget(teBrief); right->addWidget(lblDesc); right->addWidget(teDesc); - right->addWidget(genBt); + right->addWidget(genBut); widgetLayout->addLayout(left); widgetLayout->addLayout(right); @@ -66,23 +67,116 @@ BlockWidget::BlockWidget(QWidget *parent) : QWidget(parent) show(); } -BlockWidget::~BlockWidget() -{ +VHDLConverter::~VHDLConverter() { } +QString VHDLConverter::skipBlankAndComments(QTextStream &in) { + + QString line = ""; + + // skipping blank/comment lines + while ( (line.isEmpty()) || ((line.at(0) == '-') && (line.at(1) == '-')) ) { + if (in.atEnd()) { + return ""; + } + line = in.readLine(); + if (!line.isEmpty()) line = line.trimmed(); + } + return line; +} + +void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) { + + QRegularExpression rxLib("^library[\\s\\t]*(.+);$",QRegularExpression::CaseInsensitiveOption); + QRegularExpression rxPack("^use[\\s\\t]*([^.]+)[.](.+);$",QRegularExpression::CaseInsensitiveOption); + QString line = ""; + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + + while (! line.contains("entity",Qt::CaseInsensitive)) { + + QRegularExpressionMatch matchLib = rxLib.match(line); + QRegularExpressionMatch matchPack = rxPack.match(line); + + if (matchLib.hasMatch()) { + + QString libName = matchLib.captured(1); + libName = libName.toLower(); + + cout << "matching library: " << qPrintable(libName) << endl; + + if (!packages.contains(libName)) { + packages.insert(libName,new QList()); + } + } + else if (matchPack.hasMatch()) { + cout << "matching packages" << endl; + + QString libName = matchPack.captured(1); + QString packName = matchPack.captured(2); + + libName = libName.toLower(); + packName = packName.toLower(); + + if (libName == "work") { + if (!packages.contains("work")) { + packages.insert("work",new QList()); + } + } + else if (libName == "std") { + if (!packages.contains("std")) { + packages.insert("std",new QList()); + } + } + else if (!packages.contains(libName)) throw(Exception(VHDLFILE_CORRUPTED)); + + QList* lstPack = packages.value(libName); + QString s = libName + "." + packName; + lstPack->append(s); + cout << qPrintable(s) << endl; + + } + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + cout << "read line = " << qPrintable(line) << endl; + } +} + +void VHDLConverter::readEntity(QTextStream &in) throw(Exception) { + +} + +void VHDLConverter::readGenerics(QTextStream &in) throw(Exception) { + +} + +void VHDLConverter::readPorts(QTextStream &in) throw(Exception) { + +} + +void VHDLConverter::readArchitecture(QTextStream &in) throw(Exception) { + +} + // This function opens a VHDL file and get the informations about the entity : // First the generics, then the signals. // You can edit the descriptions in the right, one for the brief description, the other for the detailled. -void BlockWidget::loadCode() { +void VHDLConverter::loadVHDLFile() { QString line, portName, portType, portId, genName, genType, genValue; QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList; cpt = 0; - twPort->setColumnCount(3); - twPort->setRowCount(cpt); - twGen->setColumnCount(3); - twGen->setRowCount(cpt); + twDataPort->setColumnCount(3); + twDataPort->setRowCount(cpt); + twGenerics->setColumnCount(3); + twGenerics->setRowCount(cpt); portNameList = new QStringList; portTypeList = new QStringList; portIdList = new QStringList; @@ -97,6 +191,10 @@ void BlockWidget::loadCode() { if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream ts(&file); + + readLibraries(ts); + + /* while (!ts.atEnd()) { line = ts.readLine(); @@ -156,27 +254,28 @@ void BlockWidget::loadCode() { } } } + */ - twGen->setRowCount(genNameList->size()); + twGenerics->setRowCount(genNameList->size()); for(int i = 0; i < genNameList->size(); i++) { - twGen->setItem(i, 0, new QTableWidgetItem(genNameList->at(i))); - twGen->setItem(i, 1, new QTableWidgetItem(genTypeList->at(i))); - twGen->setItem(i, 2, new QTableWidgetItem(genValueList->at(i))); + twGenerics->setItem(i, 0, new QTableWidgetItem(genNameList->at(i))); + twGenerics->setItem(i, 1, new QTableWidgetItem(genTypeList->at(i))); + twGenerics->setItem(i, 2, new QTableWidgetItem(genValueList->at(i))); } - twPort->setRowCount(portNameList->size()); + twDataPort->setRowCount(portNameList->size()); for(int i = 0; i < portNameList->size(); i++) { - twPort->setItem(i, 0, new QTableWidgetItem(portIdList->at(i))); - twPort->setItem(i, 1, new QTableWidgetItem(portNameList->at(i))); - twPort->setItem(i, 2, new QTableWidgetItem(portTypeList->at(i))); + twDataPort->setItem(i, 0, new QTableWidgetItem(portIdList->at(i))); + twDataPort->setItem(i, 1, new QTableWidgetItem(portNameList->at(i))); + twDataPort->setItem(i, 2, new QTableWidgetItem(portTypeList->at(i))); } file.close(); - scrollPort->setWidget(twPort); + scrollDataPort->setWidget(twDataPort); return; } // This function gets the informations in the table and the descriptions, and creates a XML file with this content -void BlockWidget::generateXml() { +void VHDLConverter::generateXml() { QString portName, portType, portId, genName, genType, genValue; QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList; @@ -191,16 +290,16 @@ void BlockWidget::generateXml() { genNameList = new QStringList; genTypeList = new QStringList; genValueList = new QStringList; - for(int i = 0; i < twGen->rowCount(); i++) { - genNameList->append(twGen->item(i,0)->text()); - genTypeList->append(twGen->item(i,1)->text()); - genValueList->append(twGen->item(i,2)->text()); + for(int i = 0; i < twGenerics->rowCount(); i++) { + genNameList->append(twGenerics->item(i,0)->text()); + genTypeList->append(twGenerics->item(i,1)->text()); + genValueList->append(twGenerics->item(i,2)->text()); } - for(int i = 0; i < twPort->rowCount(); i++) { - portIdList->append(twPort->item(i,0)->text()); - portNameList->append(twPort->item(i,1)->text()); - portTypeList->append(twPort->item(i,2)->text()); + for(int i = 0; i < twDataPort->rowCount(); i++) { + portIdList->append(twDataPort->item(i,0)->text()); + portNameList->append(twDataPort->item(i,1)->text()); + portTypeList->append(twDataPort->item(i,2)->text()); } QDomDocument doc (entName); @@ -239,7 +338,7 @@ void BlockWidget::generateXml() { interfaces.appendChild(outputs); interfaces.appendChild(bidirs); - for(int i = 0; i < twGen->rowCount(); i++) { + for(int i = 0; i < twGenerics->rowCount(); i++) { genName = genNameList->at(i); genType = genTypeList->at(i); genValue = genValueList->at(i); diff --git a/VHDLConverter.h b/VHDLConverter.h new file mode 100644 index 0000000..7ddce3d --- /dev/null +++ b/VHDLConverter.h @@ -0,0 +1,70 @@ +#ifndef __VHDLCONVERTER_H__ +#define __VHDLCONVERTER_H__ + + +#include +#include +#include +#include +#include +#include +#include + +#include "Parameters.h" +#include "Exception.h" + +class VHDLConverter : public QWidget { + Q_OBJECT +public: + explicit VHDLConverter(QWidget *parent = 0); + ~VHDLConverter(); + +private: + QPushButton* loadBut; + QPushButton* genBut; + + // clk & rst ports related + QTextEdit* clkNameEdit; + QTextEdit* rstNameEdit; + QComboBox* clkCombo; + QComboBox* rstCombo; + + // data ports related + QScrollArea *scrollDataPort; + QTableWidget* twDataPort; + + // wishbone ports related + QScrollArea *scrollWBPort; + QTableWidget* twWBPort; + + // generics related + QScrollArea* scrollGenerics; + QTableWidget* twGenerics; + + int cptIn, cptOut, cptInout, cpt; + QRegExp *rxPort, *rxEnt, *rxArch, *rxComp, *rxComment, *rxComma, + *rxEndComp, *rxEnd, *rxGeneric, *rxEndGen, *rxGen, *rxConst, *rxWidth; + QString fileName, txt, s, entName, brief, desc; + + QHash* > packages; + + QWidget *wid; + + QTextEdit *teBrief, *teDesc, *teName; + + void readLibraries(QTextStream& in) throw(Exception); + void readEntity(QTextStream& in) throw(Exception); + void readGenerics(QTextStream& in) throw(Exception); + void readPorts(QTextStream& in) throw(Exception); + void readArchitecture(QTextStream& in) throw(Exception); + + QString skipBlankAndComments(QTextStream& in); + +signals: + +public slots: + void loadVHDLFile(); + void generateXml(); +}; + +#endif // __VHDLCONVERTER_H__ diff --git a/blast.creator.user b/blast.creator.user index 0f7c253..95274be 100755 --- a/blast.creator.user +++ b/blast.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -40,6 +40,7 @@ true false 0 + true true 0 4 @@ -125,6 +126,11 @@ 1 + false + false + 0 + + true false false @@ -184,10 +190,10 @@ ProjectExplorer.Project.Updater.FileVersion - 16 + 18 Version - 16 + 18 diff --git a/blast.files b/blast.files index 3975c5f..1dbb3f1 100755 --- a/blast.files +++ b/blast.files @@ -26,6 +26,8 @@ GroupInterface.h GroupInterface.cpp BlockLibraryWidget.cpp BlockLibraryWidget.h +VHDLConverter.cpp +VHDLConverter.h blast.cpp BlockCategory.cpp BlockCategory.h @@ -63,8 +65,6 @@ Abstractblockitem.h Abstractblockitem.cpp GroupWidget.h GroupWidget.cpp -BlockWidget.cpp -BlockWidget.h BlocksToConfigureWidget.h BlocksToConfigureWidget.cpp ParametersWindow.h diff --git a/object-files.txt b/object-files.txt index 704e921..b46c2d8 100644 --- a/object-files.txt +++ b/object-files.txt @@ -31,8 +31,8 @@ COMMON-OBJ = $(BUILDPATH)/AbstractBlock.o \ $(BUILDPATH)/MainWindow.o \ $(BUILDPATH)/moc_MainWindow.o \ $(BUILDPATH)/ArithmeticEvaluator.o \ - $(BUILDPATH)/BlockWidget.o \ - $(BUILDPATH)/moc_BlockWidget.o \ + $(BUILDPATH)/VHDLConverter.o \ + $(BUILDPATH)/moc_VHDLConverter.o \ $(BUILDPATH)/GroupWidget.o \ $(BUILDPATH)/moc_GroupWidget.o \ $(BUILDPATH)/Parameters.o \