From aa6c308eaa085c07cfca4749ac5ebfc6e09dbddf Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sat, 15 Jun 2019 20:23:01 +0000 Subject: [PATCH] Enhanced CLI parsing to allow non-option values --- ...aunch => riscv-sim Debug hello gdb.launch} | 0 ... => riscv-sim Debug hello w plugin.launch} | 0 etc/riscv-sim Debug hello.launch | 42 +++++++++++++++++++ etc/riscv-vp Debug hello.launch | 42 +++++++++++++++++++ platform/src/CLIParser.cpp | 22 +++++++++- platform/src/sc_main.cpp | 8 +++- scc | 2 +- 7 files changed, 113 insertions(+), 3 deletions(-) rename etc/{dbt-riscv Debug hello gdb.launch => riscv-sim Debug hello gdb.launch} (100%) rename etc/{dbt-riscv Debug hello w plugin.launch => riscv-sim Debug hello w plugin.launch} (100%) create mode 100644 etc/riscv-sim Debug hello.launch create mode 100644 etc/riscv-vp Debug hello.launch diff --git a/etc/dbt-riscv Debug hello gdb.launch b/etc/riscv-sim Debug hello gdb.launch similarity index 100% rename from etc/dbt-riscv Debug hello gdb.launch rename to etc/riscv-sim Debug hello gdb.launch diff --git a/etc/dbt-riscv Debug hello w plugin.launch b/etc/riscv-sim Debug hello w plugin.launch similarity index 100% rename from etc/dbt-riscv Debug hello w plugin.launch rename to etc/riscv-sim Debug hello w plugin.launch diff --git a/etc/riscv-sim Debug hello.launch b/etc/riscv-sim Debug hello.launch new file mode 100644 index 0000000..b16d31e --- /dev/null +++ b/etc/riscv-sim Debug hello.launch @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/riscv-vp Debug hello.launch b/etc/riscv-vp Debug hello.launch new file mode 100644 index 0000000..541eda7 --- /dev/null +++ b/etc/riscv-vp Debug hello.launch @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/src/CLIParser.cpp b/platform/src/CLIParser.cpp index e4d74f7..c388744 100644 --- a/platform/src/CLIParser.cpp +++ b/platform/src/CLIParser.cpp @@ -49,7 +49,27 @@ CLIParser::CLIParser(int argc, char *argv[]) build(); try { - po::store(po::parse_command_line(argc, argv, desc), vm_); // can throw + // Variant 1: no non-options + //po::store(po::parse_command_line(argc, argv, desc), vm_); // can throw + // Variant 2: collect unrecognized options + //auto parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + //po::store(parsed, vm_); // can throw + // Variant 3: collect options in string vector + po::options_description hidden; + hidden.add_options()("argv", po::value>(), "arguments"); + + po::options_description all_opt; + po::positional_options_description posopt; + po::store(po::command_line_parser(argc, argv). + options(all_opt.add(desc).add(hidden)). + //allow_unregistered(). + positional(posopt.add("argv", -1)). +// style( +// po::command_line_style::default_style | +// po::command_line_style::allow_slash_for_short). + run(), + vm_); // can throw + // --help option if (vm_.count("help")) { std::cout << "DBT-RISE-RiscV simulator for RISC-V" << std::endl << desc << std::endl; diff --git a/platform/src/sc_main.cpp b/platform/src/sc_main.cpp index 27c058a..24a9b67 100644 --- a/platform/src/sc_main.cpp +++ b/platform/src/sc_main.cpp @@ -108,7 +108,13 @@ int sc_main(int argc, char *argv[]) { /////////////////////////////////////////////////////////////////////////// cfg.set_value("i_system.i_hifive1.i_fe310.i_core_complex.gdb_server_port", parser.get("gdb-port")); cfg.set_value("i_system.i_hifive1.i_fe310.i_core_complex.dump_ir", parser.is_set("dump-ir")); - if (parser.is_set("elf")) cfg.set_value("i_system.i_hifive1.i_fe310.i_core_complex.elf_file", parser.get("elf")); + if (parser.is_set("elf")) + cfg.set_value("i_system.i_hifive1.i_fe310.i_core_complex.elf_file", parser.get("elf")); + else { + auto args = parser.get>("argv"); + if(args.size()) + cfg.set_value("i_system.i_hifive1.i_fe310.i_core_complex.elf_file", args[0]); + } if (parser.is_set("quantum")) tlm::tlm_global_quantum::instance().set(sc_core::sc_time(parser.get("quantum"), sc_core::SC_NS)); if (parser.is_set("reset")) { diff --git a/scc b/scc index e0d61e7..c602fc8 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit e0d61e70ed65a582b348dea473ca05130f4baa34 +Subproject commit c602fc83b0e0e7eed8ed219bff18737d859bd460