Merge branch 'master' into verilog-ams
[sverilog.git] / functor.cc
blob406d0ff9f37646f80151c5e8df8b5a78c7e8569c
1 /*
2 * Copyright (c) 1999-2008 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
20 # include "config.h"
22 # include <iostream>
24 # include "functor.h"
25 # include "netlist.h"
27 functor_t::~functor_t()
31 void functor_t::event(class Design*, class NetEvent*)
35 void functor_t::signal(class Design*, class NetNet*)
39 void functor_t::process(class Design*, class NetProcTop*)
43 void functor_t::lpm_abs(class Design*, class NetAbs*)
47 void functor_t::lpm_add_sub(class Design*, class NetAddSub*)
51 void functor_t::lpm_compare(class Design*, class NetCompare*)
55 void functor_t::lpm_const(class Design*, class NetConst*)
59 void functor_t::lpm_divide(class Design*, class NetDivide*)
63 void functor_t::lpm_literal(class Design*, class NetLiteral*)
67 void functor_t::lpm_modulo(class Design*, class NetModulo*)
71 void functor_t::lpm_ff(class Design*, class NetFF*)
75 void functor_t::lpm_logic(class Design*, class NetLogic*)
79 void functor_t::lpm_mult(class Design*, class NetMult*)
83 void functor_t::lpm_mux(class Design*, class NetMux*)
87 void functor_t::lpm_pow(class Design*, class NetPow*)
91 void functor_t::sign_extend(class Design*, class NetSignExtend*)
95 void functor_t::lpm_ureduce(class Design*, class NetUReduce*)
100 void NetScope::run_functor(Design*des, functor_t*fun)
102 for (NetScope*cur = sub_ ; cur ; cur = cur->sib_) {
103 cur->run_functor(des, fun);
106 for (NetEvent*cur = events_ ; cur ; /* */) {
107 NetEvent*tmp = cur;
108 cur = cur->snext_;
109 fun->event(des, tmp);
112 // apply to signals. Each iteration, allow for the possibility
113 // that the current signal deletes itself.
114 if (signals_) {
115 unsigned count = 0;
116 NetNet*cur = signals_->sig_next_;
117 do {
118 count += 1;
119 cur = cur->sig_next_;
120 } while (cur != signals_->sig_next_);
122 cur = signals_->sig_next_;
123 for (unsigned idx = 0 ; idx < count ; idx += 1) {
124 NetNet*tmp = cur->sig_next_;
125 fun->signal(des, cur);
126 cur = tmp;
131 void Design::functor(functor_t*fun)
133 // Scan the scopes
134 for (list<NetScope*>::const_iterator scope = root_scopes_.begin();
135 scope != root_scopes_.end(); scope++)
136 (*scope)->run_functor(this, fun);
138 // apply to processes
139 procs_idx_ = procs_;
140 while (procs_idx_) {
141 NetProcTop*idx = procs_idx_;
142 procs_idx_ = idx->next_;
143 fun->process(this, idx);
146 // apply to nodes
147 if (nodes_) {
148 assert(nodes_functor_cur_ == 0);
149 assert(nodes_functor_nxt_ == 0);
151 /* Scan the circular list of nodes, starting with the
152 front of the list.
154 This loop interacts with the Design::del_node method
155 so that the functor is free to delete any nodes it
156 choose. The destructors of the NetNode objects call
157 the del_node method, which checks with the
158 nodes_functor_* members, to keep the iterator
159 operating safely. */
160 nodes_functor_cur_ = nodes_;
161 do {
162 nodes_functor_nxt_ = nodes_functor_cur_->node_next_;
163 nodes_functor_cur_->functor_node(this, fun);
165 if (nodes_functor_nxt_ == 0)
166 break;
168 nodes_functor_cur_ = nodes_functor_nxt_;
169 } while (nodes_ && (nodes_functor_cur_ != nodes_));
170 nodes_functor_cur_ = 0;
171 nodes_functor_nxt_ = 0;
177 void NetNode::functor_node(Design*, functor_t*)
181 void NetAbs::functor_node(Design*des, functor_t*fun)
183 fun->lpm_abs(des, this);
186 void NetAddSub::functor_node(Design*des, functor_t*fun)
188 fun->lpm_add_sub(des, this);
191 void NetCompare::functor_node(Design*des, functor_t*fun)
193 fun->lpm_compare(des, this);
196 void NetConst::functor_node(Design*des, functor_t*fun)
198 fun->lpm_const(des, this);
201 void NetDivide::functor_node(Design*des, functor_t*fun)
203 fun->lpm_divide(des, this);
206 void NetFF::functor_node(Design*des, functor_t*fun)
208 fun->lpm_ff(des, this);
211 void NetLiteral::functor_node(Design*des, functor_t*fun)
213 fun->lpm_literal(des, this);
216 void NetLogic::functor_node(Design*des, functor_t*fun)
218 fun->lpm_logic(des, this);
221 void NetModulo::functor_node(Design*des, functor_t*fun)
223 fun->lpm_modulo(des, this);
226 void NetMult::functor_node(Design*des, functor_t*fun)
228 fun->lpm_mult(des, this);
231 void NetMux::functor_node(Design*des, functor_t*fun)
233 fun->lpm_mux(des, this);
236 void NetPow::functor_node(Design*des, functor_t*fun)
238 fun->lpm_pow(des, this);
241 void NetSignExtend::functor_node(Design*des, functor_t*fun)
243 fun->sign_extend(des, this);
246 void NetUReduce::functor_node(Design*des, functor_t*fun)
248 fun->lpm_ureduce(des, this);
251 proc_match_t::~proc_match_t()
255 int NetProc::match_proc(proc_match_t*that)
257 return 0;
260 int proc_match_t::assign(NetAssign*)
262 return 0;
265 int NetAssign::match_proc(proc_match_t*that)
267 return that->assign(this);
270 int proc_match_t::assign_nb(NetAssignNB*)
272 return 0;
275 int NetAssignNB::match_proc(proc_match_t*that)
277 return that->assign_nb(this);
280 int proc_match_t::block(NetBlock*)
282 return 0;
285 int NetBlock::match_proc(proc_match_t*that)
287 return that->block(this);
290 int proc_match_t::condit(NetCondit*)
292 return 0;
295 int NetCondit::match_proc(proc_match_t*that)
297 return that->condit(this);
300 int NetEvWait::match_proc(proc_match_t*that)
302 return that->event_wait(this);
305 int proc_match_t::event_wait(NetEvWait*)
307 return 0;