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
chmod +x yosys-config
yosys-svgviewer: libs/svgviewer/*
cd libs/svgviewer && qmake && make
cp libs/svgviewer/svgviewer yosys-svgviewer
yosys-svgviewer: libs/svgviewer/*.h libs/svgviewer/*.cpp
-cd libs/svgviewer && qmake-qt4 && make
-cp libs/svgviewer/svgviewer yosys-svgviewer
test: yosys
cd tests/simple && bash run-test.sh
@ -63,7 +63,7 @@ test: yosys
install: yosys
install yosys /usr/local/bin/yosys
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
clean:

View File

@ -373,10 +373,14 @@ struct ShowPass : public Pass {
log(" show [options] [selection]\n");
log("\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(" -viewer <command>\n");
log(" Also run the specified command with the postscript file as parameter.\n");
log(" -viewer <viewer>\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(" -lib <verilog_or_ilang_file>\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(" (including inout ports) are on the right side.\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");
}
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_push();
std::string format;
std::string viewer_exe;
std::string prefix = "yosys-show";
std::vector<std::string> libfiles;
@ -434,6 +443,10 @@ struct ShowPass : public Pass {
colorSeed = atoi(args[++argidx].c_str());
continue;
}
if (arg == "-format" && argidx+1 < args.size()) {
format = atoi(args[++argidx].c_str());
continue;
}
if (arg == "-width") {
flag_width= true;
continue;
@ -460,33 +473,42 @@ struct ShowPass : public Pass {
log_header("Continuing show pass.\n");
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());
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());
}
ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_stretch);
fclose(f);
for (auto lib : libs)
delete lib;
if (worker.page_counter == 0)
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());
if (system(cmd.c_str()) != 0)
log_cmd_error("Shell command failed!\n");
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());
if (system(cmd.c_str()) != 0)
log_cmd_error("Shell command failed!\n");
}
for (auto lib : libs)
delete lib;
log_pop();
}
} ShowPass;

View File

@ -41,12 +41,15 @@
#include "mainwindow.h"
#include <QtGui>
#include <QFileSystemWatcher>
#include "svgview.h"
MainWindow::MainWindow()
: QMainWindow()
, m_view(new SvgView)
, m_watcher(NULL)
, m_filehandle(NULL)
{
QMenu *fileMenu = new QMenu(tr("&File"), this);
QAction *openAction = fileMenu->addAction(tr("&Open..."));
@ -118,6 +121,15 @@ void MainWindow::openFile(const QString &path)
else
fileName = path;
if (m_watcher) {
delete m_watcher;
m_watcher = NULL;
}
if (m_filehandle) {
fclose(m_filehandle);
m_filehandle = NULL;
}
if (!fileName.isEmpty()) {
QFile file(fileName);
if (!file.exists()) {
@ -129,6 +141,13 @@ void MainWindow::openFile(const QString &path)
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);
if (!fileName.startsWith(":/")) {
@ -139,10 +158,15 @@ void MainWindow::openFile(const QString &path)
m_outlineAction->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)
{
#ifndef QT_NO_OPENGL

View File

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