SystemC.py revision 13331:2e3f70431e60
110259SAndrew.Bardsley@arm.com# Copyright 2018 Google, Inc.
213954Sgiacomo.gabrielli@arm.com#
310259SAndrew.Bardsley@arm.com# Redistribution and use in source and binary forms, with or without
410259SAndrew.Bardsley@arm.com# modification, are permitted provided that the following conditions are
510259SAndrew.Bardsley@arm.com# met: redistributions of source code must retain the above copyright
610259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer;
710259SAndrew.Bardsley@arm.com# redistributions in binary form must reproduce the above copyright
810259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer in the
910259SAndrew.Bardsley@arm.com# documentation and/or other materials provided with the distribution;
1010259SAndrew.Bardsley@arm.com# neither the name of the copyright holders nor the names of its
1110259SAndrew.Bardsley@arm.com# contributors may be used to endorse or promote products derived from
1210259SAndrew.Bardsley@arm.com# this software without specific prior written permission.
1310259SAndrew.Bardsley@arm.com#
1410259SAndrew.Bardsley@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1510259SAndrew.Bardsley@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1610259SAndrew.Bardsley@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1710259SAndrew.Bardsley@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1810259SAndrew.Bardsley@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1910259SAndrew.Bardsley@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2010259SAndrew.Bardsley@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2110259SAndrew.Bardsley@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2210259SAndrew.Bardsley@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2310259SAndrew.Bardsley@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2410259SAndrew.Bardsley@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2510259SAndrew.Bardsley@arm.com#
2610259SAndrew.Bardsley@arm.com# Authors: Gabe Black
2710259SAndrew.Bardsley@arm.com
2810259SAndrew.Bardsley@arm.comfrom m5.SimObject import SimObject
2910259SAndrew.Bardsley@arm.com
3010259SAndrew.Bardsley@arm.com# This class represents the systemc kernel. There should be exactly one in the
3110259SAndrew.Bardsley@arm.com# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats,
3210259SAndrew.Bardsley@arm.com# etc.) and manages the lifecycle of the systemc simulation accordingly.
3310259SAndrew.Bardsley@arm.com# It also acts as a collecting point for systemc related control functionality.
3410259SAndrew.Bardsley@arm.comclass SystemC_Kernel(SimObject):
3510259SAndrew.Bardsley@arm.com    type = 'SystemC_Kernel'
3610259SAndrew.Bardsley@arm.com    cxx_class = 'sc_gem5::Kernel'
3710259SAndrew.Bardsley@arm.com    cxx_header = 'systemc/core/kernel.hh'
3810259SAndrew.Bardsley@arm.com
3910259SAndrew.Bardsley@arm.com    class ScMainResult(object):
4011793Sbrandon.potter@amd.com        def __init__(self, code, message):
4111793Sbrandon.potter@amd.com            self.code = code
4210259SAndrew.Bardsley@arm.com            self.message = message
4310259SAndrew.Bardsley@arm.com
4410259SAndrew.Bardsley@arm.com    def sc_main(self, *args):
4510259SAndrew.Bardsley@arm.com        '''Call the systemc sc_main function with the given string args'''
4610259SAndrew.Bardsley@arm.com        from _m5.systemc import sc_main
4713449Sgabeblack@google.com        sc_main(*args)
4810259SAndrew.Bardsley@arm.com
4910259SAndrew.Bardsley@arm.com    def sc_main_result(self):
5010259SAndrew.Bardsley@arm.com        '''Retrieve and return the results of running sc_main'''
5110259SAndrew.Bardsley@arm.com        from _m5.systemc import sc_main_result_code, sc_main_result_str
5213954Sgiacomo.gabrielli@arm.com        return SystemC_Kernel.ScMainResult(
5310259SAndrew.Bardsley@arm.com                sc_main_result_code(), sc_main_result_str());
5410259SAndrew.Bardsley@arm.com
5510259SAndrew.Bardsley@arm.com# This class represents systemc sc_object instances in python config files. It
5610259SAndrew.Bardsley@arm.com# inherits from SimObject in python, but the c++ version, sc_core::sc_object,
5710259SAndrew.Bardsley@arm.com# doesn't inherit from gem5's c++ SimObject class.
5810259SAndrew.Bardsley@arm.comclass SystemC_ScObject(SimObject):
5910259SAndrew.Bardsley@arm.com    type = 'SystemC_ScObject'
6010259SAndrew.Bardsley@arm.com    abstract = True
6110259SAndrew.Bardsley@arm.com    cxx_class = 'sc_core::sc_object'
6210259SAndrew.Bardsley@arm.com    cxx_header = 'systemc/ext/core/sc_object.hh'
6310259SAndrew.Bardsley@arm.com
6410259SAndrew.Bardsley@arm.com    # Clear cxx_base to stop the c++ binding code from assuming
6510259SAndrew.Bardsley@arm.com    # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject
6610259SAndrew.Bardsley@arm.com    # does on the python side.
6710259SAndrew.Bardsley@arm.com    cxx_base = None
6810259SAndrew.Bardsley@arm.com
6910259SAndrew.Bardsley@arm.com    # Hide the cxx_exports from SimObject since we don't inherit from
7010259SAndrew.Bardsley@arm.com    # SimObject on the c++ side and so don't have those methods to call down
7114105Sgabor.dozsa@arm.com    # into.
7210259SAndrew.Bardsley@arm.com    locals().update({
7312749Sgiacomo.travaglini@arm.com        method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports
7412749Sgiacomo.travaglini@arm.com    })
7512749Sgiacomo.travaglini@arm.com
7610259SAndrew.Bardsley@arm.comclass SystemC_ScModule(SystemC_ScObject):
7713954Sgiacomo.gabrielli@arm.com    type = 'SystemC_ScModule'
7814105Sgabor.dozsa@arm.com    abstract = True
7914105Sgabor.dozsa@arm.com    cxx_class = 'sc_core::sc_module'
8014105Sgabor.dozsa@arm.com    cxx_header = 'systemc/ext/core/sc_module.hh'
8114105Sgabor.dozsa@arm.com
8214105Sgabor.dozsa@arm.comtry:
8314105Sgabor.dozsa@arm.com    import _m5
8414105Sgabor.dozsa@arm.comexcept:
8514105Sgabor.dozsa@arm.com    pass
8614105Sgabor.dozsa@arm.comelse:
8714105Sgabor.dozsa@arm.com    import _m5.systemc
8814105Sgabor.dozsa@arm.com    _m5.systemc.python_ready()
8914105Sgabor.dozsa@arm.com