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.
This commit is contained in:
Stephen Williams 2013-06-20 17:26:16 -04:00
parent 75b4b94061
commit fbc5557a10
2 changed files with 50 additions and 2 deletions

View File

@ -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;
}

View File

@ -141,6 +141,31 @@ template <class T> 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<vvp_vector2_t*>(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 T> class property_real : public class_property_t {
public:
inline explicit property_real(void) { }
@ -234,6 +259,25 @@ template <class T> void property_atom<T>::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<vvp_vector2_t*> (buf+offset_);
*obj = val;
}
void property_bit::get_vec4(char*buf, vvp_vector4_t&val)
{
vvp_vector2_t*obj = reinterpret_cast<vvp_vector2_t*> (buf+offset_);
val = vector2_to_vector4(*obj, obj->size());
}
void property_bit::copy(char*dst, char*src)
{
vvp_vector2_t*dst_obj = reinterpret_cast<vvp_vector2_t*> (dst+offset_);
vvp_vector2_t*src_obj = reinterpret_cast<vvp_vector2_t*> (src+offset_);
*dst_obj = *src_obj;
}
template <class T> void property_real<T>::set_real(char*buf, double val)
{
T*tmp = reinterpret_cast<T*>(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)