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() {
}
};
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() {
}
};
How do I name an array of ports?
UPDATE:
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);
}
Compiled with:
g++ -I. -I<SYSTEMC LIB>/include -L. -L<SYSTEMC LIB>/lib-linux64 -o sim example.cpp -lsystemc -lm -std=c++0x
Error:
example.cpp: In constructor ‘example::example(sc_core::sc_module_name)’: example.cpp:11: error: bad array initializer
No sooner had i sent the answer i remembered option 3! Use sc_vector. For example:
Produces the following output my_port_0 my_port_1 my_port_2 my_port_3
Two choices: 1) Create an array of signals and let systemc name them 2) An array of signal pointers name as we construct them
Example code:
SC_MODULE(M){
};
int sc_main(int, char**){
}
Produces the following output on my machine