SystemC.py revision 13722:4f0de9b591df
14484Sbinkertn@umich.edu# Copyright 2018 Google, Inc. 24484Sbinkertn@umich.edu# 34484Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 44484Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 54484Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 64484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 74484Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 84484Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 94484Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 104484Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 114484Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 124484Sbinkertn@umich.edu# this software without specific prior written permission. 134484Sbinkertn@umich.edu# 144484Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 154484Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 164484Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 174484Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 184484Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 194484Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 204484Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 214484Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 224484Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 234484Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 244484Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 254484Sbinkertn@umich.edu# 264484Sbinkertn@umich.edu# Authors: Gabe Black 274484Sbinkertn@umich.edu 284484Sbinkertn@umich.edufrom m5.SimObject import SimObject 294484Sbinkertn@umich.edu 304484Sbinkertn@umich.edu# This class represents the systemc kernel. There should be exactly one in the 314494Ssaidi@eecs.umich.edu# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats, 324484Sbinkertn@umich.edu# etc.) and manages the lifecycle of the systemc simulation accordingly. 336121Snate@binkert.org# It also acts as a collecting point for systemc related control functionality. 344484Sbinkertn@umich.educlass SystemC_Kernel(SimObject): 358946Sandreas.hansson@arm.com type = 'SystemC_Kernel' 368946Sandreas.hansson@arm.com cxx_class = 'sc_gem5::Kernel' 374484Sbinkertn@umich.edu cxx_header = 'systemc/core/kernel.hh' 384484Sbinkertn@umich.edu 394484Sbinkertn@umich.edu # The sc_time type won't exist until some setup code runs in gem5. 404781Snate@binkert.org try: 414484Sbinkertn@umich.edu from _m5.systemc import sc_time 424484Sbinkertn@umich.edu except: 434484Sbinkertn@umich.edu pass 444484Sbinkertn@umich.edu 458349Sgblack@eecs.umich.edu class ScMainResult(object): 468349Sgblack@eecs.umich.edu def __init__(self, code, message): 474484Sbinkertn@umich.edu self.code = code 484484Sbinkertn@umich.edu self.message = message 494484Sbinkertn@umich.edu 504484Sbinkertn@umich.edu def sc_main(self, *args): 514484Sbinkertn@umich.edu '''Call the systemc sc_main function with the given string args''' 524484Sbinkertn@umich.edu from _m5.systemc import sc_main 534484Sbinkertn@umich.edu sc_main(*args) 544484Sbinkertn@umich.edu 554484Sbinkertn@umich.edu def sc_main_result(self): 564484Sbinkertn@umich.edu '''Retrieve and return the results of running sc_main''' 574484Sbinkertn@umich.edu from _m5.systemc import sc_main_result_code, sc_main_result_str 584484Sbinkertn@umich.edu return SystemC_Kernel.ScMainResult( 594484Sbinkertn@umich.edu sc_main_result_code(), sc_main_result_str()); 604484Sbinkertn@umich.edu 614484Sbinkertn@umich.edu# This class represents systemc sc_object instances in python config files. It 624484Sbinkertn@umich.edu# inherits from SimObject in python, but the c++ version, sc_core::sc_object, 634484Sbinkertn@umich.edu# doesn't inherit from gem5's c++ SimObject class. 644484Sbinkertn@umich.educlass SystemC_ScObject(SimObject): 654484Sbinkertn@umich.edu type = 'SystemC_ScObject' 664484Sbinkertn@umich.edu abstract = True 674484Sbinkertn@umich.edu cxx_class = 'sc_core::sc_object' 684484Sbinkertn@umich.edu cxx_header = 'systemc/ext/core/sc_object.hh' 694484Sbinkertn@umich.edu 704484Sbinkertn@umich.edu # Clear cxx_base to stop the c++ binding code from assuming 714484Sbinkertn@umich.edu # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject 724484Sbinkertn@umich.edu # does on the python side. 734484Sbinkertn@umich.edu cxx_base = None 744484Sbinkertn@umich.edu 754484Sbinkertn@umich.edu # Hide the cxx_exports from SimObject since we don't inherit from 764484Sbinkertn@umich.edu # SimObject on the c++ side and so don't have those methods to call down 774484Sbinkertn@umich.edu # into. 784484Sbinkertn@umich.edu locals().update({ 794484Sbinkertn@umich.edu method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports 804484Sbinkertn@umich.edu }) 814484Sbinkertn@umich.edu 824484Sbinkertn@umich.educlass SystemC_ScModule(SystemC_ScObject): 834484Sbinkertn@umich.edu type = 'SystemC_ScModule' 844484Sbinkertn@umich.edu abstract = True 854484Sbinkertn@umich.edu cxx_class = 'sc_core::sc_module' 864484Sbinkertn@umich.edu cxx_header = 'systemc/ext/core/sc_module.hh' 874484Sbinkertn@umich.edu 884484Sbinkertn@umich.edutry: 894484Sbinkertn@umich.edu import _m5 904484Sbinkertn@umich.eduexcept: 914484Sbinkertn@umich.edu pass 924484Sbinkertn@umich.eduelse: 934484Sbinkertn@umich.edu import _m5.systemc 946121Snate@binkert.org _m5.systemc.python_ready() 956121Snate@binkert.org