Reformulate number-to-real on vvp code generator
[iverilog.git] / net_assign.cc
blob485b2cc4588127b16e12c2b4536934eb3ef1cbed
1 /*
2 * Copyright (c) 2000 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: net_assign.cc,v 1.22 2007/01/16 05:44:15 steve Exp $"
21 #endif
23 # include "config.h"
25 # include "netlist.h"
28 * NetAssign
31 unsigned count_lval_width(const NetAssign_*idx)
33 unsigned wid = 0;
34 while (idx) {
35 wid += idx->lwidth();
36 idx = idx->more;
38 return wid;
41 NetAssign_::NetAssign_(NetNet*s)
42 : sig_(s), word_(0), base_(0)
44 lwid_ = sig_->vector_width();
45 sig_->incr_lref();
46 more = 0;
49 NetAssign_::~NetAssign_()
51 if (sig_) {
52 sig_->decr_lref();
53 if (turn_sig_to_wire_on_release_ && sig_->peek_lref() == 0)
54 sig_->type(NetNet::WIRE);
57 assert( more == 0 );
58 if (word_) delete word_;
61 void NetAssign_::set_word(NetExpr*r)
63 assert(word_ == 0);
64 word_ = r;
67 NetExpr* NetAssign_::word()
69 return word_;
72 const NetExpr* NetAssign_::word() const
74 return word_;
77 const NetExpr* NetAssign_::get_base() const
79 return base_;
82 unsigned NetAssign_::lwidth() const
84 return lwid_;
87 perm_string NetAssign_::name() const
89 if (sig_) {
90 return sig_->name();
91 } else {
92 return perm_string::literal("");
96 NetNet* NetAssign_::sig() const
98 return sig_;
101 void NetAssign_::set_part(NetExpr*base, unsigned wid)
103 base_ = base;
104 lwid_ = wid;
109 void NetAssign_::turn_sig_to_wire_on_release()
111 turn_sig_to_wire_on_release_ = true;
114 NetAssignBase::NetAssignBase(NetAssign_*lv, NetExpr*rv)
115 : lval_(lv), rval_(rv), delay_(0)
119 NetAssignBase::~NetAssignBase()
121 if (rval_) delete rval_;
122 while (lval_) {
123 NetAssign_*tmp = lval_;
124 lval_ = tmp->more;
125 tmp->more = 0;
126 delete tmp;
130 NetExpr* NetAssignBase::rval()
132 return rval_;
135 const NetExpr* NetAssignBase::rval() const
137 return rval_;
140 void NetAssignBase::set_rval(NetExpr*r)
142 if (rval_) delete rval_;
143 rval_ = r;
146 NetAssign_* NetAssignBase::l_val(unsigned idx)
148 NetAssign_*cur = lval_;
149 while (idx > 0) {
150 if (cur == 0)
151 return cur;
153 cur = cur->more;
154 idx -= 1;
157 assert(idx == 0);
158 return cur;
161 const NetAssign_* NetAssignBase::l_val(unsigned idx) const
163 const NetAssign_*cur = lval_;
164 while (idx > 0) {
165 if (cur == 0)
166 return cur;
168 cur = cur->more;
169 idx -= 1;
172 assert(idx == 0);
173 return cur;
176 unsigned NetAssignBase::l_val_count() const
178 const NetAssign_*cur = lval_;
179 unsigned cnt = 0;
180 while (cur) {
181 cnt += 1;
182 cur = cur->more;
185 return cnt;
188 unsigned NetAssignBase::lwidth() const
190 unsigned sum = 0;
191 for (NetAssign_*cur = lval_ ; cur ; cur = cur->more)
192 sum += cur->lwidth();
193 return sum;
196 void NetAssignBase::set_delay(NetExpr*expr)
198 delay_ = expr;
201 const NetExpr* NetAssignBase::get_delay() const
203 return delay_;
206 NetAssign::NetAssign(NetAssign_*lv, NetExpr*rv)
207 : NetAssignBase(lv, rv)
211 NetAssign::~NetAssign()
215 NetAssignNB::NetAssignNB(NetAssign_*lv, NetExpr*rv)
216 : NetAssignBase(lv, rv)
220 NetAssignNB::~NetAssignNB()
224 NetCAssign::NetCAssign(NetAssign_*lv, NetExpr*rv)
225 : NetAssignBase(lv, rv)
229 NetCAssign::~NetCAssign()
233 NetDeassign::NetDeassign(NetAssign_*l)
234 : NetAssignBase(l, 0)
238 NetDeassign::~NetDeassign()
242 NetForce::NetForce(NetAssign_*lv, NetExpr*rv)
243 : NetAssignBase(lv, rv)
247 NetForce::~NetForce()
251 NetRelease::NetRelease(NetAssign_*l)
252 : NetAssignBase(l, 0)
256 NetRelease::~NetRelease()
261 * $Log: net_assign.cc,v $
262 * Revision 1.22 2007/01/16 05:44:15 steve
263 * Major rework of array handling. Memories are replaced with the
264 * more general concept of arrays. The NetMemory and NetEMemory
265 * classes are removed from the ivl core program, and the IVL_LPM_RAM
266 * lpm type is removed from the ivl_target API.
268 * Revision 1.21 2006/02/02 02:43:58 steve
269 * Allow part selects of memory words in l-values.
271 * Revision 1.20 2005/07/11 16:56:50 steve
272 * Remove NetVariable and ivl_variable_t structures.
274 * Revision 1.19 2004/12/11 02:31:26 steve
275 * Rework of internals to carry vectors through nexus instead
276 * of single bits. Make the ivl, tgt-vvp and vvp initial changes
277 * down this path.
279 * Revision 1.18 2004/08/28 15:08:31 steve
280 * Do not change reg to wire in NetAssign_ unless synthesizing.
282 * Revision 1.17 2004/02/18 17:11:56 steve
283 * Use perm_strings for named langiage items.
285 * Revision 1.16 2003/01/26 21:15:58 steve
286 * Rework expression parsing and elaboration to
287 * accommodate real/realtime values and expressions.