gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:59:54 24 4
gpt4 key购买 nike

编辑:通过移动 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 的新手,所以我希望有一个简单的解决方案,但没有通过搜索网络找到任何解决方案。

最佳答案

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 themodule class being constructed shall be passed as the argument to themacro. The macro invocation shall be terminated with a semicolon.


看起来您正在全局范围内使用宏。
如果您还没有,可以从 here 下载 LRM 的拷贝。 .

关于c++ - SystemC:单个 cpp 文件中的多个模块实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45308468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com