Added AstNode::asInt()
authorClifford Wolf <clifford@clifford.at>
Thu, 21 Aug 2014 15:11:51 +0000 (17:11 +0200)
committerClifford Wolf <clifford@clifford.at>
Thu, 21 Aug 2014 15:11:51 +0000 (17:11 +0200)
frontends/ast/ast.cc
frontends/ast/ast.h
frontends/ast/dpicall.cc

index de38eff6c8bf00322b1fab790be309a9450bd4b7..2fc8f9835aef6ec15861973de69f5c4954be67c0 100644 (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;
index 88917c64bf6cd54295cdc213db6649a95742309a..0a4016736350372cb1679468fc1c06bbeb017fb7 100644 (file)
@@ -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();
 
index a1954dabf8703717f96cb7ca5b0a53f1dfdf1e3f..965645cde221623598d777b4a59b482241f62b9e 100644 (file)
@@ -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);