2012-07-14 03:41:41 +02:00
|
|
|
/*
|
2014-08-01 02:56:16 +02:00
|
|
|
* Copyright (c) 2012-2014 Stephen Williams (steve@icarus.com)
|
2012-07-14 03:41:41 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2012-07-14 03:41:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "vvp_net_sig.h"
|
2012-11-21 02:40:52 +01:00
|
|
|
# include "vvp_darray.h"
|
2014-11-14 18:25:49 +01:00
|
|
|
# include "array_common.h"
|
2012-07-14 03:41:41 +02:00
|
|
|
# include "schedule.h"
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
# include "vvp_cleanup.h"
|
|
|
|
|
#endif
|
|
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cstring>
|
|
|
|
|
# include <cassert>
|
|
|
|
|
# include "ivl_alloc.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
__vpiDarrayVar::__vpiDarrayVar(__vpiScope*sc, const char*na, vvp_net_t*ne)
|
2012-11-17 04:13:06 +01:00
|
|
|
: __vpiBaseVar(sc, na, ne)
|
2012-07-14 03:41:41 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 18:25:49 +01:00
|
|
|
unsigned __vpiDarrayVar::get_size() const
|
2012-07-14 03:41:41 +02:00
|
|
|
{
|
2012-11-17 04:13:06 +01:00
|
|
|
vvp_fun_signal_object*fun = dynamic_cast<vvp_fun_signal_object*> (get_net()->fun);
|
2014-11-14 18:25:49 +01:00
|
|
|
if(!fun)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
vvp_object_t val = fun->get_object();
|
2012-11-18 02:20:33 +01:00
|
|
|
vvp_darray*aval = val.peek<vvp_darray>();
|
2012-07-14 03:41:41 +02:00
|
|
|
|
2014-11-14 18:25:49 +01:00
|
|
|
if(!aval)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return aval->get_size();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:23:16 +01:00
|
|
|
vpiHandle __vpiDarrayVar::get_left_range()
|
|
|
|
|
{
|
2014-11-26 11:14:51 +01:00
|
|
|
left_range_.set_value(0);
|
|
|
|
|
return &left_range_;
|
2014-11-20 17:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiDarrayVar::get_right_range()
|
|
|
|
|
{
|
2014-11-26 11:14:51 +01:00
|
|
|
right_range_.set_value(get_size() - 1);
|
|
|
|
|
return &right_range_;
|
2014-11-20 17:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int __vpiDarrayVar::get_word_size() const
|
|
|
|
|
{
|
|
|
|
|
return get_vvp_darray()->get_size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char*__vpiDarrayVar::get_word_str(struct __vpiArrayWord*word, int code)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __vpiDarrayVar::get_word_value(struct __vpiArrayWord*word, p_vpi_value vp)
|
|
|
|
|
{
|
|
|
|
|
unsigned index = word->get_index();
|
|
|
|
|
vvp_darray*aobj = get_vvp_darray();
|
|
|
|
|
|
|
|
|
|
switch(vp->format) {
|
|
|
|
|
case vpiIntVal:
|
|
|
|
|
case vpiVectorVal:
|
|
|
|
|
{
|
|
|
|
|
vvp_vector4_t v;
|
|
|
|
|
aobj->get_word(index, v);
|
|
|
|
|
vpip_vec2_get_value(v, get_word_size(), true, vp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiRealVal:
|
|
|
|
|
{
|
|
|
|
|
double d;
|
|
|
|
|
aobj->get_word(index, d);
|
|
|
|
|
vpip_real_get_value(d, vp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiStringVal:
|
|
|
|
|
{
|
|
|
|
|
string s;
|
|
|
|
|
aobj->get_word(index, s);
|
|
|
|
|
vpip_string_get_value(s, vp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vpi sorry: format is not implemented");
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __vpiDarrayVar::put_word_value(struct __vpiArrayWord*word, p_vpi_value vp, int flags)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiDarrayVar::get_iter_index(struct __vpiArrayIterator*iter, int idx)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 18:25:49 +01:00
|
|
|
int __vpiDarrayVar::vpi_get(int code)
|
|
|
|
|
{
|
2012-07-14 03:41:41 +02:00
|
|
|
switch (code) {
|
2014-08-01 02:56:16 +02:00
|
|
|
case vpiArrayType:
|
|
|
|
|
return vpiDynamicArray;
|
2012-07-16 05:44:07 +02:00
|
|
|
case vpiSize:
|
2014-11-14 18:25:49 +01:00
|
|
|
return get_size();
|
2012-07-16 05:44:07 +02:00
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 18:25:49 +01:00
|
|
|
char* __vpiDarrayVar::vpi_get_str(int code)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiDarrayVar::vpi_handle(int code)
|
|
|
|
|
{
|
2014-11-26 11:14:51 +01:00
|
|
|
switch (code) {
|
|
|
|
|
case vpiLeftRange:
|
|
|
|
|
return get_left_range();
|
|
|
|
|
|
|
|
|
|
case vpiRightRange:
|
|
|
|
|
return get_right_range();
|
|
|
|
|
|
|
|
|
|
//case vpiModule:
|
|
|
|
|
//return vpip_module(scope_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2014-11-14 18:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiDarrayVar::vpi_index(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index >= (long) get_size())
|
|
|
|
|
return 0;
|
|
|
|
|
if (index < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (vals_words == 0)
|
|
|
|
|
make_vals_words();
|
|
|
|
|
|
|
|
|
|
return &(vals_words[index].as_word);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
void __vpiDarrayVar::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{
|
|
|
|
|
val->format = vpiSuppressVal;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:23:16 +01:00
|
|
|
vvp_darray*__vpiDarrayVar::get_vvp_darray() const
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_signal_object*fun = dynamic_cast<vvp_fun_signal_object*> (get_net()->fun);
|
|
|
|
|
assert(fun);
|
|
|
|
|
vvp_object_t obj = fun->get_object();
|
|
|
|
|
|
|
|
|
|
return obj.peek<vvp_darray>();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
vpiHandle vpip_make_darray_var(const char*name, vvp_net_t*net)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*scope = vpip_peek_current_scope();
|
|
|
|
|
const char*use_name = name ? vpip_name_string(name) : 0;
|
|
|
|
|
|
2012-08-07 00:47:35 +02:00
|
|
|
class __vpiDarrayVar*obj = new __vpiDarrayVar(scope, use_name, net);
|
2012-07-14 03:41:41 +02:00
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
2012-12-18 20:08:30 +01:00
|
|
|
|
2014-08-01 02:56:16 +02:00
|
|
|
__vpiQueueVar::__vpiQueueVar(__vpiScope*sc, const char*na, vvp_net_t*ne)
|
|
|
|
|
: __vpiBaseVar(sc, na, ne)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int __vpiQueueVar::get_type_code(void) const
|
|
|
|
|
{ return vpiArrayVar; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int __vpiQueueVar::vpi_get(int code)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_signal_object*fun = dynamic_cast<vvp_fun_signal_object*> (get_net()->fun);
|
|
|
|
|
assert(fun);
|
|
|
|
|
vvp_object_t val = fun->get_object();
|
2014-08-10 05:43:53 +02:00
|
|
|
vvp_queue*aval = val.peek<vvp_queue>();
|
2014-08-01 02:56:16 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiArrayType:
|
|
|
|
|
return vpiQueueArray;
|
|
|
|
|
case vpiSize:
|
|
|
|
|
if (aval == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return aval->get_size();
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __vpiQueueVar::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{
|
|
|
|
|
val->format = vpiSuppressVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vpiHandle vpip_make_queue_var(const char*name, vvp_net_t*net)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*scope = vpip_peek_current_scope();
|
|
|
|
|
const char*use_name = name ? vpip_name_string(name) : 0;
|
|
|
|
|
|
|
|
|
|
class __vpiQueueVar*obj = new __vpiQueueVar(scope, use_name, net);
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-18 20:08:30 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void darray_delete(vpiHandle item)
|
|
|
|
|
{
|
|
|
|
|
class __vpiDarrayVar*obj = dynamic_cast<__vpiDarrayVar*>(item);
|
|
|
|
|
delete obj;
|
|
|
|
|
}
|
2014-08-01 02:56:16 +02:00
|
|
|
|
|
|
|
|
void queue_delete(vpiHandle item)
|
|
|
|
|
{
|
|
|
|
|
class __vpiQueueVar*obj = dynamic_cast<__vpiQueueVar*>(item);
|
|
|
|
|
delete obj;
|
|
|
|
|
}
|
2012-12-18 20:08:30 +01:00
|
|
|
#endif
|