SystemC:单个cpp文件中的多个模块实现

SystemC: Multiple module implementations in single cpp file

编辑:通过将 .cpp 文件中的 SC_HAS_PROCESS(Module); 语句移动到头文件中的 class 定义中找到了解决方案。

我正在用 SystemC 编写一个包含小子模块的模块。我想将所有声明保存在单个头文件中,并将实现保存在单个 .cpp 文件中。我不认为这种方法有任何本质上的错误,但我收到与使用 SC_HAS_PROCESS 宏重新定义 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);

错误似乎是我第二次使用 SC_HAS_PROCESS。我的代码的一般格式如下(为简洁起见删除了部分)。

在“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 */
};

在“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 */

有没有一种方法可以使用 SC_HAS_PROCESS 宏在单个文件中实现多个模块来实现这种格式?我是 SystemC 的新手,所以我希望有一个简单的解决方案,但通过搜索网络没有找到任何解决方案。

看起来你在多个区域有相同的代码。

如 below/above 错误消息中所示:

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);

查看第 146 行和第 50 行。

IEEE 1666-2011 LRM(SystemC 的标准定义)说

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.

您似乎在全局范围内使用宏。

如果您还没有,可以从 here 下载 LRM 的副本。

我遇到了关于 SC_HAS_PROCESS() 的类似错误,并且能够通过在构造函数的定义中使用 SC_HAS_PROCESS() 宏来解决这些错误,如下所述: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();
}