SystemC.py revision 13081:fd1b50840830
112027Sjungma@eit.uni-kl.de# Copyright 2018 Google, Inc.
212027Sjungma@eit.uni-kl.de#
312027Sjungma@eit.uni-kl.de# Redistribution and use in source and binary forms, with or without
412027Sjungma@eit.uni-kl.de# modification, are permitted provided that the following conditions are
512027Sjungma@eit.uni-kl.de# met: redistributions of source code must retain the above copyright
612027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer;
712027Sjungma@eit.uni-kl.de# redistributions in binary form must reproduce the above copyright
812027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer in the
912027Sjungma@eit.uni-kl.de# documentation and/or other materials provided with the distribution;
1012027Sjungma@eit.uni-kl.de# neither the name of the copyright holders nor the names of its
1112027Sjungma@eit.uni-kl.de# contributors may be used to endorse or promote products derived from
1212027Sjungma@eit.uni-kl.de# this software without specific prior written permission.
1312027Sjungma@eit.uni-kl.de#
1412027Sjungma@eit.uni-kl.de# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1512027Sjungma@eit.uni-kl.de# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1612027Sjungma@eit.uni-kl.de# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1712027Sjungma@eit.uni-kl.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1812027Sjungma@eit.uni-kl.de# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1912027Sjungma@eit.uni-kl.de# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2012027Sjungma@eit.uni-kl.de# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2112027Sjungma@eit.uni-kl.de# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2212027Sjungma@eit.uni-kl.de# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2312027Sjungma@eit.uni-kl.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2412027Sjungma@eit.uni-kl.de# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2512027Sjungma@eit.uni-kl.de#
2612027Sjungma@eit.uni-kl.de# Authors: Gabe Black
2712027Sjungma@eit.uni-kl.de
2812027Sjungma@eit.uni-kl.defrom m5.SimObject import SimObject
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.de# This class represents the systemc kernel. There should be exactly one in the
3112027Sjungma@eit.uni-kl.de# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats,
3212027Sjungma@eit.uni-kl.de# etc.) and manages the lifecycle of the systemc simulation accordingly.
3312027Sjungma@eit.uni-kl.de# It also acts as a collecting point for systemc related control functionality.
3412027Sjungma@eit.uni-kl.declass SystemC_Kernel(SimObject):
3512027Sjungma@eit.uni-kl.de    type = 'SystemC_Kernel'
3612027Sjungma@eit.uni-kl.de    cxx_class = 'sc_gem5::Kernel'
3712027Sjungma@eit.uni-kl.de    cxx_header = 'systemc/core/kernel.hh'
3812027Sjungma@eit.uni-kl.de
3912027Sjungma@eit.uni-kl.de    class ScMainResult(object):
4012027Sjungma@eit.uni-kl.de        def __init__(self, code, message):
4112027Sjungma@eit.uni-kl.de            self.code = code
4212027Sjungma@eit.uni-kl.de            self.message = message
4312027Sjungma@eit.uni-kl.de
4412027Sjungma@eit.uni-kl.de    def sc_main(self, *args):
4512027Sjungma@eit.uni-kl.de        '''Call the systemc sc_main function with the given string args'''
4612027Sjungma@eit.uni-kl.de        from _m5.systemc import sc_main
4712027Sjungma@eit.uni-kl.de        sc_main(*args)
4812027Sjungma@eit.uni-kl.de
4912027Sjungma@eit.uni-kl.de    def sc_main_result(self):
5012027Sjungma@eit.uni-kl.de        '''Retrieve and return the results of running sc_main'''
5112027Sjungma@eit.uni-kl.de        from _m5.systemc import sc_main_result_code, sc_main_result_str
5212027Sjungma@eit.uni-kl.de        return SystemC_Kernel.ScMainResult(
5312027Sjungma@eit.uni-kl.de                sc_main_result_code(), sc_main_result_str());
5412027Sjungma@eit.uni-kl.de
5512027Sjungma@eit.uni-kl.de# This class represents systemc sc_object instances in python config files. It
5612027Sjungma@eit.uni-kl.de# inherits from SimObject in python, but the c++ version, sc_core::sc_object,
5712027Sjungma@eit.uni-kl.de# doesn't inherit from gem5's c++ SimObject class.
5812027Sjungma@eit.uni-kl.declass SystemC_ScObject(SimObject):
5912027Sjungma@eit.uni-kl.de    type = 'SystemC_ScObject'
6012027Sjungma@eit.uni-kl.de    abstract = True
6112027Sjungma@eit.uni-kl.de    cxx_class = 'sc_core::sc_object'
6212027Sjungma@eit.uni-kl.de    cxx_header = 'systemc/ext/core/sc_object.hh'
6312027Sjungma@eit.uni-kl.de
6412027Sjungma@eit.uni-kl.de    # Clear cxx_base to stop the c++ binding code from assuming
6512027Sjungma@eit.uni-kl.de    # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject
6612027Sjungma@eit.uni-kl.de    # does on the python side.
6712027Sjungma@eit.uni-kl.de    cxx_base = None
6812027Sjungma@eit.uni-kl.de
6912027Sjungma@eit.uni-kl.de    # Hide the cxx_exports from SimObject since we don't inherit from
7012027Sjungma@eit.uni-kl.de    # SimObject on the c++ side and so don't have those methods to call down
7112027Sjungma@eit.uni-kl.de    # into.
7212027Sjungma@eit.uni-kl.de    locals().update({
7312027Sjungma@eit.uni-kl.de        method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports
7412027Sjungma@eit.uni-kl.de    })
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.detry:
7712027Sjungma@eit.uni-kl.de    import _m5
7812027Sjungma@eit.uni-kl.deexcept:
7912027Sjungma@eit.uni-kl.de    pass
8012027Sjungma@eit.uni-kl.deelse:
8112027Sjungma@eit.uni-kl.de    import _m5.systemc
8212027Sjungma@eit.uni-kl.de    _m5.systemc.python_ready()
8312027Sjungma@eit.uni-kl.de