diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 2d3135378..0740ef297 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -214,6 +214,16 @@ RTLIL::Const::Const(const std::string &str) } } +RTLIL::Const::Const(int val, int width) +{ + flags = RTLIL::CONST_FLAG_NONE; + bits.reserve(width); + for (int i = 0; i < width; i++) { + bits.push_back((val & 1) != 0 ? State::S1 : State::S0); + val = val >> 1; + } +} + RTLIL::Const::Const(long long val, int width) { flags = RTLIL::CONST_FLAG_NONE; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index c49734cd0..131c7a433 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -663,6 +663,7 @@ struct RTLIL::Const Const() : flags(RTLIL::CONST_FLAG_NONE) {} Const(const std::string &str); + Const(int val, int width = 32); Const(long long val, int width = 32); Const(RTLIL::State bit, int width = 1); Const(const std::vector &bits) : bits(bits) { flags = CONST_FLAG_NONE; }