PlatformConfig.py revision 13731
12100SN/A# Copyright (c) 2012, 2015 ARM Limited 22083SN/A# All rights reserved. 32706Sksewell@umich.edu# 42706Sksewell@umich.edu# Copyright (c) 2017, Centre National de la Recherche Scientifique (CNRS) 52706Sksewell@umich.edu# 62706Sksewell@umich.edu# The license below extends only to copyright in the software and shall 72706Sksewell@umich.edu# not be construed as granting a license to any other intellectual 82706Sksewell@umich.edu# property including but not limited to intellectual property relating 92706Sksewell@umich.edu# to a hardware implementation of the functionality of the software 102706Sksewell@umich.edu# licensed hereunder. You may use the software subject to the license 112706Sksewell@umich.edu# terms below provided that you ensure that this notice is replicated 122706Sksewell@umich.edu# unmodified and in its entirety in all distributions of the software, 132706Sksewell@umich.edu# modified or unmodified, in source code or in binary form. 142706Sksewell@umich.edu# 152706Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without 162706Sksewell@umich.edu# modification, are permitted provided that the following conditions are 172706Sksewell@umich.edu# met: redistributions of source code must retain the above copyright 182706Sksewell@umich.edu# notice, this list of conditions and the following disclaimer; 192706Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright 202706Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the 212706Sksewell@umich.edu# documentation and/or other materials provided with the distribution; 222706Sksewell@umich.edu# neither the name of the copyright holders nor the names of its 232706Sksewell@umich.edu# contributors may be used to endorse or promote products derived from 242706Sksewell@umich.edu# this software without specific prior written permission. 252706Sksewell@umich.edu# 262706Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 272706Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 282706Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 292706Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 302706Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 312089SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 322022SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 332089SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 342022SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 352022SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 362022SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 372083SN/A# 382239SN/A# Authors: Andreas Sandberg 392239SN/A# Pierre-Yves Peneau 402239SN/A 412083SN/Afrom __future__ import print_function 422083SN/A 432083SN/Aimport m5.objects 442083SN/Aimport inspect 452083SN/Aimport sys 462083SN/Afrom m5.util import fatal 472083SN/Afrom textwrap import TextWrapper 482083SN/A 492083SN/A# Dictionary of mapping names of real CPU models to classes. 502089SN/A_platform_classes = {} 512083SN/A 522083SN/A# Platform aliases. The platforms listed here might not be compiled, 532083SN/A# we make sure they exist before we add them to the platform list. 542083SN/A_platform_aliases_all = [ 552089SN/A ("RealView_PBX", "RealViewPBX"), 562083SN/A ("VExpress_GEM5", "VExpress_GEM5_V1"), 572083SN/A ] 582083SN/A 592083SN/A# Filtered list of aliases. Only aliases for existing platforms exist 602083SN/A# in this list. 612083SN/A_platform_aliases = {} 622089SN/A 632083SN/Adef is_platform_class(cls): 642022SN/A """Determine if a class is a Platform that can be instantiated""" 652083SN/A 662022SN/A # We can't use the normal inspect.isclass because the ParamFactory 672083SN/A # and ProxyFactory classes have a tendency to confuse it. 682083SN/A try: 692083SN/A return issubclass(cls, m5.objects.Platform) and \ 702022SN/A not cls.abstract 712083SN/A except (TypeError, AttributeError): 722083SN/A return False 732083SN/A 742083SN/Adef get(name): 752083SN/A """Get a platform class from a user provided class name.""" 762083SN/A 772083SN/A real_name = _platform_aliases.get(name, name) 782089SN/A 792104SN/A try: 802083SN/A return _platform_classes[real_name] 812083SN/A except KeyError: 822083SN/A fatal("%s is not a valid Platform model." % (name,)) 832083SN/A 842104SN/Adef print_platform_list(): 852089SN/A """Print a list of available Platform classes including their aliases.""" 862239SN/A 872239SN/A print("Available Platform classes:") 882239SN/A doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t") 892239SN/A for name, cls in _platform_classes.items(): 902089SN/A print("\t%s" % name) 912089SN/A 922089SN/A # Try to extract the class documentation from the class help 932089SN/A # string. 942089SN/A doc = inspect.getdoc(cls) 952089SN/A if doc: 962089SN/A for line in doc_wrapper.wrap(doc): 972089SN/A print(line) 982089SN/A 992083SN/A if _platform_aliases: 1002089SN/A print("\Platform aliases:") 1012083SN/A for alias, target in _platform_aliases.items(): 1022083SN/A print("\t%s => %s" % (alias, target)) 1032083SN/A 1042083SN/Adef platform_names(): 1052083SN/A """Return a list of valid Platform names.""" 1062083SN/A return list(_platform_classes.keys()) + list(_platform_aliases.keys()) 1072083SN/A 1082083SN/A# Add all Platforms in the object hierarchy. 1092239SN/Afor name, cls in inspect.getmembers(m5.objects, is_platform_class): 1102239SN/A _platform_classes[name] = cls 1112083SN/A 1122083SN/Afor alias, target in _platform_aliases_all: 1132083SN/A if target in _platform_classes: 1142083SN/A _platform_aliases[alias] = target 1152239SN/A