diff --git a/cppcheck-global.sup b/cppcheck-global.sup new file mode 100644 index 000000000..f14df5655 --- /dev/null +++ b/cppcheck-global.sup @@ -0,0 +1,4 @@ +// Skip all messages about missing system include files +missingIncludeSystem +// Skip the active checker report message +checkersReport diff --git a/tgt-blif/Makefile.in b/tgt-blif/Makefile.in index 9908466a2..aebe254ec 100644 --- a/tgt-blif/Makefile.in +++ b/tgt-blif/Makefile.in @@ -59,6 +59,8 @@ distclean: clean cppcheck: $(O:.o=.cc) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-null/Makefile.in b/tgt-null/Makefile.in index 50fbfa674..b488cab51 100644 --- a/tgt-null/Makefile.in +++ b/tgt-null/Makefile.in @@ -57,6 +57,8 @@ distclean: clean cppcheck: $(O:.o=.c) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-pcb/Makefile.in b/tgt-pcb/Makefile.in index 5b6c77157..bbc9aaf31 100644 --- a/tgt-pcb/Makefile.in +++ b/tgt-pcb/Makefile.in @@ -62,6 +62,8 @@ distclean: clean cppcheck: $(O:.o=.cc) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ -UYY_USER_INIT \ -UYYPARSE_PARAM -UYYPRINT -Ushort -Usize_t -Uyyoverflow \ diff --git a/tgt-pcb/show_pcb.cc b/tgt-pcb/show_pcb.cc index fc46f76ef..83e9f7fbb 100644 --- a/tgt-pcb/show_pcb.cc +++ b/tgt-pcb/show_pcb.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 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 @@ -30,7 +30,7 @@ static void show_pcb_header(FILE*fpcb) fprintf(fpcb, "Grid[100.0 0 0 1]\n"); } -static void show_pcb_element(FILE*fpcb, const string&refdes, element_data_t*elem); +static void show_pcb_element(FILE*fpcb, const string&refdes, const element_data_t*elem); void show_pcb(const char*pcb_path) { @@ -53,7 +53,7 @@ void show_pcb(const char*pcb_path) fclose(fpcb); } -static void show_pcb_element(FILE*fpcb, const string&refdes, element_data_t*elem) +static void show_pcb_element(FILE*fpcb, const string&refdes, const element_data_t*elem) { string descr = elem->description; const string&value = elem->value; diff --git a/tgt-sizer/Makefile.in b/tgt-sizer/Makefile.in index f11f994b5..d3361a24b 100644 --- a/tgt-sizer/Makefile.in +++ b/tgt-sizer/Makefile.in @@ -57,6 +57,8 @@ distclean: clean cppcheck: $(O:.o=.cc) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-sizer/sizer.cc b/tgt-sizer/sizer.cc index d533e7f01..4203d5be1 100644 --- a/tgt-sizer/sizer.cc +++ b/tgt-sizer/sizer.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2014-2025 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 @@ -56,7 +56,7 @@ FILE*sizer_out = 0; static int process_scan_fun(ivl_process_t net, void*raw); static void emit_sizer_scope(ivl_design_t des, ivl_scope_t model, struct sizer_statistics&stats); -static void show_stats(struct sizer_statistics&stats); +static void show_stats(const struct sizer_statistics&stats); /* * This is called by the ivl core to get version information from the @@ -149,7 +149,7 @@ static void emit_sizer_scope(ivl_design_t des, ivl_scope_t scope, struct sizer_s } } -static void show_stats(struct sizer_statistics&stats) +static void show_stats(const struct sizer_statistics&stats) { fprintf(sizer_out, " Flip-Flops : %u\n", stats.flop_count); fprintf(sizer_out, " Logic Gates : %u\n", stats.gate_count); diff --git a/tgt-stub/Makefile.in b/tgt-stub/Makefile.in index 632308dd4..9fc66f02d 100644 --- a/tgt-stub/Makefile.in +++ b/tgt-stub/Makefile.in @@ -58,6 +58,8 @@ distclean: clean cppcheck: $(O:.o=.c) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c index d8b49c8e6..eb7a59afe 100644 --- a/tgt-stub/stub.c +++ b/tgt-stub/stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2025 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 @@ -503,7 +503,7 @@ static void show_lpm_concat(ivl_lpm_t net) static void show_lpm_ff(ivl_lpm_t net) { ivl_nexus_t nex; - char*edge = ivl_lpm_negedge(net) ? "negedge" : "posedge"; + const char*edge = ivl_lpm_negedge(net) ? "negedge" : "posedge"; unsigned width = ivl_lpm_width(net); fprintf(out, " LPM_FF %s: \n", diff --git a/tgt-vhdl/Makefile.in b/tgt-vhdl/Makefile.in index 34196baf8..f6cc2acfd 100644 --- a/tgt-vhdl/Makefile.in +++ b/tgt-vhdl/Makefile.in @@ -61,6 +61,8 @@ distclean: clean cppcheck: $(O:.o=.cc) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-vhdl/cast.cc b/tgt-vhdl/cast.cc index 4d7abed94..effdd464a 100644 --- a/tgt-vhdl/cast.cc +++ b/tgt-vhdl/cast.cc @@ -1,7 +1,7 @@ /* * Generate code to convert between VHDL types. * - * Copyright (C) 2008-2021 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -90,8 +90,8 @@ vhdl_expr *vhdl_expr::to_vector(vhdl_type_name_t name, int w) // We have to cast the expression before resizing or the // wrong sign bit may be extended (i.e. when casting between // signed/unsigned *and* resizing) - vhdl_type *t = new vhdl_type(name, w - 1, 0); - vhdl_fcall *conv = new vhdl_fcall(t->get_string().c_str(), t); + const vhdl_type *t = new vhdl_type(name, w - 1, 0); + vhdl_fcall *conv = new vhdl_fcall(t->get_string(), t); conv->add_expr(this); if (w != type_->get_width()) @@ -229,7 +229,7 @@ vhdl_expr *vhdl_expr::to_std_ulogic() */ vhdl_expr *vhdl_expr::resize(int newwidth) { - vhdl_type *rtype; + const vhdl_type *rtype; assert(type_); if (type_->get_name() == VHDL_TYPE_SIGNED) rtype = vhdl_type::nsigned(newwidth); diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index 7b0bcacad..52c8ecb11 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -220,7 +220,7 @@ static vhdl_expr *translate_numeric(vhdl_expr *lhs, vhdl_expr *rhs, else if (rhs->get_type()->get_name() == VHDL_TYPE_BOOLEAN) lhs = lhs->cast(&boolean); - vhdl_type *rtype; + const vhdl_type *rtype; if (op == VHDL_BINOP_MULT) rtype = new vhdl_type(lhs->get_type()->get_name(), (lhs->get_type()->get_width()*2) - 1, 0); @@ -257,7 +257,7 @@ static vhdl_expr *translate_shift(vhdl_expr *lhs, vhdl_expr *rhs, vhdl_type integer(VHDL_TYPE_INTEGER); vhdl_expr *r_cast = rhs->cast(&integer); - vhdl_type *rtype = new vhdl_type(*lhs->get_type()); + const vhdl_type *rtype = new vhdl_type(*lhs->get_type()); // The sra operator is not defined on numeric_std types until // VHDL-2006 which is not well supported. Instead we can use @@ -297,7 +297,7 @@ static vhdl_expr *translate_power(ivl_expr_t e, vhdl_expr *lhs, vhdl_expr *rhs) int width = ivl_expr_width(e); const char *func = ivl_expr_signed(e) ? "To_Signed" : "To_Unsigned"; - vhdl_type *type = ivl_expr_signed(e) + const vhdl_type *type = ivl_expr_signed(e) ? vhdl_type::nsigned(width) : vhdl_type::nunsigned(width); vhdl_fcall *conv = new vhdl_fcall(func, type); @@ -554,7 +554,7 @@ static vhdl_expr *translate_ufunc(ivl_expr_t e) const char *funcname = ivl_scope_tname(defscope); - vhdl_type *rettype = + const vhdl_type *rettype = vhdl_type::type_for(ivl_expr_width(e), ivl_expr_signed(e) != 0); vhdl_fcall *fcall = new vhdl_fcall(funcname, rettype); @@ -615,7 +615,7 @@ static vhdl_expr *translate_ternary(ivl_expr_t e) static vhdl_expr *translate_concat(ivl_expr_t e) { - vhdl_type *rtype = + const vhdl_type *rtype = vhdl_type::type_for(ivl_expr_width(e), ivl_expr_signed(e) != 0); vhdl_binop_expr *concat = new vhdl_binop_expr(VHDL_BINOP_CONCAT, rtype); diff --git a/tgt-vhdl/logic.cc b/tgt-vhdl/logic.cc index 562481566..89f59c080 100644 --- a/tgt-vhdl/logic.cc +++ b/tgt-vhdl/logic.cc @@ -1,7 +1,7 @@ /* * VHDL code generation for logic devices. * - * Copyright (C) 2008-2021 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -118,7 +118,7 @@ static void comb_udp_logic(vhdl_arch *arch, ivl_net_logic_t log) ostringstream ss; ss << ivl_logic_basename(log) << "_Tmp"; int msb = ivl_udp_nin(udp) - 1; - vhdl_type *tmp_type = vhdl_type::std_logic_vector(msb, 0); + const vhdl_type *tmp_type = vhdl_type::std_logic_vector(msb, 0); vhdl_signal_decl *tmp_decl = new vhdl_signal_decl(ss.str(), tmp_type); arch->get_scope()->add_decl(tmp_decl); @@ -184,11 +184,11 @@ static void seq_udp_logic(vhdl_arch *arch, ivl_net_logic_t log) ostringstream ss; ss << "Generated from UDP " << ivl_udp_name(udp); - proc->set_comment(ss.str().c_str()); + proc->set_comment(ss.str()); // Create a variable to hold the concatenation of the inputs int msb = ivl_udp_nin(udp) - 1; - vhdl_type *tmp_type = vhdl_type::std_logic_vector(msb, 0); + const vhdl_type *tmp_type = vhdl_type::std_logic_vector(msb, 0); proc->get_scope()->add_decl(new vhdl_var_decl("UDP_Inputs", tmp_type)); // Concatenate the inputs into a single expression that can be diff --git a/tgt-vhdl/lpm.cc b/tgt-vhdl/lpm.cc index 7153ec06b..3e7a3c061 100644 --- a/tgt-vhdl/lpm.cc +++ b/tgt-vhdl/lpm.cc @@ -1,7 +1,7 @@ /* * VHDL code generation for LPM devices. * - * Copyright (C) 2008-2009 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -44,7 +44,7 @@ static vhdl_expr *part_select_base(vhdl_scope *scope, ivl_lpm_t lpm) static vhdl_expr *binop_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_binop_t op) { unsigned out_width = ivl_lpm_width(lpm); - vhdl_type *result_type = + const vhdl_type *result_type = vhdl_type::type_for(out_width, ivl_lpm_signed(lpm) != 0); vhdl_binop_expr *expr = new vhdl_binop_expr(op, result_type); @@ -219,7 +219,7 @@ static vhdl_expr *shift_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_type integer(VHDL_TYPE_INTEGER); vhdl_expr *r_cast = rhs->cast(&integer); - vhdl_type *rtype = new vhdl_type(*lhs->get_type()); + const vhdl_type *rtype = new vhdl_type(*lhs->get_type()); return new vhdl_binop_expr(lhs, shift_op, r_cast, rtype); } diff --git a/tgt-vhdl/scope.cc b/tgt-vhdl/scope.cc index c14606ad3..b207f277d 100644 --- a/tgt-vhdl/scope.cc +++ b/tgt-vhdl/scope.cc @@ -1,7 +1,7 @@ /* * VHDL code generation for scopes. * - * Copyright (C) 2008-2021 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -60,7 +60,7 @@ struct nexus_private_t { /* * Returns the scope_nexus_t of this nexus visible within scope. */ -static scope_nexus_t *visible_nexus(nexus_private_t *priv, vhdl_scope *scope) +static scope_nexus_t *visible_nexus(nexus_private_t *priv, const vhdl_scope *scope) { list::iterator it; for (it = priv->signals.begin(); it != priv->signals.end(); ++it) { @@ -109,7 +109,7 @@ static void link_scope_to_nexus_tmp(nexus_private_t *priv, vhdl_scope *scope, /* * Finds the name of the nexus signal within this scope. */ -static string visible_nexus_signal_name(nexus_private_t *priv, vhdl_scope *scope, +static string visible_nexus_signal_name(nexus_private_t *priv, const vhdl_scope *scope, unsigned *pin) { scope_nexus_t *sn = visible_nexus(priv, scope); @@ -201,7 +201,7 @@ void draw_nexus(ivl_nexus_t nexus) } else { // Create a temporary signal to connect it to the nexus - vhdl_type *type = + const vhdl_type *type = vhdl_type::type_for(ivl_logic_width(log), false); ostringstream ss; @@ -238,8 +238,8 @@ void draw_nexus(ivl_nexus_t nexus) else lpm_temp_width = ivl_lpm_width(lpm); - vhdl_type *type = vhdl_type::type_for(lpm_temp_width, - ivl_lpm_signed(lpm) != 0); + const vhdl_type *type = vhdl_type::type_for(lpm_temp_width, + ivl_lpm_signed(lpm) != 0); ostringstream ss; ss << "LPM"; if (nexus == ivl_lpm_q(lpm)) @@ -352,8 +352,8 @@ vhdl_var_ref *nexus_to_var_ref(vhdl_scope *scope, ivl_nexus_t nexus) vhdl_decl *decl = scope->get_decl(renamed); assert(decl); - vhdl_type *type = new vhdl_type(*(decl->get_type())); - vhdl_var_ref *ref = new vhdl_var_ref(renamed.c_str(), type); + const vhdl_type *type = new vhdl_type(*(decl->get_type())); + vhdl_var_ref *ref = new vhdl_var_ref(renamed, type); if (decl->get_type()->get_name() == VHDL_TYPE_ARRAY) ref->set_slice(new vhdl_const_int(pin), 0); @@ -478,7 +478,7 @@ string make_safe_name(ivl_signal_t sig) // Check if `name' differs from an existing name only in case and // make it unique if it does. -static void avoid_name_collision(string& name, vhdl_scope* scope) +static void avoid_name_collision(string& name, const vhdl_scope* scope) { if (scope->name_collides(name)) { name += "_"; @@ -542,7 +542,7 @@ static void declare_one_signal(vhdl_entity *ent, ivl_signal_t sig, rename_signal(sig, name); - vhdl_type *sig_type; + const vhdl_type *sig_type; unsigned dimensions = ivl_signal_dimensions(sig); if (dimensions > 0) { // Arrays are implemented by generating a separate type @@ -561,7 +561,7 @@ static void declare_one_signal(vhdl_entity *ent, ivl_signal_t sig, int lsb = ivl_signal_array_base(sig); int msb = lsb + ivl_signal_array_count(sig) - 1; - vhdl_type *array_type = + const vhdl_type *array_type = vhdl_type::array_of(base_type, type_name, msb, lsb); vhdl_decl *array_decl = new vhdl_type_decl(type_name, array_type); ent->get_arch()->get_scope()->add_decl(array_decl); @@ -590,7 +590,7 @@ static void declare_one_signal(vhdl_entity *ent, ivl_signal_t sig, ss << "Declared at " << ivl_signal_file(sig) << ":" << ivl_signal_lineno(sig); } - decl->set_comment(ss.str().c_str()); + decl->set_comment(ss.str()); ent->get_arch()->get_scope()->add_decl(decl); } @@ -616,7 +616,7 @@ static void declare_one_signal(vhdl_entity *ent, ivl_signal_t sig, newname += "_Reg"; rename_signal(sig, newname); - vhdl_type *reg_type = new vhdl_type(*sig_type); + const vhdl_type *reg_type = new vhdl_type(*sig_type); ent->get_arch()->get_scope()->add_decl (new vhdl_signal_decl(newname, reg_type)); @@ -624,8 +624,8 @@ static void declare_one_signal(vhdl_entity *ent, ivl_signal_t sig, // connect the register to the output ent->get_arch()->add_stmt (new vhdl_cassign_stmt - (new vhdl_var_ref(name.c_str(), NULL), - new vhdl_var_ref(newname.c_str(), NULL))); + (new vhdl_var_ref(name, NULL), + new vhdl_var_ref(newname, NULL))); } break; case IVL_SIP_INOUT: @@ -678,7 +678,7 @@ static void declare_lpm(vhdl_arch *arch, ivl_scope_t scope) * Map two signals together in an instantiation. * The signals are joined by a nexus. */ -static void map_signal(ivl_signal_t to, vhdl_entity *parent, +static void map_signal(ivl_signal_t to, const vhdl_entity *parent, vhdl_comp_inst *inst) { // TODO: Work for multiple words @@ -704,7 +704,7 @@ static void map_signal(ivl_signal_t to, vhdl_entity *parent, // However, Verilog allows the signal to be read in the parent. // The solution used here is to create an intermediate signal // and connect it to both ports. - vhdl_decl* from_decl = + const vhdl_decl* from_decl = parent->get_arch()->get_scope()->get_decl(ref->get_name()); if (!from_decl->is_readable() && !arch_scope->have_declared(name + "_Readable")) { @@ -738,7 +738,7 @@ static void map_signal(ivl_signal_t to, vhdl_entity *parent, /* * Find all the port mappings of a module instantiation. */ -static void port_map(ivl_scope_t scope, vhdl_entity *parent, +static void port_map(ivl_scope_t scope, const vhdl_entity *parent, vhdl_comp_inst *inst) { // Find all the port mappings @@ -796,7 +796,7 @@ static int draw_function(ivl_scope_t scope, ivl_scope_t parent) for (int i = 0; i < nports; i++) { ivl_signal_t sig = ivl_scope_port(scope, i); - vhdl_type *sigtype = + const vhdl_type *sigtype = vhdl_type::type_for(ivl_signal_width(sig), ivl_signal_signed(sig) != 0); @@ -828,7 +828,7 @@ static int draw_function(ivl_scope_t scope, ivl_scope_t parent) ivl_signal_t sig = ivl_scope_sig(scope, i); if (ivl_signal_port(sig) == IVL_SIP_NONE) { - vhdl_type *sigtype = + const vhdl_type *sigtype = vhdl_type::type_for( ivl_signal_width(sig), ivl_signal_signed(sig) != 0); @@ -859,7 +859,7 @@ static int draw_function(ivl_scope_t scope, ivl_scope_t parent) ostringstream ss; ss << "Generated from function " << funcname << " at " << ivl_scope_def_file(scope) << ":" << ivl_scope_def_lineno(scope); - func->set_comment(ss.str().c_str()); + func->set_comment(ss.str()); ent->get_arch()->get_scope()->add_decl(func); return 0; @@ -882,7 +882,7 @@ static int draw_task(ivl_scope_t scope, ivl_scope_t parent) int nsigs = ivl_scope_sigs(scope); for (int i = 0; i < nsigs; i++) { ivl_signal_t sig = ivl_scope_sig(scope, i); - vhdl_type *sigtype = + const vhdl_type *sigtype = vhdl_type::type_for(ivl_signal_width(sig), ivl_signal_signed(sig) != 0); @@ -899,7 +899,7 @@ static int draw_task(ivl_scope_t scope, ivl_scope_t parent) ostringstream ss; ss << "Declared at " << ivl_signal_file(sig) << ":" << ivl_signal_lineno(sig) << " (in task " << taskname << ")"; - decl->set_comment(ss.str().c_str()); + decl->set_comment(ss.str()); ent->get_arch()->get_scope()->add_decl(decl); @@ -1110,10 +1110,10 @@ extern "C" int draw_constant_drivers(ivl_scope_t scope, void *) for (list::const_iterator it = sn->connect.begin(); it != sn->connect.end(); ++it) { - vhdl_type* rtype = + const vhdl_type* rtype = vhdl_type::type_for(ivl_signal_width(sn->sig), ivl_signal_signed(sn->sig)); - vhdl_type* ltype = + const vhdl_type* ltype = vhdl_type::type_for(ivl_signal_width(*it), ivl_signal_signed(*it)); @@ -1179,7 +1179,7 @@ extern "C" int draw_hierarchy(ivl_scope_t scope, void *_parent) assert(parent_arch != NULL); // Create a forward declaration for it - vhdl_scope *parent_scope = parent_arch->get_scope(); + const vhdl_scope *parent_scope = parent_arch->get_scope(); if (!parent_scope->have_declared(ent->get_name())) { vhdl_decl *comp_decl = vhdl_component_decl::component_decl_for(ent); parent_arch->get_scope()->add_decl(comp_decl); @@ -1227,7 +1227,7 @@ extern "C" int draw_hierarchy(ivl_scope_t scope, void *_parent) ostringstream ss; ss << "Generated from instantiation at " << ivl_scope_file(scope) << ":" << ivl_scope_lineno(scope); - inst->set_comment(ss.str().c_str()); + inst->set_comment(ss.str()); parent_arch->add_stmt(inst); } diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index b54fd34dd..08496f932 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -1,7 +1,7 @@ /* * VHDL code generation for statements. * - * Copyright (C) 2008-2023 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -212,8 +212,8 @@ static int draw_block(vhdl_procedural *proc, stmt_container *container, ivl_signal_t sig = ivl_scope_sig(block_scope, i); remember_signal(sig, proc->get_scope()); - vhdl_type* type = vhdl_type::type_for(ivl_signal_width(sig), - ivl_signal_signed(sig)); + const vhdl_type* type = vhdl_type::type_for(ivl_signal_width(sig), + ivl_signal_signed(sig)); proc->get_scope()->add_decl (new vhdl_var_decl(make_safe_name(sig), type)); } @@ -284,7 +284,7 @@ static vhdl_var_ref *make_assign_lhs(ivl_lval_t lval, vhdl_scope *scope) decl = shadow_decl; } - vhdl_type *ltype = new vhdl_type(*decl->get_type()); + const vhdl_type *ltype = new vhdl_type(*decl->get_type()); vhdl_var_ref *lval_ref = new vhdl_var_ref(decl->get_name(), ltype); if (base) { if (decl->get_type()->get_name() == VHDL_TYPE_ARRAY) @@ -384,7 +384,7 @@ static void emit_wait_for_0(vhdl_procedural *proc, need_wait_for_0 = true; } - stmt_container::stmt_list_t &stmts = container->get_stmts(); + const stmt_container::stmt_list_t &stmts = container->get_stmts(); bool last_was_wait = !stmts.empty() && dynamic_cast(stmts.back()); @@ -577,7 +577,7 @@ void make_assignment(vhdl_procedural *proc, stmt_container *container, // Find the declaration of the LHS so we know what type // of assignment statement to generate (is it a signal, // a variable, etc?) - vhdl_decl *decl = proc->get_scope()->get_decl((*it)->get_name()); + const vhdl_decl *decl = proc->get_scope()->get_decl((*it)->get_name()); assign_type = decl->assignment_type(); if (!check_valid_assignment(decl->assignment_type(), proc, stmt)) @@ -1060,7 +1060,7 @@ static vhdl_var_ref *draw_case_test(vhdl_procedural *proc, stmt_container *conta // variable to hold the result of the expression evaluation if (typeid(*test) != typeid(vhdl_var_ref)) { const char *tmp_name = "Verilog_Case_Ex"; - vhdl_type *test_type = new vhdl_type(*test->get_type()); + const vhdl_type *test_type = new vhdl_type(*test->get_type()); if (!proc->get_scope()->have_declared(tmp_name)) { proc->get_scope()->add_decl @@ -1199,7 +1199,7 @@ static long get_number_as_long(ivl_expr_t expr) * Build a check against a constant 'x'. This is for an out of range * or undefined select. */ -static void check_against_x(vhdl_binop_expr *all, vhdl_var_ref *test, +static void check_against_x(vhdl_binop_expr *all, const vhdl_var_ref *test, ivl_expr_t expr, unsigned width, unsigned base, bool is_casez) { @@ -1208,7 +1208,7 @@ static void check_against_x(vhdl_binop_expr *all, vhdl_var_ref *test, for (unsigned i = 0; i < ivl_expr_width(expr); i++) { vhdl_binop_expr *sub_expr = new vhdl_binop_expr(VHDL_BINOP_OR, vhdl_type::boolean()); - vhdl_type *type; + const vhdl_type *type; vhdl_var_ref *ref; // Check if the test bit is 'z'. @@ -1241,7 +1241,7 @@ static void check_against_x(vhdl_binop_expr *all, vhdl_var_ref *test, /* * Build the test signal to constant bits check. */ -static void process_number(vhdl_binop_expr *all, vhdl_var_ref *test, +static void process_number(vhdl_binop_expr *all, const vhdl_var_ref *test, ivl_expr_t expr, unsigned width, unsigned base, bool is_casez) { @@ -1260,7 +1260,7 @@ static void process_number(vhdl_binop_expr *all, vhdl_var_ref *test, vhdl_binop_expr *sub_expr = new vhdl_binop_expr(VHDL_BINOP_OR, vhdl_type::boolean()); - vhdl_type *type; + const vhdl_type *type; vhdl_var_ref *ref; // Check if the test bit is 'z'. @@ -1306,7 +1306,7 @@ static void process_number(vhdl_binop_expr *all, vhdl_var_ref *test, /* * Build the test signal to label signal check. */ -static bool process_signal(vhdl_binop_expr *all, vhdl_var_ref *test, +static bool process_signal(vhdl_binop_expr *all, const vhdl_var_ref *test, ivl_expr_t expr, unsigned width, unsigned base, bool is_casez, unsigned swid, long sbase) { @@ -1331,7 +1331,7 @@ static bool process_signal(vhdl_binop_expr *all, vhdl_var_ref *test, for (unsigned i = 0; i < swid; i++) { // Generate a comparison for this bit position vhdl_binop_expr *cmp; - vhdl_type *type; + const vhdl_type *type; vhdl_var_ref *ref; // Check if this is an out of bounds access. If this is a casez diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index bfab67402..68ebcae5f 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -1,7 +1,7 @@ /* * VHDL abstract syntax elements. * - * Copyright (C) 2008-2013 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -203,12 +203,12 @@ void vhdl_arch::emit(std::ostream &of, int level) const blank_line(of, level); // Extra blank line after architectures; } -void vhdl_procedural::add_blocking_target(vhdl_var_ref* ref) +void vhdl_procedural::add_blocking_target(const vhdl_var_ref* ref) { blocking_targets_.insert(ref->get_name()); } -bool vhdl_procedural::is_blocking_target(vhdl_var_ref* ref) const +bool vhdl_procedural::is_blocking_target(const vhdl_var_ref* ref) const { return blocking_targets_.find(ref->get_name()) != blocking_targets_.end(); } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 6298f66f2..c66fb22d4 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -1,7 +1,7 @@ /* * VHDL abstract syntax elements. * - * Copyright (C) 2008-2021 Nick Gasson (nick@nickg.me.uk) + * Copyright (C) 2008-2025 Nick Gasson (nick@nickg.me.uk) * * 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 @@ -141,7 +141,7 @@ enum vhdl_unaryop_t { class vhdl_unaryop_expr : public vhdl_expr { public: vhdl_unaryop_expr(vhdl_unaryop_t op, vhdl_expr *operand, - vhdl_type *type) + const vhdl_type *type) : vhdl_expr(type), op_(op), operand_(operand) {} ~vhdl_unaryop_expr(); @@ -158,7 +158,7 @@ private: */ class vhdl_bit_spec_expr : public vhdl_expr { public: - vhdl_bit_spec_expr(vhdl_type *type, vhdl_expr *others) + vhdl_bit_spec_expr(const vhdl_type *type, vhdl_expr *others) : vhdl_expr(type), others_(others) {} ~vhdl_bit_spec_expr(); @@ -608,7 +608,7 @@ public: const std::string &get_name() const { return name_; } const vhdl_type *get_type() const; - void set_type(vhdl_type *t) { type_ = t; } + void set_type(const vhdl_type *t) { type_ = t; } void set_initial(vhdl_expr *initial); bool has_initial() const { return has_initial_; } @@ -699,7 +699,7 @@ public: */ class vhdl_param_decl : public vhdl_decl { public: - vhdl_param_decl(const char *name, vhdl_type *type) + vhdl_param_decl(const char *name, const vhdl_type *type) : vhdl_decl(name, type) {} void emit(std::ostream &of, int level) const; assign_type_t assignment_type() const { return ASSIGN_CONST; } @@ -719,7 +719,7 @@ enum vhdl_port_mode_t { */ class vhdl_port_decl : public vhdl_decl { public: - vhdl_port_decl(const char *name, vhdl_type *type, + vhdl_port_decl(const char *name, const vhdl_type *type, vhdl_port_mode_t mode) : vhdl_decl(name, type), mode_(mode) {} @@ -817,8 +817,8 @@ public: bool contains_wait_stmt() const { return contains_wait_stmt_; } // Managing set of blocking assignment targets in this block - void add_blocking_target(vhdl_var_ref* ref); - bool is_blocking_target(vhdl_var_ref* ref) const; + void add_blocking_target(const vhdl_var_ref* ref); + bool is_blocking_target(const vhdl_var_ref* ref) const; protected: stmt_container stmts_; diff --git a/tgt-vlog95/Makefile.in b/tgt-vlog95/Makefile.in index 678c23d40..a2073ca67 100644 --- a/tgt-vlog95/Makefile.in +++ b/tgt-vlog95/Makefile.in @@ -1,5 +1,5 @@ # -# Copyright (C) 2011-2012 Cary R. (cygcary@yahoo.com) +# Copyright (C) 2011-2025 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 @@ -57,6 +57,8 @@ distclean: clean cppcheck: $(O:.o=.c) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-vlog95/misc.c b/tgt-vlog95/misc.c index 248dfeb3b..591dc363b 100644 --- a/tgt-vlog95/misc.c +++ b/tgt-vlog95/misc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 Cary R. (cygcary@yahoo.com) + * Copyright (C) 2011-2025 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 @@ -844,7 +844,7 @@ void emit_scope_call_path(ivl_scope_t scope, ivl_scope_t call_scope) if (mod_scope != call_mod_scope) { emit_scope_piece(mod_scope, call_mod_scope); - } else if (scope != call_scope) { + } else { ivl_scope_t parent; /* We only emit a scope path if the scope is a parent of the * call scope. */ diff --git a/tgt-vvp/Makefile.in b/tgt-vvp/Makefile.in index bf458f272..793821219 100644 --- a/tgt-vvp/Makefile.in +++ b/tgt-vvp/Makefile.in @@ -65,6 +65,8 @@ distclean: clean cppcheck: $(O:.o=.c) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^ diff --git a/tgt-vvp/draw_delay.c b/tgt-vvp/draw_delay.c index 1fcc92a21..62e9ae9bc 100644 --- a/tgt-vvp/draw_delay.c +++ b/tgt-vvp/draw_delay.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Stephen Williams (steve@icarus.com) + * Copyright (c) 2016-2025 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 @@ -26,7 +26,7 @@ /* * This function draws a BUFT to drive a constant delay value. */ -static char* draw_const_net(void*ptr, char*suffix, uint64_t value) +static char* draw_const_net(const void*ptr, const char*suffix, uint64_t value) { char tmp[64]; char c4_value[69]; @@ -52,7 +52,7 @@ static char* draw_const_net(void*ptr, char*suffix, uint64_t value) /* * Draw the appropriate delay statement. */ -void draw_delay(void*ptr, unsigned wid, const char*input, ivl_expr_t rise_exp, +void draw_delay(const void*ptr, unsigned wid, const char*input, ivl_expr_t rise_exp, ivl_expr_t fall_exp, ivl_expr_t decay_exp) { char tmp[64]; diff --git a/tgt-vvp/draw_net_input.c b/tgt-vvp/draw_net_input.c index 6e4859f89..d50eaaf38 100644 --- a/tgt-vvp/draw_net_input.c +++ b/tgt-vvp/draw_net_input.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2025 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 @@ -334,7 +334,7 @@ static char* draw_net_input_drive(const ivl_nexus_t nex, ivl_nexus_ptr_t nptr) char *result = 0; ivl_expr_t d_rise, d_fall, d_decay; unsigned dly_width = 0; - char *dly; + const char *dly; /* Constants should have exactly 1 pin, with a literal value. */ assert(nptr_pin == 0); diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 4103bc735..2ff855ac4 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2025 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 @@ -196,7 +196,7 @@ uint64_t get_number_immediate64(ivl_expr_t expr) return imm; } -void eval_logic_into_integer(ivl_expr_t expr, unsigned ix) +static void eval_logic_into_integer(ivl_expr_t expr, unsigned ix) { switch (ivl_expr_type(expr)) { diff --git a/tgt-vvp/eval_object.c b/tgt-vvp/eval_object.c index a825d6045..055ef38ae 100644 --- a/tgt-vvp/eval_object.c +++ b/tgt-vvp/eval_object.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2012-2025 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 @@ -24,7 +24,7 @@ void darray_new(ivl_type_t element_type, unsigned size_reg) { int wid; - char*signed_char; + const char*signed_char; ivl_variable_type_t type = ivl_type_base(element_type); if ((type == IVL_VT_BOOL) || (type == IVL_VT_LOGIC)) { diff --git a/tgt-vvp/vvp_priv.h b/tgt-vvp/vvp_priv.h index 1f46b8801..70133a007 100644 --- a/tgt-vvp/vvp_priv.h +++ b/tgt-vvp/vvp_priv.h @@ -239,7 +239,7 @@ extern void draw_immediate_vec4(ivl_expr_t expr, const char*opcode); /* * Draw a delay statement. */ -extern void draw_delay(void*ptr, unsigned wid, const char*input, +extern void draw_delay(const void*ptr, unsigned wid, const char*input, ivl_expr_t rise_exp, ivl_expr_t fall_exp, ivl_expr_t decay_exp); diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index 3173b7b0a..467ae6d8a 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -46,7 +46,7 @@ const char *vvp_mangle_id(const char *id) const char nosym[] = "!\"#%&'()*+,-/:;<=>?@[\\]^`{|}~"; - char *se = strpbrk(inp, nosym); + const char *se = strpbrk(inp, nosym); if (!se) return id; @@ -95,7 +95,7 @@ const char *vvp_mangle_name(const char *id) const char nosym[] = "\"\\"; - char *se = strpbrk(inp, nosym); + const char *se = strpbrk(inp, nosym); if (!se) return id; @@ -1792,7 +1792,7 @@ static void draw_lpm_ff(ivl_lpm_t net) assert(ivl_lpm_sync_set(net) == 0); unsigned width = ivl_lpm_width(net); - char*edge = ivl_lpm_negedge(net) ? "n" : "p"; + const char*edge = ivl_lpm_negedge(net) ? "n" : "p"; nex = ivl_lpm_clk(net); assert(nex); diff --git a/vhdlpp/Makefile.in b/vhdlpp/Makefile.in index ab645c6ff..2fdaf18c8 100644 --- a/vhdlpp/Makefile.in +++ b/vhdlpp/Makefile.in @@ -86,6 +86,8 @@ distclean: clean cppcheck: $(O:.o=.cc) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ -UYY_USER_INIT \ -UYYPARSE_PARAM -UYYPRINT -Ushort -Usize_t -Uyyoverflow \ -UYYTYPE_INT8 -UYYTYPE_INT16 -UYYTYPE_UINT8 -UYYTYPE_UINT16 \ diff --git a/vhdlpp/entity_elaborate.cc b/vhdlpp/entity_elaborate.cc index 4d74d0039..c661be11d 100644 --- a/vhdlpp/entity_elaborate.cc +++ b/vhdlpp/entity_elaborate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -104,7 +104,7 @@ int Entity::elaborate_ports_(void) for (std::vector::const_iterator cur = ports_.begin() ; cur != ports_.end() ; ++cur) { - InterfacePort*cur_port = *cur; + const InterfacePort*cur_port = *cur; const VType*type = cur_port->type; if (type == 0) { diff --git a/vhdlpp/entity_emit.cc b/vhdlpp/entity_emit.cc index 968339bd3..067a0e48c 100644 --- a/vhdlpp/entity_emit.cc +++ b/vhdlpp/entity_emit.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 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 @@ -72,7 +72,7 @@ int Entity::emit(ostream&out) ; cur != ports_.end() ; ++cur) { InterfacePort*port = *cur; - VType::decl_t&decl = declarations_[port->name]; + const VType::decl_t&decl = declarations_[port->name]; if (sep) out << sep << endl; else sep = ", "; diff --git a/vhdlpp/expression.cc b/vhdlpp/expression.cc index b9dff1b91..712cf7350 100644 --- a/vhdlpp/expression.cc +++ b/vhdlpp/expression.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2012-2015 / Stephen Williams (steve@icarus.com), * Copyright CERN 2016 * @author Maciej Suminski (maciej.suminski@cern.ch) @@ -276,7 +276,7 @@ ExpAggregate::choice_t::choice_t(ExpRange*rang) ExpAggregate::choice_t::choice_t(const choice_t&other) { - if(Expression*e = other.expr_.get()) + if(const Expression*e = other.expr_.get()) expr_.reset(e->clone()); if(other.range_.get()) diff --git a/vhdlpp/expression.h b/vhdlpp/expression.h index 9b084645e..8c0a7e531 100644 --- a/vhdlpp/expression.h +++ b/vhdlpp/expression.h @@ -1,7 +1,7 @@ #ifndef IVL_expression_H #define IVL_expression_H /* - * Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2015 / Stephen Williams (steve@icarus.com), * Copyright CERN 2016 * @author Maciej Suminski (maciej.suminski@cern.ch) @@ -724,7 +724,7 @@ class ExpName : public Expression { public: // Base methods Expression*clone() const; int elaborate_lval(Entity*ent, ScopeBase*scope, bool); - int elaborate_rval(Entity*ent, ScopeBase*scope, const InterfacePort*); + int elaborate_rval(const Entity*ent, const ScopeBase*scope, const InterfacePort*); const VType* probe_type(Entity*ent, ScopeBase*scope) const; const VType* fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*host) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); @@ -841,7 +841,7 @@ class ExpScopedName : public Expression { int elaborate_lval(Entity*ent, ScopeBase*scope, bool is_sequ) { return name_->elaborate_lval(ent, get_scope(scope), is_sequ); } - int elaborate_rval(Entity*ent, ScopeBase*scope, const InterfacePort*lval) + int elaborate_rval(const Entity*ent, const ScopeBase*scope, const InterfacePort*lval) { return name_->elaborate_rval(ent, get_scope(scope), lval); } const VType* probe_type(Entity*ent, ScopeBase*scope) const diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index 97405ca0b..02a4e5ac1 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) * Copyright CERN 2016 * @author Maciej Suminski (maciej.suminski@cern.ch) @@ -275,7 +275,7 @@ int ExpName::elaborate_lval(Entity*ent, ScopeBase*scope, bool is_sequ) return errors; } -int ExpName::elaborate_rval(Entity*ent, ScopeBase*scope, const InterfacePort*lval) +int ExpName::elaborate_rval(const Entity*ent, const ScopeBase*scope, const InterfacePort*lval) { int errors = 0; @@ -466,7 +466,7 @@ int ExpAggregate::elaborate_expr_array_(Entity*ent, ScopeBase*scope, const VType // each parsed element may be bound to multiple choices, so // account for that. for (size_t edx = 0 ; edx < elements_.size() ; edx += 1) { - element_t*ecur = elements_[edx]; + const element_t*ecur = elements_[edx]; if (ecur->count_choices() == 0) choice_count += 1; else @@ -867,7 +867,7 @@ int ExpFunc::elaborate_expr(Entity*ent, ScopeBase*scope, const VType*) // SystemVerilog functions work only with defined size data types, therefore // if header does not specify argument or return type size, create a function // instance that work with this particular size. - if(def_ && !def_->is_std() && def_->unbounded()) { + if(!def_->is_std() && def_->unbounded()) { def_ = def_->make_instance(argv_, scope); name_ = def_->name(); // TODO necessary? } @@ -1013,10 +1013,10 @@ const VType* ExpName::probe_type(Entity*ent, ScopeBase*scope) const } if(scope) { - if (Signal*sig = scope->find_signal(name_)) + if (const Signal*sig = scope->find_signal(name_)) return sig->peek_type(); - if (Variable*var = scope->find_variable(name_)) + if (const Variable*var = scope->find_variable(name_)) return var->peek_type(); const VType*type = 0; diff --git a/vhdlpp/expression_emit.cc b/vhdlpp/expression_emit.cc index a3d6e77e0..39c9e0c10 100644 --- a/vhdlpp/expression_emit.cc +++ b/vhdlpp/expression_emit.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2012-2015 / Stephen Williams (steve@icarus.com) * @author Maciej Suminski (maciej.suminski@cern.ch) * @@ -828,7 +828,7 @@ bool ExpName::check_const_record_workaround_(const VTypeRecord*rec, for(vector::const_reverse_iterator it = elements.rbegin(); it != elements.rend(); ++it) { - VTypeRecord::element_t* el = (*it); + const VTypeRecord::element_t* el = (*it); if(el->peek_name() == name_) { const VType*type = el->peek_type(); diff --git a/vhdlpp/lexor.lex b/vhdlpp/lexor.lex index fdafcb058..f952e24ac 100644 --- a/vhdlpp/lexor.lex +++ b/vhdlpp/lexor.lex @@ -6,7 +6,7 @@ %{ /* - * Copyright (c) 2011-2017 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 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 @@ -53,10 +53,10 @@ extern int lexor_keyword_code (const char*str, unsigned len); #define yylloc (*yyllocp) #define yylval (*yylvalp) -static bool are_underscores_correct(char* text); -static bool is_based_correct(char* text); -static char* escape_quot_and_dup(char* text); -static char* escape_apostrophe_and_dup(char* text); +static bool are_underscores_correct(const char* text); +static bool is_based_correct(const char* text); +static char* escape_quot_and_dup(const char* text); +static char* escape_apostrophe_and_dup(const char* text); static double make_double_from_based(char* text); static int64_t make_long_from_based(char* text); @@ -220,7 +220,7 @@ extern void yyparse_set_filepath(const char*path); * \return true is returned if underscores are placed * correctly according to specification */ -static bool are_underscores_correct(char* text) +static bool are_underscores_correct(const char* text) { unsigned char underscore_allowed = 0; const char* cp; @@ -253,12 +253,12 @@ static bool is_char_ok(char c, int base) * \return true is returned if a based number * is formed well according to specification */ -static bool is_based_correct(char* text) +static bool is_based_correct(const char* text) { - char* ptr; + const char* ptr; //BASE examination char clean_base[4] = {0,}; - char* clean_base_end = clean_base + sizeof(clean_base); + const char* clean_base_end = clean_base + sizeof(clean_base); char* clean_base_ptr = clean_base; for(ptr = text; ptr != strchr(text, '#'); ++ptr) { @@ -336,7 +336,7 @@ static bool is_based_correct(char* text) * * \return pointer to the new string is returned */ -static char* escape_quot_and_dup(char* text) +static char* escape_quot_and_dup(const char* text) { char* newstr = new char[strlen(text)+1]; @@ -377,7 +377,7 @@ static char* escape_quot_and_dup(char* text) * * \return pointer to the new string is returned */ -static char* escape_apostrophe_and_dup(char* text) +static char* escape_apostrophe_and_dup(const char* text) { char* newstr = new char[2]; newstr[0] = text[1]; @@ -629,7 +629,7 @@ static double make_double_from_based(char* text) { char* first_hash_ptr = strchr(text, '#'); char* second_hash_ptr = strrchr(text, '#'); - char* last_char_ptr = strchr(text, '\0') - 1; + const char* last_char_ptr = strchr(text, '\0') - 1; //put null byte in lieu of hashes *first_hash_ptr = '\0'; *second_hash_ptr = '\0'; @@ -638,7 +638,7 @@ static double make_double_from_based(char* text) unsigned base = (unsigned)strtol(text, 0, 10) ; double mantissa = 0.0; - char*ptr = first_hash_ptr + 1; + const char*ptr = first_hash_ptr + 1; for( ; ptr != second_hash_ptr ; ++ptr) { if(*ptr == '.') @@ -699,12 +699,12 @@ static unsigned short short_from_hex_char(char ch) static int64_t make_long_from_based(char* text) { char* first_hash_ptr = strchr(text, '#'); char* second_hash_ptr = strrchr(text, '#'); - char* end_ptr = strrchr(text, '\0'); + const char* end_ptr = strrchr(text, '\0'); //now lets deduce the base *first_hash_ptr = '\0'; unsigned base = (unsigned)strtol(text, 0, 10) ; - char *ptr = first_hash_ptr + 1; + const char *ptr = first_hash_ptr + 1; int64_t mantissa = 0; for( ; ptr != second_hash_ptr ; ++ptr) { diff --git a/vhdlpp/library.cc b/vhdlpp/library.cc index 1203b987c..968c95b3d 100644 --- a/vhdlpp/library.cc +++ b/vhdlpp/library.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * Copyright CERN 2016 * @author Maciej Suminski @@ -114,7 +114,7 @@ static void import_ieee(void); static void import_ieee_use(const YYLTYPE&loc, ActiveScope*res, perm_string package, perm_string name); static void import_std_use(const YYLTYPE&loc, ActiveScope*res, perm_string package, perm_string name); -static void dump_library_package(ostream&file, perm_string lname, perm_string pname, Package*pack) +static void dump_library_package(ostream&file, perm_string lname, perm_string pname, const Package*pack) { file << "package " << lname << "." << pname << endl; if (pack) { diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 231826023..7a246d47e 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -6,7 +6,7 @@ %parse-param {perm_string parse_library_name} %{ /* - * Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2012-2016 / Stephen Williams (steve@icarus.com), * @author Maciej Suminski (maciej.suminski@cern.ch) * @@ -68,7 +68,7 @@ inline void FILE_NAME(LineInfo*tmp, const struct yyltype&where) (Current).first_line = (Rhs)[1].first_line; \ (Current).text = file_path; /*(Rhs)[1].text;*/ } while (0) -static void yyerror(YYLTYPE*yyllocp,yyscan_t yyscanner,const char*file_path,bool, const char*msg); +static void yyerror(const YYLTYPE*yyllocp,yyscan_t yyscanner,const char*file_path,bool, const char*msg); int parse_errors = 0; int parse_sorrys = 0; @@ -758,7 +758,7 @@ component_specification composite_type_definition /* constrained_array_definition */ : K_array index_constraint K_of subtype_indication - { VTypeArray*tmp = new VTypeArray($4, $2); + { const VTypeArray*tmp = new VTypeArray($4, $2); delete $2; $$ = tmp; } @@ -770,7 +770,7 @@ composite_type_definition ExpRange*tmp = new ExpRange(NULL, NULL, ExpRange::DOWNTO); r.push_back(tmp); FILE_NAME(tmp, @1); - VTypeArray*arr = new VTypeArray($6, &r); + const VTypeArray*arr = new VTypeArray($6, &r); $$ = arr; } @@ -2218,7 +2218,7 @@ range_list record_type_definition : K_record element_declaration_list K_end K_record - { VTypeRecord*tmp = new VTypeRecord($2); + { const VTypeRecord*tmp = new VTypeRecord($2); $$ = tmp; } ; @@ -2787,7 +2787,7 @@ type_declaration type_definition : '(' enumeration_literal_list ')' - { VTypeEnum*tmp = new VTypeEnum($2); + { const VTypeEnum*tmp = new VTypeEnum($2); active_scope->use_enum(tmp); delete $2; $$ = tmp; @@ -2935,7 +2935,7 @@ K_postponed_opt : K_postponed | ; K_shared_opt : K_shared | ; %% -static void yyerror(YYLTYPE*loc, yyscan_t, const char*, bool, const char*msg) +static void yyerror(const YYLTYPE*loc, yyscan_t, const char*, bool, const char*msg) { fprintf(stderr, "%s:%u: %s\n", loc->text, loc->first_line, msg); parse_errors += 1; diff --git a/vhdlpp/parse_misc.cc b/vhdlpp/parse_misc.cc index f1d86184d..b81a86036 100644 --- a/vhdlpp/parse_misc.cc +++ b/vhdlpp/parse_misc.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011,2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -58,7 +58,7 @@ void bind_architecture_to_entity(const char*ename, Architecture*arch) /* FIXME: entities can have multiple architectures attached to them This is to be configured by VHDL's configurations (not yet implemented) */ - Architecture*old_arch = idx->second->add_architecture(arch); + const Architecture*old_arch = idx->second->add_architecture(arch); if (old_arch != arch) { cerr << arch->get_fileline() << ": warning: " << "Architecture " << arch->get_name() diff --git a/vhdlpp/sequential_elaborate.cc b/vhdlpp/sequential_elaborate.cc index 7d25bdc30..e6e61c122 100644 --- a/vhdlpp/sequential_elaborate.cc +++ b/vhdlpp/sequential_elaborate.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2025 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 @@ -187,7 +187,7 @@ int ProcedureCall::elaborate(Entity*ent, ScopeBase*scope) if(param_list_) { for(list::iterator it = param_list_->begin(); it != param_list_->end(); ++it) { - named_expr_t* e = *it; + const named_expr_t* e = *it; arg_types.push_back(e->expr()->probe_type(ent, scope)); } } diff --git a/vhdlpp/subprogram.cc b/vhdlpp/subprogram.cc index d06917a31..fd91f97e2 100644 --- a/vhdlpp/subprogram.cc +++ b/vhdlpp/subprogram.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Stephen Williams (steve@icarus.com) + * Copyright (c) 2013-2025 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * Copyright CERN 2015 * @author Maciej Suminski (maciej.suminski@cern.ch) @@ -290,13 +290,13 @@ struct check_return_type : public SeqStmtVisitor { void operator() (SequentialStmt*s) { - ReturnStmt*ret; + const ReturnStmt*ret; if((ret = dynamic_cast(s))) { const Expression*expr = ret->peek_expr(); const VType*t = NULL; if(const ExpName*n = dynamic_cast(expr)) { - if(Variable*v = subp_->find_variable(n->peek_name())) + if(const Variable*v = subp_->find_variable(n->peek_name())) t = v->peek_type(); } else { t = expr->peek_type(); diff --git a/vpi/Makefile.in b/vpi/Makefile.in index f2cdf198b..e4c294d18 100644 --- a/vpi/Makefile.in +++ b/vpi/Makefile.in @@ -104,6 +104,8 @@ distclean: clean # an explicit value (i.e. the define is expected to be real code). cppcheck: $(O:.o=.c) $(OPP:.o=.cc) $(M:.o=.c) $(V:.o=.c) cppcheck --enable=all --std=c99 --std=c++11 -f \ + --check-level=exhaustive \ + --suppressions-list=$(srcdir)/../cppcheck-global.sup \ --suppressions-list=$(srcdir)/cppcheck.sup \ -UYY_USER_INIT -UYY_LOCATION_PRINT -Uyyset_out -Uyyset_lineno \ -Uyyset_in -Uyyset_extra -Uyyset_debug -Uyylex_destroy \ diff --git a/vpi/sys_display.c b/vpi/sys_display.c index d4d8d9e15..3b1ed97ee 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -573,7 +573,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus, if (width == -1) width = 0; { - char *cp = vpi_get_str(vpiFullName, info->scope); + const char *cp = vpi_get_str(vpiFullName, info->scope); /* If the default buffer is too small, make it big enough. */ size = strlen(cp) + 1; if ((signed)size < (width+1)) size = width+1; diff --git a/vpi/sys_lxt.c b/vpi/sys_lxt.c index 3ceedf4c2..75e5665d2 100644 --- a/vpi/sys_lxt.c +++ b/vpi/sys_lxt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2002-2025 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 @@ -126,7 +126,7 @@ static char *create_full_name(const char *name) char *n, *n2; int len = 0; int is_esc_id = is_escaped_id(name); - struct lxt_scope *t = lxt_scope_head; + const struct lxt_scope *t = lxt_scope_head; /* Figure out how long the combined string will be. */ while(t) { diff --git a/vpi/sys_lxt2.c b/vpi/sys_lxt2.c index ce68387ec..76ec458ba 100644 --- a/vpi/sys_lxt2.c +++ b/vpi/sys_lxt2.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2025 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 @@ -61,7 +61,7 @@ struct vcd_info_chunk { struct vcd_info_chunk*info_chunk_list = 0; -struct vcd_info*new_vcd_info(void) +static struct vcd_info*new_vcd_info(void) { struct vcd_info_chunk*cur_chunk = info_chunk_list; if (cur_chunk == 0 || cur_chunk->chunk_fill == 0xffff) { @@ -77,7 +77,7 @@ struct vcd_info*new_vcd_info(void) return ptr; } -void functor_all_vcd_info( void (*fun) (struct vcd_info*info) ) +static void functor_all_vcd_info( void (*fun) (struct vcd_info*info) ) { struct vcd_info_chunk*cur; for (cur = info_chunk_list ; cur ; cur = cur->chunk_next) { @@ -88,7 +88,7 @@ void functor_all_vcd_info( void (*fun) (struct vcd_info*info) ) } } -void delete_all_vcd_info(void) +static void delete_all_vcd_info(void) { while (info_chunk_list) { struct vcd_info_chunk*tmp = info_chunk_list->chunk_next; diff --git a/vpi/sys_plusargs.c b/vpi/sys_plusargs.c index 9c40f53ed..4faeb77d2 100644 --- a/vpi/sys_plusargs.c +++ b/vpi/sys_plusargs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2002-2025 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 @@ -230,7 +230,8 @@ static PLI_INT32 sys_value_plusargs_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) /* Look for a +arg that matches the prefix supplied. */ for (idx = 0 ; idx < info.argc ; idx += 1) { - char*sp, *tp, *end; + char*sp, *end; + const char*tp; size_t sp_len; /* Skip arguments that are not +args. */ diff --git a/vpi/sys_sdf.c b/vpi/sys_sdf.c index 830837a48..f575e6fd2 100644 --- a/vpi/sys_sdf.c +++ b/vpi/sys_sdf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2023 Stephen Williams (steve@icarus.com) + * Copyright (c) 2007-2025 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 @@ -146,7 +146,7 @@ static const char*edge_str(int vpi_edge) return "edge.. "; } -vpiHandle get_port_handle(char* port_name, const int sdf_lineno) +static vpiHandle get_port_handle(char* port_name, const int sdf_lineno) { vpiHandle scope = sdf_cur_cell; @@ -176,7 +176,7 @@ vpiHandle get_port_handle(char* port_name, const int sdf_lineno) vpiHandle port_handle = NULL; while ((port=vpi_scan(port_i)) != NULL) { - char *port_name_ = vpi_get_str(vpiName, port) ; + const char *port_name_ = vpi_get_str(vpiName, port) ; if (strcmp(port_name_, token) == 0) { if (port_handle != NULL) { diff --git a/vpi/vams_simparam.c b/vpi/vams_simparam.c index c0f1fb648..461922247 100644 --- a/vpi/vams_simparam.c +++ b/vpi/vams_simparam.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2021 Cary R. (cygcary@yahoo.com) + * Copyright (C) 2008-2025 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 @@ -217,7 +217,7 @@ static PLI_INT32 simparam_str_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name_ext) retval = strdup("N/A"); /* Nothing for now. */ } else if (strcmp(param, "cwd") == 0) { char path [MAX_STRING_RESULT]; - char *ptr = getcwd(path, MAX_STRING_RESULT); + const char *ptr = getcwd(path, MAX_STRING_RESULT); if (ptr == NULL) { strcpy(path, ""); } diff --git a/vpi/vcd_priv.c b/vpi/vcd_priv.c index df1279cd1..75d53bc63 100644 --- a/vpi/vcd_priv.c +++ b/vpi/vcd_priv.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2025 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 @@ -51,7 +51,7 @@ int is_escaped_id(const char *name) return 1; } -int vcd_instance_contains_dumpable_items(int dumpable_types[], vpiHandle item) +int vcd_instance_contains_dumpable_items(const int dumpable_types[], vpiHandle item) { int i; for (i = 0; dumpable_types[i] > 0; i++) { @@ -101,7 +101,7 @@ static int vcd_names_compare(const void *s1, const void *s2) return strcmp(v1, v2); } -const char *vcd_names_search(struct vcd_names_list_s*tab, const char *key) +const char *vcd_names_search(const struct vcd_names_list_s*tab, const char *key) { const char **v; diff --git a/vpi/vcd_priv.h b/vpi/vcd_priv.h index 267fa7d5f..e2e9723eb 100644 --- a/vpi/vcd_priv.h +++ b/vpi/vcd_priv.h @@ -1,7 +1,7 @@ #ifndef IVL_vcd_priv_H #define IVL_vcd_priv_H /* - * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2025 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 @@ -29,7 +29,7 @@ EXTERN int is_escaped_id(const char *name); -EXTERN int vcd_instance_contains_dumpable_items(int dumpable_types[], vpiHandle item); +EXTERN int vcd_instance_contains_dumpable_items(const int dumpable_types[], vpiHandle item); struct vcd_names_s; EXTERN struct stringheap_s name_heap; @@ -42,7 +42,7 @@ struct vcd_names_list_s { EXTERN void vcd_names_add(struct vcd_names_list_s*tab, const char *name); -EXTERN const char *vcd_names_search(struct vcd_names_list_s*tab, +EXTERN const char *vcd_names_search(const struct vcd_names_list_s*tab, const char *key); EXTERN void vcd_names_sort(struct vcd_names_list_s*tab);