From 1f7957c612d6f0e4a1d37c631b1cc5b17a731679 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 8 Jan 2008 18:54:55 -0800 Subject: [PATCH] Fix type handling of real-value system functions in nets In nets, if system functions return a real value the function lookup was getting the correct width, but was also setting the width to 0, which confused down-stream net handling. Real-value system fuctions have a width of 1. (1 real-valued scalar.) --- design_dump.cc | 3 ++- elab_net.cc | 10 ++++++++++ net_func.cc | 5 +++++ netlist.h | 1 + sys_funcs.cc | 8 ++++---- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/design_dump.cc b/design_dump.cc index 950925d53..b9ce6ad04 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -512,7 +512,8 @@ void NetUReduce::dump_node(ostream&o, unsigned ind) const void NetSysFunc::dump_node(ostream&o, unsigned ind) const { - o << setw(ind) << "" << def_->name << "(...)" << endl; + o << setw(ind) << "" << def_->name << "(...) -->" + << data_type() << " width=" << vector_width() << endl; dump_node_pins(o, ind+4); dump_obj_attr(o, ind+4); } diff --git a/elab_net.cc b/elab_net.cc index ffcbd27e7..dcbed7a70 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -1365,6 +1365,11 @@ NetNet* PECallFunction::elaborate_net_sfunc_(Design*des, NetScope*scope, return 0; } + if (debug_elaborate) { + cerr << get_fileline() << ": debug: Net system function " + << name << " returns " << def->type << endl; + } + NetSysFunc*net = new NetSysFunc(scope, scope->local_symbol(), def, 1+parms_.count()); des->add_node(net); @@ -1373,6 +1378,7 @@ NetNet* PECallFunction::elaborate_net_sfunc_(Design*des, NetScope*scope, NetNet*osig = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, def->wid); osig->local_flag(true); + osig->set_signed(def->type==IVL_VT_REAL? true : false); osig->data_type(def->type); osig->set_line(*this); @@ -2170,7 +2176,9 @@ NetNet* PEFNumber::elaborate_net(Design*des, NetScope*scope, NetNet*net = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, 1); net->data_type(IVL_VT_REAL); + net->set_signed(true); net->local_flag(true); + net->set_line(*this); connect(net->pin(0), obj->pin(0)); return net; @@ -3158,7 +3166,9 @@ NetNet* PEUnary::elab_net_uminus_const_real_(Design*des, NetScope*scope, NetNet*sig = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, width); sig->data_type(IVL_VT_REAL); + sig->set_signed(true); sig->local_flag(true); + sig->set_line(*this); NetLiteral*con = new NetLiteral(scope, scope->local_symbol(), -val); diff --git a/net_func.cc b/net_func.cc index 137e75dbd..5d270475e 100644 --- a/net_func.cc +++ b/net_func.cc @@ -138,6 +138,11 @@ const char*NetSysFunc::func_name() const return def_->name; } +ivl_variable_type_t NetSysFunc::data_type() const +{ + return def_->type; +} + unsigned NetSysFunc::vector_width() const { return def_->wid; diff --git a/netlist.h b/netlist.h index 022187df3..a4d47e58d 100644 --- a/netlist.h +++ b/netlist.h @@ -1047,6 +1047,7 @@ class NetSysFunc : public NetNode { unsigned ports); ~NetSysFunc(); + ivl_variable_type_t data_type() const; unsigned vector_width() const; const char* func_name() const; diff --git a/sys_funcs.cc b/sys_funcs.cc index 498d31a54..633540b00 100644 --- a/sys_funcs.cc +++ b/sys_funcs.cc @@ -33,9 +33,9 @@ */ static const struct sfunc_return_type sfunc_table[] = { - { "$realtime", IVL_VT_REAL, 0, 0 }, - { "$bitstoreal", IVL_VT_REAL, 0, 0 }, - { "$itor", IVL_VT_REAL, 0, 0 }, + { "$realtime", IVL_VT_REAL, 1, 0 }, + { "$bitstoreal", IVL_VT_REAL, 1, 0 }, + { "$itor", IVL_VT_REAL, 1, 0 }, { "$realtobits", IVL_VT_LOGIC, 64, 0 }, { "$time", IVL_VT_LOGIC, 64, 0 }, { "$stime", IVL_VT_LOGIC, 32, 0 }, @@ -127,7 +127,7 @@ int load_sys_func_table(const char*path) cell = new struct sfunc_return_type_cell; cell->name = lex_strings.add(name); cell->type = IVL_VT_REAL; - cell->wid = 0; + cell->wid = 1; cell->signed_flag = true; cell->next = sfunc_stack; sfunc_stack = cell;