Build and run

The D flip-flop in Figure 2 and the testbench in Figure 3 can be compiled using

g++ -c -I /usr/local/systemc-2.3.1a/include d_ff_tb.cpp
g++ -c -I /usr/local/systemc-2.3.1a/include d_ff.cpp
g++ -c -I /usr/local/systemc-2.3.1a/include d_ff_tb_main.cpp

The combined system, containing the D flip-flip and the testbench, can be created by linking the object files from the compilation into an executable program. The linking is simplified by setting an environment variable L_SYSTEMC, as described in Section Make it run.

An executable program can be generated by giving the command

g++ -o d_ff_tb_main d_ff_tb_main.o d_ff_tb.o d_ff.o \
-L $L_SYSTEMC -lsystemc

The program can now be run, in Linux by giving the command


and on Mac by giving the command


The resulting printout is shown in Figure 4.

        SystemC 2.3.1-Accellera --- Jan  3 2017 19:23:14
        Copyright (c) 1996-2014 by all Contributors,
Time: 0 s, data_in=0, data_out=0
Time: 0 s, data_in=1, data_out=0

Info: (I702) default timescale unit used for tracing: 1 ps \
Time: 1 ns, data_in=0, data_out=1
Time: 4 ns, data_in=0, data_out=1
Time: 6 ns, data_in=1, data_out=0
Time: 8 ns, data_in=1, data_out=0
Time: 9 ns, data_in=0, data_out=1
Time: 12 ns, data_in=0, data_out=1
Time: 16 ns, data_in=0, data_out=0

Figure 4. Printout from running the testbench in Figure 3.

This the SystemC-TLM view - other views are VHDL - Verilog

The printout in Figure 4 shows the values of data_in and data_out for a sequence of time instants. The time instants are defined by the sensitivity statements for the SystemC method named reporter in Figure 3, as

    sensitive << d_ff_0.clk.pos();
    sensitive << d_ff_data_in; 

with the effect that the SystemC method reporter is executed whenever the clock signal has a rising edge, or the variable d_ff_data_in changes value. The changes for the variable d_ff_data_in are defined in the function d_ff_tb::stim_gen in Figure 3.

The printout in Figure 4 also contains a printout of the file name d_ff_tb_wave.vcd. This is a file where waveform data are stored. The display of waveforms is treated in Section Making waves.