简体   繁体   English

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

[英]SystemC: Multiple module implementations in single cpp file

Edit: Solution found by moving the SC_HAS_PROCESS(Module);编辑:通过移动SC_HAS_PROCESS(Module);找到的解决方案SC_HAS_PROCESS(Module); statements from the .cpp file into the class definition in the header file. .cpp 文件中的语句到头文件中的类定义中。

I am writing a module in SystemC which has small sub-modules.我正在 SystemC 中编写一个具有小的子模块的模块。 I would like to keep all of the declarations in a single header file, and the implementation on a single .cpp file.我想将所有声明保留在单个头文件中,并将实现保留在单个.cpp文件中。 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 .我不认为这种方法本质上有任何问题,但是我收到了一个与使用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);

The error seems to be from my second use of SC_HAS_PROCESS .该错误似乎来自我第二次使用SC_HAS_PROCESS The general format of my code is as follows (with portions removed for brevity).我的代码的一般格式如下(为简洁起见,删除了部分)。

In ' Decoder.h ':在“解码器.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 ':在“解码器.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?有没有办法使用SC_HAS_PROCESS宏在单个文件中通过多个模块实现来完成这种格式? 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.我是 SystemC 的新手,所以我希望有一个简单的解决方案,但没有通过搜索网络找到任何解决方案。

The IEEE 1666-2011 LRM (the standard definition for SystemC) says 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.宏 SC_HAS_PROCESS 只能在模块的类定义、构造函数体或成员函数体中使用。 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 .如果您还没有,可以从这里下载 LRM 的副本。

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.查看第 146 行和第 50 行。

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 .我遇到了关于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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM