From 8be05e61a7e24ff4c0d44b1e5bb0c29aef4c9b2b Mon Sep 17 00:00:00 2001 From: Marc Emery Date: Fri, 13 Feb 2026 20:40:18 +0100 Subject: [PATCH] gatemate: improve mode arg error message --- himbaechel/uarch/gatemate/gatemate.cc | 55 ++++++++++++++++++++------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/himbaechel/uarch/gatemate/gatemate.cc b/himbaechel/uarch/gatemate/gatemate.cc index bee44ad9..286470df 100644 --- a/himbaechel/uarch/gatemate/gatemate.cc +++ b/himbaechel/uarch/gatemate/gatemate.cc @@ -32,32 +32,64 @@ NEXTPNR_NAMESPACE_BEGIN GateMateImpl::~GateMateImpl() {}; +static const std::vector> timing_mode_array = {{{1, "best"}, {2, "typical"}, {3, "worst"}}}; +static const std::vector> fpga_mode_array = { + {{1, "lowpower"}, {2, "economy"}, {3, "speed"}}}; + +static std::string mode_array_to_values_str(const std::vector> &array, + std::string separator) +{ + std::ostringstream s; + bool first = true; + for (const auto &pair : array) { + s << (first ? "" : separator) << pair.first << separator << pair.second; + first = false; + } + return s.str(); +} + po::options_description GateMateImpl::getUArchOptions() { + std::string fpga_mode_description = "operation mode (" + mode_array_to_values_str(fpga_mode_array, ", ") + ")"; + std::string time_mode_description = "timing mode (" + mode_array_to_values_str(timing_mode_array, ", ") + ")"; + po::options_description specific("GateMate specific options"); specific.add_options()("out", po::value(), "textual configuration bitstream output file"); specific.add_options()("ccf", po::value(), "name of constraints file"); specific.add_options()("allow-unconstrained", "allow unconstrained IOs"); - specific.add_options()("fpga_mode", po::value(), "operation mode (1:lowpower, 2:economy, 3:speed)"); - specific.add_options()("time_mode", po::value(), "timing mode (1:best, 2:typical, 3:worst)"); + specific.add_options()("fpga_mode", po::value(), fpga_mode_description.c_str()); + specific.add_options()("time_mode", po::value(), time_mode_description.c_str()); specific.add_options()("strategy", po::value(), "multi-die clock placement strategy (mirror, full or clk1)"); specific.add_options()("force_die", po::value(), "force specific die (example 1A,1B...)"); return specific; } -static int parse_mode(const std::string &val, const std::map &map, const char *error_msg) +static int parse_mode(const std::string &val, const std::vector> &array, + const char *error_msg) { try { int i = std::stoi(val); if (i >= 1 && i <= 3) return i; } catch (...) { - auto it = map.find(val); - if (it != map.end()) - return it->second; + + for (const auto &pair : array) { + if (pair.second == val) { + return pair.first; + } + } } - log_error("%s\n", error_msg); + std::ostringstream full_error_msg; + full_error_msg << error_msg << ": '" << val << "' is not valid. Valid values are: "; + bool first = true; + for (const auto &pair : array) { + full_error_msg << (first ? "'" : ", '") << pair.first << "', '" << pair.second << "'"; + first = false; + } + std::string modes = mode_array_to_values_str(array, "', '"); + + log_error("%s: '%s' is not valid. Valid values are: '%s'\n", error_msg, val.c_str(), modes.c_str()); } void GateMateImpl::init_database(Arch *arch) @@ -70,15 +102,10 @@ void GateMateImpl::init_database(Arch *arch) fpga_mode = 3; timing_mode = 3; - static const std::map fpga_map = {{"lowpower", 1}, {"economy", 2}, {"speed", 3}}; - static const std::map timing_map = {{"best", 1}, {"typical", 2}, {"worst", 3}}; - if (args.options.count("fpga_mode")) - fpga_mode = parse_mode(args.options["fpga_mode"].as(), fpga_map, - "operation mode valid values are {1:lowpower, 2:economy, 3:speed}"); + fpga_mode = parse_mode(args.options["fpga_mode"].as(), fpga_mode_array, "invalid fpga_mode"); if (args.options.count("time_mode")) - timing_mode = parse_mode(args.options["time_mode"].as(), timing_map, - "timing mode valid values are {1:best, 2:typical, 3:worst}"); + timing_mode = parse_mode(args.options["time_mode"].as(), timing_mode_array, "invalid time_mode"); std::string speed_grade = ""; switch (timing_mode) {