112855Sgabeblack@google.com 212855Sgabeblack@google.com/***************************************************************************** 312855Sgabeblack@google.com 412855Sgabeblack@google.com The following code is derived, directly or indirectly, from the SystemC 512855Sgabeblack@google.com source code Copyright (c) 1996-2014 by all Contributors. 612855Sgabeblack@google.com All Rights reserved. 712855Sgabeblack@google.com 812855Sgabeblack@google.com The contents of this file are subject to the restrictions and limitations 912855Sgabeblack@google.com set forth in the SystemC Open Source License (the "License"); 1012855Sgabeblack@google.com You may not use this file except in compliance with such restrictions and 1112855Sgabeblack@google.com limitations. You may obtain instructions on how to receive a copy of the 1212855Sgabeblack@google.com License at http://www.accellera.org/. Software distributed by Contributors 1312855Sgabeblack@google.com under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 1412855Sgabeblack@google.com ANY KIND, either express or implied. See the License for the specific 1512855Sgabeblack@google.com language governing rights and limitations under the License. 1612855Sgabeblack@google.com 1712855Sgabeblack@google.com *****************************************************************************/ 1812855Sgabeblack@google.com 1912855Sgabeblack@google.com/***************************************************************************** 2012855Sgabeblack@google.com 2112855Sgabeblack@google.com sc_method_reset_throw.cpp -- 2212855Sgabeblack@google.com 2312855Sgabeblack@google.com Original Author: Bishnupriya Bhattacharya, Cadence Design Systems, 2012-08-07 2412855Sgabeblack@google.com 2512855Sgabeblack@google.com *****************************************************************************/ 2612855Sgabeblack@google.com 2712855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 2812855Sgabeblack@google.com#include <systemc.h> 2912855Sgabeblack@google.com 3012855Sgabeblack@google.comclass my_exception 3112855Sgabeblack@google.com{ 3212855Sgabeblack@google.compublic: 3312855Sgabeblack@google.com explicit my_exception(const char* s) : s_(s) { } 3412855Sgabeblack@google.com const char* message() const { return s_.c_str(); } 3512855Sgabeblack@google.comprotected: 3612855Sgabeblack@google.com std::string s_; 3712855Sgabeblack@google.com}; 3812855Sgabeblack@google.com 3912855Sgabeblack@google.comSC_MODULE(sctop) 4012855Sgabeblack@google.com{ 4112855Sgabeblack@google.compublic: 4212855Sgabeblack@google.com SC_CTOR(sctop) 4312855Sgabeblack@google.com { 4412855Sgabeblack@google.com SC_THREAD(run); 4512855Sgabeblack@google.com SC_METHOD(m1); dont_initialize(); 4612855Sgabeblack@google.com method_handle = sc_get_current_process_handle(); 4712855Sgabeblack@google.com SC_THREAD(throwee1); 4812855Sgabeblack@google.com throwee1_h = sc_get_current_process_handle(); 4912855Sgabeblack@google.com } 5012855Sgabeblack@google.com 5112855Sgabeblack@google.com void run() { 5212855Sgabeblack@google.com wait (5, SC_NS); 5312855Sgabeblack@google.com cout << sc_time_stamp() << ": reset method m1" << endl; 5412855Sgabeblack@google.com method_handle.reset(); 5512855Sgabeblack@google.com cout << sc_time_stamp() << ": after reset of method m1" << endl; 5612855Sgabeblack@google.com } 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com void m1() 5912855Sgabeblack@google.com { 6012855Sgabeblack@google.com cout << sc_time_stamp() << ": in m1" << endl; 6112855Sgabeblack@google.com cout << sc_time_stamp() << ": in m1() " 6212855Sgabeblack@google.com << "throwing exception in throwee1" << endl; 6312855Sgabeblack@google.com 6412855Sgabeblack@google.com throwee1_h.throw_it( 6512855Sgabeblack@google.com my_exception("thrown in throwee1 from m1()") 6612855Sgabeblack@google.com ); 6712855Sgabeblack@google.com 6812855Sgabeblack@google.com cout << sc_time_stamp() << ": in m1() " 6912855Sgabeblack@google.com << "after throwing exception in throwee1" << endl; 7012855Sgabeblack@google.com } 7112855Sgabeblack@google.com 7212855Sgabeblack@google.com void throwee1() 7312855Sgabeblack@google.com { 7412855Sgabeblack@google.com // catch exception and exit 7512855Sgabeblack@google.com while (1) { 7612855Sgabeblack@google.com try { 7712855Sgabeblack@google.com wait(50, SC_NS); 7812855Sgabeblack@google.com cerr << sc_time_stamp() << ": in throwee1, normal flow" << endl; 7912855Sgabeblack@google.com } 8012855Sgabeblack@google.com catch (my_exception const & x) { 8112855Sgabeblack@google.com cerr << sc_time_stamp() << ": in throwee1, caught exception " 8212855Sgabeblack@google.com << endl; 8312855Sgabeblack@google.com return; 8412855Sgabeblack@google.com } 8512855Sgabeblack@google.com } 8612855Sgabeblack@google.com } 8712855Sgabeblack@google.com 8812855Sgabeblack@google.comprotected: 8912855Sgabeblack@google.com sc_process_handle method_handle; 9012855Sgabeblack@google.com sc_process_handle throwee1_h; 9112855Sgabeblack@google.com}; 9212855Sgabeblack@google.com 9312855Sgabeblack@google.com 9412855Sgabeblack@google.comint sc_main (int, char*[]) 9512855Sgabeblack@google.com{ 9612876Sgabeblack@google.com sc_report_handler::set_actions( "disable() or dont_initialize() " 9712876Sgabeblack@google.com "called on process with no static sensitivity, it will be orphaned", 9812876Sgabeblack@google.com SC_DO_NOTHING ); 9912855Sgabeblack@google.com sctop top1("Top1"); 10012855Sgabeblack@google.com sc_start(10, SC_NS); 10112855Sgabeblack@google.com return 0; 10212855Sgabeblack@google.com} 103