全てはここからなんちゃらかんちゃら
うれしいかどうかは別にして、組み込むのは簡単です。
systemcのサンプルとしてついてくるsimple_fifo.cppに、Tclインタープリターを組込みました。
変更点は2カ所です。
まずはtcl.hをインクルードします。
#include <tcl.h> #include <systemc.h>
今回はtopのコンストラクタでインタープリタを組み込みました。
top(sc_module_name name) : sc_module(name) { Tcl_Interp *interp; // Tcl interpreter interp = Tcl_CreateInterp(); const char code [] = "puts \"Hello Tcl\""; Tcl_Eval(interp, code); fifo_inst = new fifo("Fifo1"); prod_inst = new producer("Producer1"); prod_inst->out(*fifo_inst); cons_inst = new consumer("Consumer1"); cons_inst->in(*fifo_inst); }
実行すると、sc_start() の前に、Tclインタープリタによる Hello Tclが表示されます。
SystemC 2.3.0-ASI --- Apr 27 2013 09:09:16 Copyright (c) 1996-2012 by all Contributors, ALL RIGHTS RESERVED Hello Tcl V<9>isit www<1>.s<9>ystemc.o<1>rg<9> and see<1> w<9>hat Syst<1>em<9>C can do<1> f<9>or you t<1>oday!<1>
素のCだと文字列処理やリスト処理がうれしい気がしますが、C++の全機能が使えるSystemCだといまいち使い道がない気もします。
全ソースとMakefileはgithubに。
https://github.com/natsutan/systemc_tcl
Makefileでは、/lib/libtcl.aを直にリンクしていますが、正しいやり方は-ltclオプションでいけるはずです。手持ちのcygwin環境でいろいろやってみましたが、上手くいかなかったのでこうなってます。
同じ勢いでGaucheも組込みできそうですね。