test05.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 test05.cpp -- Test user exception throws. 23 24 Original Author: Andy Goodrich, Forte Design Systems, 15 December 2006 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// $Log: test05.cpp,v $ 39// Revision 1.3 2011/02/14 17:00:00 acg 40// Andy Goodrich: updated copyright and added cvs logging information inline. 41// 42 43#include "systemc.h" 44 45class my_exception {}; 46class your_exception {}; 47 48SC_MODULE(DUT) 49{ 50 SC_CTOR(DUT) 51 { 52 SC_CTHREAD(thread,m_clk.pos()); 53 SC_THREAD(monitor); 54 } 55 void monitor() 56 { 57 m_monitor_handle = sc_get_current_process_handle(); 58 for (;;) 59 { 60 try 61 { 62 wait(m_never_event); 63 } 64 catch (my_exception& except) 65 { 66 cout << sc_time_stamp() << " caught my exception " << endl; 67 } 68 catch (your_exception& except) 69 { 70 cout << sc_time_stamp() << " caught your exception " << endl; 71 } 72 } 73 } 74 void thread() 75 { 76 my_exception exception; 77 your_exception other_exception; 78 for (;;) 79 { 80 wait(3); 81 cout << sc_time_stamp() << " throwing my exception " << endl; 82 m_monitor_handle.throw_it(exception); 83 wait(); 84 85 // test that both exceptions appear. 86 87 cout << sc_time_stamp() << " throwing my exception " << endl; 88 m_monitor_handle.throw_it(exception); 89 cout << sc_time_stamp() << " throwing your exception " << endl; 90 m_monitor_handle.throw_it(other_exception); 91 wait(); 92 wait(); 93 sc_stop(); 94 } 95 } 96 sc_in<bool> m_clk; 97 sc_process_handle m_monitor_handle; 98 sc_event m_never_event; 99}; 100 101int sc_main(int argc, char* argv[]) 102{ 103 sc_clock clock; 104 DUT dut("dut"); 105 106 dut.m_clk(clock); 107 108 sc_start(); 109 110 cout << "Program completed" << endl; 111 return 0; 112} 113