2018-06-21 21:41:40 +08:00
|
|
|
#include "worker.h"
|
|
|
|
#include <fstream>
|
2018-06-21 23:44:18 +08:00
|
|
|
#include "bitstream.h"
|
|
|
|
#include "design_utils.h"
|
2018-06-21 21:41:40 +08:00
|
|
|
#include "jsonparse.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "pack.h"
|
|
|
|
#include "pcf.h"
|
|
|
|
#include "place_sa.h"
|
|
|
|
#include "route.h"
|
|
|
|
#include "timing.h"
|
|
|
|
|
2018-06-22 18:11:22 +08:00
|
|
|
struct WorkerInterruptionRequested
|
2018-06-21 21:41:40 +08:00
|
|
|
{
|
2018-06-22 18:11:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx)
|
|
|
|
{
|
|
|
|
log_write_function = [this, parent](std::string text) {
|
|
|
|
Q_EMIT log(text);
|
|
|
|
if (parent->shouldTerminate()) {
|
|
|
|
parent->clearTerminate();
|
|
|
|
throw WorkerInterruptionRequested();
|
|
|
|
}
|
2018-06-22 18:49:20 +08:00
|
|
|
while (parent->isPaused()){
|
|
|
|
QThread::sleep(1);
|
|
|
|
}
|
2018-06-22 18:11:22 +08:00
|
|
|
};
|
2018-06-21 21:41:40 +08:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:44:18 +08:00
|
|
|
void Worker::parsejson(const std::string &filename)
|
2018-06-21 21:41:40 +08:00
|
|
|
{
|
|
|
|
std::string fn = filename;
|
2018-06-21 22:16:58 +08:00
|
|
|
std::ifstream f(fn);
|
2018-06-21 23:56:45 +08:00
|
|
|
try {
|
2018-06-22 00:08:28 +08:00
|
|
|
if (!parse_json_file(f, fn, ctx))
|
|
|
|
log_error("Loading design failed.\n");
|
2018-06-21 23:56:45 +08:00
|
|
|
if (!pack_design(ctx))
|
|
|
|
log_error("Packing design failed.\n");
|
|
|
|
double freq = 50e6;
|
|
|
|
assign_budget(ctx, freq);
|
|
|
|
print_utilisation(ctx);
|
2018-06-21 21:41:40 +08:00
|
|
|
|
2018-06-21 23:56:45 +08:00
|
|
|
if (!place_design_sa(ctx))
|
|
|
|
log_error("Placing design failed.\n");
|
|
|
|
if (!route_design(ctx))
|
|
|
|
log_error("Routing design failed.\n");
|
2018-06-22 18:11:22 +08:00
|
|
|
Q_EMIT log("DONE\n");
|
2018-06-21 23:56:45 +08:00
|
|
|
} catch (log_execution_error_exception) {
|
2018-06-22 18:11:22 +08:00
|
|
|
} catch (WorkerInterruptionRequested) {
|
|
|
|
Q_EMIT log("CANCELED\n");
|
2018-06-21 23:56:45 +08:00
|
|
|
}
|
2018-06-21 21:41:40 +08:00
|
|
|
}
|
|
|
|
|
2018-06-22 18:49:20 +08:00
|
|
|
TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false)
|
2018-06-21 21:41:40 +08:00
|
|
|
{
|
2018-06-22 18:11:22 +08:00
|
|
|
Worker *worker = new Worker(ctx, this);
|
2018-06-21 21:41:40 +08:00
|
|
|
worker->moveToThread(&workerThread);
|
|
|
|
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
|
|
|
|
connect(this, &TaskManager::parsejson, worker, &Worker::parsejson);
|
|
|
|
connect(worker, &Worker::log, this, &TaskManager::info);
|
|
|
|
workerThread.start();
|
|
|
|
}
|
|
|
|
|
2018-06-21 23:44:18 +08:00
|
|
|
TaskManager::~TaskManager()
|
2018-06-21 21:41:40 +08:00
|
|
|
{
|
2018-06-22 18:24:50 +08:00
|
|
|
if (workerThread.isRunning())
|
|
|
|
terminate_thread();
|
2018-06-21 21:41:40 +08:00
|
|
|
workerThread.quit();
|
|
|
|
workerThread.wait();
|
|
|
|
}
|
|
|
|
|
2018-06-22 18:11:22 +08:00
|
|
|
void TaskManager::info(const std::string &result) { Q_EMIT log(result); }
|
|
|
|
|
|
|
|
void TaskManager::terminate_thread()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
toTerminate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TaskManager::shouldTerminate()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
return toTerminate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskManager::clearTerminate()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
toTerminate = false;
|
2018-06-22 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TaskManager::pause_thread()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
toPause = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskManager::continue_thread()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
toPause = false;
|
|
|
|
}
|
|
|
|
bool TaskManager::isPaused()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
return toPause;
|
2018-06-22 18:11:22 +08:00
|
|
|
}
|