From fbc5557a10dff9d4fc851ee25962c2898640dbaa Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 20 Jun 2013 17:26:16 -0400 Subject: [PATCH] Handle properties that have arbitrary bit widths. This fixes the run time handling of arbitrary width bit vectors as class properties. The vvp code generator already did the right things. --- parse.y | 2 +- vvp/class_type.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index f436f28b5..f0bcbaa1b 100644 --- a/parse.y +++ b/parse.y @@ -769,7 +769,7 @@ class_item /* IEEE1800-2005: A.1.8 */ { current_function->set_ports($6); pform_set_constructor_return(current_function); pform_set_this_class(@3, current_function); - current_function_set_statement($10? @10 : @3, $10); + current_function_set_statement(@3, $10); pform_pop_scope(); current_function = 0; } diff --git a/vvp/class_type.cc b/vvp/class_type.cc index 5b6791eb0..8f61c50da 100644 --- a/vvp/class_type.cc +++ b/vvp/class_type.cc @@ -141,6 +141,31 @@ template class property_atom : public class_property_t { void copy(char*dst, char*src); }; +class property_bit : public class_property_t { + public: + inline property_bit(size_t wid): wid_(wid) { } + ~property_bit() { } + + size_t instance_size() const { return sizeof(vvp_vector2_t); } + + public: + void construct(char*buf) const + { new (buf+offset_) vvp_vector2_t (0, wid_); } + + void destruct(char*buf) const + { vvp_vector2_t*tmp = reinterpret_cast(buf+offset_); + tmp->~vvp_vector2_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) { } @@ -234,6 +259,25 @@ template void property_atom::copy(char*dst, char*src) *dst_obj = *src_obj; } +void property_bit::set_vec4(char*buf, const vvp_vector4_t&val) +{ + vvp_vector2_t*obj = reinterpret_cast (buf+offset_); + *obj = val; +} + +void property_bit::get_vec4(char*buf, vvp_vector4_t&val) +{ + vvp_vector2_t*obj = reinterpret_cast (buf+offset_); + val = vector2_to_vector4(*obj, obj->size()); +} + +void property_bit::copy(char*dst, char*src) +{ + vvp_vector2_t*dst_obj = reinterpret_cast (dst+offset_); + vvp_vector2_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_); @@ -326,8 +370,12 @@ void class_type::set_property(size_t idx, const string&name, const string&type) properties_[idx].type = new property_string; else if (type == "o") properties_[idx].type = new property_object; - else + else if (type[0] == 'b') { + size_t wid = strtoul(type.c_str()+1, 0, 0); + properties_[idx].type = new property_bit(wid); + } else { properties_[idx].type = 0; + } } void class_type::finish_setup(void)