From e15b125da8075774ce55b7ca80221159df1ea14f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 17 Feb 2022 10:48:43 +0100 Subject: [PATCH] Replace svector with std::vector The custom `svector` class is essentially a subset of `std::vector`. There is no inherent advantage to using `svector`. Both have the same memory footprint. `svector` was designed to be of static size, but there are a few places in the parser where it has to grow at runtime. Handling this becomes a bit easier by switching to `std::vector` since it is possible to use its methods which take care of resizing the vector. This also allows to remove the unused parameter of the `lgate` struct constructor, which was only needed for compatibility with `svector`. Signed-off-by: Lars-Peter Clausen --- PDelays.h | 1 - PGate.h | 1 - PUdp.cc | 4 +- PUdp.h | 10 ++--- Statement.cc | 10 ++--- Statement.h | 9 ++-- elab_anet.cc | 2 +- elab_expr.cc | 2 +- elab_net.cc | 10 ++--- elab_scope.cc | 2 +- elab_sig.cc | 2 +- elaborate.cc | 30 ++++++------- net_udp.cc | 8 ++-- netlist.h | 2 +- parse.y | 63 +++++++++----------------- pform.cc | 53 +++++++++++----------- pform.h | 4 +- pform_dump.cc | 20 ++++----- pform_types.h | 4 +- svector.h | 121 -------------------------------------------------- synth2.cc | 2 +- 21 files changed, 106 insertions(+), 254 deletions(-) delete mode 100644 svector.h diff --git a/PDelays.h b/PDelays.h index b745b7330..30709070d 100644 --- a/PDelays.h +++ b/PDelays.h @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -# include "svector.h" # include # include # include diff --git a/PGate.h b/PGate.h index 1e57b8f67..ab514f16b 100644 --- a/PGate.h +++ b/PGate.h @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -# include "svector.h" # include "StringHeap.h" # include "named.h" # include "PNamedItem.h" diff --git a/PUdp.cc b/PUdp.cc index 61a9ff4c9..8b10c548d 100644 --- a/PUdp.cc +++ b/PUdp.cc @@ -26,12 +26,12 @@ PUdp::PUdp(perm_string n, unsigned nports) unsigned PUdp::find_port(const char*name) { - for (unsigned idx = 0 ; idx < ports.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < ports.size() ; idx += 1) { if (ports[idx] == name) return idx; } - return ports.count(); + return ports.size(); } diff --git a/PUdp.h b/PUdp.h index f39da6b37..46111e2a6 100644 --- a/PUdp.h +++ b/PUdp.h @@ -20,9 +20,9 @@ */ # include +# include # include "LineInfo.h" # include "StringHeap.h" -# include "svector.h" # include "verinum.h" class PExpr; @@ -53,14 +53,14 @@ class PUdp : public LineInfo { public: explicit PUdp(perm_string n, unsigned nports); - svectorports; + std::vector ports; unsigned find_port(const char*name); bool sequential; - svectortinput; - svector tcurrent; - svector toutput; + std::vector tinput; + std::vector tcurrent; + std::vector toutput; verinum::V initial; diff --git a/Statement.cc b/Statement.cc index fd9488496..83f796bdd 100644 --- a/Statement.cc +++ b/Statement.cc @@ -208,7 +208,7 @@ const pform_name_t& PCallTask::path() const return path_; } -PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, svector*l) +PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, std::vector*l) : quality_(q), type_(t), expr_(ex), items_(l) { } @@ -216,7 +216,7 @@ PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, svectorcount() ; idx += 1) + for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) if ((*items_)[idx]->stat) delete (*items_)[idx]->stat; delete[]items_; @@ -300,10 +300,10 @@ PDoWhile::~PDoWhile() delete statement_; } -PEventStatement::PEventStatement(const svector&ee) +PEventStatement::PEventStatement(const std::vector&ee) : expr_(ee), statement_(0), always_sens_(false) { - assert(expr_.count() > 0); + assert(expr_.size() > 0); } @@ -331,7 +331,7 @@ void PEventStatement::set_statement(Statement*st) bool PEventStatement::has_aa_term(Design*des, NetScope*scope) { bool flag = false; - for (unsigned idx = 0 ; idx < expr_.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < expr_.size() ; idx += 1) { flag = expr_[idx]->has_aa_term(des, scope) || flag; } return flag; diff --git a/Statement.h b/Statement.h index 9ad531f24..72ab46a3d 100644 --- a/Statement.h +++ b/Statement.h @@ -23,7 +23,6 @@ # include # include # include "ivl_target.h" -# include "svector.h" # include "StringHeap.h" # include "PDelays.h" # include "PExpr.h" @@ -267,7 +266,7 @@ class PCase : public Statement { Statement*stat; }; - PCase(ivl_case_quality_t, NetCase::TYPE, PExpr*ex, svector*); + PCase(ivl_case_quality_t, NetCase::TYPE, PExpr*ex, std::vector*); ~PCase(); virtual NetProc* elaborate(Design*des, NetScope*scope) const; @@ -280,7 +279,7 @@ class PCase : public Statement { NetCase::TYPE type_; PExpr*expr_; - svector*items_; + std::vector*items_; private: // not implemented PCase(const PCase&); @@ -416,7 +415,7 @@ class PEventStatement : public Statement { public: - explicit PEventStatement(const svector&ee); + explicit PEventStatement(const std::vector&ee); explicit PEventStatement(PEEvent*ee); // Make an @* statement or make a special @* version with the items // from functions added and outputs removed for always_comb/latch. @@ -444,7 +443,7 @@ class PEventStatement : public Statement { NetProc* elaborate_wait_fork(Design*des, NetScope*scope) const; private: - svectorexpr_; + std::vectorexpr_; Statement*statement_; bool always_sens_; }; diff --git a/elab_anet.cc b/elab_anet.cc index bae913518..918229e1f 100644 --- a/elab_anet.cc +++ b/elab_anet.cc @@ -48,7 +48,7 @@ NetNet* PEConcat::elaborate_anet(Design*des, NetScope*scope) const return 0; } - svectornets (parms_.count()); + std::vector nets(parms_.count()); unsigned pins = 0; unsigned errors = 0; diff --git a/elab_expr.cc b/elab_expr.cc index 844c1e89c..b6a378d09 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -3637,7 +3637,7 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, unsigned wid_sum = 0; unsigned parm_cnt = 0; unsigned parm_errors = 0; - svector parms(parms_.size()); + std::vector parms(parms_.size()); /* Elaborate all the parameters and attach them to the concat node. */ for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1) { diff --git a/elab_net.cc b/elab_net.cc index 1c8cb6b5a..733768c46 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -46,7 +46,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope, { assert(scope); - svectornets (parms_.size()); + std::vector nets(parms_.size()); unsigned width = 0; unsigned errors = 0; @@ -57,11 +57,11 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope, } /* Elaborate the operands of the concatenation. */ - for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) { if (debug_elaborate) { cerr << get_fileline() << ": debug: Elaborate subexpression " - << idx << " of " << nets.count() << " l-values: " + << idx << " of " << nets.size() << " l-values: " << *parms_[idx] << endl; } @@ -117,7 +117,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope, << endl; } - for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) { unsigned wid = nets[idx]->vector_width(); unsigned off = width - wid; NetTran*ps = new NetTran(scope, scope->local_symbol(), @@ -141,7 +141,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope, NetPartSelect::dir_t part_dir = NetPartSelect::VP; - for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) { unsigned wid = nets[idx]->vector_width(); unsigned off = width - wid; NetPartSelect*ps = new NetPartSelect(osig, off, wid, part_dir); diff --git a/elab_scope.cc b/elab_scope.cc index d6a3bf40a..e798d0c91 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -1704,7 +1704,7 @@ void PBlock::elaborate_scope(Design*des, NetScope*scope) const void PCase::elaborate_scope(Design*des, NetScope*scope) const { assert(items_); - for (unsigned idx = 0 ; idx < (*items_).count() ; idx += 1) { + for (unsigned idx = 0 ; idx < (*items_).size() ; idx += 1) { assert( (*items_)[idx] ); if (Statement*sp = (*items_)[idx]->stat) diff --git a/elab_sig.cc b/elab_sig.cc index 8c2e7d2b5..9f762c5ad 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -852,7 +852,7 @@ void PCase::elaborate_sig(Design*des, NetScope*scope) const if (items_ == 0) return; - for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) { if ( (*items_)[idx]->stat ) (*items_)[idx]->stat ->elaborate_sig(des,scope); } diff --git a/elaborate.cc b/elaborate.cc index 1fadc7219..2ae646711 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -2014,7 +2014,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const } assert(udp); - NetUDP*net = new NetUDP(scope, my_name, udp->ports.count(), udp); + NetUDP*net = new NetUDP(scope, my_name, udp->ports.size(), udp); net->set_line(*this); net->rise_time(rise_expr); net->fall_time(fall_expr); @@ -2043,7 +2043,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const // ports. If this is simply positional binding in the first // place, then get the binding from the base class. if (pins_) { - unsigned nexp = udp->ports.count(); + unsigned nexp = udp->ports.size(); pins = vector(nexp); // Scan the bindings, matching them with port names. @@ -2086,9 +2086,9 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const connections. In this case, the port count must be right. Check that is is, the get the pin list. */ - if (pin_count() != udp->ports.count()) { + if (pin_count() != udp->ports.size()) { cerr << get_fileline() << ": error: Wrong number " - "of ports. Expecting " << udp->ports.count() << + "of ports. Expecting " << udp->ports.size() << ", got " << pin_count() << "." << endl; des->errors += 1; @@ -2097,7 +2097,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const // No named bindings, just use the positional list I // already have. - assert(pin_count() == udp->ports.count()); + assert(pin_count() == udp->ports.size()); pins = get_pins(); } @@ -3046,7 +3046,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const bool context_is_real = (expr_->expr_type() == IVL_VT_REAL); bool context_unsigned = !expr_->has_sign(); - for (unsigned idx = 0; idx < items_->count(); idx += 1) { + for (unsigned idx = 0; idx < items_->size(); idx += 1) { PCase::Item*cur = (*items_)[idx]; @@ -3082,7 +3082,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const context_width = test_case_width(des, scope, expr_, context_mode); - for (unsigned idx = 0; idx < items_->count(); idx += 1) { + for (unsigned idx = 0; idx < items_->size(); idx += 1) { PCase::Item*cur = (*items_)[idx]; @@ -3126,7 +3126,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const be some cases that have multiple guards. Count each as a separate item. */ unsigned icount = 0; - for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) { PCase::Item*cur = (*items_)[idx]; if (cur->expr.empty()) @@ -3143,7 +3143,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const is a "default" case. Otherwise, the guard has one or more expressions, and each guard is a case. */ unsigned inum = 0; - for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) { ivl_assert(*this, inum < icount); PCase::Item*cur = (*items_)[idx]; @@ -4648,7 +4648,7 @@ NetProc* PEventStatement::elaborate_st(Design*des, NetScope*scope, /* If there are no expressions, this is a signal that it is an @* statement. Generate an expression to use. */ - if (expr_.count() == 0) { + if (expr_.size() == 0) { assert(enet); /* For synthesis or always_comb/latch we want just the inputs, * but for the rest we want inputs and outputs that may cause @@ -4732,7 +4732,7 @@ cerr << endl; expr_count = 1; - } else for (unsigned idx = 0 ; idx < expr_.count() ; idx += 1) { + } else for (unsigned idx = 0 ; idx < expr_.size() ; idx += 1) { assert(expr_[idx]->expr()); @@ -4889,7 +4889,7 @@ NetProc* PEventStatement::elaborate_wait(Design*des, NetScope*scope, NetProc*enet) const { assert(scope); - assert(expr_.count() == 1); + assert(expr_.size() == 1); if (scope->in_func()) { cerr << get_fileline() << ": error: functions cannot have " @@ -5051,7 +5051,7 @@ NetProc* PEventStatement::elaborate_wait(Design*des, NetScope*scope, NetProc* PEventStatement::elaborate_wait_fork(Design*des, NetScope*scope) const { assert(scope); - assert(expr_.count() == 1); + assert(expr_.size() == 1); assert(expr_[0] == 0); assert(! statement_); @@ -5086,7 +5086,7 @@ NetProc* PEventStatement::elaborate_wait_fork(Design*des, NetScope*scope) const NetProc* PEventStatement::elaborate(Design*des, NetScope*scope) const { /* Check to see if this is a wait fork statement. */ - if ((expr_.count() == 1) && (expr_[0] == 0)) + if ((expr_.size() == 1) && (expr_[0] == 0)) return elaborate_wait_fork(des, scope); NetProc*enet = 0; @@ -5100,7 +5100,7 @@ NetProc* PEventStatement::elaborate(Design*des, NetScope*scope) const enet->set_line(*this); } - if ((expr_.count() == 1) && (expr_[0]->type() == PEEvent::POSITIVE)) + if ((expr_.size() == 1) && (expr_[0]->type() == PEEvent::POSITIVE)) return elaborate_wait(des, scope, enet); return elaborate_st(des, scope, enet); diff --git a/net_udp.cc b/net_udp.cc index a4797ecf7..2ef1fc166 100644 --- a/net_udp.cc +++ b/net_udp.cc @@ -31,7 +31,7 @@ NetUDP::NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp *u) for (unsigned idx = 1 ; idx < pins ; idx += 1) { pin(idx).set_dir(Link::INPUT); } - table_idx = udp->tinput.count()-1; + table_idx = udp->tinput.size() - 1; } bool NetUDP::first(string&inp, char&out) const @@ -44,7 +44,7 @@ bool NetUDP::next(string&inp, char&out) const { table_idx++; - if (table_idx >= udp->tinput.count()) return false; + if (table_idx >= udp->tinput.size()) return false; if (is_sequential()) { inp = string("") + udp->tcurrent[table_idx] + @@ -84,11 +84,11 @@ char NetUDP::get_initial() const unsigned NetUDP::port_count() const { - return udp->ports.count(); + return udp->ports.size(); } string NetUDP::port_name(unsigned idx) const { - assert(idx < udp->ports.count()); + assert(idx < udp->ports.size()); return udp->ports[idx]; } diff --git a/netlist.h b/netlist.h index 2159d5fcf..ac6956db4 100644 --- a/netlist.h +++ b/netlist.h @@ -2626,7 +2626,7 @@ class NetUDP : public NetNode { return false when the scan is done. */ bool first(std::string&inp, char&out) const; bool next(std::string&inp, char&out) const; - unsigned rows() const { return udp->tinput.count(); } + unsigned rows() const { return udp->tinput.size(); } unsigned nin() const { return pin_count()-1; } bool is_sequential() const { return udp->sequential; } diff --git a/parse.y b/parse.y index 61e439787..f56ebbb27 100644 --- a/parse.y +++ b/parse.y @@ -402,10 +402,10 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector*citems; + std::vector*citems; lgate*gate; - svector*gates; + std::vector*gates; Module::port_t *mport; LexicalScope::range_t* value_range; @@ -425,7 +425,8 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector*exprs; - svector*event_expr; + PEEvent*event_expr; + std::vector*event_exprs; ivl_case_quality_t case_quality; NetNet::Type nettype; @@ -687,7 +688,7 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector integer_vector_type %type parameter_value_opt -%type event_expression_list +%type event_expression_list %type event_expression %type event_control %type statement statement_item statement_or_null @@ -2924,15 +2925,11 @@ case_item case_items : case_items case_item - { svector*tmp; - tmp = new svector(*$1, $2); - delete $1; - $$ = tmp; + { $1->push_back($2); + $$ = $1; } | case_item - { svector*tmp = new svector(1); - (*tmp)[0] = $1; - $$ = tmp; + { $$ = new std::vector(1, $1); } ; @@ -3256,18 +3253,15 @@ event_control /* A.K.A. clocking_event */ event_expression_list : event_expression - { $$ = $1; } + { $$ = new std::vector(1, $1); + } | event_expression_list K_or event_expression - { svector*tmp = new svector(*$1, *$3); - delete $1; - delete $3; - $$ = tmp; + { $1->push_back($3); + $$ = $1; } | event_expression_list ',' event_expression - { svector*tmp = new svector(*$1, *$3); - delete $1; - delete $3; - $$ = tmp; + { $1->push_back($3); + $$ = $1; } ; @@ -3275,31 +3269,23 @@ event_expression : K_posedge expression { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2); FILE_NAME(tmp, @1); - svector*tl = new svector(1); - (*tl)[0] = tmp; - $$ = tl; + $$ = tmp; } | K_negedge expression { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2); FILE_NAME(tmp, @1); - svector*tl = new svector(1); - (*tl)[0] = tmp; - $$ = tl; + $$ = tmp; } | K_edge expression { PEEvent*tmp = new PEEvent(PEEvent::EDGE, $2); FILE_NAME(tmp, @1); - svector*tl = new svector(1); - (*tl)[0] = tmp; - $$ = tl; + $$ = tmp; pform_requires_sv(@1, "Edge event"); } | expression { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1); FILE_NAME(tmp, @1); - svector*tl = new svector(1); - (*tl)[0] = tmp; - $$ = tl; + $$ = tmp; } ; @@ -4189,18 +4175,13 @@ gate_instance gate_instance_list : gate_instance_list ',' gate_instance - { svector*tmp1 = $1; - lgate*tmp2 = $3; - svector*out = new svector (*tmp1, *tmp2); - delete tmp1; - delete tmp2; - $$ = out; + { $1->push_back(*$3); + delete $3; + $$ = $1; } | gate_instance - { svector*tmp = new svector(1); - (*tmp)[0] = *$1; + { $$ = new std::vector(1, *$1); delete $1; - $$ = tmp; } ; diff --git a/pform.cc b/pform.cc index 51ae6f4cb..e5cd59427 100644 --- a/pform.cc +++ b/pform.cc @@ -1796,11 +1796,6 @@ PExpr* pform_select_mtm_expr(PExpr*min, PExpr*typ, PExpr*max) return res; } -template <> inline svector::svector(unsigned size) -: nitems_(size), items_(new perm_string[size]) -{ -} - static void process_udp_table(PUdp*udp, list*table, const struct vlltype&loc) { @@ -1819,18 +1814,23 @@ static void process_udp_table(PUdp*udp, list*table, The parser doesn't check that we got the right kind here, so this loop must watch out. */ - svector input (table->size()); - svector current (table->size()); - svector output (table->size()); + std::vector &input = udp->tinput; + std::vector ¤t = udp->tcurrent; + std::vector &output = udp->toutput; + + input.resize(table->size()); + current.resize(table->size()); + output.resize(table->size()); + { unsigned idx = 0; for (list::iterator cur = table->begin() ; cur != table->end() ; ++ cur , idx += 1) { string tmp = *cur; /* Pull the input values from the string. */ - assert(tmp.find(':') == (udp->ports.count() - 1)); - input[idx] = tmp.substr(0, udp->ports.count()-1); - tmp = tmp.substr(udp->ports.count()-1); + assert(tmp.find(':') == (udp->ports.size() - 1)); + input[idx] = tmp.substr(0, udp->ports.size()-1); + tmp = tmp.substr(udp->ports.size()-1); assert(tmp[0] == ':'); @@ -1862,9 +1862,6 @@ static void process_udp_table(PUdp*udp, list*table, } } - udp->tinput = input; - udp->tcurrent = current; - udp->toutput = output; } void pform_make_udp(const struct vlltype&loc, perm_string name, @@ -1908,8 +1905,8 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, the parms list in the list of ports in the port list of the UDP declaration, and the defs map maps that name to a PWire* created by an input or output declaration. */ - svector pins (parms->size()); - svector pin_names (parms->size()); + std::vector pins(parms->size()); + std::vector pin_names(parms->size()); { list::iterator cur; unsigned idx; for (cur = parms->begin(), idx = 0 @@ -1930,7 +1927,7 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, -- An input port is declared output. */ - assert(pins.count() > 0); + assert(pins.size() > 0); do { if (pins[0] == 0) { cerr << loc << ": error: " @@ -1956,7 +1953,7 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, } } while (0); - for (unsigned idx = 1 ; idx < pins.count() ; idx += 1) { + for (unsigned idx = 1 ; idx < pins.size() ; idx += 1) { if (pins[idx] == 0) { cerr << loc << ": error: " << "Port " << (idx+1) @@ -2044,7 +2041,7 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, udp->sequential = true; // Make the port list for the UDP - for (unsigned idx = 0 ; idx < pins.count() ; idx += 1) + for (unsigned idx = 0 ; idx < pins.size() ; idx += 1) udp->ports[idx] = pins[idx]->basename(); process_udp_table(udp, table, loc); @@ -2067,7 +2064,7 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, list*table) { - svector pins(parms->size() + 1); + std::vector pins(parms->size() + 1); /* Make the PWire for the output port. */ pins[0] = new PWire(out_name, @@ -2081,12 +2078,12 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, for (cur = parms->begin(), idx = 1 ; cur != parms->end() ; idx += 1, ++ cur) { - assert(idx < pins.count()); + assert(idx < pins.size()); pins[idx] = new PWire(*cur, NetNet::WIRE, NetNet::PINPUT, IVL_VT_LOGIC); FILE_NAME(pins[idx], loc); } - assert(idx == pins.count()); + assert(idx == pins.size()); } /* Verify the initial expression, if present, to be sure that @@ -2117,14 +2114,14 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, VLerror("UDP primitive already exists."); } else { - PUdp*udp = new PUdp(name, pins.count()); + PUdp*udp = new PUdp(name, pins.size()); FILE_NAME(udp, loc); // Detect sequential udp. udp->sequential = synchronous_flag; // Make the port list for the UDP - for (unsigned idx = 0 ; idx < pins.count() ; idx += 1) + for (unsigned idx = 0 ; idx < pins.size() ; idx += 1) udp->ports[idx] = pins[idx]->basename(); assert(udp); @@ -2238,7 +2235,7 @@ void pform_makegates(const struct vlltype&loc, PGBuiltin::Type type, struct str_pair_t str, list*delay, - svector*gates, + std::vector*gates, list*attr) { assert(! pform_cur_module.empty()); @@ -2253,7 +2250,7 @@ void pform_makegates(const struct vlltype&loc, error_count += 1; } - for (unsigned idx = 0 ; idx < gates->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < gates->size() ; idx += 1) { pform_makegate(type, str, delay, (*gates)[idx], attr); } @@ -2369,7 +2366,7 @@ static void pform_make_modgate(perm_string type, void pform_make_modgates(const struct vlltype&loc, perm_string type, struct parmvalue_t*overrides, - svector*gates, + std::vector*gates, std::list*attr) { // The grammer should not allow module gates to happen outside @@ -2399,7 +2396,7 @@ void pform_make_modgates(const struct vlltype&loc, error_count += 1; } - for (unsigned idx = 0 ; idx < gates->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < gates->size() ; idx += 1) { lgate cur = (*gates)[idx]; perm_string cur_name = lex_strings.make(cur.name); diff --git a/pform.h b/pform.h index 1afc9b2ea..044e4b751 100644 --- a/pform.h +++ b/pform.h @@ -445,13 +445,13 @@ extern void pform_makegates(const struct vlltype&loc, PGBuiltin::Type type, struct str_pair_t str, std::list*delay, - svector*gates, + std::vector*gates, std::list*attr); extern void pform_make_modgates(const struct vlltype&loc, perm_string type, struct parmvalue_t*overrides, - svector*gates, + std::vector*gates, std::list*attr); /* Make a continuous assignment node, with optional bit- or part- select. */ diff --git a/pform_dump.cc b/pform_dump.cc index 38c1675cc..7c80aed06 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -950,7 +950,7 @@ void PCase::dump(ostream&out, unsigned ind) const out << " (" << *expr_ << ") /* " << get_fileline() << " */" << endl; dump_attributes_map(out, attributes, ind+2); - for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) { + for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) { PCase::Item*cur = (*items_)[idx]; if (cur->expr.empty()) { @@ -1050,16 +1050,16 @@ void PDoWhile::dump(ostream&out, unsigned ind) const void PEventStatement::dump(ostream&out, unsigned ind) const { - if (expr_.count() == 0) { + if (expr_.size() == 0) { out << setw(ind) << "" << "@* "; - } else if ((expr_.count() == 1) && (expr_[0] == 0)) { + } else if ((expr_.size() == 1) && (expr_[0] == 0)) { out << setw(ind) << "" << "wait fork "; } else { out << setw(ind) << "" << "@(" << *(expr_[0]); - if (expr_.count() > 1) - for (unsigned idx = 1 ; idx < expr_.count() ; idx += 1) + if (expr_.size() > 1) + for (unsigned idx = 1 ; idx < expr_.size() ; idx += 1) out << " or " << *(expr_[idx]); out << ")"; @@ -1077,13 +1077,13 @@ void PEventStatement::dump_inline(ostream&out) const { assert(statement_ == 0); - if (expr_.count() == 0) { + if (expr_.size() == 0) { out << "@* "; } else { out << "@(" << *(expr_[0]); - if (expr_.count() > 1) - for (unsigned idx = 1 ; idx < expr_.count() ; idx += 1) + if (expr_.size() > 1) + for (unsigned idx = 1 ; idx < expr_.size() ; idx += 1) out << " or " << *(expr_[idx]); out << ")"; @@ -1775,7 +1775,7 @@ void pform_dump(ostream&out, Module*mod) void PUdp::dump(ostream&out) const { out << "primitive " << name_ << "(" << ports[0]; - for (unsigned idx = 1 ; idx < ports.count() ; idx += 1) + for (unsigned idx = 1 ; idx < ports.size() ; idx += 1) out << ", " << ports[idx]; out << ");" << endl; @@ -1783,7 +1783,7 @@ void PUdp::dump(ostream&out) const out << " reg " << ports[0] << ";" << endl; out << " table" << endl; - for (unsigned idx = 0 ; idx < tinput.count() ; idx += 1) { + for (unsigned idx = 0 ; idx < tinput.size() ; idx += 1) { out << " "; for (unsigned chr = 0 ; chr < tinput[idx].length() ; chr += 1) out << " " << tinput[idx][chr]; diff --git a/pform_types.h b/pform_types.h index 72529170d..d40dc08a7 100644 --- a/pform_types.h +++ b/pform_types.h @@ -77,9 +77,7 @@ typedef std::pair pform_range_t; /* The lgate is gate instantiation information. */ struct lgate : public LineInfo { - explicit lgate(int = 0) - : parms(0), parms_by_name(0), ranges(0) - { } + explicit lgate() : parms(0), parms_by_name(0), ranges(0) { } std::string name; std::list*parms; diff --git a/svector.h b/svector.h deleted file mode 100644 index 69776a05a..000000000 --- a/svector.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef IVL_svector_H -#define IVL_svector_H -/* - * Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com) - * - * This source code is free software; you can redistribute it - * and/or modify it in source code form under the terms of the GNU - * General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) - * any later version. In order to redistribute the software in - * binary form, you will need a Picture Elements Binary Software - * License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -# include "config.h" -# include -# include -# include - -/* - * This is a way simplified vector class that cannot grow or shrink, - * and is really only able to handle values. It is intended to be - * lighter weight than the STL list class. - */ - -template class svector { - - public: - explicit svector() : nitems_(0), items_(0) { } - - explicit svector(unsigned size) : nitems_(size), items_(new TYPE[size]) - { for (unsigned idx = 0 ; idx < size ; idx += 1) - items_[idx] = TYPE(0); - } - - svector(const svector&that) - : nitems_(that.nitems_), items_(new TYPE[nitems_]) - { for (unsigned idx = 0 ; idx < that.nitems_ ; idx += 1) - items_[idx] = that[idx]; - } - - svector(const svector&l, const svector&r) - : nitems_(l.nitems_ + r.nitems_), items_(new TYPE[nitems_]) - { for (unsigned idx = 0 ; idx < l.nitems_ ; idx += 1) - items_[idx] = l[idx]; - - for (unsigned idx = 0 ; idx < r.nitems_ ; idx += 1) - items_[l.nitems_+idx] = r[idx]; - } - - svector(const svector&l, const TYPE&r) - : nitems_(l.nitems_ + 1), items_(new TYPE[nitems_]) - { for (unsigned idx = 0 ; idx < l.nitems_ ; idx += 1) - items_[idx] = l[idx]; - items_[nitems_-1] = r; - } - - ~svector() { delete[]items_; } - - svector& operator= (const svector&that) - { if (&that == this) return *this; - delete[]items_; - nitems_ = that.nitems_; - items_ = new TYPE[nitems_]; - for (unsigned idx = 0 ; idx < nitems_ ; idx += 1) { - items_[idx] = that.items_[idx]; - } - return *this; - } - - unsigned count() const { return nitems_; } - - TYPE&operator[] (unsigned idx) - { assert(idx < nitems_); - return items_[idx]; - } - - TYPE operator[] (unsigned idx) const - { assert(idx < nitems_); - return items_[idx]; - } - - private: - unsigned nitems_; - TYPE* items_; - -}; - -/* - * Override the implementation of the above template for the string - * type parameter. The initialization to nil works different here. - */ -template <> inline svector::svector(unsigned size) -: nitems_(size), items_(new std::string[size]) -{ -} - -/* -* This is a convenience function that converts an svector to a -* vector. This is to ease the transition from svector to vector so -* that the svector class can be gradually removed. -*/ -template inline std::vector vector_from_svector(const svector&that) -{ - std::vector res (that.count()); - for (unsigned idx = 0 ; idx < that.count() ; idx += 1) - res[idx] = that[idx]; - - return res; -} - -#endif /* IVL_svector_H */ diff --git a/synth2.cc b/synth2.cc index 7a5d7aaf2..3d5e2ccda 100644 --- a/synth2.cc +++ b/synth2.cc @@ -1965,7 +1965,7 @@ bool NetCondit::synth_sync(Design*des, NetScope*scope, assert(else_ != 0); flag = else_->synth_sync(des, scope, ff, nex_map, - nex_out, svector(0)) + nex_out, std::vector()) && flag; DEBUG_SYNTH2_EXIT("NetCondit",flag) return flag;