From 276136cd5029111adcaaf28c0fedc8de8954f41d Mon Sep 17 00:00:00 2001 From: Dhaval Chaudhari Date: Tue, 20 Jan 2026 16:05:27 +0530 Subject: [PATCH 1/7] Add Yosys-Verific settings management Introduce a new structure for managing Yosys-Verific settings, allowing users to get, set, and reset options related to Verific integration. Implement options for ignoring translate pragmas and specifying file extensions for SystemVerilog. Update command-line interface to support these settings, including help documentation for usage examples. --- frontends/verific/verific.cc | 305 +++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 5790e92f0..b99ea8f2f 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -114,6 +114,168 @@ int verific_sva_fsm_limit; vector verific_incdirs, verific_libdirs, verific_libexts; #endif +struct YosysVerificSettings { + enum class Type { BOOL, STRING, STRING_LIST }; + + struct Option { + Type type; + bool bool_value; + std::string string_value; + std::vector string_list_value; + bool default_bool; + std::string default_string; + std::vector default_string_list; + std::string description; + bool available; + }; + + std::map options; + + void init() { +#ifdef VERIFIC_SYSTEMVERILOG_SUPPORT + // Bool option example: ignore_translate_off + // When true, translate_off/translate_on pragmas are ignored + { + Option opt; + opt.type = Type::BOOL; + opt.bool_value = false; + opt.default_bool = false; + opt.description = "Ignore translate_off/translate_on pragmas"; + opt.available = true; + options["ignore_translate_off"] = opt; + } + + // String-list option example: vlog_file_extensions + // Allows user to specify which file extensions should be treated as SystemVerilog + { + Option opt; + opt.type = Type::STRING_LIST; + opt.string_list_value = {".v", ".vh", ".sv", ".svh"}; + opt.default_string_list = {".v", ".vh", ".sv", ".svh"}; + opt.description = "Comma-separated Verilog/SystemVerilog file extensions"; + opt.available = true; + options["vlog_file_extensions"] = opt; + } +#endif + } + + void reset() { + for (auto &it : options) { + auto &opt = it.second; + switch (opt.type) { + case Type::BOOL: + opt.bool_value = opt.default_bool; + break; + case Type::STRING: + opt.string_value = opt.default_string; + break; + case Type::STRING_LIST: + opt.string_list_value = opt.default_string_list; + break; + } + } + } + + bool has_option(const std::string &name) const { + auto it = options.find(name); + return it != options.end() && it->second.available; + } + + bool get_bool(const std::string &name) const { + auto it = options.find(name); + if (it == options.end() || it->second.type != Type::BOOL) + return false; + return it->second.bool_value; + } + + std::string get_string(const std::string &name) const { + auto it = options.find(name); + if (it == options.end() || it->second.type != Type::STRING) + return ""; + return it->second.string_value; + } + + std::vector get_string_list(const std::string &name) const { + auto it = options.find(name); + if (it == options.end() || it->second.type != Type::STRING_LIST) + return {}; + return it->second.string_list_value; + } + + void set_bool(const std::string &name, bool value) { + auto it = options.find(name); + if (it != options.end() && it->second.type == Type::BOOL) + it->second.bool_value = value; + } + + void set_string(const std::string &name, const std::string &value) { + auto it = options.find(name); + if (it != options.end() && it->second.type == Type::STRING) + it->second.string_value = value; + } + + void set_string_list(const std::string &name, const std::vector &value) { + auto it = options.find(name); + if (it != options.end() && it->second.type == Type::STRING_LIST) + it->second.string_list_value = value; + } + + // Apply a setting to Verific APIs when changed + void apply_setting(const std::string &name) { +#ifdef VERIFIC_SYSTEMVERILOG_SUPPORT + if (name == "ignore_translate_off") { + veri_file::SetIgnoreTranslateOff(get_bool("ignore_translate_off") ? 1 : 0); + return; + } + if (name == "vlog_file_extensions") { + // Remove default .v extension and add user-specified ones + veri_file::RemoveFileExt(".v"); + for (const auto &ext : get_string_list("vlog_file_extensions")) { + veri_file::AddFileExtMode(ext.c_str(), veri_file::SYSTEM_VERILOG); + } + return; + } +#else + (void)name; +#endif + } + + // Parse comma-separated string into vector + static std::vector parse_string_list(const std::string &value) { + std::vector result; + size_t start = 0; + size_t end; + while ((end = value.find(',', start)) != std::string::npos) { + std::string item = value.substr(start, end - start); + // Trim whitespace + size_t first = item.find_first_not_of(" \t"); + size_t last = item.find_last_not_of(" \t"); + if (first != std::string::npos) + result.push_back(item.substr(first, last - first + 1)); + start = end + 1; + } + std::string item = value.substr(start); + size_t first = item.find_first_not_of(" \t"); + size_t last = item.find_last_not_of(" \t"); + if (first != std::string::npos) + result.push_back(item.substr(first, last - first + 1)); + return result; + } + + // Format vector as comma-separated string + static std::string format_string_list(const std::vector &list) { + std::string result; + for (size_t i = 0; i < list.size(); i++) { + if (i > 0) result += ","; + result += list[i]; + } + return result; + } +}; + +static YosysVerificSettings yosys_verific_settings; +static bool yosys_verific_settings_initialized = false; + void msg_func(msg_type_t msg_type, const char *message_id, linefile_type linefile, const char *msg, va_list args) { string message_prefix = stringf("VERIFIC-%s [%s] ", @@ -3345,6 +3507,34 @@ struct VerificPass : public Pass { log("Get/set Verific runtime flags.\n"); log("\n"); log("\n"); + log(" verific -set [ []]\n"); + log("\n"); + log("Get/set Yosys-Verific settings. These are Yosys-specific options that control\n"); + log("how Verific integration behaves.\n"); + log("\n"); + log("Without arguments, lists all available settings and their current values.\n"); + log("With one argument, shows the current value of the specified setting.\n"); + log("With two arguments, sets the specified setting to the given value.\n"); + log("\n"); + log("Available settings:\n"); +#ifdef VERIFIC_SYSTEMVERILOG_SUPPORT + log(" ignore_translate_off (bool) Ignore translate_off/translate_on pragmas\n"); + log(" vlog_file_extensions (string-list) Verilog/SV file extensions for relaxed mode\n"); +#endif + log("\n"); + log("For boolean settings, use 0/1, true/false, on/off, yes/no.\n"); + log("For string-list settings, provide comma-separated values (e.g. \".v,.sv,.vh\").\n"); + log("\n"); + log("Example usage:\n"); + log(" verific -set ignore_translate_off true\n"); + log(" verific -set vlog_file_extensions \".v,.sv,.vh,.svh,.h,.inc\"\n"); + log("\n"); + log("\n"); + log(" verific -set-reset\n"); + log("\n"); + log("Reset all Yosys-Verific settings to their default values.\n"); + log("\n"); + log("\n"); #if defined(YOSYS_ENABLE_VERIFIC) and defined(YOSYSHQ_VERIFIC_EXTENSIONS) VerificExtensions::Help(); #endif @@ -3540,6 +3730,12 @@ struct VerificPass : public Pass { set_verific_global_flags = false; } + // Initialize Yosys-Verific settings if not done yet + if (!yosys_verific_settings_initialized) { + yosys_verific_settings.init(); + yosys_verific_settings_initialized = true; + } + verific_verbose = 0; verific_sva_fsm_limit = 16; @@ -4303,6 +4499,115 @@ struct VerificPass : public Pass { } } } + + if (argidx < GetSize(args) && args[argidx] == "-set-reset") + { + if (!yosys_verific_settings_initialized) { + yosys_verific_settings.init(); + yosys_verific_settings_initialized = true; + } + yosys_verific_settings.reset(); + log("All Yosys-Verific settings reset to defaults.\n"); + goto check_error; + } + + if (argidx < GetSize(args) && args[argidx] == "-set") + { + if (!yosys_verific_settings_initialized) { + yosys_verific_settings.init(); + yosys_verific_settings_initialized = true; + } + + // No arguments: list all settings + if (argidx+1 == GetSize(args)) { + log("Yosys-Verific settings:\n"); + for (const auto &it : yosys_verific_settings.options) { + if (!it.second.available) + continue; + const auto &name = it.first; + const auto &opt = it.second; + switch (opt.type) { + case YosysVerificSettings::Type::BOOL: + log(" %s = %s (bool, default: %s)\n", name.c_str(), + opt.bool_value ? "true" : "false", + opt.default_bool ? "true" : "false"); + break; + case YosysVerificSettings::Type::STRING: + log(" %s = \"%s\" (string, default: \"%s\")\n", name.c_str(), + opt.string_value.c_str(), + opt.default_string.c_str()); + break; + case YosysVerificSettings::Type::STRING_LIST: + log(" %s = \"%s\" (string-list, default: \"%s\")\n", name.c_str(), + YosysVerificSettings::format_string_list(opt.string_list_value).c_str(), + YosysVerificSettings::format_string_list(opt.default_string_list).c_str()); + break; + } + } + goto check_error; + } + + // One argument: show specific setting + if (argidx+2 == GetSize(args)) { + const std::string &name = args[argidx+1]; + if (!yosys_verific_settings.has_option(name)) + log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); + const auto &opt = yosys_verific_settings.options.at(name); + switch (opt.type) { + case YosysVerificSettings::Type::BOOL: + log("verific -set %s %s\n", name.c_str(), + opt.bool_value ? "true" : "false"); + break; + case YosysVerificSettings::Type::STRING: + log("verific -set %s \"%s\"\n", name.c_str(), + opt.string_value.c_str()); + break; + case YosysVerificSettings::Type::STRING_LIST: + log("verific -set %s \"%s\"\n", name.c_str(), + YosysVerificSettings::format_string_list(opt.string_list_value).c_str()); + break; + } + goto check_error; + } + + // Two arguments: set specific setting + if (argidx+3 == GetSize(args)) { + const std::string &name = args[argidx+1]; + const std::string &value = args[argidx+2]; + if (!yosys_verific_settings.has_option(name)) + log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); + auto &opt = yosys_verific_settings.options.at(name); + switch (opt.type) { + case YosysVerificSettings::Type::BOOL: { + bool bval; + if (value == "1" || value == "true" || value == "on" || value == "yes") + bval = true; + else if (value == "0" || value == "false" || value == "off" || value == "no") + bval = false; + else + log_cmd_error("Invalid boolean value '%s'. Use 0/1, true/false, on/off, or yes/no.\n", value.c_str()); + yosys_verific_settings.set_bool(name, bval); + log("Setting '%s' = %s\n", name.c_str(), bval ? "true" : "false"); + break; + } + case YosysVerificSettings::Type::STRING: + yosys_verific_settings.set_string(name, value); + log("Setting '%s' = \"%s\"\n", name.c_str(), value.c_str()); + break; + case YosysVerificSettings::Type::STRING_LIST: { + auto list = YosysVerificSettings::parse_string_list(value); + yosys_verific_settings.set_string_list(name, list); + log("Setting '%s' = \"%s\"\n", name.c_str(), + YosysVerificSettings::format_string_list(list).c_str()); + break; + } + } + // Apply the setting to Verific APIs + yosys_verific_settings.apply_setting(name); + goto check_error; + } + } + #ifdef YOSYSHQ_VERIFIC_EXTENSIONS if (VerificExtensions::Execute(args, argidx, work, [this](const std::vector &args, size_t argidx, std::string msg) From bd710134fcbeee3c79d11bbc56e9d9adfee6e4fe Mon Sep 17 00:00:00 2001 From: Dhaval Chaudhari Date: Tue, 20 Jan 2026 18:14:02 +0530 Subject: [PATCH 2/7] Refactor Yosys-Verific settings structure --- frontends/verific/verific.cc | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index b99ea8f2f..7f155aa6d 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -126,7 +126,6 @@ struct YosysVerificSettings { std::string default_string; std::vector default_string_list; std::string description; - bool available; }; std::map options; @@ -138,10 +137,8 @@ struct YosysVerificSettings { { Option opt; opt.type = Type::BOOL; - opt.bool_value = false; opt.default_bool = false; opt.description = "Ignore translate_off/translate_on pragmas"; - opt.available = true; options["ignore_translate_off"] = opt; } @@ -150,13 +147,12 @@ struct YosysVerificSettings { { Option opt; opt.type = Type::STRING_LIST; - opt.string_list_value = {".v", ".vh", ".sv", ".svh"}; opt.default_string_list = {".v", ".vh", ".sv", ".svh"}; opt.description = "Comma-separated Verilog/SystemVerilog file extensions"; - opt.available = true; options["vlog_file_extensions"] = opt; } #endif + reset(); } void reset() { @@ -177,8 +173,7 @@ struct YosysVerificSettings { } bool has_option(const std::string &name) const { - auto it = options.find(name); - return it != options.end() && it->second.available; + return options.find(name) != options.end(); } bool get_bool(const std::string &name) const { @@ -3517,18 +3512,21 @@ struct VerificPass : public Pass { log("With two arguments, sets the specified setting to the given value.\n"); log("\n"); log("Available settings:\n"); -#ifdef VERIFIC_SYSTEMVERILOG_SUPPORT - log(" ignore_translate_off (bool) Ignore translate_off/translate_on pragmas\n"); - log(" vlog_file_extensions (string-list) Verilog/SV file extensions for relaxed mode\n"); -#endif + // Initialize settings to get option metadata + if (!yosys_verific_settings_initialized) { + yosys_verific_settings.init(); + yosys_verific_settings_initialized = true; + } + for (const auto &it : yosys_verific_settings.options) { + const char *type_str = + it.second.type == YosysVerificSettings::Type::BOOL ? "bool" : + it.second.type == YosysVerificSettings::Type::STRING ? "string" : "string-list"; + log(" %-20s (%s) %s\n", it.first.c_str(), type_str, it.second.description.c_str()); + } log("\n"); log("For boolean settings, use 0/1, true/false, on/off, yes/no.\n"); log("For string-list settings, provide comma-separated values (e.g. \".v,.sv,.vh\").\n"); log("\n"); - log("Example usage:\n"); - log(" verific -set ignore_translate_off true\n"); - log(" verific -set vlog_file_extensions \".v,.sv,.vh,.svh,.h,.inc\"\n"); - log("\n"); log("\n"); log(" verific -set-reset\n"); log("\n"); @@ -4522,8 +4520,6 @@ struct VerificPass : public Pass { if (argidx+1 == GetSize(args)) { log("Yosys-Verific settings:\n"); for (const auto &it : yosys_verific_settings.options) { - if (!it.second.available) - continue; const auto &name = it.first; const auto &opt = it.second; switch (opt.type) { From 75501ada55de05f59dfe901bf10958d5898a7500 Mon Sep 17 00:00:00 2001 From: Dhaval Chaudhari Date: Tue, 20 Jan 2026 19:26:12 +0530 Subject: [PATCH 3/7] remove option --- frontends/verific/verific.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 7f155aa6d..d9be43216 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -172,10 +172,6 @@ struct YosysVerificSettings { } } - bool has_option(const std::string &name) const { - return options.find(name) != options.end(); - } - bool get_bool(const std::string &name) const { auto it = options.find(name); if (it == options.end() || it->second.type != Type::BOOL) @@ -4546,7 +4542,7 @@ struct VerificPass : public Pass { // One argument: show specific setting if (argidx+2 == GetSize(args)) { const std::string &name = args[argidx+1]; - if (!yosys_verific_settings.has_option(name)) + if (!yosys_verific_settings.options.count(name)) log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); const auto &opt = yosys_verific_settings.options.at(name); switch (opt.type) { @@ -4570,7 +4566,7 @@ struct VerificPass : public Pass { if (argidx+3 == GetSize(args)) { const std::string &name = args[argidx+1]; const std::string &value = args[argidx+2]; - if (!yosys_verific_settings.has_option(name)) + if (!yosys_verific_settings.options.count(name)) log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); auto &opt = yosys_verific_settings.options.at(name); switch (opt.type) { From 6435b4a643cc1bc40b3e10a4053d1e9daff542b9 Mon Sep 17 00:00:00 2001 From: Dhaval Chaudhari Date: Fri, 20 Feb 2026 10:26:41 +0530 Subject: [PATCH 4/7] Add applied vlog extensions management and apply_all method Enhance YosysVerificSettings by introducing a vector to track applied SystemVerilog file extensions, ensuring stale mappings are removed before adding new extensions. Implement an apply_all method to apply all settings to Verific APIs after a reset, improving settings management and consistency. --- frontends/verific/verific.cc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index d9be43216..59848dcba 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -129,6 +129,7 @@ struct YosysVerificSettings { }; std::map options; + std::vector _applied_vlog_extensions; void init() { #ifdef VERIFIC_SYSTEMVERILOG_SUPPORT @@ -148,7 +149,7 @@ struct YosysVerificSettings { Option opt; opt.type = Type::STRING_LIST; opt.default_string_list = {".v", ".vh", ".sv", ".svh"}; - opt.description = "Comma-separated Verilog/SystemVerilog file extensions"; + opt.description = "Comma-separated SystemVerilog file extensions"; options["vlog_file_extensions"] = opt; } #endif @@ -219,11 +220,16 @@ struct YosysVerificSettings { return; } if (name == "vlog_file_extensions") { - // Remove default .v extension and add user-specified ones - veri_file::RemoveFileExt(".v"); - for (const auto &ext : get_string_list("vlog_file_extensions")) { + // Remove all previously applied extensions to avoid stale mappings + for (const auto &ext : _applied_vlog_extensions) { + veri_file::RemoveFileExt(ext.c_str()); + } + auto new_exts = get_string_list("vlog_file_extensions"); + for (const auto &ext : new_exts) { + veri_file::RemoveFileExt(ext.c_str()); veri_file::AddFileExtMode(ext.c_str(), veri_file::SYSTEM_VERILOG); } + _applied_vlog_extensions = new_exts; return; } #else @@ -231,6 +237,13 @@ struct YosysVerificSettings { #endif } + // Apply all settings to Verific APIs (used after reset) + void apply_all() { + for (const auto &it : options) { + apply_setting(it.first); + } + } + // Parse comma-separated string into vector static std::vector parse_string_list(const std::string &value) { std::vector result; @@ -4501,6 +4514,7 @@ struct VerificPass : public Pass { yosys_verific_settings_initialized = true; } yosys_verific_settings.reset(); + yosys_verific_settings.apply_all(); log("All Yosys-Verific settings reset to defaults.\n"); goto check_error; } @@ -4521,17 +4535,17 @@ struct VerificPass : public Pass { switch (opt.type) { case YosysVerificSettings::Type::BOOL: log(" %s = %s (bool, default: %s)\n", name.c_str(), - opt.bool_value ? "true" : "false", + yosys_verific_settings.get_bool(name) ? "true" : "false", opt.default_bool ? "true" : "false"); break; case YosysVerificSettings::Type::STRING: log(" %s = \"%s\" (string, default: \"%s\")\n", name.c_str(), - opt.string_value.c_str(), + yosys_verific_settings.get_string(name).c_str(), opt.default_string.c_str()); break; case YosysVerificSettings::Type::STRING_LIST: log(" %s = \"%s\" (string-list, default: \"%s\")\n", name.c_str(), - YosysVerificSettings::format_string_list(opt.string_list_value).c_str(), + YosysVerificSettings::format_string_list(yosys_verific_settings.get_string_list(name)).c_str(), YosysVerificSettings::format_string_list(opt.default_string_list).c_str()); break; } @@ -4548,15 +4562,15 @@ struct VerificPass : public Pass { switch (opt.type) { case YosysVerificSettings::Type::BOOL: log("verific -set %s %s\n", name.c_str(), - opt.bool_value ? "true" : "false"); + yosys_verific_settings.get_bool(name) ? "true" : "false"); break; case YosysVerificSettings::Type::STRING: log("verific -set %s \"%s\"\n", name.c_str(), - opt.string_value.c_str()); + yosys_verific_settings.get_string(name).c_str()); break; case YosysVerificSettings::Type::STRING_LIST: log("verific -set %s \"%s\"\n", name.c_str(), - YosysVerificSettings::format_string_list(opt.string_list_value).c_str()); + YosysVerificSettings::format_string_list(yosys_verific_settings.get_string_list(name)).c_str()); break; } goto check_error; From c5023dce7aece9b58968740ca051feac3abad0c0 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 23 Feb 2026 12:06:06 +0100 Subject: [PATCH 5/7] Use templates where applicable --- frontends/verific/verific.cc | 131 ++++++++++++++++------------------- 1 file changed, 59 insertions(+), 72 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 59848dcba..c3d95111d 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -116,16 +116,41 @@ vector verific_incdirs, verific_libdirs, verific_libexts; struct YosysVerificSettings { enum class Type { BOOL, STRING, STRING_LIST }; + template + struct OptionType; + + template<> + struct OptionType { + static constexpr Type value = Type::BOOL; + }; + + template<> + struct OptionType { + static constexpr Type value = Type::STRING; + }; + + template<> + struct OptionType> { + static constexpr Type value = Type::STRING_LIST; + }; + + using OptionValue = std::variant>; struct Option { Type type; - bool bool_value; - std::string string_value; - std::vector string_list_value; - bool default_bool; - std::string default_string; - std::vector default_string_list; + OptionValue value; + OptionValue default_value; std::string description; + + template + T get() const { return std::get(value); } + template + T get_default() const { return std::get(default_value); } + + template + void set(T v) { value = v; } + template + void default_set(T v) { default_value = v; } }; std::map options; @@ -133,22 +158,20 @@ struct YosysVerificSettings { void init() { #ifdef VERIFIC_SYSTEMVERILOG_SUPPORT - // Bool option example: ignore_translate_off // When true, translate_off/translate_on pragmas are ignored { Option opt; opt.type = Type::BOOL; - opt.default_bool = false; + opt.default_set(false); opt.description = "Ignore translate_off/translate_on pragmas"; options["ignore_translate_off"] = opt; } - // String-list option example: vlog_file_extensions // Allows user to specify which file extensions should be treated as SystemVerilog { Option opt; opt.type = Type::STRING_LIST; - opt.default_string_list = {".v", ".vh", ".sv", ".svh"}; + opt.default_set>({".v", ".vh", ".sv", ".svh"}); opt.description = "Comma-separated SystemVerilog file extensions"; options["vlog_file_extensions"] = opt; } @@ -159,64 +182,25 @@ struct YosysVerificSettings { void reset() { for (auto &it : options) { auto &opt = it.second; - switch (opt.type) { - case Type::BOOL: - opt.bool_value = opt.default_bool; - break; - case Type::STRING: - opt.string_value = opt.default_string; - break; - case Type::STRING_LIST: - opt.string_list_value = opt.default_string_list; - break; - } + opt.value = opt.default_value; } } - bool get_bool(const std::string &name) const { + template + T get_setting(const std::string &name) const { auto it = options.find(name); - if (it == options.end() || it->second.type != Type::BOOL) - return false; - return it->second.bool_value; - } - - std::string get_string(const std::string &name) const { - auto it = options.find(name); - if (it == options.end() || it->second.type != Type::STRING) - return ""; - return it->second.string_value; - } - - std::vector get_string_list(const std::string &name) const { - auto it = options.find(name); - if (it == options.end() || it->second.type != Type::STRING_LIST) - return {}; - return it->second.string_list_value; - } - - void set_bool(const std::string &name, bool value) { - auto it = options.find(name); - if (it != options.end() && it->second.type == Type::BOOL) - it->second.bool_value = value; - } - - void set_string(const std::string &name, const std::string &value) { - auto it = options.find(name); - if (it != options.end() && it->second.type == Type::STRING) - it->second.string_value = value; - } - - void set_string_list(const std::string &name, const std::vector &value) { - auto it = options.find(name); - if (it != options.end() && it->second.type == Type::STRING_LIST) - it->second.string_list_value = value; + if (it == options.end()) + throw std::invalid_argument(stringf("Unknown Yosys-Verific setting '%s'.\n", name.c_str())); + if (it->second.type != OptionType::value) + throw std::invalid_argument(stringf("Reading Yosys-Verific setting '%s' as wrong type.\n", name.c_str())); + return it->second.get(); } // Apply a setting to Verific APIs when changed void apply_setting(const std::string &name) { #ifdef VERIFIC_SYSTEMVERILOG_SUPPORT if (name == "ignore_translate_off") { - veri_file::SetIgnoreTranslateOff(get_bool("ignore_translate_off") ? 1 : 0); + veri_file::SetIgnoreTranslateOff(get_setting("ignore_translate_off") ? 1 : 0); return; } if (name == "vlog_file_extensions") { @@ -224,7 +208,7 @@ struct YosysVerificSettings { for (const auto &ext : _applied_vlog_extensions) { veri_file::RemoveFileExt(ext.c_str()); } - auto new_exts = get_string_list("vlog_file_extensions"); + auto new_exts = get_setting>("vlog_file_extensions"); for (const auto &ext : new_exts) { veri_file::RemoveFileExt(ext.c_str()); veri_file::AddFileExtMode(ext.c_str(), veri_file::SYSTEM_VERILOG); @@ -3521,6 +3505,7 @@ struct VerificPass : public Pass { log("With two arguments, sets the specified setting to the given value.\n"); log("\n"); log("Available settings:\n"); +#if defined(YOSYS_ENABLE_VERIFIC) // Initialize settings to get option metadata if (!yosys_verific_settings_initialized) { yosys_verific_settings.init(); @@ -3532,6 +3517,7 @@ struct VerificPass : public Pass { it.second.type == YosysVerificSettings::Type::STRING ? "string" : "string-list"; log(" %-20s (%s) %s\n", it.first.c_str(), type_str, it.second.description.c_str()); } +#endif log("\n"); log("For boolean settings, use 0/1, true/false, on/off, yes/no.\n"); log("For string-list settings, provide comma-separated values (e.g. \".v,.sv,.vh\").\n"); @@ -4535,18 +4521,18 @@ struct VerificPass : public Pass { switch (opt.type) { case YosysVerificSettings::Type::BOOL: log(" %s = %s (bool, default: %s)\n", name.c_str(), - yosys_verific_settings.get_bool(name) ? "true" : "false", - opt.default_bool ? "true" : "false"); + opt.get() ? "true" : "false", + opt.get_default() ? "true" : "false"); break; case YosysVerificSettings::Type::STRING: log(" %s = \"%s\" (string, default: \"%s\")\n", name.c_str(), - yosys_verific_settings.get_string(name).c_str(), - opt.default_string.c_str()); + opt.get().c_str(), + opt.get_default().c_str()); break; case YosysVerificSettings::Type::STRING_LIST: log(" %s = \"%s\" (string-list, default: \"%s\")\n", name.c_str(), - YosysVerificSettings::format_string_list(yosys_verific_settings.get_string_list(name)).c_str(), - YosysVerificSettings::format_string_list(opt.default_string_list).c_str()); + YosysVerificSettings::format_string_list(opt.get>()).c_str(), + YosysVerificSettings::format_string_list(opt.get_default>()).c_str()); break; } } @@ -4562,15 +4548,15 @@ struct VerificPass : public Pass { switch (opt.type) { case YosysVerificSettings::Type::BOOL: log("verific -set %s %s\n", name.c_str(), - yosys_verific_settings.get_bool(name) ? "true" : "false"); + opt.get() ? "true" : "false"); break; case YosysVerificSettings::Type::STRING: log("verific -set %s \"%s\"\n", name.c_str(), - yosys_verific_settings.get_string(name).c_str()); + opt.get().c_str()); break; case YosysVerificSettings::Type::STRING_LIST: log("verific -set %s \"%s\"\n", name.c_str(), - YosysVerificSettings::format_string_list(yosys_verific_settings.get_string_list(name)).c_str()); + YosysVerificSettings::format_string_list(opt.get>()).c_str()); break; } goto check_error; @@ -4579,9 +4565,10 @@ struct VerificPass : public Pass { // Two arguments: set specific setting if (argidx+3 == GetSize(args)) { const std::string &name = args[argidx+1]; - const std::string &value = args[argidx+2]; + std::string value = args[argidx+2]; if (!yosys_verific_settings.options.count(name)) log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); + if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2); auto &opt = yosys_verific_settings.options.at(name); switch (opt.type) { case YosysVerificSettings::Type::BOOL: { @@ -4592,17 +4579,17 @@ struct VerificPass : public Pass { bval = false; else log_cmd_error("Invalid boolean value '%s'. Use 0/1, true/false, on/off, or yes/no.\n", value.c_str()); - yosys_verific_settings.set_bool(name, bval); + opt.set(bval); log("Setting '%s' = %s\n", name.c_str(), bval ? "true" : "false"); break; } case YosysVerificSettings::Type::STRING: - yosys_verific_settings.set_string(name, value); + opt.set(value); log("Setting '%s' = \"%s\"\n", name.c_str(), value.c_str()); break; case YosysVerificSettings::Type::STRING_LIST: { auto list = YosysVerificSettings::parse_string_list(value); - yosys_verific_settings.set_string_list(name, list); + opt.set>(list); log("Setting '%s' = \"%s\"\n", name.c_str(), YosysVerificSettings::format_string_list(list).c_str()); break; From d52cad1ae2bf5a1c56ee4f2a9cc5f3e411f3d1a4 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 23 Feb 2026 12:40:48 +0100 Subject: [PATCH 6/7] Remove not needed initialization --- frontends/verific/verific.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index c3d95111d..8023ccdb4 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -4495,10 +4495,6 @@ struct VerificPass : public Pass { if (argidx < GetSize(args) && args[argidx] == "-set-reset") { - if (!yosys_verific_settings_initialized) { - yosys_verific_settings.init(); - yosys_verific_settings_initialized = true; - } yosys_verific_settings.reset(); yosys_verific_settings.apply_all(); log("All Yosys-Verific settings reset to defaults.\n"); @@ -4507,11 +4503,6 @@ struct VerificPass : public Pass { if (argidx < GetSize(args) && args[argidx] == "-set") { - if (!yosys_verific_settings_initialized) { - yosys_verific_settings.init(); - yosys_verific_settings_initialized = true; - } - // No arguments: list all settings if (argidx+1 == GetSize(args)) { log("Yosys-Verific settings:\n"); From eb5a9cc96a4521cf47b9203a55862a78f44a6e65 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 23 Feb 2026 13:04:55 +0100 Subject: [PATCH 7/7] More templates --- frontends/verific/verific.cc | 67 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 8023ccdb4..6eb4d1d8b 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -151,6 +151,34 @@ struct YosysVerificSettings { void set(T v) { value = v; } template void default_set(T v) { default_value = v; } + + static std::string to_string(const OptionValue &val) + { + return std::visit([](const auto &v) -> std::string { + using V = std::decay_t; + + if constexpr (std::is_same_v) + return v ? "true" : "false"; + else if constexpr (std::is_same_v) + return "\"" + v + "\""; + else if constexpr (std::is_same_v>) + return "\"" + YosysVerificSettings::format_string_list(v) + "\""; + }, val); + } + + std::string str() const { return to_string(value); } + + std::string str_default() const { return to_string(default_value); } + + std::string type_str() const + { + switch (type) { + case Type::BOOL: return "bool"; + case Type::STRING: return "string"; + case Type::STRING_LIST: return "string-list"; + } + return "unknown"; + } }; std::map options; @@ -4509,23 +4537,8 @@ struct VerificPass : public Pass { for (const auto &it : yosys_verific_settings.options) { const auto &name = it.first; const auto &opt = it.second; - switch (opt.type) { - case YosysVerificSettings::Type::BOOL: - log(" %s = %s (bool, default: %s)\n", name.c_str(), - opt.get() ? "true" : "false", - opt.get_default() ? "true" : "false"); - break; - case YosysVerificSettings::Type::STRING: - log(" %s = \"%s\" (string, default: \"%s\")\n", name.c_str(), - opt.get().c_str(), - opt.get_default().c_str()); - break; - case YosysVerificSettings::Type::STRING_LIST: - log(" %s = \"%s\" (string-list, default: \"%s\")\n", name.c_str(), - YosysVerificSettings::format_string_list(opt.get>()).c_str(), - YosysVerificSettings::format_string_list(opt.get_default>()).c_str()); - break; - } + log(" %s = %s (%s, default: %s)\n", name.c_str(), opt.str().c_str(), + opt.type_str().c_str(), opt.str_default().c_str()); } goto check_error; } @@ -4536,20 +4549,7 @@ struct VerificPass : public Pass { if (!yosys_verific_settings.options.count(name)) log_cmd_error("Unknown Yosys-Verific setting '%s'.\n", name.c_str()); const auto &opt = yosys_verific_settings.options.at(name); - switch (opt.type) { - case YosysVerificSettings::Type::BOOL: - log("verific -set %s %s\n", name.c_str(), - opt.get() ? "true" : "false"); - break; - case YosysVerificSettings::Type::STRING: - log("verific -set %s \"%s\"\n", name.c_str(), - opt.get().c_str()); - break; - case YosysVerificSettings::Type::STRING_LIST: - log("verific -set %s \"%s\"\n", name.c_str(), - YosysVerificSettings::format_string_list(opt.get>()).c_str()); - break; - } + log("verific -set %s %s\n", name.c_str(), opt.str().c_str()); goto check_error; } @@ -4571,21 +4571,18 @@ struct VerificPass : public Pass { else log_cmd_error("Invalid boolean value '%s'. Use 0/1, true/false, on/off, or yes/no.\n", value.c_str()); opt.set(bval); - log("Setting '%s' = %s\n", name.c_str(), bval ? "true" : "false"); break; } case YosysVerificSettings::Type::STRING: opt.set(value); - log("Setting '%s' = \"%s\"\n", name.c_str(), value.c_str()); break; case YosysVerificSettings::Type::STRING_LIST: { auto list = YosysVerificSettings::parse_string_list(value); opt.set>(list); - log("Setting '%s' = \"%s\"\n", name.c_str(), - YosysVerificSettings::format_string_list(list).c_str()); break; } } + log("Setting '%s' = %s\n", name.c_str(), opt.str().c_str()); // Apply the setting to Verific APIs yosys_verific_settings.apply_setting(name); goto check_error;