enable lading of jsons and setting up context
This commit is contained in:
parent
aca372de99
commit
66ea9f39f7
@ -245,7 +245,7 @@ int CommandHandler::executeMain(std::unique_ptr<Context> ctx)
|
|||||||
#ifndef NO_GUI
|
#ifndef NO_GUI
|
||||||
if (vm.count("gui")) {
|
if (vm.count("gui")) {
|
||||||
Application a(argc, argv, (vm.count("gui-no-aa") > 0));
|
Application a(argc, argv, (vm.count("gui-no-aa") > 0));
|
||||||
MainWindow w(std::move(ctx), chipArgs);
|
MainWindow w(std::move(ctx), this);
|
||||||
try {
|
try {
|
||||||
if (vm.count("json")) {
|
if (vm.count("json")) {
|
||||||
std::string filename = vm["json"].as<std::string>();
|
std::string filename = vm["json"].as<std::string>();
|
||||||
@ -378,6 +378,28 @@ int CommandHandler::exec()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Context> CommandHandler::load_json(std::string filename)
|
||||||
|
{
|
||||||
|
vm.clear();
|
||||||
|
std::unordered_map<std::string,Property> values;
|
||||||
|
{
|
||||||
|
std::ifstream f(filename);
|
||||||
|
if (!load_json_settings(f, filename, values))
|
||||||
|
log_error("Loading design failed.\n");
|
||||||
|
}
|
||||||
|
std::unique_ptr<Context> ctx = createContext(values);
|
||||||
|
settings = std::unique_ptr<Settings>(new Settings(ctx.get()));
|
||||||
|
setupContext(ctx.get());
|
||||||
|
setupArchContext(ctx.get());
|
||||||
|
{
|
||||||
|
std::ifstream f(filename);
|
||||||
|
if (!parse_json_file(f, filename, ctx.get()))
|
||||||
|
log_error("Loading design failed.\n");
|
||||||
|
}
|
||||||
|
customAfterLoad(ctx.get());
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
void CommandHandler::run_script_hook(const std::string &name)
|
void CommandHandler::run_script_hook(const std::string &name)
|
||||||
{
|
{
|
||||||
#ifndef NO_PYTHON
|
#ifndef NO_PYTHON
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define COMMAND_H
|
#define COMMAND_H
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
#include <fstream>
|
||||||
#include "nextpnr.h"
|
#include "nextpnr.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ class CommandHandler
|
|||||||
virtual ~CommandHandler(){};
|
virtual ~CommandHandler(){};
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
std::unique_ptr<Context> load_json(std::string filename);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setupArchContext(Context *ctx) = 0;
|
virtual void setupArchContext(Context *ctx) = 0;
|
||||||
@ -57,7 +59,6 @@ class CommandHandler
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
ArchArgs chipArgs;
|
|
||||||
std::unique_ptr<Settings> settings;
|
std::unique_ptr<Settings> settings;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -111,6 +111,7 @@ static std::string speedString(ArchArgs::SpeedGrade speed)
|
|||||||
|
|
||||||
std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
|
ArchArgs chipArgs;
|
||||||
chipArgs.type = ArchArgs::NONE;
|
chipArgs.type = ArchArgs::NONE;
|
||||||
|
|
||||||
if (vm.count("25k"))
|
if (vm.count("25k"))
|
||||||
|
@ -53,6 +53,7 @@ void GenericCommandHandler::customBitstream(Context *ctx) {}
|
|||||||
|
|
||||||
std::unique_ptr<Context> GenericCommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
std::unique_ptr<Context> GenericCommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
|
ArchArgs chipArgs;
|
||||||
if (values.find("arch.name")!=values.end()) {
|
if (values.find("arch.name")!=values.end()) {
|
||||||
std::string arch_name = values["arch.name"].str;
|
std::string arch_name = values["arch.name"].str;
|
||||||
if (arch_name != "generic")
|
if (arch_name != "generic")
|
||||||
|
@ -38,8 +38,8 @@ static void initBasenameResource() { Q_INIT_RESOURCE(base); }
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent)
|
BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent)
|
||||||
: QMainWindow(parent), chipArgs(args), ctx(std::move(context)), timing_driven(false)
|
: QMainWindow(parent), handler(handler), ctx(std::move(context)), timing_driven(false)
|
||||||
{
|
{
|
||||||
initBasenameResource();
|
initBasenameResource();
|
||||||
qRegisterMetaType<std::string>();
|
qRegisterMetaType<std::string>();
|
||||||
@ -293,25 +293,16 @@ void BaseMainWindow::createMenusAndBars()
|
|||||||
setStatusBar(statusBar);
|
setStatusBar(statusBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseMainWindow::load_json(std::string filename)
|
|
||||||
{
|
|
||||||
disableActions();
|
|
||||||
std::ifstream f(filename);
|
|
||||||
if (parse_json_file(f, filename, ctx.get())) {
|
|
||||||
log("Loading design successful.\n");
|
|
||||||
Q_EMIT updateTreeView();
|
|
||||||
updateActions();
|
|
||||||
} else {
|
|
||||||
actionLoadJSON->setEnabled(true);
|
|
||||||
log("Loading design failed.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseMainWindow::open_json()
|
void BaseMainWindow::open_json()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, QString("Open JSON"), QString(), QString("*.json"));
|
QString fileName = QFileDialog::getOpenFileName(this, QString("Open JSON"), QString(), QString("*.json"));
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
load_json(fileName.toStdString());
|
disableActions();
|
||||||
|
ctx = handler->load_json(fileName.toStdString());
|
||||||
|
Q_EMIT contextChanged(ctx.get());
|
||||||
|
Q_EMIT updateTreeView();
|
||||||
|
log("Loading design successful.\n");
|
||||||
|
updateActions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "nextpnr.h"
|
#include "nextpnr.h"
|
||||||
#include "worker.h"
|
#include "worker.h"
|
||||||
|
#include "command.h"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@ -45,7 +46,7 @@ class BaseMainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BaseMainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent = 0);
|
explicit BaseMainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent = 0);
|
||||||
virtual ~BaseMainWindow();
|
virtual ~BaseMainWindow();
|
||||||
Context *getContext() { return ctx.get(); }
|
Context *getContext() { return ctx.get(); }
|
||||||
void updateActions();
|
void updateActions();
|
||||||
@ -55,7 +56,6 @@ class BaseMainWindow : public QMainWindow
|
|||||||
protected:
|
protected:
|
||||||
void createMenusAndBars();
|
void createMenusAndBars();
|
||||||
void disableActions();
|
void disableActions();
|
||||||
void load_json(std::string filename);
|
|
||||||
|
|
||||||
virtual void onDisableActions(){};
|
virtual void onDisableActions(){};
|
||||||
virtual void onUpdateActions(){};
|
virtual void onUpdateActions(){};
|
||||||
@ -88,7 +88,7 @@ class BaseMainWindow : public QMainWindow
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// state variables
|
// state variables
|
||||||
ArchArgs chipArgs;
|
CommandHandler *handler;
|
||||||
std::unique_ptr<Context> ctx;
|
std::unique_ptr<Context> ctx;
|
||||||
TaskManager *task;
|
TaskManager *task;
|
||||||
bool timing_driven;
|
bool timing_driven;
|
||||||
|
@ -30,8 +30,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent)
|
MainWindow::MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent)
|
||||||
: BaseMainWindow(std::move(context), args, parent)
|
: BaseMainWindow(std::move(context), handler, parent)
|
||||||
{
|
{
|
||||||
initMainResource();
|
initMainResource();
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ MainWindow::~MainWindow() {}
|
|||||||
|
|
||||||
void MainWindow::newContext(Context *ctx)
|
void MainWindow::newContext(Context *ctx)
|
||||||
{
|
{
|
||||||
std::string title = "nextpnr-ecp5 - " + ctx->getChipName() + " ( " + chipArgs.package + " )";
|
std::string title = "nextpnr-ecp5 - " + ctx->getChipName() + " ( " + ctx->archArgs().package + " )";
|
||||||
setWindowTitle(title.c_str());
|
setWindowTitle(title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ void MainWindow::new_proj()
|
|||||||
bool ok;
|
bool ok;
|
||||||
QString item = QInputDialog::getItem(this, "Select new context", "Chip:", arch.keys(), 0, false, &ok);
|
QString item = QInputDialog::getItem(this, "Select new context", "Chip:", arch.keys(), 0, false, &ok);
|
||||||
if (ok && !item.isEmpty()) {
|
if (ok && !item.isEmpty()) {
|
||||||
|
ArchArgs chipArgs;
|
||||||
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(item);
|
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(item);
|
||||||
|
|
||||||
QString package = QInputDialog::getItem(this, "Select package", "Package:", getSupportedPackages(chipArgs.type),
|
QString package = QInputDialog::getItem(this, "Select package", "Package:", getSupportedPackages(chipArgs.type),
|
||||||
|
@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent = 0);
|
explicit MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent = 0);
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -26,8 +26,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent)
|
MainWindow::MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent)
|
||||||
: BaseMainWindow(std::move(context), args, parent)
|
: BaseMainWindow(std::move(context), handler, parent)
|
||||||
{
|
{
|
||||||
initMainResource();
|
initMainResource();
|
||||||
QMessageBox::critical(0, "Error - FIXME", "No GUI support for nextpnr-generic");
|
QMessageBox::critical(0, "Error - FIXME", "No GUI support for nextpnr-generic");
|
||||||
|
@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent = 0);
|
explicit MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent = 0);
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -35,8 +35,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); }
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
MainWindow::MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent)
|
MainWindow::MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent)
|
||||||
: BaseMainWindow(std::move(context), args, parent)
|
: BaseMainWindow(std::move(context), handler, parent)
|
||||||
{
|
{
|
||||||
initMainResource();
|
initMainResource();
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void MainWindow::new_proj()
|
|||||||
bool ok;
|
bool ok;
|
||||||
QString item = QInputDialog::getItem(this, "Select new context", "Chip:", arch.keys(), 0, false, &ok);
|
QString item = QInputDialog::getItem(this, "Select new context", "Chip:", arch.keys(), 0, false, &ok);
|
||||||
if (ok && !item.isEmpty()) {
|
if (ok && !item.isEmpty()) {
|
||||||
|
ArchArgs chipArgs;
|
||||||
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(item);
|
chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(item);
|
||||||
|
|
||||||
QString package = QInputDialog::getItem(this, "Select package", "Package:", getSupportedPackages(chipArgs.type),
|
QString package = QInputDialog::getItem(this, "Select package", "Package:", getSupportedPackages(chipArgs.type),
|
||||||
@ -156,7 +156,7 @@ void MainWindow::load_pcf(std::string filename)
|
|||||||
|
|
||||||
void MainWindow::newContext(Context *ctx)
|
void MainWindow::newContext(Context *ctx)
|
||||||
{
|
{
|
||||||
std::string title = "nextpnr-ice40 - " + ctx->getChipName() + " ( " + chipArgs.package + " )";
|
std::string title = "nextpnr-ice40 - " + ctx->getChipName() + " ( " + ctx->archArgs().package + " )";
|
||||||
setWindowTitle(title.c_str());
|
setWindowTitle(title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(std::unique_ptr<Context> context, ArchArgs args, QWidget *parent = 0);
|
explicit MainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent = 0);
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -118,6 +118,8 @@ void Ice40CommandHandler::setupArchContext(Context *ctx)
|
|||||||
|
|
||||||
std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
|
ArchArgs chipArgs;
|
||||||
|
chipArgs.type = ArchArgs::NONE;
|
||||||
if (vm.count("lp384")) {
|
if (vm.count("lp384")) {
|
||||||
chipArgs.type = ArchArgs::LP384;
|
chipArgs.type = ArchArgs::LP384;
|
||||||
chipArgs.package = "qn32";
|
chipArgs.package = "qn32";
|
||||||
|
Loading…
Reference in New Issue
Block a user