diff --git a/Module.h b/Module.h index 162761e88..e05aa244e 100644 --- a/Module.h +++ b/Module.h @@ -76,40 +76,6 @@ class Module : public PScope, public LineInfo { NetNet::Type default_nettype; - struct range_t { - // True if this is an exclude - bool exclude_flag; - // lower bound - // If low_open_flag is false and low_expr=0, then use -inf - bool low_open_flag; - PExpr*low_expr; - // upper bound - // If high_open_flag is false and high_expr=0, then use +inf - bool high_open_flag; - PExpr*high_expr; - // Next range description in list - struct range_t*next; - }; - - /* The module has parameters that are evaluated when the - module is elaborated. During parsing, I put the parameters - into this map. */ - struct param_expr_t : public LineInfo { - param_expr_t() : type(IVL_VT_NO_TYPE), msb(0), lsb(0), signed_flag(false), expr(0), range(0) { } - // Type information - ivl_variable_type_t type; - PExpr*msb; - PExpr*lsb; - bool signed_flag; - // Value expression - PExpr*expr; - // If there are range constraints, list them here - range_t*range; - }; - mapparameters; - maplocalparams; - - /* specparams are simpler then other params, in that they have no type information. They are merely constant expressions. */ diff --git a/PGenerate.h b/PGenerate.h index d88115533..a9af52120 100644 --- a/PGenerate.h +++ b/PGenerate.h @@ -78,8 +78,6 @@ class PGenerate : public LineInfo, public LexicalScope { list gates; void add_gate(PGate*); - list behaviors; - // Tasks instantiated within this scheme. map tasks; mapfuncs; diff --git a/PScope.h b/PScope.h index 545b502f3..c2749ac9f 100644 --- a/PScope.h +++ b/PScope.h @@ -19,11 +19,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +# include "LineInfo.h" # include "StringHeap.h" # include "pform_types.h" +# include "ivl_target.h" # include class PEvent; +class PExpr; class AProcess; class PProcess; class PWire; @@ -36,7 +39,7 @@ class NetScope; * represents lexical scope. For example, a module, a function/task, a * named block is derived from a PScope. * - * NOTE: This is note the same concept as the "scope" of an elaborated + * NOTE: This is not the same concept as the "scope" of an elaborated * hierarchy. That is represented by NetScope objects after elaboration. */ @@ -47,7 +50,43 @@ class LexicalScope { // A virtual destructor is so that dynamic_cast can work. virtual ~LexicalScope() { } - // Nets an variables (wires) in the scope + struct range_t { + // True if this is an exclude + bool exclude_flag; + // lower bound + // If low_open_flag is false and low_expr=0, then use -inf + bool low_open_flag; + PExpr*low_expr; + // upper bound + // If high_open_flag is false and high_expr=0, then use +inf + bool high_open_flag; + PExpr*high_expr; + // Next range description in list + struct range_t*next; + }; + + /* The scope has parameters that are evaluated when the scope + is elaborated. During parsing, I put the parameters into + this map. */ + struct param_expr_t : public LineInfo { + param_expr_t() : type(IVL_VT_NO_TYPE), msb(0), lsb(0), signed_flag(false), expr(0), range(0) { } + // Type information + ivl_variable_type_t type; + PExpr*msb; + PExpr*lsb; + bool signed_flag; + // Value expression + PExpr*expr; + // If there are range constraints, list them here + range_t*range; + }; + mapparameters; + maplocalparams; + + // Named events in the scope. + mapevents; + + // Nets and variables (wires) in the scope mapwires; PWire* wires_find(perm_string name); @@ -55,6 +94,15 @@ class LexicalScope { list behaviors; list analog_behaviors; + protected: + void dump_parameters_(ostream&out, unsigned indent) const; + + void dump_localparams_(ostream&out, unsigned indent) const; + + void dump_events_(ostream&out, unsigned indent) const; + + void dump_wires_(ostream&out, unsigned indent) const; + private: }; @@ -76,12 +124,7 @@ class PScope : public LexicalScope { perm_string pscope_name() const { return name_; } PScope* pscope_parent() { return parent_; } - // Named events in the scope. - mapevents; - protected: - void dump_wires_(ostream&out, unsigned indent) const; - bool elaborate_sig_wires_(Design*des, NetScope*scope) const; bool elaborate_behaviors_(Design*des, NetScope*scope) const; diff --git a/elab_scope.cc b/elab_scope.cc index a356ff349..3529129df 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -46,8 +46,42 @@ # include # include "ivl_assert.h" -void Module::elaborate_parm_item_(perm_string name, const param_expr_t&cur, - Design*des, NetScope*scope) +typedef map::const_iterator mparm_it_t; + +static void collect_scope_parameters_(NetScope*scope, + const map¶meters) +{ + for (mparm_it_t cur = parameters.begin() + ; cur != parameters.end() ; cur ++) { + + NetEParam*tmp = new NetEParam; + tmp->set_line(*((*cur).second.expr)); + tmp->cast_signed( (*cur).second.signed_flag ); + + scope->set_parameter((*cur).first, tmp, (*cur).second.type, + 0, 0, false, 0, (*cur).second); + } +} + +static void collect_scope_localparams_(NetScope*scope, + const map&localparams) +{ + for (mparm_it_t cur = localparams.begin() + ; cur != localparams.end() ; cur ++) { + + NetEParam*tmp = new NetEParam; + tmp->set_line(*((*cur).second.expr)); + if ((*cur).second.msb) + tmp->cast_signed( (*cur).second.signed_flag ); + + scope->set_parameter((*cur).first, tmp, (*cur).second.type, + 0, 0, false, 0, (*cur).second); + } +} + +static void elaborate_parm_item_(perm_string name, + const LexicalScope::param_expr_t&cur, + Design*des, NetScope*scope) { PExpr*ex = cur.expr; assert(ex); @@ -72,7 +106,7 @@ void Module::elaborate_parm_item_(perm_string name, const param_expr_t&cur, } NetScope::range_t*range_list = 0; - for (Module::range_t*range = cur.range ; range ; range = range->next) { + for (LexicalScope::range_t*range = cur.range ; range ; range = range->next) { NetScope::range_t*tmp = new NetScope::range_t; tmp->exclude_flag = range->exclude_flag; tmp->low_open_flag = range->low_open_flag; @@ -131,6 +165,66 @@ void Module::elaborate_parm_item_(perm_string name, const param_expr_t&cur, delete val; } +static void elaborate_scope_parameters_(Design*des, NetScope*scope, + const map¶meters) +{ + for (mparm_it_t cur = parameters.begin() + ; cur != parameters.end() ; cur ++) { + + elaborate_parm_item_((*cur).first, (*cur).second, des, scope); + } +} + +static void elaborate_scope_localparams_(Design*des, NetScope*scope, + const map&localparams) +{ + for (mparm_it_t cur = localparams.begin() + ; cur != localparams.end() ; cur ++) { + + elaborate_parm_item_((*cur).first, (*cur).second, des, scope); + } +} + +static void replace_scope_parameters_(NetScope*scope, const LineInfo&loc, + const Module::replace_t&replacements) +{ + for (Module::replace_t::const_iterator cur = replacements.begin() + ; cur != replacements.end() ; cur ++) { + + NetExpr*val = (*cur).second; + if (val == 0) { + cerr << loc.get_fileline() << ": internal error: " + << "Missing expression in parameter replacement for " + << (*cur).first; + } + assert(val); + if (debug_scopes) { + cerr << loc.get_fileline() << ": debug: " + << "Replace " << (*cur).first + << " with expression " << *val + << " from " << val->get_fileline() << "." << endl; + cerr << loc.get_fileline() << ": : " + << "Type=" << val->expr_type() << endl; + } + bool flag = scope->replace_parameter((*cur).first, val); + if (! flag) { + cerr << val->get_fileline() << ": warning: parameter " + << (*cur).first << " not found in " + << scope_path(scope) << "." << endl; + } + } +} + +static void elaborate_scope_events_(Design*des, NetScope*scope, + const map&events) +{ + for (map::const_iterator et = events.begin() + ; et != events.end() ; et ++ ) { + + (*et).second->elaborate_scope(des, scope); + } +} + static void elaborate_scope_tasks(Design*des, NetScope*scope, const LineInfo&loc, const map&tasks) @@ -242,79 +336,25 @@ bool Module::elaborate_scope(Design*des, NetScope*scope, // the pform and just place a NetEParam placeholder in the // place of the elaborated expression. - typedef map::const_iterator mparm_it_t; + // Scan the parameters in the module, and create stub parameter + // entries in the scope for the parameter names. - // This loop scans the parameters in the module, and creates - // stub parameter entries in the scope for the parameter name. - - for (mparm_it_t cur = parameters.begin() - ; cur != parameters.end() ; cur ++) { - - NetEParam*tmp = new NetEParam; - tmp->set_line(*((*cur).second.expr)); - tmp->cast_signed( (*cur).second.signed_flag ); - - scope->set_parameter((*cur).first, tmp, (*cur).second.type, - 0, 0, false, 0, (*cur).second); - } - - for (mparm_it_t cur = localparams.begin() - ; cur != localparams.end() ; cur ++) { - - NetEParam*tmp = new NetEParam; - tmp->set_line(*((*cur).second.expr)); - if ((*cur).second.msb) - tmp->cast_signed( (*cur).second.signed_flag ); - - scope->set_parameter((*cur).first, tmp, (*cur).second.type, - 0, 0, false, 0, (*cur).second); - } + collect_scope_parameters_(scope, parameters); + collect_scope_localparams_(scope, localparams); // Now scan the parameters again, this time elaborating them // for use as parameter values. This is after the previous // scan so that local parameter names can be used in the // r-value expressions. - for (mparm_it_t cur = parameters.begin() - ; cur != parameters.end() ; cur ++) { - - elaborate_parm_item_((*cur).first, (*cur).second, des, scope); - } + elaborate_scope_parameters_(des, scope, parameters); /* run parameter replacements that were collected from the containing scope and meant for me. */ - for (replace_t::const_iterator cur = replacements.begin() - ; cur != replacements.end() ; cur ++) { + replace_scope_parameters_(scope, *this, replacements); - NetExpr*val = (*cur).second; - if (val == 0) { - cerr << get_fileline() << ": internal error: " - << "Missing expression in parameter replacement for " - << (*cur).first; - } - assert(val); - if (debug_scopes) { - cerr << get_fileline() << ": debug: " - << "Replace " << (*cur).first - << " with expression " << *val - << " from " << val->get_fileline() << "." << endl; - cerr << get_fileline() << ": : " - << "Type=" << val->expr_type() << endl; - } - bool flag = scope->replace_parameter((*cur).first, val); - if (! flag) { - cerr << val->get_fileline() << ": warning: parameter " - << (*cur).first << " not found in " - << scope_path(scope) << "." << endl; - } - } - - for (mparm_it_t cur = localparams.begin() - ; cur != localparams.end() ; cur ++) { - - elaborate_parm_item_((*cur).first, (*cur).second, des, scope); - } + elaborate_scope_localparams_(des, scope, localparams); // Run through the defparams for this module, elaborate the // expressions in this context and save the result is a table @@ -401,11 +441,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope, // elaboration, so do it now. This allows for normal // elaboration to reference these events. - for (map::const_iterator et = events.begin() - ; et != events.end() ; et ++ ) { - - (*et).second->elaborate_scope(des, scope); - } + elaborate_scope_events_(des, scope, events); return des->errors == 0; } @@ -693,6 +729,16 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope) (*cur) -> generate_scope(des, scope); } + // Scan the localparams in this scope, and create stub parameter + // entries in the scope for the parameter names. + collect_scope_localparams_(scope, localparams); + + // Now scan the localparams again, this time elaborating them + // for use as parameter values. + elaborate_scope_localparams_(des, scope, localparams); + + // Scan through all the task and function declarations in this + // scope. elaborate_scope_tasks(des, scope, *this, tasks); elaborate_scope_funcs(des, scope, *this, funcs); @@ -710,6 +756,9 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope) (*cur) -> statement() -> elaborate_scope(des, scope); } + // Scan through all the named events in this scope. + elaborate_scope_events_(des, scope, events); + // Save the scope that we created, for future use. scope_list_.push_back(scope); } @@ -991,6 +1040,25 @@ void PFunction::elaborate_scope(Design*des, NetScope*scope) const { assert(scope->type() == NetScope::FUNC); + // Scan the parameters in the function, and create stub parameter + // entries in the scope for the parameter names. + + collect_scope_parameters_(scope, parameters); + + collect_scope_localparams_(scope, localparams); + + // Now scan the parameters again, this time elaborating them + // for use as parameter values. This is after the previous + // scan so that local parameter names can be used in the + // r-value expressions. + + elaborate_scope_parameters_(des, scope, parameters); + + elaborate_scope_localparams_(des, scope, localparams); + + // Scan through all the named events in this scope. + elaborate_scope_events_(des, scope, events); + if (statement_) statement_->elaborate_scope(des, scope); } @@ -999,6 +1067,25 @@ void PTask::elaborate_scope(Design*des, NetScope*scope) const { assert(scope->type() == NetScope::TASK); + // Scan the parameters in the task, and create stub parameter + // entries in the scope for the parameter names. + + collect_scope_parameters_(scope, parameters); + + collect_scope_localparams_(scope, localparams); + + // Now scan the parameters again, this time elaborating them + // for use as parameter values. This is after the previous + // scan so that local parameter names can be used in the + // r-value expressions. + + elaborate_scope_parameters_(des, scope, parameters); + + elaborate_scope_localparams_(des, scope, localparams); + + // Scan through all the named events in this scope. + elaborate_scope_events_(des, scope, events); + if (statement_) statement_->elaborate_scope(des, scope); } @@ -1035,11 +1122,29 @@ void PBlock::elaborate_scope(Design*des, NetScope*scope) const ? NetScope::FORK_JOIN : NetScope::BEGIN_END); my_scope->set_line(get_file(), get_lineno()); + + // Scan the parameters in the module, and create stub parameter + // entries in the scope for the parameter names. + + collect_scope_parameters_(my_scope, parameters); + + collect_scope_localparams_(my_scope, localparams); + + // Now scan the parameters again, this time elaborating them + // for use as parameter values. This is after the previous + // scan so that local parameter names can be used in the + // r-value expressions. + + elaborate_scope_parameters_(des, my_scope, parameters); + + elaborate_scope_localparams_(des, my_scope, localparams); + + // Scan through all the named events in this scope. + elaborate_scope_events_(des, my_scope, events); } for (unsigned idx = 0 ; idx < list_.count() ; idx += 1) list_[idx] -> elaborate_scope(des, my_scope); - } /* diff --git a/parse.y b/parse.y index a0dde49d0..75bcf60dc 100644 --- a/parse.y +++ b/parse.y @@ -157,7 +157,7 @@ static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2) svector*gates; Module::port_t *mport; - Module::range_t* value_range; + LexicalScope::range_t* value_range; svector*mports; named_pexpr_t*named_pexpr; @@ -464,6 +464,10 @@ block_item_decl | attribute_list_opt K_realtime real_variable_list ';' { delete $3; } + | K_event list_of_identifiers ';' + { pform_make_events($2, @1.text, @1.first_line); + } + | K_parameter parameter_assign_decl ';' | K_localparam localparam_assign_decl ';' @@ -2036,9 +2040,6 @@ module_item /* */ | K_defparam defparam_assign_list ';' - | K_event list_of_identifiers ';' - { pform_make_events($2, @1.text, @1.first_line); - } /* Most gate types have an optional drive strength and optional three-value delay. These rules handle the different cases. */ diff --git a/pform.cc b/pform.cc index c0b1156e4..03c6b266f 100644 --- a/pform.cc +++ b/pform.cc @@ -170,52 +170,39 @@ void pform_bind_attributes(map&attributes, delete attr; } +static LexicalScope*pform_get_cur_scope() +{ + if (pform_cur_generate) + if (pform_cur_generate->lexical_scope) + return pform_cur_generate->lexical_scope; + else + return pform_cur_generate; + else + return lexical_scope; +} + PWire*pform_get_wire_in_scope(perm_string name) { /* Note that if we are processing a generate, then the scope depth will be empty because generate schemes cannot be within sub-scopes. Only directly in modules. */ - if (pform_cur_generate) - if (pform_cur_generate->lexical_scope) - return pform_cur_generate->lexical_scope->wires_find(name); - else - return pform_cur_generate->wires_find(name); - else - return lexical_scope->wires_find(name); + return pform_get_cur_scope()->wires_find(name); } static void pform_put_wire_in_scope(perm_string name, PWire*net) { - if (pform_cur_generate) - if (pform_cur_generate->lexical_scope) - pform_cur_generate->lexical_scope->wires[name] = net; - else - pform_cur_generate->wires[name] = net; - else - lexical_scope->wires[name] = net; + pform_get_cur_scope()->wires[name] = net; } static void pform_put_behavior_in_scope(PProcess*pp) { - if (pform_cur_generate) - if (pform_cur_generate->lexical_scope) - pform_cur_generate->lexical_scope->behaviors.push_back(pp); - else - pform_cur_generate->behaviors.push_back(pp); - else - lexical_scope->behaviors.push_back(pp); + pform_get_cur_scope()->behaviors.push_back(pp); } void pform_put_behavior_in_scope(AProcess*pp) { - if (pform_cur_generate) - if (pform_cur_generate->lexical_scope) - pform_cur_generate->lexical_scope->analog_behaviors.push_back(pp); - else - pform_cur_generate->analog_behaviors.push_back(pp); - else - lexical_scope->analog_behaviors.push_back(pp); + pform_get_cur_scope()->analog_behaviors.push_back(pp); } void pform_set_default_nettype(NetNet::Type type, @@ -1045,7 +1032,7 @@ static void pform_make_event(perm_string name, const char*fn, unsigned ln) { PEvent*event = new PEvent(name); FILE_NAME(event, fn, ln); - pform_cur_module->events[name] = event; + pform_get_cur_scope()->events[name] = event; } void pform_make_events(list*names, const char*fn, unsigned ln) @@ -1705,7 +1692,7 @@ void pform_set_reg_idx(perm_string name, PExpr*l, PExpr*r) cur->set_memory_idx(l, r); } -Module::range_t* pform_parameter_value_range(bool exclude_flag, +LexicalScope::range_t* pform_parameter_value_range(bool exclude_flag, bool low_open, PExpr*low_expr, bool hig_open, PExpr*hig_expr) { @@ -1714,7 +1701,7 @@ Module::range_t* pform_parameter_value_range(bool exclude_flag, if (low_expr == 0) low_open = false; if (hig_expr == 0) hig_open = false; - Module::range_t*tmp = new Module::range_t; + LexicalScope::range_t*tmp = new LexicalScope::range_t; tmp->exclude_flag = exclude_flag; tmp->low_open_flag = low_open; tmp->low_expr = low_expr; @@ -1727,10 +1714,15 @@ Module::range_t* pform_parameter_value_range(bool exclude_flag, void pform_set_parameter(const struct vlltype&loc, perm_string name, ivl_variable_type_t type, bool signed_flag, svector*range, PExpr*expr, - Module::range_t*value_range) + LexicalScope::range_t*value_range) { + if (pform_get_cur_scope() == pform_cur_generate) { + VLerror("parameter declarations are not permitted in generate blocks"); + return; + } + assert(expr); - Module::param_expr_t&parm = pform_cur_module->parameters[name]; + Module::param_expr_t&parm = pform_get_cur_scope()->parameters[name]; FILE_NAME(&parm, loc); parm.expr = expr; @@ -1749,7 +1741,8 @@ void pform_set_parameter(const struct vlltype&loc, parm.signed_flag = signed_flag; parm.range = value_range; - pform_cur_module->param_names.push_back(name); + if (pform_get_cur_scope() == pform_cur_module) + pform_cur_module->param_names.push_back(name); } void pform_set_localparam(const struct vlltype&loc, @@ -1757,7 +1750,7 @@ void pform_set_localparam(const struct vlltype&loc, bool signed_flag, svector*range, PExpr*expr) { assert(expr); - Module::param_expr_t&parm = pform_cur_module->localparams[name]; + Module::param_expr_t&parm = pform_get_cur_scope()->localparams[name]; FILE_NAME(&parm, loc); parm.expr = expr; diff --git a/pform.h b/pform.h index 455178804..d372db52b 100644 --- a/pform.h +++ b/pform.h @@ -272,7 +272,7 @@ extern void pform_set_attrib(perm_string name, perm_string key, extern void pform_set_type_attrib(perm_string name, const string&key, char*value); -extern Module::range_t* pform_parameter_value_range(bool exclude_flag, +extern LexicalScope::range_t* pform_parameter_value_range(bool exclude_flag, bool low_open, PExpr*low_expr, bool hig_open, PExpr*hig_expr); @@ -281,7 +281,7 @@ extern void pform_set_parameter(const struct vlltype&loc, ivl_variable_type_t type, bool signed_flag, svector*range, - PExpr*expr, Module::range_t*value_range); + PExpr*expr, LexicalScope::range_t*value_range); extern void pform_set_localparam(const struct vlltype&loc, perm_string name, ivl_variable_type_t type, diff --git a/pform_dump.cc b/pform_dump.cc index 91f715ffc..a41b835d3 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -595,8 +595,15 @@ void PBlock::dump(ostream&out, unsigned ind) const out << " : " << pscope_name(); out << endl; - if (pscope_name() != 0) + if (pscope_name() != 0) { + dump_parameters_(out, ind+2); + + dump_localparams_(out, ind+2); + + dump_events_(out, ind+2); + dump_wires_(out, ind+2); + } for (unsigned idx = 0 ; idx < list_.count() ; idx += 1) { if (list_[idx]) @@ -815,6 +822,12 @@ void PFunction::dump(ostream&out, unsigned ind) const out << (*ports_)[idx]->basename() << ";" << endl; } + dump_parameters_(out, ind); + + dump_localparams_(out, ind); + + dump_events_(out, ind); + dump_wires_(out, ind); if (statement_) @@ -860,6 +873,12 @@ void PTask::dump(ostream&out, unsigned ind) const out << (*ports_)[idx]->basename() << ";" << endl; } + dump_parameters_(out, ind); + + dump_localparams_(out, ind); + + dump_events_(out, ind); + dump_wires_(out, ind); if (statement_) @@ -996,11 +1015,11 @@ void PGenerate::dump(ostream&out, unsigned indent) const out << endl; - for (map::const_iterator idx = wires.begin() - ; idx != wires.end() ; idx++) { + dump_localparams_(out, indent+2); - (*idx).second->dump(out, indent+2); - } + dump_events_(out, indent+2); + + dump_wires_(out, indent+2); for (list::const_iterator idx = gates.begin() ; idx != gates.end() ; idx++) { @@ -1025,7 +1044,83 @@ void PGenerate::dump(ostream&out, unsigned indent) const out << setw(indent) << "" << "endgenerate" << endl; } -void PScope::dump_wires_(ostream&out, unsigned indent) const +void LexicalScope::dump_parameters_(ostream&out, unsigned indent) const +{ + typedef map::const_iterator parm_iter_t; + for (parm_iter_t cur = parameters.begin() + ; cur != parameters.end() ; cur ++) { + out << setw(indent) << "" << "parameter " + << (*cur).second.type << " "; + if ((*cur).second.signed_flag) + out << "signed "; + if ((*cur).second.msb) + out << "[" << *(*cur).second.msb << ":" + << *(*cur).second.lsb << "] "; + out << (*cur).first << " = "; + if ((*cur).second.expr) + out << *(*cur).second.expr; + else + out << "/* ERROR */"; + for (LexicalScope::range_t*tmp = (*cur).second.range + ; tmp ; tmp = tmp->next) { + if (tmp->exclude_flag) + out << " exclude "; + else + out << " from "; + if (tmp->low_open_flag) + out << "("; + else + out << "["; + if (tmp->low_expr) + out << *(tmp->low_expr); + else if (tmp->low_open_flag==false) + out << "-inf"; + else + out << ""; + out << ":"; + if (tmp->high_expr) + out << *(tmp->high_expr); + else if (tmp->high_open_flag==false) + out << "inf"; + else + out << ""; + if (tmp->high_open_flag) + out << ")"; + else + out << "]"; + } + out << ";" << endl; + } +} + +void LexicalScope::dump_localparams_(ostream&out, unsigned indent) const +{ + typedef map::const_iterator parm_iter_t; + for (parm_iter_t cur = localparams.begin() + ; cur != localparams.end() ; cur ++) { + out << setw(indent) << "" << "localparam "; + if ((*cur).second.msb) + out << "[" << *(*cur).second.msb << ":" + << *(*cur).second.lsb << "] "; + out << (*cur).first << " = "; + if ((*cur).second.expr) + out << *(*cur).second.expr << ";" << endl; + else + out << "/* ERROR */;" << endl; + } +} + +void LexicalScope::dump_events_(ostream&out, unsigned indent) const +{ + for (map::const_iterator cur = events.begin() + ; cur != events.end() ; cur ++ ) { + PEvent*ev = (*cur).second; + out << setw(indent) << "" << "event " << ev->name() << "; // " + << ev->get_fileline() << endl; + } +} + +void LexicalScope::dump_wires_(ostream&out, unsigned indent) const { // Iterate through and display all the wires. for (map::const_iterator wire = wires.begin() @@ -1070,63 +1165,9 @@ void Module::dump(ostream&out) const out << ")" << endl; } - typedef map::const_iterator parm_iter_t; - for (parm_iter_t cur = parameters.begin() - ; cur != parameters.end() ; cur ++) { - out << " parameter " << (*cur).second.type << " "; - if ((*cur).second.signed_flag) - out << "signed "; - if ((*cur).second.msb) - out << "[" << *(*cur).second.msb << ":" - << *(*cur).second.lsb << "] "; - out << (*cur).first << " = "; - if ((*cur).second.expr) - out << *(*cur).second.expr; - else - out << "/* ERROR */"; - for (Module::range_t*tmp = (*cur).second.range - ; tmp ; tmp = tmp->next) { - if (tmp->exclude_flag) - out << " exclude "; - else - out << " from "; - if (tmp->low_open_flag) - out << "("; - else - out << "["; - if (tmp->low_expr) - out << *(tmp->low_expr); - else if (tmp->low_open_flag==false) - out << "-inf"; - else - out << ""; - out << ":"; - if (tmp->high_expr) - out << *(tmp->high_expr); - else if (tmp->high_open_flag==false) - out << "inf"; - else - out << ""; - if (tmp->high_open_flag) - out << ")"; - else - out << "]"; - } - out << ";" << endl; - } + dump_parameters_(out, 4); - for (parm_iter_t cur = localparams.begin() - ; cur != localparams.end() ; cur ++) { - out << " localparam "; - if ((*cur).second.msb) - out << "[" << *(*cur).second.msb << ":" - << *(*cur).second.lsb << "] "; - out << (*cur).first << " = "; - if ((*cur).second.expr) - out << *(*cur).second.expr << ";" << endl; - else - out << "/* ERROR */;" << endl; - } + dump_localparams_(out, 4); typedef map::const_iterator genvar_iter_t; for (genvar_iter_t cur = genvars.begin() @@ -1157,12 +1198,7 @@ void Module::dump(ostream&out) const out << "/* ERROR */;" << endl; } - for (map::const_iterator cur = events.begin() - ; cur != events.end() ; cur ++ ) { - PEvent*ev = (*cur).second; - out << " event " << ev->name() << "; // " - << ev->get_fileline() << endl; - } + dump_events_(out, 4); // Iterate through and display all the wires. dump_wires_(out, 4);