Skip to content

Commit e15b125

Browse files
committed
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 <[email protected]>
1 parent e67a796 commit e15b125

21 files changed

+106
-254
lines changed

Diff for: PDelays.h

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
*/
2121

22-
# include "svector.h"
2322
# include <string>
2423
# include <list>
2524
# include <iostream>

Diff for: PGate.h

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
*/
2121

22-
# include "svector.h"
2322
# include "StringHeap.h"
2423
# include "named.h"
2524
# include "PNamedItem.h"

Diff for: PUdp.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ PUdp::PUdp(perm_string n, unsigned nports)
2626

2727
unsigned PUdp::find_port(const char*name)
2828
{
29-
for (unsigned idx = 0 ; idx < ports.count() ; idx += 1) {
29+
for (unsigned idx = 0 ; idx < ports.size() ; idx += 1) {
3030

3131
if (ports[idx] == name)
3232
return idx;
3333
}
3434

35-
return ports.count();
35+
return ports.size();
3636
}
3737

Diff for: PUdp.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121

2222
# include <map>
23+
# include <vector>
2324
# include "LineInfo.h"
2425
# include "StringHeap.h"
25-
# include "svector.h"
2626
# include "verinum.h"
2727

2828
class PExpr;
@@ -53,14 +53,14 @@ class PUdp : public LineInfo {
5353
public:
5454
explicit PUdp(perm_string n, unsigned nports);
5555

56-
svector<std::string>ports;
56+
std::vector<std::string> ports;
5757
unsigned find_port(const char*name);
5858

5959
bool sequential;
6060

61-
svector<std::string>tinput;
62-
svector<char> tcurrent;
63-
svector<char> toutput;
61+
std::vector<std::string> tinput;
62+
std::vector<char> tcurrent;
63+
std::vector<char> toutput;
6464

6565
verinum::V initial;
6666

Diff for: Statement.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ const pform_name_t& PCallTask::path() const
208208
return path_;
209209
}
210210

211-
PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, svector<PCase::Item*>*l)
211+
PCase::PCase(ivl_case_quality_t q, NetCase::TYPE t, PExpr*ex, std::vector<PCase::Item*>*l)
212212
: quality_(q), type_(t), expr_(ex), items_(l)
213213
{
214214
}
215215

216216
PCase::~PCase()
217217
{
218218
delete expr_;
219-
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1)
219+
for (unsigned idx = 0 ; idx < items_->size() ; idx += 1)
220220
if ((*items_)[idx]->stat) delete (*items_)[idx]->stat;
221221

222222
delete[]items_;
@@ -300,10 +300,10 @@ PDoWhile::~PDoWhile()
300300
delete statement_;
301301
}
302302

303-
PEventStatement::PEventStatement(const svector<PEEvent*>&ee)
303+
PEventStatement::PEventStatement(const std::vector<PEEvent*>&ee)
304304
: expr_(ee), statement_(0), always_sens_(false)
305305
{
306-
assert(expr_.count() > 0);
306+
assert(expr_.size() > 0);
307307
}
308308

309309

@@ -331,7 +331,7 @@ void PEventStatement::set_statement(Statement*st)
331331
bool PEventStatement::has_aa_term(Design*des, NetScope*scope)
332332
{
333333
bool flag = false;
334-
for (unsigned idx = 0 ; idx < expr_.count() ; idx += 1) {
334+
for (unsigned idx = 0 ; idx < expr_.size() ; idx += 1) {
335335
flag = expr_[idx]->has_aa_term(des, scope) || flag;
336336
}
337337
return flag;

Diff for: Statement.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# include <vector>
2424
# include <list>
2525
# include "ivl_target.h"
26-
# include "svector.h"
2726
# include "StringHeap.h"
2827
# include "PDelays.h"
2928
# include "PExpr.h"
@@ -267,7 +266,7 @@ class PCase : public Statement {
267266
Statement*stat;
268267
};
269268

270-
PCase(ivl_case_quality_t, NetCase::TYPE, PExpr*ex, svector<Item*>*);
269+
PCase(ivl_case_quality_t, NetCase::TYPE, PExpr*ex, std::vector<Item*>*);
271270
~PCase();
272271

273272
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
@@ -280,7 +279,7 @@ class PCase : public Statement {
280279
NetCase::TYPE type_;
281280
PExpr*expr_;
282281

283-
svector<Item*>*items_;
282+
std::vector<Item*>*items_;
284283

285284
private: // not implemented
286285
PCase(const PCase&);
@@ -416,7 +415,7 @@ class PEventStatement : public Statement {
416415

417416
public:
418417

419-
explicit PEventStatement(const svector<PEEvent*>&ee);
418+
explicit PEventStatement(const std::vector<PEEvent*>&ee);
420419
explicit PEventStatement(PEEvent*ee);
421420
// Make an @* statement or make a special @* version with the items
422421
// from functions added and outputs removed for always_comb/latch.
@@ -444,7 +443,7 @@ class PEventStatement : public Statement {
444443
NetProc* elaborate_wait_fork(Design*des, NetScope*scope) const;
445444

446445
private:
447-
svector<PEEvent*>expr_;
446+
std::vector<PEEvent*>expr_;
448447
Statement*statement_;
449448
bool always_sens_;
450449
};

Diff for: elab_anet.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NetNet* PEConcat::elaborate_anet(Design*des, NetScope*scope) const
4848
return 0;
4949
}
5050

51-
svector<NetNet*>nets (parms_.count());
51+
std::vector<NetNet*> nets(parms_.count());
5252
unsigned pins = 0;
5353
unsigned errors = 0;
5454

Diff for: elab_expr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,7 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope,
36373637
unsigned wid_sum = 0;
36383638
unsigned parm_cnt = 0;
36393639
unsigned parm_errors = 0;
3640-
svector<NetExpr*> parms(parms_.size());
3640+
std::vector<NetExpr*> parms(parms_.size());
36413641

36423642
/* Elaborate all the parameters and attach them to the concat node. */
36433643
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1) {

Diff for: elab_net.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope,
4646
{
4747
assert(scope);
4848

49-
svector<NetNet*>nets (parms_.size());
49+
std::vector<NetNet*> nets(parms_.size());
5050
unsigned width = 0;
5151
unsigned errors = 0;
5252

@@ -57,11 +57,11 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope,
5757
}
5858

5959
/* Elaborate the operands of the concatenation. */
60-
for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) {
60+
for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) {
6161

6262
if (debug_elaborate) {
6363
cerr << get_fileline() << ": debug: Elaborate subexpression "
64-
<< idx << " of " << nets.count() << " l-values: "
64+
<< idx << " of " << nets.size() << " l-values: "
6565
<< *parms_[idx] << endl;
6666
}
6767

@@ -117,7 +117,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope,
117117
<< endl;
118118
}
119119

120-
for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) {
120+
for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) {
121121
unsigned wid = nets[idx]->vector_width();
122122
unsigned off = width - wid;
123123
NetTran*ps = new NetTran(scope, scope->local_symbol(),
@@ -141,7 +141,7 @@ NetNet* PEConcat::elaborate_lnet_common_(Design*des, NetScope*scope,
141141

142142
NetPartSelect::dir_t part_dir = NetPartSelect::VP;
143143

144-
for (unsigned idx = 0 ; idx < nets.count() ; idx += 1) {
144+
for (unsigned idx = 0 ; idx < nets.size() ; idx += 1) {
145145
unsigned wid = nets[idx]->vector_width();
146146
unsigned off = width - wid;
147147
NetPartSelect*ps = new NetPartSelect(osig, off, wid, part_dir);

Diff for: elab_scope.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ void PBlock::elaborate_scope(Design*des, NetScope*scope) const
17041704
void PCase::elaborate_scope(Design*des, NetScope*scope) const
17051705
{
17061706
assert(items_);
1707-
for (unsigned idx = 0 ; idx < (*items_).count() ; idx += 1) {
1707+
for (unsigned idx = 0 ; idx < (*items_).size() ; idx += 1) {
17081708
assert( (*items_)[idx] );
17091709

17101710
if (Statement*sp = (*items_)[idx]->stat)

Diff for: elab_sig.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ void PCase::elaborate_sig(Design*des, NetScope*scope) const
852852
if (items_ == 0)
853853
return;
854854

855-
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
855+
for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) {
856856
if ( (*items_)[idx]->stat )
857857
(*items_)[idx]->stat ->elaborate_sig(des,scope);
858858
}

Diff for: elaborate.cc

+15-15
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const
20142014
}
20152015

20162016
assert(udp);
2017-
NetUDP*net = new NetUDP(scope, my_name, udp->ports.count(), udp);
2017+
NetUDP*net = new NetUDP(scope, my_name, udp->ports.size(), udp);
20182018
net->set_line(*this);
20192019
net->rise_time(rise_expr);
20202020
net->fall_time(fall_expr);
@@ -2043,7 +2043,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const
20432043
// ports. If this is simply positional binding in the first
20442044
// place, then get the binding from the base class.
20452045
if (pins_) {
2046-
unsigned nexp = udp->ports.count();
2046+
unsigned nexp = udp->ports.size();
20472047
pins = vector<PExpr*>(nexp);
20482048

20492049
// Scan the bindings, matching them with port names.
@@ -2086,9 +2086,9 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const
20862086
connections. In this case, the port count must be
20872087
right. Check that is is, the get the pin list. */
20882088

2089-
if (pin_count() != udp->ports.count()) {
2089+
if (pin_count() != udp->ports.size()) {
20902090
cerr << get_fileline() << ": error: Wrong number "
2091-
"of ports. Expecting " << udp->ports.count() <<
2091+
"of ports. Expecting " << udp->ports.size() <<
20922092
", got " << pin_count() << "."
20932093
<< endl;
20942094
des->errors += 1;
@@ -2097,7 +2097,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const
20972097

20982098
// No named bindings, just use the positional list I
20992099
// already have.
2100-
assert(pin_count() == udp->ports.count());
2100+
assert(pin_count() == udp->ports.size());
21012101
pins = get_pins();
21022102
}
21032103

@@ -3046,7 +3046,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const
30463046
bool context_is_real = (expr_->expr_type() == IVL_VT_REAL);
30473047
bool context_unsigned = !expr_->has_sign();
30483048

3049-
for (unsigned idx = 0; idx < items_->count(); idx += 1) {
3049+
for (unsigned idx = 0; idx < items_->size(); idx += 1) {
30503050

30513051
PCase::Item*cur = (*items_)[idx];
30523052

@@ -3082,7 +3082,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const
30823082

30833083
context_width = test_case_width(des, scope, expr_, context_mode);
30843084

3085-
for (unsigned idx = 0; idx < items_->count(); idx += 1) {
3085+
for (unsigned idx = 0; idx < items_->size(); idx += 1) {
30863086

30873087
PCase::Item*cur = (*items_)[idx];
30883088

@@ -3126,7 +3126,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const
31263126
be some cases that have multiple guards. Count each as a
31273127
separate item. */
31283128
unsigned icount = 0;
3129-
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
3129+
for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) {
31303130
PCase::Item*cur = (*items_)[idx];
31313131

31323132
if (cur->expr.empty())
@@ -3143,7 +3143,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const
31433143
is a "default" case. Otherwise, the guard has one or more
31443144
expressions, and each guard is a case. */
31453145
unsigned inum = 0;
3146-
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
3146+
for (unsigned idx = 0 ; idx < items_->size() ; idx += 1) {
31473147

31483148
ivl_assert(*this, inum < icount);
31493149
PCase::Item*cur = (*items_)[idx];
@@ -4648,7 +4648,7 @@ NetProc* PEventStatement::elaborate_st(Design*des, NetScope*scope,
46484648
/* If there are no expressions, this is a signal that it is an
46494649
@* statement. Generate an expression to use. */
46504650

4651-
if (expr_.count() == 0) {
4651+
if (expr_.size() == 0) {
46524652
assert(enet);
46534653
/* For synthesis or always_comb/latch we want just the inputs,
46544654
* but for the rest we want inputs and outputs that may cause
@@ -4732,7 +4732,7 @@ cerr << endl;
47324732

47334733
expr_count = 1;
47344734

4735-
} else for (unsigned idx = 0 ; idx < expr_.count() ; idx += 1) {
4735+
} else for (unsigned idx = 0 ; idx < expr_.size() ; idx += 1) {
47364736

47374737
assert(expr_[idx]->expr());
47384738

@@ -4889,7 +4889,7 @@ NetProc* PEventStatement::elaborate_wait(Design*des, NetScope*scope,
48894889
NetProc*enet) const
48904890
{
48914891
assert(scope);
4892-
assert(expr_.count() == 1);
4892+
assert(expr_.size() == 1);
48934893

48944894
if (scope->in_func()) {
48954895
cerr << get_fileline() << ": error: functions cannot have "
@@ -5051,7 +5051,7 @@ NetProc* PEventStatement::elaborate_wait(Design*des, NetScope*scope,
50515051
NetProc* PEventStatement::elaborate_wait_fork(Design*des, NetScope*scope) const
50525052
{
50535053
assert(scope);
5054-
assert(expr_.count() == 1);
5054+
assert(expr_.size() == 1);
50555055
assert(expr_[0] == 0);
50565056
assert(! statement_);
50575057

@@ -5086,7 +5086,7 @@ NetProc* PEventStatement::elaborate_wait_fork(Design*des, NetScope*scope) const
50865086
NetProc* PEventStatement::elaborate(Design*des, NetScope*scope) const
50875087
{
50885088
/* Check to see if this is a wait fork statement. */
5089-
if ((expr_.count() == 1) && (expr_[0] == 0))
5089+
if ((expr_.size() == 1) && (expr_[0] == 0))
50905090
return elaborate_wait_fork(des, scope);
50915091

50925092
NetProc*enet = 0;
@@ -5100,7 +5100,7 @@ NetProc* PEventStatement::elaborate(Design*des, NetScope*scope) const
51005100
enet->set_line(*this);
51015101
}
51025102

5103-
if ((expr_.count() == 1) && (expr_[0]->type() == PEEvent::POSITIVE))
5103+
if ((expr_.size() == 1) && (expr_[0]->type() == PEEvent::POSITIVE))
51045104
return elaborate_wait(des, scope, enet);
51055105

51065106
return elaborate_st(des, scope, enet);

Diff for: net_udp.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NetUDP::NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp *u)
3131
for (unsigned idx = 1 ; idx < pins ; idx += 1) {
3232
pin(idx).set_dir(Link::INPUT);
3333
}
34-
table_idx = udp->tinput.count()-1;
34+
table_idx = udp->tinput.size() - 1;
3535
}
3636

3737
bool NetUDP::first(string&inp, char&out) const
@@ -44,7 +44,7 @@ bool NetUDP::next(string&inp, char&out) const
4444
{
4545
table_idx++;
4646

47-
if (table_idx >= udp->tinput.count()) return false;
47+
if (table_idx >= udp->tinput.size()) return false;
4848

4949
if (is_sequential()) {
5050
inp = string("") + udp->tcurrent[table_idx] +
@@ -84,11 +84,11 @@ char NetUDP::get_initial() const
8484

8585
unsigned NetUDP::port_count() const
8686
{
87-
return udp->ports.count();
87+
return udp->ports.size();
8888
}
8989

9090
string NetUDP::port_name(unsigned idx) const
9191
{
92-
assert(idx < udp->ports.count());
92+
assert(idx < udp->ports.size());
9393
return udp->ports[idx];
9494
}

Diff for: netlist.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,7 @@ class NetUDP : public NetNode {
26262626
return false when the scan is done. */
26272627
bool first(std::string&inp, char&out) const;
26282628
bool next(std::string&inp, char&out) const;
2629-
unsigned rows() const { return udp->tinput.count(); }
2629+
unsigned rows() const { return udp->tinput.size(); }
26302630

26312631
unsigned nin() const { return pin_count()-1; }
26322632
bool is_sequential() const { return udp->sequential; }

0 commit comments

Comments
 (0)