aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-10-21 10:08:04 +0100
committerGitHub <noreply@github.com>2018-10-21 10:08:04 +0100
commitcdc9e0e81cb234c2cbc3dfcf6c4570e823595fab (patch)
treef8790747172727fd8d3609785a096c6d780d58db /common
parentb53a4862db99e41f16c06425f314a1a398a21985 (diff)
parent7c9ab173da50dce5abfe5a28da4dc49816216537 (diff)
downloadnextpnr-cdc9e0e81cb234c2cbc3dfcf6c4570e823595fab.tar.gz
nextpnr-cdc9e0e81cb234c2cbc3dfcf6c4570e823595fab.tar.bz2
nextpnr-cdc9e0e81cb234c2cbc3dfcf6c4570e823595fab.zip
Merge pull request #92 from YosysHQ/python-cmdline
Allow running Python scripts for all points in flow
Diffstat (limited to 'common')
-rw-r--r--common/command.cc55
-rw-r--r--common/command.h1
2 files changed, 41 insertions, 15 deletions
diff --git a/common/command.cc b/common/command.cc
index ab0c92f2..c5c777e8 100644
--- a/common/command.cc
+++ b/common/command.cc
@@ -91,8 +91,14 @@ po::options_description CommandHandler::getGeneralOptions()
general.add_options()("gui", "start gui");
#endif
#ifndef NO_PYTHON
- general.add_options()("run", po::value<std::vector<std::string>>(), "python file to execute");
+ general.add_options()("run", po::value<std::vector<std::string>>(),
+ "python file to execute instead of default flow");
pos.add("run", -1);
+ 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");
+
#endif
general.add_options()("json", po::value<std::string>(), "JSON design file to ingest");
general.add_options()("seed", po::value<int>(), "seed value for random number generator");
@@ -200,40 +206,48 @@ int CommandHandler::executeMain(std::unique_ptr<Context> ctx)
customAfterLoad(ctx.get());
}
- if (vm.count("json") || vm.count("load")) {
+#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
+ if (vm.count("json") || vm.count("load")) {
+ run_script_hook("pre-pack");
if (!ctx->pack() && !ctx->force)
log_error("Packing design failed.\n");
assign_budget(ctx.get());
ctx->check();
print_utilisation(ctx.get());
+ run_script_hook("pre-place");
+
if (!vm.count("pack-only")) {
if (!ctx->place() && !ctx->force)
log_error("Placing design failed.\n");
ctx->check();
+ run_script_hook("pre-route");
+
if (!ctx->route() && !ctx->force)
log_error("Routing design failed.\n");
}
+ run_script_hook("post-route");
customBitstream(ctx.get());
}
-#ifndef NO_PYTHON
- if (vm.count("run")) {
- init_python(argv[0], true);
- python_export_global("ctx", *ctx);
-
- std::vector<std::string> files = vm["run"].as<std::vector<std::string>>();
- for (auto filename : files)
- execute_python_file(filename.c_str());
-
- deinit_python();
- }
-#endif
-
if (vm.count("save")) {
project.save(ctx.get(), vm["save"].as<std::string>());
}
+#ifndef NO_PYTHON
+ deinit_python();
+#endif
+
return 0;
}
@@ -270,4 +284,15 @@ int CommandHandler::exec()
}
}
+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
+}
+
NEXTPNR_NAMESPACE_END
diff --git a/common/command.h b/common/command.h
index 900cf74b..12f710f6 100644
--- a/common/command.h
+++ b/common/command.h
@@ -53,6 +53,7 @@ class CommandHandler
void setupContext(Context *ctx);
int executeMain(std::unique_ptr<Context> ctx);
po::options_description getGeneralOptions();
+ void run_script_hook(const std::string &name);
protected:
po::variables_map vm;