112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_except.cpp -- kill/reset exception handling
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Philipp A. Hartmann, OFFIS
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de CHANGE LOG APPEARS AT THE END OF THE FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_cmnhdr.h"
3012027Sjungma@eit.uni-kl.de//
3112027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_except.h"
3212027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_process.h"
3312027Sjungma@eit.uni-kl.de//
3412027Sjungma@eit.uni-kl.de#include "sysc/utils/sc_report.h"
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.denamespace sc_core {
3712027Sjungma@eit.uni-kl.de
3812027Sjungma@eit.uni-kl.desc_unwind_exception::sc_unwind_exception( sc_process_b* proc_p, bool is_reset )
3912027Sjungma@eit.uni-kl.de  : m_proc_p(proc_p), m_is_reset( is_reset )
4012027Sjungma@eit.uni-kl.de{
4112027Sjungma@eit.uni-kl.de  sc_assert( m_proc_p );
4212027Sjungma@eit.uni-kl.de  m_proc_p->start_unwinding();
4312027Sjungma@eit.uni-kl.de}
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.debool
4612027Sjungma@eit.uni-kl.desc_unwind_exception::active() const
4712027Sjungma@eit.uni-kl.de{
4812027Sjungma@eit.uni-kl.de  return m_proc_p && m_proc_p->is_unwinding();
4912027Sjungma@eit.uni-kl.de}
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.devoid
5212027Sjungma@eit.uni-kl.desc_unwind_exception::clear() const
5312027Sjungma@eit.uni-kl.de{
5412027Sjungma@eit.uni-kl.de  sc_assert( m_proc_p );
5512027Sjungma@eit.uni-kl.de  m_proc_p->clear_unwinding();
5612027Sjungma@eit.uni-kl.de}
5712027Sjungma@eit.uni-kl.de
5812027Sjungma@eit.uni-kl.deconst char*
5912027Sjungma@eit.uni-kl.desc_unwind_exception::what() const throw()
6012027Sjungma@eit.uni-kl.de{
6112027Sjungma@eit.uni-kl.de  return ( m_is_reset ) ? "RESET" : "KILL";
6212027Sjungma@eit.uni-kl.de}
6312027Sjungma@eit.uni-kl.de
6412027Sjungma@eit.uni-kl.desc_unwind_exception::~sc_unwind_exception() throw()
6512027Sjungma@eit.uni-kl.de{
6612027Sjungma@eit.uni-kl.de  if( active() ) {
6712027Sjungma@eit.uni-kl.de      // can't throw an exception, since we're already throwing
6812027Sjungma@eit.uni-kl.de      // -> abort instead
6912027Sjungma@eit.uni-kl.de      SC_REPORT_FATAL( SC_ID_RETHROW_UNWINDING_, m_proc_p->name() );
7012027Sjungma@eit.uni-kl.de  }
7112027Sjungma@eit.uni-kl.de}
7212027Sjungma@eit.uni-kl.de
7312027Sjungma@eit.uni-kl.de// handle and translate uncaught exceptions here
7412027Sjungma@eit.uni-kl.de//
7512027Sjungma@eit.uni-kl.de// These exceptions can either escape from sc_main() directly,
7612027Sjungma@eit.uni-kl.de// indirectly from an SC_METHOD(), or are thrown from within
7712027Sjungma@eit.uni-kl.de// an SC_(C)THREAD()
7812027Sjungma@eit.uni-kl.de//
7912027Sjungma@eit.uni-kl.de// returns a pointer to a dynamically allocated sc_report object,
8012027Sjungma@eit.uni-kl.de// containing the caught message
8112027Sjungma@eit.uni-kl.de
8212027Sjungma@eit.uni-kl.desc_report*
8312027Sjungma@eit.uni-kl.desc_handle_exception()
8412027Sjungma@eit.uni-kl.de{
8512027Sjungma@eit.uni-kl.de    try {
8612027Sjungma@eit.uni-kl.de
8712027Sjungma@eit.uni-kl.de        // re-throw exception here
8812027Sjungma@eit.uni-kl.de        try { throw; }
8912027Sjungma@eit.uni-kl.de
9012027Sjungma@eit.uni-kl.de        catch( sc_report & ) // to be on the safe side
9112027Sjungma@eit.uni-kl.de        {
9212027Sjungma@eit.uni-kl.de            throw; // continue
9312027Sjungma@eit.uni-kl.de        }
9412027Sjungma@eit.uni-kl.de        catch( sc_unwind_exception const & )
9512027Sjungma@eit.uni-kl.de        {
9612027Sjungma@eit.uni-kl.de            sc_assert( false && "Unhandled kill/reset, should never happen" );
9712027Sjungma@eit.uni-kl.de        }
9812027Sjungma@eit.uni-kl.de        catch( std::exception const & x )
9912027Sjungma@eit.uni-kl.de        {
10012027Sjungma@eit.uni-kl.de            SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, x.what() );
10112027Sjungma@eit.uni-kl.de        }
10212027Sjungma@eit.uni-kl.de        catch( char const * x )
10312027Sjungma@eit.uni-kl.de        {
10412027Sjungma@eit.uni-kl.de            SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_, x );
10512027Sjungma@eit.uni-kl.de        }
10612027Sjungma@eit.uni-kl.de        catch( ... )
10712027Sjungma@eit.uni-kl.de        {
10812027Sjungma@eit.uni-kl.de            SC_REPORT_ERROR( SC_ID_SIMULATION_UNCAUGHT_EXCEPTION_,
10912027Sjungma@eit.uni-kl.de                             "UNKNOWN EXCEPTION" );
11012027Sjungma@eit.uni-kl.de        }
11112027Sjungma@eit.uni-kl.de    }
11212027Sjungma@eit.uni-kl.de    // everything is an sc_report now
11312027Sjungma@eit.uni-kl.de    catch( sc_report & rpt )
11412027Sjungma@eit.uni-kl.de    {
11512027Sjungma@eit.uni-kl.de        sc_report* rpt_p = new sc_report;
11612027Sjungma@eit.uni-kl.de        rpt_p->swap( rpt );
11712027Sjungma@eit.uni-kl.de        return rpt_p;
11812027Sjungma@eit.uni-kl.de    }
11912027Sjungma@eit.uni-kl.de    return 0;
12012027Sjungma@eit.uni-kl.de}
12112027Sjungma@eit.uni-kl.de
12212027Sjungma@eit.uni-kl.de} // namespace sc_core
12312027Sjungma@eit.uni-kl.de
12412027Sjungma@eit.uni-kl.de// $Log: sc_except.cpp,v $
12512027Sjungma@eit.uni-kl.de// Revision 1.4  2011/08/26 20:46:09  acg
12612027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
12712027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
12812027Sjungma@eit.uni-kl.de//
12912027Sjungma@eit.uni-kl.de// Revision 1.3  2011/05/09 04:07:48  acg
13012027Sjungma@eit.uni-kl.de//  Philipp A. Hartmann:
13112027Sjungma@eit.uni-kl.de//    (1) Restore hierarchy in all phase callbacks.
13212027Sjungma@eit.uni-kl.de//    (2) Ensure calls to before_end_of_elaboration.
13312027Sjungma@eit.uni-kl.de//
13412027Sjungma@eit.uni-kl.de// Revision 1.2  2011/02/13 21:47:37  acg
13512027Sjungma@eit.uni-kl.de//  Andy Goodrich: update copyright notice.
13612027Sjungma@eit.uni-kl.de//
13712027Sjungma@eit.uni-kl.de// Revision 1.1  2011/02/10 22:47:38  acg
13812027Sjungma@eit.uni-kl.de//  Andy Goodrich: first check in of Philipp A. Hartmann's new exception
13912027Sjungma@eit.uni-kl.de//  processing code.
14012027Sjungma@eit.uni-kl.de//
14112027Sjungma@eit.uni-kl.de
14212027Sjungma@eit.uni-kl.de// Taf!
143