Merge branch 'master' of gitlab.com:SymbioticEDA/nextpnr

# Conflicts:
#	common/route.cc
This commit is contained in:
Clifford Wolf 2018-06-21 19:31:50 +02:00
commit bfae4663fc
18 changed files with 634 additions and 594 deletions

View File

@ -150,12 +150,8 @@ void logv_error(const char *format, va_list ap)
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
log_files = backup_log_files; log_files = backup_log_files;
throw 0;
#elif defined(_MSC_VER)
_exit(EXIT_FAILURE);
#else
_Exit(EXIT_FAILURE);
#endif #endif
throw log_execution_error_exception();
} }
void log(const char *format, ...) void log(const char *format, ...)

View File

@ -43,6 +43,10 @@ struct log_cmd_error_exception
{ {
}; };
struct log_execution_error_exception
{
};
extern std::vector<FILE *> log_files; extern std::vector<FILE *> log_files;
extern std::vector<std::ostream *> log_streams; extern std::vector<std::ostream *> log_streams;
extern FILE *log_errfile; extern FILE *log_errfile;

View File

@ -478,10 +478,14 @@ class SAPlacer
bool place_design_sa(Context *ctx) bool place_design_sa(Context *ctx)
{ {
try {
SAPlacer placer(ctx); SAPlacer placer(ctx);
placer.place(); placer.place();
log_info("Checksum: 0x%08x\n", ctx->checksum()); log_info("Checksum: 0x%08x\n", ctx->checksum());
return true; return true;
} catch (log_execution_error_exception) {
return false;
}
} }
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -406,6 +406,7 @@ NEXTPNR_NAMESPACE_BEGIN
bool route_design(Context *ctx) bool route_design(Context *ctx)
{ {
try {
delay_t ripup_penalty = ctx->getRipupDelayPenalty(); delay_t ripup_penalty = ctx->getRipupDelayPenalty();
RipupScoreboard scores; RipupScoreboard scores;
@ -452,8 +453,8 @@ bool route_design(Context *ctx)
if (driver_port_it != net_info->driver.cell->pins.end()) if (driver_port_it != net_info->driver.cell->pins.end())
driver_port = driver_port_it->second; driver_port = driver_port_it->second;
auto src_wire = auto src_wire = ctx->getWireBelPin(src_bel,
ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); ctx->portPinFromId(driver_port));
if (src_wire == WireId()) if (src_wire == WireId())
continue; continue;
@ -471,8 +472,8 @@ bool route_design(Context *ctx)
if (user_port_it != user_it.cell->pins.end()) if (user_port_it != user_it.cell->pins.end())
user_port = user_port_it->second; user_port = user_port_it->second;
auto dst_wire = auto dst_wire = ctx->getWireBelPin(
ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); dst_bel, ctx->portPinFromId(user_port));
if (dst_wire == WireId()) if (dst_wire == WireId())
continue; continue;
@ -515,7 +516,8 @@ bool route_design(Context *ctx)
for (auto net_name : netsArray) { for (auto net_name : netsArray) {
if (printNets) if (printNets)
log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), log_info(" routing net %s. (%d users)\n",
net_name.c_str(ctx),
int(ctx->nets.at(net_name)->users.size())); int(ctx->nets.at(net_name)->users.size()));
Router router(ctx, scores, net_name, false); Router router(ctx, scores, net_name, false);
@ -527,7 +529,8 @@ bool route_design(Context *ctx)
if (!router.routedOkay) { if (!router.routedOkay) {
if (printNets) if (printNets)
log_info(" failed to route to %s.\n", log_info(
" failed to route to %s.\n",
ctx->getWireName(router.failedDest).c_str(ctx)); ctx->getWireName(router.failedDest).c_str(ctx));
ripupQueue.insert(net_name); ripupQueue.insert(net_name);
} }
@ -542,8 +545,8 @@ bool route_design(Context *ctx)
int normalRouteCnt = netCnt - int(ripupQueue.size()); int normalRouteCnt = netCnt - int(ripupQueue.size());
if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0))
log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt, log_info(" processed %d nets. (%d routed, %d failed)\n",
normalRouteCnt, int(ripupQueue.size())); netCnt, normalRouteCnt, int(ripupQueue.size()));
if (ctx->verbose) if (ctx->verbose)
log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime revisits).\n", log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime revisits).\n",
@ -551,7 +554,8 @@ bool route_design(Context *ctx)
if (!ripupQueue.empty()) { if (!ripupQueue.empty()) {
if (ctx->verbose || iterCnt == 1) if (ctx->verbose || iterCnt == 1)
log_info("failed to route %d nets. re-routing in ripup mode.\n", log_info("failed to route %d nets. re-routing in ripup "
"mode.\n",
int(ripupQueue.size())); int(ripupQueue.size()));
printNets = ctx->verbose && (ripupQueue.size() < 10); printNets = ctx->verbose && (ripupQueue.size() < 10);
@ -608,7 +612,8 @@ bool route_design(Context *ctx)
} }
if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0))
log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt); log_info(" routed %d nets, ripped %d nets.\n", netCnt,
ripCnt);
if (ctx->verbose) if (ctx->verbose)
log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime revisits).\n", log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime revisits).\n",
@ -621,18 +626,22 @@ bool route_design(Context *ctx)
} }
if (!ctx->verbose) if (!ctx->verbose)
log_info("iteration %d: routed %d nets without ripup, routed %d " log_info(
"iteration %d: routed %d nets without ripup, routed %d "
"nets with ripup.\n", "nets with ripup.\n",
iterCnt, normalRouteCnt, int(ripupQueue.size())); iterCnt, normalRouteCnt, int(ripupQueue.size()));
if (iterCnt == 8 || iterCnt == 16 || iterCnt == 32 || iterCnt == 64 || if (iterCnt == 8 || iterCnt == 16 || iterCnt == 32 ||
iterCnt == 128) iterCnt == 64 || iterCnt == 128)
ripup_penalty += ctx->getRipupDelayPenalty(); ripup_penalty += ctx->getRipupDelayPenalty();
} }
log_info("routing complete after %d iterations.\n", iterCnt); log_info("routing complete after %d iterations.\n", iterCnt);
log_info("Checksum: 0x%08x\n", ctx->checksum()); log_info("Checksum: 0x%08x\n", ctx->checksum());
return true; return true;
} catch (log_execution_error_exception) {
return false;
}
} }
bool get_actual_route_delay(Context *ctx, WireId src_wire, WireId dst_wire, bool get_actual_route_delay(Context *ctx, WireId src_wire, WireId dst_wire,

View File

@ -32,6 +32,8 @@ USING_NEXTPNR_NAMESPACE
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
try {
namespace po = boost::program_options; namespace po = boost::program_options;
int rc = 0; int rc = 0;
@ -113,6 +115,13 @@ int main(int argc, char *argv[])
} }
deinit_python(); deinit_python();
return rc; return rc;
} catch (log_execution_error_exception) {
#if defined(_MSC_VER)
_exit(EXIT_FAILURE);
#else
_Exit(EXIT_FAILURE);
#endif
}
} }
#endif #endif

View File

@ -797,8 +797,9 @@ void json_import(Context *ctx, string modname, JsonNode *node)
} }
}; // End Namespace JsonParser }; // End Namespace JsonParser
void parse_json_file(std::istream &f, std::string &filename, Context *ctx) bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
{ {
try {
using namespace JsonParser; using namespace JsonParser;
JsonNode root(f); JsonNode root(f);
@ -818,6 +819,10 @@ void parse_json_file(std::istream &f, std::string &filename, Context *ctx)
log_info("Checksum: 0x%08x\n", ctx->checksum()); log_info("Checksum: 0x%08x\n", ctx->checksum());
log_break(); log_break();
return true;
} catch (log_execution_error_exception) {
return false;
}
} }
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -26,7 +26,7 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
extern void parse_json_file(std::istream &, std::string &, Context *); extern bool parse_json_file(std::istream &, std::string &, Context *);
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -10,7 +10,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "pythontab.h" #include "pythontab.h"
BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent)
: QMainWindow(parent), ctx(_ctx) : QMainWindow(parent), ctx(_ctx)
{ {

View File

@ -17,11 +17,6 @@ void MainWindow::createMenu()
menuBar->addAction(menu_Custom->menuAction()); menuBar->addAction(menu_Custom->menuAction());
} }
void MainWindow::open() void MainWindow::open() {}
{
}
bool MainWindow::save() bool MainWindow::save() { return false; }
{
return false;
}

View File

@ -20,8 +20,7 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent)
createMenu(); createMenu();
task = new TaskManager(_ctx); task = new TaskManager(_ctx);
connect(task, SIGNAL(log(std::string)), this, connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string)));
SLOT(writeInfo(std::string)));
} }
MainWindow::~MainWindow() {} MainWindow::~MainWindow() {}
@ -43,7 +42,4 @@ void MainWindow::open()
task->parsejson(fn); task->parsejson(fn);
} }
} }
bool MainWindow::save() bool MainWindow::save() { return false; }
{
return false;
}

View File

@ -1,13 +1,13 @@
#include "worker.h" #include "worker.h"
#include <fstream> #include <fstream>
#include "bitstream.h"
#include "design_utils.h"
#include "jsonparse.h" #include "jsonparse.h"
#include "log.h" #include "log.h"
#include "pack.h" #include "pack.h"
#include "pcf.h" #include "pcf.h"
#include "place_sa.h" #include "place_sa.h"
#include "route.h" #include "route.h"
#include "bitstream.h"
#include "design_utils.h"
#include "timing.h" #include "timing.h"
Worker::Worker(Context *_ctx) : ctx(_ctx) Worker::Worker(Context *_ctx) : ctx(_ctx)
@ -19,8 +19,9 @@ void Worker::parsejson(const std::string &filename)
{ {
std::string fn = filename; std::string fn = filename;
std::ifstream f(fn); std::ifstream f(fn);
try {
parse_json_file(f, fn, ctx); if (!parse_json_file(f, fn, ctx))
log_error("Loading design failed.\n");
if (!pack_design(ctx)) if (!pack_design(ctx))
log_error("Packing design failed.\n"); log_error("Packing design failed.\n");
double freq = 50e6; double freq = 50e6;
@ -31,11 +32,11 @@ void Worker::parsejson(const std::string &filename)
log_error("Placing design failed.\n"); log_error("Placing design failed.\n");
if (!route_design(ctx)) if (!route_design(ctx))
log_error("Routing design failed.\n"); log_error("Routing design failed.\n");
print_utilisation(ctx);
Q_EMIT log("done"); Q_EMIT log("done");
} catch (log_execution_error_exception) {
}
} }
TaskManager::TaskManager(Context *ctx) TaskManager::TaskManager(Context *ctx)
{ {
Worker *worker = new Worker(ctx); Worker *worker = new Worker(ctx);
@ -52,7 +53,4 @@ TaskManager::~TaskManager()
workerThread.wait(); workerThread.wait();
} }
void TaskManager::info(const std::string &result) void TaskManager::info(const std::string &result) { Q_EMIT log(result); }
{
Q_EMIT log(result);
}

View File

@ -1,8 +1,8 @@
#ifndef WORKER_H #ifndef WORKER_H
#define WORKER_H #define WORKER_H
#include "nextpnr.h"
#include <QThread> #include <QThread>
#include "nextpnr.h"
// FIXME // FIXME
USING_NEXTPNR_NAMESPACE USING_NEXTPNR_NAMESPACE
@ -10,13 +10,14 @@ USING_NEXTPNR_NAMESPACE
class Worker : public QObject class Worker : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Worker(Context *ctx); Worker(Context *ctx);
public Q_SLOTS: public Q_SLOTS:
void parsejson(const std::string &filename); void parsejson(const std::string &filename);
Q_SIGNALS: Q_SIGNALS:
void log(const std::string &text); void log(const std::string &text);
private:
private:
Context *ctx; Context *ctx;
}; };
@ -24,12 +25,13 @@ class TaskManager : public QObject
{ {
Q_OBJECT Q_OBJECT
QThread workerThread; QThread workerThread;
public:
public:
TaskManager(Context *ctx); TaskManager(Context *ctx);
~TaskManager(); ~TaskManager();
public Q_SLOTS: public Q_SLOTS:
void info(const std::string &text); void info(const std::string &text);
Q_SIGNALS: Q_SIGNALS:
void parsejson(const std::string &); void parsejson(const std::string &);
void log(const std::string &text); void log(const std::string &text);
}; };

View File

@ -60,6 +60,7 @@ void svg_dump_el(const GraphicElement &el)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
try {
namespace po = boost::program_options; namespace po = boost::program_options;
int rc = 0; int rc = 0;
std::string str; std::string str;
@ -185,7 +186,8 @@ int main(int argc, char *argv[])
} }
#ifdef ICE40_HX1K_ONLY #ifdef ICE40_HX1K_ONLY
if (chipArgs.type != ArchArgs::HX1K) { if (chipArgs.type != ArchArgs::HX1K) {
std::cout << "This version of nextpnr-ice40 is built with HX1K-support " std::cout << "This version of nextpnr-ice40 is built with "
"HX1K-support "
"only.\n"; "only.\n";
return 1; return 1;
} }
@ -219,7 +221,8 @@ int main(int argc, char *argv[])
std::cout << "<svg xmlns=\"http://www.w3.org/2000/svg\" " std::cout << "<svg xmlns=\"http://www.w3.org/2000/svg\" "
"xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"; "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
for (auto bel : ctx.getBels()) { for (auto bel : ctx.getBels()) {
std::cout << "<!-- " << ctx.getBelName(bel).str(&ctx) << " -->\n"; std::cout << "<!-- " << ctx.getBelName(bel).str(&ctx)
<< " -->\n";
for (auto &el : ctx.getBelGraphics(bel)) for (auto &el : ctx.getBelGraphics(bel))
svg_dump_el(el); svg_dump_el(el);
} }
@ -254,15 +257,16 @@ int main(int argc, char *argv[])
} }
if (ctx.getBelType(b) == TYPE_SB_IO) { if (ctx.getBelType(b) == TYPE_SB_IO) {
dst_wires.push_back(ctx.getWireBelPin(b, PIN_D_OUT_0)); dst_wires.push_back(ctx.getWireBelPin(b, PIN_D_OUT_0));
dst_wires.push_back(ctx.getWireBelPin(b, PIN_OUTPUT_ENABLE)); dst_wires.push_back(
ctx.getWireBelPin(b, PIN_OUTPUT_ENABLE));
} }
} }
ctx.shuffle(src_wires); ctx.shuffle(src_wires);
ctx.shuffle(dst_wires); ctx.shuffle(dst_wires);
for (int i = 0; i < int(src_wires.size()) && i < int(dst_wires.size()); for (int i = 0;
i++) { i < int(src_wires.size()) && i < int(dst_wires.size()); i++) {
delay_t actual_delay; delay_t actual_delay;
WireId src = src_wires[i], dst = dst_wires[i]; WireId src = src_wires[i], dst = dst_wires[i];
if (!get_actual_route_delay(&ctx, src, dst, actual_delay)) if (!get_actual_route_delay(&ctx, src, dst, actual_delay))
@ -284,12 +288,13 @@ int main(int argc, char *argv[])
if (vm.count("json")) { if (vm.count("json")) {
std::string filename = vm["json"].as<std::string>(); std::string filename = vm["json"].as<std::string>();
std::ifstream f(filename); std::ifstream f(filename);
if (!parse_json_file(f, filename, &ctx))
parse_json_file(f, filename, &ctx); log_error("Loading design failed.\n");
if (vm.count("pcf")) { if (vm.count("pcf")) {
std::ifstream pcf(vm["pcf"].as<std::string>()); std::ifstream pcf(vm["pcf"].as<std::string>());
apply_pcf(&ctx, pcf); if (!apply_pcf(&ctx, pcf))
log_error("Loading PCF failed.\n");
} }
if (!pack_design(&ctx) && !ctx.force) if (!pack_design(&ctx) && !ctx.force)
@ -330,6 +335,13 @@ int main(int argc, char *argv[])
} }
deinit_python(); deinit_python();
return rc; return rc;
} catch (log_execution_error_exception) {
#if defined(_MSC_VER)
_exit(EXIT_FAILURE);
#else
_Exit(EXIT_FAILURE);
#endif
}
} }
#endif #endif

View File

@ -487,6 +487,7 @@ static void promote_globals(Context *ctx)
// Main pack function // Main pack function
bool pack_design(Context *ctx) bool pack_design(Context *ctx)
{ {
try {
log_break(); log_break();
pack_constants(ctx); pack_constants(ctx);
promote_globals(ctx); promote_globals(ctx);
@ -496,6 +497,9 @@ bool pack_design(Context *ctx)
pack_ram(ctx); pack_ram(ctx);
log_info("Checksum: 0x%08x\n", ctx->checksum()); log_info("Checksum: 0x%08x\n", ctx->checksum());
return true; return true;
} catch (log_execution_error_exception) {
return false;
}
} }
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -27,8 +27,9 @@ NEXTPNR_NAMESPACE_BEGIN
// Read a w // Read a w
// Apply PCF constraints to a pre-packing design // Apply PCF constraints to a pre-packing design
void apply_pcf(Context *ctx, std::istream &in) bool apply_pcf(Context *ctx, std::istream &in)
{ {
try {
if (!in) if (!in)
log_error("failed to open PCF file"); log_error("failed to open PCF file");
std::string line; std::string line;
@ -46,7 +47,8 @@ void apply_pcf(Context *ctx, std::istream &in)
std::string cmd = words.at(0); std::string cmd = words.at(0);
if (cmd == "set_io") { if (cmd == "set_io") {
size_t args_end = 1; size_t args_end = 1;
while (args_end < words.size() && words.at(args_end).at(0) == '-') while (args_end < words.size() &&
words.at(args_end).at(0) == '-')
args_end++; args_end++;
std::string cell = words.at(args_end); std::string cell = words.at(args_end);
std::string pin = words.at(args_end + 1); std::string pin = words.at(args_end + 1);
@ -58,7 +60,8 @@ void apply_pcf(Context *ctx, std::istream &in)
if (pin_bel == BelId()) if (pin_bel == BelId())
log_error("package does not have a pin named %s\n", log_error("package does not have a pin named %s\n",
pin.c_str()); pin.c_str());
fnd_cell->second->attrs["BEL"] = ctx->getBelName(pin_bel).str(); fnd_cell->second->attrs["BEL"] =
ctx->getBelName(pin_bel).str();
log_info("constrained '%s' to bel '%s'\n", cell.c_str(), log_info("constrained '%s' to bel '%s'\n", cell.c_str(),
fnd_cell->second->attrs["BEL"].c_str()); fnd_cell->second->attrs["BEL"].c_str());
} }
@ -66,6 +69,10 @@ void apply_pcf(Context *ctx, std::istream &in)
log_error("unsupported pcf command '%s'\n", cmd.c_str()); log_error("unsupported pcf command '%s'\n", cmd.c_str());
} }
} }
return true;
} catch (log_execution_error_exception) {
return false;
}
} }
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -27,7 +27,7 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
// Apply PCF constraints to a pre-packing design // Apply PCF constraints to a pre-packing design
void apply_pcf(Context *ctx, std::istream &in); bool apply_pcf(Context *ctx, std::istream &in);
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END