112855Sgabeblack@google.com#include <systemc>
212855Sgabeblack@google.comusing namespace sc_core;
312855Sgabeblack@google.comusing namespace sc_dt;
412855Sgabeblack@google.comusing std::cout;
512855Sgabeblack@google.comusing std::endl;
612855Sgabeblack@google.com
712855Sgabeblack@google.com// 35) Port policy (correct binding)
812855Sgabeblack@google.com
912855Sgabeblack@google.comSC_MODULE(M)
1012855Sgabeblack@google.com{
1112855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,1,SC_ONE_OR_MORE_BOUND> p1;
1212855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ONE_OR_MORE_BOUND> p2;
1312855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ONE_OR_MORE_BOUND> p3;
1412855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ONE_OR_MORE_BOUND> p4;
1512855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p5;
1612855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p6;
1712855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p7;
1812855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p8;
1912855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p9;
2012855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p10;
2112855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,1,SC_ALL_BOUND> p11;
2212855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,3,SC_ALL_BOUND> p12;
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ALL_BOUND> p1_all_2;
2512855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ALL_BOUND> p2_all_2;
2612855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ALL_BOUND> p3_all_2;
2712855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,5,SC_ALL_BOUND> p4_all_5;
2812855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ALL_BOUND> p5_all_2;
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p6_zero;
3112855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p7_one;
3212855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,2,SC_ZERO_OR_MORE_BOUND> p8_two;
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com  SC_CTOR(M)
3512855Sgabeblack@google.com    : p1("p1"),
3612855Sgabeblack@google.com      p2("p2"),
3712855Sgabeblack@google.com      p3("p3"),
3812855Sgabeblack@google.com      p4("p4"),
3912855Sgabeblack@google.com      p5("p5"),
4012855Sgabeblack@google.com      p6("p6"),
4112855Sgabeblack@google.com      p7("p7"),
4212855Sgabeblack@google.com      p8("p8"),
4312855Sgabeblack@google.com      p9("p9"),
4412855Sgabeblack@google.com      p10("p10"),
4512855Sgabeblack@google.com      p11("p11"),
4612855Sgabeblack@google.com      p12("p12"),
4712855Sgabeblack@google.com      p1_all_2("p1_all_2"),
4812855Sgabeblack@google.com      p2_all_2("p2_all_2"),
4912855Sgabeblack@google.com      p3_all_2("p3_all_2"),
5012855Sgabeblack@google.com      p4_all_5("p4_all_5"),
5112855Sgabeblack@google.com      p5_all_2("p5_all_2"),
5212855Sgabeblack@google.com      p6_zero("p6_zero"),
5312855Sgabeblack@google.com      p7_one("p7_one"),
5412855Sgabeblack@google.com      p8_two("p8_two")
5512855Sgabeblack@google.com  {}
5612855Sgabeblack@google.com  void end_of_elaboration()
5712855Sgabeblack@google.com  {
5812855Sgabeblack@google.com    sc_assert(p1.size() == 1);
5912855Sgabeblack@google.com    sc_assert(p2.size() == 1);
6012855Sgabeblack@google.com    sc_assert(p3.size() == 2);
6112855Sgabeblack@google.com    sc_assert(p4.size() == 3);
6212855Sgabeblack@google.com    sc_assert(p5.size() == 0);
6312855Sgabeblack@google.com    sc_assert(p6.size() == 1);
6412855Sgabeblack@google.com    sc_assert(p7.size() == 2);
6512855Sgabeblack@google.com    sc_assert(p8.size() == 0);
6612855Sgabeblack@google.com    sc_assert(p9.size() == 1);
6712855Sgabeblack@google.com    sc_assert(p10.size() == 2);
6812855Sgabeblack@google.com    sc_assert(p11.size() == 1);
6912855Sgabeblack@google.com    sc_assert(p12.size() == 3);
7012855Sgabeblack@google.com
7112855Sgabeblack@google.com    sc_assert(p1_all_2.size() == 2);
7212855Sgabeblack@google.com    sc_assert(p2_all_2.size() == 2);
7312855Sgabeblack@google.com    sc_assert(p3_all_2.size() == 2);
7412855Sgabeblack@google.com    sc_assert(p4_all_5.size() == 5);
7512855Sgabeblack@google.com    sc_assert(p5_all_2.size() == 2);
7612855Sgabeblack@google.com
7712855Sgabeblack@google.com    sc_assert(p6_zero.size() == 0);
7812855Sgabeblack@google.com    sc_assert(p7_one.size() == 1);
7912855Sgabeblack@google.com    sc_assert(p8_two.size() == 2);
8012855Sgabeblack@google.com  }
8112855Sgabeblack@google.com};
8212855Sgabeblack@google.com
8312855Sgabeblack@google.comSC_MODULE(Top)
8412855Sgabeblack@google.com{
8512855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p1_twice;
8612855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p2_once;
8712855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p3_once;
8812855Sgabeblack@google.com  sc_port<sc_signal_in_if<int>,0,SC_ZERO_OR_MORE_BOUND> p4_unbound;
8912855Sgabeblack@google.com
9012855Sgabeblack@google.com  M *m;
9112855Sgabeblack@google.com  sc_signal<int> sig1, sig2, sig3, sig4;
9212855Sgabeblack@google.com
9312855Sgabeblack@google.com  SC_CTOR(Top)
9412855Sgabeblack@google.com  {
9512855Sgabeblack@google.com    m = new M("m");
9612855Sgabeblack@google.com    m->p1(sig1);
9712855Sgabeblack@google.com
9812855Sgabeblack@google.com    m->p2(sig1);
9912855Sgabeblack@google.com
10012855Sgabeblack@google.com    m->p3(sig1);
10112855Sgabeblack@google.com    m->p3(sig2);
10212855Sgabeblack@google.com
10312855Sgabeblack@google.com    m->p4(sig1);
10412855Sgabeblack@google.com    m->p4(sig2);
10512855Sgabeblack@google.com    m->p4(sig3);
10612855Sgabeblack@google.com
10712855Sgabeblack@google.com    m->p6(sig3);
10812855Sgabeblack@google.com
10912855Sgabeblack@google.com    m->p7(sig1);
11012855Sgabeblack@google.com    m->p7(sig2);
11112855Sgabeblack@google.com
11212855Sgabeblack@google.com    m->p9(sig1);
11312855Sgabeblack@google.com
11412855Sgabeblack@google.com    m->p10(sig1);
11512855Sgabeblack@google.com    m->p10(sig2);
11612855Sgabeblack@google.com
11712855Sgabeblack@google.com    m->p11(sig1);
11812855Sgabeblack@google.com
11912855Sgabeblack@google.com    m->p12(sig1);
12012855Sgabeblack@google.com    m->p12(sig2);
12112855Sgabeblack@google.com    m->p12(sig3);
12212855Sgabeblack@google.com
12312855Sgabeblack@google.com    m->p1_all_2(p1_twice);
12412855Sgabeblack@google.com
12512855Sgabeblack@google.com    m->p2_all_2(p2_once);
12612855Sgabeblack@google.com    m->p2_all_2(p3_once);
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com    m->p3_all_2(sig1);
12912855Sgabeblack@google.com    m->p3_all_2(p2_once);
13012855Sgabeblack@google.com
13112855Sgabeblack@google.com    m->p4_all_5(p2_once);
13212855Sgabeblack@google.com    m->p4_all_5(sig1);
13312855Sgabeblack@google.com    m->p4_all_5(p1_twice);
13412855Sgabeblack@google.com    m->p4_all_5(p3_once);
13512855Sgabeblack@google.com    m->p4_all_5(p4_unbound);
13612855Sgabeblack@google.com
13712855Sgabeblack@google.com    m->p5_all_2(p2_once);
13812855Sgabeblack@google.com    m->p5_all_2(p4_unbound);
13912855Sgabeblack@google.com
14012855Sgabeblack@google.com    m->p6_zero(p4_unbound);
14112855Sgabeblack@google.com
14212855Sgabeblack@google.com    m->p7_one(p2_once);
14312855Sgabeblack@google.com
14412855Sgabeblack@google.com    m->p8_two(p2_once);
14512855Sgabeblack@google.com  }
14612855Sgabeblack@google.com  void before_end_of_elaboration()
14712855Sgabeblack@google.com  {
14812855Sgabeblack@google.com    m->p5_all_2(p4_unbound);
14912855Sgabeblack@google.com    m->p5_all_2(p3_once);
15012855Sgabeblack@google.com    m->p5_all_2(p4_unbound);
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com    m->p6_zero(p4_unbound);
15312855Sgabeblack@google.com
15412855Sgabeblack@google.com    m->p8_two(sig1);
15512855Sgabeblack@google.com  }
15612855Sgabeblack@google.com};
15712855Sgabeblack@google.com
15812855Sgabeblack@google.comint sc_main(int argc, char* argv[])
15912855Sgabeblack@google.com{
16012855Sgabeblack@google.com  cout << "Should be silent..." << endl;
16112855Sgabeblack@google.com
16212855Sgabeblack@google.com  sc_signal<int> sig1, sig2, sig3, sig4;
16312855Sgabeblack@google.com
16412855Sgabeblack@google.com  Top top("top");
16512855Sgabeblack@google.com  top.p1_twice(sig1);
16612855Sgabeblack@google.com  top.p1_twice(sig2);
16712855Sgabeblack@google.com
16812855Sgabeblack@google.com  top.p2_once(sig3);
16912855Sgabeblack@google.com  top.p3_once(sig4);
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com  sc_start(1, SC_NS);
17212855Sgabeblack@google.com
17312855Sgabeblack@google.com  cout << endl << "Success" << endl;
17412855Sgabeblack@google.com  return 0;
17512855Sgabeblack@google.com}
176