3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-06 14:13:23 +00:00

Added AstNode::asInt()

This commit is contained in:
Clifford Wolf 2014-08-21 17:11:51 +02:00
parent 490d7a5bf2
commit 085c8e873d
3 changed files with 24 additions and 2 deletions

View file

@ -792,9 +792,30 @@ int AstNode::isConst()
return 0;
}
uint64_t AstNode::asInt(bool is_signed)
{
if (type == AST_CONSTANT)
{
RTLIL::Const v = bitsAsConst(64, is_signed);
uint64_t ret = 0;
for (int i = 0; i < 64; i++)
if (v.bits.at(i) == RTLIL::State::S1)
ret |= uint64_t(1) << i;
return ret;
}
if (type == AST_REALVALUE)
return realvalue;
log_abort();
}
double AstNode::asReal(bool is_signed)
{
if (type == AST_CONSTANT) {
if (type == AST_CONSTANT)
{
RTLIL::Const val(bits);
bool is_negative = is_signed && val.bits.back() == RTLIL::State::S1;