3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-15 13:28:59 +00:00

Now using SVG and yosys-svgviewer per default in show command

This commit is contained in:
Clifford Wolf 2013-03-27 18:14:16 +01:00
parent 9c401b58a2
commit 35a02ee81e
4 changed files with 67 additions and 16 deletions

View file

@ -51,9 +51,9 @@ yosys-config: yosys-config.in
sed 's,@CXX@,$(CXX),; s,@CXXFLAGS@,$(CXXFLAGS),; s,@LDFLAGS@,$(LDFLAGS),; s,@LDLIBS@,$(LDLIBS),;' < yosys-config.in > yosys-config sed 's,@CXX@,$(CXX),; s,@CXXFLAGS@,$(CXXFLAGS),; s,@LDFLAGS@,$(LDFLAGS),; s,@LDLIBS@,$(LDLIBS),;' < yosys-config.in > yosys-config
chmod +x yosys-config chmod +x yosys-config
yosys-svgviewer: libs/svgviewer/* yosys-svgviewer: libs/svgviewer/*.h libs/svgviewer/*.cpp
cd libs/svgviewer && qmake && make -cd libs/svgviewer && qmake-qt4 && make
cp libs/svgviewer/svgviewer yosys-svgviewer -cp libs/svgviewer/svgviewer yosys-svgviewer
test: yosys test: yosys
cd tests/simple && bash run-test.sh cd tests/simple && bash run-test.sh
@ -63,7 +63,7 @@ test: yosys
install: yosys install: yosys
install yosys /usr/local/bin/yosys install yosys /usr/local/bin/yosys
install yosys-config /usr/local/bin/yosys-config install yosys-config /usr/local/bin/yosys-config
install yosys-svgviewer /usr/local/bin/yosys-svgviewer -install yosys-svgviewer /usr/local/bin/yosys-svgviewer
install yosys-filterlib /usr/local/bin/yosys-filterlib install yosys-filterlib /usr/local/bin/yosys-filterlib
clean: clean:

View file

@ -373,10 +373,14 @@ struct ShowPass : public Pass {
log(" show [options] [selection]\n"); log(" show [options] [selection]\n");
log("\n"); log("\n");
log("Create a graphviz DOT file for the selected part of the design and compile it\n"); log("Create a graphviz DOT file for the selected part of the design and compile it\n");
log("to a postscript file.\n"); log("to a graphics file (usually SVG or PostScript).\n");
log("\n"); log("\n");
log(" -viewer <command>\n"); log(" -viewer <viewer>\n");
log(" Also run the specified command with the postscript file as parameter.\n"); log(" Run the specified command with the graphics file as parameter.\n");
log("\n");
log(" -format <format>\n");
log(" Generate a graphics file in the specified format.\n");
log(" Usually <format> is 'svg' or 'ps'.\n");
log("\n"); log("\n");
log(" -lib <verilog_or_ilang_file>\n"); log(" -lib <verilog_or_ilang_file>\n");
log(" Use the specified library file for determining whether cell ports are\n"); log(" Use the specified library file for determining whether cell ports are\n");
@ -398,7 +402,11 @@ struct ShowPass : public Pass {
log(" stretch the graph so all inputs are on the left side and all outputs\n"); log(" stretch the graph so all inputs are on the left side and all outputs\n");
log(" (including inout ports) are on the right side.\n"); log(" (including inout ports) are on the right side.\n");
log("\n"); log("\n");
log("The generated output files are `yosys-show.dot' and `yosys-show.ps'.\n"); log("When no <format> is specified, SVG is used. When no <format> and <viewer> is\n");
log("specified, 'yosys-svgviewer' is used to display the schematic.\n");
log("\n");
log("The generated output files are 'yosys-show.dot' and 'yosys-show.<format>',\n");
log("unless another prefix is specified using -prefix <prefix>.\n");
log("\n"); log("\n");
} }
virtual void execute(std::vector<std::string> args, RTLIL::Design *design) virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
@ -406,6 +414,7 @@ struct ShowPass : public Pass {
log_header("Generating Graphviz representation of design.\n"); log_header("Generating Graphviz representation of design.\n");
log_push(); log_push();
std::string format;
std::string viewer_exe; std::string viewer_exe;
std::string prefix = "yosys-show"; std::string prefix = "yosys-show";
std::vector<std::string> libfiles; std::vector<std::string> libfiles;
@ -434,6 +443,10 @@ struct ShowPass : public Pass {
colorSeed = atoi(args[++argidx].c_str()); colorSeed = atoi(args[++argidx].c_str());
continue; continue;
} }
if (arg == "-format" && argidx+1 < args.size()) {
format = atoi(args[++argidx].c_str());
continue;
}
if (arg == "-width") { if (arg == "-width") {
flag_width= true; flag_width= true;
continue; continue;
@ -460,33 +473,42 @@ struct ShowPass : public Pass {
log_header("Continuing show pass.\n"); log_header("Continuing show pass.\n");
std::string dot_file = stringf("%s.dot", prefix.c_str()); std::string dot_file = stringf("%s.dot", prefix.c_str());
std::string ps_file = stringf("%s.ps", prefix.c_str()); std::string out_file = stringf("%s.%s", prefix.c_str(), format.empty() ? "svg" : format.c_str());
log("Writing dot description to `%s'.\n", dot_file.c_str()); log("Writing dot description to `%s'.\n", dot_file.c_str());
FILE *f = fopen(dot_file.c_str(), "w"); FILE *f = fopen(dot_file.c_str(), "w");
if (f == NULL) if (f == NULL) {
for (auto lib : libs)
delete lib;
log_cmd_error("Can't open dot file `%s' for writing.\n", dot_file.c_str()); log_cmd_error("Can't open dot file `%s' for writing.\n", dot_file.c_str());
}
ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_stretch); ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_stretch);
fclose(f); fclose(f);
for (auto lib : libs)
delete lib;
if (worker.page_counter == 0) if (worker.page_counter == 0)
log_cmd_error("Nothing there to show.\n"); log_cmd_error("Nothing there to show.\n");
std::string cmd = stringf("dot -Tps -o '%s' '%s'", ps_file.c_str(), dot_file.c_str()); std::string cmd = stringf("dot -T%s -o '%s' '%s'", format.empty() ? "svg" : format.c_str(), out_file.c_str(), dot_file.c_str());
log("Exec: %s\n", cmd.c_str()); log("Exec: %s\n", cmd.c_str());
if (system(cmd.c_str()) != 0) if (system(cmd.c_str()) != 0)
log_cmd_error("Shell command failed!\n"); log_cmd_error("Shell command failed!\n");
if (!viewer_exe.empty()) { if (!viewer_exe.empty()) {
cmd = stringf("%s '%s' &", viewer_exe.c_str(), ps_file.c_str()); cmd = stringf("%s '%s' &", viewer_exe.c_str(), out_file.c_str());
log("Exec: %s\n", cmd.c_str());
if (system(cmd.c_str()) != 0)
log_cmd_error("Shell command failed!\n");
} else
if (format.empty()) {
cmd = stringf("fuser -s '%s' || yosys-svgviewer '%s' &", out_file.c_str(), out_file.c_str());
log("Exec: %s\n", cmd.c_str()); log("Exec: %s\n", cmd.c_str());
if (system(cmd.c_str()) != 0) if (system(cmd.c_str()) != 0)
log_cmd_error("Shell command failed!\n"); log_cmd_error("Shell command failed!\n");
} }
for (auto lib : libs)
delete lib;
log_pop(); log_pop();
} }
} ShowPass; } ShowPass;

View file

@ -41,12 +41,15 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QtGui> #include <QtGui>
#include <QFileSystemWatcher>
#include "svgview.h" #include "svgview.h"
MainWindow::MainWindow() MainWindow::MainWindow()
: QMainWindow() : QMainWindow()
, m_view(new SvgView) , m_view(new SvgView)
, m_watcher(NULL)
, m_filehandle(NULL)
{ {
QMenu *fileMenu = new QMenu(tr("&File"), this); QMenu *fileMenu = new QMenu(tr("&File"), this);
QAction *openAction = fileMenu->addAction(tr("&Open...")); QAction *openAction = fileMenu->addAction(tr("&Open..."));
@ -118,6 +121,15 @@ void MainWindow::openFile(const QString &path)
else else
fileName = path; fileName = path;
if (m_watcher) {
delete m_watcher;
m_watcher = NULL;
}
if (m_filehandle) {
fclose(m_filehandle);
m_filehandle = NULL;
}
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); QFile file(fileName);
if (!file.exists()) { if (!file.exists()) {
@ -129,6 +141,13 @@ void MainWindow::openFile(const QString &path)
return; return;
} }
m_watcher = new QFileSystemWatcher(this);
m_watcher->addPath(fileName);
connect(m_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(reloadFile()));
// just keep the file open so this process is found using 'fuser'
m_filehandle = fopen(fileName.toAscii(), "r");
m_view->openFile(file); m_view->openFile(file);
if (!fileName.startsWith(":/")) { if (!fileName.startsWith(":/")) {
@ -139,10 +158,15 @@ void MainWindow::openFile(const QString &path)
m_outlineAction->setEnabled(true); m_outlineAction->setEnabled(true);
m_backgroundAction->setEnabled(true); m_backgroundAction->setEnabled(true);
resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); // resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
} }
} }
void MainWindow::reloadFile()
{
openFile(m_currentPath);
}
void MainWindow::setRenderer(QAction *action) void MainWindow::setRenderer(QAction *action)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL

View file

@ -43,6 +43,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <QString> #include <QString>
#include <stdio.h>
class SvgView; class SvgView;
@ -51,6 +52,7 @@ class QAction;
class QGraphicsView; class QGraphicsView;
class QGraphicsScene; class QGraphicsScene;
class QGraphicsRectItem; class QGraphicsRectItem;
class QFileSystemWatcher;
QT_END_NAMESPACE QT_END_NAMESPACE
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
@ -63,6 +65,7 @@ public:
public slots: public slots:
void openFile(const QString &path = QString()); void openFile(const QString &path = QString());
void setRenderer(QAction *action); void setRenderer(QAction *action);
void reloadFile();
private: private:
QAction *m_nativeAction; QAction *m_nativeAction;
@ -75,6 +78,8 @@ private:
SvgView *m_view; SvgView *m_view;
QString m_currentPath; QString m_currentPath;
QFileSystemWatcher *m_watcher;
FILE *m_filehandle;
}; };
#endif #endif