Add push front for string queues and improve some warning messages

This commit is contained in:
Cary R 2020-07-19 19:17:18 -07:00
parent 83c86735bb
commit bf6c4329b9
3 changed files with 36 additions and 11 deletions

View File

@ -5761,9 +5761,17 @@ bool of_STORE_QF_R(vthread_t, vvp_code_t)
/* /*
* %store/qf/str <var-label>, <max-idx> * %store/qf/str <var-label>, <max-idx>
*/ */
bool of_STORE_QF_STR(vthread_t, vvp_code_t) bool of_STORE_QF_STR(vthread_t thr, vvp_code_t cp)
{ {
fprintf(stderr, "XXXX %%store/qf/str NOT IMPLEMENTED\n"); // Pop the string to be stored...
string value = thr->pop_str();
vvp_net_t*net = cp->net;
unsigned max_size = thr->words[cp->bit_idx[0]].w_int;
vvp_queue*dqueue = get_queue_object<vvp_queue_string>(thr, net);
assert(dqueue);
dqueue->push_front(value, max_size);
return true; return true;
} }

View File

@ -449,12 +449,6 @@ size_t vvp_queue_string::get_size() const
return array_.size(); return array_.size();
} }
void vvp_queue_string::push_back(const string&val, unsigned max_size)
{
if (!max_size || (array_.size() < max_size)) array_.push_back(val);
else cerr << "Warning: value \"" << val << "\" was not added to queue." << endl;
}
void vvp_queue_string::set_word(unsigned adr, const string&value) void vvp_queue_string::set_word(unsigned adr, const string&value)
{ {
if (adr >= array_.size()) if (adr >= array_.size())
@ -485,6 +479,25 @@ void vvp_queue_string::get_word(unsigned adr, string&value)
value = *cur; value = *cur;
} }
void vvp_queue_string::push_back(const string&val, unsigned max_size)
{
if (!max_size || (array_.size() < max_size)) array_.push_back(val);
else cerr << "Warning: value \"" << val
<< "\" was not added to the end of already full sized ("
<< max_size << ") queue." << endl;
}
void vvp_queue_string::push_front(const string&val, unsigned max_size)
{
if (max_size && (array_.size() == max_size)) {
cerr << "Warning: value \"" << array_.back()
<< "\" was removed from already full sized ("
<< max_size << ") queue." << endl;
array_.pop_back();
}
array_.push_front(val);
}
void vvp_queue_string::pop_back(void) void vvp_queue_string::pop_back(void)
{ {
array_.pop_back(); array_.pop_back();
@ -537,13 +550,17 @@ void vvp_queue_vec4::get_word(unsigned adr, vvp_vector4_t&value)
void vvp_queue_vec4::push_back(const vvp_vector4_t&val, unsigned max_size) void vvp_queue_vec4::push_back(const vvp_vector4_t&val, unsigned max_size)
{ {
if (!max_size || (array_.size() < max_size)) array_.push_back(val); if (!max_size || (array_.size() < max_size)) array_.push_back(val);
else cerr << "Warning: value " << val << " was not added to queue." << endl; else cerr << "Warning: value " << val
<< " was not added to the end of already full sized ("
<< max_size << ") queue." << endl;
} }
void vvp_queue_vec4::push_front(const vvp_vector4_t&val, unsigned max_size) void vvp_queue_vec4::push_front(const vvp_vector4_t&val, unsigned max_size)
{ {
if (max_size && (array_.size() == max_size)) { if (max_size && (array_.size() == max_size)) {
cerr << "Warning: value " << array_.back() << " was removed from queue." << endl; cerr << "Warning: value " << array_.back()
<< " was removed from already full sized ("
<< max_size << ") queue." << endl;
array_.pop_back(); array_.pop_back();
} }
array_.push_front(val); array_.push_front(val);

View File

@ -194,7 +194,7 @@ class vvp_queue_string : public vvp_queue {
void set_word(unsigned adr, const std::string&value); void set_word(unsigned adr, const std::string&value);
void get_word(unsigned adr, std::string&value); void get_word(unsigned adr, std::string&value);
void push_back(const std::string&value, unsigned max_size); void push_back(const std::string&value, unsigned max_size);
//void push_front(const std::string&value, unsigned max_size); void push_front(const std::string&value, unsigned max_size);
void pop_back(void); void pop_back(void);
void pop_front(void); void pop_front(void);