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

SystemC: Multiple module implementations in single cpp file

本文关键字:模块 实现 单个 cpp 文件 SystemC      更新时间:2023-10-16

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

我正在用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.我的代码的一般格式如下(为简洁起见,删除了部分内容(。

在">解码器.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 */
};

在">解码器.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的新手,所以我希望有一个简单的解决方案,但通过搜索网络没有找到任何解决方案。

IEEE1666-2011 LRM(SystemC的标准定义(说

宏SC_HAS_PROCESS只能在类定义中使用, 构造函数体,或模块的成员函数体。的名称 正在构造的模块类应作为参数传递给 宏观。宏调用应以分号终止。

看起来您正在全局范围内使用宏。

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

看起来您在多个区域中具有相同的代码。

在下面/上面的误差测量中可以看出:

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 行。

我遇到了关于SC_HAS_PROCESS()的类似错误,并且能够通过将SC_HAS_PROCESS()宏的使用放在构造函数的定义中来解决它们,如下所述:链接。

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