diff options
author | Clifford Wolf <clifford@clifford.at> | 2017-08-18 11:40:08 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2017-08-18 11:40:08 +0200 |
commit | 4ba5bd12c612cbe27422cf86fe317d0723b11f30 (patch) | |
tree | 15914f6b1a1991877ced6297764487e56f04e15a /kernel | |
parent | 0be738eaac7808f4362ef265c7a3e1f2e6a15deb (diff) | |
download | yosys-4ba5bd12c612cbe27422cf86fe317d0723b11f30.tar.gz yosys-4ba5bd12c612cbe27422cf86fe317d0723b11f30.tar.bz2 yosys-4ba5bd12c612cbe27422cf86fe317d0723b11f30.zip |
Add Const methods is_fully_zero(), is_fully_def(), and is_fully_undef()
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/rtlil.cc | 33 | ||||
-rw-r--r-- | kernel/rtlil.h | 4 |
2 files changed, 37 insertions, 0 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 93cfef80e..4427303cc 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -161,6 +161,39 @@ std::string RTLIL::Const::decode_string() const return string; } +bool RTLIL::Const::is_fully_zero() const +{ + cover("kernel.rtlil.const.is_fully_zero"); + + for (auto bit : bits) + if (bit != RTLIL::State::S0) + return false; + + return true; +} + +bool RTLIL::Const::is_fully_def() const +{ + cover("kernel.rtlil.const.is_fully_def"); + + for (auto bit : bits) + if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1) + return false; + + return true; +} + +bool RTLIL::Const::is_fully_undef() const +{ + cover("kernel.rtlil.const.is_fully_undef"); + + for (auto bit : bits) + if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz) + return false; + + return true; +} + void RTLIL::AttrObject::set_bool_attribute(RTLIL::IdString id) { attributes[id] = RTLIL::Const(1); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 51a3fad6f..be558932f 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -479,6 +479,10 @@ struct RTLIL::Const inline RTLIL::State &operator[](int index) { return bits.at(index); } inline const RTLIL::State &operator[](int index) const { return bits.at(index); } + bool is_fully_zero() const; + bool is_fully_def() const; + bool is_fully_undef() const; + inline RTLIL::Const extract(int offset, int len = 1, RTLIL::State padding = RTLIL::State::S0) const { RTLIL::Const ret; ret.bits.reserve(len); |