X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fpython%2Fm5%2FSimObject.py;h=9c9a9ed0fe2b9a18a59648076e0b9b82248c018f;hb=392c1ce;hp=b76db5c319cf557d3a2ec6db43485bc008fd257b;hpb=6eb6b346a0ceb157f6703c271d2e9a1f6b6479a3;p=gem5.git diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index b76db5c31..9c9a9ed0f 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2019 ARM Limited +# Copyright (c) 2017-2020 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -40,6 +40,7 @@ from __future__ import print_function from __future__ import absolute_import +from six import add_metaclass import six if six.PY3: long = int @@ -185,11 +186,11 @@ def createCxxConfigDirectoryEntryFile(code, name, simobj, is_header): for port in simobj._ports.values(): is_vector = isinstance(port, m5.params.VectorPort) - is_master = port.role == 'MASTER' + is_requestor = port.role == 'GEM5 REQUESTOR' code('ports["%s"] = new PortDesc("%s", %s, %s);' % (port.name, port.name, cxx_bool(is_vector), - cxx_bool(is_master))) + cxx_bool(is_requestor))) code.dedent() code('}') @@ -466,6 +467,12 @@ class MetaSimObject(type): cls._params = multidict() # param descriptions cls._ports = multidict() # port descriptions + # Parameter names that are deprecated. Dict[str, DeprecatedParam] + # The key is the "old_name" so that when the old_name is used in + # python config files, we will use the DeprecatedParam object to + # translate to the new type. + cls._deprecated_params = multidict() + # class or instance attributes cls._values = multidict() # param values cls._hr_values = multidict() # human readable param values @@ -494,6 +501,7 @@ class MetaSimObject(type): cls._base = base cls._params.parent = base._params cls._ports.parent = base._ports + cls._deprecated_params.parent = base._deprecated_params cls._values.parent = base._values cls._hr_values.parent = base._hr_values cls._children.parent = base._children @@ -531,6 +539,15 @@ class MetaSimObject(type): elif isinstance(val, Port): cls._new_port(key, val) + # Deprecated variable names + elif isinstance(val, DeprecatedParam): + new_name, new_val = cls._get_param_by_value(val.newParam) + # Note: We don't know the (string) name of this variable until + # here, so now we can finish setting up the dep_param. + val.oldName = key + val.newName = new_name + cls._deprecated_params[key] = val + # init-time-only keywords elif key in cls.init_keywords: cls._set_keyword(key, val, cls.init_keywords[key]) @@ -603,6 +620,18 @@ class MetaSimObject(type): cls._port_refs[attr] = ref return ref + def _get_param_by_value(cls, value): + """Given an object, value, return the name and the value from the + internal list of parameter values. If this value can't be found, raise + a runtime error. This will search both the current object and its + parents. + """ + for k,v in cls._value_dict.items(): + if v == value: + return k,v + raise RuntimeError("Cannot find parameter {} in parameter list" + .format(value)) + # Set attribute (called on foo.attr = value when foo is an # instance of class cls). def __setattr__(cls, attr, value): @@ -685,7 +714,7 @@ class MetaSimObject(type): # the object itself, not including inherited params (which # will also be inherited from the base class's param struct # here). Sort the params based on their key - params = map(lambda k_v: k_v[1], sorted(cls._params.local.items())) + params = list(map(lambda k_v: k_v[1], sorted(cls._params.local.items()))) ports = cls._ports.local code('''#include "pybind11/pybind11.h" @@ -782,7 +811,7 @@ module_init(py::module &m_internal) # the object itself, not including inherited params (which # will also be inherited from the base class's param struct # here). Sort the params based on their key - params = map(lambda k_v: k_v[1], sorted(cls._params.local.items())) + params = list(map(lambda k_v: k_v[1], sorted(cls._params.local.items()))) ports = cls._ports.local try: ptypes = [p.ptype for p in params] @@ -1070,13 +1099,16 @@ class SimObjectCliWrapper(object): out.extend(sim_object[i] for i in _range) return SimObjectCliWrapper(out) + def __iter__(self): + return iter(self._sim_objects) + # The SimObject class is the root of the special hierarchy. Most of # the code in this class deals with the configuration hierarchy itself # (parent/child node relationships). +@add_metaclass(MetaSimObject) class SimObject(object): # Specify metaclass. Any class inheriting from SimObject will # get this metaclass. - __metaclass__ = MetaSimObject type = 'SimObject' abstract = True @@ -1251,6 +1283,11 @@ class SimObject(object): return ref def __getattr__(self, attr): + if attr in self._deprecated_params: + dep_param = self._deprecated_params[attr] + dep_param.printWarning(self._name, self.__class__.__name__) + return getattr(self, self._deprecated_params[attr].newName) + if attr in self._ports: return self._get_port_ref(attr) @@ -1283,6 +1320,11 @@ class SimObject(object): object.__setattr__(self, attr, value) return + if attr in self._deprecated_params: + dep_param = self._deprecated_params[attr] + dep_param.printWarning(self._name, self.__class__.__name__) + return setattr(self, self._deprecated_params[attr].newName, value) + if attr in self._ports: # set up port connection self._get_port_ref(attr).connect(value) @@ -1694,6 +1736,18 @@ class SimObject(object): for param in params: exec(param, d) + def get_simobj(self, simobj_path): + """ + Get all sim objects that match a given string. + + The format is the same as that supported by SimObjectCliWrapper. + + :param simobj_path: Current state to be in. + :type simobj_path: str + """ + d = self._apply_config_get_dict() + return eval(simobj_path, d) + # Function to provide to C++ so it can look up instances based on paths def resolveSimObject(name): obj = instanceDict[name]