diff --git a/vvp/array.cc b/vvp/array.cc index 26bf2d6ff..dd3b8fd0a 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -18,11 +18,12 @@ */ # include "array.h" -#include "symbols.h" -#include "schedule.h" -#include "vpi_priv.h" -#include "vvp_net_sig.h" -#include "config.h" +# include "symbols.h" +# include "schedule.h" +# include "vpi_priv.h" +# include "vvp_net_sig.h" +# include "vvp_darray.h" +# include "config.h" #ifdef CHECK_WITH_VALGRIND #include "vvp_cleanup.h" #endif @@ -34,6 +35,8 @@ # include # include "ivl_alloc.h" +class vvp_darray_real; + unsigned long count_net_arrays = 0; unsigned long count_net_array_words = 0; unsigned long count_var_arrays = 0; @@ -101,7 +104,7 @@ struct __vpiArray : public __vpiHandle { vpiHandle*nets; // If this is a var array, then these are used instead of nets. vvp_vector4array_t *vals4; - vvp_realarray_t *valsr; + vvp_darray_real *valsr; struct __vpiArrayWord*vals_words; vvp_fun_arrayport*ports_; @@ -1050,7 +1053,14 @@ double array_get_word_r(vvp_array_t arr, unsigned address) if (arr->valsr) { assert(arr->vals4 == 0); assert(arr->nets == 0); - return arr->valsr->get_word(address); + // In this context, address out of bounds returns 0.0 + // instead of an error. + if (address >= arr->valsr->get_size()) + return 0.0; + + double val; + arr->valsr->get_word(address, val); + return val; } assert(arr->nets); @@ -1199,7 +1209,7 @@ void compile_real_array(char*label, char*name, int last, int first, struct __vpiArray*arr = dynamic_cast<__vpiArray*>(obj); /* Make the words. */ - arr->valsr = new vvp_realarray_t(arr->array_count); + arr->valsr = new vvp_darray_real(arr->array_count); arr->vals_width = 1; /* For a real array the MSB and LSB must be zero. */ @@ -1515,8 +1525,10 @@ void array_word_change(vvp_array_t array, unsigned long addr) if (cur->test_value_callback_ready()) { if (cur->cb_data.value) { if (vpi_array_is_real(array)) { - vpip_real_get_value(array->valsr->get_word(addr), - cur->cb_data.value); + double val = 0.0; + if (addr < array->valsr->get_size()) + array->valsr->get_word(addr, val); + vpip_real_get_value(val, cur->cb_data.value); } else { vpip_vec4_get_value(array->vals4->get_word(addr), array->vals_width, diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 1281ca67c..204c2fc8e 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -1779,36 +1779,6 @@ bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed) return a.size() <= 32; } -vvp_realarray_t::vvp_realarray_t(unsigned wor) -: words_(wor) -{ - array_ = new double[words_]; - // Real array words have a default value of zero. - for (unsigned idx = 0 ; idx < words_; idx += 1) { - array_[idx] = 0.0; - } -} - -vvp_realarray_t::~vvp_realarray_t() -{ - delete[]array_; -} - -void vvp_realarray_t::set_word(unsigned word, double value) -{ - if (word >= words_) - return; - array_[word] = value; -} - -double vvp_realarray_t::get_word(unsigned word) const -{ - if (word >= words_) - return 0.0; - else - return array_[word]; -} - vvp_vector4array_t::vvp_vector4array_t(unsigned width__, unsigned words__) : width_(width__), words_(words__) { diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index 92968e782..8335eb410 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -1,7 +1,7 @@ #ifndef __vvp_net_H #define __vvp_net_H /* - * Copyright (c) 2004-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2004-2013 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 @@ -522,25 +522,6 @@ extern bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed) extern vvp_vector4_t vector4_from_text(const char*bits, unsigned wid); -/* - * The __vpiArray handle uses instances of this to keep an array of - * real valued variables. - */ -class vvp_realarray_t { - - public: - vvp_realarray_t(unsigned words); - ~vvp_realarray_t(); - - unsigned words() const { return words_; } - - double get_word(unsigned idx) const; - void set_word(unsigned idx, double val); - - private: - unsigned words_; - double*array_; -}; /* * vvp_vector4array_t