SimObject.py (3101:6cce868ddaa6) SimObject.py (3102:225b76c8ac68)
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 15 unchanged lines hidden (view full) ---

24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30import sys, types
31
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 15 unchanged lines hidden (view full) ---

24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30import sys, types
31
32import m5
33from m5 import panic, cc_main
34from convert import *
32from util import *
35from multidict import multidict
36
33from multidict import multidict
34
35# These utility functions have to come first because they're
36# referenced in params.py... otherwise they won't be defined when we
37# import params below, and the recursive import of this file from
38# params.py will not find these names.
39def isSimObject(value):
40 return isinstance(value, SimObject)
41
42def isSimObjectClass(value):
43 return issubclass(value, SimObject)
44
45def isSimObjectSequence(value):
46 if not isinstance(value, (list, tuple)) or len(value) == 0:
47 return False
48
49 for val in value:
50 if not isNullPointer(val) and not isSimObject(val):
51 return False
52
53 return True
54
55def isSimObjectOrSequence(value):
56 return isSimObject(value) or isSimObjectSequence(value)
57
58# Have to import params up top since Param is referenced on initial
59# load (when SimObject class references Param to create a class
60# variable, the 'name' param)...
61from params import *
62# There are a few things we need that aren't in params.__all__ since
63# normal users don't need them
64from params import ParamDesc, isNullPointer, SimObjVector
65
37noDot = False
38try:
39 import pydot
40except:
41 noDot = True
42
43#####################################################################
44#

--- 514 unchanged lines hidden (view full) ---

559 if len(np_child_names):
560 print 'children=%s' % ' '.join(np_child_names)
561
562 param_names = self._params.keys()
563 param_names.sort()
564 for param in param_names:
565 value = self._values.get(param, None)
566 if value != None:
66noDot = False
67try:
68 import pydot
69except:
70 noDot = True
71
72#####################################################################
73#

--- 514 unchanged lines hidden (view full) ---

588 if len(np_child_names):
589 print 'children=%s' % ' '.join(np_child_names)
590
591 param_names = self._params.keys()
592 param_names.sort()
593 for param in param_names:
594 value = self._values.get(param, None)
595 if value != None:
567 if isproxy(value):
596 if proxy.isproxy(value):
568 try:
569 value = value.unproxy(self)
570 except:
571 print >> sys.stderr, \
572 "Error in unproxying param '%s' of %s" % \
573 (param, self.path())
574 raise
575 setattr(self, param, value)

--- 98 unchanged lines hidden (view full) ---

674
675 # recursively dump out children
676 for c in self.children:
677 c.outputDot(dot)
678
679class ParamContext(SimObject):
680 pass
681
597 try:
598 value = value.unproxy(self)
599 except:
600 print >> sys.stderr, \
601 "Error in unproxying param '%s' of %s" % \
602 (param, self.path())
603 raise
604 setattr(self, param, value)

--- 98 unchanged lines hidden (view full) ---

703
704 # recursively dump out children
705 for c in self.children:
706 c.outputDot(dot)
707
708class ParamContext(SimObject):
709 pass
710
682# Special class for NULL pointers. Note the special check in
683# make_param_value() above that lets these be assigned where a
684# SimObject is required.
685# only one copy of a particular node
686class NullSimObject(object):
687 __metaclass__ = Singleton
688
689 def __call__(cls):
690 return cls
691
692 def _instantiate(self, parent = None, path = ''):
693 pass
694
695 def ini_str(self):
696 return 'Null'
697
698 def unproxy(self, base):
699 return self
700
701 def set_path(self, parent, name):
702 pass
703 def __str__(self):
704 return 'Null'
705
706# The only instance you'll ever need...
707Null = NULL = NullSimObject()
708
709def isSimObject(value):
710 return isinstance(value, SimObject)
711
712def isNullPointer(value):
713 return isinstance(value, NullSimObject)
714
715def isSimObjectSequence(value):
716 if not isinstance(value, (list, tuple)) or len(value) == 0:
717 return False
718
719 for val in value:
720 if not isNullPointer(val) and not isSimObject(val):
721 return False
722
723 return True
724
725def isSimObjectOrSequence(value):
726 return isSimObject(value) or isSimObjectSequence(value)
727
728# Function to provide to C++ so it can look up instances based on paths
729def resolveSimObject(name):
730 obj = instanceDict[name]
731 return obj.getCCObject()
732
733# __all__ defines the list of symbols that get exported when
734# 'from config import *' is invoked. Try to keep this reasonably
735# short to avoid polluting other namespaces.
736__all__ = ['SimObject', 'ParamContext']
737
711# Function to provide to C++ so it can look up instances based on paths
712def resolveSimObject(name):
713 obj = instanceDict[name]
714 return obj.getCCObject()
715
716# __all__ defines the list of symbols that get exported when
717# 'from config import *' is invoked. Try to keep this reasonably
718# short to avoid polluting other namespaces.
719__all__ = ['SimObject', 'ParamContext']
720
721
722# see comment on imports at end of __init__.py.
723import proxy
724import cc_main