mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-05 05:49:15 +00:00
Use SigSpec::try_as_const in some places
This commit is contained in:
parent
0d45d9cc6e
commit
82f86164d3
1 changed files with 18 additions and 34 deletions
|
|
@ -5541,74 +5541,58 @@ bool RTLIL::SigSpec::as_bool() const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_bool");
|
cover("kernel.rtlil.sigspec.as_bool");
|
||||||
|
|
||||||
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->as_bool();
|
||||||
return RTLIL::Const(chunks_[0].data).as_bool();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int RTLIL::SigSpec::as_int(bool is_signed) const
|
int RTLIL::SigSpec::as_int(bool is_signed) const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_int");
|
cover("kernel.rtlil.sigspec.as_int");
|
||||||
|
|
||||||
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->as_int(is_signed);
|
||||||
return RTLIL::Const(chunks_[0].data).as_int(is_signed);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RTLIL::SigSpec::convertible_to_int(bool is_signed) const
|
bool RTLIL::SigSpec::convertible_to_int(bool is_signed) const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.convertible_to_int");
|
cover("kernel.rtlil.sigspec.convertible_to_int");
|
||||||
|
|
||||||
pack();
|
std::optional<RTLIL::Const> c = try_as_const();
|
||||||
if (!is_fully_const())
|
if (!c.has_value())
|
||||||
return false;
|
return false;
|
||||||
|
return c->convertible_to_int(is_signed);
|
||||||
if (empty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return RTLIL::Const(chunks_[0].data).convertible_to_int(is_signed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int> RTLIL::SigSpec::try_as_int(bool is_signed) const
|
std::optional<int> RTLIL::SigSpec::try_as_int(bool is_signed) const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.try_as_int");
|
cover("kernel.rtlil.sigspec.try_as_int");
|
||||||
|
|
||||||
pack();
|
std::optional<RTLIL::Const> c = try_as_const();
|
||||||
if (!is_fully_const())
|
if (!c.has_value())
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
return c->try_as_int(is_signed);
|
||||||
if (empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return RTLIL::Const(chunks_[0].data).try_as_int(is_signed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int RTLIL::SigSpec::as_int_saturating(bool is_signed) const
|
int RTLIL::SigSpec::as_int_saturating(bool is_signed) const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.try_as_int");
|
cover("kernel.rtlil.sigspec.try_as_int");
|
||||||
|
|
||||||
pack();
|
std::optional<RTLIL::Const> c = try_as_const();
|
||||||
log_assert(is_fully_const() && GetSize(chunks_) <= 1);
|
log_assert(c.has_value());
|
||||||
|
return c->as_int_saturating(is_signed);
|
||||||
if (empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return RTLIL::Const(chunks_[0].data).as_int_saturating(is_signed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RTLIL::SigSpec::as_string() const
|
std::string RTLIL::SigSpec::as_string() const
|
||||||
{
|
{
|
||||||
cover("kernel.rtlil.sigspec.as_string");
|
cover("kernel.rtlil.sigspec.as_string");
|
||||||
|
|
||||||
pack();
|
|
||||||
std::string str;
|
std::string str;
|
||||||
str.reserve(size());
|
str.reserve(size());
|
||||||
for (size_t i = chunks_.size(); i > 0; i--) {
|
std::vector<RTLIL::SigChunk> chunks = *this;
|
||||||
const RTLIL::SigChunk &chunk = chunks_[i-1];
|
for (size_t i = chunks.size(); i > 0; i--) {
|
||||||
|
const RTLIL::SigChunk &chunk = chunks[i-1];
|
||||||
if (chunk.wire != NULL)
|
if (chunk.wire != NULL)
|
||||||
str.append(chunk.width, '?');
|
str.append(chunk.width, '?');
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue