Fix for assertion error when expanding macro.
[iverilog.git] / pform_dump.cc
blobddab6468aae4d6b631045dfdf34fe717bd28c164
1 /*
2 * Copyright (c) 1998-2006 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"
23 * This file provides the pform_dump function, that dumps the module
24 * passed as a parameter. The dump is as much as possible in Verilog
25 * syntax, so that a human can tell that it really does describe the
26 * module in question.
28 # include "pform.h"
29 # include "PEvent.h"
30 # include "PGenerate.h"
31 # include "PSpec.h"
32 # include <iostream>
33 # include <iomanip>
34 # include <typeinfo>
36 ostream& operator << (ostream&out, const PExpr&obj)
38 obj.dump(out);
39 return out;
42 ostream& operator << (ostream&o, const PDelays&d)
44 d.dump_delays(o);
45 return o;
48 ostream& operator<< (ostream&o, PGate::strength_t str)
50 switch (str) {
51 case PGate::HIGHZ:
52 o << "highz";
53 break;
54 case PGate::WEAK:
55 o << "weak";
56 break;
57 case PGate::PULL:
58 o << "pull";
59 break;
60 case PGate::STRONG:
61 o << "strong";
62 break;
63 case PGate::SUPPLY:
64 o << "supply";
65 break;
66 default:
67 assert(0);
69 return o;
72 ostream& operator<< (ostream&out, perm_string that)
74 out << that.str();
75 return out;
78 ostream& operator<< (ostream&out, const index_component_t&that)
80 out << "[";
81 switch (that.sel) {
82 case index_component_t::SEL_BIT:
83 out << *that.msb;
84 break;
85 case index_component_t::SEL_PART:
86 out << *that.msb << ":" << *that.lsb;
87 break;
88 case index_component_t::SEL_IDX_UP:
89 out << *that.msb << "+:" << *that.lsb;
90 break;
91 case index_component_t::SEL_IDX_DO:
92 out << *that.msb << "-:" << *that.lsb;
93 break;
94 default:
95 out << "???";
96 break;
98 out << "]";
99 return out;
102 ostream& operator<< (ostream&out, const name_component_t&that)
104 out << that.name.str();
106 typedef std::list<index_component_t>::const_iterator index_it_t;
107 for (index_it_t idx = that.index.begin()
108 ; idx != that.index.end() ; idx++) {
110 out << *idx;
112 return out;
115 ostream& operator<< (ostream&o, const pform_name_t&that)
117 pform_name_t::const_iterator cur;
119 cur = that.begin();
120 o << *cur;
122 cur++;
123 while (cur != that.end()) {
124 o << "." << *cur;
125 cur++;
128 return o;
131 void PExpr::dump(ostream&out) const
133 out << typeid(*this).name();
136 void PEConcat::dump(ostream&out) const
138 if (repeat_)
139 out << "{" << *repeat_;
141 if (parms_.count() == 0) {
142 out << "{}";
143 return;
146 out << "{";
147 if (parms_[0]) out << *parms_[0];
148 for (unsigned idx = 1 ; idx < parms_.count() ; idx += 1) {
149 out << ", ";
150 if (parms_[idx]) out << *parms_[idx];
153 out << "}";
155 if (repeat_) out << "}";
158 void PECallFunction::dump(ostream &out) const
160 out << path_ << "(";
162 if (parms_.count() > 0) {
163 if (parms_[0]) parms_[0]->dump(out);
164 for (unsigned idx = 1; idx < parms_.count(); ++idx) {
165 out << ", ";
166 if (parms_[idx]) parms_[idx]->dump(out);
169 out << ")";
172 void PEEvent::dump(ostream&out) const
174 switch (type_) {
175 case PEEvent::ANYEDGE:
176 break;
177 case PEEvent::POSEDGE:
178 out << "posedge ";
179 break;
180 case PEEvent::NEGEDGE:
181 out << "negedge ";
182 break;
183 case PEEvent::POSITIVE:
184 out << "positive ";
185 break;
187 out << *expr_;
191 void PEFNumber::dump(ostream &out) const
193 out << value();
196 void PENumber::dump(ostream&out) const
198 out << value();
201 void PEIdent::dump(ostream&out) const
203 out << path_;
206 void PEString::dump(ostream&out) const
208 out << "\"" << text_ << "\"";
211 void PETernary::dump(ostream&out) const
213 out << "(" << *expr_ << ")?(" << *tru_ << "):(" << *fal_ << ")";
216 void PEUnary::dump(ostream&out) const
218 out << op_ << "(" << *expr_ << ")";
221 void PEBinary::dump(ostream&out) const
223 out << "(" << *left_ << ")";
224 switch (op_) {
225 case 'a':
226 out << "&&";
227 break;
228 case 'e':
229 out << "==";
230 break;
231 case 'E':
232 out << "===";
233 break;
234 case 'l':
235 out << "<<";
236 break;
237 case 'n':
238 out << "!=";
239 break;
240 case 'N':
241 out << "!==";
242 break;
243 case 'R':
244 out << ">>>";
245 break;
246 case 'r':
247 out << ">>";
248 break;
249 default:
250 out << op_;
251 break;
253 out << "(" << *right_ << ")";
257 void PWire::dump(ostream&out, unsigned ind) const
259 out << setw(ind) << "" << type_;
261 switch (port_type_) {
262 case NetNet::PIMPLICIT:
263 out << " implicit input";
264 break;
265 case NetNet::PINPUT:
266 out << " input";
267 break;
268 case NetNet::POUTPUT:
269 out << " output";
270 break;
271 case NetNet::PINOUT:
272 out << " inout";
273 break;
274 case NetNet::NOT_A_PORT:
275 break;
278 out << " " << data_type_;
280 if (signed_) {
281 out << " signed";
284 if (port_set_) {
285 if (port_msb_ == 0) {
286 out << " port<scalar>";
287 } else {
288 out << " port[" << *port_msb_ << ":" << *port_lsb_ << "]";
291 if (net_set_) {
292 if (net_msb_ == 0) {
293 out << " net<scalar>";
294 } else {
295 out << " net[" << *net_msb_ << ":" << *net_lsb_ << "]";
299 out << " " << hname_;
301 // If the wire has indices, dump them.
302 if (lidx_ || ridx_) {
303 out << "[";
304 if (lidx_) out << *lidx_;
305 if (ridx_) out << ":" << *ridx_;
306 out << "]";
309 out << ";" << endl;
310 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
311 ; idx != attributes.end()
312 ; idx ++) {
313 out << " " << (*idx).first;
314 if ((*idx).second)
315 out << " = " << *(*idx).second;
316 out << endl;
320 void PGate::dump_pins(ostream&out) const
322 if (pin_count()) {
323 if (pin(0)) out << *pin(0);
325 for (unsigned idx = 1 ; idx < pin_count() ; idx += 1) {
326 out << ", ";
327 if (pin(idx)) out << *pin(idx);
332 void PDelays::dump_delays(ostream&out) const
334 if (delay_[0] && delay_[1] && delay_[2])
335 out << "#(" << *delay_[0] << "," << *delay_[1] << "," <<
336 *delay_[2] << ")";
337 else if (delay_[0])
338 out << "#" << *delay_[0];
339 else
340 out << "#0";
344 void PGate::dump_delays(ostream&out) const
346 delay_.dump_delays(out);
349 void PGate::dump(ostream&out, unsigned ind) const
351 out << setw(ind) << "" << typeid(*this).name() << " ";
352 delay_.dump_delays(out);
353 out << " " << get_name() << "(";
354 dump_pins(out);
355 out << ");" << endl;
359 void PGAssign::dump(ostream&out, unsigned ind) const
361 out << setw(ind) << "";
362 out << "assign (" << strength0() << "0 " << strength1() << "1) ";
363 dump_delays(out);
364 out << " " << *pin(0) << " = " << *pin(1) << ";" << endl;
367 void PGBuiltin::dump(ostream&out, unsigned ind) const
369 out << setw(ind) << "";
370 switch (type()) {
371 case PGBuiltin::BUFIF0:
372 out << "bufif0 ";
373 break;
374 case PGBuiltin::BUFIF1:
375 out << "bufif1 ";
376 break;
377 case PGBuiltin::NOTIF0:
378 out << "bufif0 ";
379 break;
380 case PGBuiltin::NOTIF1:
381 out << "bufif1 ";
382 break;
383 case PGBuiltin::NAND:
384 out << "nand ";
385 break;
386 case PGBuiltin::NMOS:
387 out << "nmos ";
388 break;
389 case PGBuiltin::RNMOS:
390 out << "rnmos ";
391 break;
392 case PGBuiltin::RPMOS:
393 out << "rpmos ";
394 break;
395 case PGBuiltin::PMOS:
396 out << "pmos ";
397 break;
398 case PGBuiltin::RCMOS:
399 out << "rcmos ";
400 break;
401 case PGBuiltin::CMOS:
402 out << "cmos ";
403 break;
404 default:
405 out << "builtin gate ";
408 out << "(" << strength0() << "0 " << strength1() << "1) ";
409 dump_delays(out);
410 out << " " << get_name();
412 if (msb_) {
413 out << " [" << *msb_ << ":" << *lsb_ << "]";
416 out << "(";
417 dump_pins(out);
418 out << ");" << endl;
421 void PGModule::dump(ostream&out, unsigned ind) const
423 out << setw(ind) << "" << type_ << " ";
425 // If parameters are overridden by order, dump them.
426 if (overrides_ && overrides_->count() > 0) {
427 assert(parms_ == 0);
428 out << "#(";
430 if ((*overrides_)[0] == 0)
431 out << "<nil>";
432 else
433 out << *((*overrides_)[0]);
434 for (unsigned idx = 1 ; idx < overrides_->count() ; idx += 1) {
435 out << "," << *((*overrides_)[idx]);
437 out << ") ";
440 // If parameters are overridden by name, dump them.
441 if (parms_) {
442 assert(overrides_ == 0);
443 out << "#(";
444 out << "." << parms_[0].name << "(" << *parms_[0].parm << ")";
445 for (unsigned idx = 1 ; idx < nparms_ ; idx += 1) {
446 out << ", ." << parms_[idx].name << "(" <<
447 *parms_[idx].parm << ")";
449 out << ") ";
452 out << get_name();
454 // If the module is arrayed, print the index expressions.
455 if (msb_ || lsb_) {
456 out << "[";
457 if (msb_) out << *msb_;
458 out << ":";
459 if (lsb_) out << *lsb_;
460 out << "]";
463 out << "(";
464 if (pins_) {
465 out << "." << pins_[0].name << "(";
466 if (pins_[0].parm) out << *pins_[0].parm;
467 out << ")";
468 for (unsigned idx = 1 ; idx < npins_ ; idx += 1) {
469 out << ", ." << pins_[idx].name << "(";
470 if (pins_[idx].parm)
471 out << *pins_[idx].parm;
472 out << ")";
474 } else {
475 dump_pins(out);
477 out << ");" << endl;
480 void Statement::dump(ostream&out, unsigned ind) const
482 /* I give up. I don't know what type this statement is,
483 so just print the C++ typeid and let the user figure
484 it out. */
485 out << setw(ind) << "";
486 out << "/* " << get_line() << ": " << typeid(*this).name()
487 << " */ ;" << endl;
490 void PAssign::dump(ostream&out, unsigned ind) const
492 out << setw(ind) << "";
493 out << *lval() << " = " << delay_ << " " << *rval() << ";";
494 out << " /* " << get_line() << " */" << endl;
497 void PAssignNB::dump(ostream&out, unsigned ind) const
499 out << setw(ind) << "";
500 out << *lval() << " <= " << delay_ << " " << *rval() << ";";
501 out << " /* " << get_line() << " */" << endl;
504 void PBlock::dump(ostream&out, unsigned ind) const
506 out << setw(ind) << "" << "begin";
507 if (name_ != 0)
508 out << " : " << name_;
509 out << endl;
511 for (unsigned idx = 0 ; idx < list_.count() ; idx += 1) {
512 if (list_[idx])
513 list_[idx]->dump(out, ind+2);
514 else
515 out << setw(ind+2) << "" << "/* NOOP */ ;" << endl;
518 out << setw(ind) << "" << "end" << endl;
521 void PCallTask::dump(ostream&out, unsigned ind) const
523 out << setw(ind) << "" << path_;
525 if (parms_.count() > 0) {
526 out << "(";
527 if (parms_[0])
528 out << *parms_[0];
530 for (unsigned idx = 1 ; idx < parms_.count() ; idx += 1) {
531 out << ", ";
532 if (parms_[idx])
533 out << *parms_[idx];
535 out << ")";
538 out << "; /* " << get_line() << " */" << endl;
541 void PCase::dump(ostream&out, unsigned ind) const
543 out << setw(ind) << "";
544 switch (type_) {
545 case NetCase::EQ:
546 out << "case";
547 break;
548 case NetCase::EQX:
549 out << "casex";
550 break;
551 case NetCase::EQZ:
552 out << "casez";
553 break;
555 out << " (" << *expr_ << ") /* " << get_line() << " */" << endl;
557 for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
558 PCase::Item*cur = (*items_)[idx];
560 if (cur->expr.count() == 0) {
561 out << setw(ind+2) << "" << "default:";
563 } else {
564 out << setw(ind+2) << "" << *cur->expr[0];
566 for(unsigned e = 1 ; e < cur->expr.count() ; e += 1)
567 out << ", " << *cur->expr[e];
569 out << ":";
572 if (cur->stat) {
573 out << endl;
574 cur->stat->dump(out, ind+6);
575 } else {
576 out << " ;" << endl;
580 out << setw(ind) << "" << "endcase" << endl;
583 void PCondit::dump(ostream&out, unsigned ind) const
585 out << setw(ind) << "" << "if (" << *expr_ << ")" << endl;
586 if (if_)
587 if_->dump(out, ind+3);
588 else
589 out << setw(ind) << ";" << endl;
590 if (else_) {
591 out << setw(ind) << "" << "else" << endl;
592 else_->dump(out, ind+3);
596 void PCAssign::dump(ostream&out, unsigned ind) const
598 out << setw(ind) << "" << "assign " << *lval_ << " = " << *expr_
599 << "; /* " << get_line() << " */" << endl;
602 void PDeassign::dump(ostream&out, unsigned ind) const
604 out << setw(ind) << "" << "deassign " << *lval_ << "; /* "
605 << get_line() << " */" << endl;
608 void PDelayStatement::dump(ostream&out, unsigned ind) const
610 out << setw(ind) << "" << "#" << *delay_ << " /* " <<
611 get_line() << " */";
612 if (statement_) {
613 out << endl;
614 statement_->dump(out, ind+2);
615 } else {
616 out << " /* noop */;" << endl;
620 void PDisable::dump(ostream&out, unsigned ind) const
622 out << setw(ind) << "" << "disable " << scope_ << "; /* "
623 << get_line() << " */" << endl;
626 void PEventStatement::dump(ostream&out, unsigned ind) const
628 if (expr_.count() == 0) {
629 out << setw(ind) << "" << "@* ";
631 } else {
632 out << setw(ind) << "" << "@(" << *(expr_[0]);
633 if (expr_.count() > 1)
634 for (unsigned idx = 1 ; idx < expr_.count() ; idx += 1)
635 out << " or " << *(expr_[idx]);
637 out << ")";
640 if (statement_) {
641 out << endl;
642 statement_->dump(out, ind+2);
643 } else {
644 out << " ;" << endl;
648 void PForce::dump(ostream&out, unsigned ind) const
650 out << setw(ind) << "" << "force " << *lval_ << " = " << *expr_
651 << "; /* " << get_line() << " */" << endl;
654 void PForever::dump(ostream&out, unsigned ind) const
656 out << setw(ind) << "" << "forever /* " << get_line() << " */" << endl;
657 statement_->dump(out, ind+3);
660 void PForStatement::dump(ostream&out, unsigned ind) const
662 out << setw(ind) << "" << "for (" << *name1_ << " = " << *expr1_
663 << "; " << *cond_ << "; " << *name2_ << " = " << *expr2_ <<
664 ")" << endl;
665 statement_->dump(out, ind+3);
668 void PFunction::dump(ostream&out, unsigned ind) const
670 out << setw(ind) << "" << "function ";
671 switch (return_type_.type) {
672 case PTF_NONE:
673 out << "?none? ";
674 break;
675 case PTF_REG:
676 out << "reg ";
677 break;
678 case PTF_REG_S:
679 out << "reg_s ";
680 break;
681 case PTF_INTEGER:
682 out << "integer ";
683 break;
684 case PTF_REAL:
685 out << "real ";
686 break;
687 case PTF_REALTIME:
688 out << "realtime ";
689 break;
690 case PTF_TIME:
691 out << "time ";
692 break;
695 if (return_type_.range) {
696 out << "[";
697 out << "] ";
700 out << name_ << ";" << endl;
702 if (ports_)
703 for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
704 out << setw(ind) << "";
705 out << "input ";
706 out << (*ports_)[idx]->path() << ";" << endl;
709 if (statement_)
710 statement_->dump(out, ind);
711 else
712 out << setw(ind) << "" << "/* NOOP */" << endl;
715 void PRelease::dump(ostream&out, unsigned ind) const
717 out << setw(ind) << "" << "release " << *lval_ << "; /* "
718 << get_line() << " */" << endl;
721 void PRepeat::dump(ostream&out, unsigned ind) const
723 out << setw(ind) << "" << "repeat (" << *expr_ << ")" << endl;
724 statement_->dump(out, ind+3);
727 void PTask::dump(ostream&out, unsigned ind) const
729 if (ports_)
730 for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
731 out << setw(ind) << "";
732 switch ((*ports_)[idx]->get_port_type()) {
733 case NetNet::PINPUT:
734 out << "input ";
735 break;
736 case NetNet::POUTPUT:
737 out << "output ";
738 break;
739 case NetNet::PINOUT:
740 out << "inout ";
741 break;
742 default:
743 assert(0);
744 break;
746 out << (*ports_)[idx]->path() << ";" << endl;
749 if (statement_)
750 statement_->dump(out, ind);
751 else
752 out << setw(ind) << "" << "/* NOOP */" << endl;
755 void PTrigger::dump(ostream&out, unsigned ind) const
757 out << setw(ind) << "" << "-> " << event_ << ";" << endl;
760 void PWhile::dump(ostream&out, unsigned ind) const
762 out << setw(ind) << "" << "while (" << *cond_ << ")" << endl;
763 statement_->dump(out, ind+3);
766 void PProcess::dump(ostream&out, unsigned ind) const
768 switch (type_) {
769 case PProcess::PR_INITIAL:
770 out << setw(ind) << "" << "initial";
771 break;
772 case PProcess::PR_ALWAYS:
773 out << setw(ind) << "" << "always";
774 break;
777 out << " /* " << get_line() << " */" << endl;
779 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
780 ; idx != attributes.end() ; idx++ ) {
782 out << setw(ind+2) << "" << "(* " << (*idx).first;
783 if ((*idx).second) {
784 out << " = " << *(*idx).second;
786 out << " *)" << endl;
789 statement_->dump(out, ind+2);
792 void PSpecPath::dump(std::ostream&out, unsigned ind) const
794 out << setw(ind) << "" << "specify path ";
796 if (condition)
797 out << "if (" << *condition << ") ";
799 out << "(";
800 if (edge) {
801 if (edge > 0)
802 out << "posedge ";
803 else
804 out << "negedge ";
807 for (unsigned idx = 0 ; idx < src.size() ; idx += 1) {
808 if (idx > 0) out << ", ";
809 assert(src[idx]);
810 out << src[idx];
813 out << " => ";
815 if (data_source_expression)
816 out << "(";
818 for (unsigned idx = 0 ; idx < dst.size() ; idx += 1) {
819 if (idx > 0) out << ", ";
820 assert(dst[idx]);
821 out << dst[idx];
824 if (data_source_expression)
825 out << " : " << *data_source_expression << ")";
827 out << ") = (";
828 for (unsigned idx = 0 ; idx < delays.size() ; idx += 1) {
829 if (idx > 0) out << ", ";
830 assert(delays[idx]);
831 out << *delays[idx];
833 out << ");" << endl;
836 void PGenerate::dump(ostream&out, unsigned indent) const
838 out << setw(indent) << "" << "generate(" << id_number << ")";
840 switch (scheme_type) {
841 case GS_NONE:
842 break;
843 case GS_LOOP:
844 out << " for ("
845 << loop_index
846 << "=" << *loop_init
847 << "; " << *loop_test
848 << "; " << loop_index
849 << "=" << *loop_step << ")";
850 break;
851 case GS_CONDIT:
852 out << " if (" << *loop_test << ")";
853 break;
854 case GS_ELSE:
855 out << " else !(" << *loop_test << ")";
856 break;
859 if (scope_name)
860 out << " : " << scope_name;
862 out << endl;
864 for (map<pform_name_t,PWire*>::const_iterator idx = wires.begin()
865 ; idx != wires.end() ; idx++) {
867 (*idx).second->dump(out, indent+2);
870 for (list<PGate*>::const_iterator idx = gates.begin()
871 ; idx != gates.end() ; idx++) {
872 (*idx)->dump(out, indent+2);
875 for (list<PProcess*>::const_iterator idx = behaviors.begin()
876 ; idx != behaviors.end() ; idx++) {
877 (*idx)->dump(out, indent+2);
880 for (list<PGenerate*>::const_iterator idx = generates.begin()
881 ; idx != generates.end() ; idx++) {
882 (*idx)->dump(out, indent+2);
885 out << " endgenerate" << endl;
888 void Module::dump(ostream&out) const
890 if (attributes.begin() != attributes.end()) {
891 out << "(* ";
892 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
893 ; idx != attributes.end() ; idx++ ) {
894 if (idx != attributes.begin()) {
895 out << " , ";
897 out << (*idx).first;
898 if ((*idx).second) {
899 out << " = " << *(*idx).second;
902 out << " *) ";
905 out << "module " << name_ << ";" << endl;
907 for (unsigned idx = 0 ; idx < ports.count() ; idx += 1) {
908 port_t*cur = ports[idx];
910 if (cur == 0) {
911 out << " unconnected" << endl;
912 continue;
915 out << " ." << cur->name << "(" << *cur->expr[0];
916 for (unsigned wdx = 1 ; wdx < cur->expr.count() ; wdx += 1) {
917 out << ", " << *cur->expr[wdx];
920 out << ")" << endl;
923 typedef map<perm_string,param_expr_t>::const_iterator parm_iter_t;
924 typedef map<pform_name_t,PExpr*>::const_iterator parm_hiter_t;
925 for (parm_iter_t cur = parameters.begin()
926 ; cur != parameters.end() ; cur ++) {
927 out << " parameter ";
928 if ((*cur).second.signed_flag)
929 out << "signed ";
930 if ((*cur).second.msb)
931 out << "[" << *(*cur).second.msb << ":"
932 << *(*cur).second.lsb << "] ";
933 out << (*cur).first << " = ";
934 if ((*cur).second.expr)
935 out << *(*cur).second.expr << ";" << endl;
936 else
937 out << "/* ERROR */;" << endl;
940 for (parm_iter_t cur = localparams.begin()
941 ; cur != localparams.end() ; cur ++) {
942 out << " localparam ";
943 if ((*cur).second.msb)
944 out << "[" << *(*cur).second.msb << ":"
945 << *(*cur).second.lsb << "] ";
946 out << (*cur).first << " = ";
947 if ((*cur).second.expr)
948 out << *(*cur).second.expr << ";" << endl;
949 else
950 out << "/* ERROR */;" << endl;
953 typedef list<perm_string>::const_iterator genvar_iter_t;
954 for (genvar_iter_t cur = genvars.begin()
955 ; cur != genvars.end() ; cur++) {
956 out << " genvar " << (*cur) << ";" << endl;
959 typedef list<PGenerate*>::const_iterator genscheme_iter_t;
960 for (genscheme_iter_t cur = generate_schemes.begin()
961 ; cur != generate_schemes.end() ; cur++) {
962 (*cur)->dump(out, 4);
965 typedef map<perm_string,PExpr*>::const_iterator specparm_iter_t;
966 for (specparm_iter_t cur = specparams.begin()
967 ; cur != specparams.end() ; cur ++) {
968 out << " specparam " << (*cur).first << " = "
969 << *(*cur).second << ";" << endl;
972 for (parm_hiter_t cur = defparms.begin()
973 ; cur != defparms.end() ; cur ++) {
974 out << " defparam " << (*cur).first << " = ";
975 if ((*cur).second)
976 out << *(*cur).second << ";" << endl;
977 else
978 out << "/* ERROR */;" << endl;
981 for (map<perm_string,PEvent*>::const_iterator cur = events.begin()
982 ; cur != events.end() ; cur ++ ) {
983 PEvent*ev = (*cur).second;
984 out << " event " << ev->name() << "; // "
985 << ev->get_line() << endl;
988 // Iterate through and display all the wires.
989 for (map<pform_name_t,PWire*>::const_iterator wire = wires_.begin()
990 ; wire != wires_.end()
991 ; wire ++ ) {
993 (*wire).second->dump(out);
996 // Dump the task definitions.
997 typedef map<perm_string,PTask*>::const_iterator task_iter_t;
998 for (task_iter_t cur = tasks_.begin()
999 ; cur != tasks_.end() ; cur ++) {
1000 out << " task " << (*cur).first << ";" << endl;
1001 (*cur).second->dump(out, 6);
1002 out << " endtask;" << endl;
1005 // Dump the function definitions.
1006 typedef map<perm_string,PFunction*>::const_iterator func_iter_t;
1007 for (func_iter_t cur = funcs_.begin()
1008 ; cur != funcs_.end() ; cur ++) {
1009 out << " function " << (*cur).first << ";" << endl;
1010 (*cur).second->dump(out, 6);
1011 out << " endfunction;" << endl;
1015 // Iterate through and display all the gates
1016 for (list<PGate*>::const_iterator gate = gates_.begin()
1017 ; gate != gates_.end()
1018 ; gate ++ ) {
1020 (*gate)->dump(out);
1024 for (list<PProcess*>::const_iterator behav = behaviors_.begin()
1025 ; behav != behaviors_.end()
1026 ; behav ++ ) {
1028 (*behav)->dump(out, 4);
1031 for (list<PSpecPath*>::const_iterator spec = specify_paths.begin()
1032 ; spec != specify_paths.end()
1033 ; spec ++ ) {
1035 (*spec)->dump(out, 4);
1038 out << "endmodule" << endl;
1041 void pform_dump(ostream&out, Module*mod)
1043 mod->dump(out);
1046 void PUdp::dump(ostream&out) const
1048 out << "primitive " << name_ << "(" << ports[0];
1049 for (unsigned idx = 1 ; idx < ports.count() ; idx += 1)
1050 out << ", " << ports[idx];
1051 out << ");" << endl;
1053 if (sequential)
1054 out << " reg " << ports[0] << ";" << endl;
1056 out << " table" << endl;
1057 for (unsigned idx = 0 ; idx < tinput.count() ; idx += 1) {
1058 out << " ";
1059 for (unsigned chr = 0 ; chr < tinput[idx].length() ; chr += 1)
1060 out << " " << tinput[idx][chr];
1062 if (sequential)
1063 out << " : " << tcurrent[idx];
1065 out << " : " << toutput[idx] << " ;" << endl;
1067 out << " endtable" << endl;
1069 if (sequential)
1070 out << " initial " << ports[0] << " = 1'b" << initial
1071 << ";" << endl;
1073 // Dump the attributes for the primitive as attribute
1074 // statements.
1075 for (map<string,PExpr*>::const_iterator idx = attributes.begin()
1076 ; idx != attributes.end()
1077 ; idx ++) {
1078 out << " attribute " << (*idx).first;
1079 if ((*idx).second)
1080 out << " = " << *(*idx).second;
1081 out << endl;
1084 out << "endprimitive" << endl;