Create a stub vvp_cobject class.

This commit is contained in:
Stephen Williams 2012-11-20 17:40:52 -08:00
parent a186e5ad31
commit e7c6829512
9 changed files with 304 additions and 180 deletions

View File

@ -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

View File

@ -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"

View File

@ -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;
}

30
vvp/vvp_cobject.cc Normal file
View File

@ -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()
{
}

35
vvp/vvp_cobject.h Normal file
View File

@ -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

139
vvp/vvp_darray.cc Normal file
View File

@ -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 <iostream>
# include <typeinfo>
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 <class TYPE> vvp_darray_atom<TYPE>::~vvp_darray_atom()
{
}
template <class TYPE> void vvp_darray_atom<TYPE>::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 <class TYPE> void vvp_darray_atom<TYPE>::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<uint8_t>;
template class vvp_darray_atom<uint16_t>;
template class vvp_darray_atom<uint32_t>;
template class vvp_darray_atom<uint64_t>;
template class vvp_darray_atom<int8_t>;
template class vvp_darray_atom<int16_t>;
template class vvp_darray_atom<int32_t>;
template class vvp_darray_atom<int64_t>;
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];
}

89
vvp/vvp_darray.h Normal file
View File

@ -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 <string>
# include <vector>
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 TYPE> 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<TYPE> 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<double> 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<std::string> array_;
};
#endif

View File

@ -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 <class TYPE> vvp_darray_atom<TYPE>::~vvp_darray_atom()
{
}
template <class TYPE> void vvp_darray_atom<TYPE>::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 <class TYPE> void vvp_darray_atom<TYPE>::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<uint8_t>;
template class vvp_darray_atom<uint16_t>;
template class vvp_darray_atom<uint32_t>;
template class vvp_darray_atom<uint64_t>;
template class vvp_darray_atom<int8_t>;
template class vvp_darray_atom<int16_t>;
template class vvp_darray_atom<int32_t>;
template class vvp_darray_atom<int64_t>;
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];
}

View File

@ -20,11 +20,6 @@
*/
# include <stdlib.h>
# include <string>
# include <vector>
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 <class T> inline T*vvp_object_t::peek(void) const
return dynamic_cast<T*> (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 TYPE> 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<TYPE> 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<double> 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<std::string> array_;
};
#endif