Jump to content

Using sc_vector. Error deleting object of polymorphic class type


Andy Tomlin
 Share

Recommended Posts

I am trying to replace array of objects with the sc_vector as it seems like a better solution to the problem after some research

/home/tools/libraries/systemc-2.3.3/include/sysc/utils/sc_vector.h: In instantiation of ‘void sc_core::sc_vector<T>::clear() [with T = mm_ready_valid_in<busy_st>]’:
/home/tools/libraries/systemc-2.3.3/include/sysc/utils/sc_vector.h:749:3:   required from ‘sc_core::sc_vector<T>::~sc_vector() [with T = mm_ready_valid_in<busy_st>]’
./xxx.h:171:74:   required from here
/home/tools/libraries/systemc-2.3.3/include/sysc/utils/sc_vector.h:707:5: error: deleting object of polymorphic class type ‘mm_ready_valid_in<busy_st>’ which has non-virtual destructor might cause undefined behavior [-Werror=delete-non-virtual-dtor]
  707 |     delete &( (*this)[i] );
      |     ^~~~~~
/

We have some classes we have created which we are using to instantiate our architecture for modelling. 

busy_st, and busy_t is simple classes which we generate. These are used then as input to our interface templates. The template class creates all the interface signaling etc to implement the ready busy. When I try and convert this to a sc_vector

sc_vector<mm_ready_valid_in<busy_st>> I get this error. I'm kind of stuck, can anyone help?

 

struct busy_t : public sc_uint<1> {
  using sc_uint<1>::sc_uint;
  std::string prt() const {
  switch (m_val) {
    case 0x0: return("BUSY_NOT");
    case 0x1: return("BUSY");
    };
  return("BADVAL");};
}; // 0 = Not Busy, 1 = Busy
struct busy_t : public sc_uint<1> {
  using sc_uint<1>::sc_uint;
  std::string prt() const {
  switch (m_val) {
    case 0x0: return("BUSY_NOT");
    case 0x1: return("BUSY");
    };
  return("BADVAL");};
}; // 0 = Not Busy, 1 = Busy

struct busy_st {

    busy_t busy;                                            // 0 = Not Busy, 1 = Busy

    busy_st()
     
    {
        zero_fields();
        fields[0].pfield = &busy;
        fields[0].pbigfield = NULL;
        fields[0].pos = 0;
        fields[0].bits = 1;
    }

    std::string prt() const
    {
        std::string s;
        s += "busy:" + busy.prt();
        return(s);
    }

    void zero_fields()
    {
        busy = 0;
    }

    bool is_all_zeros() const
    {
        bool ret = true;
        ret = ret && (busy == 0);
        return ret;
    }

    static const unsigned int field_count = 1;             // field count
    static const unsigned int bit_count = 1;                // bit count (all fields)
    FIELD_ATTR fields[field_count];

    inline bool operator == (const busy_st& r) const {
        return (busy == r.busy);
    }

    inline busy_st& operator = (const busy_st& r) {
        busy = r.busy;
        return *this;
    }

    inline busy_st& make_copy (const busy_st& r) {
        busy = r.busy;
        return *this;
    }

    inline friend void sc_trace(sc_trace_file* ptf, const busy_st& v, const std::string& NAME)
    {
        if (v.fields[0].pfield) {
            sc_trace(ptf, *v.fields[0].pfield, "busy");
        } else {
            sc_trace(ptf, *v.fields[0].pbigfield, "busy");
        }
    }

    inline friend ostream& operator << (ostream& os, busy_st const & v)
    {
        if (v.fields[0].pfield) {
            os << "busy: " << v.fields[0].pfield << endl;
        } else {
            os << "busy: " << v.fields[0].pbigfield << endl;
        }
        return os;
    }
};
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...