デバッグ出力のコードの作り方

SystemCにおいてデバッグ用に表示を拡張させたい時には、
以下のように #defineマクロを作成して作ることができます。
今回は、シミュレーション時間と呼ばられた際のコード行を
一緒に出力するものをサンプルとしてあげています。

  • サンプルコード(SystemC-2.3版)
#include <systemc.h>

#define DEBUG_INFO  \
        cout << "[Simulation @ " << sc_time_stamp() \
             << ", l="    << __LINE__ << "]";       \
{                                                   \
  sc_simcontext* simc = sc_get_curr_simcontext();   \
  if((simc != 0) && sc_is_running()) {              \
    sc_process_b* p =                               \
       simc->get_curr_proc_info()->process_handle;  \
    if(p != 0) cout << p->name();                   \
  }                                                 \
}                                                   \
cout << " : "


int sc_main(int argc, char* argv[])
{
  sc_signal< sc_uint<32> > data;

  data = 0;
  DEBUG_INFO << "Data = "<< data << endl ;

  data = 30;
  sc_start(100, SC_NS);
  DEBUG_INFO << "Data = "<< data << endl ;

  data = 1100;
  sc_start(50, SC_NS);
  DEBUG_INFO << "Data = "<< data << endl ;

  sc_start(50, SC_NS);

  return 0;
}
  • 実行結果
$> ./main 

             SystemC 2.3.0-ASI --- Jul 13 2012 06:33:43
        Copyright (c) 1996-2012 by all Contributors,
        ALL RIGHTS RESERVED

[Simulation @ 0 s, l=22] : Data = 0
[Simulation @ 100 ns, l=26] : Data = 30
[Simulation @ 150 ns, l=30] : Data = 1100