aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.cc14
-rw-r--r--kernel/rtlil.h9
2 files changed, 16 insertions, 7 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index a09f4a0d1..fd98ab4bd 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -3297,7 +3297,7 @@ void RTLIL::SigSpec::replace(int offset, const RTLIL::SigSpec &with)
check();
}
-void RTLIL::SigSpec::remove_const()
+RTLIL::SigSpec& RTLIL::SigSpec::remove_const()
{
if (packed())
{
@@ -3331,6 +3331,7 @@ void RTLIL::SigSpec::remove_const()
}
check();
+ return *this;
}
void RTLIL::SigSpec::remove(int offset, int length)
@@ -3353,7 +3354,13 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
{
unpack();
cover("kernel.rtlil.sigspec.extract_pos");
- return std::vector<RTLIL::SigBit>(bits_.begin() + offset, bits_.begin() + offset + length);
+ auto it = bits_.begin() + std::min<int>(offset, width_);
+ decltype(it) ie;
+ if (length >= 0)
+ ie = bits_.begin() + std::min<int>(offset + length, width_);
+ else
+ ie = bits_.end() + std::max<int>(length + 1, offset - width_);
+ return std::vector<RTLIL::SigBit>(it, ie);
}
void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)
@@ -3426,7 +3433,7 @@ void RTLIL::SigSpec::append_bit(const RTLIL::SigBit &bit)
check();
}
-void RTLIL::SigSpec::extend_u0(int width, bool is_signed)
+RTLIL::SigSpec& RTLIL::SigSpec::extend_u0(int width, bool is_signed)
{
cover("kernel.rtlil.sigspec.extend_u0");
@@ -3443,6 +3450,7 @@ void RTLIL::SigSpec::extend_u0(int width, bool is_signed)
append(padding);
}
+ return *this;
}
RTLIL::SigSpec RTLIL::SigSpec::repeat(int num) const
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 712250b3e..02bf274fb 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -750,8 +750,8 @@ public:
inline int size() const { return width_; }
inline bool empty() const { return width_ == 0; }
- inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); }
- inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); }
+ inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return index >= 0 ? bits_.at(index) : bits_.at(width_ + index); }
+ inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return index >= 0 ? bits_.at(index) : bits_.at(width_ + index); }
inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; }
inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; }
@@ -783,7 +783,7 @@ public:
void remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
void remove(int offset, int length = 1);
- void remove_const();
+ RTLIL::SigSpec& remove_const();
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other = NULL) const;
RTLIL::SigSpec extract(const pool<RTLIL::SigBit> &pattern, const RTLIL::SigSpec *other = NULL) const;
@@ -792,7 +792,7 @@ public:
void append(const RTLIL::SigSpec &signal);
void append_bit(const RTLIL::SigBit &bit);
- void extend_u0(int width, bool is_signed = false);
+ RTLIL::SigSpec& extend_u0(int width, bool is_signed = false);
RTLIL::SigSpec repeat(int num) const;
@@ -834,6 +834,7 @@ public:
operator std::vector<RTLIL::SigChunk>() const { return chunks(); }
operator std::vector<RTLIL::SigBit>() const { return bits(); }
+ RTLIL::SigBit at(int offset, const RTLIL::SigBit &defval) { return offset < width_ ? (*this)[offset] : defval; }
unsigned int hash() const { if (!hash_) updhash(); return hash_; };