From 7299625ab56a8c80549b01e9eb1e3c142a579b47 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sat, 2 Jan 2021 13:52:25 -0800 Subject: [PATCH] Cleanup vvp with suggestions from cppcheck --- vvp/arith.cc | 6 +++--- vvp/arith.h | 4 ++-- vvp/array.cc | 13 +++---------- vvp/cppcheck.sup | 2 +- vvp/file_line.cc | 44 +++++++++++++++++++++++++----------------- vvp/island_tran.cc | 12 +++++------- vvp/main.cc | 4 +++- vvp/schedule.cc | 3 ++- vvp/vpi_callback.cc | 5 +++-- vvp/vpi_darray.cc | 13 +++---------- vvp/vpi_priv.cc | 8 +++++--- vvp/vpi_tasks.cc | 15 +++++++------- vvp/vpi_vthr_vector.cc | 37 +++++++++++++++++++---------------- vvp/vthread.cc | 9 ++++++--- vvp/vvp_net.h | 4 ++-- 15 files changed, 92 insertions(+), 87 deletions(-) diff --git a/vvp/arith.cc b/vvp/arith.cc index 409cb71a0..092a5c583 100644 --- a/vvp/arith.cc +++ b/vvp/arith.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2017 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -35,7 +35,7 @@ vvp_arith_::vvp_arith_(unsigned wid) } } -void vvp_arith_::dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit) +void vvp_arith_::dispatch_operand_(vvp_net_ptr_t ptr, const vvp_vector4_t&bit) { unsigned port = ptr.port(); switch (port) { @@ -159,7 +159,7 @@ void vvp_arith_cast_vec2::recv_real(vvp_net_ptr_t ptr, double bit, void vvp_arith_cast_vec2::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit, vvp_context_t) { - vvp_vector2_t tmp = bit; + vvp_vector2_t tmp = vvp_vector2_t(bit); ptr.ptr()->send_vec4(vector2_to_vector4(tmp,wid_), 0); } diff --git a/vvp/arith.h b/vvp/arith.h index 1cf6888d2..d473d2953 100644 --- a/vvp/arith.h +++ b/vvp/arith.h @@ -1,7 +1,7 @@ #ifndef IVL_arith_H #define IVL_arith_H /* - * Copyright (c) 2001-2017 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -42,7 +42,7 @@ class vvp_arith_ : public vvp_net_fun_t { vvp_context_t ctx); protected: - void dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit); + void dispatch_operand_(vvp_net_ptr_t ptr, const vvp_vector4_t&bit); protected: unsigned wid_; diff --git a/vvp/array.cc b/vvp/array.cc index 8ad909505..3c53e50aa 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2007-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 @@ -210,18 +210,11 @@ void __vpiArray::get_word_value(struct __vpiArrayWord*word, p_vpi_value vp) case vpiHexStrVal: case vpiScalarVal: case vpiIntVal: - { - vvp_vector4_t v; - vals->get_word(index, v); - vpip_vec4_get_value(v, vals_width, signed_flag, vp); - } - break; - case vpiVectorVal: { vvp_vector4_t v; vals->get_word(index, v); - vpip_vec2_get_value(v, vals_width, signed_flag, vp); + vpip_vec4_get_value(v, vals_width, signed_flag, vp); } break; @@ -1460,7 +1453,7 @@ value_callback*vpip_array_word_change(p_cb_data data) struct __vpiArray*parent = 0; array_word_value_callback*cbh = 0; if (struct __vpiArrayWord*word = array_var_word_from_handle(data->obj)) { - parent = (__vpiArray*) word->get_parent(); + parent = static_cast<__vpiArray*>(word->get_parent()); unsigned addr = word->get_index(); cbh = new array_word_value_callback(data); cbh->word_addr = addr; diff --git a/vvp/cppcheck.sup b/vvp/cppcheck.sup index bcdd0ab0e..1d0fe930b 100644 --- a/vvp/cppcheck.sup +++ b/vvp/cppcheck.sup @@ -1,6 +1,6 @@ // The new() operator is always used to allocate space for this class and // pool is defined there. -uninitVar:vvp_net.cc:190 +uninitMemberVar:vvp_net.cc:190 // These functions are not used by Icarus // vpi_chk_error() diff --git a/vvp/file_line.cc b/vvp/file_line.cc index 738189805..885b0b384 100644 --- a/vvp/file_line.cc +++ b/vvp/file_line.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2020 Cary R. (cygcary@yahoo.com) + * Copyright (C) 2011-2021 Cary R. (cygcary@yahoo.com) * * 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 @@ -19,12 +19,18 @@ # include "compile.h" # include "vpi_priv.h" -struct __vpiFileLine : public __vpiHandle { - __vpiFileLine(); +class __vpiFileLine : public __vpiHandle { + public: + explicit __vpiFileLine(const char*desc_, long file_idx_, long lineno_); int get_type_code(void) const; int vpi_get(int code); char* vpi_get_str(int code); + const char* get_description() const { return description; }; + unsigned get_file_idx() const { return file_idx; }; + unsigned get_lineno() const { return lineno; }; + + private: const char *description; unsigned file_idx; unsigned lineno; @@ -35,12 +41,12 @@ bool code_is_instrumented = false; static int file_line_get(int type, vpiHandle ref) { - struct __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref); + __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref); assert(rfp); switch (type) { case vpiLineNo: - return rfp->lineno; + return rfp->get_lineno(); default: return vpiUndefined; } @@ -48,23 +54,30 @@ static int file_line_get(int type, vpiHandle ref) static char *file_line_get_str(int type, vpiHandle ref) { - struct __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref); + __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref); assert(rfp); switch (type) { case vpiFile: - assert(rfp->file_idx < file_names.size()); - return simple_set_rbuf_str(file_names[rfp->file_idx]); + assert(rfp->get_file_idx() < file_names.size()); + return simple_set_rbuf_str(file_names[rfp->get_file_idx()]); case _vpiDescription: - if (rfp->description) return simple_set_rbuf_str(rfp->description); - else return simple_set_rbuf_str("Procedural tracing."); + if (rfp->get_description()) { + return simple_set_rbuf_str(rfp->get_description()); + } else return simple_set_rbuf_str("Procedural tracing."); default: return 0; } } -inline __vpiFileLine::__vpiFileLine() -{ } +inline __vpiFileLine::__vpiFileLine(const char*desc_, long file_idx_, + long lineno_) +{ + if (desc_) description = vpip_name_string(desc_); + else description = 0; + file_idx = (unsigned) file_idx_; + lineno = (unsigned) lineno_; +} int __vpiFileLine::get_type_code(void) const { return _vpiFileLine; } @@ -78,15 +91,10 @@ char* __vpiFileLine::vpi_get_str(int code) vpiHandle vpip_build_file_line(char*description, long file_idx, long lineno) { - struct __vpiFileLine*obj = new struct __vpiFileLine; + __vpiFileLine*obj = new __vpiFileLine(description, file_idx, lineno); /* You can turn on the diagnostic output if we find a %file_line. */ code_is_instrumented = true; - if (description) obj->description = vpip_name_string(description); - else obj->description = 0; - obj->file_idx = (unsigned) file_idx; - obj->lineno = (unsigned) lineno; - return obj; } diff --git a/vvp/island_tran.cc b/vvp/island_tran.cc index 7d2953708..cdb3946a6 100644 --- a/vvp/island_tran.cc +++ b/vvp/island_tran.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2018 Stephen Williams (steve@icarus.com) + * Copyright (c) 2008-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 @@ -46,7 +46,7 @@ struct vvp_island_branch_tran : public vvp_island_branch { vvp_island_branch_tran(vvp_net_t*en__, bool active_high__, unsigned width__, unsigned part__, unsigned offset__, bool resistive__); - bool run_test_enabled(); + void run_test_enabled(); void run_resolution(); void run_output(); @@ -85,11 +85,10 @@ void vvp_island_tran::run_island() // Test to see if any of the branches are enabled. This loop // tests the enabled inputs for all the branches and caches // the results in the state for each branch. - bool runnable = false; for (vvp_island_branch*cur = branches_ ; cur ; cur = cur->next_branch) { vvp_island_branch_tran*tmp = dynamic_cast(cur); assert(tmp); - runnable |= tmp->run_test_enabled(); + tmp->run_test_enabled(); } // Now resolve all the branches in the island. @@ -184,7 +183,7 @@ void vvp_island_tran::count_drivers(vvp_island_port*port, unsigned bit_idx, count_drivers_(endpoint, false, bit_idx, counts); } -bool vvp_island_branch_tran::run_test_enabled() +void vvp_island_branch_tran::run_test_enabled() { vvp_island_port*ep = en? dynamic_cast (en->fun) : 0; @@ -192,7 +191,7 @@ bool vvp_island_branch_tran::run_test_enabled() // tran branch. Assume it is always enabled. if (ep == 0) { state = tran_enabled; - return true; + return; } // Get the input that is driving this enable. @@ -229,7 +228,6 @@ bool vvp_island_branch_tran::run_test_enabled() state = tran_unknown; break; } - return (state != tran_disabled); } // The IEEE standard does not specify the behaviour when a tranif control diff --git a/vvp/main.cc b/vvp/main.cc index 9fc69fa06..4d7d85fbb 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -31,6 +31,7 @@ # include # include # include +# include #ifdef CHECK_WITH_VALGRIND # include #endif @@ -155,6 +156,7 @@ void verify_version(char*ivl_ver, char*commit) if (rc == 2) { file_extra[0] = 0; rc = sscanf(ivl_ver, "%d.%d %127s", &file_major, &file_minor, file_extra); + assert((rc == 2) || (rc == 3)); file_minor2 = 0; } delete[] ivl_ver; diff --git a/vvp/schedule.cc b/vvp/schedule.cc index e5b9df561..95caeccf5 100644 --- a/vvp/schedule.cc +++ b/vvp/schedule.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -74,6 +74,7 @@ void event_s::single_step_display(void) struct event_time_s { event_time_s() { count_time_events += 1; + delay = 0; start = 0; active = 0; inactive = 0; diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index bd0b80cad..0c9a38d92 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -691,7 +691,8 @@ void callback_execute(struct __vpiCallback*cur) case vpiScaledRealTime: { cur->cb_data.time->real = vpip_time_to_scaled_real(schedule_simtime(), - (__vpiScope *) vpi_handle(vpiScope, cur->cb_data.obj)); + static_cast<__vpiScope *>(vpi_handle(vpiScope, + cur->cb_data.obj))); break; } case vpiSuppressTime: diff --git a/vvp/vpi_darray.cc b/vvp/vpi_darray.cc index 9159bcee4..bc63ff741 100644 --- a/vvp/vpi_darray.cc +++ b/vvp/vpi_darray.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2015 Stephen Williams (steve@icarus.com) + * Copyright (c) 2012-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 @@ -109,18 +109,11 @@ void __vpiDarrayVar::get_word_value(struct __vpiArrayWord*word, p_vpi_value vp) case vpiHexStrVal: case vpiScalarVal: case vpiIntVal: - { - vvp_vector4_t v; - aobj->get_word(index, v); // width == 1? - vpip_vec4_get_value(v, 1, false, vp); // TODO sign? - } - break; - - case vpiVectorVal: // TODO vpip_vec2_ or vpip_vec4_? + case vpiVectorVal: { vvp_vector4_t v; aobj->get_word(index, v); - vpip_vec2_get_value(v, v.size(), false, vp); // TODO sign? + vpip_vec4_get_value(v, v.size(), false, vp); // TODO sign? } break; diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 42d301a50..d8cea2add 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2008-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 @@ -111,7 +111,8 @@ unsigned vpip_size(__vpiSignal *sig) __vpiScope* vpip_scope(__vpiSignal*sig) { if (sig->is_netarray) - return (__vpiScope*) vpi_handle(vpiScope, sig->within.parent); + return static_cast<__vpiScope*>(vpi_handle(vpiScope, + sig->within.parent)); else return sig->within.scope; } @@ -119,7 +120,8 @@ __vpiScope* vpip_scope(__vpiSignal*sig) __vpiScope* vpip_scope(__vpiRealVar*sig) { if (sig->is_netarray) - return (__vpiScope*) vpi_handle(vpiScope, sig->within.parent); + return static_cast<__vpiScope*>(vpi_handle(vpiScope, + sig->within.parent)); else return sig->within.scope; } diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index 27da387da..30b577f1f 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -601,8 +601,9 @@ void def_table_delete(void) } #endif -struct __vpiSystfIterator : public __vpiHandle { - __vpiSystfIterator(); +class __vpiSystfIterator : public __vpiHandle { + public: + explicit __vpiSystfIterator(unsigned idx); int get_type_code(void) const; vpiHandle vpi_index(int idx); free_object_fun_t free_object_fun(void); @@ -612,7 +613,7 @@ struct __vpiSystfIterator : public __vpiHandle { static vpiHandle systf_iterator_scan(vpiHandle ref, int) { - struct __vpiSystfIterator*obj = dynamic_cast<__vpiSystfIterator*>(ref); + __vpiSystfIterator*obj = dynamic_cast<__vpiSystfIterator*>(ref); if (obj->next >= def_count) { vpi_free_object(ref); @@ -634,13 +635,13 @@ static vpiHandle systf_iterator_scan(vpiHandle ref, int) static int systf_iterator_free_object(vpiHandle ref) { - struct __vpiSystfIterator*obj = dynamic_cast<__vpiSystfIterator*>(ref); + __vpiSystfIterator*obj = dynamic_cast<__vpiSystfIterator*>(ref); delete obj; return 1; } -inline __vpiSystfIterator::__vpiSystfIterator() -{ } +inline __vpiSystfIterator::__vpiSystfIterator(unsigned idx) +{ next = idx; } int __vpiSystfIterator::get_type_code(void) const { return vpiIterator; } @@ -664,7 +665,7 @@ vpiHandle vpip_make_systf_iterator(void) } if (!have_user_defn) return 0; - struct __vpiSystfIterator*res = new __vpiSystfIterator; + __vpiSystfIterator*res = new __vpiSystfIterator(idx); res->next = idx; return res; } diff --git a/vvp/vpi_vthr_vector.cc b/vvp/vpi_vthr_vector.cc index db279daad..232b24a2c 100644 --- a/vvp/vpi_vthr_vector.cc +++ b/vvp/vpi_vthr_vector.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com) * Copyright (c) 2001 Stephan Boettcher * * This source code is free software; you can redistribute it @@ -50,12 +50,17 @@ extern const char hex_digits[256]; extern const char oct_digits[64]; -struct __vpiVThrWord : public __vpiHandle { - __vpiVThrWord(); +class __vpiVThrWord : public __vpiHandle { + public: + explicit __vpiVThrWord(unsigned base); int get_type_code(void) const; int vpi_get(int code); void vpi_get_value(p_vpi_value val); + int get_subtype() const { return subtype; }; + unsigned get_index() const { return index; }; + + private: const char* name; int subtype; unsigned index; @@ -63,12 +68,12 @@ struct __vpiVThrWord : public __vpiHandle { static int vthr_word_get(int code, vpiHandle ref) { - struct __vpiVThrWord*rfp = dynamic_cast<__vpiVThrWord*>(ref); + __vpiVThrWord*rfp = dynamic_cast<__vpiVThrWord*>(ref); switch (code) { case vpiConstType: - return rfp->subtype; + return rfp->get_subtype(); #if defined(CHECK_WITH_VALGRIND) || defined(BR916_STOPGAP_FIX) case _vpiFromThr: @@ -91,7 +96,7 @@ static double vlg_round(double rval) static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp) { - struct __vpiVThrWord*obj = dynamic_cast<__vpiVThrWord*>(ref); + __vpiVThrWord*obj = dynamic_cast<__vpiVThrWord*>(ref); char *rbuf = (char *) need_result_buf(66, RBUF_VAL); double val = 0.0; @@ -102,7 +107,8 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp) will not have access to the proper value. Punt and return a 0.0 value instead. */ if (vpip_current_vthread) - val = vthread_get_real_stack(vpip_current_vthread, obj->index); + val = vthread_get_real_stack(vpip_current_vthread, + obj->get_index()); switch (vp->format) { @@ -174,8 +180,12 @@ static void vthr_real_get_value(vpiHandle ref, s_vpi_value*vp) } } -inline __vpiVThrWord::__vpiVThrWord() -{ } +inline __vpiVThrWord::__vpiVThrWord(unsigned base) +{ + name = vpip_name_string("W<>"); + subtype = vpiRealConst; + index = base; +} int __vpiVThrWord::get_type_code(void) const { return vpiConstant; } @@ -188,14 +198,9 @@ void __vpiVThrWord::vpi_get_value(p_vpi_value val) vpiHandle vpip_make_vthr_word(unsigned base, const char*type) { - struct __vpiVThrWord*obj = new __vpiVThrWord; - assert(type[0] == 'r'); - - obj->name = vpip_name_string("W<>"); - obj->subtype = vpiRealConst; assert(base < 65536); - obj->index = base; + __vpiVThrWord*obj = new __vpiVThrWord(base); return obj; } @@ -449,7 +454,6 @@ void __vpiVThrVec4Stack::vpi_get_value_octstr_(p_vpi_value vp, const vvp_vector4 if (owid > 0) { owid -= 1; rbuf[owid] = oct_digits[oval]; - oval = 0; } vp->value.str = rbuf; } @@ -490,7 +494,6 @@ void __vpiVThrVec4Stack::vpi_get_value_hexstr_(p_vpi_value vp, const vvp_vector4 if (hwid > 0) { hwid -= 1; rbuf[hwid] = hex_digits[hval]; - hval = 0; } vp->value.str = rbuf; } diff --git a/vvp/vthread.cc b/vvp/vthread.cc index ef3b969c0..8e47312b8 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -2654,7 +2654,7 @@ static bool do_disable(vthread_t thr, vthread_t match) */ bool of_DISABLE(vthread_t thr, vvp_code_t cp) { - __vpiScope*scope = (__vpiScope*)cp->handle; + __vpiScope*scope = static_cast<__vpiScope*>(cp->handle); bool disabled_myself_flag = false; @@ -3954,8 +3954,11 @@ bool of_LOAD_VEC4(vthread_t thr, vvp_code_t cp) if (sig == 0) { cerr << thr->get_fileline() << "%load/v error: Net arg not a signal? " - << (net->fil ? typeid(*net->fil).name() : typeid(*net->fun).name()) << endl; + << (net->fil ? typeid(*net->fil).name() : + typeid(*net->fun).name()) + << endl; assert(sig); + return true; } // Extract the value from the signal and directly into the diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index 4533915cc..a243df5e5 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -1,7 +1,7 @@ #ifndef IVL_vvp_net_H #define IVL_vvp_net_H /* - * Copyright (c) 2004-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2004-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 @@ -674,7 +674,7 @@ class vvp_vector2_t { // is true and there are X or Z bits, then the result becomes // a NaN value. If enable_NaN is false then X or Z bits are // converted to 0 as per the standard Verilog rules. - vvp_vector2_t(const vvp_vector4_t&that, bool allow_NaN = false); + explicit vvp_vector2_t(const vvp_vector4_t&that, bool allow_NaN = false); // Make from a native long and a specified width. vvp_vector2_t(unsigned long val, unsigned wid); // Make with the width, and filled with 1 or 0 bits.