summaryrefslogtreecommitdiff
path: root/frontends/ast/ast.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-08-21 17:11:51 +0200
committerClifford Wolf <clifford@clifford.at>2014-08-21 17:11:51 +0200
commit085c8e873d4d90129a952eba85836891635a7f8c (patch)
tree7afb69f3d74151c225f5ea13e1de615e2fb0b949 /frontends/ast/ast.cc
parent490d7a5bf2062481dfda656de86bfbeca83c080d (diff)
Added AstNode::asInt()
Diffstat (limited to 'frontends/ast/ast.cc')
-rw-r--r--frontends/ast/ast.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc
index de38eff6..2fc8f983 100644
--- a/frontends/ast/ast.cc
+++ b/frontends/ast/ast.cc
@@ -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;