test03.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// test03.cpp -- test for delayed before end of elaboration. 21// 22// Original Author: Philipp A. Hartmann, OFFIS Institute for Information 23// Technology 24// 25// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 26// 27// $Log: test03.cpp,v $ 28// Revision 1.2 2011/07/24 13:05:30 acg 29// Alan Fitch: added return 0 to sc_main that was missing. 30// 31// Revision 1.1 2011/05/08 17:55:36 acg 32// Philipp A. Hartmann: first check in of test. 33// 34 35#include <systemc> 36 37using namespace sc_core; 38 39#define PRINT_CALL( CallBack, Condition ) \ 40 std::cout << this->name() \ 41 << "->" #CallBack "()" \ 42 << ( ( Condition ) ? " " : " NOT " ) \ 43 << "called" \ 44 << std::endl 45 46SC_MODULE(in_port_module) 47{ 48 SC_CTOR(in_port_module) : beoe_called(false) {} 49 50 void before_end_of_elaboration() 51 { beoe_called = true; } 52 53 void end_of_elaboration() 54 { PRINT_CALL(before_end_of_elaboration,beoe_called); } 55 56 bool beoe_called; 57}; 58 59struct my_port : sc_in<bool> 60{ 61 typedef sc_in<bool> base_type; 62 63 explicit my_port( const char* nm ) 64 : base_type(nm) 65 , direct_mod( (std::string(nm)+"_direct_mod").c_str() ) 66 , beoe_called(false) {} 67 68 void before_end_of_elaboration() 69 { 70 beoe_called = true; 71 std::string nm = std::string(basename()) + "_delayed_mod"; 72 delayed_mod = new in_port_module( nm.c_str() ); 73 } 74 75 void end_of_elaboration() 76 { PRINT_CALL(before_end_of_elaboration,beoe_called); } 77 78 in_port_module direct_mod; 79 in_port_module* delayed_mod; 80 bool beoe_called; 81}; 82 83SC_MODULE(sub_module) 84{ 85 my_port direct_port; 86 my_port* delayed_port; 87 88 SC_CTOR(sub_module) 89 : direct_port("direct_port") 90 , delayed_port(0) 91 , beoe_called(false) 92 {} 93 94 void before_end_of_elaboration() 95 { 96 delayed_port = new my_port( "delayed_port" ); 97 (*delayed_port)( direct_port ); 98 beoe_called = true; 99 } 100 101 void end_of_elaboration() 102 { PRINT_CALL(before_end_of_elaboration,beoe_called); } 103 104 bool beoe_called; 105}; 106 107SC_MODULE(module) 108{ 109 sub_module direct_mod; 110 my_port direct_port; 111 sub_module* delayed_mod; 112 my_port* delayed_port; 113 114 SC_CTOR(module) 115 : direct_mod("direct_mod") 116 , direct_port("direct_port") 117 , delayed_mod(0) 118 , delayed_port(0) 119 , beoe_called(false) 120 { 121 direct_mod.direct_port( direct_port ); 122 } 123 124 void before_end_of_elaboration() 125 { 126 delayed_port = new my_port( "delayed_port" ); 127 (*delayed_port)( direct_port ); 128 129 delayed_mod = new sub_module( "delayed_mod" ); 130 delayed_mod->direct_port( *delayed_port ); 131 beoe_called = true; 132 } 133 134 void end_of_elaboration() 135 { PRINT_CALL(before_end_of_elaboration,beoe_called); } 136 137 bool beoe_called; 138}; 139 140int sc_main( int, char*[] ) 141{ 142 module mod("top"); 143 sc_signal<bool> sig("sig"); 144 mod.direct_port( sig ); 145 146 sc_start(); 147 return 0; 148} 149