2001-02-11 03:15:52 +01:00
|
|
|
/*
|
2003-02-26 02:29:24 +01:00
|
|
|
* Copyright (c) 2001-2003 Stephen Williams (steve@icarus.com)
|
2001-02-11 03:15:52 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2007-06-02 05:42:12 +02:00
|
|
|
#ident "$Id: netmisc.cc,v 1.14 2007/06/02 03:42:13 steve Exp $"
|
2001-02-11 03:15:52 +01:00
|
|
|
#endif
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
2001-02-11 03:15:52 +01:00
|
|
|
# include "netlist.h"
|
|
|
|
|
# include "netmisc.h"
|
|
|
|
|
# include "PExpr.h"
|
2007-06-02 05:42:12 +02:00
|
|
|
# include "pform_types.h"
|
|
|
|
|
# include "ivl_assert.h"
|
2001-02-11 03:15:52 +01:00
|
|
|
|
2002-08-31 05:48:50 +02:00
|
|
|
NetNet* add_to_net(Design*des, NetNet*sig, long val)
|
|
|
|
|
{
|
|
|
|
|
if (val == 0)
|
|
|
|
|
return sig;
|
2004-12-11 03:31:25 +01:00
|
|
|
#if 0
|
2002-08-31 05:48:50 +02:00
|
|
|
NetScope*scope = sig->scope();
|
|
|
|
|
unsigned long abs_val = (val >= 0)? val : (-val);
|
|
|
|
|
unsigned width = sig->pin_count();
|
|
|
|
|
|
|
|
|
|
verinum val_v (abs_val, width);
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
NetConst*val_c = new NetConst(scope, scope->local_symbol(), val_v);
|
2002-08-31 05:48:50 +02:00
|
|
|
|
2003-03-06 01:28:41 +01:00
|
|
|
NetNet*val_s = new NetNet(scope, scope->local_symbol(),
|
2002-08-31 05:48:50 +02:00
|
|
|
NetNet::IMPLICIT, width);
|
|
|
|
|
val_s->local_flag(true);
|
|
|
|
|
|
2003-03-06 01:28:41 +01:00
|
|
|
NetNet*res = new NetNet(scope, scope->local_symbol(),
|
2002-08-31 05:48:50 +02:00
|
|
|
NetNet::IMPLICIT, width);
|
|
|
|
|
res->local_flag(true);
|
|
|
|
|
|
2003-02-26 02:29:24 +01:00
|
|
|
NetAddSub*add = new NetAddSub(scope, scope->local_symbol(), width);
|
2002-08-31 05:48:50 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
connect(sig->pin(idx), add->pin_DataA(idx));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
connect(val_c->pin(idx), add->pin_DataB(idx));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
connect(val_s->pin(idx), add->pin_DataB(idx));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
connect(res->pin(idx), add->pin_Result(idx));
|
|
|
|
|
|
|
|
|
|
if (val < 0)
|
2004-02-20 19:53:33 +01:00
|
|
|
add->attribute(perm_string::literal("LPM_Direction"), verinum("SUB"));
|
2002-08-31 05:48:50 +02:00
|
|
|
else
|
2004-02-20 19:53:33 +01:00
|
|
|
add->attribute(perm_string::literal("LPM_Direction"), verinum("ADD"));
|
2002-08-31 05:48:50 +02:00
|
|
|
|
|
|
|
|
des->add_node(add);
|
|
|
|
|
des->add_node(val_c);
|
|
|
|
|
|
|
|
|
|
return res;
|
2004-12-11 03:31:25 +01:00
|
|
|
#else
|
|
|
|
|
cerr << sig->get_line() << ": XXXX: Forgot how to implement add_to_net" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
2002-08-31 05:48:50 +02:00
|
|
|
}
|
|
|
|
|
|
2005-01-24 06:28:30 +01:00
|
|
|
/*
|
|
|
|
|
* Add a signed constant to an existing expression. Generate a new
|
|
|
|
|
* NetEBAdd node that has the input expression and an expression made
|
|
|
|
|
* from the constant value.
|
|
|
|
|
*/
|
|
|
|
|
NetExpr* make_add_expr(NetExpr*expr, long val)
|
|
|
|
|
{
|
|
|
|
|
if (val == 0)
|
|
|
|
|
return expr;
|
|
|
|
|
|
|
|
|
|
// If the value to be added is <0, then instead generate a
|
|
|
|
|
// SUBTRACT node and turn the value positive.
|
|
|
|
|
char add_op = '+';
|
|
|
|
|
if (val < 0) {
|
|
|
|
|
add_op = '-';
|
|
|
|
|
val = -val;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-08 06:50:31 +02:00
|
|
|
verinum val_v (val);
|
2005-01-24 06:28:30 +01:00
|
|
|
val_v.has_sign(true);
|
2005-04-08 06:50:31 +02:00
|
|
|
|
|
|
|
|
if (expr->has_width()) {
|
|
|
|
|
val_v = verinum(val_v, expr->expr_width());
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-24 06:28:30 +01:00
|
|
|
NetEConst*val_c = new NetEConst(val_v);
|
|
|
|
|
val_c->set_line(*expr);
|
|
|
|
|
|
|
|
|
|
NetEBAdd*res = new NetEBAdd(add_op, expr, val_c);
|
|
|
|
|
res->set_line(*expr);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetExpr* make_sub_expr(long val, NetExpr*expr)
|
|
|
|
|
{
|
|
|
|
|
verinum val_v (val, expr->expr_width());
|
|
|
|
|
val_v.has_sign(true);
|
|
|
|
|
NetEConst*val_c = new NetEConst(val_v);
|
|
|
|
|
val_c->set_line(*expr);
|
|
|
|
|
|
|
|
|
|
NetEBAdd*res = new NetEBAdd('-', val_c, expr);
|
|
|
|
|
res->set_line(*expr);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2001-02-11 03:15:52 +01:00
|
|
|
|
2006-06-02 06:48:49 +02:00
|
|
|
NetExpr* elab_and_eval(Design*des, NetScope*scope,
|
2007-03-08 06:30:02 +01:00
|
|
|
const PExpr*pe, int expr_wid, int prune_width)
|
2001-02-11 03:15:52 +01:00
|
|
|
{
|
2006-06-02 06:48:49 +02:00
|
|
|
NetExpr*tmp = pe->elaborate_expr(des, scope, expr_wid, false);
|
2001-02-11 03:15:52 +01:00
|
|
|
if (tmp == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2007-03-08 06:30:02 +01:00
|
|
|
if (NetExpr*tmp2 = tmp->eval_tree(prune_width)) {
|
2001-02-11 03:15:52 +01:00
|
|
|
delete tmp;
|
|
|
|
|
tmp = tmp2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-02 05:42:12 +02:00
|
|
|
std::list<hname_t> eval_scope_path(Design*des, NetScope*scope,
|
|
|
|
|
const pform_name_t&path)
|
|
|
|
|
{
|
|
|
|
|
list<hname_t> res;
|
|
|
|
|
|
|
|
|
|
typedef pform_name_t::const_iterator pform_path_it;
|
|
|
|
|
|
|
|
|
|
for (pform_path_it cur = path.begin() ; cur != path.end(); cur++) {
|
|
|
|
|
const name_component_t&comp = *cur;
|
|
|
|
|
if (comp.index.empty()) {
|
|
|
|
|
res.push_back(hname_t(comp.name));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(comp.index.size() == 1);
|
|
|
|
|
const index_component_t&index = comp.index.front();
|
|
|
|
|
assert(index.sel == index_component_t::SEL_BIT);
|
|
|
|
|
|
|
|
|
|
NetExpr*tmp = elab_and_eval(des, scope, index.msb, -1);
|
|
|
|
|
ivl_assert(*index.msb, tmp);
|
|
|
|
|
|
|
|
|
|
if (NetEConst*ctmp = dynamic_cast<NetEConst*>(tmp)) {
|
|
|
|
|
res.push_back(hname_t(comp.name, ctmp->value().as_long()));
|
|
|
|
|
delete ctmp;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2001-02-11 03:15:52 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: netmisc.cc,v $
|
2007-06-02 05:42:12 +02:00
|
|
|
* Revision 1.14 2007/06/02 03:42:13 steve
|
|
|
|
|
* Properly evaluate scope path expressions.
|
|
|
|
|
*
|
2007-03-08 06:30:02 +01:00
|
|
|
* Revision 1.13 2007/03/08 05:30:03 steve
|
|
|
|
|
* Limit the calculated widths of constants.
|
|
|
|
|
*
|
2006-06-02 06:48:49 +02:00
|
|
|
* Revision 1.12 2006/06/02 04:48:50 steve
|
|
|
|
|
* Make elaborate_expr methods aware of the width that the context
|
|
|
|
|
* requires of it. In the process, fix sizing of the width of unary
|
|
|
|
|
* minus is context determined sizes.
|
|
|
|
|
*
|
2005-04-08 06:50:31 +02:00
|
|
|
* Revision 1.11 2005/04/08 04:50:31 steve
|
|
|
|
|
* Don not give to make_add express an unwanted width.
|
|
|
|
|
*
|
2005-01-24 06:28:30 +01:00
|
|
|
* Revision 1.10 2005/01/24 05:28:31 steve
|
|
|
|
|
* Remove the NetEBitSel and combine all bit/part select
|
|
|
|
|
* behavior into the NetESelect node and IVL_EX_SELECT
|
|
|
|
|
* ivl_target expression type.
|
2001-02-11 03:15:52 +01:00
|
|
|
*/
|
|
|
|
|
|