params.py (13594:441bb7a7b2a8) params.py (13663:9b64aeabf9a5)
1# Copyright (c) 2012-2014, 2017, 2018 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

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

150
151 if args:
152 if len(args) == 1:
153 self.desc = args[0]
154 elif len(args) == 2:
155 self.default = args[0]
156 self.desc = args[1]
157 else:
1# Copyright (c) 2012-2014, 2017, 2018 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

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

150
151 if args:
152 if len(args) == 1:
153 self.desc = args[0]
154 elif len(args) == 2:
155 self.default = args[0]
156 self.desc = args[1]
157 else:
158 raise TypeError, 'too many arguments'
158 raise TypeError('too many arguments')
159
160 if kwargs.has_key('desc'):
161 assert(not hasattr(self, 'desc'))
162 self.desc = kwargs['desc']
163 del kwargs['desc']
164
165 if kwargs.has_key('default'):
166 assert(not hasattr(self, 'default'))
167 self.default = kwargs['default']
168 del kwargs['default']
169
170 if kwargs:
159
160 if kwargs.has_key('desc'):
161 assert(not hasattr(self, 'desc'))
162 self.desc = kwargs['desc']
163 del kwargs['desc']
164
165 if kwargs.has_key('default'):
166 assert(not hasattr(self, 'default'))
167 self.default = kwargs['default']
168 del kwargs['default']
169
170 if kwargs:
171 raise TypeError, 'extra unknown kwargs %s' % kwargs
171 raise TypeError('extra unknown kwargs %s' % kwargs)
172
173 if not hasattr(self, 'desc'):
172
173 if not hasattr(self, 'desc'):
174 raise TypeError, 'desc attribute missing'
174 raise TypeError('desc attribute missing')
175
176 def __getattr__(self, attr):
177 if attr == 'ptype':
178 ptype = SimObject.allClasses[self.ptype_str]
179 assert isSimObjectClass(ptype)
180 self.ptype = ptype
181 return ptype
182
175
176 def __getattr__(self, attr):
177 if attr == 'ptype':
178 ptype = SimObject.allClasses[self.ptype_str]
179 assert isSimObjectClass(ptype)
180 self.ptype = ptype
181 return ptype
182
183 raise AttributeError, "'%s' object has no attribute '%s'" % \
184 (type(self).__name__, attr)
183 raise AttributeError("'%s' object has no attribute '%s'" % \
184 (type(self).__name__, attr))
185
186 def example_str(self):
187 if hasattr(self.ptype, "ex_str"):
188 return self.ptype.ex_str
189 else:
190 return self.ptype_str
191
192 # Is the param available to be exposed on the command line

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

229
230# Vector-valued parameter description. Just like ParamDesc, except
231# that the value is a vector (list) of the specified type instead of a
232# single value.
233
234class VectorParamValue(list):
235 __metaclass__ = MetaParamValue
236 def __setattr__(self, attr, value):
185
186 def example_str(self):
187 if hasattr(self.ptype, "ex_str"):
188 return self.ptype.ex_str
189 else:
190 return self.ptype_str
191
192 # Is the param available to be exposed on the command line

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

229
230# Vector-valued parameter description. Just like ParamDesc, except
231# that the value is a vector (list) of the specified type instead of a
232# single value.
233
234class VectorParamValue(list):
235 __metaclass__ = MetaParamValue
236 def __setattr__(self, attr, value):
237 raise AttributeError, \
238 "Not allowed to set %s on '%s'" % (attr, type(self).__name__)
237 raise AttributeError("Not allowed to set %s on '%s'" % \
238 (attr, type(self).__name__))
239
240 def config_value(self):
241 return [v.config_value() for v in self]
242
243 def ini_str(self):
244 return ' '.join([v.ini_str() for v in self])
245
246 def getValue(self):

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

534# bounds. Initialization of the min and max bounds is done in the
535# metaclass CheckedIntType.__init__.
536class CheckedInt(NumericParamValue):
537 __metaclass__ = CheckedIntType
538 cmd_line_settable = True
539
540 def _check(self):
541 if not self.min <= self.value <= self.max:
239
240 def config_value(self):
241 return [v.config_value() for v in self]
242
243 def ini_str(self):
244 return ' '.join([v.ini_str() for v in self])
245
246 def getValue(self):

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

534# bounds. Initialization of the min and max bounds is done in the
535# metaclass CheckedIntType.__init__.
536class CheckedInt(NumericParamValue):
537 __metaclass__ = CheckedIntType
538 cmd_line_settable = True
539
540 def _check(self):
541 if not self.min <= self.value <= self.max:
542 raise TypeError, 'Integer param out of bounds %d < %d < %d' % \
543 (self.min, self.value, self.max)
542 raise TypeError('Integer param out of bounds %d < %d < %d' % \
543 (self.min, self.value, self.max))
544
545 def __init__(self, value):
546 if isinstance(value, str):
547 self.value = convert.toInteger(value)
548 elif isinstance(value, (int, long, float, NumericParamValue)):
549 self.value = long(value)
550 else:
544
545 def __init__(self, value):
546 if isinstance(value, str):
547 self.value = convert.toInteger(value)
548 elif isinstance(value, (int, long, float, NumericParamValue)):
549 self.value = long(value)
550 else:
551 raise TypeError, "Can't convert object of type %s to CheckedInt" \
552 % type(value).__name__
551 raise TypeError("Can't convert object of type %s to CheckedInt" \
552 % type(value).__name__)
553 self._check()
554
555 def __call__(self, value):
556 self.__init__(value)
557 return value
558
559 @classmethod
560 def cxx_predecls(cls, code):

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

609class Float(ParamValue, float):
610 cxx_type = 'double'
611 cmd_line_settable = True
612
613 def __init__(self, value):
614 if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
615 self.value = float(value)
616 else:
553 self._check()
554
555 def __call__(self, value):
556 self.__init__(value)
557 return value
558
559 @classmethod
560 def cxx_predecls(cls, code):

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

609class Float(ParamValue, float):
610 cxx_type = 'double'
611 cmd_line_settable = True
612
613 def __init__(self, value):
614 if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
615 self.value = float(value)
616 else:
617 raise TypeError, "Can't convert object of type %s to Float" \
618 % type(value).__name__
617 raise TypeError("Can't convert object of type %s to Float" \
618 % type(value).__name__)
619
620 def __call__(self, value):
621 self.__init__(value)
622 return value
623
624 def getValue(self):
625 return float(self.value)
626

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

706 # An address range needs to have an upper limit, specified
707 # either explicitly with an end, or as an offset using the
708 # size keyword.
709 if 'end' in kwargs:
710 self.end = Addr(kwargs.pop('end'))
711 elif 'size' in kwargs:
712 self.end = self.start + Addr(kwargs.pop('size')) - 1
713 else:
619
620 def __call__(self, value):
621 self.__init__(value)
622 return value
623
624 def getValue(self):
625 return float(self.value)
626

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

706 # An address range needs to have an upper limit, specified
707 # either explicitly with an end, or as an offset using the
708 # size keyword.
709 if 'end' in kwargs:
710 self.end = Addr(kwargs.pop('end'))
711 elif 'size' in kwargs:
712 self.end = self.start + Addr(kwargs.pop('size')) - 1
713 else:
714 raise TypeError, "Either end or size must be specified"
714 raise TypeError("Either end or size must be specified")
715
716 # Now on to the optional bit
717 if 'intlvHighBit' in kwargs:
718 self.intlvHighBit = int(kwargs.pop('intlvHighBit'))
719 if 'xorHighBit' in kwargs:
720 self.xorHighBit = int(kwargs.pop('xorHighBit'))
721 if 'intlvBits' in kwargs:
722 self.intlvBits = int(kwargs.pop('intlvBits'))

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

737 else:
738 self.start = Addr(0)
739 self.end = Addr(args[0]) - 1
740
741 elif len(args) == 2:
742 self.start = Addr(args[0])
743 self.end = Addr(args[1])
744 else:
715
716 # Now on to the optional bit
717 if 'intlvHighBit' in kwargs:
718 self.intlvHighBit = int(kwargs.pop('intlvHighBit'))
719 if 'xorHighBit' in kwargs:
720 self.xorHighBit = int(kwargs.pop('xorHighBit'))
721 if 'intlvBits' in kwargs:
722 self.intlvBits = int(kwargs.pop('intlvBits'))

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

737 else:
738 self.start = Addr(0)
739 self.end = Addr(args[0]) - 1
740
741 elif len(args) == 2:
742 self.start = Addr(args[0])
743 self.end = Addr(args[1])
744 else:
745 raise TypeError, "Too many arguments specified"
745 raise TypeError("Too many arguments specified")
746
747 if kwargs:
746
747 if kwargs:
748 raise TypeError, "Too many keywords: %s" % kwargs.keys()
748 raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
749
750 def __str__(self):
751 return '%s:%s:%s:%s:%s:%s' \
752 % (self.start, self.end, self.intlvHighBit, self.xorHighBit,\
753 self.intlvBits, self.intlvMatch)
754
755 def size(self):
756 # Divide the size by the size of the interleaving slice

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

880 code('#include "base/inet.hh"')
881
882 def __init__(self, value):
883 if value == NextEthernetAddr:
884 self.value = value
885 return
886
887 if not isinstance(value, str):
749
750 def __str__(self):
751 return '%s:%s:%s:%s:%s:%s' \
752 % (self.start, self.end, self.intlvHighBit, self.xorHighBit,\
753 self.intlvBits, self.intlvMatch)
754
755 def size(self):
756 # Divide the size by the size of the interleaving slice

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

880 code('#include "base/inet.hh"')
881
882 def __init__(self, value):
883 if value == NextEthernetAddr:
884 self.value = value
885 return
886
887 if not isinstance(value, str):
888 raise TypeError, "expected an ethernet address and didn't get one"
888 raise TypeError("expected an ethernet address and didn't get one")
889
890 bytes = value.split(':')
891 if len(bytes) != 6:
889
890 bytes = value.split(':')
891 if len(bytes) != 6:
892 raise TypeError, 'invalid ethernet address %s' % value
892 raise TypeError('invalid ethernet address %s' % value)
893
894 for byte in bytes:
895 if not 0 <= int(byte, base=16) <= 0xff:
893
894 for byte in bytes:
895 if not 0 <= int(byte, base=16) <= 0xff:
896 raise TypeError, 'invalid ethernet address %s' % value
896 raise TypeError('invalid ethernet address %s' % value)
897
898 self.value = value
899
900 def __call__(self, value):
901 self.__init__(value)
902 return value
903
904 def unproxy(self, base):

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

961 else:
962 return self.ip == other
963
964 def __ne__(self, other):
965 return not (self == other)
966
967 def verifyIp(self):
968 if self.ip < 0 or self.ip >= (1 << 32):
897
898 self.value = value
899
900 def __call__(self, value):
901 self.__init__(value)
902 return value
903
904 def unproxy(self, base):

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

961 else:
962 return self.ip == other
963
964 def __ne__(self, other):
965 return not (self == other)
966
967 def verifyIp(self):
968 if self.ip < 0 or self.ip >= (1 << 32):
969 raise TypeError, "invalid ip address %#08x" % self.ip
969 raise TypeError("invalid ip address %#08x" % self.ip)
970
971 def getValue(self):
972 from _m5.net import IpAddress
973 return IpAddress(self.ip)
974
975# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
976# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
977# positional or keyword arguments.

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

986
987 def __init__(self, *args, **kwargs):
988 def handle_kwarg(self, kwargs, key, elseVal = None):
989 if key in kwargs:
990 setattr(self, key, kwargs.pop(key))
991 elif elseVal:
992 setattr(self, key, elseVal)
993 else:
970
971 def getValue(self):
972 from _m5.net import IpAddress
973 return IpAddress(self.ip)
974
975# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
976# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
977# positional or keyword arguments.

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

986
987 def __init__(self, *args, **kwargs):
988 def handle_kwarg(self, kwargs, key, elseVal = None):
989 if key in kwargs:
990 setattr(self, key, kwargs.pop(key))
991 elif elseVal:
992 setattr(self, key, elseVal)
993 else:
994 raise TypeError, "No value set for %s" % key
994 raise TypeError("No value set for %s" % key)
995
996 if len(args) == 0:
997 handle_kwarg(self, kwargs, 'ip')
998 handle_kwarg(self, kwargs, 'netmask')
999
1000 elif len(args) == 1:
1001 if kwargs:
1002 if not 'ip' in kwargs and not 'netmask' in kwargs:
995
996 if len(args) == 0:
997 handle_kwarg(self, kwargs, 'ip')
998 handle_kwarg(self, kwargs, 'netmask')
999
1000 elif len(args) == 1:
1001 if kwargs:
1002 if not 'ip' in kwargs and not 'netmask' in kwargs:
1003 raise TypeError, "Invalid arguments"
1003 raise TypeError("Invalid arguments")
1004 handle_kwarg(self, kwargs, 'ip', args[0])
1005 handle_kwarg(self, kwargs, 'netmask', args[0])
1006 elif isinstance(args[0], IpNetmask):
1007 self.ip = args[0].ip
1008 self.netmask = args[0].netmask
1009 else:
1010 (self.ip, self.netmask) = convert.toIpNetmask(args[0])
1011
1012 elif len(args) == 2:
1013 self.ip = args[0]
1014 self.netmask = args[1]
1015 else:
1004 handle_kwarg(self, kwargs, 'ip', args[0])
1005 handle_kwarg(self, kwargs, 'netmask', args[0])
1006 elif isinstance(args[0], IpNetmask):
1007 self.ip = args[0].ip
1008 self.netmask = args[0].netmask
1009 else:
1010 (self.ip, self.netmask) = convert.toIpNetmask(args[0])
1011
1012 elif len(args) == 2:
1013 self.ip = args[0]
1014 self.netmask = args[1]
1015 else:
1016 raise TypeError, "Too many arguments specified"
1016 raise TypeError("Too many arguments specified")
1017
1018 if kwargs:
1017
1018 if kwargs:
1019 raise TypeError, "Too many keywords: %s" % kwargs.keys()
1019 raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
1020
1021 self.verify()
1022
1023 def __call__(self, value):
1024 self.__init__(value)
1025 return value
1026
1027 def __str__(self):

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

1036 except:
1037 return False
1038 else:
1039 return False
1040
1041 def verify(self):
1042 self.verifyIp()
1043 if self.netmask < 0 or self.netmask > 32:
1020
1021 self.verify()
1022
1023 def __call__(self, value):
1024 self.__init__(value)
1025 return value
1026
1027 def __str__(self):

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

1036 except:
1037 return False
1038 else:
1039 return False
1040
1041 def verify(self):
1042 self.verifyIp()
1043 if self.netmask < 0 or self.netmask > 32:
1044 raise TypeError, "invalid netmask %d" % netmask
1044 raise TypeError("invalid netmask %d" % netmask)
1045
1046 def getValue(self):
1047 from _m5.net import IpNetmask
1048 return IpNetmask(self.ip, self.netmask)
1049
1050# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
1051# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
1052class IpWithPort(IpAddress):

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

1060
1061 def __init__(self, *args, **kwargs):
1062 def handle_kwarg(self, kwargs, key, elseVal = None):
1063 if key in kwargs:
1064 setattr(self, key, kwargs.pop(key))
1065 elif elseVal:
1066 setattr(self, key, elseVal)
1067 else:
1045
1046 def getValue(self):
1047 from _m5.net import IpNetmask
1048 return IpNetmask(self.ip, self.netmask)
1049
1050# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
1051# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
1052class IpWithPort(IpAddress):

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

1060
1061 def __init__(self, *args, **kwargs):
1062 def handle_kwarg(self, kwargs, key, elseVal = None):
1063 if key in kwargs:
1064 setattr(self, key, kwargs.pop(key))
1065 elif elseVal:
1066 setattr(self, key, elseVal)
1067 else:
1068 raise TypeError, "No value set for %s" % key
1068 raise TypeError("No value set for %s" % key)
1069
1070 if len(args) == 0:
1071 handle_kwarg(self, kwargs, 'ip')
1072 handle_kwarg(self, kwargs, 'port')
1073
1074 elif len(args) == 1:
1075 if kwargs:
1076 if not 'ip' in kwargs and not 'port' in kwargs:
1069
1070 if len(args) == 0:
1071 handle_kwarg(self, kwargs, 'ip')
1072 handle_kwarg(self, kwargs, 'port')
1073
1074 elif len(args) == 1:
1075 if kwargs:
1076 if not 'ip' in kwargs and not 'port' in kwargs:
1077 raise TypeError, "Invalid arguments"
1077 raise TypeError("Invalid arguments")
1078 handle_kwarg(self, kwargs, 'ip', args[0])
1079 handle_kwarg(self, kwargs, 'port', args[0])
1080 elif isinstance(args[0], IpWithPort):
1081 self.ip = args[0].ip
1082 self.port = args[0].port
1083 else:
1084 (self.ip, self.port) = convert.toIpWithPort(args[0])
1085
1086 elif len(args) == 2:
1087 self.ip = args[0]
1088 self.port = args[1]
1089 else:
1078 handle_kwarg(self, kwargs, 'ip', args[0])
1079 handle_kwarg(self, kwargs, 'port', args[0])
1080 elif isinstance(args[0], IpWithPort):
1081 self.ip = args[0].ip
1082 self.port = args[0].port
1083 else:
1084 (self.ip, self.port) = convert.toIpWithPort(args[0])
1085
1086 elif len(args) == 2:
1087 self.ip = args[0]
1088 self.port = args[1]
1089 else:
1090 raise TypeError, "Too many arguments specified"
1090 raise TypeError("Too many arguments specified")
1091
1092 if kwargs:
1091
1092 if kwargs:
1093 raise TypeError, "Too many keywords: %s" % kwargs.keys()
1093 raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
1094
1095 self.verify()
1096
1097 def __call__(self, value):
1098 self.__init__(value)
1099 return value
1100
1101 def __str__(self):

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

1110 except:
1111 return False
1112 else:
1113 return False
1114
1115 def verify(self):
1116 self.verifyIp()
1117 if self.port < 0 or self.port > 0xffff:
1094
1095 self.verify()
1096
1097 def __call__(self, value):
1098 self.__init__(value)
1099 return value
1100
1101 def __str__(self):

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

1110 except:
1111 return False
1112 else:
1113 return False
1114
1115 def verify(self):
1116 self.verifyIp()
1117 if self.port < 0 or self.port > 0xffff:
1118 raise TypeError, "invalid port %d" % self.port
1118 raise TypeError("invalid port %d" % self.port)
1119
1120 def getValue(self):
1121 from _m5.net import IpWithPort
1122 return IpWithPort(self.ip, self.port)
1123
1124time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
1125 "%a %b %d %H:%M:%S %Y",
1126 "%Y/%m/%d %H:%M:%S",

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

1152 return time.gmtime(time.time())
1153
1154 for format in time_formats:
1155 try:
1156 return strptime(value, format)
1157 except ValueError:
1158 pass
1159
1119
1120 def getValue(self):
1121 from _m5.net import IpWithPort
1122 return IpWithPort(self.ip, self.port)
1123
1124time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
1125 "%a %b %d %H:%M:%S %Y",
1126 "%Y/%m/%d %H:%M:%S",

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

1152 return time.gmtime(time.time())
1153
1154 for format in time_formats:
1155 try:
1156 return strptime(value, format)
1157 except ValueError:
1158 pass
1159
1160 raise ValueError, "Could not parse '%s' as a time" % value
1160 raise ValueError("Could not parse '%s' as a time" % value)
1161
1162class Time(ParamValue):
1163 cxx_type = 'tm'
1164
1165 @classmethod
1166 def cxx_predecls(cls, code):
1167 code('#include <time.h>')
1168

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

1221
1222 cls = super(MetaEnum, mcls).__new__(mcls, name, bases, dict)
1223 allEnums[name] = cls
1224 return cls
1225
1226 def __init__(cls, name, bases, init_dict):
1227 if init_dict.has_key('map'):
1228 if not isinstance(cls.map, dict):
1161
1162class Time(ParamValue):
1163 cxx_type = 'tm'
1164
1165 @classmethod
1166 def cxx_predecls(cls, code):
1167 code('#include <time.h>')
1168

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

1221
1222 cls = super(MetaEnum, mcls).__new__(mcls, name, bases, dict)
1223 allEnums[name] = cls
1224 return cls
1225
1226 def __init__(cls, name, bases, init_dict):
1227 if init_dict.has_key('map'):
1228 if not isinstance(cls.map, dict):
1229 raise TypeError, "Enum-derived class attribute 'map' " \
1230 "must be of type dict"
1229 raise TypeError("Enum-derived class attribute 'map' " \
1230 "must be of type dict")
1231 # build list of value strings from map
1232 cls.vals = cls.map.keys()
1233 cls.vals.sort()
1234 elif init_dict.has_key('vals'):
1235 if not isinstance(cls.vals, list):
1231 # build list of value strings from map
1232 cls.vals = cls.map.keys()
1233 cls.vals.sort()
1234 elif init_dict.has_key('vals'):
1235 if not isinstance(cls.vals, list):
1236 raise TypeError, "Enum-derived class attribute 'vals' " \
1237 "must be of type list"
1236 raise TypeError("Enum-derived class attribute 'vals' " \
1237 "must be of type list")
1238 # build string->value map from vals sequence
1239 cls.map = {}
1240 for idx,val in enumerate(cls.vals):
1241 cls.map[val] = idx
1242 else:
1238 # build string->value map from vals sequence
1239 cls.map = {}
1240 for idx,val in enumerate(cls.vals):
1241 cls.map[val] = idx
1242 else:
1243 raise TypeError, "Enum-derived class must define "\
1244 "attribute 'map' or 'vals'"
1243 raise TypeError("Enum-derived class must define "\
1244 "attribute 'map' or 'vals'")
1245
1246 if cls.is_class:
1247 cls.cxx_type = '%s' % name
1248 else:
1249 cls.cxx_type = 'Enums::%s' % name
1250
1251 super(MetaEnum, cls).__init__(name, bases, init_dict)
1252

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

1380
1381 is_class = False
1382
1383 # If not None, use this as the enum name rather than this class name
1384 enum_name = None
1385
1386 def __init__(self, value):
1387 if value not in self.map:
1245
1246 if cls.is_class:
1247 cls.cxx_type = '%s' % name
1248 else:
1249 cls.cxx_type = 'Enums::%s' % name
1250
1251 super(MetaEnum, cls).__init__(name, bases, init_dict)
1252

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

1380
1381 is_class = False
1382
1383 # If not None, use this as the enum name rather than this class name
1384 enum_name = None
1385
1386 def __init__(self, value):
1387 if value not in self.map:
1388 raise TypeError, "Enum param got bad value '%s' (not in %s)" \
1389 % (value, self.vals)
1388 raise TypeError("Enum param got bad value '%s' (not in %s)" \
1389 % (value, self.vals))
1390 self.value = value
1391
1392 def __call__(self, value):
1393 self.__init__(value)
1394 return value
1395
1396 @classmethod
1397 def cxx_predecls(cls, code):

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

1486 self.__init__(value)
1487 return value
1488
1489 def __getattr__(self, attr):
1490 if attr in ('latency', 'period'):
1491 return self
1492 if attr == 'frequency':
1493 return Frequency(self)
1390 self.value = value
1391
1392 def __call__(self, value):
1393 self.__init__(value)
1394 return value
1395
1396 @classmethod
1397 def cxx_predecls(cls, code):

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

1486 self.__init__(value)
1487 return value
1488
1489 def __getattr__(self, attr):
1490 if attr in ('latency', 'period'):
1491 return self
1492 if attr == 'frequency':
1493 return Frequency(self)
1494 raise AttributeError, "Latency object has no attribute '%s'" % attr
1494 raise AttributeError("Latency object has no attribute '%s'" % attr)
1495
1496 def getValue(self):
1497 if self.ticks or self.value == 0:
1498 value = self.value
1499 else:
1500 value = ticks.fromSeconds(self.value)
1501 return long(value)
1502

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

1528 self.__init__(value)
1529 return value
1530
1531 def __getattr__(self, attr):
1532 if attr == 'frequency':
1533 return self
1534 if attr in ('latency', 'period'):
1535 return Latency(self)
1495
1496 def getValue(self):
1497 if self.ticks or self.value == 0:
1498 value = self.value
1499 else:
1500 value = ticks.fromSeconds(self.value)
1501 return long(value)
1502

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

1528 self.__init__(value)
1529 return value
1530
1531 def __getattr__(self, attr):
1532 if attr == 'frequency':
1533 return self
1534 if attr in ('latency', 'period'):
1535 return Latency(self)
1536 raise AttributeError, "Frequency object has no attribute '%s'" % attr
1536 raise AttributeError("Frequency object has no attribute '%s'" % attr)
1537
1538 # convert latency to ticks
1539 def getValue(self):
1540 if self.ticks or self.value == 0:
1541 value = self.value
1542 else:
1543 value = ticks.fromSeconds(1.0 / self.value)
1544 return long(value)

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

1573 def __str__(self):
1574 return "%s" % Latency(self)
1575
1576 def __getattr__(self, attr):
1577 if attr == 'frequency':
1578 return Frequency(self)
1579 if attr in ('latency', 'period'):
1580 return Latency(self)
1537
1538 # convert latency to ticks
1539 def getValue(self):
1540 if self.ticks or self.value == 0:
1541 value = self.value
1542 else:
1543 value = ticks.fromSeconds(1.0 / self.value)
1544 return long(value)

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

1573 def __str__(self):
1574 return "%s" % Latency(self)
1575
1576 def __getattr__(self, attr):
1577 if attr == 'frequency':
1578 return Frequency(self)
1579 if attr in ('latency', 'period'):
1580 return Latency(self)
1581 raise AttributeError, "Frequency object has no attribute '%s'" % attr
1581 raise AttributeError("Frequency object has no attribute '%s'" % attr)
1582
1583 def getValue(self):
1584 return self.period.getValue()
1585
1586 def config_value(self):
1587 return self.period.config_value()
1588
1589 def ini_str(self):

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

1795 # for config.json
1796 def get_config_as_dict(self):
1797 return {'role' : self.role, 'peer' : str(self.peer)}
1798
1799 def __getattr__(self, attr):
1800 if attr == 'peerObj':
1801 # shorthand for proxies
1802 return self.peer.simobj
1582
1583 def getValue(self):
1584 return self.period.getValue()
1585
1586 def config_value(self):
1587 return self.period.config_value()
1588
1589 def ini_str(self):

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

1795 # for config.json
1796 def get_config_as_dict(self):
1797 return {'role' : self.role, 'peer' : str(self.peer)}
1798
1799 def __getattr__(self, attr):
1800 if attr == 'peerObj':
1801 # shorthand for proxies
1802 return self.peer.simobj
1803 raise AttributeError, "'%s' object has no attribute '%s'" % \
1804 (self.__class__.__name__, attr)
1803 raise AttributeError("'%s' object has no attribute '%s'" % \
1804 (self.__class__.__name__, attr))
1805
1806 # Full connection is symmetric (both ways). Called via
1807 # SimObject.__setattr__ as a result of a port assignment, e.g.,
1808 # "obj1.portA = obj2.portB", or via VectorPortElementRef.__setitem__,
1809 # e.g., "obj1.portA[3] = obj2.portB".
1810 def connect(self, other):
1811 if isinstance(other, VectorPortRef):
1812 # reference to plain VectorPort is implicit append
1813 other = other._get_next()
1814 if self.peer and not proxy.isproxy(self.peer):
1815 fatal("Port %s is already connected to %s, cannot connect %s\n",
1816 self, self.peer, other);
1817 self.peer = other
1818 if proxy.isproxy(other):
1819 other.set_param_desc(PortParamDesc())
1820 elif isinstance(other, PortRef):
1821 if other.peer is not self:
1822 other.connect(self)
1823 else:
1805
1806 # Full connection is symmetric (both ways). Called via
1807 # SimObject.__setattr__ as a result of a port assignment, e.g.,
1808 # "obj1.portA = obj2.portB", or via VectorPortElementRef.__setitem__,
1809 # e.g., "obj1.portA[3] = obj2.portB".
1810 def connect(self, other):
1811 if isinstance(other, VectorPortRef):
1812 # reference to plain VectorPort is implicit append
1813 other = other._get_next()
1814 if self.peer and not proxy.isproxy(self.peer):
1815 fatal("Port %s is already connected to %s, cannot connect %s\n",
1816 self, self.peer, other);
1817 self.peer = other
1818 if proxy.isproxy(other):
1819 other.set_param_desc(PortParamDesc())
1820 elif isinstance(other, PortRef):
1821 if other.peer is not self:
1822 other.connect(self)
1823 else:
1824 raise TypeError, \
1825 "assigning non-port reference '%s' to port '%s'" \
1826 % (other, self)
1824 raise TypeError("assigning non-port reference '%s' to port '%s'" \
1825 % (other, self))
1827
1828 # Allow a master/slave port pair to be spliced between
1829 # a port and its connected peer. Useful operation for connecting
1830 # instrumentation structures into a system when it is necessary
1831 # to connect the instrumentation after the full system has been
1832 # constructed.
1833 def splice(self, new_master_peer, new_slave_peer):
1834 if not self.peer or proxy.isproxy(self.peer):
1835 fatal("Port %s not connected, cannot splice in new peers\n", self)
1836
1837 if not isinstance(new_master_peer, PortRef) or \
1838 not isinstance(new_slave_peer, PortRef):
1826
1827 # Allow a master/slave port pair to be spliced between
1828 # a port and its connected peer. Useful operation for connecting
1829 # instrumentation structures into a system when it is necessary
1830 # to connect the instrumentation after the full system has been
1831 # constructed.
1832 def splice(self, new_master_peer, new_slave_peer):
1833 if not self.peer or proxy.isproxy(self.peer):
1834 fatal("Port %s not connected, cannot splice in new peers\n", self)
1835
1836 if not isinstance(new_master_peer, PortRef) or \
1837 not isinstance(new_slave_peer, PortRef):
1839 raise TypeError, \
1838 raise TypeError(
1840 "Splicing non-port references '%s','%s' to port '%s'" % \
1839 "Splicing non-port references '%s','%s' to port '%s'" % \
1841 (new_master_peer, new_slave_peer, self)
1840 (new_master_peer, new_slave_peer, self))
1842
1843 old_peer = self.peer
1844 if self.role == 'SLAVE':
1845 self.peer = new_master_peer
1846 old_peer.peer = new_slave_peer
1847 new_master_peer.connect(self)
1848 new_slave_peer.connect(old_peer)
1849 elif self.role == 'MASTER':

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

1887 return
1888
1889 peer = self.peer
1890 if not self.peer: # nothing to connect to
1891 return
1892
1893 # check that we connect a master to a slave
1894 if self.role == peer.role:
1841
1842 old_peer = self.peer
1843 if self.role == 'SLAVE':
1844 self.peer = new_master_peer
1845 old_peer.peer = new_slave_peer
1846 new_master_peer.connect(self)
1847 new_slave_peer.connect(old_peer)
1848 elif self.role == 'MASTER':

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

1886 return
1887
1888 peer = self.peer
1889 if not self.peer: # nothing to connect to
1890 return
1891
1892 # check that we connect a master to a slave
1893 if self.role == peer.role:
1895 raise TypeError, \
1896 "cannot connect '%s' and '%s' due to identical role '%s'" \
1897 % (peer, self, self.role)
1894 raise TypeError(
1895 "cannot connect '%s' and '%s' due to identical role '%s'" % \
1896 (peer, self, self.role))
1898
1899 if self.role == 'SLAVE':
1900 # do nothing and let the master take care of it
1901 return
1902
1903 try:
1904 # self is always the master and peer the slave
1905 connectPorts(self.simobj.getCCObject(), self.name, self.index,

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

1946
1947 # for config.json
1948 def get_config_as_dict(self):
1949 return {'role' : self.role,
1950 'peer' : [el.ini_str() for el in self.elements]}
1951
1952 def __getitem__(self, key):
1953 if not isinstance(key, int):
1897
1898 if self.role == 'SLAVE':
1899 # do nothing and let the master take care of it
1900 return
1901
1902 try:
1903 # self is always the master and peer the slave
1904 connectPorts(self.simobj.getCCObject(), self.name, self.index,

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

1945
1946 # for config.json
1947 def get_config_as_dict(self):
1948 return {'role' : self.role,
1949 'peer' : [el.ini_str() for el in self.elements]}
1950
1951 def __getitem__(self, key):
1952 if not isinstance(key, int):
1954 raise TypeError, "VectorPort index must be integer"
1953 raise TypeError("VectorPort index must be integer")
1955 if key >= len(self.elements):
1956 # need to extend list
1957 ext = [VectorPortElementRef(self.simobj, self.name, self.role, i)
1958 for i in range(len(self.elements), key+1)]
1959 self.elements.extend(ext)
1960 return self.elements[key]
1961
1962 def _get_next(self):
1963 return self[len(self.elements)]
1964
1965 def __setitem__(self, key, value):
1966 if not isinstance(key, int):
1954 if key >= len(self.elements):
1955 # need to extend list
1956 ext = [VectorPortElementRef(self.simobj, self.name, self.role, i)
1957 for i in range(len(self.elements), key+1)]
1958 self.elements.extend(ext)
1959 return self.elements[key]
1960
1961 def _get_next(self):
1962 return self[len(self.elements)]
1963
1964 def __setitem__(self, key, value):
1965 if not isinstance(key, int):
1967 raise TypeError, "VectorPort index must be integer"
1966 raise TypeError("VectorPort index must be integer")
1968 self[key].connect(value)
1969
1970 def connect(self, other):
1971 if isinstance(other, (list, tuple)):
1972 # Assign list of port refs to vector port.
1973 # For now, append them... not sure if that's the right semantics
1974 # or if it should replace the current vector.
1975 for ref in other:

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

2024
2025class MasterPort(Port):
2026 # MasterPort("description")
2027 def __init__(self, *args):
2028 if len(args) == 1:
2029 self.desc = args[0]
2030 self.role = 'MASTER'
2031 else:
1967 self[key].connect(value)
1968
1969 def connect(self, other):
1970 if isinstance(other, (list, tuple)):
1971 # Assign list of port refs to vector port.
1972 # For now, append them... not sure if that's the right semantics
1973 # or if it should replace the current vector.
1974 for ref in other:

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

2023
2024class MasterPort(Port):
2025 # MasterPort("description")
2026 def __init__(self, *args):
2027 if len(args) == 1:
2028 self.desc = args[0]
2029 self.role = 'MASTER'
2030 else:
2032 raise TypeError, 'wrong number of arguments'
2031 raise TypeError('wrong number of arguments')
2033
2034class SlavePort(Port):
2035 # SlavePort("description")
2036 def __init__(self, *args):
2037 if len(args) == 1:
2038 self.desc = args[0]
2039 self.role = 'SLAVE'
2040 else:
2032
2033class SlavePort(Port):
2034 # SlavePort("description")
2035 def __init__(self, *args):
2036 if len(args) == 1:
2037 self.desc = args[0]
2038 self.role = 'SLAVE'
2039 else:
2041 raise TypeError, 'wrong number of arguments'
2040 raise TypeError('wrong number of arguments')
2042
2043# VectorPort description object. Like Port, but represents a vector
2044# of connections (e.g., as on a XBar).
2045class VectorPort(Port):
2046 def __init__(self, *args):
2047 self.isVec = True
2048
2049 def makeRef(self, simobj):
2050 return VectorPortRef(simobj, self.name, self.role)
2051
2052class VectorMasterPort(VectorPort):
2053 # VectorMasterPort("description")
2054 def __init__(self, *args):
2055 if len(args) == 1:
2056 self.desc = args[0]
2057 self.role = 'MASTER'
2058 VectorPort.__init__(self, *args)
2059 else:
2041
2042# VectorPort description object. Like Port, but represents a vector
2043# of connections (e.g., as on a XBar).
2044class VectorPort(Port):
2045 def __init__(self, *args):
2046 self.isVec = True
2047
2048 def makeRef(self, simobj):
2049 return VectorPortRef(simobj, self.name, self.role)
2050
2051class VectorMasterPort(VectorPort):
2052 # VectorMasterPort("description")
2053 def __init__(self, *args):
2054 if len(args) == 1:
2055 self.desc = args[0]
2056 self.role = 'MASTER'
2057 VectorPort.__init__(self, *args)
2058 else:
2060 raise TypeError, 'wrong number of arguments'
2059 raise TypeError('wrong number of arguments')
2061
2062class VectorSlavePort(VectorPort):
2063 # VectorSlavePort("description")
2064 def __init__(self, *args):
2065 if len(args) == 1:
2066 self.desc = args[0]
2067 self.role = 'SLAVE'
2068 VectorPort.__init__(self, *args)
2069 else:
2060
2061class VectorSlavePort(VectorPort):
2062 # VectorSlavePort("description")
2063 def __init__(self, *args):
2064 if len(args) == 1:
2065 self.desc = args[0]
2066 self.role = 'SLAVE'
2067 VectorPort.__init__(self, *args)
2068 else:
2070 raise TypeError, 'wrong number of arguments'
2069 raise TypeError('wrong number of arguments')
2071
2072# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
2073# proxy objects (via set_param_desc()) so that proxy error messages
2074# make sense.
2075class PortParamDesc(object):
2076 __metaclass__ = Singleton
2077
2078 ptype_str = 'Port'

--- 29 unchanged lines hidden ---
2070
2071# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
2072# proxy objects (via set_param_desc()) so that proxy error messages
2073# make sense.
2074class PortParamDesc(object):
2075 __metaclass__ = Singleton
2076
2077 ptype_str = 'Port'

--- 29 unchanged lines hidden ---