1

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.

3 Answers3

2

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.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
  • Thanks for the standard definition. I guess the SC_HAS_PROCESS cannot be used as I wanted. I fixed the problem by moving the statement to the header file definition and will update my post to reflect the solution. – Reid Pinkham Jul 25 '17 at 17:09
0

It looks like You have the same code in multiple areas.

As can be seen in below/above error meassages:

src/Decoder.cpp:146:1: note: in expansion of macro ‘SC_HAS_PROCESS’
 SC_HAS_PROCESS(Fifo_shift);
 ^
src/Decoder.cpp:50:1: note: in expansion of macro ‘SC_HAS_PROCESS’
 SC_HAS_PROCESS(Decoder);

Look in lines 146 and 50.

Robert Andrzejuk
  • 5,076
  • 2
  • 22
  • 31
  • I have included those portions of the code in my question. The error may be coming from the expansion of the **SC_HAS_PROCESS** macro, however this statement is needed before the constructor in SystemC. – Reid Pinkham Jul 25 '17 at 16:33
  • Then I would declare it inside the class before the constructor, not outside the class. – Robert Andrzejuk Jul 25 '17 at 16:49
0

I was getting similar errors regarding SC_HAS_PROCESS() and was able to address them by putting the usage of the SC_HAS_PROCESS() macro within the definition of the constructor, as described here: link.

Fifo_shift::Fifo_shift(sc_module_name nm, int chunk_size_in) :
  /* Member variable init */
{
  SC_HAS_PROCESS(Fifo_shift);
  // Create thread and specify sensitivity
  SC_THREAD(do_Fifo_shift);
    sensitive << CLK.pos();
}
plafratt
  • 738
  • 1
  • 8
  • 14