c++compiler-errorssystemc

SystemC: Multiple module implementations in single cpp file


Edit: Solution found by moving the SC_HAS_PROCESS(Module); statements from the .cpp file into the class definition in the header file.

I am writing a module in SystemC which has small sub-modules. I would like to keep all of the declarations in a single header file, and the implementation on a single .cpp file. I don't think there is anything inherently wrong with this approach, but I am getting an error related to the use of the SC_HAS_PROCESS macro redefining SC_CURRENT_USER_MODULE.

In file included from /.../systemc/2.3.1/include/systemc:72:0,
                 from src/Decoder.cpp:39:
/.../systemc/2.3.1/include/sysc/kernel/sc_module.h:403:30: error: conflicting declaration ‘typedef struct Fifo_shift SC_CURRENT_USER_MODULE’
     typedef user_module_name SC_CURRENT_USER_MODULE
                              ^
src/Decoder.cpp:146:1: note: in expansion of macro ‘SC_HAS_PROCESS’
 SC_HAS_PROCESS(Fifo_shift);
 ^
/.../systemc/2.3.1/include/sysc/kernel/sc_module.h:403:30: error: ‘SC_CURRENT_USER_MODULE’ has a previous declaration as ‘typedef struct Decoder SC_CURRENT_USER_MODULE’
     typedef user_module_name SC_CURRENT_USER_MODULE
                              ^
src/Decoder.cpp:50:1: note: in expansion of macro ‘SC_HAS_PROCESS’
 SC_HAS_PROCESS(Decoder);

The error seems to be from my second use of SC_HAS_PROCESS. The general format of my code is as follows (with portions removed for brevity).

In 'Decoder.h':

SC_MODULE(Fifo_shift)
{
public:
  /* Port declarations */

  /* Variable declarations */

  Fifo_shift(sc_module_name nm, int chunk_size_in);
  ~Fifo_shift();

  /* Member functions */
private:
  /* Private variables */
};

/* Other modules */

SC_MODULE(Decoder)
{
public:
  /* Port declarations */

  /* Variable declarations */

  Decoder(sc_module_name nm, int num_mac_in); // constructor
  ~Decoder(); // destructor

  /* Member functions */
private:
  /* Private variables */
};

In 'Decoder.cpp':

/* First Use of SC_HAS_PROCESS */
SC_HAS_PROCESS(Decoder);
Decoder::Decoder(sc_module_name nm, int num_mac_in) :
   /* Member variable init */ 
{
  /* Do some initializing of dynamic variables */

  /* Connect sub-modules */

  /* Specify thread process */
  SC_THREAD(do_Decoder);
    sensitive << CLK.pos();
}

// Destructor
Decoder::~Decoder()
{ /* Delete dynamic variables */ }

void Decoder::do_Decoder()
{ /* Process implementation */ }




/* Second use of SC_HAS_PROCESS */
SC_HAS_PROCESS(Fifo_shift);
Fifo_shift::Fifo_shift(sc_module_name nm, int chunk_size_in) :
  /* Member variable init */
{
  // Create thread and specify sensitivity
  SC_THREAD(do_Fifo_shift);
    sensitive << CLK.pos();
}

// Destructor
Fifo_shift::~Fifo_shift()
{ /* Delete dynamic variables */ }

// Function to perform opperation
void Fifo_shift::do_Fifo_shift()
{ /* Process implementation */ }

/* Additional module implementations */

Is there a way to accomplish this format with multiple implementations of modules in a single file using the SC_HAS_PROCESS macro? I am new to SystemC, so I am hoping there is a simple solution to this but have not found any through searching the web.


Solution

  • The IEEE 1666-2011 LRM (the standard definition for SystemC) says

    Macro SC_HAS_PROCESS shall only be used within the class definition, constructor body, or member function body of a module. The name of the module class being constructed shall be passed as the argument to the macro. The macro invocation shall be terminated with a semicolon.

    It looks like you're using the macro in the global scope.

    If you haven't already, you can download a copy of the LRM from here.