]> AND Private Git Repository - blast.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
changed VHDL converter
authorstephane Domas <stephane.domas@univ-fcomte.fr>
Sun, 15 Oct 2017 18:16:05 +0000 (20:16 +0200)
committerstephane Domas <stephane.domas@univ-fcomte.fr>
Sun, 15 Oct 2017 18:16:05 +0000 (20:16 +0200)
VHDLConverter.cpp
VHDLConverter.h
blast.creator.user

index d32ab152c0a6ce43f2c6bdc4f97bb8ffe57eb948..ea8991e16c80a3d2f784d1e5c8e5a2b78e363f3e 100644 (file)
@@ -4,20 +4,6 @@ using namespace std;
 using namespace Qt;\r
 \r
 VHDLConverter::VHDLConverter(QWidget *parent) : QWidget(parent) {\r
-\r
-    rxComment = new QRegExp("(.*)--.*");\r
-    rxComma = new QRegExp("(.*)[;]");\r
-    rxPort = new QRegExp("[\\s\\t]*(.*)[\\s\\t]*:[\\s\\t]*(in|out|inout)[\\s\\t]*(.*)",CaseInsensitive,QRegExp::RegExp);\r
-    rxEnt = new QRegExp("[\\s\\t]*entity[\\s\\t]*(.*)[\\s\\t]*is",CaseInsensitive,QRegExp::RegExp);\r
-    rxArch = new QRegExp("[\\s\\t]*architecture[\\s\\t]*(.*)[\\s\\t]*of (.*)[\\s\\t]*is",CaseInsensitive,QRegExp::RegExp);\r
-    rxComp = new QRegExp("[\\s\\t]*component[\\s\\t]*(.*)[\\s\\t]*",CaseInsensitive,QRegExp::RegExp);\r
-    rxEnd = new QRegExp("[\\s\\t]*end(.*)",CaseInsensitive,QRegExp::RegExp);\r
-    rxComp = new QRegExp("[\\s\\t]*end component;",CaseInsensitive,QRegExp::RegExp);\r
-    rxGeneric = new QRegExp("[\\s\\t]*generic[\\s\\t]*[(][\\s\\t]*",CaseInsensitive,QRegExp::RegExp);\r
-    rxEndGen = new QRegExp("[\\s\\t]*[)]",CaseInsensitive,QRegExp::RegExp);\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
@@ -81,12 +67,13 @@ QString VHDLConverter::skipBlankAndComments(QTextStream &in) {
       return "";\r
     }\r
     line = in.readLine();\r
-    if (!line.isEmpty()) line = line.trimmed();\r
-  }  \r
+    if (!line.isEmpty()) line = line.simplified();\r
+  }\r
+  line.remove(QRegularExpression("--.*$"));\r
   return line;\r
 }\r
 \r
-void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) {\r
+QString VHDLConverter::readLibraries(QTextStream &in) throw(Exception) {\r
   \r
   QRegularExpression rxLib("^library[\\s\\t]*(.+);$",QRegularExpression::CaseInsensitiveOption);\r
   QRegularExpression rxPack("^use[\\s\\t]*([^.]+)[.](.+);$",QRegularExpression::CaseInsensitiveOption);\r
@@ -147,18 +134,121 @@ void VHDLConverter::readLibraries(QTextStream &in) throw(Exception) {
     }\r
     cout << "read line = " << qPrintable(line) << endl;\r
   }\r
+\r
+  return line;\r
 }\r
 \r
-void VHDLConverter::readEntity(QTextStream &in) throw(Exception) {\r
-  \r
+QString VHDLConverter::readEntity(QTextStream &in) throw(Exception) {\r
+\r
+  QRegularExpression rxGen("^generic[\\s\\t]*[(](.*)$",QRegularExpression::CaseInsensitiveOption);\r
+  QRegularExpression rxPorts("^port[\\s\\t]*[(](.*)$",QRegularExpression::CaseInsensitiveOption);\r
+\r
+  QString line = "";\r
+\r
+  line = skipBlankAndComments(in);\r
+  if (line == "") {\r
+    throw(Exception(VHDLFILE_CORRUPTED));\r
+  }\r
+\r
+  while (! line.contains("architecture",Qt::CaseInsensitive)) {\r
+\r
+    QRegularExpressionMatch matchGen = rxGen.match(line);\r
+    QRegularExpressionMatch matchPorts = rxPorts.match(line);\r
+\r
+    if (matchGen.hasMatch()) {\r
+      cout << "matching generics" << endl;\r
+      if (matchGen.captured(1).length() > 0) {\r
+        cerr << "Please, modify VHDL source so that the generic list does not begin at the same line as generic (" << endl;\r
+        throw(Exception(VHDLFILE_CORRUPTED));\r
+      }\r
+      readGenerics(in);\r
+    }\r
+    else if (matchPorts.hasMatch()) {\r
+      cout << "matching ports" << endl;\r
+      if (matchPorts.captured(1).length() > 0) {\r
+        cerr << "Please, modify VHDL source so that the port list does not begin at the same line as port (" << endl;\r
+        throw(Exception(VHDLFILE_CORRUPTED));\r
+      }\r
+      readPorts(in);\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
+  return line;\r
 }\r
 \r
 void VHDLConverter::readGenerics(QTextStream &in) throw(Exception) {\r
-  \r
+\r
+  QRegularExpression rxGen("^([^:]+):([^:]+)(:=)?([^;]*);?$",QRegularExpression::CaseInsensitiveOption);\r
+\r
+  QString line = "";\r
+\r
+  line = skipBlankAndComments(in);\r
+  if (line == "") {\r
+    throw(Exception(VHDLFILE_CORRUPTED));\r
+  }\r
+  line = line.remove(' ');\r
+\r
+  while (! line.contains(QRegExp("\\);"))) {\r
+\r
+    QRegularExpressionMatch matchGen = rxGen.match(line);\r
+\r
+    if (matchGen.hasMatch()) {\r
+      cout << "matching generic value" << endl;\r
+      QString genName = matchGen.captured(1);\r
+      QString genType = matchGen.captured(2);\r
+      QString genValue = matchGen.captured(4);\r
+      cout << qPrintable(genName) << " " << qPrintable(genType) << " " << qPrintable(genValue) << endl;\r
+    }\r
+\r
+    line = skipBlankAndComments(in);\r
+    if (line == "") {\r
+      throw(Exception(VHDLFILE_CORRUPTED));\r
+    }\r
+    line = line.remove(' ');\r
+     cout << "read line = " << qPrintable(line) << endl;\r
+  }\r
 }\r
 \r
 void VHDLConverter::readPorts(QTextStream &in) throw(Exception) {\r
-  \r
+\r
+  QRegularExpression rxPort("^([^:]+):(in|out|inout)([a-zA-Z0-9_]+)(\\([^:)]*\\))?(:=)?([^;]*);?$",QRegularExpression::CaseInsensitiveOption);\r
+\r
+  QString line = "";\r
+\r
+  line = skipBlankAndComments(in);\r
+  if (line == "") {\r
+    throw(Exception(VHDLFILE_CORRUPTED));\r
+  }\r
+  line = line.remove(' ');\r
+\r
+  while (! line.contains(QRegExp("^\\);$"))) {\r
+\r
+    QRegularExpressionMatch matchPort = rxPort.match(line);\r
+\r
+    if (matchPort.hasMatch()) {\r
+      cout << "matching port value" << endl;\r
+      QString portName = matchPort.captured(1);\r
+      QString portDir = matchPort.captured(2);\r
+      QString portType = matchPort.captured(3);\r
+      QString portSize = matchPort.captured(4);\r
+      QString portValue = matchPort.captured(6);\r
+      cout << qPrintable(portName) << " " << qPrintable(portDir) << " " << qPrintable(portType) << " " << qPrintable(portSize) << " " << qPrintable(portValue) << endl;\r
+    }\r
+\r
+    line = skipBlankAndComments(in);\r
+    if (line == "") {\r
+      throw(Exception(VHDLFILE_CORRUPTED));\r
+    }\r
+    line = line.remove(' ');\r
+     cout << "read line = " << qPrintable(line) << endl;\r
+  }\r
+\r
 }\r
 \r
 void VHDLConverter::readArchitecture(QTextStream &in) throw(Exception) {\r
@@ -184,15 +274,42 @@ void VHDLConverter::loadVHDLFile() {
     genTypeList = new QStringList;\r
     genValueList = new QStringList;\r
 \r
+\r
     fileName = QFileDialog::getOpenFileName(this,\r
-                                            tr("Open File"), "C:", tr("Files (*.txt *.vhd)"));\r
+                                            tr("Open File"), QDir::homePath() , tr("Files (*.txt *.vhd)"));\r
     QFile file(fileName);\r
 \r
     if(!file.open(QIODevice::ReadOnly | QIODevice::Text))\r
         return;\r
     QTextStream ts(&file);\r
     \r
-    readLibraries(ts);\r
+    QString entityLine = "";\r
+    try {\r
+      entityLine = readLibraries(ts);\r
+    }\r
+    catch(Exception e) {\r
+      cerr << "VHDL seems to be malformed" << endl;\r
+      return;\r
+    }\r
+\r
+    QRegularExpression rxEnt("^entity[\\s\\t]+(.+)[\\s\\t]+is$",QRegularExpression::CaseInsensitiveOption);\r
+    QRegularExpressionMatch matchEnt = rxEnt.match(entityLine);\r
+    if (!matchEnt.hasMatch()) {\r
+      cerr << "VHDL seems to be malformed" << endl;\r
+      return;\r
+    }\r
+    entityName = matchEnt.captured(1);\r
+    cout << "foudn entity " << qPrintable(entityName) << endl;\r
+\r
+    QString archLine = "";\r
+    try {\r
+      archLine = readEntity(ts);\r
+    }\r
+    catch(Exception e) {\r
+      cerr << "VHDL seems to be malformed" << endl;\r
+      return;\r
+    }\r
+\r
     \r
     /*\r
     while (!ts.atEnd())\r
@@ -276,7 +393,7 @@ void VHDLConverter::loadVHDLFile() {
 \r
 // This function gets the informations in the table and the descriptions, and creates a XML file with this content\r
 void VHDLConverter::generateXml() {\r
-\r
+/*\r
     QString portName, portType, portId, genName, genType, genValue;\r
     QStringList *portNameList, *portTypeList, *portIdList, *genNameList, *genTypeList, *genValueList;\r
     int x, y, width;\r
@@ -396,4 +513,5 @@ void VHDLConverter::generateXml() {
 \r
     QLabel *popup = new QLabel("Votre fichier XML est rempli");\r
     popup->show();\r
+    */\r
 }\r
index 7ddce3dce6b24c8ca523cdf539171680cc5a99a7..ff9defe91b8c26a9d72fd978fc1e344cb9f0f07c 100644 (file)
@@ -22,7 +22,10 @@ public:
 private:\r
     QPushButton* loadBut;\r
     QPushButton* genBut;\r
-    \r
+\r
+    // entity related\r
+    QString entityName;\r
+\r
     // clk & rst ports related\r
     QTextEdit* clkNameEdit;\r
     QTextEdit* rstNameEdit;\r
@@ -41,9 +44,7 @@ private:
     QScrollArea* scrollGenerics;    \r
     QTableWidget* twGenerics;\r
     \r
-    int cptIn, cptOut, cptInout, cpt;\r
-    QRegExp *rxPort, *rxEnt, *rxArch, *rxComp, *rxComment, *rxComma,\r
-    *rxEndComp, *rxEnd, *rxGeneric, *rxEndGen, *rxGen, *rxConst, *rxWidth;\r
+    int cptIn, cptOut, cptInout, cpt;        \r
     QString fileName, txt, s, entName, brief, desc;        \r
     \r
     QHash<QString,QList<QString>* > packages;\r
@@ -52,8 +53,8 @@ private:
     \r
     QTextEdit *teBrief, *teDesc, *teName;\r
 \r
-    void readLibraries(QTextStream& in) throw(Exception);\r
-    void readEntity(QTextStream& in) throw(Exception);\r
+    QString readLibraries(QTextStream& in) throw(Exception);\r
+    QString readEntity(QTextStream& in) throw(Exception);\r
     void readGenerics(QTextStream& in) throw(Exception);\r
     void readPorts(QTextStream& in) throw(Exception);\r
     void readArchitecture(QTextStream& in) throw(Exception);\r
index 95274beb96c4f253fc5228f25a17e246eb55bee1..8b995819353205c0ec27fb5ff04f0daa2d55f54e 100755 (executable)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.2.0, 2017-10-13T10:38:54. -->
+<!-- Written by QtCreator 4.2.0, 2017-10-15T20:15:50. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
-  <value type="QByteArray">{3701e197-5b6c-48ea-9e98-a6cf6de18672}</value>
+  <value type="QByteArray">{c8006d66-d34f-42be-ad10-d0207752286d}</value>
  </data>
  <data>
   <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -19,7 +19,7 @@
    <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
     <value type="QString" key="language">Cpp</value>
     <valuemap type="QVariantMap" key="value">
-     <value type="QByteArray" key="CurrentPreferences">qt2</value>
+     <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
     </valuemap>
    </valuemap>
    <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
@@ -31,7 +31,7 @@
    <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
    <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
    <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
-   <value type="int" key="EditorConfiguration.IndentSize">2</value>
+   <value type="int" key="EditorConfiguration.IndentSize">4</value>
    <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
    <value type="int" key="EditorConfiguration.MarginColumn">80</value>
    <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
    <value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
    <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
    <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
-   <value type="int" key="EditorConfiguration.TabSize">4</value>
-   <value type="bool" key="EditorConfiguration.UseGlobal">false</value>
+   <value type="int" key="EditorConfiguration.TabSize">8</value>
+   <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
    <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
    <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
    <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
-   <value type="bool" key="EditorConfiguration.cleanWhitespace">false</value>
+   <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
    <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
   </valuemap>
  </data>
@@ -61,7 +61,7 @@
   <valuemap type="QVariantMap">
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
-   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{ed04208c-8774-456b-99b9-4a02094ca7a4}</value>
+   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{2c9bf876-3476-44eb-8065-1f0844704dda}</value>
    <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
    <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
     <value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
     <value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
-    <value type="uint" key="Analyzer.QmlProfiler.FlushInterval">0</value>
+    <value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
     <value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
     <value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
     <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
     <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
     <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
     <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
-    <value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">false</value>
     <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
-    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Exécutable personnalisé</value>
+    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
     <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>