sc_except.cpp revision 12027
111923Sandreas.sandberg@arm.com/***************************************************************************** 211923Sandreas.sandberg@arm.com 311923Sandreas.sandberg@arm.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 411923Sandreas.sandberg@arm.com more contributor license agreements. See the NOTICE file distributed 511923Sandreas.sandberg@arm.com with this work for additional information regarding copyright ownership. 611923Sandreas.sandberg@arm.com Accellera licenses this file to you under the Apache License, Version 2.0 711923Sandreas.sandberg@arm.com (the "License"); you may not use this file except in compliance with the 811923Sandreas.sandberg@arm.com License. You may obtain a copy of the License at 911923Sandreas.sandberg@arm.com 1011923Sandreas.sandberg@arm.com http://www.apache.org/licenses/LICENSE-2.0 1111923Sandreas.sandberg@arm.com 1211923Sandreas.sandberg@arm.com Unless required by applicable law or agreed to in writing, software 136654Snate@binkert.org distributed under the License is distributed on an "AS IS" BASIS, 146654Snate@binkert.org WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 155467Snate@binkert.org implied. See the License for the specific language governing 165467Snate@binkert.org permissions and limitations under the License. 175467Snate@binkert.org 185467Snate@binkert.org *****************************************************************************/ 195467Snate@binkert.org 205467Snate@binkert.org/***************************************************************************** 215467Snate@binkert.org 225467Snate@binkert.org sc_except.cpp -- kill/reset exception handling 235467Snate@binkert.org 245467Snate@binkert.org Original Author: Philipp A. Hartmann, OFFIS 255467Snate@binkert.org 265467Snate@binkert.org CHANGE LOG APPEARS AT THE END OF THE FILE 275467Snate@binkert.org *****************************************************************************/ 285467Snate@binkert.org 295467Snate@binkert.org#include "sysc/kernel/sc_cmnhdr.h" 305467Snate@binkert.org// 315467Snate@binkert.org#include "sysc/kernel/sc_except.h" 325467Snate@binkert.org#include "sysc/kernel/sc_process.h" 335467Snate@binkert.org// 345467Snate@binkert.org#include "sysc/utils/sc_report.h" 355467Snate@binkert.org 365467Snate@binkert.orgnamespace sc_core { 375467Snate@binkert.org 385467Snate@binkert.orgsc_unwind_exception::sc_unwind_exception( sc_process_b* proc_p, bool is_reset ) 395467Snate@binkert.org : m_proc_p(proc_p), m_is_reset( is_reset ) 405467Snate@binkert.org{ 415467Snate@binkert.org sc_assert( m_proc_p ); 4212563Sgabeblack@google.com m_proc_p->start_unwinding(); 4312563Sgabeblack@google.com} 446654Snate@binkert.org 456654Snate@binkert.orgbool 466654Snate@binkert.orgsc_unwind_exception::active() const 476654Snate@binkert.org{ 4813714Sandreas.sandberg@arm.com return m_proc_p && m_proc_p->is_unwinding(); 4913714Sandreas.sandberg@arm.com} 506654Snate@binkert.org 5113714Sandreas.sandberg@arm.comvoid 5213714Sandreas.sandberg@arm.comsc_unwind_exception::clear() const 5313714Sandreas.sandberg@arm.com{ 5413714Sandreas.sandberg@arm.com sc_assert( m_proc_p ); 5513714Sandreas.sandberg@arm.com m_proc_p->clear_unwinding(); 565873Snate@binkert.org} 576654Snate@binkert.org 586654Snate@binkert.orgconst char* 596654Snate@binkert.orgsc_unwind_exception::what() const throw() 606654Snate@binkert.org{ 6112563Sgabeblack@google.com return ( m_is_reset ) ? "RESET" : "KILL"; 626654Snate@binkert.org} 636654Snate@binkert.org 646654Snate@binkert.orgsc_unwind_exception::~sc_unwind_exception() throw() 656654Snate@binkert.org{ 666654Snate@binkert.org if( active() ) { 676654Snate@binkert.org // can't throw an exception, since we're already throwing 6812563Sgabeblack@google.com // -> abort instead 696654Snate@binkert.org SC_REPORT_FATAL( SC_ID_RETHROW_UNWINDING_, m_proc_p->name() ); 706654Snate@binkert.org } 719528Ssascha.bischoff@arm.com} 729528Ssascha.bischoff@arm.com 739528Ssascha.bischoff@arm.com// handle and translate uncaught exceptions here 749528Ssascha.bischoff@arm.com// 7512563Sgabeblack@google.com// These exceptions can either escape from sc_main() directly, 769528Ssascha.bischoff@arm.com// indirectly from an SC_METHOD(), or are thrown from within 779528Ssascha.bischoff@arm.com// an SC_(C)THREAD() 789528Ssascha.bischoff@arm.com// 799528Ssascha.bischoff@arm.com// returns a pointer to a dynamically allocated sc_report object, 8012563Sgabeblack@google.com// containing the caught message 819528Ssascha.bischoff@arm.com 826654Snate@binkert.orgsc_report* 836654Snate@binkert.orgsc_handle_exception() 846654Snate@binkert.org{ 856654Snate@binkert.org try { 866654Snate@binkert.org 876654Snate@binkert.org // re-throw exception here 886654Snate@binkert.org try { throw; } 896654Snate@binkert.org 906654Snate@binkert.org catch( sc_report & ) // to be on the safe side 916654Snate@binkert.org { 926654Snate@binkert.org throw; // continue 936654Snate@binkert.org } 946654Snate@binkert.org catch( sc_unwind_exception const & ) 956654Snate@binkert.org { 966654Snate@binkert.org sc_assert( false && "Unhandled kill/reset, should never happen" ); 976654Snate@binkert.org } 986654Snate@binkert.org catch( std::exception const & x ) 996654Snate@binkert.org { 1006654Snate@binkert.org SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, x.what() ); 1016654Snate@binkert.org } 1026654Snate@binkert.org catch( char const * x ) 1036654Snate@binkert.org { 1046654Snate@binkert.org SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, x ); 1056654Snate@binkert.org } 1066654Snate@binkert.org catch( ... ) 1076654Snate@binkert.org { 1086654Snate@binkert.org SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, 1096654Snate@binkert.org "UNKNOWN EXCEPTION" ); 1106654Snate@binkert.org } 1116654Snate@binkert.org } 1126654Snate@binkert.org // everything is an sc_report now 1136654Snate@binkert.org catch( sc_report & rpt ) 1146654Snate@binkert.org { 1156654Snate@binkert.org sc_report* rpt_p = new sc_report; 1166654Snate@binkert.org rpt_p->swap( rpt ); 1176654Snate@binkert.org return rpt_p; 1186654Snate@binkert.org } 1196654Snate@binkert.org return 0; 1206654Snate@binkert.org} 1216654Snate@binkert.org 1226654Snate@binkert.org} // namespace sc_core 1236654Snate@binkert.org 1246654Snate@binkert.org// $Log: sc_except.cpp,v $ 1256654Snate@binkert.org// Revision 1.4 2011/08/26 20:46:09 acg 1266654Snate@binkert.org// Andy Goodrich: moved the modification log to the end of the file to 1276654Snate@binkert.org// eliminate source line number skew when check-ins are done. 1286654Snate@binkert.org// 1296654Snate@binkert.org// Revision 1.3 2011/05/09 04:07:48 acg 13013663Sandreas.sandberg@arm.com// Philipp A. Hartmann: 1316654Snate@binkert.org// (1) Restore hierarchy in all phase callbacks. 1326654Snate@binkert.org// (2) Ensure calls to before_end_of_elaboration. 1336654Snate@binkert.org// 1346654Snate@binkert.org// Revision 1.2 2011/02/13 21:47:37 acg 1356654Snate@binkert.org// Andy Goodrich: update copyright notice. 1366654Snate@binkert.org// 1376654Snate@binkert.org// Revision 1.1 2011/02/10 22:47:38 acg 1386654Snate@binkert.org// Andy Goodrich: first check in of Philipp A. Hartmann's new exception 1396654Snate@binkert.org// processing code. 1406654Snate@binkert.org// 1416654Snate@binkert.org 1426654Snate@binkert.org// Taf! 1436654Snate@binkert.org