diff options
author | Steve Reinhardt <steve.reinhardt@amd.com> | 2010-08-17 05:06:22 -0700 |
---|---|---|
committer | Steve Reinhardt <steve.reinhardt@amd.com> | 2010-08-17 05:06:22 -0700 |
commit | 1fbe466345b43caabece9730c1f0456f1b57b82f (patch) | |
tree | 8285f10d6ab642649d74ae79909508679f264d54 /src/python | |
parent | 0f8b5afd7ad82fda05c3ad42cda4f9046992428d (diff) | |
download | gem5-1fbe466345b43caabece9730c1f0456f1b57b82f.tar.xz |
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.
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/m5/SimObject.py | 2 | ||||
-rw-r--r-- | src/python/m5/simulate.py | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index 3b84d6000..8e14b63d2 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -623,7 +623,7 @@ class SimObject(object): def path(self): if not self._parent: - return 'root' + return '(orphan)' ppath = self._parent.path() if ppath == 'root': return self._name diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index e43f90173..2db5c6952 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -39,13 +39,19 @@ from main import options import SimObject import ticks import objects +from util import fatal # define a MaxTick parameter MaxTick = 2**63 - 1 # The final hook to generate .ini files. Called from the user script # once the config is built. -def instantiate(root): +def instantiate(): + root = objects.Root.getInstance() + + if not root: + fatal("Need to instantiate Root() before calling instantiate()") + # we need to fix the global frequency ticks.fixGlobalFrequency() @@ -136,7 +142,8 @@ def drain(root): def resume(root): root.resume() -def checkpoint(root, dir): +def checkpoint(dir): + root = objects.Root.getInstance() if not isinstance(root, objects.Root): raise TypeError, "Checkpoint must be called on a root object." doDrain(root) @@ -144,7 +151,8 @@ def checkpoint(root, dir): internal.core.serializeAll(dir) resume(root) -def restoreCheckpoint(root, dir): +def restoreCheckpoint(dir): + root = objects.Root.getInstance() print "Restoring from checkpoint" internal.core.unserializeAll(dir) need_resume.append(root) |