sc_main_fiber.cc revision 13403
12SN/A/* 210688Sandreas.hansson@arm.com * Copyright 2018 Google, Inc. 310688Sandreas.hansson@arm.com * 410688Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 510688Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 610688Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 710688Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 810688Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 910688Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 1010688Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 1110688Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 1210688Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 1310688Sandreas.hansson@arm.com * this software without specific prior written permission. 141762SN/A * 152SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262SN/A * 272SN/A * Authors: Gabe Black 282SN/A */ 292SN/A 302SN/A#include "systemc/core/sc_main_fiber.hh" 312SN/A 322SN/A#include <cstring> 332SN/A#include <string> 342SN/A 352SN/A#include "systemc/core/kernel.hh" 362SN/A#include "systemc/core/scheduler.hh" 372SN/A#include "systemc/ext/core/messages.hh" 382SN/A#include "systemc/ext/core/sc_main.hh" 392665SN/A#include "systemc/ext/utils/sc_report_handler.hh" 402665SN/A#include "systemc/utils/report.hh" 412665SN/A 4210688Sandreas.hansson@arm.com// A weak symbol to detect if sc_main has been defined, and if so where it is. 432SN/A[[gnu::weak]] int sc_main(int argc, char *argv[]); 442SN/A 4510348Sandreas.hansson@arm.comnamespace sc_gem5 46146SN/A{ 477632SBrad.Beckmann@amd.com 488232Snate@binkert.orgvoid 493348SN/AScMainFiber::main() 5010688Sandreas.hansson@arm.com{ 51695SN/A _called = true; 528832SAli.Saidi@ARM.com 532SN/A if (::sc_main) { 542SN/A try { 552SN/A _resultInt = ::sc_main(_argc, _argv); 5610688Sandreas.hansson@arm.com if (_resultInt) 571298SN/A _resultStr = "sc_main returned non-zero"; 583187SN/A else 598975Sandreas.hansson@arm.com _resultStr = "sc_main finished"; 603187SN/A // Make sure no systemc events/notifications are scheduled 6110688Sandreas.hansson@arm.com // after sc_main returns. 623187SN/A } catch (const ::sc_core::sc_report &r) { 633187SN/A // There was an exception nobody caught. 643187SN/A _resultStr = "uncaught sc_report"; 653187SN/A reportHandlerProc( 6610713Sandreas.hansson@arm.com r, ::sc_core::sc_report_handler::get_catch_actions()); 673187SN/A } catch (...) { 6810688Sandreas.hansson@arm.com // There was some other type of exception we need to wrap. 693187SN/A _resultStr = "uncaught exception"; 703187SN/A reportHandlerProc(reportifyException(), 7110688Sandreas.hansson@arm.com ::sc_core::sc_report_handler::get_catch_actions()); 723349SN/A } 733262SN/A scheduler.clear(); 7410688Sandreas.hansson@arm.com } else { 753262SN/A // If python tries to call sc_main but no sc_main was defined... 767544SN/A fatal("sc_main called but not defined.\n"); 7710688Sandreas.hansson@arm.com } 7810688Sandreas.hansson@arm.com} 7910688Sandreas.hansson@arm.com 807544SN/AScMainFiber scMainFiber; 813262SN/A 8210688Sandreas.hansson@arm.com} // namespace sc_gem5 833262SN/A