Deleted Added
sdiff udiff text old ( 10201:30a20d2072c1 ) new ( 10267:ed97f6f2ed7a )
full compact
1# Copyright (c) 2012-2013 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

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

88 allParams[name] = cls
89 return cls
90
91
92# Dummy base class to identify types that are legitimate for SimObject
93# parameters.
94class ParamValue(object):
95 __metaclass__ = MetaParamValue
96
97
98 # Generate the code needed as a prerequisite for declaring a C++
99 # object of this type. Typically generates one or more #include
100 # statements. Used when declaring parameters of this type.
101 @classmethod
102 def cxx_predecls(cls, code):
103 pass
104
105 # Generate the code needed as a prerequisite for including a

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

114 def ini_str(self):
115 return str(self)
116
117 # allows us to blithely call unproxy() on things without checking
118 # if they're really proxies or not
119 def unproxy(self, base):
120 return self
121
122# Regular parameter description.
123class ParamDesc(object):
124 def __init__(self, ptype_str, ptype, *args, **kwargs):
125 self.ptype_str = ptype_str
126 # remember ptype only if it is provided
127 if ptype != None:
128 self.ptype = ptype
129

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

157 ptype = SimObject.allClasses[self.ptype_str]
158 assert isSimObjectClass(ptype)
159 self.ptype = ptype
160 return ptype
161
162 raise AttributeError, "'%s' object has no attribute '%s'" % \
163 (type(self).__name__, attr)
164
165 def convert(self, value):
166 if isinstance(value, proxy.BaseProxy):
167 value.set_param_desc(self)
168 return value
169 if not hasattr(self, 'ptype') and isNullPointer(value):
170 # deferred evaluation of SimObject; continue to defer if
171 # we're just assigning a null pointer
172 return value
173 if isinstance(value, self.ptype):
174 return value
175 if isNullPointer(value) and isSimObjectClass(self.ptype):
176 return value
177 return self.ptype(value)
178
179 def cxx_predecls(self, code):
180 code('#include <cstddef>')
181 self.ptype.cxx_predecls(code)
182
183 def swig_predecls(self, code):
184 self.ptype.swig_predecls(code)
185
186 def cxx_decl(self, code):

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

255 def __setitem__(self, key, value):
256 val = self[key]
257 if value.has_parent():
258 warn("SimObject %s already has a parent" % value.get_name() +\
259 " that is being overwritten by a SimObjectVector")
260 value.set_parent(val.get_parent(), val._name)
261 super(SimObjectVector, self).__setitem__(key, value)
262
263class VectorParamDesc(ParamDesc):
264 # Convert assigned value to appropriate type. If the RHS is not a
265 # list or tuple, it generates a single-element list.
266 def convert(self, value):
267 if isinstance(value, (list, tuple)):
268 # list: coerce each element into new list
269 tmp_list = [ ParamDesc.convert(self, v) for v in value ]
270 else:
271 # singleton: coerce to a single-element list
272 tmp_list = [ ParamDesc.convert(self, value) ]
273
274 if isSimObjectSequence(tmp_list):
275 return SimObjectVector(tmp_list)
276 else:
277 return VectorParamValue(tmp_list)
278
279 def swig_module_name(self):
280 return "%s_vector" % self.ptype_str
281
282 def swig_predecls(self, code):
283 code('%import "${{self.swig_module_name()}}.i"')
284
285 def swig_decl(self, code):
286 code('%module(package="m5.internal") ${{self.swig_module_name()}}')

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

344# the __str__() conversion method).
345#
346#####################################################################
347
348# String-valued parameter. Just mixin the ParamValue class with the
349# built-in str class.
350class String(ParamValue,str):
351 cxx_type = 'std::string'
352
353 @classmethod
354 def cxx_predecls(self, code):
355 code('#include <string>')
356
357 @classmethod
358 def swig_predecls(cls, code):
359 code('%include "std_string.i"')
360
361 def getValue(self):
362 return self
363
364# superclass for "numeric" parameter values, to emulate math
365# operations in a type-safe way. e.g., a Latency times an int returns
366# a new Latency object.
367class NumericParamValue(ParamValue):
368 def __str__(self):

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

425 cls.max = (2 ** (cls.size - 1)) - 1
426
427# Abstract superclass for bounds-checked integer parameters. This
428# class is subclassed to generate parameter classes with specific
429# bounds. Initialization of the min and max bounds is done in the
430# metaclass CheckedIntType.__init__.
431class CheckedInt(NumericParamValue):
432 __metaclass__ = CheckedIntType
433
434 def _check(self):
435 if not self.min <= self.value <= self.max:
436 raise TypeError, 'Integer param out of bounds %d < %d < %d' % \
437 (self.min, self.value, self.max)
438
439 def __init__(self, value):
440 if isinstance(value, str):
441 self.value = convert.toInteger(value)
442 elif isinstance(value, (int, long, float, NumericParamValue)):
443 self.value = long(value)
444 else:
445 raise TypeError, "Can't convert object of type %s to CheckedInt" \
446 % type(value).__name__
447 self._check()
448
449 @classmethod
450 def cxx_predecls(cls, code):
451 # most derived types require this, so we just do it here once
452 code('#include "base/types.hh"')
453
454 @classmethod
455 def swig_predecls(cls, code):
456 # most derived types require this, so we just do it here once

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

485 unsigned = True
486
487 def getValue(self):
488 from m5.internal.core import Cycles
489 return Cycles(self.value)
490
491class Float(ParamValue, float):
492 cxx_type = 'double'
493
494 def __init__(self, value):
495 if isinstance(value, (int, long, float, NumericParamValue, Float)):
496 self.value = float(value)
497 else:
498 raise TypeError, "Can't convert object of type %s to Float" \
499 % type(value).__name__
500
501 def getValue(self):
502 return float(self.value)
503
504class MemorySize(CheckedInt):
505 cxx_type = 'uint64_t'
506 size = 64
507 unsigned = True
508 def __init__(self, value):
509 if isinstance(value, MemorySize):
510 self.value = value.value
511 else:
512 self.value = convert.toMemorySize(value)
513 self._check()
514
515class MemorySize32(CheckedInt):
516 cxx_type = 'uint32_t'
517 size = 32
518 unsigned = True
519 def __init__(self, value):
520 if isinstance(value, MemorySize):
521 self.value = value.value
522 else:
523 self.value = convert.toMemorySize(value)
524 self._check()

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

536 except TypeError:
537 self.value = long(value)
538 self._check()
539 def __add__(self, other):
540 if isinstance(other, Addr):
541 return self.value + other.value
542 else:
543 return self.value + other
544
545class AddrRange(ParamValue):
546 cxx_type = 'AddrRange'
547
548 def __init__(self, *args, **kwargs):
549 # Disable interleaving by default
550 self.intlvHighBit = 0
551 self.intlvBits = 0

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

619 int(self.intlvHighBit), int(self.intlvBits),
620 int(self.intlvMatch))
621
622# Boolean parameter type. Python doesn't let you subclass bool, since
623# it doesn't want to let you create multiple instances of True and
624# False. Thus this is a little more complicated than String.
625class Bool(ParamValue):
626 cxx_type = 'bool'
627 def __init__(self, value):
628 try:
629 self.value = convert.toBool(value)
630 except TypeError:
631 self.value = bool(value)
632
633 def getValue(self):
634 return bool(self.value)
635
636 def __str__(self):
637 return str(self.value)
638
639 # implement truth value testing for Bool parameters so that these params
640 # evaluate correctly during the python configuration phase

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

663 global _NextEthernetAddr
664
665 value = _NextEthernetAddr
666 _NextEthernetAddr = IncEthernetAddr(_NextEthernetAddr, 1)
667 return value
668
669class EthernetAddr(ParamValue):
670 cxx_type = 'Net::EthAddr'
671
672 @classmethod
673 def cxx_predecls(cls, code):
674 code('#include "base/inet.hh"')
675
676 @classmethod
677 def swig_predecls(cls, code):
678 code('%include "python/swig/inet.i"')

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

690 raise TypeError, 'invalid ethernet address %s' % value
691
692 for byte in bytes:
693 if not 0 <= int(byte, base=16) <= 0xff:
694 raise TypeError, 'invalid ethernet address %s' % value
695
696 self.value = value
697
698 def unproxy(self, base):
699 if self.value == NextEthernetAddr:
700 return EthernetAddr(self.value())
701 return self
702
703 def getValue(self):
704 from m5.internal.params import EthAddr
705 return EthAddr(self.value)
706
707 def ini_str(self):
708 return self.value
709
710# When initializing an IpAddress, pass in an existing IpAddress, a string of
711# the form "a.b.c.d", or an integer representing an IP.
712class IpAddress(ParamValue):
713 cxx_type = 'Net::IpAddress'
714
715 @classmethod
716 def cxx_predecls(cls, code):
717 code('#include "base/inet.hh"')
718
719 @classmethod
720 def swig_predecls(cls, code):
721 code('%include "python/swig/inet.i"')
722
723 def __init__(self, value):
724 if isinstance(value, IpAddress):
725 self.ip = value.ip
726 else:
727 try:
728 self.ip = convert.toIpAddress(value)
729 except TypeError:
730 self.ip = long(value)
731 self.verifyIp()
732
733 def __str__(self):
734 tup = [(self.ip >> i) & 0xff for i in (24, 16, 8, 0)]
735 return '%d.%d.%d.%d' % tuple(tup)
736
737 def __eq__(self, other):
738 if isinstance(other, IpAddress):
739 return self.ip == other.ip
740 elif isinstance(other, str):

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

756 from m5.internal.params import IpAddress
757 return IpAddress(self.ip)
758
759# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
760# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
761# positional or keyword arguments.
762class IpNetmask(IpAddress):
763 cxx_type = 'Net::IpNetmask'
764
765 @classmethod
766 def cxx_predecls(cls, code):
767 code('#include "base/inet.hh"')
768
769 @classmethod
770 def swig_predecls(cls, code):
771 code('%include "python/swig/inet.i"')

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

801 else:
802 raise TypeError, "Too many arguments specified"
803
804 if kwargs:
805 raise TypeError, "Too many keywords: %s" % kwargs.keys()
806
807 self.verify()
808
809 def __str__(self):
810 return "%s/%d" % (super(IpNetmask, self).__str__(), self.netmask)
811
812 def __eq__(self, other):
813 if isinstance(other, IpNetmask):
814 return self.ip == other.ip and self.netmask == other.netmask
815 elif isinstance(other, str):
816 try:

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

828 def getValue(self):
829 from m5.internal.params import IpNetmask
830 return IpNetmask(self.ip, self.netmask)
831
832# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
833# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
834class IpWithPort(IpAddress):
835 cxx_type = 'Net::IpWithPort'
836
837 @classmethod
838 def cxx_predecls(cls, code):
839 code('#include "base/inet.hh"')
840
841 @classmethod
842 def swig_predecls(cls, code):
843 code('%include "python/swig/inet.i"')

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

873 else:
874 raise TypeError, "Too many arguments specified"
875
876 if kwargs:
877 raise TypeError, "Too many keywords: %s" % kwargs.keys()
878
879 self.verify()
880
881 def __str__(self):
882 return "%s:%d" % (super(IpWithPort, self).__str__(), self.port)
883
884 def __eq__(self, other):
885 if isinstance(other, IpWithPort):
886 return self.ip == other.ip and self.port == other.port
887 elif isinstance(other, str):
888 try:

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

948
949 @classmethod
950 def swig_predecls(cls, code):
951 code('%include "python/swig/time.i"')
952
953 def __init__(self, value):
954 self.value = parse_time(value)
955
956 def getValue(self):
957 from m5.internal.params import tm
958
959 c_time = tm()
960 py_time = self.value
961
962 # UNIX is years since 1900
963 c_time.tm_year = py_time.tm_year - 1900;

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

1106%include "enums/$name.hh"
1107''')
1108
1109
1110# Base class for enum types.
1111class Enum(ParamValue):
1112 __metaclass__ = MetaEnum
1113 vals = []
1114
1115 # The name of the wrapping namespace or struct
1116 wrapper_name = 'Enums'
1117
1118 # If true, the enum is wrapped in a struct rather than a namespace
1119 wrapper_is_struct = False
1120
1121 # If not None, use this as the enum name rather than this class name
1122 enum_name = None
1123
1124 def __init__(self, value):
1125 if value not in self.map:
1126 raise TypeError, "Enum param got bad value '%s' (not in %s)" \
1127 % (value, self.vals)
1128 self.value = value
1129
1130 @classmethod
1131 def cxx_predecls(cls, code):
1132 code('#include "enums/$0.hh"', cls.__name__)
1133
1134 @classmethod
1135 def swig_predecls(cls, code):
1136 code('%import "python/m5/internal/enum_$0.i"', cls.__name__)
1137
1138 def getValue(self):
1139 return int(self.map[self.value])
1140
1141 def __str__(self):
1142 return self.value
1143
1144# how big does a rounding error need to be before we warn about it?
1145frequency_tolerance = 0.001 # 0.1%
1146
1147class TickParamValue(NumericParamValue):
1148 cxx_type = 'Tick'
1149
1150 @classmethod
1151 def cxx_predecls(cls, code):
1152 code('#include "base/types.hh"')
1153
1154 @classmethod
1155 def swig_predecls(cls, code):
1156 code('%import "stdint.i"')
1157 code('%import "base/types.hh"')
1158
1159 def getValue(self):
1160 return long(self.value)
1161
1162class Latency(TickParamValue):
1163 def __init__(self, value):
1164 if isinstance(value, (Latency, Clock)):
1165 self.ticks = value.ticks
1166 self.value = value.value
1167 elif isinstance(value, Frequency):
1168 self.ticks = value.ticks
1169 self.value = 1.0 / value.value
1170 elif value.endswith('t'):
1171 self.ticks = True
1172 self.value = int(value[:-1])
1173 else:
1174 self.ticks = False
1175 self.value = convert.toLatency(value)
1176
1177 def __getattr__(self, attr):
1178 if attr in ('latency', 'period'):
1179 return self
1180 if attr == 'frequency':
1181 return Frequency(self)
1182 raise AttributeError, "Latency object has no attribute '%s'" % attr
1183
1184 def getValue(self):
1185 if self.ticks or self.value == 0:
1186 value = self.value
1187 else:
1188 value = ticks.fromSeconds(self.value)
1189 return long(value)
1190
1191 # convert latency to ticks
1192 def ini_str(self):
1193 return '%d' % self.getValue()
1194
1195class Frequency(TickParamValue):
1196 def __init__(self, value):
1197 if isinstance(value, (Latency, Clock)):
1198 if value.value == 0:
1199 self.value = 0
1200 else:
1201 self.value = 1.0 / value.value
1202 self.ticks = value.ticks
1203 elif isinstance(value, Frequency):
1204 self.value = value.value
1205 self.ticks = value.ticks
1206 else:
1207 self.ticks = False
1208 self.value = convert.toFrequency(value)
1209
1210 def __getattr__(self, attr):
1211 if attr == 'frequency':
1212 return self
1213 if attr in ('latency', 'period'):
1214 return Latency(self)
1215 raise AttributeError, "Frequency object has no attribute '%s'" % attr
1216
1217 # convert latency to ticks

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

1237 self.value = 1.0 / value.value
1238 elif value.endswith('t'):
1239 self.ticks = True
1240 self.value = int(value[:-1])
1241 else:
1242 self.ticks = False
1243 self.value = convert.anyToLatency(value)
1244
1245 def __getattr__(self, attr):
1246 if attr == 'frequency':
1247 return Frequency(self)
1248 if attr in ('latency', 'period'):
1249 return Latency(self)
1250 raise AttributeError, "Frequency object has no attribute '%s'" % attr
1251
1252 def getValue(self):
1253 return self.period.getValue()
1254
1255 def ini_str(self):
1256 return self.period.ini_str()
1257
1258class Voltage(float,ParamValue):
1259 cxx_type = 'double'
1260 def __new__(cls, value):
1261 # convert to voltage
1262 val = convert.toVoltage(value)
1263 return super(cls, Voltage).__new__(cls, val)
1264
1265 def __str__(self):
1266 return str(self.val)
1267
1268 def getValue(self):
1269 value = float(self)
1270 return value
1271
1272 def ini_str(self):
1273 return '%f' % self.getValue()
1274
1275class NetworkBandwidth(float,ParamValue):
1276 cxx_type = 'float'
1277 def __new__(cls, value):
1278 # convert to bits per second
1279 val = convert.toNetworkBandwidth(value)
1280 return super(cls, NetworkBandwidth).__new__(cls, val)
1281
1282 def __str__(self):
1283 return str(self.val)
1284
1285 def getValue(self):
1286 # convert to seconds per byte
1287 value = 8.0 / float(self)
1288 # convert to ticks per byte
1289 value = ticks.fromSeconds(value)
1290 return float(value)
1291
1292 def ini_str(self):
1293 return '%f' % self.getValue()
1294
1295class MemoryBandwidth(float,ParamValue):
1296 cxx_type = 'float'
1297 def __new__(cls, value):
1298 # convert to bytes per second
1299 val = convert.toMemoryBandwidth(value)
1300 return super(cls, MemoryBandwidth).__new__(cls, val)
1301
1302 def __str__(self):
1303 return str(self.val)
1304
1305 def getValue(self):
1306 # convert to seconds per byte
1307 value = float(self)
1308 if value:
1309 value = 1.0 / float(self)
1310 # convert to ticks per byte
1311 value = ticks.fromSeconds(value)

--- 360 unchanged lines hidden ---