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 22 test05.cpp -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38// test of the child objects of a module and the simcontext 39 40#include "systemc.h" 41 42SC_MODULE( mod_a ) 43{ 44 sc_in_clk clk; 45 sc_out<int> out; 46 47 int a; 48 49 void main_action() 50 { 51 out = ++ a; 52 } 53 54 SC_CTOR( mod_a ) 55 { 56 SC_METHOD( main_action ); 57 sensitive << clk.pos(); 58 a = 0; 59 } 60}; 61 62SC_MODULE( mod_b ) 63{ 64 sc_in<int> in; 65 66 void main_action() 67 { 68 while( true ) { 69 wait(); 70 cout << in.read() << endl; 71 } 72 } 73 74 SC_CTOR( mod_b ) 75 { 76 SC_THREAD( main_action ); 77 sensitive << in; 78 } 79}; 80 81SC_MODULE( mod_c ) 82{ 83 sc_in_clk clk; 84 85 void main_action() 86 { 87 while( true ) { 88 cout << sc_time_stamp() << endl; 89 wait(); 90 } 91 } 92 93 mod_a a; 94 mod_b b; 95 sc_signal<int> sig; 96 97 SC_CTOR( mod_c ) 98 : a( "a" ), b( "b" ) 99 { 100 SC_CTHREAD( main_action, clk.neg() ); 101 a.clk( clk ); 102 a.out( sig ); 103 b.in( sig ); 104 } 105}; 106 107void 108print_child_objects( const ::std::vector<sc_object*>& child_objects_ ) 109{ 110 int size = child_objects_.size(); 111 cout << "***\n"; 112 for( int i = 0; i < size; ++ i ) { 113 sc_object* object = child_objects_[i]; 114 cout << object->kind() << " " << object->name() << endl; 115 } 116} 117 118int 119sc_main( int, char*[] ) 120{ 121 mod_a a( "a" ); 122 mod_b b( "b" ); 123 sc_clock clk; 124 sc_signal<int> sig; 125 126 a.clk( clk ); 127 a.out( sig ); 128 b.in( sig ); 129 130 mod_c c( "c" ); 131 c.clk( clk ); 132 133 sc_start(1, SC_NS); 134 135 print_child_objects( sc_get_top_level_objects() ); 136 print_child_objects( a.get_child_objects() ); 137 print_child_objects( b.get_child_objects() ); 138 print_child_objects( c.get_child_objects() ); 139 print_child_objects( c.a.get_child_objects() ); 140 print_child_objects( c.b.get_child_objects() ); 141 142 return 0; 143} 144