mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-05 05:49:15 +00:00
Add try_as_const and use the const iterator a bit more
This commit is contained in:
parent
04a6dbc562
commit
000c081965
2 changed files with 29 additions and 11 deletions
|
|
@ -5621,33 +5621,48 @@ std::string RTLIL::SigSpec::as_string() const
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<RTLIL::Const> RTLIL::SigSpec::try_as_const() const
|
||||||
|
{
|
||||||
|
cover("kernel.rtlil.sigspec.as_const");
|
||||||
|
|
||||||
|
auto it = chunks().begin();
|
||||||
|
if (it == chunks().end())
|
||||||
|
return RTLIL::Const();
|
||||||
|
SigChunk chunk = *it;
|
||||||
|
if (chunk.wire != NULL || ++it != chunks().end())
|
||||||
|
return std::nullopt;
|
||||||
|
return RTLIL::Const(std::move(chunk.data));
|
||||||
|
}
|
||||||
|
|
||||||
RTLIL::Const RTLIL::SigSpec::as_const() const
|
RTLIL::Const RTLIL::SigSpec::as_const() const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_const");
|
cover("kernel.rtlil.sigspec.as_const");
|
||||||
|
|
||||||
pack();
|
std::optional<RTLIL::Const> c = try_as_const();
|
||||||
log_assert(is_fully_const() && GetSize(chunks_) <= 1);
|
log_assert(c.has_value());
|
||||||
if (width_)
|
return *c;
|
||||||
return chunks_[0].data;
|
|
||||||
return RTLIL::Const();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::Wire *RTLIL::SigSpec::as_wire() const
|
RTLIL::Wire *RTLIL::SigSpec::as_wire() const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_wire");
|
cover("kernel.rtlil.sigspec.as_wire");
|
||||||
|
|
||||||
pack();
|
auto it = chunks().begin();
|
||||||
log_assert(is_wire());
|
log_assert(it != chunks().end());
|
||||||
return chunks_[0].wire;
|
RTLIL::SigChunk chunk = *it;
|
||||||
|
log_assert(++it == chunks().end() && chunk.wire && chunk.wire->width == width_);
|
||||||
|
return chunk.wire;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::SigChunk RTLIL::SigSpec::as_chunk() const
|
RTLIL::SigChunk RTLIL::SigSpec::as_chunk() const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_chunk");
|
cover("kernel.rtlil.sigspec.as_chunk");
|
||||||
|
|
||||||
pack();
|
auto it = chunks().begin();
|
||||||
log_assert(is_chunk());
|
log_assert(it != chunks().end());
|
||||||
return chunks_[0];
|
RTLIL::SigChunk chunk = *it;
|
||||||
|
log_assert(++it == chunks().end());
|
||||||
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::SigBit RTLIL::SigSpec::as_bit() const
|
RTLIL::SigBit RTLIL::SigSpec::as_bit() const
|
||||||
|
|
|
||||||
|
|
@ -1453,6 +1453,9 @@ public:
|
||||||
int as_int_saturating(bool is_signed = false) const;
|
int as_int_saturating(bool is_signed = false) const;
|
||||||
|
|
||||||
std::string as_string() const;
|
std::string as_string() const;
|
||||||
|
// Returns std::nullopt if there are any non-constant bits. Returns an empty
|
||||||
|
// Const if this has zero width.
|
||||||
|
std::optional<RTLIL::Const> try_as_const() const;
|
||||||
RTLIL::Const as_const() const;
|
RTLIL::Const as_const() const;
|
||||||
RTLIL::Wire *as_wire() const;
|
RTLIL::Wire *as_wire() const;
|
||||||
RTLIL::SigChunk as_chunk() const;
|
RTLIL::SigChunk as_chunk() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue