forked from steveicarus/iverilog
/
netmisc.cc
119 lines (96 loc) · 3.42 KB
/
netmisc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2001-2003 Stephen Williams (steve@icarus.com)
*
* 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
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: netmisc.cc,v 1.8 2004/02/20 18:53:35 steve Exp $"
#endif
# include "config.h"
# include "netlist.h"
# include "netmisc.h"
# include "PExpr.h"
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);
NetConst*val_c = new NetConst(scope, scope->local_symbol(), val_v);
NetNet*val_s = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, width);
val_s->local_flag(true);
NetNet*res = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, width);
res->local_flag(true);
NetAddSub*add = new NetAddSub(scope, scope->local_symbol(), width);
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)
add->attribute(perm_string::literal("LPM_Direction"), verinum("SUB"));
else
add->attribute(perm_string::literal("LPM_Direction"), verinum("ADD"));
des->add_node(add);
des->add_node(val_c);
return res;
}
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;
}
/*
* $Log: netmisc.cc,v $
* Revision 1.8 2004/02/20 18:53:35 steve
* Addtrbute keys are perm_strings.
*
* Revision 1.7 2004/02/18 17:11:57 steve
* Use perm_strings for named langiage items.
*
* Revision 1.6 2003/03/06 00:28:42 steve
* All NetObj objects have lex_string base names.
*
* Revision 1.5 2003/02/26 01:29:24 steve
* LPM objects store only their base names.
*
* Revision 1.4 2002/08/31 03:48:50 steve
* Fix reverse bit ordered bit select in continuous assignment.
*
* Revision 1.3 2002/08/12 01:35:00 steve
* conditional ident string using autoconfig.
*
* Revision 1.2 2001/07/25 03:10:49 steve
* Create a config.h.in file to hold all the config
* junk, and support gcc 3.0. (Stephan Boettcher)
*
* Revision 1.1 2001/02/11 02:15:52 steve
* Add the netmisc.cc source file.
*
*/