From 3bb9a7df01a03a31be87da719e0ee4bd4c38d5fd Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 5 Aug 2018 16:13:34 +0200 Subject: Added command parser and common implementation --- generic/main.cc | 136 +++++++++++++------------------------------------------- 1 file changed, 30 insertions(+), 106 deletions(-) (limited to 'generic') diff --git a/generic/main.cc b/generic/main.cc index 8653da01..412a28ac 100644 --- a/generic/main.cc +++ b/generic/main.cc @@ -19,123 +19,47 @@ #ifdef MAIN_EXECUTABLE -#ifndef NO_GUI -#include -#include "application.h" -#include "mainwindow.h" -#endif -#ifndef NO_PYTHON -#include "pybindings.h" -#endif -#include -#include -#include +#include +#include "command.h" +#include "design_utils.h" #include "log.h" -#include "nextpnr.h" -#include "version.h" +#include "timing.h" USING_NEXTPNR_NAMESPACE -int main(int argc, char *argv[]) +class GenericCommandHandler : public CommandHandler { - try { - - namespace po = boost::program_options; - int rc = 0; - - log_files.push_back(stdout); - - po::options_description options("Allowed options"); - options.add_options()("help,h", "show help"); - options.add_options()("verbose,v", "verbose output"); - options.add_options()("force,f", "keep running after errors"); -#ifndef NO_GUI - options.add_options()("gui", "start gui"); -#endif - - po::positional_options_description pos; -#ifndef NO_PYTHON - options.add_options()("run", po::value>(), "python file to execute"); - pos.add("run", -1); -#endif - options.add_options()("version,V", "show version"); - - po::variables_map vm; - try { - po::parsed_options parsed = po::command_line_parser(argc, argv).options(options).positional(pos).run(); - - po::store(parsed, vm); - - po::notify(vm); - } - - catch (std::exception &e) { - std::cout << e.what() << "\n"; - return 1; - } - - if (vm.count("help") || argc == 1) { - std::cout << boost::filesystem::basename(argv[0]) - << " -- Next Generation Place and Route (git " - "sha1 " GIT_COMMIT_HASH_STR ")\n"; - std::cout << "\n"; - std::cout << options << "\n"; - return argc != 1; - } + public: + GenericCommandHandler(int argc, char **argv); + virtual ~GenericCommandHandler(){}; + std::unique_ptr createContext() override; + void setupArchContext(Context *ctx) override{}; + void customBitstream(Context *ctx) override; - if (vm.count("version")) { - std::cout << boost::filesystem::basename(argv[0]) - << " -- Next Generation Place and Route (git " - "sha1 " GIT_COMMIT_HASH_STR ")\n"; - return 1; - } + protected: + po::options_description getArchOptions(); +}; - ArchArgs chipArgs{}; - std::unique_ptr ctx = std::unique_ptr(new Context(chipArgs)); +GenericCommandHandler::GenericCommandHandler(int argc, char **argv) : CommandHandler(argc, argv) {} - if (vm.count("verbose")) { - ctx->verbose = true; - } - - if (vm.count("force")) { - ctx->force = true; - } - - if (vm.count("seed")) { - ctx->rngseed(vm["seed"].as()); - } - -#ifndef NO_GUI - if (vm.count("gui")) { - Application a(argc, argv); - MainWindow w(std::move(ctx), chipArgs); - w.show(); - - return a.exec(); - } -#endif - -#ifndef NO_PYTHON - if (vm.count("run")) { - init_python(argv[0], true); - python_export_global("ctx", *ctx.get()); +po::options_description GenericCommandHandler::getArchOptions() +{ + po::options_description specific("Architecture specific options"); + specific.add_options()("generic", "set device type to generic"); + return specific; +} - std::vector files = vm["run"].as>(); - for (auto filename : files) - execute_python_file(filename.c_str()); +void GenericCommandHandler::customBitstream(Context *ctx) { log_error("Here is when bitstream gets created"); } - deinit_python(); - } -#endif +std::unique_ptr GenericCommandHandler::createContext() +{ + return std::unique_ptr(new Context(chipArgs)); +} - return rc; - } catch (log_execution_error_exception) { -#if defined(_MSC_VER) - _exit(EXIT_FAILURE); -#else - _Exit(EXIT_FAILURE); -#endif - } +int main(int argc, char *argv[]) +{ + GenericCommandHandler handler(argc, argv); + return handler.exec(); } #endif -- cgit v1.2.3