SystemC:未使用 or 固定値端子を隠蔽出来る闇記述
前に SystemC:未使用 or 固定値端子の処理
を書いた際に思ったことがあります。
先ずはこちらのコードをみてください。
#include <systemc.h> //---------------------------------------------// static struct { template < typename T > operator sc_core::sc_signal_inout_if<T> & () const { return *(new sc_core::sc_signal<T>(sc_core::sc_gen_unique_name("vh_open"))); } } const vh_open = {}; //---------------------------------------------// template<typename T> sc_core::sc_signal_in_if<T> const & vh_const( T const & v ) // keep the name consistent with vh_open { // Yes, this is an (elaboration-time) memory leak. You can avoid it with some extra effort sc_core::sc_signal<T>* sig_p = new sc_core::sc_signal<T>( sc_core::sc_gen_unique_name("vh_const") ); sig_p->write( v ); return *sig_p; } //---------------------------------------------// SC_MODULE( hoge ){ sc_in <int> a; sc_in <int> b; sc_in <int> c; sc_out<int> out; sc_out<bool> irq; void process(){ out = a + b + c; irq = ((a+b+c) > 10)? 1 : 0; } SC_CTOR( hoge ) { c(vh_const(42)); irq(vh_open); SC_METHOD( process ); sensitive << a << b << c ; } }; int sc_main( int argc, char* argv[] ) { sc_signal<int> sig_a; sc_signal<int> sig_b; sc_signal<int> sig_c; sc_signal<int> sig_out; sc_signal<bool> sig_irq; hoge uhoge("hoge"); uhoge.a(sig_a); uhoge.b(sig_b); uhoge.out(sig_out); sig_a = 1; sig_b = 2; sig_c = 3; sc_start(1.0, SC_PS); cout << "a = " ; sig_a.print(); cout << ", "; cout << "b = " ; sig_b.print(); cout << ", "; cout << "c = " ; sig_c.print(); cout << ", "; cout << "out = "; sig_out.print(); cout << ", "; cout << "irq = "; sig_irq.print(); cout << endl; sig_a = 3; sig_b = 4; sig_c = 5; sc_start(1.0, SC_PS); cout << "a = " ; sig_a.print(); cout << ", "; cout << "b = " ; sig_b.print(); cout << ", "; cout << "c = " ; sig_c.print(); cout << ", "; cout << "out = "; sig_out.print(); cout << ", "; cout << "irq = "; sig_irq.print(); cout << endl; return 0; }
違い分かりますでしょうか?
実は、56行目から59行目までの hogeモジュールの接続に「c」「irq」が無いんです。
無くても問題ないんです!!!
実行結果
a = 1, b = 2, c = 3, out = 45, irq = 0 a = 3, b = 4, c = 5, out = 49, irq = 0
ってことは、「c」「irq」は何処へ?というと
hogeモジュールの中なんです!!!
SC_CTOR( hoge )
{
c(vh_const(42));
irq(vh_open);
:
あくまで、モデルを作る人が隠したい場合に使えるかなと思っているのですが、
こういった記述は Verilog HDLや VHDLだと出来ないのでなかなかの闇記述ですよね。