Implement the size method for queues.
This works by translating it to a $size() system function call. The $size function is already implemented for dynamic queues and it is easy enough to expand it for queues.
This commit is contained in:
parent
a730572e37
commit
da63ef02d4
|
|
@ -2318,7 +2318,7 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
if (net->darray_type()) {
|
||||
|
||||
if (method_name == "size") {
|
||||
NetESFunc*sys_expr = new NetESFunc("$ivl_darray_method$size",
|
||||
NetESFunc*sys_expr = new NetESFunc("$size",
|
||||
IVL_VT_BOOL, 32, 1);
|
||||
sys_expr->parm(0, new NetESignal(net));
|
||||
sys_expr->set_line(*this);
|
||||
|
|
@ -2812,7 +2812,7 @@ unsigned PEIdent::test_width_method_(Design*des, NetScope*scope, width_mode_t&mo
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (const netdarray_t*dtype = net->darray_type()) {
|
||||
if (/*const netdarray_t*dtype =*/ net->darray_type()) {
|
||||
if (member_name == "size") {
|
||||
expr_type_ = IVL_VT_BOOL;
|
||||
expr_width_ = 32;
|
||||
|
|
@ -3246,8 +3246,7 @@ NetExpr* PEIdent::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
|
||||
if (const netdarray_t*dtype = net->darray_type()) {
|
||||
if (member_name == "size") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$size",
|
||||
expr_type_, expr_width_, 1);
|
||||
NetESFunc*fun = new NetESFunc("$size", IVL_VT_BOOL, 32, 1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(net);
|
||||
|
|
|
|||
|
|
@ -2016,6 +2016,7 @@ static bool get_array_info(const NetExpr*arg, long dim,
|
|||
/* A string or dynamic array must be handled by the run time. */
|
||||
switch (sig->data_type()) {
|
||||
case IVL_VT_DARRAY:
|
||||
case IVL_VT_QUEUE:
|
||||
case IVL_VT_STRING:
|
||||
defer = true;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -83,11 +83,11 @@ void sys_darray_register(void)
|
|||
|
||||
tf_data.type = vpiSysFunc;
|
||||
tf_data.sysfunctype = vpiIntFunc;
|
||||
tf_data.tfname = "$ivl_darray_method$size";
|
||||
tf_data.tfname = "$size";
|
||||
tf_data.calltf = size_calltf;
|
||||
tf_data.compiletf = one_darray_arg_compiletf;
|
||||
tf_data.sizetf = 0;
|
||||
tf_data.user_data = "$ivl_darray_method$size";
|
||||
tf_data.user_data = "$size";
|
||||
res = vpi_register_systf(&tf_data);
|
||||
vpip_make_systf_system_defined(res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,4 @@ void v2009_array_register(void)
|
|||
tf_data.user_data = "$increment";
|
||||
res = vpi_register_systf(&tf_data);
|
||||
vpip_make_systf_system_defined(res);
|
||||
|
||||
tf_data.tfname = "$size";
|
||||
tf_data.user_data = "$size";
|
||||
res = vpi_register_systf(&tf_data);
|
||||
vpip_make_systf_system_defined(res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ 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();
|
||||
vvp_darray*aval = val.peek<vvp_darray>();
|
||||
vvp_queue*aval = val.peek<vvp_queue>();
|
||||
|
||||
switch (code) {
|
||||
case vpiArrayType:
|
||||
|
|
|
|||
|
|
@ -4272,7 +4272,8 @@ bool of_NEW_DARRAY(vthread_t thr, vvp_code_t cp)
|
|||
} else if (strcmp(text,"S") == 0) {
|
||||
obj = new vvp_darray_string(size);
|
||||
} else {
|
||||
obj = new vvp_darray (size);
|
||||
// XXXX This should not happen.
|
||||
obj = new vvp_darray_atom<uint8_t> (size);
|
||||
}
|
||||
|
||||
thr->push_object(obj);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ template <class TYPE> vvp_darray_atom<TYPE>::~vvp_darray_atom()
|
|||
{
|
||||
}
|
||||
|
||||
template <class TYPE> size_t vvp_darray_atom<TYPE>::get_size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
template <class TYPE> void vvp_darray_atom<TYPE>::set_word(unsigned adr, const vvp_vector4_t&value)
|
||||
{
|
||||
if (adr >= array_.size())
|
||||
|
|
@ -100,6 +105,11 @@ vvp_darray_real::~vvp_darray_real()
|
|||
{
|
||||
}
|
||||
|
||||
size_t vvp_darray_real::get_size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
void vvp_darray_real::set_word(unsigned adr, double value)
|
||||
{
|
||||
if (adr >= array_.size())
|
||||
|
|
@ -121,6 +131,11 @@ vvp_darray_string::~vvp_darray_string()
|
|||
{
|
||||
}
|
||||
|
||||
size_t vvp_darray_string::get_size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
void vvp_darray_string::set_word(unsigned adr, const string&value)
|
||||
{
|
||||
if (adr >= array_.size())
|
||||
|
|
@ -176,6 +191,11 @@ vvp_queue_string::~vvp_queue_string()
|
|||
{
|
||||
}
|
||||
|
||||
size_t vvp_queue_string::get_size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
void vvp_queue_string::push_back(const string&val)
|
||||
{
|
||||
array_.push_back(val);
|
||||
|
|
@ -185,6 +205,11 @@ vvp_queue_vec4::~vvp_queue_vec4()
|
|||
{
|
||||
}
|
||||
|
||||
size_t vvp_queue_vec4::get_size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
void vvp_queue_vec4::push_back(const vvp_vector4_t&val)
|
||||
{
|
||||
array_.push_back(val);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ class vvp_vector4_t;
|
|||
class vvp_darray : public vvp_object {
|
||||
|
||||
public:
|
||||
inline vvp_darray(size_t siz) : size_(siz) { }
|
||||
inline vvp_darray() { }
|
||||
virtual ~vvp_darray();
|
||||
|
||||
inline size_t get_size(void) const { return size_; }
|
||||
virtual size_t get_size(void) const =0;
|
||||
|
||||
virtual void set_word(unsigned adr, const vvp_vector4_t&value);
|
||||
virtual void get_word(unsigned adr, vvp_vector4_t&value);
|
||||
|
|
@ -42,17 +42,15 @@ class vvp_darray : public vvp_object {
|
|||
|
||||
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) { }
|
||||
inline vvp_darray_atom(size_t siz) : array_(siz) { }
|
||||
~vvp_darray_atom();
|
||||
|
||||
size_t get_size(void) const;
|
||||
void set_word(unsigned adr, const vvp_vector4_t&value);
|
||||
void get_word(unsigned adr, vvp_vector4_t&value);
|
||||
|
||||
|
|
@ -63,9 +61,10 @@ template <class TYPE> class vvp_darray_atom : public vvp_darray {
|
|||
class vvp_darray_real : public vvp_darray {
|
||||
|
||||
public:
|
||||
inline vvp_darray_real(size_t siz) : vvp_darray(siz), array_(siz) { }
|
||||
inline vvp_darray_real(size_t siz) : array_(siz) { }
|
||||
~vvp_darray_real();
|
||||
|
||||
size_t get_size(void) const;
|
||||
void set_word(unsigned adr, double value);
|
||||
void get_word(unsigned adr, double&value);
|
||||
|
||||
|
|
@ -76,9 +75,10 @@ class vvp_darray_real : public vvp_darray {
|
|||
class vvp_darray_string : public vvp_darray {
|
||||
|
||||
public:
|
||||
inline vvp_darray_string(size_t siz) : vvp_darray(siz), array_(siz) { }
|
||||
inline vvp_darray_string(size_t siz) : array_(siz) { }
|
||||
~vvp_darray_string();
|
||||
|
||||
size_t get_size(void) const;
|
||||
void set_word(unsigned adr, const std::string&value);
|
||||
void get_word(unsigned adr, std::string&value);
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ class vvp_darray_string : public vvp_darray {
|
|||
class vvp_queue : public vvp_darray {
|
||||
|
||||
public:
|
||||
inline vvp_queue(void) : vvp_darray(0) { }
|
||||
inline vvp_queue(void) { }
|
||||
~vvp_queue();
|
||||
|
||||
virtual void push_back(const vvp_vector4_t&value);
|
||||
|
|
@ -108,6 +108,7 @@ class vvp_queue_vec4 : public vvp_queue {
|
|||
public:
|
||||
~vvp_queue_vec4();
|
||||
|
||||
size_t get_size(void) const;
|
||||
void push_back(const vvp_vector4_t&value);
|
||||
void push_front(const vvp_vector4_t&value);
|
||||
|
||||
|
|
@ -121,6 +122,7 @@ class vvp_queue_string : public vvp_queue {
|
|||
public:
|
||||
~vvp_queue_string();
|
||||
|
||||
size_t get_size(void) const;
|
||||
//void set_word(unsigned adr, const std::string&value);
|
||||
//void get_word(unsigned adr, std::string&value);
|
||||
void push_back(const std::string&value);
|
||||
|
|
|
|||
Loading…
Reference in New Issue