1

I am working on a small project in SystemC and got stocked in filling a sc_lv (logic vector) with values from a sc_logic. So:

#include <systemc.h>
#include "fullAdder.h"

SC_MODULE(eightBitAdder)
{
    public:
    fullAdder *fullAdder_p;

    //define I/O
    sc_in  < bool >      clk;
    sc_in  < sc_lv <8> > A;
    sc_in  < sc_lv <8> > B;
    sc_out < sc_lv <8> > SUM;
    sc_out < sc_logic >    C_out;

    // define internal signals
    sc_signal < sc_logic > fa_A, fa_B, fa_SUM, fa_C_out, fa_C_in;
    sc_signal < sc_lv <8> > SUM_temp;


    SC_CTOR(eightBitAdder)
    {
        fullAdder_p = new fullAdder("FullAdder");

        fullAdder_p -> fa_A(fa_A);
        fullAdder_p -> fa_B(fa_B);
        fullAdder_p -> fa_C_in(fa_C_in);
        fullAdder_p -> fa_SUM(fa_SUM);
        fullAdder_p -> fa_C_out(fa_C_out);

        SC_CTHREAD(eightBitAdderFunc, clk.pos());
        //sensitive << A << B << SUM << C_out;
    }

    private:
    void eightBitAdderFunc()
    {
        fa_C_in = SC_LOGIC_0;

        for (int i = 1; i <= 8; i++)
        {
            fa_A.write(A.read()[i]);
            fa_B.write(B.read()[i]);
            wait();
            SUM_temp[i] = fa_SUM; //hier is the problem
            C_out = fa_C_out;
            fa_C_in = fa_C_out;
            wait();
        }
        SUM.write(SUM_temp);
    };
};

Error message:

eightBitAdder.h:55:14: error: no match for ‘operator[]’ in ‘((eightBitAdder*)this)->eightBitAdder::SUM_temp[i]’

I tried several methods to assign fa_SUM-bits to the SUM-vectors and alway get the same error. For example:

SUM_temp[i] = fa_SUM.read();

SUM_temp[i].write(fa_SUM);

SUM_temp[i].write(fa_SUM.read());
ArcaGraphy
  • 53
  • 3
  • 11

1 Answers1

2

That errror is because you are trying to access the [] operators of an object of type sc_signal and not of an object of type sc_lv. Only the latter supports [] operators. (See also page 139 and page 261-262 of IEEE 1666-2011 for class definitions of sc_signal and sc_bv.)

As far as I'm concerned, you are using SUM_temp only as an internal temporary variable. So it shouldn't be necessary to make it a signal. The code below worked for me.

//old: sc_signal < sc_lv <8> > SUM_temp;
sc_lv<8> SUM_temp


//old: SUM_temp[i] = fa_SUM; // this is the problem
SUM_temp[i] = fa_SUM.read();
Silicon1602
  • 1,151
  • 1
  • 7
  • 18