diff --git a/vvp/vthread.cc b/vvp/vthread.cc index a84800e27..e0f5e79ab 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -5825,15 +5825,57 @@ bool of_SPLIT_VEC4(vthread_t thr, vvp_code_t cp) } /* - * %store/dar/real + * The following are used to allow the darray templates to print correctly. */ -bool of_STORE_DAR_R(vthread_t thr, vvp_code_t cp) +inline static string get_darray_type(double&) +{ + return "darray"; +} + +inline static string get_darray_type(string&) +{ + return "darray"; +} + +inline static string get_darray_type(vvp_vector4_t value) +{ + ostringstream buf; + buf << "darray"; + string res = buf.str(); + return res; +} + +/* + * The following are used to allow a common template to be written for + * darray real/string/vec4 operations + */ +inline static void dar_pop_value(vthread_t thr, double&value) +{ + value = thr->pop_real(); +} + +inline static void dar_pop_value(vthread_t thr, string&value) +{ + value = thr->pop_str(); +} + +inline static void dar_pop_value(vthread_t thr, vvp_vector4_t&value) +{ + value = thr->pop_vec4(); +} + +template +static bool store_dar(vthread_t thr, vvp_code_t cp) { int64_t adr = thr->words[3].w_int; - double value = thr->pop_real(); // Pop the real value to store... - vvp_net_t*net = cp->net; + ELEM value; + // FIXME: Can we get the size of the underlying array element + // and use the normal pop_value? + dar_pop_value(thr, value); + vvp_net_t*net = cp->net; assert(net); + vvp_fun_signal_object*obj = dynamic_cast (net->fun); assert(obj); @@ -5841,53 +5883,36 @@ bool of_STORE_DAR_R(vthread_t thr, vvp_code_t cp) if (adr < 0) cerr << thr->get_fileline() - << "Warning: cannot write to a negative array index (" - << adr << ")." << endl; + << "Warning: cannot write to a negative " << get_darray_type(value) + << " index (" << adr << ")." << endl; else if (thr->flags[4] != BIT4_0) cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array index." - << endl; + << "Warning: cannot write to an undefined " << get_darray_type(value) + << " index." << endl; else if (darray) darray->set_word(adr, value); else cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array." - << endl; + << "Warning: cannot write to an undefined " << get_darray_type(value) + << "." << endl; return true; } +/* + * %store/dar/real + */ +bool of_STORE_DAR_R(vthread_t thr, vvp_code_t cp) +{ + return store_dar(thr, cp); +} + /* * %store/dar/str */ bool of_STORE_DAR_STR(vthread_t thr, vvp_code_t cp) { - int64_t adr = thr->words[3].w_int; - string value = thr->pop_str(); // Pop the string to be stored... - vvp_net_t*net = cp->net; - - assert(net); - vvp_fun_signal_object*obj = dynamic_cast (net->fun); - assert(obj); - - vvp_darray*darray = obj->get_object().peek(); - - if (adr < 0) - cerr << thr->get_fileline() - << "Warning: cannot write to a negative array index (" - << adr << ")." << endl; - else if (thr->flags[4] != BIT4_0) - cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array index." - << endl; - else if (darray) - darray->set_word(adr, value); - else - cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array." - << endl; - - return true; + return store_dar(thr, cp); } /* @@ -5895,32 +5920,7 @@ bool of_STORE_DAR_STR(vthread_t thr, vvp_code_t cp) */ bool of_STORE_DAR_VEC4(vthread_t thr, vvp_code_t cp) { - int64_t adr = thr->words[3].w_int; - vvp_vector4_t value = thr->pop_vec4(); // Pop the vector4 value to be store... - vvp_net_t*net = cp->net; - - assert(net); - vvp_fun_signal_object*obj = dynamic_cast (net->fun); - assert(obj); - - vvp_darray*darray = obj->get_object().peek(); - - if (adr < 0) - cerr << thr->get_fileline() - << "Warning: cannot write to a negative array index (" << adr << ")." << endl; - else if (thr->flags[4] != BIT4_0) - cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array index." << endl; - else if (darray) - darray->set_word(adr, value); - else - cerr << thr->get_fileline() - << "Warning: cannot write to an undefined array." << endl; - - return true; + return store_dar(thr, cp); } bool of_STORE_OBJ(vthread_t thr, vvp_code_t cp)