Add file and line information for parameters, etc.
[sverilog.git] / pform_dump.cc
blob9bcc7efa3dd41f0ba7299849128fcb47e7f3571f
1 /*
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)
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 switch (op_) {
219 case 'm':
220 out << "abs";
221 break;
222 default:
223 out << op_;
224 break;
226 out << "(" << *expr_ << ")";
229 void PEBinary::dump(ostream&out) const
231 /* Handle some special cases, where the operators are written
232 in function notation. */
233 if (op_ == 'm') {
234 out << "min(" << *left_ << "," << *right_ << ")";
235 return;
237 if (op_ == 'M') {
238 out << "min(" << *left_ << "," << *right_ << ")";
239 return;
242 out << "(" << *left_ << ")";
243 switch (op_) {
244 case 'a':
245 out << "&&";
246 break;
247 case 'e':
248 out << "==";
249 break;
250 case 'E':
251 out << "===";
252 break;
253 case 'l':
254 out << "<<";
255 break;
256 case 'n':
257 out << "!=";
258 break;
259 case 'N':
260 out << "!==";
261 break;
262 case 'R':
263 out << ">>>";
264 break;
265 case 'r':
266 out << ">>";
267 break;
268 default:
269 out << op_;
270 break;
272 out << "(" << *right_ << ")";
276 void PWire::dump(ostream&out, unsigned ind) const
278 out << setw(ind) << "" << type_;
280 switch (port_type_) {
281 case NetNet::PIMPLICIT:
282 out << " implicit input";
283 break;
284 case NetNet::PINPUT:
285 out << " input";
286 break;
287 case NetNet::POUTPUT:
288 out << " output";
289 break;
290 case NetNet::PINOUT:
291 out << " inout";
292 break;
293 case NetNet::NOT_A_PORT:
294 break;
297 out << " " << data_type_;
299 if (signed_) {
300 out << " signed";
303 if (port_set_) {
304 if (port_msb_ == 0) {
305 out << " port<scalar>";
306 } else {
307 out << " port[" << *port_msb_ << ":" << *port_lsb_ << "]";
310 if (net_set_) {
311 if (net_msb_ == 0) {
312 out << " net<scalar>";
313 } else {
314 out << " net[" << *net_msb_ << ":" << *net_lsb_ << "]";
318 out << " " << name_;
320 // If the wire has indices, dump them.
321 if (lidx_ || ridx_) {
322 out << "[";
323 if (lidx_) out << *lidx_;
324 if (ridx_) out << ":" << *ridx_;
325 out << "]";
328 out << ";" << endl;
329 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
330 ; idx != attributes.end()
331 ; idx ++) {
332 out << " " << (*idx).first;
333 if ((*idx).second)
334 out << " = " << *(*idx).second;
335 out << endl;
339 void PGate::dump_pins(ostream&out) const
341 if (pin_count()) {
342 if (pin(0)) out << *pin(0);
344 for (unsigned idx = 1 ; idx < pin_count() ; idx += 1) {
345 out << ", ";
346 if (pin(idx)) out << *pin(idx);
351 void PDelays::dump_delays(ostream&out) const
353 if (delay_[0] && delay_[1] && delay_[2])
354 out << "#(" << *delay_[0] << "," << *delay_[1] << "," <<
355 *delay_[2] << ")";
356 else if (delay_[0])
357 out << "#" << *delay_[0];
358 else
359 out << "#0";
363 void PGate::dump_delays(ostream&out) const
365 delay_.dump_delays(out);
368 void PGate::dump(ostream&out, unsigned ind) const
370 out << setw(ind) << "" << typeid(*this).name() << " ";
371 delay_.dump_delays(out);
372 out << " " << get_name() << "(";
373 dump_pins(out);
374 out << ");" << endl;
378 void PGAssign::dump(ostream&out, unsigned ind) const
380 out << setw(ind) << "";
381 out << "assign (" << strength0() << "0 " << strength1() << "1) ";
382 dump_delays(out);
383 out << " " << *pin(0) << " = " << *pin(1) << ";" << endl;
386 void PGBuiltin::dump(ostream&out, unsigned ind) const
388 out << setw(ind) << "";
389 switch (type()) {
390 case PGBuiltin::BUFIF0:
391 out << "bufif0 ";
392 break;
393 case PGBuiltin::BUFIF1:
394 out << "bufif1 ";
395 break;
396 case PGBuiltin::NOTIF0:
397 out << "bufif0 ";
398 break;
399 case PGBuiltin::NOTIF1:
400 out << "bufif1 ";
401 break;
402 case PGBuiltin::NAND:
403 out << "nand ";
404 break;
405 case PGBuiltin::NMOS:
406 out << "nmos ";
407 break;
408 case PGBuiltin::RNMOS:
409 out << "rnmos ";
410 break;
411 case PGBuiltin::RPMOS:
412 out << "rpmos ";
413 break;
414 case PGBuiltin::PMOS:
415 out << "pmos ";
416 break;
417 case PGBuiltin::RCMOS:
418 out << "rcmos ";
419 break;
420 case PGBuiltin::CMOS:
421 out << "cmos ";
422 break;
423 default:
424 out << "builtin gate ";
427 out << "(" << strength0() << "0 " << strength1() << "1) ";
428 dump_delays(out);
429 out << " " << get_name();
431 if (msb_) {
432 out << " [" << *msb_ << ":" << *lsb_ << "]";
435 out << "(";
436 dump_pins(out);
437 out << ");" << endl;
440 void PGModule::dump(ostream&out, unsigned ind) const
442 out << setw(ind) << "" << type_ << " ";
444 // If parameters are overridden by order, dump them.
445 if (overrides_ && overrides_->count() > 0) {
446 assert(parms_ == 0);
447 out << "#(";
449 if ((*overrides_)[0] == 0)
450 out << "<nil>";
451 else
452 out << *((*overrides_)[0]);
453 for (unsigned idx = 1 ; idx < overrides_->count() ; idx += 1) {
454 out << "," << *((*overrides_)[idx]);
456 out << ") ";
459 // If parameters are overridden by name, dump them.
460 if (parms_) {
461 assert(overrides_ == 0);
462 out << "#(";
463 out << "." << parms_[0].name << "(" << *parms_[0].parm << ")";
464 for (unsigned idx = 1 ; idx < nparms_ ; idx += 1) {
465 out << ", ." << parms_[idx].name << "(" <<
466 *parms_[idx].parm << ")";
468 out << ") ";
471 out << get_name();
473 // If the module is arrayed, print the index expressions.
474 if (msb_ || lsb_) {
475 out << "[";
476 if (msb_) out << *msb_;
477 out << ":";
478 if (lsb_) out << *lsb_;
479 out << "]";
482 out << "(";
483 if (pins_) {
484 out << "." << pins_[0].name << "(";
485 if (pins_[0].parm) out << *pins_[0].parm;
486 out << ")";
487 for (unsigned idx = 1 ; idx < npins_ ; idx += 1) {
488 out << ", ." << pins_[idx].name << "(";
489 if (pins_[idx].parm)
490 out << *pins_[idx].parm;
491 out << ")";
493 } else {
494 dump_pins(out);
496 out << ");" << endl;
499 void Statement::dump(ostream&out, unsigned ind) const
501 /* I give up. I don't know what type this statement is,
502 so just print the C++ typeid and let the user figure
503 it out. */
504 out << setw(ind) << "";
505 out << "/* " << get_fileline() << ": " << typeid(*this).name()
506 << " */ ;" << endl;
509 void PAssign::dump(ostream&out, unsigned ind) const
511 out << setw(ind) << "";
512 out << *lval() << " = " << delay_ << " " << *rval() << ";";
513 out << " /* " << get_fileline() << " */" << endl;
516 void PAssignNB::dump(ostream&out, unsigned ind) const
518 out << setw(ind) << "";
519 out << *lval() << " <= " << delay_ << " " << *rval() << ";";
520 out << " /* " << get_fileline() << " */" << endl;
523 void PBlock::dump(ostream&out, unsigned ind) const
525 out << setw(ind) << "" << "begin";
526 if (pscope_name() != 0)
527 out << " : " << pscope_name();
528 out << endl;
530 if (pscope_name() != 0)
531 dump_wires_(out, ind+2);
533 for (unsigned idx = 0 ; idx < list_.count() ; idx += 1) {
534 if (list_[idx])
535 list_[idx]->dump(out, ind+2);
536 else
537 out << setw(ind+2) << "" << "/* NOOP */ ;" << endl;
540 out << setw(ind) << "" << "end" << endl;
543 void PCallTask::dump(ostream&out, unsigned ind) const
545 out << setw(ind) << "" << path_;
547 if (parms_.count() > 0) {
548 out << "(";
549 if (parms_[0])
550 out << *parms_[0];
552 for (unsigned idx = 1 ; idx < parms_.count() ; idx += 1) {
553 out << ", ";
554 if (parms_[idx])
555 out << *parms_[idx];
557 out << ")";
560 out << "; /* " << get_fileline() << " */" << endl;
563 void PCase::dump(ostream&out, unsigned ind) const
565 out << setw(ind) << "";
566 switch (type_) {
567 case NetCase::EQ:
568 out << "case";
569 break;
570 case NetCase::EQX:
571 out << "casex";
572 break;
573 case NetCase::EQZ:
574 out << "casez";
575 break;
577 out << " (" << *expr_ << ") /* " << get_fileline() << " */" << endl;
579 for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
580 PCase::Item*cur = (*items_)[idx];
582 if (cur->expr.count() == 0) {
583 out << setw(ind+2) << "" << "default:";
585 } else {
586 out << setw(ind+2) << "" << *cur->expr[0];
588 for(unsigned e = 1 ; e < cur->expr.count() ; e += 1)
589 out << ", " << *cur->expr[e];
591 out << ":";
594 if (cur->stat) {
595 out << endl;
596 cur->stat->dump(out, ind+6);
597 } else {
598 out << " ;" << endl;
602 out << setw(ind) << "" << "endcase" << endl;
605 void PCondit::dump(ostream&out, unsigned ind) const
607 out << setw(ind) << "" << "if (" << *expr_ << ")" << endl;
608 if (if_)
609 if_->dump(out, ind+3);
610 else
611 out << setw(ind) << ";" << endl;
612 if (else_) {
613 out << setw(ind) << "" << "else" << endl;
614 else_->dump(out, ind+3);
618 void PCAssign::dump(ostream&out, unsigned ind) const
620 out << setw(ind) << "" << "assign " << *lval_ << " = " << *expr_
621 << "; /* " << get_fileline() << " */" << endl;
624 void PDeassign::dump(ostream&out, unsigned ind) const
626 out << setw(ind) << "" << "deassign " << *lval_ << "; /* "
627 << get_fileline() << " */" << endl;
630 void PDelayStatement::dump(ostream&out, unsigned ind) const
632 out << setw(ind) << "" << "#" << *delay_ << " /* " <<
633 get_fileline() << " */";
634 if (statement_) {
635 out << endl;
636 statement_->dump(out, ind+2);
637 } else {
638 out << " /* noop */;" << endl;
642 void PDisable::dump(ostream&out, unsigned ind) const
644 out << setw(ind) << "" << "disable " << scope_ << "; /* "
645 << get_fileline() << " */" << endl;
648 void PEventStatement::dump(ostream&out, unsigned ind) const
650 if (expr_.count() == 0) {
651 out << setw(ind) << "" << "@* ";
653 } else {
654 out << setw(ind) << "" << "@(" << *(expr_[0]);
655 if (expr_.count() > 1)
656 for (unsigned idx = 1 ; idx < expr_.count() ; idx += 1)
657 out << " or " << *(expr_[idx]);
659 out << ")";
662 if (statement_) {
663 out << endl;
664 statement_->dump(out, ind+2);
665 } else {
666 out << " ;" << endl;
670 void PForce::dump(ostream&out, unsigned ind) const
672 out << setw(ind) << "" << "force " << *lval_ << " = " << *expr_
673 << "; /* " << get_fileline() << " */" << endl;
676 void PForever::dump(ostream&out, unsigned ind) const
678 out << setw(ind) << "" << "forever /* " << get_fileline() << " */" << endl;
679 statement_->dump(out, ind+3);
682 void PForStatement::dump(ostream&out, unsigned ind) const
684 out << setw(ind) << "" << "for (" << *name1_ << " = " << *expr1_
685 << "; " << *cond_ << "; " << *name2_ << " = " << *expr2_ <<
686 ")" << endl;
687 statement_->dump(out, ind+3);
690 void PFunction::dump(ostream&out, unsigned ind) const
692 out << setw(ind) << "" << "function ";
693 switch (return_type_.type) {
694 case PTF_NONE:
695 out << "?none? ";
696 break;
697 case PTF_REG:
698 out << "reg ";
699 break;
700 case PTF_REG_S:
701 out << "reg_s ";
702 break;
703 case PTF_INTEGER:
704 out << "integer ";
705 break;
706 case PTF_REAL:
707 out << "real ";
708 break;
709 case PTF_REALTIME:
710 out << "realtime ";
711 break;
712 case PTF_TIME:
713 out << "time ";
714 break;
717 if (return_type_.range) {
718 out << "[";
719 out << "] ";
722 out << pscope_name() << ";" << endl;
724 if (ports_)
725 for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
726 out << setw(ind) << "";
727 out << "input ";
728 out << (*ports_)[idx]->basename() << ";" << endl;
731 dump_wires_(out, ind);
733 if (statement_)
734 statement_->dump(out, ind);
735 else
736 out << setw(ind) << "" << "/* NOOP */" << endl;
739 void PRelease::dump(ostream&out, unsigned ind) const
741 out << setw(ind) << "" << "release " << *lval_ << "; /* "
742 << get_fileline() << " */" << endl;
745 void PRepeat::dump(ostream&out, unsigned ind) const
747 out << setw(ind) << "" << "repeat (" << *expr_ << ")" << endl;
748 statement_->dump(out, ind+3);
751 void PTask::dump(ostream&out, unsigned ind) const
753 if (ports_)
754 for (unsigned idx = 0 ; idx < ports_->count() ; idx += 1) {
755 out << setw(ind) << "";
756 switch ((*ports_)[idx]->get_port_type()) {
757 case NetNet::PINPUT:
758 out << "input ";
759 break;
760 case NetNet::POUTPUT:
761 out << "output ";
762 break;
763 case NetNet::PINOUT:
764 out << "inout ";
765 break;
766 default:
767 assert(0);
768 break;
770 out << (*ports_)[idx]->basename() << ";" << endl;
773 dump_wires_(out, ind);
775 if (statement_)
776 statement_->dump(out, ind);
777 else
778 out << setw(ind) << "" << "/* NOOP */" << endl;
781 void PTrigger::dump(ostream&out, unsigned ind) const
783 out << setw(ind) << "" << "-> " << event_ << ";" << endl;
786 void PWhile::dump(ostream&out, unsigned ind) const
788 out << setw(ind) << "" << "while (" << *cond_ << ")" << endl;
789 statement_->dump(out, ind+3);
792 void PProcess::dump(ostream&out, unsigned ind) const
794 switch (type_) {
795 case PProcess::PR_INITIAL:
796 out << setw(ind) << "" << "initial";
797 break;
798 case PProcess::PR_ALWAYS:
799 out << setw(ind) << "" << "always";
800 break;
803 out << " /* " << get_fileline() << " */" << endl;
805 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
806 ; idx != attributes.end() ; idx++ ) {
808 out << setw(ind+2) << "" << "(* " << (*idx).first;
809 if ((*idx).second) {
810 out << " = " << *(*idx).second;
812 out << " *)" << endl;
815 statement_->dump(out, ind+2);
818 void PSpecPath::dump(std::ostream&out, unsigned ind) const
820 out << setw(ind) << "" << "specify path ";
822 if (condition)
823 out << "if (" << *condition << ") ";
825 out << "(";
826 if (edge) {
827 if (edge > 0)
828 out << "posedge ";
829 else
830 out << "negedge ";
833 for (unsigned idx = 0 ; idx < src.size() ; idx += 1) {
834 if (idx > 0) out << ", ";
835 assert(src[idx]);
836 out << src[idx];
839 out << " => ";
841 if (data_source_expression)
842 out << "(";
844 for (unsigned idx = 0 ; idx < dst.size() ; idx += 1) {
845 if (idx > 0) out << ", ";
846 assert(dst[idx]);
847 out << dst[idx];
850 if (data_source_expression)
851 out << " : " << *data_source_expression << ")";
853 out << ") = (";
854 for (unsigned idx = 0 ; idx < delays.size() ; idx += 1) {
855 if (idx > 0) out << ", ";
856 assert(delays[idx]);
857 out << *delays[idx];
859 out << ");" << endl;
862 void PGenerate::dump(ostream&out, unsigned indent) const
864 out << setw(indent) << "" << "generate(" << id_number << ")";
866 switch (scheme_type) {
867 case GS_NONE:
868 break;
869 case GS_LOOP:
870 out << " for ("
871 << loop_index
872 << "=" << *loop_init
873 << "; " << *loop_test
874 << "; " << loop_index
875 << "=" << *loop_step << ")";
876 break;
877 case GS_CONDIT:
878 out << " if (" << *loop_test << ")";
879 break;
880 case GS_ELSE:
881 out << " else !(" << *loop_test << ")";
882 break;
883 case GS_CASE:
884 out << " case (" << *loop_test << ")";
885 break;
886 case GS_CASE_ITEM:
887 if (loop_test)
888 out << " (" << *loop_test << ") == (" << *parent->loop_test << ")";
889 else
890 out << " default:";
891 break;
894 if (scope_name)
895 out << " : " << scope_name;
897 out << endl;
899 for (map<perm_string,PWire*>::const_iterator idx = wires.begin()
900 ; idx != wires.end() ; idx++) {
902 (*idx).second->dump(out, indent+2);
905 for (list<PGate*>::const_iterator idx = gates.begin()
906 ; idx != gates.end() ; idx++) {
907 (*idx)->dump(out, indent+2);
910 for (list<PProcess*>::const_iterator idx = behaviors.begin()
911 ; idx != behaviors.end() ; idx++) {
912 (*idx)->dump(out, indent+2);
915 for (list<PGenerate*>::const_iterator idx = generates.begin()
916 ; idx != generates.end() ; idx++) {
917 (*idx)->dump(out, indent+2);
920 out << setw(indent) << "" << "endgenerate" << endl;
923 void PScope::dump_wires_(ostream&out, unsigned indent) const
925 // Iterate through and display all the wires.
926 for (map<perm_string,PWire*>::const_iterator wire = wires.begin()
927 ; wire != wires.end() ; wire ++ ) {
929 (*wire).second->dump(out, indent);
933 void Module::dump(ostream&out) const
935 if (attributes.begin() != attributes.end()) {
936 out << "(* ";
937 for (map<perm_string,PExpr*>::const_iterator idx = attributes.begin()
938 ; idx != attributes.end() ; idx++ ) {
939 if (idx != attributes.begin()) {
940 out << " , ";
942 out << (*idx).first;
943 if ((*idx).second) {
944 out << " = " << *(*idx).second;
947 out << " *) ";
950 out << "module " << mod_name() << ";" << endl;
952 for (unsigned idx = 0 ; idx < ports.count() ; idx += 1) {
953 port_t*cur = ports[idx];
955 if (cur == 0) {
956 out << " unconnected" << endl;
957 continue;
960 out << " ." << cur->name << "(" << *cur->expr[0];
961 for (unsigned wdx = 1 ; wdx < cur->expr.count() ; wdx += 1) {
962 out << ", " << *cur->expr[wdx];
965 out << ")" << endl;
968 typedef map<perm_string,param_expr_t>::const_iterator parm_iter_t;
969 typedef map<pform_name_t,PExpr*>::const_iterator parm_hiter_t;
970 for (parm_iter_t cur = parameters.begin()
971 ; cur != parameters.end() ; cur ++) {
972 out << " parameter ";
973 if ((*cur).second.signed_flag)
974 out << "signed ";
975 if ((*cur).second.msb)
976 out << "[" << *(*cur).second.msb << ":"
977 << *(*cur).second.lsb << "] ";
978 out << (*cur).first << " = ";
979 if ((*cur).second.expr)
980 out << *(*cur).second.expr << ";" << endl;
981 else
982 out << "/* ERROR */;" << endl;
985 for (parm_iter_t cur = localparams.begin()
986 ; cur != localparams.end() ; cur ++) {
987 out << " localparam ";
988 if ((*cur).second.msb)
989 out << "[" << *(*cur).second.msb << ":"
990 << *(*cur).second.lsb << "] ";
991 out << (*cur).first << " = ";
992 if ((*cur).second.expr)
993 out << *(*cur).second.expr << ";" << endl;
994 else
995 out << "/* ERROR */;" << endl;
998 typedef list<pair<perm_string,LineInfo*> >::const_iterator genvar_iter_t;
999 for (genvar_iter_t cur = genvars.begin()
1000 ; cur != genvars.end() ; cur++) {
1001 out << " genvar " << ((*cur).first) << ";" << endl;
1004 typedef list<PGenerate*>::const_iterator genscheme_iter_t;
1005 for (genscheme_iter_t cur = generate_schemes.begin()
1006 ; cur != generate_schemes.end() ; cur++) {
1007 (*cur)->dump(out, 4);
1010 typedef map<perm_string,PExpr*>::const_iterator specparm_iter_t;
1011 for (specparm_iter_t cur = specparams.begin()
1012 ; cur != specparams.end() ; cur ++) {
1013 out << " specparam " << (*cur).first << " = "
1014 << *(*cur).second << ";" << endl;
1017 for (parm_hiter_t cur = defparms.begin()
1018 ; cur != defparms.end() ; cur ++) {
1019 out << " defparam " << (*cur).first << " = ";
1020 if ((*cur).second)
1021 out << *(*cur).second << ";" << endl;
1022 else
1023 out << "/* ERROR */;" << endl;
1026 for (map<perm_string,PEvent*>::const_iterator cur = events.begin()
1027 ; cur != events.end() ; cur ++ ) {
1028 PEvent*ev = (*cur).second;
1029 out << " event " << ev->name() << "; // "
1030 << ev->get_fileline() << endl;
1033 // Iterate through and display all the wires.
1034 dump_wires_(out, 4);
1036 // Dump the task definitions.
1037 typedef map<perm_string,PTask*>::const_iterator task_iter_t;
1038 for (task_iter_t cur = tasks_.begin()
1039 ; cur != tasks_.end() ; cur ++) {
1040 out << " task " << (*cur).first << ";" << endl;
1041 (*cur).second->dump(out, 6);
1042 out << " endtask;" << endl;
1045 // Dump the function definitions.
1046 typedef map<perm_string,PFunction*>::const_iterator func_iter_t;
1047 for (func_iter_t cur = funcs_.begin()
1048 ; cur != funcs_.end() ; cur ++) {
1049 out << " function " << (*cur).first << ";" << endl;
1050 (*cur).second->dump(out, 6);
1051 out << " endfunction;" << endl;
1055 // Iterate through and display all the gates
1056 for (list<PGate*>::const_iterator gate = gates_.begin()
1057 ; gate != gates_.end()
1058 ; gate ++ ) {
1060 (*gate)->dump(out);
1064 for (list<PProcess*>::const_iterator behav = behaviors.begin()
1065 ; behav != behaviors.end()
1066 ; behav ++ ) {
1068 (*behav)->dump(out, 4);
1071 for (list<PSpecPath*>::const_iterator spec = specify_paths.begin()
1072 ; spec != specify_paths.end()
1073 ; spec ++ ) {
1075 (*spec)->dump(out, 4);
1078 out << "endmodule" << endl;
1081 void pform_dump(ostream&out, Module*mod)
1083 mod->dump(out);
1086 void PUdp::dump(ostream&out) const
1088 out << "primitive " << name_ << "(" << ports[0];
1089 for (unsigned idx = 1 ; idx < ports.count() ; idx += 1)
1090 out << ", " << ports[idx];
1091 out << ");" << endl;
1093 if (sequential)
1094 out << " reg " << ports[0] << ";" << endl;
1096 out << " table" << endl;
1097 for (unsigned idx = 0 ; idx < tinput.count() ; idx += 1) {
1098 out << " ";
1099 for (unsigned chr = 0 ; chr < tinput[idx].length() ; chr += 1)
1100 out << " " << tinput[idx][chr];
1102 if (sequential)
1103 out << " : " << tcurrent[idx];
1105 out << " : " << toutput[idx] << " ;" << endl;
1107 out << " endtable" << endl;
1109 if (sequential)
1110 out << " initial " << ports[0] << " = 1'b" << initial
1111 << ";" << endl;
1113 // Dump the attributes for the primitive as attribute
1114 // statements.
1115 for (map<string,PExpr*>::const_iterator idx = attributes.begin()
1116 ; idx != attributes.end()
1117 ; idx ++) {
1118 out << " attribute " << (*idx).first;
1119 if ((*idx).second)
1120 out << " = " << *(*idx).second;
1121 out << endl;
1124 out << "endprimitive" << endl;