112855Sgabeblack@google.com#include "systemc.h"
212855Sgabeblack@google.com
312855Sgabeblack@google.comSC_MODULE(READ_LEAF)
412855Sgabeblack@google.com{
512855Sgabeblack@google.com    SC_CTOR(READ_LEAF)
612855Sgabeblack@google.com    {
712855Sgabeblack@google.com        SC_METHOD(delta);
812855Sgabeblack@google.com        sensitive << in;
912855Sgabeblack@google.com    }
1012855Sgabeblack@google.com    void delta()
1112855Sgabeblack@google.com    {
1212855Sgabeblack@google.com        cout << "READ_LEAF: change " << (int)in.read() << endl;
1312855Sgabeblack@google.com    }
1412855Sgabeblack@google.com    sc_in<sc_int<8> >     in;
1512855Sgabeblack@google.com};
1612855Sgabeblack@google.com
1712855Sgabeblack@google.comSC_MODULE(WRITE_LEAF)
1812855Sgabeblack@google.com{
1912855Sgabeblack@google.com    SC_CTOR(WRITE_LEAF)
2012855Sgabeblack@google.com    {
2112855Sgabeblack@google.com		SC_METHOD(sync)
2212855Sgabeblack@google.com		sensitive << clk.pos();
2312855Sgabeblack@google.com    }
2412855Sgabeblack@google.com	void sync()
2512855Sgabeblack@google.com	{
2612855Sgabeblack@google.com		out = out.read() + 1;
2712855Sgabeblack@google.com	}
2812855Sgabeblack@google.com    sc_signal<sc_int<8> >  out;
2912855Sgabeblack@google.com	sc_in_clk			   clk;
3012855Sgabeblack@google.com};
3112855Sgabeblack@google.com
3212855Sgabeblack@google.comSC_MODULE(MIDDLE)
3312855Sgabeblack@google.com{
3412855Sgabeblack@google.com    SC_CTOR(MIDDLE) : reader("reader"), writer("writer")
3512855Sgabeblack@google.com    {
3612855Sgabeblack@google.com		writer.clk(clk);     // Bind clk going down the module hierarchy.
3712855Sgabeblack@google.com        reader.in(my_port);  // Bind my_port going down the module hierarchy.
3812855Sgabeblack@google.com        my_port(writer.out); // Bind my_port coming up the module hierarchy.
3912855Sgabeblack@google.com    }
4012855Sgabeblack@google.com	sc_in_clk			   clk;
4112855Sgabeblack@google.com    sc_in<sc_int<8> >     my_port;
4212855Sgabeblack@google.com	READ_LEAF			   reader;
4312855Sgabeblack@google.com	WRITE_LEAF			   writer;
4412855Sgabeblack@google.com};
4512855Sgabeblack@google.com
4612855Sgabeblack@google.comSC_MODULE(TOP)
4712855Sgabeblack@google.com{
4812855Sgabeblack@google.com    SC_CTOR(TOP) : down("down")
4912855Sgabeblack@google.com    {
5012855Sgabeblack@google.com		down.clk(clk);    // Bind clk going down the module hierarchy.
5112855Sgabeblack@google.com        in(down.my_port); // Bind in coming up the module hierarchy.
5212855Sgabeblack@google.com        SC_METHOD(delta);
5312855Sgabeblack@google.com        sensitive << in;
5412855Sgabeblack@google.com    }
5512855Sgabeblack@google.com    void delta()
5612855Sgabeblack@google.com    {
5712855Sgabeblack@google.com        cout << "TOP: change " << (int)in.read() << endl;
5812855Sgabeblack@google.com    }
5912855Sgabeblack@google.com	sc_in_clk			   clk;
6012855Sgabeblack@google.com    sc_in<sc_int<8> >      in;
6112855Sgabeblack@google.com	MIDDLE     			   down;
6212855Sgabeblack@google.com};
6312855Sgabeblack@google.com
6412855Sgabeblack@google.comint sc_main(int argc, char* arg[])
6512855Sgabeblack@google.com{
6612855Sgabeblack@google.com    sc_clock clock;
6712855Sgabeblack@google.com    TOP top("top");
6812855Sgabeblack@google.com	top.clk(clock);
6912855Sgabeblack@google.com
7012855Sgabeblack@google.com    sc_start(10, SC_NS);
7112855Sgabeblack@google.com    return 0;
7212855Sgabeblack@google.com}
7312855Sgabeblack@google.com
74