From ec4fc0f830b859733b8729b03cdc3c54e84f8cea Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 21 Jul 2018 11:24:29 +0200 Subject: made open project to work --- gui/ice40/mainwindow.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'gui/ice40/mainwindow.cc') diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 28792ed3..b58d6e8c 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -20,9 +20,12 @@ #include "mainwindow.h" #include #include +#include #include #include #include +#include +#include #include "bitstream.h" #include "design_utils.h" #include "jsonparse.h" @@ -252,10 +255,78 @@ void MainWindow::newContext(Context *ctx) void MainWindow::open_proj() { + QMap arch; +#ifdef ICE40_HX1K_ONLY + arch.insert("hx1k", ArchArgs::HX1K); +#else + arch.insert("lp384", ArchArgs::LP384); + arch.insert("lp1k", ArchArgs::LP1K); + arch.insert("hx1k", ArchArgs::HX1K); + arch.insert("up5k", ArchArgs::UP5K); + arch.insert("lp8k", ArchArgs::LP8K); + arch.insert("hx8k", ArchArgs::HX8K); +#endif + QString fileName = QFileDialog::getOpenFileName(this, QString("Open Project"), QString(), QString("*.proj")); if (!fileName.isEmpty()) { - std::string fn = fileName.toStdString(); - disableActions(); + try { + namespace pt = boost::property_tree; + + std::string fn = fileName.toStdString(); + disableActions(); + + pt::ptree root; + std::string filename = fileName.toStdString(); + pt::read_json(filename, root); + log_info("Loading project %s...\n", filename.c_str()); + log_break(); + + int version = root.get("project.version"); + if (version != 1) + log_error("Wrong project format version.\n"); + + std::string arch_name = root.get("project.arch.name"); + if (arch_name != "ice40") + log_error("Unsuported project architecture.\n"); + + std::string arch_type = root.get("project.arch.type"); + std::string arch_package = root.get("project.arch.package"); + + chipArgs.type = (ArchArgs::ArchArgsTypes)arch.value(arch_type); + chipArgs.package = arch_package; + ctx = std::unique_ptr(new Context(chipArgs)); + Q_EMIT contextChanged(ctx.get()); + + QFileInfo fi(fileName); + QDir::setCurrent(fi.absoluteDir().absolutePath()); + log_info("Setting current dir to %s...\n", fi.absoluteDir().absolutePath().toStdString().c_str()); + log_info("Loading project %s...\n", filename.c_str()); + log_info("Context changed to %s (%s)\n", arch_type.c_str(), arch_package.c_str()); + + auto project = root.get_child("project"); + std::string json; + std::string pcf; + if (project.count("input")) { + auto input = project.get_child("input"); + if (input.count("json")) + json = input.get("json"); + if (input.count("pcf")) + pcf = input.get("pcf"); + } + + if (!(QFileInfo::exists(json.c_str()) && QFileInfo(json.c_str()).isFile())) { + log_error("Json file does not exist.\n"); + } + if (!pcf.empty()) { + if (!(QFileInfo::exists(pcf.c_str()) && QFileInfo(pcf.c_str()).isFile())) { + log_error("PCF file does not exist.\n"); + } + } + + log_info("Loading json: %s...\n", json.c_str()); + load_json(json, pcf); + } catch (log_execution_error_exception) { + } } } -- cgit v1.2.3