2018-08-05 22:13:34 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Clifford Wolf <clifford@symbioticeda.com>
|
|
|
|
* Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NO_GUI
|
|
|
|
#include <QApplication>
|
|
|
|
#include "application.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#endif
|
|
|
|
#ifndef NO_PYTHON
|
|
|
|
#include "pybindings.h"
|
|
|
|
#endif
|
|
|
|
|
2019-06-04 03:01:05 +08:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2019-06-26 00:19:25 +08:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2018-08-05 22:13:34 +08:00
|
|
|
#include <boost/filesystem/convenience.hpp>
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include "command.h"
|
|
|
|
#include "design_utils.h"
|
2019-11-16 01:59:42 +08:00
|
|
|
#include "json_frontend.h"
|
2019-05-31 17:09:13 +08:00
|
|
|
#include "jsonwrite.h"
|
2018-08-05 22:13:34 +08:00
|
|
|
#include "log.h"
|
2018-08-09 00:17:34 +08:00
|
|
|
#include "timing.h"
|
2018-11-27 03:14:38 +08:00
|
|
|
#include "util.h"
|
2018-08-05 22:13:34 +08:00
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-11-22 01:08:45 +08:00
|
|
|
CommandHandler::CommandHandler(int argc, char **argv) : argc(argc), argv(argv) { log_streams.clear(); }
|
2018-08-05 22:13:34 +08:00
|
|
|
|
|
|
|
bool CommandHandler::parseOptions()
|
|
|
|
{
|
|
|
|
options.add(getGeneralOptions()).add(getArchOptions());
|
|
|
|
try {
|
|
|
|
po::parsed_options parsed =
|
|
|
|
po::command_line_parser(argc, argv)
|
|
|
|
.style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing)
|
|
|
|
.options(options)
|
|
|
|
.positional(pos)
|
|
|
|
.run();
|
|
|
|
po::store(parsed, vm);
|
|
|
|
po::notify(vm);
|
|
|
|
return true;
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
std::cout << e.what() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandHandler::executeBeforeContext()
|
|
|
|
{
|
|
|
|
if (vm.count("help") || argc == 1) {
|
2018-11-22 01:08:45 +08:00
|
|
|
std::cerr << boost::filesystem::basename(argv[0])
|
2020-01-11 18:04:07 +08:00
|
|
|
<< " -- Next Generation Place and Route (Version " GIT_DESCRIBE_STR ")\n";
|
2018-11-22 01:08:45 +08:00
|
|
|
std::cerr << options << "\n";
|
2018-08-05 22:13:34 +08:00
|
|
|
return argc != 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("version")) {
|
2018-11-22 01:08:45 +08:00
|
|
|
std::cerr << boost::filesystem::basename(argv[0])
|
2020-01-11 18:04:07 +08:00
|
|
|
<< " -- Next Generation Place and Route (Version " GIT_DESCRIBE_STR ")\n";
|
2018-08-05 22:13:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
validate();
|
2018-12-27 00:05:12 +08:00
|
|
|
|
|
|
|
if (vm.count("quiet")) {
|
|
|
|
log_streams.push_back(std::make_pair(&std::cerr, LogLevel::WARNING_MSG));
|
|
|
|
} else {
|
|
|
|
log_streams.push_back(std::make_pair(&std::cerr, LogLevel::LOG_MSG));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("log")) {
|
|
|
|
std::string logfilename = vm["log"].as<std::string>();
|
2019-04-03 00:39:21 +08:00
|
|
|
logfile.open(logfilename);
|
|
|
|
if (!logfile.is_open())
|
2018-12-27 00:05:12 +08:00
|
|
|
log_error("Failed to open log file '%s' for writing.\n", logfilename.c_str());
|
|
|
|
log_streams.push_back(std::make_pair(&logfile, LogLevel::LOG_MSG));
|
|
|
|
}
|
2018-08-05 22:13:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
po::options_description CommandHandler::getGeneralOptions()
|
|
|
|
{
|
|
|
|
po::options_description general("General options");
|
|
|
|
general.add_options()("help,h", "show help");
|
|
|
|
general.add_options()("verbose,v", "verbose output");
|
2018-11-22 01:08:45 +08:00
|
|
|
general.add_options()("quiet,q", "quiet mode, only errors and warnings displayed");
|
|
|
|
general.add_options()("log,l", po::value<std::string>(),
|
|
|
|
"log file, all log messages are written to this file regardless of -q");
|
2018-08-05 22:13:34 +08:00
|
|
|
general.add_options()("debug", "debug output");
|
|
|
|
general.add_options()("force,f", "keep running after errors");
|
|
|
|
#ifndef NO_GUI
|
|
|
|
general.add_options()("gui", "start gui");
|
2019-05-28 01:10:50 +08:00
|
|
|
general.add_options()("gui-no-aa", "disable anti aliasing (use together with --gui option)");
|
2018-08-05 22:13:34 +08:00
|
|
|
#endif
|
|
|
|
#ifndef NO_PYTHON
|
2018-10-17 17:51:23 +08:00
|
|
|
general.add_options()("run", po::value<std::vector<std::string>>(),
|
|
|
|
"python file to execute instead of default flow");
|
2018-08-05 22:13:34 +08:00
|
|
|
pos.add("run", -1);
|
2018-10-17 17:51:23 +08:00
|
|
|
general.add_options()("pre-pack", po::value<std::vector<std::string>>(), "python file to run before packing");
|
|
|
|
general.add_options()("pre-place", po::value<std::vector<std::string>>(), "python file to run before placement");
|
|
|
|
general.add_options()("pre-route", po::value<std::vector<std::string>>(), "python file to run before routing");
|
|
|
|
general.add_options()("post-route", po::value<std::vector<std::string>>(), "python file to run after routing");
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
#endif
|
|
|
|
general.add_options()("json", po::value<std::string>(), "JSON design file to ingest");
|
2019-05-31 17:09:13 +08:00
|
|
|
general.add_options()("write", po::value<std::string>(), "JSON design file to write");
|
2018-08-05 22:13:34 +08:00
|
|
|
general.add_options()("seed", po::value<int>(), "seed value for random number generator");
|
2018-11-20 02:45:12 +08:00
|
|
|
general.add_options()("randomize-seed,r", "randomize seed value for random number generator");
|
2019-03-24 19:10:20 +08:00
|
|
|
|
|
|
|
general.add_options()(
|
|
|
|
"placer", po::value<std::string>(),
|
|
|
|
std::string("placer algorithm to use; available: " + boost::algorithm::join(Arch::availablePlacers, ", ") +
|
|
|
|
"; default: " + Arch::defaultPlacer)
|
|
|
|
.c_str());
|
|
|
|
|
2020-02-03 19:54:38 +08:00
|
|
|
general.add_options()(
|
|
|
|
"router", po::value<std::string>(),
|
|
|
|
std::string("router algorithm to use; available: " + boost::algorithm::join(Arch::availableRouters, ", ") +
|
|
|
|
"; default: " + Arch::defaultPlacer)
|
|
|
|
.c_str());
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
general.add_options()("slack_redist_iter", po::value<int>(), "number of iterations between slack redistribution");
|
|
|
|
general.add_options()("cstrweight", po::value<float>(), "placer weighting for relative constraint satisfaction");
|
2018-12-11 02:53:21 +08:00
|
|
|
general.add_options()("starttemp", po::value<float>(), "placer SA start temperature");
|
2018-12-08 21:59:10 +08:00
|
|
|
general.add_options()("placer-budgets", "use budget rather than criticality in placer timing weights");
|
|
|
|
|
2018-08-09 00:34:12 +08:00
|
|
|
general.add_options()("pack-only", "pack design only without placement or routing");
|
2019-06-02 15:13:19 +08:00
|
|
|
general.add_options()("no-route", "process design without routing");
|
|
|
|
general.add_options()("no-place", "process design without placement");
|
2019-06-02 16:01:20 +08:00
|
|
|
general.add_options()("no-pack", "process design without packing");
|
2018-08-05 22:13:34 +08:00
|
|
|
|
2018-12-14 21:06:00 +08:00
|
|
|
general.add_options()("ignore-loops", "ignore combinational loops in timing analysis");
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
general.add_options()("version,V", "show version");
|
|
|
|
general.add_options()("test", "check architecture database integrity");
|
|
|
|
general.add_options()("freq", po::value<double>(), "set target frequency for design in MHz");
|
2019-03-04 19:29:19 +08:00
|
|
|
general.add_options()("timing-allow-fail", "allow timing to fail in design");
|
2018-08-05 22:13:34 +08:00
|
|
|
general.add_options()("no-tmdriv", "disable timing-driven placement");
|
2019-10-19 23:52:47 +08:00
|
|
|
general.add_options()("sdf", po::value<std::string>(), "SDF delay back-annotation file to write");
|
2019-10-24 19:37:07 +08:00
|
|
|
general.add_options()("sdf-cvc", "enable tweaks for SDF file compatibility with the CVC simulator");
|
2019-10-19 23:52:47 +08:00
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
return general;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandHandler::setupContext(Context *ctx)
|
|
|
|
{
|
2019-06-15 21:31:18 +08:00
|
|
|
if (ctx->settings.find(ctx->id("seed")) != ctx->settings.end())
|
|
|
|
ctx->rngstate = ctx->setting<uint64_t>("seed");
|
2019-06-26 00:19:25 +08:00
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
if (vm.count("verbose")) {
|
|
|
|
ctx->verbose = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("debug")) {
|
|
|
|
ctx->verbose = true;
|
|
|
|
ctx->debug = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("force")) {
|
|
|
|
ctx->force = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("seed")) {
|
|
|
|
ctx->rngseed(vm["seed"].as<int>());
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:45:12 +08:00
|
|
|
if (vm.count("randomize-seed")) {
|
|
|
|
srand(time(NULL));
|
|
|
|
int r;
|
|
|
|
do {
|
|
|
|
r = rand();
|
2018-11-22 01:08:45 +08:00
|
|
|
} while (r == 0);
|
2018-11-20 02:45:12 +08:00
|
|
|
ctx->rngseed(r);
|
|
|
|
}
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
if (vm.count("slack_redist_iter")) {
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("slack_redist_iter")] = vm["slack_redist_iter"].as<int>();
|
2018-08-05 22:13:34 +08:00
|
|
|
if (vm.count("freq") && vm["freq"].as<double>() == 0) {
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("auto_freq")] = true;
|
2018-08-05 22:13:34 +08:00
|
|
|
#ifndef NO_GUI
|
|
|
|
if (!vm.count("gui"))
|
|
|
|
#endif
|
|
|
|
log_warning("Target frequency not specified. Will optimise for max frequency.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-14 21:06:00 +08:00
|
|
|
if (vm.count("ignore-loops")) {
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("timing/ignoreLoops")] = true;
|
2018-12-14 21:06:00 +08:00
|
|
|
}
|
|
|
|
|
2019-03-04 19:29:19 +08:00
|
|
|
if (vm.count("timing-allow-fail")) {
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("timing/allowFail")] = true;
|
2019-03-04 19:29:19 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 19:10:20 +08:00
|
|
|
if (vm.count("placer")) {
|
|
|
|
std::string placer = vm["placer"].as<std::string>();
|
|
|
|
if (std::find(Arch::availablePlacers.begin(), Arch::availablePlacers.end(), placer) ==
|
|
|
|
Arch::availablePlacers.end())
|
|
|
|
log_error("Placer algorithm '%s' is not supported (available options: %s)\n", placer.c_str(),
|
|
|
|
boost::algorithm::join(Arch::availablePlacers, ", ").c_str());
|
2019-06-15 19:09:49 +08:00
|
|
|
ctx->settings[ctx->id("placer")] = placer;
|
2019-03-24 19:10:20 +08:00
|
|
|
}
|
|
|
|
|
2020-02-03 19:54:38 +08:00
|
|
|
if (vm.count("router")) {
|
|
|
|
std::string router = vm["router"].as<std::string>();
|
|
|
|
if (std::find(Arch::availableRouters.begin(), Arch::availableRouters.end(), router) ==
|
|
|
|
Arch::availableRouters.end())
|
|
|
|
log_error("Router algorithm '%s' is not supported (available options: %s)\n", router.c_str(),
|
|
|
|
boost::algorithm::join(Arch::availableRouters, ", ").c_str());
|
|
|
|
ctx->settings[ctx->id("router")] = router;
|
|
|
|
}
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
if (vm.count("cstrweight")) {
|
2019-06-15 19:09:49 +08:00
|
|
|
ctx->settings[ctx->id("placer1/constraintWeight")] = std::to_string(vm["cstrweight"].as<float>());
|
2018-08-05 22:13:34 +08:00
|
|
|
}
|
2018-12-11 02:53:21 +08:00
|
|
|
if (vm.count("starttemp")) {
|
2019-06-15 19:09:49 +08:00
|
|
|
ctx->settings[ctx->id("placer1/startTemp")] = std::to_string(vm["starttemp"].as<float>());
|
2018-12-11 02:53:21 +08:00
|
|
|
}
|
2018-08-05 22:13:34 +08:00
|
|
|
|
2018-12-08 21:59:10 +08:00
|
|
|
if (vm.count("placer-budgets")) {
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("placer1/budgetBased")] = true;
|
2018-12-08 21:59:10 +08:00
|
|
|
}
|
2018-08-05 22:13:34 +08:00
|
|
|
if (vm.count("freq")) {
|
|
|
|
auto freq = vm["freq"].as<double>();
|
|
|
|
if (freq > 0)
|
2019-06-15 21:23:51 +08:00
|
|
|
ctx->settings[ctx->id("target_freq")] = std::to_string(freq * 1e6);
|
2018-08-05 22:13:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("no-tmdriv"))
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("timing_driven")] = false;
|
2019-06-14 00:39:16 +08:00
|
|
|
|
2019-06-15 21:23:51 +08:00
|
|
|
// Setting default values
|
|
|
|
if (ctx->settings.find(ctx->id("target_freq")) == ctx->settings.end())
|
|
|
|
ctx->settings[ctx->id("target_freq")] = std::to_string(12e6);
|
|
|
|
if (ctx->settings.find(ctx->id("timing_driven")) == ctx->settings.end())
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("timing_driven")] = true;
|
2019-06-15 21:23:51 +08:00
|
|
|
if (ctx->settings.find(ctx->id("slack_redist_iter")) == ctx->settings.end())
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("slack_redist_iter")] = 0;
|
2019-06-15 21:23:51 +08:00
|
|
|
if (ctx->settings.find(ctx->id("auto_freq")) == ctx->settings.end())
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("auto_freq")] = false;
|
2019-06-26 00:19:25 +08:00
|
|
|
if (ctx->settings.find(ctx->id("placer")) == ctx->settings.end())
|
2019-06-15 21:35:23 +08:00
|
|
|
ctx->settings[ctx->id("placer")] = Arch::defaultPlacer;
|
2020-02-03 19:54:38 +08:00
|
|
|
if (ctx->settings.find(ctx->id("router")) == ctx->settings.end())
|
|
|
|
ctx->settings[ctx->id("router")] = Arch::defaultRouter;
|
2019-06-15 21:35:23 +08:00
|
|
|
|
2019-06-15 19:09:49 +08:00
|
|
|
ctx->settings[ctx->id("arch.name")] = std::string(ctx->archId().c_str(ctx));
|
|
|
|
ctx->settings[ctx->id("arch.type")] = std::string(ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
|
2019-08-01 21:28:21 +08:00
|
|
|
ctx->settings[ctx->id("seed")] = ctx->rngstate;
|
2018-08-05 22:13:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CommandHandler::executeMain(std::unique_ptr<Context> ctx)
|
|
|
|
{
|
|
|
|
if (vm.count("test")) {
|
|
|
|
ctx->archcheck();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NO_GUI
|
|
|
|
if (vm.count("gui")) {
|
2019-05-25 14:42:17 +08:00
|
|
|
Application a(argc, argv, (vm.count("gui-no-aa") > 0));
|
2019-06-14 21:18:35 +08:00
|
|
|
MainWindow w(std::move(ctx), this);
|
2018-08-05 22:13:34 +08:00
|
|
|
try {
|
|
|
|
if (vm.count("json")) {
|
|
|
|
std::string filename = vm["json"].as<std::string>();
|
|
|
|
std::ifstream f(filename);
|
2019-11-16 01:59:42 +08:00
|
|
|
if (!parse_json(f, filename, w.getContext()))
|
|
|
|
log_error("Loading design failed.\n");
|
2018-08-05 22:13:34 +08:00
|
|
|
customAfterLoad(w.getContext());
|
2019-06-01 16:27:01 +08:00
|
|
|
w.notifyChangeContext();
|
2019-06-14 17:14:18 +08:00
|
|
|
w.updateActions();
|
2018-08-09 03:15:54 +08:00
|
|
|
} else
|
|
|
|
w.notifyChangeContext();
|
2018-08-05 22:13:34 +08:00
|
|
|
} catch (log_execution_error_exception) {
|
|
|
|
// show error is handled by gui itself
|
|
|
|
}
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (vm.count("json")) {
|
|
|
|
std::string filename = vm["json"].as<std::string>();
|
|
|
|
std::ifstream f(filename);
|
2019-11-16 01:59:42 +08:00
|
|
|
if (!parse_json(f, filename, ctx.get()))
|
|
|
|
log_error("Loading design failed.\n");
|
2018-08-05 22:13:34 +08:00
|
|
|
|
|
|
|
customAfterLoad(ctx.get());
|
2018-08-07 01:32:17 +08:00
|
|
|
}
|
2018-08-05 22:13:34 +08:00
|
|
|
|
2018-10-17 17:51:23 +08:00
|
|
|
#ifndef NO_PYTHON
|
|
|
|
init_python(argv[0], true);
|
|
|
|
python_export_global("ctx", *ctx);
|
|
|
|
|
|
|
|
if (vm.count("run")) {
|
|
|
|
|
|
|
|
std::vector<std::string> files = vm["run"].as<std::vector<std::string>>();
|
|
|
|
for (auto filename : files)
|
|
|
|
execute_python_file(filename.c_str());
|
|
|
|
} else
|
|
|
|
#endif
|
2019-06-26 00:19:25 +08:00
|
|
|
if (vm.count("json")) {
|
|
|
|
bool do_pack = vm.count("pack-only") != 0 || vm.count("no-pack") == 0;
|
|
|
|
bool do_place = vm.count("pack-only") == 0 && vm.count("no-place") == 0;
|
|
|
|
bool do_route = vm.count("pack-only") == 0 && vm.count("no-route") == 0;
|
2019-06-02 15:13:19 +08:00
|
|
|
|
|
|
|
if (do_pack) {
|
|
|
|
run_script_hook("pre-pack");
|
|
|
|
if (!ctx->pack() && !ctx->force)
|
|
|
|
log_error("Packing design failed.\n");
|
2019-06-26 00:19:25 +08:00
|
|
|
}
|
2019-06-02 16:01:20 +08:00
|
|
|
assign_budget(ctx.get());
|
|
|
|
ctx->check();
|
|
|
|
print_utilisation(ctx.get());
|
|
|
|
|
2019-06-02 15:13:19 +08:00
|
|
|
if (do_place) {
|
|
|
|
run_script_hook("pre-place");
|
2018-08-05 22:13:34 +08:00
|
|
|
if (!ctx->place() && !ctx->force)
|
|
|
|
log_error("Placing design failed.\n");
|
|
|
|
ctx->check();
|
2019-06-02 15:13:19 +08:00
|
|
|
}
|
2018-10-17 17:51:23 +08:00
|
|
|
|
2019-06-02 15:13:19 +08:00
|
|
|
if (do_route) {
|
|
|
|
run_script_hook("pre-route");
|
2018-08-05 22:13:34 +08:00
|
|
|
if (!ctx->route() && !ctx->force)
|
|
|
|
log_error("Routing design failed.\n");
|
2019-06-02 15:13:19 +08:00
|
|
|
run_script_hook("post-route");
|
2018-08-05 22:13:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
customBitstream(ctx.get());
|
|
|
|
}
|
|
|
|
|
2019-06-26 00:19:25 +08:00
|
|
|
if (vm.count("write")) {
|
2019-05-31 17:09:13 +08:00
|
|
|
std::string filename = vm["write"].as<std::string>();
|
|
|
|
std::ofstream f(filename);
|
|
|
|
if (!write_json_file(f, filename, ctx.get()))
|
2019-06-02 14:50:48 +08:00
|
|
|
log_error("Saving design failed.\n");
|
2019-05-31 17:09:13 +08:00
|
|
|
}
|
2018-08-07 01:32:17 +08:00
|
|
|
|
2019-10-19 23:52:47 +08:00
|
|
|
if (vm.count("sdf")) {
|
|
|
|
std::string filename = vm["sdf"].as<std::string>();
|
|
|
|
std::ofstream f(filename);
|
|
|
|
if (!f)
|
|
|
|
log_error("Failed to open SDF file '%s' for writing.\n", filename.c_str());
|
2019-10-24 19:37:07 +08:00
|
|
|
ctx->writeSDF(f, vm.count("sdf-cvc"));
|
2019-10-19 23:52:47 +08:00
|
|
|
}
|
|
|
|
|
2018-10-17 17:51:23 +08:00
|
|
|
#ifndef NO_PYTHON
|
|
|
|
deinit_python();
|
|
|
|
#endif
|
|
|
|
|
2018-11-26 17:22:42 +08:00
|
|
|
return had_nonfatal_error ? 1 : 0;
|
2018-08-05 22:13:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandHandler::conflicting_options(const boost::program_options::variables_map &vm, const char *opt1,
|
|
|
|
const char *opt2)
|
|
|
|
{
|
|
|
|
if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) && !vm[opt2].defaulted()) {
|
|
|
|
std::string msg = "Conflicting options '" + std::string(opt1) + "' and '" + std::string(opt2) + "'.";
|
|
|
|
log_error("%s\n", msg.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 03:14:38 +08:00
|
|
|
void CommandHandler::printFooter()
|
|
|
|
{
|
2018-12-06 02:58:38 +08:00
|
|
|
int warning_count = get_or_default(message_count_by_level, LogLevel::WARNING_MSG, 0),
|
|
|
|
error_count = get_or_default(message_count_by_level, LogLevel::ERROR_MSG, 0);
|
2018-11-27 03:14:38 +08:00
|
|
|
if (warning_count > 0 || error_count > 0)
|
|
|
|
log_always("%d warning%s, %d error%s\n", warning_count, warning_count == 1 ? "" : "s", error_count,
|
|
|
|
error_count == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
int CommandHandler::exec()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (!parseOptions())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (executeBeforeContext())
|
|
|
|
return 0;
|
2018-08-09 00:17:34 +08:00
|
|
|
|
2019-06-26 00:19:25 +08:00
|
|
|
std::unordered_map<std::string, Property> values;
|
2019-06-14 02:42:11 +08:00
|
|
|
std::unique_ptr<Context> ctx = createContext(values);
|
2018-08-05 22:13:34 +08:00
|
|
|
setupContext(ctx.get());
|
|
|
|
setupArchContext(ctx.get());
|
2018-11-27 03:14:38 +08:00
|
|
|
int rc = executeMain(std::move(ctx));
|
|
|
|
printFooter();
|
|
|
|
return rc;
|
2018-08-05 22:13:34 +08:00
|
|
|
} catch (log_execution_error_exception) {
|
2018-11-27 03:14:38 +08:00
|
|
|
printFooter();
|
2018-08-05 22:13:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 21:18:35 +08:00
|
|
|
std::unique_ptr<Context> CommandHandler::load_json(std::string filename)
|
|
|
|
{
|
|
|
|
vm.clear();
|
2019-06-26 00:19:25 +08:00
|
|
|
std::unordered_map<std::string, Property> values;
|
2019-06-14 21:18:35 +08:00
|
|
|
std::unique_ptr<Context> ctx = createContext(values);
|
|
|
|
setupContext(ctx.get());
|
|
|
|
setupArchContext(ctx.get());
|
|
|
|
{
|
|
|
|
std::ifstream f(filename);
|
2019-11-27 20:11:18 +08:00
|
|
|
if (!parse_json(f, filename, ctx.get()))
|
2019-06-14 21:18:35 +08:00
|
|
|
log_error("Loading design failed.\n");
|
|
|
|
}
|
|
|
|
customAfterLoad(ctx.get());
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2018-10-17 17:51:23 +08:00
|
|
|
void CommandHandler::run_script_hook(const std::string &name)
|
|
|
|
{
|
|
|
|
#ifndef NO_PYTHON
|
|
|
|
if (vm.count(name)) {
|
|
|
|
std::vector<std::string> files = vm[name].as<std::vector<std::string>>();
|
|
|
|
for (auto filename : files)
|
|
|
|
execute_python_file(filename.c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-05 22:13:34 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|