summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2012-09-19 06:15:41 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2012-09-19 06:15:41 -0400
commitfccbf8bb45723adb07ebadd52e548e1bcd2cc44a (patch)
treedfd9d5c8ecfcec158db461f85938b9fee0e3b1c2 /src/python
parent33c904e0a560be8c5f9aedaba9940ad0df52d81c (diff)
downloadgem5-fccbf8bb45723adb07ebadd52e548e1bcd2cc44a.tar.xz
AddrRange: Simplify AddrRange params Python hierarchy
This patch simplifies the Range object hierarchy in preparation for an address range class that also allows striping (e.g. selecting a few bits as matching in addition to the range). To extend the AddrRange class to an AddrRegion, the first step is to simplify the hierarchy such that we can make it as lean as possible before adding the new functionality. The only class using Range and MetaRange is AddrRange, and the three classes are now collapsed into one.
Diffstat (limited to 'src/python')
-rw-r--r--src/python/m5/params.py66
1 files changed, 22 insertions, 44 deletions
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index c2da6171e..46c3d028c 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -549,86 +549,64 @@ class Addr(CheckedInt):
else:
return self.value + other
+class AddrRange(ParamValue):
+ cxx_type = 'Range<Addr>'
-class MetaRange(MetaParamValue):
- def __init__(cls, name, bases, dict):
- super(MetaRange, cls).__init__(name, bases, dict)
- if name == 'Range':
- return
- cls.cxx_type = 'Range< %s >' % cls.type.cxx_type
-
-class Range(ParamValue):
- __metaclass__ = MetaRange
- type = Int # default; can be overridden in subclasses
def __init__(self, *args, **kwargs):
def handle_kwargs(self, kwargs):
if 'end' in kwargs:
- self.second = self.type(kwargs.pop('end'))
+ self.end = Addr(kwargs.pop('end'))
elif 'size' in kwargs:
- self.second = self.first + self.type(kwargs.pop('size')) - 1
+ self.end = self.start + Addr(kwargs.pop('size')) - 1
else:
raise TypeError, "Either end or size must be specified"
if len(args) == 0:
- self.first = self.type(kwargs.pop('start'))
+ self.start = Addr(kwargs.pop('start'))
handle_kwargs(self, kwargs)
elif len(args) == 1:
if kwargs:
- self.first = self.type(args[0])
+ self.start = Addr(args[0])
handle_kwargs(self, kwargs)
- elif isinstance(args[0], Range):
- self.first = self.type(args[0].first)
- self.second = self.type(args[0].second)
elif isinstance(args[0], (list, tuple)):
- self.first = self.type(args[0][0])
- self.second = self.type(args[0][1])
+ self.start = Addr(args[0][0])
+ self.end = Addr(args[0][1])
else:
- self.first = self.type(0)
- self.second = self.type(args[0]) - 1
+ self.start = Addr(0)
+ self.end = Addr(args[0]) - 1
elif len(args) == 2:
- self.first = self.type(args[0])
- self.second = self.type(args[1])
+ self.start = Addr(args[0])
+ self.end = Addr(args[1])
else:
raise TypeError, "Too many arguments specified"
if kwargs:
- raise TypeError, "too many keywords: %s" % kwargs.keys()
+ raise TypeError, "Too many keywords: %s" % kwargs.keys()
def __str__(self):
- return '%s:%s' % (self.first, self.second)
+ return '%s:%s' % (self.start, self.end)
+
+ def size(self):
+ return long(self.end) - long(self.start) + 1
@classmethod
def cxx_predecls(cls, code):
- cls.type.cxx_predecls(code)
+ Addr.cxx_predecls(code)
code('#include "base/range.hh"')
@classmethod
def swig_predecls(cls, code):
- cls.type.swig_predecls(code)
+ Addr.swig_predecls(code)
code('%import "python/swig/range.i"')
-class AddrRange(Range):
- type = Addr
-
def getValue(self):
from m5.internal.range import AddrRange
value = AddrRange()
- value.start = long(self.first)
- value.end = long(self.second)
- return value
-
-class TickRange(Range):
- type = Tick
-
- def getValue(self):
- from m5.internal.range import TickRange
-
- value = TickRange()
- value.start = long(self.first)
- value.end = long(self.second)
+ value.start = long(self.start)
+ value.end = long(self.end)
return value
# Boolean parameter type. Python doesn't let you subclass bool, since
@@ -1643,7 +1621,7 @@ __all__ = ['Param', 'VectorParam',
'MemorySize', 'MemorySize32',
'Latency', 'Frequency', 'Clock',
'NetworkBandwidth', 'MemoryBandwidth',
- 'Range', 'AddrRange', 'TickRange',
+ 'AddrRange',
'MaxAddr', 'MaxTick', 'AllMemory',
'Time',
'NextEthernetAddr', 'NULL',