SystemC.py revision 13081
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 3913081Sgabeblack@google.com class ScMainResult(object): 4013081Sgabeblack@google.com def __init__(self, code, message): 4113081Sgabeblack@google.com self.code = code 4213081Sgabeblack@google.com self.message = message 4313081Sgabeblack@google.com 4412837Sgabeblack@google.com def sc_main(self, *args): 4512837Sgabeblack@google.com '''Call the systemc sc_main function with the given string args''' 4612837Sgabeblack@google.com from _m5.systemc import sc_main 4712837Sgabeblack@google.com sc_main(*args) 4812837Sgabeblack@google.com 4913081Sgabeblack@google.com def sc_main_result(self): 5013081Sgabeblack@google.com '''Retrieve and return the results of running sc_main''' 5113081Sgabeblack@google.com from _m5.systemc import sc_main_result_code, sc_main_result_str 5213081Sgabeblack@google.com return SystemC_Kernel.ScMainResult( 5313081Sgabeblack@google.com sc_main_result_code(), sc_main_result_str()); 5413081Sgabeblack@google.com 5512837Sgabeblack@google.com# This class represents systemc sc_object instances in python config files. It 5612837Sgabeblack@google.com# inherits from SimObject in python, but the c++ version, sc_core::sc_object, 5712837Sgabeblack@google.com# doesn't inherit from gem5's c++ SimObject class. 5812837Sgabeblack@google.comclass SystemC_ScObject(SimObject): 5912837Sgabeblack@google.com type = 'SystemC_ScObject' 6012837Sgabeblack@google.com abstract = True 6112837Sgabeblack@google.com cxx_class = 'sc_core::sc_object' 6212837Sgabeblack@google.com cxx_header = 'systemc/ext/core/sc_object.hh' 6312837Sgabeblack@google.com 6412837Sgabeblack@google.com # Clear cxx_base to stop the c++ binding code from assuming 6512837Sgabeblack@google.com # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject 6612837Sgabeblack@google.com # does on the python side. 6712837Sgabeblack@google.com cxx_base = None 6812837Sgabeblack@google.com 6912837Sgabeblack@google.com # Hide the cxx_exports from SimObject since we don't inherit from 7012837Sgabeblack@google.com # SimObject on the c++ side and so don't have those methods to call down 7112837Sgabeblack@google.com # into. 7212837Sgabeblack@google.com locals().update({ 7312837Sgabeblack@google.com method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports 7412837Sgabeblack@google.com }) 7513038Sgabeblack@google.com 7613038Sgabeblack@google.comtry: 7713038Sgabeblack@google.com import _m5 7813038Sgabeblack@google.comexcept: 7913038Sgabeblack@google.com pass 8013038Sgabeblack@google.comelse: 8113038Sgabeblack@google.com import _m5.systemc 8213038Sgabeblack@google.com _m5.systemc.python_ready() 83