编辑:通过将.cpp文件中的SC_HAS_PROCESS(Module);
语句移动到头文件中的类定义中找到的解决方案。
我正在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的新手,所以我希望有一个简单的解决方案,但是没有找到任何通过搜索网络。
答案 0 :(得分:0)
看起来你在多个领域拥有相同的代码。
从下面/上面的错误说明中可以看出:
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行。
答案 1 :(得分:0)
IEEE 1666-2011 LRM(SystemC的标准定义)说
宏SC_HAS_PROCESS只能在类定义中使用, 构造函数体或模块的成员函数体。的名字 正在构造的模块类应作为参数传递给 宏。宏调用应以分号结束。
看起来你在全球范围内使用宏。
如果您还没有,可以从here下载LRM的副本。
答案 2 :(得分:0)
我遇到关于SC_HAS_PROCESS()
的类似错误,并且能够通过将SC_HAS_PROCESS()
宏的用法放入构造函数的定义中来解决这些错误,如下所述:link。 / p>
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();
}