From e7c6829512321f61e59525fb30856762ffec1210 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 20 Nov 2012 17:40:52 -0800 Subject: [PATCH] Create a stub vvp_cobject class. --- vvp/Makefile.in | 3 +- vvp/vpi_darray.cc | 1 + vvp/vthread.cc | 8 +++ vvp/vvp_cobject.cc | 30 ++++++++++ vvp/vvp_cobject.h | 35 ++++++++++++ vvp/vvp_darray.cc | 139 +++++++++++++++++++++++++++++++++++++++++++++ vvp/vvp_darray.h | 89 +++++++++++++++++++++++++++++ vvp/vvp_object.cc | 114 ------------------------------------- vvp/vvp_object.h | 65 --------------------- 9 files changed, 304 insertions(+), 180 deletions(-) create mode 100644 vvp/vvp_cobject.cc create mode 100644 vvp/vvp_cobject.h create mode 100644 vvp/vvp_darray.cc create mode 100644 vvp/vvp_darray.h diff --git a/vvp/Makefile.in b/vvp/Makefile.in index 0859743c9..4c3860dba 100644 --- a/vvp/Makefile.in +++ b/vvp/Makefile.in @@ -76,7 +76,8 @@ O = main.o parse.o parse_misc.o lexor.o arith.o array.o bufif.o compile.o \ permaheap.o reduce.o resolv.o \ sfunc.o stop.o symbols.o ufunc.o codes.o vthread.o schedule.o \ statistics.o tables.o udp.o vvp_island.o vvp_net.o vvp_net_sig.o \ - vvp_object.o event.o logic.o delay.o words.o island_tran.o $V + vvp_object.o vvp_cobject.o vvp_darray.o event.o logic.o delay.o \ + words.o island_tran.o $V all: dep vvp@EXEEXT@ libvpi.a vvp.man diff --git a/vvp/vpi_darray.cc b/vvp/vpi_darray.cc index 4fade0e98..9a6336a8b 100644 --- a/vvp/vpi_darray.cc +++ b/vvp/vpi_darray.cc @@ -21,6 +21,7 @@ # include "compile.h" # include "vpi_priv.h" # include "vvp_net_sig.h" +# include "vvp_darray.h" # include "schedule.h" #ifdef CHECK_WITH_VALGRIND # include "vvp_cleanup.h" diff --git a/vvp/vthread.cc b/vvp/vthread.cc index b50590166..b107fab78 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -25,6 +25,8 @@ # include "event.h" # include "vpi_priv.h" # include "vvp_net_sig.h" +# include "vvp_cobject.h" +# include "vvp_darray.h" #ifdef CHECK_WITH_VALGRIND # include "vvp_cleanup.h" #endif @@ -4067,9 +4069,15 @@ bool of_NAND(vthread_t thr, vvp_code_t cp) return cp->opcode(thr, cp); } +/* + * %new/cobj + * This creates a new cobject (SystemVerilog class object) and pushes + * it to the stack. + */ bool of_NEW_COBJ(vthread_t thr, vvp_code_t cp) { vvp_object_t tmp; + tmp = new vvp_cobject; thr->push_object(tmp); return true; } diff --git a/vvp/vvp_cobject.cc b/vvp/vvp_cobject.cc new file mode 100644 index 000000000..b5289913c --- /dev/null +++ b/vvp/vvp_cobject.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "vvp_cobject.h" + +using namespace std; + +vvp_cobject::vvp_cobject(void) +{ +} + +vvp_cobject::~vvp_cobject() +{ +} diff --git a/vvp/vvp_cobject.h b/vvp/vvp_cobject.h new file mode 100644 index 000000000..fb4a34a54 --- /dev/null +++ b/vvp/vvp_cobject.h @@ -0,0 +1,35 @@ +#ifndef __vvp_cobject_H +#define __vvp_cobject_H +/* + * Copyright (c) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "vvp_object.h" + + +class vvp_cobject : public vvp_object { + + public: + vvp_cobject(); + ~vvp_cobject(); + + private: + int stub_; +}; + +#endif diff --git a/vvp/vvp_darray.cc b/vvp/vvp_darray.cc new file mode 100644 index 000000000..3f5151c07 --- /dev/null +++ b/vvp/vvp_darray.cc @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "vvp_darray.h" +# include "vvp_net.h" +# include +# include + +using namespace std; + +vvp_darray::~vvp_darray() +{ +} + +void vvp_darray::set_word(unsigned, const vvp_vector4_t&) +{ + cerr << "XXXX set_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl; +} + +void vvp_darray::set_word(unsigned, double) +{ + cerr << "XXXX set_word(double) not implemented for " << typeid(*this).name() << endl; +} + +void vvp_darray::set_word(unsigned, const string&) +{ + cerr << "XXXX set_word(string) not implemented for " << typeid(*this).name() << endl; +} + +void vvp_darray::get_word(unsigned, vvp_vector4_t&) +{ + cerr << "XXXX get_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl; +} + +void vvp_darray::get_word(unsigned, double&) +{ + cerr << "XXXX get_word(double) not implemented for " << typeid(*this).name() << endl; +} + +void vvp_darray::get_word(unsigned, string&) +{ + cerr << "XXXX get_word(string) not implemented for " << typeid(*this).name() << endl; +} + +template vvp_darray_atom::~vvp_darray_atom() +{ +} + +template void vvp_darray_atom::set_word(unsigned adr, const vvp_vector4_t&value) +{ + if (adr >= array_.size()) + return; + TYPE tmp; + vector4_to_value(value, tmp, true, false); + array_[adr] = tmp; +} + +template void vvp_darray_atom::get_word(unsigned adr, vvp_vector4_t&value) +{ + if (adr >= array_.size()) { + value = vvp_vector4_t(8*sizeof(TYPE), BIT4_X); + return; + } + + TYPE word = array_[adr]; + vvp_vector4_t tmp (8*sizeof(TYPE), BIT4_0); + for (unsigned idx = 0 ; idx < tmp.size() ; idx += 1) { + if (word&1) tmp.set_bit(idx, BIT4_1); + word >>= 1; + } + value = tmp; +} + +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; +template class vvp_darray_atom; + +vvp_darray_real::~vvp_darray_real() +{ +} + +void vvp_darray_real::set_word(unsigned adr, double value) +{ + if (adr >= array_.size()) + return; + array_[adr] = value; +} + +void vvp_darray_real::get_word(unsigned adr, double&value) +{ + if (adr >= array_.size()) { + value = 0.0; + return; + } + + value = array_[adr]; +} + +vvp_darray_string::~vvp_darray_string() +{ +} + +void vvp_darray_string::set_word(unsigned adr, const string&value) +{ + if (adr >= array_.size()) + return; + array_[adr] = value; +} + +void vvp_darray_string::get_word(unsigned adr, string&value) +{ + if (adr >= array_.size()) { + value = 0.0; + return; + } + + value = array_[adr]; +} diff --git a/vvp/vvp_darray.h b/vvp/vvp_darray.h new file mode 100644 index 000000000..65f0629c0 --- /dev/null +++ b/vvp/vvp_darray.h @@ -0,0 +1,89 @@ +#ifndef __vvp_darray_H +#define __vvp_darray_H +/* + * Copyright (c) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "vvp_object.h" +# include +# include + +class vvp_vector4_t; + +class vvp_darray : public vvp_object { + + public: + inline vvp_darray(size_t siz) : size_(siz) { } + virtual ~vvp_darray(); + + inline size_t get_size(void) const { return size_; } + + virtual void set_word(unsigned adr, const vvp_vector4_t&value); + virtual void get_word(unsigned adr, vvp_vector4_t&value); + + virtual void set_word(unsigned adr, double value); + virtual void get_word(unsigned adr, double&value); + + virtual void set_word(unsigned adr, const std::string&value); + virtual void get_word(unsigned adr, std::string&value); + + private: + size_t size_; +}; + +template class vvp_darray_atom : public vvp_darray { + + public: + inline vvp_darray_atom(size_t siz) : vvp_darray(siz), array_(siz) { } + ~vvp_darray_atom(); + + void set_word(unsigned adr, const vvp_vector4_t&value); + void get_word(unsigned adr, vvp_vector4_t&value); + + private: + std::vector array_; +}; + +class vvp_darray_real : public vvp_darray { + + public: + inline vvp_darray_real(size_t siz) : vvp_darray(siz), array_(siz) { } + ~vvp_darray_real(); + + void set_word(unsigned adr, double value); + void get_word(unsigned adr, double&value); + + private: + std::vector array_; +}; + +class vvp_darray_string : public vvp_darray { + + public: + inline vvp_darray_string(size_t siz) : vvp_darray(siz), array_(siz) { } + ~vvp_darray_string(); + + void set_word(unsigned adr, const std::string&value); + void get_word(unsigned adr, std::string&value); + + private: + std::vector array_; +}; + + +#endif diff --git a/vvp/vvp_object.cc b/vvp/vvp_object.cc index 964a0cde3..475ae7404 100644 --- a/vvp/vvp_object.cc +++ b/vvp/vvp_object.cc @@ -34,117 +34,3 @@ vvp_object::~vvp_object() { total_active_cnt_ -= 1; } - -vvp_darray::~vvp_darray() -{ -} - -void vvp_darray::set_word(unsigned, const vvp_vector4_t&) -{ - cerr << "XXXX set_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl; -} - -void vvp_darray::set_word(unsigned, double) -{ - cerr << "XXXX set_word(double) not implemented for " << typeid(*this).name() << endl; -} - -void vvp_darray::set_word(unsigned, const string&) -{ - cerr << "XXXX set_word(string) not implemented for " << typeid(*this).name() << endl; -} - -void vvp_darray::get_word(unsigned, vvp_vector4_t&) -{ - cerr << "XXXX get_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl; -} - -void vvp_darray::get_word(unsigned, double&) -{ - cerr << "XXXX get_word(double) not implemented for " << typeid(*this).name() << endl; -} - -void vvp_darray::get_word(unsigned, string&) -{ - cerr << "XXXX get_word(string) not implemented for " << typeid(*this).name() << endl; -} - -template vvp_darray_atom::~vvp_darray_atom() -{ -} - -template void vvp_darray_atom::set_word(unsigned adr, const vvp_vector4_t&value) -{ - if (adr >= array_.size()) - return; - TYPE tmp; - vector4_to_value(value, tmp, true, false); - array_[adr] = tmp; -} - -template void vvp_darray_atom::get_word(unsigned adr, vvp_vector4_t&value) -{ - if (adr >= array_.size()) { - value = vvp_vector4_t(8*sizeof(TYPE), BIT4_X); - return; - } - - TYPE word = array_[adr]; - vvp_vector4_t tmp (8*sizeof(TYPE), BIT4_0); - for (unsigned idx = 0 ; idx < tmp.size() ; idx += 1) { - if (word&1) tmp.set_bit(idx, BIT4_1); - word >>= 1; - } - value = tmp; -} - -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; -template class vvp_darray_atom; - -vvp_darray_real::~vvp_darray_real() -{ -} - -void vvp_darray_real::set_word(unsigned adr, double value) -{ - if (adr >= array_.size()) - return; - array_[adr] = value; -} - -void vvp_darray_real::get_word(unsigned adr, double&value) -{ - if (adr >= array_.size()) { - value = 0.0; - return; - } - - value = array_[adr]; -} - -vvp_darray_string::~vvp_darray_string() -{ -} - -void vvp_darray_string::set_word(unsigned adr, const string&value) -{ - if (adr >= array_.size()) - return; - array_[adr] = value; -} - -void vvp_darray_string::get_word(unsigned adr, string&value) -{ - if (adr >= array_.size()) { - value = 0.0; - return; - } - - value = array_[adr]; -} diff --git a/vvp/vvp_object.h b/vvp/vvp_object.h index c3f2f2c9b..cf2b8b5ea 100644 --- a/vvp/vvp_object.h +++ b/vvp/vvp_object.h @@ -20,11 +20,6 @@ */ # include -# include -# include - -class vvp_vector4_t; -class vvp_object_t; /* * A vvp_object is a garbage collected object such as a darray or @@ -120,64 +115,4 @@ template inline T*vvp_object_t::peek(void) const return dynamic_cast (ref_); } -class vvp_darray : public vvp_object { - - public: - inline vvp_darray(size_t siz) : size_(siz) { } - virtual ~vvp_darray(); - - inline size_t get_size(void) const { return size_; } - - virtual void set_word(unsigned adr, const vvp_vector4_t&value); - virtual void get_word(unsigned adr, vvp_vector4_t&value); - - virtual void set_word(unsigned adr, double value); - virtual void get_word(unsigned adr, double&value); - - virtual void set_word(unsigned adr, const std::string&value); - virtual void get_word(unsigned adr, std::string&value); - - private: - size_t size_; -}; - -template class vvp_darray_atom : public vvp_darray { - - public: - inline vvp_darray_atom(size_t siz) : vvp_darray(siz), array_(siz) { } - ~vvp_darray_atom(); - - void set_word(unsigned adr, const vvp_vector4_t&value); - void get_word(unsigned adr, vvp_vector4_t&value); - - private: - std::vector array_; -}; - -class vvp_darray_real : public vvp_darray { - - public: - inline vvp_darray_real(size_t siz) : vvp_darray(siz), array_(siz) { } - ~vvp_darray_real(); - - void set_word(unsigned adr, double value); - void get_word(unsigned adr, double&value); - - private: - std::vector array_; -}; - -class vvp_darray_string : public vvp_darray { - - public: - inline vvp_darray_string(size_t siz) : vvp_darray(siz), array_(siz) { } - ~vvp_darray_string(); - - void set_word(unsigned adr, const std::string&value); - void get_word(unsigned adr, std::string&value); - - private: - std::vector array_; -}; - #endif