SystemC.py revision 13038
112837Sgabeblack@google.com# Copyright 2018 Google, Inc. 212837Sgabeblack@google.com# 312837Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 412837Sgabeblack@google.com# modification, are permitted provided that the following conditions are 512837Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 612837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 712837Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 812837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 912837Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1012837Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1112837Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1212837Sgabeblack@google.com# this software without specific prior written permission. 1312837Sgabeblack@google.com# 1412837Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1512837Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1612837Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1712837Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1812837Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1912837Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2012837Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2112837Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2212837Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2312837Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2412837Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2512837Sgabeblack@google.com# 2612837Sgabeblack@google.com# Authors: Gabe Black 2712837Sgabeblack@google.com 2812837Sgabeblack@google.comfrom m5.SimObject import SimObject 2912837Sgabeblack@google.com 3012837Sgabeblack@google.com# This class represents the systemc kernel. There should be exactly one in the 3112837Sgabeblack@google.com# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats, 3212837Sgabeblack@google.com# etc.) and manages the lifecycle of the systemc simulation accordingly. 3312837Sgabeblack@google.com# It also acts as a collecting point for systemc related control functionality. 3412837Sgabeblack@google.comclass SystemC_Kernel(SimObject): 3512837Sgabeblack@google.com type = 'SystemC_Kernel' 3612982Sgabeblack@google.com cxx_class = 'sc_gem5::Kernel' 3712837Sgabeblack@google.com cxx_header = 'systemc/core/kernel.hh' 3812837Sgabeblack@google.com 3912837Sgabeblack@google.com def sc_main(self, *args): 4012837Sgabeblack@google.com '''Call the systemc sc_main function with the given string args''' 4112837Sgabeblack@google.com from _m5.systemc import sc_main 4212837Sgabeblack@google.com sc_main(*args) 4312837Sgabeblack@google.com 4412837Sgabeblack@google.com# This class represents systemc sc_object instances in python config files. It 4512837Sgabeblack@google.com# inherits from SimObject in python, but the c++ version, sc_core::sc_object, 4612837Sgabeblack@google.com# doesn't inherit from gem5's c++ SimObject class. 4712837Sgabeblack@google.comclass SystemC_ScObject(SimObject): 4812837Sgabeblack@google.com type = 'SystemC_ScObject' 4912837Sgabeblack@google.com abstract = True 5012837Sgabeblack@google.com cxx_class = 'sc_core::sc_object' 5112837Sgabeblack@google.com cxx_header = 'systemc/ext/core/sc_object.hh' 5212837Sgabeblack@google.com 5312837Sgabeblack@google.com # Clear cxx_base to stop the c++ binding code from assuming 5412837Sgabeblack@google.com # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject 5512837Sgabeblack@google.com # does on the python side. 5612837Sgabeblack@google.com cxx_base = None 5712837Sgabeblack@google.com 5812837Sgabeblack@google.com # Hide the cxx_exports from SimObject since we don't inherit from 5912837Sgabeblack@google.com # SimObject on the c++ side and so don't have those methods to call down 6012837Sgabeblack@google.com # into. 6112837Sgabeblack@google.com locals().update({ 6212837Sgabeblack@google.com method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports 6312837Sgabeblack@google.com }) 6413038Sgabeblack@google.com 6513038Sgabeblack@google.comtry: 6613038Sgabeblack@google.com import _m5 6713038Sgabeblack@google.comexcept: 6813038Sgabeblack@google.com pass 6913038Sgabeblack@google.comelse: 7013038Sgabeblack@google.com import _m5.systemc 7113038Sgabeblack@google.com _m5.systemc.python_ready() 72