From: stephane Domas Date: Sun, 15 Oct 2017 18:16:05 +0000 (+0200) Subject: changed VHDL converter X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/commitdiff_plain/9ea814d76cc52e24b80be4a6ea78cca24a9a4915?hp=fc9f5b8b77edda9e49a35d8ef75c4d71caf1c832 changed VHDL converter --- diff --git a/VHDLConverter.cpp b/VHDLConverter.cpp index d32ab15..ea8991e 100644 --- a/VHDLConverter.cpp +++ b/VHDLConverter.cpp @@ -4,20 +4,6 @@ using namespace std; using namespace Qt; VHDLConverter::VHDLConverter(QWidget *parent) : QWidget(parent) { - - rxComment = new QRegExp("(.*)--.*"); - rxComma = new QRegExp("(.*)[;]"); - rxPort = new QRegExp("[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(in|out|inout)[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp); - rxEnt = new QRegExp("[\\s\\t]*entity[\\s\\t]*(.*)[\\s\\t]*is",CaseInsensitive,QRegExp::RegExp); - rxArch = new QRegExp("[\\s\\t]*architecture[\\s\\t]*(.*)[\\s\\t]*of (.*)[\\s\\t]*is",CaseInsensitive,QRegExp::RegExp); - rxComp = new QRegExp("[\\s\\t]*component[\\s\\t]*(.*)[\\s\\t]*",CaseInsensitive,QRegExp::RegExp); - rxEnd = new QRegExp("[\\s\\t]*end(.*)",CaseInsensitive,QRegExp::RegExp); - rxComp = new QRegExp("[\\s\\t]*end component;",CaseInsensitive,QRegExp::RegExp); - rxGeneric = new QRegExp("[\\s\\t]*generic[\\s\\t]*[(][\\s\\t]*",CaseInsensitive,QRegExp::RegExp); - rxEndGen = new QRegExp("[\\s\\t]*[)]",CaseInsensitive,QRegExp::RegExp); - 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; @@ -81,12 +67,13 @@ QString VHDLConverter::skipBlankAndComments(QTextStream &in) { return ""; } line = in.readLine(); - if (!line.isEmpty()) line = line.trimmed(); - } + if (!line.isEmpty()) line = line.simplified(); + } + line.remove(QRegularExpression("--.*$")); return line; } -void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) { +QString VHDLConverter::readLibraries(QTextStream &in) throw(Exception) { QRegularExpression rxLib("^library[\\s\\t]*(.+);$",QRegularExpression::CaseInsensitiveOption); QRegularExpression rxPack("^use[\\s\\t]*([^.]+)[.](.+);$",QRegularExpression::CaseInsensitiveOption); @@ -147,18 +134,121 @@ void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) { } cout << "read line = " << qPrintable(line) << endl; } + + return line; } -void VHDLConverter::readEntity(QTextStream &in) throw(Exception) { - +QString VHDLConverter::readEntity(QTextStream &in) throw(Exception) { + + QRegularExpression rxGen("^generic[\\s\\t]*[(](.*)$",QRegularExpression::CaseInsensitiveOption); + QRegularExpression rxPorts("^port[\\s\\t]*[(](.*)$",QRegularExpression::CaseInsensitiveOption); + + QString line = ""; + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + + while (! line.contains("architecture",Qt::CaseInsensitive)) { + + QRegularExpressionMatch matchGen = rxGen.match(line); + QRegularExpressionMatch matchPorts = rxPorts.match(line); + + if (matchGen.hasMatch()) { + cout << "matching generics" << endl; + if (matchGen.captured(1).length() > 0) { + cerr << "Please, modify VHDL source so that the generic list does not begin at the same line as generic (" << endl; + throw(Exception(VHDLFILE_CORRUPTED)); + } + readGenerics(in); + } + else if (matchPorts.hasMatch()) { + cout << "matching ports" << endl; + if (matchPorts.captured(1).length() > 0) { + cerr << "Please, modify VHDL source so that the port list does not begin at the same line as port (" << endl; + throw(Exception(VHDLFILE_CORRUPTED)); + } + readPorts(in); + } + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + cout << "read line = " << qPrintable(line) << endl; + } + + return line; } void VHDLConverter::readGenerics(QTextStream &in) throw(Exception) { - + + QRegularExpression rxGen("^([^:]+):([^:]+)(:=)?([^;]*);?$",QRegularExpression::CaseInsensitiveOption); + + QString line = ""; + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + line = line.remove(' '); + + while (! line.contains(QRegExp("\\);"))) { + + QRegularExpressionMatch matchGen = rxGen.match(line); + + if (matchGen.hasMatch()) { + cout << "matching generic value" << endl; + QString genName = matchGen.captured(1); + QString genType = matchGen.captured(2); + QString genValue = matchGen.captured(4); + cout << qPrintable(genName) << " " << qPrintable(genType) << " " << qPrintable(genValue) << endl; + } + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + line = line.remove(' '); + cout << "read line = " << qPrintable(line) << endl; + } } void VHDLConverter::readPorts(QTextStream &in) throw(Exception) { - + + QRegularExpression rxPort("^([^:]+):(in|out|inout)([a-zA-Z0-9_]+)(\\([^:)]*\\))?(:=)?([^;]*);?$",QRegularExpression::CaseInsensitiveOption); + + QString line = ""; + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + line = line.remove(' '); + + while (! line.contains(QRegExp("^\\);$"))) { + + QRegularExpressionMatch matchPort = rxPort.match(line); + + if (matchPort.hasMatch()) { + cout << "matching port value" << endl; + QString portName = matchPort.captured(1); + QString portDir = matchPort.captured(2); + QString portType = matchPort.captured(3); + QString portSize = matchPort.captured(4); + QString portValue = matchPort.captured(6); + cout << qPrintable(portName) << " " << qPrintable(portDir) << " " << qPrintable(portType) << " " << qPrintable(portSize) << " " << qPrintable(portValue) << endl; + } + + line = skipBlankAndComments(in); + if (line == "") { + throw(Exception(VHDLFILE_CORRUPTED)); + } + line = line.remove(' '); + cout << "read line = " << qPrintable(line) << endl; + } + } void VHDLConverter::readArchitecture(QTextStream &in) throw(Exception) { @@ -184,15 +274,42 @@ void VHDLConverter::loadVHDLFile() { genTypeList = new QStringList; genValueList = new QStringList; + fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), "C:", tr("Files (*.txt *.vhd)")); + tr("Open File"), QDir::homePath() , tr("Files (*.txt *.vhd)")); QFile file(fileName); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream ts(&file); - readLibraries(ts); + QString entityLine = ""; + try { + entityLine = readLibraries(ts); + } + catch(Exception e) { + cerr << "VHDL seems to be malformed" << endl; + return; + } + + QRegularExpression rxEnt("^entity[\\s\\t]+(.+)[\\s\\t]+is$",QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch matchEnt = rxEnt.match(entityLine); + if (!matchEnt.hasMatch()) { + cerr << "VHDL seems to be malformed" << endl; + return; + } + entityName = matchEnt.captured(1); + cout << "foudn entity " << qPrintable(entityName) << endl; + + QString archLine = ""; + try { + archLine = readEntity(ts); + } + catch(Exception e) { + cerr << "VHDL seems to be malformed" << endl; + return; + } + /* while (!ts.atEnd()) @@ -276,7 +393,7 @@ void VHDLConverter::loadVHDLFile() { // This function gets the informations in the table and the descriptions, and creates a XML file with this content void VHDLConverter::generateXml() { - +/* QString portName, portType, portId, genName, genType, genValue; QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList; int x, y, width; @@ -396,4 +513,5 @@ void VHDLConverter::generateXml() { QLabel *popup = new QLabel("Votre fichier XML est rempli"); popup->show(); + */ } diff --git a/VHDLConverter.h b/VHDLConverter.h index 7ddce3d..ff9defe 100644 --- a/VHDLConverter.h +++ b/VHDLConverter.h @@ -22,7 +22,10 @@ public: private: QPushButton* loadBut; QPushButton* genBut; - + + // entity related + QString entityName; + // clk & rst ports related QTextEdit* clkNameEdit; QTextEdit* rstNameEdit; @@ -41,9 +44,7 @@ private: QScrollArea* scrollGenerics; QTableWidget* twGenerics; - int cptIn, cptOut, cptInout, cpt; - QRegExp *rxPort, *rxEnt, *rxArch, *rxComp, *rxComment, *rxComma, - *rxEndComp, *rxEnd, *rxGeneric, *rxEndGen, *rxGen, *rxConst, *rxWidth; + int cptIn, cptOut, cptInout, cpt; QString fileName, txt, s, entName, brief, desc; QHash* > packages; @@ -52,8 +53,8 @@ private: QTextEdit *teBrief, *teDesc, *teName; - void readLibraries(QTextStream& in) throw(Exception); - void readEntity(QTextStream& in) throw(Exception); + QString readLibraries(QTextStream& in) throw(Exception); + QString readEntity(QTextStream& in) throw(Exception); void readGenerics(QTextStream& in) throw(Exception); void readPorts(QTextStream& in) throw(Exception); void readArchitecture(QTextStream& in) throw(Exception); diff --git a/blast.creator.user b/blast.creator.user index 95274be..8b99581 100755 --- a/blast.creator.user +++ b/blast.creator.user @@ -1,10 +1,10 @@ - + EnvironmentId - {3701e197-5b6c-48ea-9e98-a6cf6de18672} + {c8006d66-d34f-42be-ad10-d0207752286d} ProjectExplorer.Project.ActiveTarget @@ -19,7 +19,7 @@ Cpp - qt2 + CppGlobal @@ -31,7 +31,7 @@ 2 UTF-8 false - 2 + 4 false 80 true @@ -43,12 +43,12 @@ true true 0 - 4 - false + 8 + true 1 true true - false + true false @@ -61,7 +61,7 @@ Desktop Desktop - {ed04208c-8774-456b-99b9-4a02094ca7a4} + {2c9bf876-3476-44eb-8065-1f0844704dda} 0 0 0 @@ -128,7 +128,7 @@ false false - 0 + 1000 true @@ -169,9 +169,8 @@ - false %{buildDir} - Exécutable personnalisé + Custom Executable ProjectExplorer.CustomExecutableRunConfiguration 3768