test02.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19/*****************************************************************************
20
21  test02.cpp --
22  Original Author: Andy Goodrich, Forte Design Systems
23
24 *****************************************************************************/
25/*****************************************************************************
26  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
27  changes you are making here.
28
29      Name, Affiliation, Date:
30  Description of Modification:
31
32 *****************************************************************************/
33
34// TEST THAT THE CORRECT PARENT POINTER IS SET FOR THE before_end_of_elaboration
35// and end_of_elaboration CALLBACKS
36
37#include "systemc.h"
38
39class my_object : public sc_object
40{
41  public:
42	my_object() {}
43	virtual ~my_object() {}
44};
45
46SC_MODULE(DUT)
47{
48	SC_CTOR(DUT)
49	{
50		SC_CTHREAD(thread,m_clk.pos());
51		reset_signal_is(m_reset, true);
52	}
53	void before_end_of_elaboration()
54	{
55		m_before_p = new my_object;
56	}
57	void end_of_elaboration()
58	{
59		m_end_p = new my_object;
60	}
61	void thread()
62	{
63		for (;;)
64		{
65			wait();
66			if ( m_before_p->get_parent_object() == 0 )
67				cout << "before_end_of_elaboration parent is 0!" <<endl;
68			if ( m_end_p->get_parent_object() == 0 )
69				cout << "end_of_elaboration parent is 0!" <<endl;
70		}
71	}
72	my_object*  m_before_p;
73	sc_in<bool> m_clk;
74	my_object*  m_end_p;
75	sc_in<bool> m_reset;
76};
77int sc_main(int argc, char* argv[])
78{
79	sc_clock        clock;
80	DUT             dut("dut");
81	sc_signal<bool> reset;
82
83	dut.m_clk(clock);
84	dut.m_reset(reset);
85
86	reset = true;
87	sc_start(1, SC_NS);
88	reset = false;
89	sc_start(1, SC_NS);
90
91	cout << "Program completed" << endl;
92	return 0;
93}
94