如何初始化一个数组的systemc端口名? [英] How to initialize a systemc port name which is an array?

查看:240
本文介绍了如何初始化一个数组的systemc端口名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想初始化一个端口名.该端口是一个数组,我的代码不起作用.

I wanted to initialize a port name. The port is an array and my code does not work.

SC_MODULE(example) {
  sc_clock clk;
  sc_signal<bool> mysignals[2];

 public: 

 SC_CTOR(example)
   :clk("clk"),
    mysignals[0]("mysignals[0]"), // won't work
    mysignals[1]("mysignals[1]") // won't work
      {}

  ~example() {
  }
};

下面的代码可以通过给clk命名为"clk"来工作.但是clk端口不是数组:

The code below would work by giving clk with a name "clk". However clk port is not an array:

SC_MODULE(example) {
  sc_clock clk;

 public: 

 SC_CTOR(example)
   :clk("clk")
      {}

  ~example() {
  }
};

如何命名端口数组?

更新:

尝试了建议的评论.仍然无法正常工作:

Tried the comment suggested. Still won't work:

#include "systemc.h"

SC_MODULE(example) {
  sc_clock clk;
  sc_signal<bool> mysignals[2];

 public: 

  SC_CTOR(example)
    :clk("clk"),
    mysignals{"mysig1", "mysig2"}
  {}

  ~example() {
  }
};

int sc_main(int argc, char* argv[]) {
  example hello("HELLO");

  return(0);
}

编译:

g++ -I. -I<SYSTEMC LIB>/include -L. -L<SYSTEMC LIB>/lib-linux64 -o sim example.cpp -lsystemc -lm -std=c++0x

错误:

example.cpp:在构造函数"example :: example(sc_core :: sc_module_name)"中: example.cpp:11:错误:错误的数组初始化程序

example.cpp: In constructor ‘example::example(sc_core::sc_module_name)’: example.cpp:11: error: bad array initializer

推荐答案

两个选择: 1)创建一个信号数组,并让systemc为它们命名 2)构造信号指针时要命名的数组

Two choices: 1) Create an array of signals and let systemc name them 2) An array of signal pointers name as we construct them

示例代码:

SC_MODULE(M){

    static const int SIZE = 4;

    sc_signal<bool> S[SIZE];    //array of signals let sc name them
    sc_signal<bool>* P[SIZE];   //array of pointers name on create

    SC_CTOR(M){

        for(int i = 0; i < SIZE; ++i)   //new the signals and give them a name
            P[i] = new sc_signal<bool>(("my_sig_" + to_string(i)).c_str());
    }
};

int sc_main(int, char**){

    M m("m");

    for(int i = 0; i < M::SIZE; ++i){
        cout << "S[" << i << "].name = " << m.S[i].basename() << '\n';
        cout << "P[" << i << "].name = " << m.P[i]->basename() << '\n';
    }
    return 0;
}

在我的机器上产生以下输出

Produces the following output on my machine

P[0].name = signal_0
P[0].name = my_sig_0
S[1].name = signal_1
P[1].name = my_sig_1
S[0].name = signal_0
P[0].name = my_sig_0
S[1].name = signal_1
P[1].name = my_sig_1
S[2].name = signal_2
P[2].name = my_sig_2
S[3].name = signal_3
P[3].name = my_sig_3

这篇关于如何初始化一个数组的systemc端口名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆