diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-08-21 17:11:51 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-08-21 17:11:51 +0200 |
commit | 085c8e873d4d90129a952eba85836891635a7f8c (patch) | |
tree | 7afb69f3d74151c225f5ea13e1de615e2fb0b949 /frontends/ast | |
parent | 490d7a5bf2062481dfda656de86bfbeca83c080d (diff) | |
download | yosys-085c8e873d4d90129a952eba85836891635a7f8c.tar.gz yosys-085c8e873d4d90129a952eba85836891635a7f8c.tar.bz2 yosys-085c8e873d4d90129a952eba85836891635a7f8c.zip |
Added AstNode::asInt()
Diffstat (limited to 'frontends/ast')
-rw-r--r-- | frontends/ast/ast.cc | 23 | ||||
-rw-r--r-- | frontends/ast/ast.h | 1 | ||||
-rw-r--r-- | frontends/ast/dpicall.cc | 2 |
3 files changed, 24 insertions, 2 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index de38eff6c..2fc8f9835 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; diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h index 88917c64b..0a4016736 100644 --- a/frontends/ast/ast.h +++ b/frontends/ast/ast.h @@ -247,6 +247,7 @@ namespace AST RTLIL::Const bitsAsConst(int width = -1); RTLIL::Const asAttrConst(); RTLIL::Const asParaConst(); + uint64_t asInt(bool is_signed); bool bits_only_01(); bool asBool(); diff --git a/frontends/ast/dpicall.cc b/frontends/ast/dpicall.cc index a1954dabf..965645cde 100644 --- a/frontends/ast/dpicall.cc +++ b/frontends/ast/dpicall.cc @@ -30,7 +30,7 @@ AST::AstNode *AST::dpi_call(const std::string &rtype, const std::string &fname, if (argtypes[i] == "real" || argtypes[i] == "shortreal") log(" arg %d (%s): %f\n", i, argtypes[i].c_str(), args[i]->asReal(args[i]->is_signed)); else - log(" arg %d (%s): %d\n", i, argtypes[i].c_str(), args[i]->bitsAsConst().as_int()); + log(" arg %d (%s): %lld\n", i, argtypes[i].c_str(), (long long)args[i]->asInt(args[i]->is_signed)); if (rtype == "real" || rtype == "shortreal") { newNode = new AstNode(AST_REALVALUE); |