2001-02-11 03:15:52 +01:00
|
|
|
/*
|
2010-12-14 02:42:48 +01:00
|
|
|
* Copyright (c) 2001-2010 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
|
|
|
|
|
*/
|
|
|
|
|
|
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"
|
|
|
|
|
|
2002-08-31 05:48:50 +02:00
|
|
|
NetNet* add_to_net(Design*des, NetNet*sig, long val)
|
|
|
|
|
{
|
|
|
|
|
if (val == 0)
|
|
|
|
|
return sig;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-15 05:55:22 +02:00
|
|
|
NetNet* reduction_or(Design*des, NetNet*isig)
|
|
|
|
|
{
|
|
|
|
|
NetScope*scope = isig->scope();
|
|
|
|
|
|
|
|
|
|
NetLogic*olog = new NetLogic(scope, scope->local_symbol(),
|
|
|
|
|
isig->pin_count()+1, NetLogic::OR);
|
|
|
|
|
olog->set_line(*isig);
|
|
|
|
|
des->add_node(olog);
|
|
|
|
|
|
|
|
|
|
NetNet*osig = new NetNet(scope, scope->local_symbol(),
|
|
|
|
|
NetNet::IMPLICIT, 1);
|
|
|
|
|
osig->local_flag(true);
|
|
|
|
|
osig->set_line(*isig);
|
|
|
|
|
|
|
|
|
|
connect(olog->pin(0), osig->pin(0));
|
|
|
|
|
for (unsigned idx = 0 ; idx < isig->pin_count() ; idx += 1)
|
|
|
|
|
connect(olog->pin(1+idx), isig->pin(idx));
|
|
|
|
|
|
|
|
|
|
return osig;
|
|
|
|
|
}
|
2001-02-11 03:15:52 +01:00
|
|
|
|
|
|
|
|
NetExpr* elab_and_eval(Design*des, NetScope*scope, const PExpr*pe)
|
|
|
|
|
{
|
|
|
|
|
NetExpr*tmp = pe->elaborate_expr(des, scope);
|
|
|
|
|
if (tmp == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (NetExpr*tmp2 = tmp->eval_tree()) {
|
|
|
|
|
delete tmp;
|
|
|
|
|
tmp = tmp2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|