params.py (9184:a1a8f137b796) params.py (9232:3bb99fab80d4)
1# Copyright (c) 2012 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

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

544 self.value = long(value)
545 self._check()
546 def __add__(self, other):
547 if isinstance(other, Addr):
548 return self.value + other.value
549 else:
550 return self.value + other
551
1# Copyright (c) 2012 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

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

544 self.value = long(value)
545 self._check()
546 def __add__(self, other):
547 if isinstance(other, Addr):
548 return self.value + other.value
549 else:
550 return self.value + other
551
552class AddrRange(ParamValue):
553 cxx_type = 'Range<Addr>'
552
554
553class MetaRange(MetaParamValue):
554 def __init__(cls, name, bases, dict):
555 super(MetaRange, cls).__init__(name, bases, dict)
556 if name == 'Range':
557 return
558 cls.cxx_type = 'Range< %s >' % cls.type.cxx_type
559
560class Range(ParamValue):
561 __metaclass__ = MetaRange
562 type = Int # default; can be overridden in subclasses
563 def __init__(self, *args, **kwargs):
564 def handle_kwargs(self, kwargs):
565 if 'end' in kwargs:
555 def __init__(self, *args, **kwargs):
556 def handle_kwargs(self, kwargs):
557 if 'end' in kwargs:
566 self.second = self.type(kwargs.pop('end'))
558 self.end = Addr(kwargs.pop('end'))
567 elif 'size' in kwargs:
559 elif 'size' in kwargs:
568 self.second = self.first + self.type(kwargs.pop('size')) - 1
560 self.end = self.start + Addr(kwargs.pop('size')) - 1
569 else:
570 raise TypeError, "Either end or size must be specified"
571
572 if len(args) == 0:
561 else:
562 raise TypeError, "Either end or size must be specified"
563
564 if len(args) == 0:
573 self.first = self.type(kwargs.pop('start'))
565 self.start = Addr(kwargs.pop('start'))
574 handle_kwargs(self, kwargs)
575
576 elif len(args) == 1:
577 if kwargs:
566 handle_kwargs(self, kwargs)
567
568 elif len(args) == 1:
569 if kwargs:
578 self.first = self.type(args[0])
570 self.start = Addr(args[0])
579 handle_kwargs(self, kwargs)
571 handle_kwargs(self, kwargs)
580 elif isinstance(args[0], Range):
581 self.first = self.type(args[0].first)
582 self.second = self.type(args[0].second)
583 elif isinstance(args[0], (list, tuple)):
572 elif isinstance(args[0], (list, tuple)):
584 self.first = self.type(args[0][0])
585 self.second = self.type(args[0][1])
573 self.start = Addr(args[0][0])
574 self.end = Addr(args[0][1])
586 else:
575 else:
587 self.first = self.type(0)
588 self.second = self.type(args[0]) - 1
576 self.start = Addr(0)
577 self.end = Addr(args[0]) - 1
589
590 elif len(args) == 2:
578
579 elif len(args) == 2:
591 self.first = self.type(args[0])
592 self.second = self.type(args[1])
580 self.start = Addr(args[0])
581 self.end = Addr(args[1])
593 else:
594 raise TypeError, "Too many arguments specified"
595
596 if kwargs:
582 else:
583 raise TypeError, "Too many arguments specified"
584
585 if kwargs:
597 raise TypeError, "too many keywords: %s" % kwargs.keys()
586 raise TypeError, "Too many keywords: %s" % kwargs.keys()
598
599 def __str__(self):
587
588 def __str__(self):
600 return '%s:%s' % (self.first, self.second)
589 return '%s:%s' % (self.start, self.end)
601
590
591 def size(self):
592 return long(self.end) - long(self.start) + 1
593
602 @classmethod
603 def cxx_predecls(cls, code):
594 @classmethod
595 def cxx_predecls(cls, code):
604 cls.type.cxx_predecls(code)
596 Addr.cxx_predecls(code)
605 code('#include "base/range.hh"')
606
607 @classmethod
608 def swig_predecls(cls, code):
597 code('#include "base/range.hh"')
598
599 @classmethod
600 def swig_predecls(cls, code):
609 cls.type.swig_predecls(code)
601 Addr.swig_predecls(code)
610 code('%import "python/swig/range.i"')
611
602 code('%import "python/swig/range.i"')
603
612class AddrRange(Range):
613 type = Addr
614
615 def getValue(self):
616 from m5.internal.range import AddrRange
617
618 value = AddrRange()
604 def getValue(self):
605 from m5.internal.range import AddrRange
606
607 value = AddrRange()
619 value.start = long(self.first)
620 value.end = long(self.second)
608 value.start = long(self.start)
609 value.end = long(self.end)
621 return value
622
610 return value
611
623class TickRange(Range):
624 type = Tick
625
626 def getValue(self):
627 from m5.internal.range import TickRange
628
629 value = TickRange()
630 value.start = long(self.first)
631 value.end = long(self.second)
632 return value
633
634# Boolean parameter type. Python doesn't let you subclass bool, since
635# it doesn't want to let you create multiple instances of True and
636# False. Thus this is a little more complicated than String.
637class Bool(ParamValue):
638 cxx_type = 'bool'
639 def __init__(self, value):
640 try:
641 self.value = convert.toBool(value)

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

1638 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1639 'Int32', 'UInt32', 'Int64', 'UInt64',
1640 'Counter', 'Addr', 'Tick', 'Percent',
1641 'TcpPort', 'UdpPort', 'EthernetAddr',
1642 'IpAddress', 'IpNetmask', 'IpWithPort',
1643 'MemorySize', 'MemorySize32',
1644 'Latency', 'Frequency', 'Clock',
1645 'NetworkBandwidth', 'MemoryBandwidth',
612# Boolean parameter type. Python doesn't let you subclass bool, since
613# it doesn't want to let you create multiple instances of True and
614# False. Thus this is a little more complicated than String.
615class Bool(ParamValue):
616 cxx_type = 'bool'
617 def __init__(self, value):
618 try:
619 self.value = convert.toBool(value)

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

1616 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1617 'Int32', 'UInt32', 'Int64', 'UInt64',
1618 'Counter', 'Addr', 'Tick', 'Percent',
1619 'TcpPort', 'UdpPort', 'EthernetAddr',
1620 'IpAddress', 'IpNetmask', 'IpWithPort',
1621 'MemorySize', 'MemorySize32',
1622 'Latency', 'Frequency', 'Clock',
1623 'NetworkBandwidth', 'MemoryBandwidth',
1646 'Range', 'AddrRange', 'TickRange',
1624 'AddrRange',
1647 'MaxAddr', 'MaxTick', 'AllMemory',
1648 'Time',
1649 'NextEthernetAddr', 'NULL',
1650 'MasterPort', 'SlavePort',
1651 'VectorMasterPort', 'VectorSlavePort']
1652
1653import SimObject
1625 'MaxAddr', 'MaxTick', 'AllMemory',
1626 'Time',
1627 'NextEthernetAddr', 'NULL',
1628 'MasterPort', 'SlavePort',
1629 'VectorMasterPort', 'VectorSlavePort']
1630
1631import SimObject