Fix some vvp initialization problems found with cppcheck.

This patch adds a few missing initializations to various constructors
in the vvp directory. It also enhances the array alias code to copy
more values from the aliased array.
This commit is contained in:
Cary R 2010-10-10 15:14:29 -07:00 committed by Stephen Williams
parent eb525b6c2a
commit 225ee65c31
9 changed files with 95 additions and 55 deletions

View File

@ -81,8 +81,6 @@ vvp_array_t array_find(const char*label)
* vector4 array works. * vector4 array works.
*/ */
struct __vpiArray { struct __vpiArray {
__vpiArray() { }
struct __vpiHandle base; struct __vpiHandle base;
struct __vpiScope*scope; struct __vpiScope*scope;
const char*name; /* Permanently allocated string */ const char*name; /* Permanently allocated string */
@ -1092,11 +1090,8 @@ void compile_real_array(char*label, char*name, int last, int first,
arr->valsr = new vvp_realarray_t(arr->array_count); arr->valsr = new vvp_realarray_t(arr->array_count);
arr->vals_width = 1; arr->vals_width = 1;
/* Do these even make sense for real arrays? These are the /* For a real array the MSB and LSB must be zero. */
part select of a vector, but the real value is not assert(msb == 0 && lsb == 0);
vectorable. */
vpip_make_dec_const(&arr->msb, msb);
vpip_make_dec_const(&arr->lsb, lsb);
count_real_arrays += 1; count_real_arrays += 1;
count_real_array_words += arr->array_count; count_real_array_words += arr->array_count;
@ -1449,7 +1444,8 @@ bool array_resolv_list_t::resolve(bool mes)
class array_port_resolv_list_t : public resolv_list_s { class array_port_resolv_list_t : public resolv_list_s {
public: public:
explicit array_port_resolv_list_t(char*lab) : resolv_list_s(lab) { } explicit array_port_resolv_list_t(char* lab, bool use_addr__,
long addr__);
vvp_net_t*ptr; vvp_net_t*ptr;
bool use_addr; bool use_addr;
@ -1459,6 +1455,13 @@ class array_port_resolv_list_t : public resolv_list_s {
private: private:
}; };
array_port_resolv_list_t::array_port_resolv_list_t(char *lab, bool use_addr__,
long addr__)
: resolv_list_s(lab), use_addr(use_addr__), addr(addr__)
{
ptr = new vvp_net_t;
}
bool array_port_resolv_list_t::resolve(bool mes) bool array_port_resolv_list_t::resolve(bool mes)
{ {
vvp_array_t mem = array_find(label()); vvp_array_t mem = array_find(label());
@ -1513,10 +1516,8 @@ void vpip_array_change(struct __vpiCallback*cb, vpiHandle obj)
void compile_array_port(char*label, char*array, char*addr) void compile_array_port(char*label, char*array, char*addr)
{ {
array_port_resolv_list_t*resolv_mem array_port_resolv_list_t*resolv_mem
= new array_port_resolv_list_t(array); = new array_port_resolv_list_t(array, false, 0);
resolv_mem->ptr = new vvp_net_t;
resolv_mem->use_addr = false;
define_functor_symbol(label, resolv_mem->ptr); define_functor_symbol(label, resolv_mem->ptr);
free(label); free(label);
// Connect the port-0 input as the address. // Connect the port-0 input as the address.
@ -1528,11 +1529,8 @@ void compile_array_port(char*label, char*array, char*addr)
void compile_array_port(char*label, char*array, long addr) void compile_array_port(char*label, char*array, long addr)
{ {
array_port_resolv_list_t*resolv_mem array_port_resolv_list_t*resolv_mem
= new array_port_resolv_list_t(array); = new array_port_resolv_list_t(array, true, addr);
resolv_mem->ptr = new vvp_net_t;
resolv_mem->use_addr = true;
resolv_mem->addr = addr;
define_functor_symbol(label, resolv_mem->ptr); define_functor_symbol(label, resolv_mem->ptr);
free(label); free(label);
@ -1551,16 +1549,25 @@ void compile_array_alias(char*label, char*name, char*src)
obj->scope = vpip_peek_current_scope(); obj->scope = vpip_peek_current_scope();
obj->name = vpip_name_string(name); obj->name = vpip_name_string(name);
obj->array_count = mem->array_count; obj->array_count = mem->array_count;
obj->signed_flag = mem->signed_flag;
// XXXX Need to set an accurate range of addresses. // Need to set an accurate range of addresses.
vpip_make_dec_const(&obj->first_addr, mem->first_addr.value); vpip_make_dec_const(&obj->first_addr, mem->first_addr.value);
vpip_make_dec_const(&obj->last_addr, mem->last_addr.value); vpip_make_dec_const(&obj->last_addr, mem->last_addr.value);
obj->swap_addr = mem->swap_addr;
vpip_make_dec_const(&obj->msb, mem->msb.value);
vpip_make_dec_const(&obj->lsb, mem->lsb.value);
// Share the words with the source array. // Share the words with the source array.
obj->nets = mem->nets; obj->nets = mem->nets;
obj->vals4 = mem->vals4; obj->vals4 = mem->vals4;
obj->valsr = mem->valsr;
obj->vals_width = mem->vals_width;
obj->vals_words = mem->vals_words;
obj->ports_ = 0; obj->ports_ = 0;
obj->vpi_callbacks = 0;
assert(array_table); assert(array_table);
assert(!array_find(label)); assert(!array_find(label));

View File

@ -432,7 +432,9 @@ void functor_ref_lookup(vvp_net_t**ref, char*lab)
*/ */
struct vpi_handle_resolv_list_s: public resolv_list_s { struct vpi_handle_resolv_list_s: public resolv_list_s {
explicit vpi_handle_resolv_list_s(char*lab) : resolv_list_s(lab) { } explicit vpi_handle_resolv_list_s(char*lab) : resolv_list_s(lab) {
handle = NULL;
}
virtual bool resolve(bool mes); virtual bool resolve(bool mes);
vpiHandle *handle; vpiHandle *handle;
}; };
@ -531,7 +533,9 @@ void compile_vpi_lookup(vpiHandle *handle, char*label)
*/ */
struct code_label_resolv_list_s: public resolv_list_s { struct code_label_resolv_list_s: public resolv_list_s {
code_label_resolv_list_s(char*lab) : resolv_list_s(lab) { } code_label_resolv_list_s(char*lab) : resolv_list_s(lab) {
code = NULL;
}
struct vvp_code_s *code; struct vvp_code_s *code;
virtual bool resolve(bool mes); virtual bool resolve(bool mes);
}; };
@ -564,7 +568,9 @@ void code_label_lookup(struct vvp_code_s *code, char *label)
} }
struct code_array_resolv_list_s: public resolv_list_s { struct code_array_resolv_list_s: public resolv_list_s {
code_array_resolv_list_s(char*lab) : resolv_list_s(lab) { } code_array_resolv_list_s(char*lab) : resolv_list_s(lab) {
code = NULL;
}
struct vvp_code_s *code; struct vvp_code_s *code;
virtual bool resolve(bool mes); virtual bool resolve(bool mes);
}; };

View File

@ -273,7 +273,9 @@ extern void compile_param_real(char*label, char*name, char*value,
class resolv_list_s { class resolv_list_s {
public: public:
explicit resolv_list_s(char*lab) : label_(lab) { } explicit resolv_list_s(char*lab) : label_(lab) {
next = NULL;
}
virtual ~resolv_list_s(); virtual ~resolv_list_s();
virtual bool resolve(bool mes = false) = 0; virtual bool resolve(bool mes = false) = 0;

View File

@ -75,7 +75,10 @@ class vvp_fun_delay : public vvp_net_fun_t, private vvp_gen_event_s {
enum delay_type_t {UNKNOWN_DELAY, VEC4_DELAY, VEC8_DELAY, REAL_DELAY}; enum delay_type_t {UNKNOWN_DELAY, VEC4_DELAY, VEC8_DELAY, REAL_DELAY};
struct event_ { struct event_ {
event_(vvp_time64_t s) : sim_time(s) { } event_(vvp_time64_t s) : sim_time(s) {
ptr_real = 0.0;
next = NULL;
}
void (vvp_fun_delay::*run_run_ptr)(struct vvp_fun_delay::event_*cur); void (vvp_fun_delay::*run_run_ptr)(struct vvp_fun_delay::event_*cur);
const vvp_time64_t sim_time; const vvp_time64_t sim_time;
vvp_vector4_t ptr_vec4; vvp_vector4_t ptr_vec4;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008 Stephen Williams (steve@icarus.com) * Copyright (c) 2008-2010 Stephen Williams (steve@icarus.com)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU * and/or modify it in source code form under the terms of the GNU
@ -36,12 +36,11 @@ struct vvp_island_branch_tran : public vvp_island_branch {
// Behavior. (This stuff should be moved to a derived // Behavior. (This stuff should be moved to a derived
// class. The members here are specific to the tran island // class. The members here are specific to the tran island
// class.) // class.)
vvp_island_branch_tran(vvp_net_t*en__, bool active_high__,
unsigned width__, unsigned part__,
unsigned offset__);
bool run_test_enabled(); bool run_test_enabled();
void run_resolution(); void run_resolution();
bool active_high;
bool enabled_flag;
vvp_net_t*en;
unsigned width, part, offset;
void clear_resolution_flags() { flags_ &= ~0x0f; } void clear_resolution_flags() { flags_ &= ~0x0f; }
@ -55,10 +54,27 @@ struct vvp_island_branch_tran : public vvp_island_branch {
// Use the peek only for diagnostic purposes. // Use the peek only for diagnostic purposes.
int peek_flags() const { return flags_; } int peek_flags() const { return flags_; }
vvp_net_t*en;
unsigned width, part, offset;
bool active_high;
bool enabled_flag;
private: private:
int flags_; int flags_;
}; };
vvp_island_branch_tran::vvp_island_branch_tran(vvp_net_t*en__,
bool active_high__,
unsigned width__,
unsigned part__,
unsigned offset__)
: en(en__), width(width__), part(part__), offset(offset__),
active_high(active_high__)
{
flags_ = 0;
enabled_flag = en__ ? false : true;
}
static inline vvp_island_branch_tran* BRANCH_TRAN(vvp_island_branch*tmp) static inline vvp_island_branch_tran* BRANCH_TRAN(vvp_island_branch*tmp)
{ {
vvp_island_branch_tran*res = dynamic_cast<vvp_island_branch_tran*>(tmp); vvp_island_branch_tran*res = dynamic_cast<vvp_island_branch_tran*>(tmp);
@ -410,23 +426,18 @@ void compile_island_tranif(int sense, char*island, char*pa, char*pb, char*pe)
assert(use_island); assert(use_island);
free(island); free(island);
vvp_island_branch_tran*br = new vvp_island_branch_tran; vvp_net_t*en = NULL;
if (sense)
br->active_high = true;
else
br->active_high = false;
if (pe == 0) { if (pe) {
br->en = 0; en = use_island->find_port(pe);
} else { assert(en);
br->en = use_island->find_port(pe);
assert(br->en);
free(pe); free(pe);
} }
br->width = 0; vvp_island_branch_tran*br = new vvp_island_branch_tran(en,
br->part = 0; sense ? true :
br->offset = 0; false,
0, 0, 0);
use_island->add_branch(br, pa, pb); use_island->add_branch(br, pa, pb);
@ -442,12 +453,8 @@ void compile_island_tranvp(char*island, char*pa, char*pb,
assert(use_island); assert(use_island);
free(island); free(island);
vvp_island_branch_tran*br = new vvp_island_branch_tran; vvp_island_branch_tran*br = new vvp_island_branch_tran(NULL, false,
br->active_high = false; wid, par, off) ;
br->en = 0;
br->width = wid;
br->part = par;
br->offset = off;
use_island->add_branch(br, pa, pb); use_island->add_branch(br, pa, pb);

View File

@ -79,7 +79,10 @@ static void my_getrusage(struct rusage *a)
perror("/proc/self/statm"); perror("/proc/self/statm");
return; return;
} }
if (3<=fscanf(statm, "%u%u%u", &siz, &rss, &shd)) { /* Given that these are in pages we'll limit the value to
* what will fit in a 32 bit integer to prevent undefined
* behavior in fscanf(). */
if (3 == fscanf(statm, "%9u %9u %9u", &siz, &rss, &shd)) {
a->ru_maxrss = page_size * siz; a->ru_maxrss = page_size * siz;
a->ru_idrss = page_size * rss; a->ru_idrss = page_size * rss;
a->ru_ixrss = page_size * shd; a->ru_ixrss = page_size * shd;

View File

@ -75,6 +75,7 @@ struct event_time_s {
rwsync = 0; rwsync = 0;
rosync = 0; rosync = 0;
del_thr = 0; del_thr = 0;
next = NULL;
} }
vvp_time64_t delay; vvp_time64_t delay;
@ -160,10 +161,16 @@ void del_thr_event_s::single_step_display(void)
struct assign_vector4_event_s : public event_s { struct assign_vector4_event_s : public event_s {
/* The default constructor. */ /* The default constructor. */
assign_vector4_event_s(const vvp_vector4_t&that) : val(that) { } assign_vector4_event_s(const vvp_vector4_t&that) : val(that) {
base = 0;
vwid = 0;
}
/* A constructor that makes the val directly. */ /* A constructor that makes the val directly. */
assign_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid) assign_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid)
: val(that,adr,wid) { } : val(that,adr,wid) {
base = 0;
vwid = 0;
}
/* Where to do the assign. */ /* Where to do the assign. */
vvp_net_ptr_t ptr; vvp_net_ptr_t ptr;
@ -324,10 +331,14 @@ unsigned long count_assign_aword_pool(void) { return array_w_heap.pool; }
*/ */
struct propagate_vector4_event_s : public event_s { struct propagate_vector4_event_s : public event_s {
/* The default constructor. */ /* The default constructor. */
propagate_vector4_event_s(const vvp_vector4_t&that) : val(that) { } propagate_vector4_event_s(const vvp_vector4_t&that) : val(that) {
net = NULL;
}
/* A constructor that makes the val directly. */ /* A constructor that makes the val directly. */
propagate_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid) propagate_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid)
: val(that,adr,wid) { } : val(that,adr,wid) {
net = NULL;
}
/* Propagate the output of this net. */ /* Propagate the output of this net. */
vvp_net_t*net; vvp_net_t*net;

View File

@ -191,8 +191,6 @@ class vvp_udp_seq_s : public vvp_udp_s {
private: private:
vvp_bit4_t init_;
vvp_bit4_t test_levels_(const udp_levels_table&cur); vvp_bit4_t test_levels_(const udp_levels_table&cur);
// Level sensitive rows of the device. // Level sensitive rows of the device.

View File

@ -42,9 +42,9 @@ permaheap vvp_net_fil_t::heap_;
// Allocate around 1Megbytes/chunk. // Allocate around 1Megbytes/chunk.
static const size_t VVP_NET_CHUNK = 1024*1024/sizeof(vvp_net_t); static const size_t VVP_NET_CHUNK = 1024*1024/sizeof(vvp_net_t);
static vvp_net_t*vvp_net_alloc_table = 0; static vvp_net_t*vvp_net_alloc_table = NULL;
#ifdef CHECK_WITH_VALGRIND #ifdef CHECK_WITH_VALGRIND
static vvp_net_t **vvp_net_pool = 0; static vvp_net_t **vvp_net_pool = NULL;
static unsigned vvp_net_pool_count = 0; static unsigned vvp_net_pool_count = 0;
#endif #endif
static size_t vvp_net_alloc_remaining = 0; static size_t vvp_net_alloc_remaining = 0;
@ -140,7 +140,7 @@ void vvp_net_pool_delete()
::delete [] vvp_net_pool[idx]; ::delete [] vvp_net_pool[idx];
} }
free(vvp_net_pool); free(vvp_net_pool);
vvp_net_pool = 0; vvp_net_pool = NULL;
vvp_net_pool_count = 0; vvp_net_pool_count = 0;
} }
#endif #endif
@ -155,6 +155,9 @@ vvp_net_t::vvp_net_t()
out_ = vvp_net_ptr_t(0,0); out_ = vvp_net_ptr_t(0,0);
fun = 0; fun = 0;
fil = 0; fil = 0;
#ifdef CHECK_WITH_VALGRIND
pool = NULL;
#endif
} }
void vvp_net_t::link(vvp_net_ptr_t port_to_link) void vvp_net_t::link(vvp_net_ptr_t port_to_link)