mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-05 13:56:04 +00:00
Build a temporary SigChunk list in the iterator in the cases where that's needed
This commit is contained in:
parent
8c9dd3209a
commit
973e8a3928
4 changed files with 55 additions and 25 deletions
|
|
@ -121,7 +121,8 @@ void RTLIL_BACKEND::dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig, boo
|
||||||
dump_sigchunk(f, sig.as_chunk(), autoint);
|
dump_sigchunk(f, sig.as_chunk(), autoint);
|
||||||
} else {
|
} else {
|
||||||
f << stringf("{ ");
|
f << stringf("{ ");
|
||||||
for (const auto& chunk : reversed(sig.chunks())) {
|
auto chunks = sig.chunks();
|
||||||
|
for (const auto& chunk : reversed(chunks)) {
|
||||||
dump_sigchunk(f, chunk, false);
|
dump_sigchunk(f, chunk, false);
|
||||||
f << stringf(" ");
|
f << stringf(" ");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,8 +382,9 @@ void dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig)
|
||||||
dump_sigchunk(f, sig.as_chunk());
|
dump_sigchunk(f, sig.as_chunk());
|
||||||
} else {
|
} else {
|
||||||
f << stringf("{ ");
|
f << stringf("{ ");
|
||||||
for (auto it = sig.chunks().rbegin(); it != sig.chunks().rend(); ++it) {
|
auto chunks = sig.chunks();
|
||||||
if (it != sig.chunks().rbegin())
|
for (auto it = chunks.rbegin(); it != chunks.rend(); ++it) {
|
||||||
|
if (it != chunks.rbegin())
|
||||||
f << stringf(", ");
|
f << stringf(", ");
|
||||||
dump_sigchunk(f, *it, true);
|
dump_sigchunk(f, *it, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1276,8 +1276,7 @@ public:
|
||||||
SigSpec &operator=(SigSpec &&rhs) = default;
|
SigSpec &operator=(SigSpec &&rhs) = default;
|
||||||
|
|
||||||
struct Chunks {
|
struct Chunks {
|
||||||
const SigSpec &spec;
|
Chunks(const SigSpec &spec) : spec(spec) {}
|
||||||
|
|
||||||
struct const_iterator {
|
struct const_iterator {
|
||||||
using iterator_category = std::forward_iterator_tag;
|
using iterator_category = std::forward_iterator_tag;
|
||||||
using value_type = const SigChunk &;
|
using value_type = const SigChunk &;
|
||||||
|
|
@ -1320,26 +1319,43 @@ public:
|
||||||
it.bit_index = spec.size();
|
it.bit_index = spec.size();
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
std::vector<RTLIL::SigChunk>::const_reverse_iterator rbegin() const {
|
// Later we should deprecate these and remove their in-tree calls,
|
||||||
spec.pack();
|
// so we can eventually remove chunk_vector.
|
||||||
return spec.chunks_.rbegin();
|
std::vector<RTLIL::SigChunk>::const_reverse_iterator rbegin() {
|
||||||
|
ensure_chunk_vector();
|
||||||
|
return chunk_vector.rbegin();
|
||||||
}
|
}
|
||||||
std::vector<RTLIL::SigChunk>::const_reverse_iterator rend() const {
|
std::vector<RTLIL::SigChunk>::const_reverse_iterator rend() {
|
||||||
spec.pack();
|
ensure_chunk_vector();
|
||||||
return spec.chunks_.rend();
|
return chunk_vector.rend();
|
||||||
|
}
|
||||||
|
int size() {
|
||||||
|
ensure_chunk_vector();
|
||||||
|
return chunk_vector.size();
|
||||||
}
|
}
|
||||||
int size() const {
|
int size() const {
|
||||||
spec.pack();
|
int result = 0;
|
||||||
return spec.chunks_.size();
|
for (const SigChunk &_: *this)
|
||||||
|
++result;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
const SigChunk &at(int index) const {
|
const SigChunk &at(int index) {
|
||||||
spec.pack();
|
ensure_chunk_vector();
|
||||||
return spec.chunks_.at(index);
|
return chunk_vector.at(index);
|
||||||
}
|
}
|
||||||
operator const std::vector<RTLIL::SigChunk>&() const {
|
operator const std::vector<RTLIL::SigChunk>&() {
|
||||||
spec.pack();
|
ensure_chunk_vector();
|
||||||
return spec.chunks_;
|
return chunk_vector;
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
void ensure_chunk_vector() {
|
||||||
|
if (spec.size() > 0 && chunk_vector.empty()) {
|
||||||
|
for (const RTLIL::SigChunk &c : *this)
|
||||||
|
chunk_vector.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const SigSpec &spec;
|
||||||
|
std::vector<RTLIL::SigChunk> chunk_vector;
|
||||||
};
|
};
|
||||||
friend struct Chunks::const_iterator;
|
friend struct Chunks::const_iterator;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,14 +277,26 @@ inline int ceil_log2(int x)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto reversed(T& container) {
|
||||||
|
struct reverse_view {
|
||||||
|
reverse_view(T& container) : container(container) {}
|
||||||
|
auto begin() const { return container.rbegin(); }
|
||||||
|
auto end() const { return container.rend(); }
|
||||||
|
T& container;
|
||||||
|
};
|
||||||
|
return reverse_view{container};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto reversed(const T& container) {
|
auto reversed(const T& container) {
|
||||||
struct reverse_view {
|
struct reverse_view {
|
||||||
const T& cont;
|
reverse_view(const T& container) : container(container) {}
|
||||||
auto begin() const { return cont.rbegin(); }
|
auto begin() const { return container.rbegin(); }
|
||||||
auto end() const { return cont.rend(); }
|
auto end() const { return container.rend(); }
|
||||||
};
|
const T& container;
|
||||||
return reverse_view{container};
|
};
|
||||||
|
return reverse_view{container};
|
||||||
}
|
}
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue