accellera-official / systemc

SystemC Reference Implementation
https://systemc.org/overview/systemc/
Apache License 2.0
445 stars 141 forks source link

std::array and sc_core::sc_fifo #58

Open adrian-yehe opened 10 months ago

adrian-yehe commented 10 months ago

"Define a group of FIFOs, std::array<sc_core::sc_fifo, 6> mCmdFifo.", Unable to change FIFO init, So I suggest adding methods to set FIFO depth and name to sc_fifo class;

pah commented 6 months ago

Calling the default constructor of SystemC objects is not recommended, as you lack a meaningful name for the objects. I would recommend to use sc_vector instead of std::array:

sc_core::sc_vector<sc_core::sc_fifo<uint64_t> SC_NAMED(mCmdFifo);

SC_CTOR(...) {
  int fifo_size = 5;
  mCmdFifo.init(6, [=](const char* name, size_t) { return new sc_core::sc_fifo<uint64_t>(name, fifo_size); }); 
}

Alternatively, you can use the new emplace_back function in IEEE 1666-2023 (aka SystemC 3.0) to construct individual instances explicitly (instead of calling init with a lambda):

  for(int i = 0; i < 6; ++i)
    mCmdFifo.emplace_back(fifo_size); // name will be implicitly passed as first parameter