简体   繁体   English

如何在SystemC Hello World程序中使用头文件?

[英]How to use header file in SystemC Hello World program?

I'm migrating from C++ to SystemC, met following basic questions. 我正在从C ++迁移到SystemC,遇到了以下基本问题。 (I've searched in google, but only got examples in a single .cpp file). (我在谷歌搜索,但只在一个.cpp文件中获得了示例)。 Thanks in advance. 提前致谢。

I know following "hello.cpp" works: 我知道以下“hello.cpp”有效:

//hello.cpp
#include "systemc.h"

SC_MODULE (hello_world) {
  SC_CTOR (hello_world) {   
  }
  void say_hello() {  
    cout << "Hello World.\n";
  }
};

int sc_main(int argc, char* argv[]) {
  hello_world hello("HELLO");
  hello.say_hello();
  return(0);
}

Question 1: How can I separate it into hello.h and hello.cpp? 问题1:如何将其分为hello.h和hello.cpp? Following code is in C++, I don't know how to create the equivalent SystemC code. 以下代码是用C ++编写的,我不知道如何创建等效的SystemC代码。

//hello.h
class hello_world
{
public:
    hello_world();
    void say_hello();
};

//hello.cpp
hello_world::hello_world()
{
}

hello_world::say_hello()
{
    cout << "Hello World.\n";
}

Question 2: How to create nested class in SystemC? 问题2:如何在SystemC中创建嵌套类? Eg what is the equivalent SystemC code according to following C++? 例如,根据以下C ++,等效的SystemC代码是什么?

class foo
{
public:
    int fooAttr1;

    class bar
    {
    public:
        int barAttr1;
    };
};

Question 3: Where is the best place to specify an attribute/operation's scope? 问题3:指定属性/操作范围的最佳位置在哪里? (public/protected/private). (公共/保护/私营)。

When separating out the implementation from the declarations in SystemC, you can do it the normal way as it is done in C++. 当从SystemC中的声明中分离出实现时,您可以像在C ++中那样以正常方式完成它。

But when you want a constructor with more than one argument(except the default one ie SC_CTOR accepts the module name) you will have to define your own constructor. 但是当你想要一个带有多个参数的构造函数时(默认值除外,即SC_CTOR接受模块名称),你必须定义自己的构造函数。
And if the module has SystemC processes( SC_THREAD , SC_METHOD , SC_CTHREAD ) then you will have to use the SC_HAS_PROCESS macro to indicate that your module has process/es. 如果模块具有SystemC进程( SC_THREADSC_METHODSC_CTHREAD ),则必须使用SC_HAS_PROCESS宏来指示您的模块具有进程/ es。

And regarding nested class it is the same thing as in C++. 关于嵌套类,它与C ++中的相同。

I am not sure what you mean by the 3rd question. 我不确定第3个问题是什么意思。

regarding your 3rd question: you can do same as you usually do in a C++ program. 关于你的第三个问题:你可以像在C ++程序中那样做。 The best place to specify an attribute/operation's scope is the declaration part of the SC_MODULE, whether you put it in cpp or header file. 指定属性/操作范围的最佳位置是SC_MODULE的声明部分,无论是将其放在cpp还是头文件中。 In a SystemC design, normally only the ports and constructor/destructor should be defined as public to allow other modules to connect with it, unless you have a strong reason and want to break the modularity of a systemc design to access explicitly the member functions of a module. 在SystemC设计中,通常只应将ports和constructor /析构函数定义为public以允许其他模块与其连接,除非您有充分的理由并希望打破systemc设计的模块性以明确访问其成员函数一个模块。

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

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