SystemC.py revision 13722:4f0de9b591df
112922Sgabeblack@google.com# Copyright 2018 Google, Inc. 212922Sgabeblack@google.com# 312922Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 412922Sgabeblack@google.com# modification, are permitted provided that the following conditions are 512922Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 612922Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 712922Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 812922Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 912922Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1012922Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1112922Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1212922Sgabeblack@google.com# this software without specific prior written permission. 1312922Sgabeblack@google.com# 1412922Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1512922Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1612922Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1712922Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1812922Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1912922Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2012922Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2112922Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2212922Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2312922Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2412922Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2512922Sgabeblack@google.com# 2612922Sgabeblack@google.com# Authors: Gabe Black 2712922Sgabeblack@google.com 2812922Sgabeblack@google.comfrom m5.SimObject import SimObject 2912922Sgabeblack@google.com 3012922Sgabeblack@google.com# This class represents the systemc kernel. There should be exactly one in the 3112922Sgabeblack@google.com# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats, 3212922Sgabeblack@google.com# etc.) and manages the lifecycle of the systemc simulation accordingly. 3312922Sgabeblack@google.com# It also acts as a collecting point for systemc related control functionality. 3412922Sgabeblack@google.comclass SystemC_Kernel(SimObject): 3512922Sgabeblack@google.com type = 'SystemC_Kernel' 3612922Sgabeblack@google.com cxx_class = 'sc_gem5::Kernel' 3712922Sgabeblack@google.com cxx_header = 'systemc/core/kernel.hh' 3812922Sgabeblack@google.com 3912922Sgabeblack@google.com # The sc_time type won't exist until some setup code runs in gem5. 4012922Sgabeblack@google.com try: 4112922Sgabeblack@google.com from _m5.systemc import sc_time 4212922Sgabeblack@google.com except: 4312922Sgabeblack@google.com pass 4412922Sgabeblack@google.com 4512922Sgabeblack@google.com class ScMainResult(object): 4612922Sgabeblack@google.com def __init__(self, code, message): 4712922Sgabeblack@google.com self.code = code 4812922Sgabeblack@google.com self.message = message 4912922Sgabeblack@google.com 5012922Sgabeblack@google.com def sc_main(self, *args): 5112922Sgabeblack@google.com '''Call the systemc sc_main function with the given string args''' 5212922Sgabeblack@google.com from _m5.systemc import sc_main 5312922Sgabeblack@google.com sc_main(*args) 5412922Sgabeblack@google.com 5512922Sgabeblack@google.com def sc_main_result(self): 5612922Sgabeblack@google.com '''Retrieve and return the results of running sc_main''' 5712922Sgabeblack@google.com from _m5.systemc import sc_main_result_code, sc_main_result_str 5812922Sgabeblack@google.com return SystemC_Kernel.ScMainResult( 5912922Sgabeblack@google.com sc_main_result_code(), sc_main_result_str()); 6012922Sgabeblack@google.com 6112922Sgabeblack@google.com# This class represents systemc sc_object instances in python config files. It 6212922Sgabeblack@google.com# inherits from SimObject in python, but the c++ version, sc_core::sc_object, 6312922Sgabeblack@google.com# doesn't inherit from gem5's c++ SimObject class. 6412922Sgabeblack@google.comclass SystemC_ScObject(SimObject): 6512922Sgabeblack@google.com type = 'SystemC_ScObject' 6612922Sgabeblack@google.com abstract = True 6712922Sgabeblack@google.com cxx_class = 'sc_core::sc_object' 6812922Sgabeblack@google.com cxx_header = 'systemc/ext/core/sc_object.hh' 6912922Sgabeblack@google.com 7012922Sgabeblack@google.com # Clear cxx_base to stop the c++ binding code from assuming 7112922Sgabeblack@google.com # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject 7212922Sgabeblack@google.com # does on the python side. 7312922Sgabeblack@google.com cxx_base = None 7412922Sgabeblack@google.com 7512922Sgabeblack@google.com # Hide the cxx_exports from SimObject since we don't inherit from 7612922Sgabeblack@google.com # SimObject on the c++ side and so don't have those methods to call down 7712922Sgabeblack@google.com # into. 7812922Sgabeblack@google.com locals().update({ 7912922Sgabeblack@google.com method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports 8012922Sgabeblack@google.com }) 8112922Sgabeblack@google.com 8212922Sgabeblack@google.comclass SystemC_ScModule(SystemC_ScObject): 8312922Sgabeblack@google.com type = 'SystemC_ScModule' 8412922Sgabeblack@google.com abstract = True 8512922Sgabeblack@google.com cxx_class = 'sc_core::sc_module' 8612922Sgabeblack@google.com cxx_header = 'systemc/ext/core/sc_module.hh' 8712922Sgabeblack@google.com 8812922Sgabeblack@google.comtry: 8912922Sgabeblack@google.com import _m5 9012922Sgabeblack@google.comexcept: 9112922Sgabeblack@google.com pass 9212922Sgabeblack@google.comelse: 9312922Sgabeblack@google.com import _m5.systemc 9412922Sgabeblack@google.com _m5.systemc.python_ready() 9512922Sgabeblack@google.com