instantiation_detection.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 22 end_of_elaboration.cpp -- Check instantiation detection 23 24 Original Author: Philipp A. Hartmann, OFFIS, 2011-02-14 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#include <systemc.h> 39 40template< typename T > 41T* create( const char* nm ) 42{ 43 try { 44 return new T( sc_gen_unique_name(nm) ); 45 } 46 catch ( sc_report const & x ) 47 { 48 std::cout << "\n" << x.what() << std::endl; 49 } 50 return 0; // error detected, return NULL 51} 52 53SC_MODULE(sub_module) 54{ 55 SC_CTOR(sub_module){} 56}; 57 58SC_MODULE(top) 59{ 60 SC_CTOR(top){ 61 SC_THREAD( create_things ); 62 } 63 64 void create_things() 65 { 66 sc_assert( create<sub_module>("sub_module") == NULL ); 67 sc_assert( create<sc_in<bool> >("port") == NULL ); 68 sc_assert( create<sc_export<sc_signal_in_if<bool> > >("export") == NULL ); 69 sc_assert( create<sc_signal<bool> >("signal") == NULL ); 70 71 try { 72 SC_THREAD(create_things); 73 } catch ( sc_report const & x ) { 74 std::cout << "\n" << x.what() << std::endl; 75 } 76 77 try { 78 SC_METHOD(create_things); 79 } catch ( sc_report const & x ) { 80 std::cout << "\n" << x.what() << std::endl; 81 } 82 } 83 84#if 1 85 void start_of_simulation() 86 { 87 std:: cout << "\n---8<--- start_of_simulation ---8<---\n"; 88 create_things(); 89 std:: cout << "\n--->8--- start_of_simulation --->8---\n"; 90 } 91 void end_of_elaboration() 92 { 93 std:: cout << "\n---8<--- end_of_elaboration ---8<---\n"; 94 create_things(); 95 std:: cout << "\n--->8--- end_of_elaboration --->8---\n"; 96 } 97#endif 98}; 99 100int sc_main( int, char*[] ) 101{ 102 sc_report_handler::set_actions( "object already exists", SC_DO_NOTHING ); 103 104 top dut("dut"); 105 106 // disallow ports and exports outside of modules 107 sc_assert( create<sc_in<bool> >("port") == NULL ); 108 sc_assert( create<sc_export<sc_signal_in_if<bool> > >("export") == NULL ); 109 110 sc_start( 1, SC_NS ); 111 std::cout << "\nSuccess" << std::endl; 112 return 0; 113} 114