Report when the array pattern is larger than the maximum queue size

This commit is contained in:
Cary R 2020-08-02 23:34:52 -07:00
parent 83db691586
commit 199ed39abe
6 changed files with 68 additions and 2 deletions

View File

@ -1055,8 +1055,19 @@ static int show_stmt_assign_queue_pattern(ivl_signal_t var, ivl_expr_t rval,
{
int errors = 0;
unsigned idx;
unsigned max_size;
unsigned max_elems;
assert(ivl_expr_type(rval) == IVL_EX_ARRAY_PATTERN);
for (idx = 0 ; idx < ivl_expr_parms(rval) ; idx += 1) {
max_size = ivl_signal_array_count(var);
max_elems = ivl_expr_parms(rval);
if ((max_size != 0) && (max_elems > max_size)) {
fprintf(stderr, "Warning: Array pattern assignment has more elements "
"(%u) than bounded queue '%s' supports (%u).\n"
" Only using first %u elements.\n",
max_elems, ivl_signal_basename(var), max_size, max_size);
max_elems = max_size;
}
for (idx = 0 ; idx < max_elems ; idx += 1) {
switch (ivl_type_base(element_type)) {
case IVL_VT_BOOL:
case IVL_VT_LOGIC:
@ -1086,6 +1097,15 @@ static int show_stmt_assign_queue_pattern(ivl_signal_t var, ivl_expr_t rval,
}
}
if ((max_size == 0) || (max_elems < max_size)) {
int del_idx = allocate_word();
assert(del_idx >= 0);
/* Save the first queue element to delete. */
fprintf(vvp_out, " %%ix/load %u, %u, 0;\n", del_idx, max_elems);
fprintf(vvp_out, " %%delete/tail v%p_0, %u;\n", var, del_idx);
clr_word(del_idx);
}
return errors;
}
@ -1139,7 +1159,6 @@ static int show_stmt_assign_sig_queue(ivl_statement_t net)
/* There is no l-value mux, but the r-value is an array
pattern. This is a special case of an assignment to
elements of the l-value. */
fprintf(vvp_out, " %%delete/obj v%p_0;\n", var);
errors += show_stmt_assign_queue_pattern(var, rval, element_type, idx);
} else {
fprintf(stderr, "Sorry: I don't know how to handle expr_type=%d "

View File

@ -101,6 +101,7 @@ extern bool of_DELAY(vthread_t thr, vvp_code_t code);
extern bool of_DELAYX(vthread_t thr, vvp_code_t code);
extern bool of_DELETE_ELEM(vthread_t thr, vvp_code_t code);
extern bool of_DELETE_OBJ(vthread_t thr, vvp_code_t code);
extern bool of_DELETE_TAIL(vthread_t thr, vvp_code_t code);
extern bool of_DISABLE(vthread_t thr, vvp_code_t code);
extern bool of_DISABLE_FORK(vthread_t thr, vvp_code_t code);
extern bool of_DIV(vthread_t thr, vvp_code_t code);

View File

@ -153,6 +153,7 @@ static const struct opcode_table_s opcode_table[] = {
{ "%delayx", of_DELAYX, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
{ "%delete/elem",of_DELETE_ELEM,1,{OA_FUNC_PTR,OA_NONE,OA_NONE} },
{ "%delete/obj",of_DELETE_OBJ,1,{OA_FUNC_PTR,OA_NONE, OA_NONE} },
{ "%delete/tail",of_DELETE_TAIL,2,{OA_FUNC_PTR,OA_BIT1,OA_NONE} },
{ "%disable", of_DISABLE, 1, {OA_VPI_PTR,OA_NONE, OA_NONE} },
{ "%disable/fork",of_DISABLE_FORK,0,{OA_NONE,OA_NONE, OA_NONE} },
{ "%div", of_DIV, 0, {OA_NONE, OA_NONE, OA_NONE} },

View File

@ -2468,6 +2468,26 @@ bool of_DELETE_OBJ(vthread_t thr, vvp_code_t cp)
return true;
}
/* %delete/tail <label>, idx
*
* Remove all elements after the one specified.
*/
bool of_DELETE_TAIL(vthread_t thr, vvp_code_t cp)
{
vvp_net_t*net = cp->net;
vvp_fun_signal_object*obj = dynamic_cast<vvp_fun_signal_object*> (net->fun);
assert(obj);
vvp_queue*dqueue = obj->get_object().peek<vvp_queue>();
assert(dqueue);
unsigned idx = thr->words[cp->bit_idx[0]].w_int;
dqueue->erase_tail(idx);
return true;
}
static bool do_disable(vthread_t thr, vthread_t match)
{
bool flag = false;

View File

@ -582,6 +582,13 @@ void vvp_queue_real::erase(unsigned idx)
queue.erase(pos);
}
void vvp_queue_real::erase_tail(unsigned idx)
{
assert(queue.size() >= idx);
if (queue.size() > idx)
queue.resize(idx);
}
vvp_queue_string::~vvp_queue_string()
{
}
@ -694,6 +701,13 @@ void vvp_queue_string::erase(unsigned idx)
queue.erase(pos);
}
void vvp_queue_string::erase_tail(unsigned idx)
{
assert(queue.size() >= idx);
if (queue.size() > idx)
queue.resize(idx);
}
vvp_queue_vec4::~vvp_queue_vec4()
{
}
@ -805,3 +819,10 @@ void vvp_queue_vec4::erase(unsigned idx)
queue.erase(pos);
}
void vvp_queue_vec4::erase_tail(unsigned idx)
{
assert(queue.size() >= idx);
if (queue.size() > idx)
queue.resize(idx);
}

View File

@ -172,6 +172,7 @@ class vvp_queue : public vvp_darray {
virtual void pop_back(void) =0;
virtual void pop_front(void)=0;
virtual void erase(unsigned idx)=0;
virtual void erase_tail(unsigned idx)=0;
};
class vvp_queue_real : public vvp_queue {
@ -189,6 +190,7 @@ class vvp_queue_real : public vvp_queue {
void pop_back(void) { queue.pop_back(); };
void pop_front(void) { queue.pop_front(); };
void erase(unsigned idx);
void erase_tail(unsigned idx);
private:
std::deque<double> queue;
@ -209,6 +211,7 @@ class vvp_queue_string : public vvp_queue {
void pop_back(void) { queue.pop_back(); };
void pop_front(void) { queue.pop_front(); };
void erase(unsigned idx);
void erase_tail(unsigned idx);
private:
std::deque<std::string> queue;
@ -229,6 +232,7 @@ class vvp_queue_vec4 : public vvp_queue {
void pop_back(void) { queue.pop_back(); };
void pop_front(void) { queue.pop_front(); };
void erase(unsigned idx);
void erase_tail(unsigned idx);
private:
std::deque<vvp_vector4_t> queue;