diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/rtlil.cc | 61 | ||||
-rw-r--r-- | kernel/rtlil.h | 11 |
2 files changed, 72 insertions, 0 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 96b651d89..72eced914 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -273,6 +273,67 @@ RTLIL::Module *RTLIL::Design::addModule(RTLIL::IdString name) return module; } +void RTLIL::Design::scratchpad_unset(std::string varname) +{ + scratchpad.erase(varname); +} + +void RTLIL::Design::scratchpad_set_int(std::string varname, int value) +{ + scratchpad[varname] = stringf("%d", value); +} + +void RTLIL::Design::scratchpad_set_bool(std::string varname, bool value) +{ + scratchpad[varname] = value ? "true" : "false"; +} + +void RTLIL::Design::scratchpad_set_string(std::string varname, std::string value) +{ + scratchpad[varname] = value; +} + +int RTLIL::Design::scratchpad_get_int(std::string varname, int default_value) const +{ + if (scratchpad.count(varname) == 0) + return default_value; + + std::string str = scratchpad.at(varname); + + if (str == "0" || str == "false") + return 0; + + if (str == "1" || str == "true") + return 1; + + char *endptr = nullptr; + long int parsed_value = strtol(str.c_str(), &endptr, 10); + return *endptr ? default_value : parsed_value; +} + +bool RTLIL::Design::scratchpad_get_bool(std::string varname, bool default_value) const +{ + if (scratchpad.count(varname) == 0) + return default_value; + + std::string str = scratchpad.at(varname); + + if (str == "0" || str == "false") + return false; + + if (str == "1" || str == "true") + return true; + + return default_value; +} + +std::string RTLIL::Design::scratchpad_get_string(std::string varname, std::string default_value) const +{ + if (scratchpad.count(varname) == 0) + return default_value; + return scratchpad.at(varname); +} + void RTLIL::Design::remove(RTLIL::Module *module) { for (auto mon : monitors) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index d58873570..e35c3c681 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -486,6 +486,7 @@ struct RTLIL::Monitor struct RTLIL::Design { std::set<RTLIL::Monitor*> monitors; + std::map<std::string, std::string> scratchpad; int refcount_modules_; std::map<RTLIL::IdString, RTLIL::Module*> modules_; @@ -508,6 +509,16 @@ struct RTLIL::Design RTLIL::Module *addModule(RTLIL::IdString name); void remove(RTLIL::Module *module); + void scratchpad_unset(std::string varname); + + void scratchpad_set_int(std::string varname, int value); + void scratchpad_set_bool(std::string varname, bool value); + void scratchpad_set_string(std::string varname, std::string value); + + int scratchpad_get_int(std::string varname, int default_value = 0) const; + bool scratchpad_get_bool(std::string varname, bool default_value = false) const; + std::string scratchpad_get_string(std::string varname, std::string default_value = std::string()) const; + void check(); void optimize(); |