有两种方法可以将字符串打印到控制台:
SystemC头文件: 要使用SystemC类库特性,应用程序必须包含以下指定的C头文件之一:
#include<systemc.h>
a) system .h
将名称空间sc_core
和sc_dt
中的所有名称添加到包含该名称的声明性区域,以及名称sc_unnamed
和来自标准C或C库(例如cin
, cout
, iostream
)的选定名称。
b) system .h
是为向后兼容早期版本的SystemC而提供的,可能在本标准的未来版本中被弃用。
#include <systemc>
Systemc是没有使用的旧systemh
一个常见的做法是包括,然后是"using namespace sc_core
"。然后,程序员可以根据需要包括其他名称空间。
SystemC入口点:
普通c程序的入口点是main()
函数,而systemC用户必须使用int_sc_main(int argc, char* argv[])
作为入口点。
这是因为systemC库已经定义了main()
函数。Main()
将调用sc_main()
并传递命令行参数。
SystemC模块:
systemC模块是继承sc_module基类的类(或结构)。
c++#include <systemc> // 包含systemC头文件
using namespace sc_core; // 使用命名空间
void hello1() { // 一个普通的 C++ 函数
std::cout << "Hello world using approach 1" << std::endl;
}
struct HelloWorld : sc_module { // 定义 systemC 模块
SC_CTOR(HelloWorld) {// 构造函数,稍后将解释
SC_METHOD(hello2); // 将成员函数注册到内核
}
void hello2(void) { // systemC 模拟内核的函数,可以省略 ()里的void
std::cout << "Hello world using approach 2" << std::endl;
}
};
int sc_main(int, char*[]) { // 入口点
hello1(); //方法#1:手动调用普通函数
HelloWorld helloworld("helloworld"); // 方法 #2,实例化一个 systemC 模块
sc_start(); // 让 systemC 模拟内核调用 helloworld.hello2();
return 0;
}
结果SystemC 2.3.3-Accellera --- Oct 4 2020 22:59:38 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED Hello world using approach 1 Hello world using approach 2
本文作者:古月流新
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!