Skip to content

Commit

Permalink
Update tgt- directories with cppcheck suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caryr committed Jan 2, 2021
1 parent 1d318c4 commit fbe42f1
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 34 deletions.
5 changes: 3 additions & 2 deletions tgt-fpga/d-lpm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2014 Stephen Williams ([email protected])
* Copyright (c) 2003-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -553,7 +553,7 @@ static void lpm_show_mux(ivl_lpm_t net)
edif_cellref_t ref;
edif_joint_t jnt;

unsigned idx, rdx;
unsigned idx;

char cellname[32];

Expand Down Expand Up @@ -626,6 +626,7 @@ static void lpm_show_mux(ivl_lpm_t net)
}

for (idx = 0 ; idx < wid_z ; idx += 1) {
unsigned rdx;
for (rdx = 0 ; rdx < wid_r ; rdx += 1) {
unsigned pin;

Expand Down
4 changes: 1 addition & 3 deletions tgt-fpga/mangle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2010 Stephen Williams ([email protected])
* Copyright (c) 2001-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -30,9 +30,7 @@ static size_t xnf_mangle_scope_name(ivl_scope_t net, char*buf, size_t nbuf)
if (parent) {
cnt = xnf_mangle_scope_name(parent, buf, nbuf);
buf += cnt;
nbuf -= cnt;
*buf++ = '/';
nbuf -= 1;
cnt += 1;
}

Expand Down
4 changes: 2 additions & 2 deletions tgt-stub/cppcheck.sup
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// are not used here.

// target_design()
unusedFunction:stub.c:1774
unusedFunction:stub.c:1837

// target_query()
unusedFunction:stub.c:1844
unusedFunction:stub.c:1907
4 changes: 2 additions & 2 deletions tgt-stub/expression.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007-2013 Stephen Williams ([email protected])
* Copyright (c) 2007-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -75,7 +75,7 @@ static void show_branch_access_expression(ivl_expr_t net, unsigned ind)
}

ivl_discipline_t tb_disc = discipline_of_nexus(tb);
if (ta_disc == 0) {
if (tb_disc == 0) {
fprintf(out, "%*sERROR: Reference terminal of branch has no discipline\n",
ind, "");
stub_errors += 1;
Expand Down
4 changes: 2 additions & 2 deletions tgt-stub/stub.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2020 Stephen Williams ([email protected])
* Copyright (c) 2000-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -1427,7 +1427,7 @@ static void show_signal(ivl_signal_t net)

fprintf(out, " %s %s %s", type, sign, port);
show_type_of_signal(net);
fprintf(out, " %s[word=%u, adr=%d] <width=%u%s> <discipline=%s> ",
fprintf(out, " %s[word=%u, adr=%u] <width=%u%s> <discipline=%s> ",
ivl_signal_basename(net),
idx, ivl_signal_array_base(net)+idx,
ivl_signal_width(net),
Expand Down
2 changes: 1 addition & 1 deletion tgt-verilog/cppcheck.sup
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// are not used here.

// target_design()
unusedFunction:verilog.c:408
unusedFunction:verilog.c:411
4 changes: 2 additions & 2 deletions tgt-vhdl/vhdl_element.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VHDL abstract syntax elements.
*
* Copyright (C) 2008-2011 Nick Gasson ([email protected])
* Copyright (C) 2008-2021 Nick Gasson ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,7 +66,7 @@ vector<vhdl_element*> vhdl_element::allocated_;
// Just a counter of total bytes allocated for statistics
size_t vhdl_element::total_alloc_(0);

void vhdl_element::set_comment(std::string comment)
void vhdl_element::set_comment(const std::string&comment)
{
comment_ = comment;
}
Expand Down
4 changes: 2 additions & 2 deletions tgt-vhdl/vhdl_element.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VHDL abstract syntax elements.
*
* Copyright (C) 2008 Nick Gasson ([email protected])
* Copyright (C) 2008-2021 Nick Gasson ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -52,7 +52,7 @@ public:
virtual void emit(std::ostream &of, int level=0) const = 0;
void print() const;

void set_comment(std::string comment);
void set_comment(const std::string&comment);

static int free_all_objects();
static size_t total_allocated();
Expand Down
14 changes: 7 additions & 7 deletions tgt-vhdl/vhdl_syntax.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VHDL abstract syntax elements.
*
* Copyright (C) 2008-2013 Nick Gasson ([email protected])
* Copyright (C) 2008-2021 Nick Gasson ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +38,7 @@ typedef set<vhdl_var_ref*> vhdl_var_set_t;

class vhdl_expr : public vhdl_element {
public:
vhdl_expr(const vhdl_type* type, bool isconst=false)
explicit vhdl_expr(const vhdl_type* type, bool isconst=false)
: type_(type), isconst_(isconst) {}
virtual ~vhdl_expr();

Expand Down Expand Up @@ -227,7 +227,7 @@ enum time_unit_t {

class vhdl_const_time : public vhdl_expr {
public:
vhdl_const_time(uint64_t value, time_unit_t units = TIME_UNIT_NS)
explicit vhdl_const_time(uint64_t value, time_unit_t units = TIME_UNIT_NS)
: vhdl_expr(vhdl_type::time(), true), value_(value), units_(units) {}
void emit(std::ostream &of, int level) const;
private:
Expand Down Expand Up @@ -464,8 +464,8 @@ enum vhdl_severity_t {

class vhdl_report_stmt : public vhdl_seq_stmt {
public:
vhdl_report_stmt(vhdl_expr *text,
vhdl_severity_t severity = SEVERITY_NOTE);
explicit vhdl_report_stmt(vhdl_expr *text,
vhdl_severity_t severity = SEVERITY_NOTE);
virtual ~vhdl_report_stmt() {}

virtual void emit(ostream& of, int level) const;
Expand Down Expand Up @@ -602,8 +602,8 @@ private:
*/
class vhdl_decl : public vhdl_element {
public:
vhdl_decl(const string& name, const vhdl_type *type = NULL,
vhdl_expr *initial = NULL)
explicit vhdl_decl(const string& name, const vhdl_type *type = NULL,
vhdl_expr *initial = NULL)
: name_(name), type_(type), initial_(initial),
has_initial_(initial != NULL) {}
virtual ~vhdl_decl();
Expand Down
4 changes: 2 additions & 2 deletions tgt-vhdl/vhdl_type.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VHDL variable and signal types.
*
* Copyright (C) 2008-2013 Nick Gasson ([email protected])
* Copyright (C) 2008-2021 Nick Gasson ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -188,7 +188,7 @@ vhdl_type *vhdl_type::type_for(int width, bool issigned,
return vhdl_type::nunsigned(width, lsb);
}

vhdl_type *vhdl_type::array_of(vhdl_type *b, std::string &n, int m, int l)
vhdl_type *vhdl_type::array_of(vhdl_type *b, const std::string &n, int m, int l)
{
return new vhdl_type(b, n, m, l);
}
6 changes: 3 additions & 3 deletions tgt-vhdl/vhdl_type.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VHDL variable and signal types.
*
* Copyright (C) 2008-2010 Nick Gasson ([email protected])
* Copyright (C) 2008-2021 Nick Gasson ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -46,7 +46,7 @@ enum vhdl_type_name_t {
class vhdl_type : public vhdl_element {
public:
// Scalar constructor
vhdl_type(vhdl_type_name_t name, int msb = 0, int lsb = 0)
explicit vhdl_type(vhdl_type_name_t name, int msb = 0, int lsb = 0)
: name_(name), msb_(msb), lsb_(lsb), base_(NULL) {}

// Array constructor
Expand Down Expand Up @@ -84,7 +84,7 @@ public:

static vhdl_type *type_for(int width, bool issigned,
int lsb=0, bool unresolved=false);
static vhdl_type *array_of(vhdl_type *b, std::string &n, int m, int l);
static vhdl_type *array_of(vhdl_type *b, const std::string &n, int m, int l);
protected:
vhdl_type_name_t name_;
int msb_, lsb_;
Expand Down
2 changes: 1 addition & 1 deletion tgt-vlog95/cppcheck.sup
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
unusedFunction:vlog95.c:59

// target_query()
unusedFunction:vlog95.c:251
unusedFunction:vlog95.c:257
6 changes: 3 additions & 3 deletions tgt-vlog95/numbers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2014 Cary R. ([email protected])
* Copyright (C) 2011-2021 Cary R. ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,7 +65,7 @@ static int32_t get_int32_from_bits(const char *bits, unsigned nbits,
// HERE: Need to emit 1 instead of -1 for some of the constants.
// if (is_signed && (nbits > 1) && (msb == '1') && (trim_wid < 32U)) {
if (is_signed && (msb == '1') && (trim_wid < 32U)) {
value |= ~(((int32_t)1 << trim_wid) - (int32_t)1);
value |= ~(((uint32_t)1 << trim_wid) - (uint32_t)1);
}
*result_type = 0;
return value;
Expand Down Expand Up @@ -309,7 +309,7 @@ int64_t get_int64_from_number(ivl_expr_t expr, int *result_type)
}
/* Sign extend as needed. */
if (is_signed && (msb == '1') && (trim_wid < 64U)) {
value |= ~(((int64_t)1 << trim_wid) - (int64_t)1);
value |= ~(((uint64_t)1 << trim_wid) - (uint64_t)1);
}
*result_type = 0;
return value;
Expand Down
4 changes: 2 additions & 2 deletions tgt-vvp/cppcheck.sup
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// are not used here.

// target_design()
unusedFunction:vvp.c:148
unusedFunction:vvp.c:152

// target_query()
unusedFunction:vvp.c:246
unusedFunction:vvp.c:250

0 comments on commit fbe42f1

Please sign in to comment.