2 * Copyright (c) 1998-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)
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
25 * The emit function is called to generate the output required of the
34 bool NetNode::emit_node(struct target_t
*tgt
) const
36 cerr
<< "EMIT: Gate type? " << typeid(*this).name() << endl
;
40 bool NetLogic::emit_node(struct target_t
*tgt
) const
46 bool NetUDP::emit_node(struct target_t
*tgt
) const
52 bool NetAbs::emit_node(struct target_t
*tgt
) const
58 bool NetAddSub::emit_node(struct target_t
*tgt
) const
60 tgt
->lpm_add_sub(this);
64 bool NetArrayDq::emit_node(struct target_t
*tgt
) const
66 return tgt
->lpm_array_dq(this);
69 bool NetCaseCmp::emit_node(struct target_t
*tgt
) const
71 tgt
->net_case_cmp(this);
75 bool NetCLShift::emit_node(struct target_t
*tgt
) const
77 tgt
->lpm_clshift(this);
81 bool NetCompare::emit_node(struct target_t
*tgt
) const
83 tgt
->lpm_compare(this);
87 bool NetConcat::emit_node(struct target_t
*tgt
) const
89 return tgt
->concat(this);
92 bool NetConst::emit_node(struct target_t
*tgt
) const
94 return tgt
->net_const(this);
97 bool NetDivide::emit_node(struct target_t
*tgt
) const
99 tgt
->lpm_divide(this);
103 bool NetFF::emit_node(struct target_t
*tgt
) const
109 bool NetLiteral::emit_node(struct target_t
*tgt
) const
111 return tgt
->net_literal(this);
114 bool NetModulo::emit_node(struct target_t
*tgt
) const
116 tgt
->lpm_modulo(this);
120 bool NetMult::emit_node(struct target_t
*tgt
) const
126 bool NetMux::emit_node(struct target_t
*tgt
) const
132 bool NetPartSelect::emit_node(struct target_t
*tgt
) const
134 return tgt
->part_select(this);
137 bool NetPow::emit_node(struct target_t
*tgt
) const
143 bool NetReplicate::emit_node(struct target_t
*tgt
) const
145 return tgt
->replicate(this);
148 bool NetSignExtend::emit_node(struct target_t
*tgt
) const
150 return tgt
->sign_extend(this);
153 bool NetUReduce::emit_node(struct target_t
*tgt
) const
155 return tgt
->ureduce(this);
158 bool NetSysFunc::emit_node(struct target_t
*tgt
) const
160 return tgt
->net_sysfunction(this);
163 bool NetUserFunc::emit_node(struct target_t
*tgt
) const
165 return tgt
->net_function(this);
168 bool NetTran::emit_node(struct target_t
*tgt
) const
170 return tgt
->tran(this);
173 bool NetBUFZ::emit_node(struct target_t
*tgt
) const
175 return tgt
->bufz(this);
178 bool NetProcTop::emit(struct target_t
*tgt
) const
180 return tgt
->process(this);
183 bool NetProc::emit_proc(struct target_t
*tgt
) const
185 cerr
<< "EMIT: Proc type? " << typeid(*this).name() << endl
;
189 bool NetAssign::emit_proc(struct target_t
*tgt
) const
191 tgt
->proc_assign(this);
195 bool NetAssignNB::emit_proc(struct target_t
*tgt
) const
197 tgt
->proc_assign_nb(this);
201 bool NetBlock::emit_proc(struct target_t
*tgt
) const
203 return tgt
->proc_block(this);
206 bool NetCase::emit_proc(struct target_t
*tgt
) const
208 tgt
->proc_case(this);
212 bool NetCAssign::emit_proc(struct target_t
*tgt
) const
214 return tgt
->proc_cassign(this);
217 bool NetCondit::emit_proc(struct target_t
*tgt
) const
219 return tgt
->proc_condit(this);
222 bool NetDeassign::emit_proc(struct target_t
*tgt
) const
224 return tgt
->proc_deassign(this);
227 bool NetDisable::emit_proc(struct target_t
*tgt
) const
229 return tgt
->proc_disable(this);
232 bool NetForce::emit_proc(struct target_t
*tgt
) const
234 return tgt
->proc_force(this);
237 bool NetForever::emit_proc(struct target_t
*tgt
) const
239 tgt
->proc_forever(this);
243 bool NetPDelay::emit_proc(struct target_t
*tgt
) const
245 return tgt
->proc_delay(this);
248 bool NetPDelay::emit_proc_recurse(struct target_t
*tgt
) const
250 if (statement_
) return statement_
->emit_proc(tgt
);
254 bool NetRelease::emit_proc(struct target_t
*tgt
) const
256 return tgt
->proc_release(this);
259 bool NetRepeat::emit_proc(struct target_t
*tgt
) const
261 tgt
->proc_repeat(this);
265 bool NetSTask::emit_proc(struct target_t
*tgt
) const
267 tgt
->proc_stask(this);
271 bool NetUTask::emit_proc(struct target_t
*tgt
) const
273 tgt
->proc_utask(this);
277 bool NetWhile::emit_proc(struct target_t
*tgt
) const
279 tgt
->proc_while(this);
283 void NetBlock::emit_recurse(struct target_t
*tgt
) const
292 } while (cur
!= last_
);
295 bool NetCondit::emit_recurse_if(struct target_t
*tgt
) const
298 return if_
->emit_proc(tgt
);
303 bool NetCondit::emit_recurse_else(struct target_t
*tgt
) const
306 return else_
->emit_proc(tgt
);
311 bool NetEvProbe::emit_node(struct target_t
*tgt
) const
313 tgt
->net_probe(this);
317 bool NetEvTrig::emit_proc(struct target_t
*tgt
) const
319 return tgt
->proc_trigger(this);
322 bool NetEvWait::emit_proc(struct target_t
*tgt
) const
324 return tgt
->proc_wait(this);
327 bool NetEvWait::emit_recurse(struct target_t
*tgt
) const
329 if (!statement_
) return true;
330 return statement_
->emit_proc(tgt
);
333 void NetForever::emit_recurse(struct target_t
*tgt
) const
336 statement_
->emit_proc(tgt
);
339 void NetRepeat::emit_recurse(struct target_t
*tgt
) const
342 statement_
->emit_proc(tgt
);
345 void NetScope::emit_scope(struct target_t
*tgt
) const
349 for (NetEvent
*cur
= events_
; cur
; cur
= cur
->snext_
)
352 for (NetScope
*cur
= sub_
; cur
; cur
= cur
->sib_
)
353 cur
->emit_scope(tgt
);
356 NetNet
*cur
= signals_
->sig_next_
;
359 cur
= cur
->sig_next_
;
360 } while (cur
!= signals_
->sig_next_
);
362 /* Run the signals again, but this time to connect the
363 delay paths. This is done as a second pass because
364 the paths reference other signals that may be later
365 in the list. We can do it here becase delay paths are
366 always connected within the scope. */
367 cur
= signals_
->sig_next_
;
369 tgt
->signal_paths(cur
);
370 cur
= cur
->sig_next_
;
371 } while (cur
!= signals_
->sig_next_
);
376 bool NetScope::emit_defs(struct target_t
*tgt
) const
382 for (NetScope
*cur
= sub_
; cur
; cur
= cur
->sib_
)
383 flag
&= cur
->emit_defs(tgt
);
387 flag
&= tgt
->func_def(this);
392 default: /* BEGIN_END and FORK_JOIN, GENERATE... */
393 for (NetScope
*cur
= sub_
; cur
; cur
= cur
->sib_
)
394 flag
&= cur
->emit_defs(tgt
);
401 void NetWhile::emit_proc_recurse(struct target_t
*tgt
) const
403 proc_
->emit_proc(tgt
);
406 int Design::emit(struct target_t
*tgt
) const
410 if (tgt
->start_design(this) == false)
413 // enumerate the scopes
414 for (list
<NetScope
*>::const_iterator scope
= root_scopes_
.begin();
415 scope
!= root_scopes_
.end(); scope
++)
416 (*scope
)->emit_scope(tgt
);
420 bool nodes_rc
= true;
422 NetNode
*cur
= nodes_
->node_next_
;
424 nodes_rc
= nodes_rc
&& cur
->emit_node(tgt
);
425 cur
= cur
->node_next_
;
426 } while (cur
!= nodes_
->node_next_
);
430 // emit task and function definitions
431 bool tasks_rc
= true;
432 for (list
<NetScope
*>::const_iterator scope
= root_scopes_
.begin();
433 scope
!= root_scopes_
.end(); scope
++)
434 tasks_rc
&= (*scope
)->emit_defs(tgt
);
437 // emit the processes
439 for (const NetProcTop
*idx
= procs_
; idx
; idx
= idx
->next_
)
440 proc_rc
&= idx
->emit(tgt
);
442 rc
= tgt
->end_design(this);
444 if (nodes_rc
== false)
446 if (tasks_rc
== false)
448 if (proc_rc
== false)
454 void NetEBinary::expr_scan(struct expr_scan_t
*tgt
) const
456 tgt
->expr_binary(this);
459 void NetEConcat::expr_scan(struct expr_scan_t
*tgt
) const
461 tgt
->expr_concat(this);
464 void NetEConst::expr_scan(struct expr_scan_t
*tgt
) const
466 tgt
->expr_const(this);
469 void NetEConstParam::expr_scan(struct expr_scan_t
*tgt
) const
471 tgt
->expr_param(this);
474 void NetECReal::expr_scan(struct expr_scan_t
*tgt
) const
476 tgt
->expr_creal(this);
479 void NetECRealParam::expr_scan(struct expr_scan_t
*tgt
) const
481 tgt
->expr_rparam(this);
484 void NetEParam::expr_scan(struct expr_scan_t
*tgt
) const
486 cerr
<< get_fileline() << ":internal error: unexpected NetEParam."
490 void NetEEvent::expr_scan(struct expr_scan_t
*tgt
) const
492 tgt
->expr_event(this);
495 void NetEScope::expr_scan(struct expr_scan_t
*tgt
) const
497 tgt
->expr_scope(this);
500 void NetESelect::expr_scan(struct expr_scan_t
*tgt
) const
502 tgt
->expr_select(this);
505 void NetESFunc::expr_scan(struct expr_scan_t
*tgt
) const
507 tgt
->expr_sfunc(this);
510 void NetEUFunc::expr_scan(struct expr_scan_t
*tgt
) const
512 tgt
->expr_ufunc(this);
515 void NetESignal::expr_scan(struct expr_scan_t
*tgt
) const
517 tgt
->expr_signal(this);
520 void NetETernary::expr_scan(struct expr_scan_t
*tgt
) const
522 tgt
->expr_ternary(this);
525 void NetEUnary::expr_scan(struct expr_scan_t
*tgt
) const
527 tgt
->expr_unary(this);
530 int emit(const Design
*des
, const char*type
)
532 for (unsigned idx
= 0 ; target_table
[idx
] ; idx
+= 1) {
533 const struct target
*tgt
= target_table
[idx
];
534 if (strcmp(tgt
->name
, type
) == 0)
535 return des
->emit(tgt
->meth
);
539 cerr
<< "error: Code generator type " << type
540 << " not found." << endl
;