diff --git a/t-vvm.cc b/t-vvm.cc index 1c36bffad..d2f8b4436 100644 --- a/t-vvm.cc +++ b/t-vvm.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-vvm.cc,v 1.191 2000/12/15 03:06:04 steve Exp $" +#ident "$Id: t-vvm.cc,v 1.192 2000/12/15 20:05:16 steve Exp $" #endif # include @@ -1251,8 +1251,7 @@ void target_vvm::signal(const NetNet*sig) void target_vvm::memory(const NetMemory*mem) { const string mname = mangle(mem->name()); - out << "static vvm_memory_t<" << mem->width() << ", " << - mem->count() << "> " << mname << ";" + out << "static vvm_memory_t " << mname << ";" " /* " << mem->name() << " */" << endl; init_code << " vpip_make_memory(&" << mname << ", \"" << mem->name() << "\", " << mem->width() << ", " << @@ -2657,8 +2656,7 @@ void target_vvm::proc_assign_mem_nb(const NetAssignMemNB*amem) assert(mem->width() <= amem->rval()->expr_width()); - defn << " (new vvm_memory_t<" << mem->width() << "," - << mem->count() << ">::assign_nb(" << mangle(mem->name()) + defn << " (new vvm_memory_t::assign_nb(" << mangle(mem->name()) << ", " << index << ".as_unsigned(), " << rval << ")) -> schedule();" << endl; } @@ -3406,6 +3404,9 @@ extern const struct target tgt_vvm = { }; /* * $Log: t-vvm.cc,v $ + * Revision 1.192 2000/12/15 20:05:16 steve + * Fix memory access in vvm. (PR#70) + * * Revision 1.191 2000/12/15 03:06:04 steve * functions with system tasks (PR#46) * diff --git a/vvm/Makefile.in b/vvm/Makefile.in index 427f9e559..361f812f5 100644 --- a/vvm/Makefile.in +++ b/vvm/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.40 2000/11/29 23:59:29 steve Exp $" +#ident "$Id: Makefile.in,v 1.41 2000/12/15 20:05:16 steve Exp $" # # SHELL = /bin/sh @@ -49,8 +49,8 @@ STRIP = @STRIP@ O = vvm_add_sub.o vvm_bit.o vvm_calltf.o vvm_clshift.o vvm_compare.o \ vvm_event.o vvm_ff.o vvm_force.o \ -vvm_func.o vvm_gates.o vvm_idiv.o vvm_imod.o vvm_mult.o vvm_mux.o \ -vvm_nexus.o vvm_pevent.o vvm_signal.o vvm_thread.o vvm_udp.o +vvm_func.o vvm_gates.o vvm_idiv.o vvm_imod.o vvm_memory.o vvm_mult.o \ +vvm_mux.o vvm_nexus.o vvm_pevent.o vvm_signal.o vvm_thread.o vvm_udp.o P = vpi_bit.o vpi_callback.o \ vpi_const.o vpi_iter.o vpi_memory.o vpi_null.o \ diff --git a/vvm/vvm_gates.h b/vvm/vvm_gates.h index c5171e233..3fa7bda36 100644 --- a/vvm/vvm_gates.h +++ b/vvm/vvm_gates.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vvm_gates.h,v 1.68 2000/12/10 06:42:00 steve Exp $" +#ident "$Id: vvm_gates.h,v 1.69 2000/12/15 20:05:16 steve Exp $" #endif # include "vvm.h" @@ -530,7 +530,7 @@ template class vvm_ram_dq : protected vvm_ram_callback, public vvm_nexus::recvr_t { public: - vvm_ram_dq(vvm_memory_t*mem) + vvm_ram_dq(vvm_memory_t*mem) : mem_(mem) { mem->set_callback(this); for (unsigned idx = 0 ; idx < AWIDTH+WIDTH+2 ; idx += 1) @@ -577,7 +577,7 @@ class vvm_ram_dq : protected vvm_ram_callback, public vvm_nexus::recvr_t { void handle_write(unsigned idx) { if (idx == addr_val_) send_out_(); } private: - vvm_memory_t*mem_; + vvm_memory_t*mem_; vpip_bit_t ibits_[AWIDTH+WIDTH+2]; vvm_nexus::drive_t out_[WIDTH]; @@ -1006,6 +1006,9 @@ class vvm_posedge : public vvm_nexus::recvr_t { /* * $Log: vvm_gates.h,v $ + * Revision 1.69 2000/12/15 20:05:16 steve + * Fix memory access in vvm. (PR#70) + * * Revision 1.68 2000/12/10 06:42:00 steve * Support delays on continuous assignment from idents. (PR#40) * diff --git a/vvm/vvm_memory.cc b/vvm/vvm_memory.cc new file mode 100644 index 000000000..7097b1aa1 --- /dev/null +++ b/vvm/vvm_memory.cc @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2000 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 + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: vvm_memory.cc,v 1.1 2000/12/15 20:05:16 steve Exp $" +#endif + +# include "vvm_signal.h" + +vvm_memory_t::vvm_memory_t() +{ + cb_list_ = 0; +} + +void vvm_memory_t::set_word(unsigned addr, const vvm_bitset_t&val) +{ + if (addr >= size) + return; + + unsigned base = width * addr; + for (unsigned idx = 0 ; idx < width ; idx += 1) + bits[base+idx] = val[idx]; + + call_list_(addr); +} + +void vvm_memory_t::set_word(unsigned addr, const vpip_bit_t*val) +{ + if (addr >= size) + return; + + unsigned base = width * addr; + for (unsigned idx = 0 ; idx < width ; idx += 1) + bits[base+idx] = val[idx]; + + call_list_(addr); +} + +void vvm_memory_t::get_word(unsigned addr, vvm_bitset_t&val) const +{ + if (addr >= size) { + for (unsigned idx = 0 ; idx < width ; idx += 1) + val[idx] = StX; + return; + } + + unsigned base = width * addr; + for (unsigned idx = 0 ; idx < width ; idx += 1) + val[idx] = bits[base+idx]; +} + +void vvm_memory_t::set_callback(vvm_ram_callback*ram) +{ + ram->next_ = cb_list_; + cb_list_ = ram; +} + +void vvm_memory_t::call_list_(unsigned idx) +{ + for (vvm_ram_callback*cur = cb_list_; cur; cur = cur->next_) + cur->handle_write(idx); +} + +vvm_memory_t::assign_nb::assign_nb(vvm_memory_t&m, unsigned i, + const vvm_bitset_t&v) +: mem_(m), index_(i), bits_(new vpip_bit_t[m.width]), val_(bits_, m.width) +{ + for (unsigned idx = 0 ; idx < m.width ; idx += 1) + val_[idx] = v[idx]; +} + + +vvm_memory_t::assign_nb::~assign_nb() +{ + delete[]bits_; +} + +void vvm_memory_t::assign_nb::event_function() +{ + mem_.set_word(index_, val_); +} + +/* + * $Log: vvm_memory.cc,v $ + * Revision 1.1 2000/12/15 20:05:16 steve + * Fix memory access in vvm. (PR#70) + * + */ + diff --git a/vvm/vvm_signal.h b/vvm/vvm_signal.h index ce7b9b053..afc4f9c56 100644 --- a/vvm/vvm_signal.h +++ b/vvm/vvm_signal.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vvm_signal.h,v 1.10 2000/12/12 03:30:25 steve Exp $" +#ident "$Id: vvm_signal.h,v 1.11 2000/12/15 20:05:16 steve Exp $" #endif # include "vvm.h" @@ -86,72 +86,44 @@ struct vvm_ram_callback { vvm_ram_callback*next_; }; -template class vvm_memory_t : public __vpiMemory { public: - vvm_memory_t() - { cb_list_ = 0; - } + vvm_memory_t(); - void set_word(unsigned addr, const vvm_bitset_t&val) - { unsigned base = WIDTH * addr; - assert(addr < size); - for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - bits[base+idx] = val[idx]; - call_list_(addr); - } + void set_word(unsigned addr, const vvm_bitset_t&val); - void set_word(unsigned addr, - const vpip_bit_t val[WIDTH]) - { unsigned base = WIDTH * addr; - assert(addr < size); - for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - bits[base+idx] = val[idx]; - call_list_(addr); - } + void set_word(unsigned addr, const vpip_bit_t*val); - void get_word(unsigned addr, vvm_bitset_t&val) const - { unsigned base = WIDTH * addr; - assert(addr < size); - for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - val[idx] = bits[base+idx]; - } + void get_word(unsigned addr, vvm_bitset_t&val) const; - void set_callback(vvm_ram_callback*ram) - { ram->next_ = cb_list_; - cb_list_ = ram; - } + void set_callback(vvm_ram_callback*ram); class assign_nb : public vvm_event { public: - assign_nb(vvm_memory_t&m, unsigned i, - const vvm_bitset_t&v) - : mem_(m), index_(i), val_(bits_, WIDTH) - { for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - val_[idx] = v[idx]; - } + assign_nb(vvm_memory_t&m, unsigned i, const vvm_bitset_t&v); + ~assign_nb(); - void event_function() { mem_.set_word(index_, val_); } + void event_function(); private: - vvm_memory_t&mem_; + vvm_memory_t&mem_; unsigned index_; - vpip_bit_t bits_[WIDTH]; + vpip_bit_t*bits_; vvm_bitset_t val_; }; private: vvm_ram_callback*cb_list_; - void call_list_(unsigned idx) - { for (vvm_ram_callback*cur = cb_list_; cur; cur = cur->next_) - cur->handle_write(idx); - } + void call_list_(unsigned idx); }; /* * $Log: vvm_signal.h,v $ + * Revision 1.11 2000/12/15 20:05:16 steve + * Fix memory access in vvm. (PR#70) + * * Revision 1.10 2000/12/12 03:30:25 steve * out-line vvm_bitset_t methods. *