From 1fbe466345b43caabece9730c1f0456f1b57b82f Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Tue, 17 Aug 2010 05:06:22 -0700 Subject: sim: make Python Root object a singleton Enforce that the Python Root SimObject is instantiated only once. The C++ Root object already panics if more than one is created. This change avoids the need to track what the root object is, since it's available from Root.getInstance() (if it exists). It's now redundant to have the user pass the root object to functions like instantiate(), checkpoint(), and restoreCheckpoint(), so that arg is gone. Users who use configs/common/Simulate.py should not notice. --- src/sim/Root.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/sim/Root.py') diff --git a/src/sim/Root.py b/src/sim/Root.py index fff998e0d..c7404a11f 100644 --- a/src/sim/Root.py +++ b/src/sim/Root.py @@ -28,7 +28,32 @@ from m5.SimObject import SimObject from m5.params import * +from m5.util import fatal class Root(SimObject): + + _the_instance = None + + def __new__(cls, **kwargs): + if Root._the_instance: + fatal("Attempt to allocate multiple instances of Root.") + return None + + # first call: allocate the unique instance + # + # If SimObject ever implements __new__, we may want to pass + # kwargs here, but for now this goes straight to + # object.__new__ which prints an ugly warning if you pass it + # args. Seems like a bad design but that's the way it is. + Root._the_instance = SimObject.__new__(cls) + return Root._the_instance + + @classmethod + def getInstance(cls): + return Root._the_instance + + def path(self): + return 'root' + type = 'Root' dummy = Param.Int(0, "We don't support objects without params") -- cgit v1.2.3