From 637d43fb5a9557653ca239a8d8aa7fc4fa2da6b1 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 24 Jun 2013 08:29:28 -0400 Subject: [PATCH] Add support for logic vector properties in classes. This is similar to but not the same as bit(bool) vector properties in classes. --- tgt-vvp/stmt_assign.c | 18 ++++++++++++++++- vvp/class_type.cc | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/tgt-vvp/stmt_assign.c b/tgt-vvp/stmt_assign.c index e98ec1d1f..c4eadd1b6 100644 --- a/tgt-vvp/stmt_assign.c +++ b/tgt-vvp/stmt_assign.c @@ -872,7 +872,23 @@ static int show_stmt_assign_sig_cobject(ivl_statement_t net) struct vector_info val = draw_eval_expr_wid(rval, wid, STUFF_OK_XZ); fprintf(vvp_out, " %%load/obj v%p_0;\n", sig); - fprintf(vvp_out, " %%store/prop/v %d, %u, %u;\n", prop_idx, val.base, val.wid); + fprintf(vvp_out, " %%store/prop/v %d, %u, %u; Store in bool property %s\n", + prop_idx, val.base, val.wid, + ivl_type_prop_name(sig_type, prop_idx)); + fprintf(vvp_out, " %%pop/obj 1;\n"); + clr_vector(val); + + } else if (ivl_type_base(prop_type) == IVL_VT_LOGIC) { + assert(ivl_type_packed_dimensions(prop_type) == 1); + assert(ivl_type_packed_msb(prop_type,0) >= ivl_type_packed_lsb(prop_type, 0)); + int wid = ivl_type_packed_msb(prop_type,0) - ivl_type_packed_lsb(prop_type,0) + 1; + + struct vector_info val = draw_eval_expr_wid(rval, wid, STUFF_OK_XZ); + + fprintf(vvp_out, " %%load/obj v%p_0;\n", sig); + fprintf(vvp_out, " %%store/prop/v %d, %u, %u; Store in logic property %s\n", + prop_idx, val.base, val.wid, + ivl_type_prop_name(sig_type, prop_idx)); fprintf(vvp_out, " %%pop/obj 1;\n"); clr_vector(val); diff --git a/vvp/class_type.cc b/vvp/class_type.cc index 8f61c50da..38768aa03 100644 --- a/vvp/class_type.cc +++ b/vvp/class_type.cc @@ -166,6 +166,31 @@ class property_bit : public class_property_t { size_t wid_; }; +class property_logic : public class_property_t { + public: + inline property_logic(size_t wid): wid_(wid) { } + ~property_logic() { } + + size_t instance_size() const { return sizeof(vvp_vector4_t); } + + public: + void construct(char*buf) const + { new (buf+offset_) vvp_vector4_t (0, wid_); } + + void destruct(char*buf) const + { vvp_vector4_t*tmp = reinterpret_cast(buf+offset_); + tmp->~vvp_vector4_t(); + } + + void set_vec4(char*buf, const vvp_vector4_t&val); + void get_vec4(char*buf, vvp_vector4_t&val); + + void copy(char*dst, char*src); + + private: + size_t wid_; +}; + template class property_real : public class_property_t { public: inline explicit property_real(void) { } @@ -278,6 +303,25 @@ void property_bit::copy(char*dst, char*src) *dst_obj = *src_obj; } +void property_logic::set_vec4(char*buf, const vvp_vector4_t&val) +{ + vvp_vector4_t*obj = reinterpret_cast (buf+offset_); + *obj = val; +} + +void property_logic::get_vec4(char*buf, vvp_vector4_t&val) +{ + vvp_vector4_t*obj = reinterpret_cast (buf+offset_); + val = *obj; +} + +void property_logic::copy(char*dst, char*src) +{ + vvp_vector4_t*dst_obj = reinterpret_cast (dst+offset_); + vvp_vector4_t*src_obj = reinterpret_cast (src+offset_); + *dst_obj = *src_obj; +} + template void property_real::set_real(char*buf, double val) { T*tmp = reinterpret_cast(buf+offset_); @@ -373,6 +417,9 @@ void class_type::set_property(size_t idx, const string&name, const string&type) else if (type[0] == 'b') { size_t wid = strtoul(type.c_str()+1, 0, 0); properties_[idx].type = new property_bit(wid); + } else if (type[0] == 'L') { + size_t wid = strtoul(type.c_str()+1,0,0); + properties_[idx].type = new property_logic(wid); } else { properties_[idx].type = 0; }