test03.cpp revision 12855
112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com// test03.cpp -- test for delayed before end of elaboration. 2112855Sgabeblack@google.com// 2212855Sgabeblack@google.com// Original Author: Philipp A. Hartmann, OFFIS Institute for Information 2312855Sgabeblack@google.com// Technology 2412855Sgabeblack@google.com// 2512855Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2612855Sgabeblack@google.com// 2712855Sgabeblack@google.com// $Log: test03.cpp,v $ 2812855Sgabeblack@google.com// Revision 1.2 2011/07/24 13:05:30 acg 2912855Sgabeblack@google.com// Alan Fitch: added return 0 to sc_main that was missing. 3012855Sgabeblack@google.com// 3112855Sgabeblack@google.com// Revision 1.1 2011/05/08 17:55:36 acg 3212855Sgabeblack@google.com// Philipp A. Hartmann: first check in of test. 3312855Sgabeblack@google.com// 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com#include <systemc> 3612855Sgabeblack@google.com 3712855Sgabeblack@google.comusing namespace sc_core; 3812855Sgabeblack@google.com 3912855Sgabeblack@google.com#define PRINT_CALL( CallBack, Condition ) \ 4012855Sgabeblack@google.com std::cout << this->name() \ 4112855Sgabeblack@google.com << "->" #CallBack "()" \ 4212855Sgabeblack@google.com << ( ( Condition ) ? " " : " NOT " ) \ 4312855Sgabeblack@google.com << "called" \ 4412855Sgabeblack@google.com << std::endl 4512855Sgabeblack@google.com 4612855Sgabeblack@google.comSC_MODULE(in_port_module) 4712855Sgabeblack@google.com{ 4812855Sgabeblack@google.com SC_CTOR(in_port_module) : beoe_called(false) {} 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com void before_end_of_elaboration() 5112855Sgabeblack@google.com { beoe_called = true; } 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com void end_of_elaboration() 5412855Sgabeblack@google.com { PRINT_CALL(before_end_of_elaboration,beoe_called); } 5512855Sgabeblack@google.com 5612855Sgabeblack@google.com bool beoe_called; 5712855Sgabeblack@google.com}; 5812855Sgabeblack@google.com 5912855Sgabeblack@google.comstruct my_port : sc_in<bool> 6012855Sgabeblack@google.com{ 6112855Sgabeblack@google.com typedef sc_in<bool> base_type; 6212855Sgabeblack@google.com 6312855Sgabeblack@google.com explicit my_port( const char* nm ) 6412855Sgabeblack@google.com : base_type(nm) 6512855Sgabeblack@google.com , direct_mod( (std::string(nm)+"_direct_mod").c_str() ) 6612855Sgabeblack@google.com , beoe_called(false) {} 6712855Sgabeblack@google.com 6812855Sgabeblack@google.com void before_end_of_elaboration() 6912855Sgabeblack@google.com { 7012855Sgabeblack@google.com beoe_called = true; 7112855Sgabeblack@google.com std::string nm = std::string(basename()) + "_delayed_mod"; 7212855Sgabeblack@google.com delayed_mod = new in_port_module( nm.c_str() ); 7312855Sgabeblack@google.com } 7412855Sgabeblack@google.com 7512855Sgabeblack@google.com void end_of_elaboration() 7612855Sgabeblack@google.com { PRINT_CALL(before_end_of_elaboration,beoe_called); } 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com in_port_module direct_mod; 7912855Sgabeblack@google.com in_port_module* delayed_mod; 8012855Sgabeblack@google.com bool beoe_called; 8112855Sgabeblack@google.com}; 8212855Sgabeblack@google.com 8312855Sgabeblack@google.comSC_MODULE(sub_module) 8412855Sgabeblack@google.com{ 8512855Sgabeblack@google.com my_port direct_port; 8612855Sgabeblack@google.com my_port* delayed_port; 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com SC_CTOR(sub_module) 8912855Sgabeblack@google.com : direct_port("direct_port") 9012855Sgabeblack@google.com , delayed_port(0) 9112855Sgabeblack@google.com , beoe_called(false) 9212855Sgabeblack@google.com {} 9312855Sgabeblack@google.com 9412855Sgabeblack@google.com void before_end_of_elaboration() 9512855Sgabeblack@google.com { 9612855Sgabeblack@google.com delayed_port = new my_port( "delayed_port" ); 9712855Sgabeblack@google.com (*delayed_port)( direct_port ); 9812855Sgabeblack@google.com beoe_called = true; 9912855Sgabeblack@google.com } 10012855Sgabeblack@google.com 10112855Sgabeblack@google.com void end_of_elaboration() 10212855Sgabeblack@google.com { PRINT_CALL(before_end_of_elaboration,beoe_called); } 10312855Sgabeblack@google.com 10412855Sgabeblack@google.com bool beoe_called; 10512855Sgabeblack@google.com}; 10612855Sgabeblack@google.com 10712855Sgabeblack@google.comSC_MODULE(module) 10812855Sgabeblack@google.com{ 10912855Sgabeblack@google.com sub_module direct_mod; 11012855Sgabeblack@google.com my_port direct_port; 11112855Sgabeblack@google.com sub_module* delayed_mod; 11212855Sgabeblack@google.com my_port* delayed_port; 11312855Sgabeblack@google.com 11412855Sgabeblack@google.com SC_CTOR(module) 11512855Sgabeblack@google.com : direct_mod("direct_mod") 11612855Sgabeblack@google.com , direct_port("direct_port") 11712855Sgabeblack@google.com , delayed_mod(0) 11812855Sgabeblack@google.com , delayed_port(0) 11912855Sgabeblack@google.com , beoe_called(false) 12012855Sgabeblack@google.com { 12112855Sgabeblack@google.com direct_mod.direct_port( direct_port ); 12212855Sgabeblack@google.com } 12312855Sgabeblack@google.com 12412855Sgabeblack@google.com void before_end_of_elaboration() 12512855Sgabeblack@google.com { 12612855Sgabeblack@google.com delayed_port = new my_port( "delayed_port" ); 12712855Sgabeblack@google.com (*delayed_port)( direct_port ); 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com delayed_mod = new sub_module( "delayed_mod" ); 13012855Sgabeblack@google.com delayed_mod->direct_port( *delayed_port ); 13112855Sgabeblack@google.com beoe_called = true; 13212855Sgabeblack@google.com } 13312855Sgabeblack@google.com 13412855Sgabeblack@google.com void end_of_elaboration() 13512855Sgabeblack@google.com { PRINT_CALL(before_end_of_elaboration,beoe_called); } 13612855Sgabeblack@google.com 13712855Sgabeblack@google.com bool beoe_called; 13812855Sgabeblack@google.com}; 13912855Sgabeblack@google.com 14012855Sgabeblack@google.comint sc_main( int, char*[] ) 14112855Sgabeblack@google.com{ 14212855Sgabeblack@google.com module mod("top"); 14312855Sgabeblack@google.com sc_signal<bool> sig("sig"); 14412855Sgabeblack@google.com mod.direct_port( sig ); 14512855Sgabeblack@google.com 14612855Sgabeblack@google.com sc_start(); 14712855Sgabeblack@google.com return 0; 14812855Sgabeblack@google.com} 149