params.py (3101:6cce868ddaa6) | params.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 --- 32 unchanged lines hidden (view full) --- 41# Note that the default values are loaded into the class's attribute 42# space when the parameter dictionary is initialized (in 43# MetaSimObject._new_param()); after that point they aren't used. 44# 45##################################################################### 46 47import sys, inspect, copy 48import convert | 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 --- 32 unchanged lines hidden (view full) --- 41# Note that the default values are loaded into the class's attribute 42# space when the parameter dictionary is initialized (in 43# MetaSimObject._new_param()); after that point they aren't used. 44# 45##################################################################### 46 47import sys, inspect, copy 48import convert |
49from util import * |
|
49 50# Dummy base class to identify types that are legitimate for SimObject 51# parameters. 52class ParamValue(object): 53 54 cxx_predecls = [] 55 swig_predecls = [] 56 --- 38 unchanged lines hidden (view full) --- 95 raise TypeError, 'extra unknown kwargs %s' % kwargs 96 97 if not hasattr(self, 'desc'): 98 raise TypeError, 'desc attribute missing' 99 100 def __getattr__(self, attr): 101 if attr == 'ptype': 102 try: | 50 51# Dummy base class to identify types that are legitimate for SimObject 52# parameters. 53class ParamValue(object): 54 55 cxx_predecls = [] 56 swig_predecls = [] 57 --- 38 unchanged lines hidden (view full) --- 96 raise TypeError, 'extra unknown kwargs %s' % kwargs 97 98 if not hasattr(self, 'desc'): 99 raise TypeError, 'desc attribute missing' 100 101 def __getattr__(self, attr): 102 if attr == 'ptype': 103 try: |
103 ptype = eval(self.ptype_str, m5.objects.__dict__) | 104 ptype = eval(self.ptype_str, objects.__dict__) |
104 if not isinstance(ptype, type): | 105 if not isinstance(ptype, type): |
105 panic("Param qualifier is not a type: %s" % self.ptype) | 106 raise NameError |
106 self.ptype = ptype 107 return ptype 108 except NameError: | 107 self.ptype = ptype 108 return ptype 109 except NameError: |
109 pass | 110 raise TypeError, \ 111 "Param qualifier '%s' is not a type" % self.ptype_str |
110 raise AttributeError, "'%s' object has no attribute '%s'" % \ 111 (type(self).__name__, attr) 112 113 def convert(self, value): 114 if isinstance(value, proxy.BaseProxy): 115 value.set_param_desc(self) 116 return value 117 if not hasattr(self, 'ptype') and isNullPointer(value): 118 # deferred evaluation of SimObject; continue to defer if 119 # we're just assigning a null pointer 120 return value 121 if isinstance(value, self.ptype): 122 return value | 112 raise AttributeError, "'%s' object has no attribute '%s'" % \ 113 (type(self).__name__, attr) 114 115 def convert(self, value): 116 if isinstance(value, proxy.BaseProxy): 117 value.set_param_desc(self) 118 return value 119 if not hasattr(self, 'ptype') and isNullPointer(value): 120 # deferred evaluation of SimObject; continue to defer if 121 # we're just assigning a null pointer 122 return value 123 if isinstance(value, self.ptype): 124 return value |
123 if isNullPointer(value) and issubclass(self.ptype, SimObject): | 125 if isNullPointer(value) and isSimObjectClass(self.ptype): |
124 return value 125 return self.ptype(value) 126 127 def cxx_predecls(self): 128 return self.ptype.cxx_predecls 129 130 def swig_predecls(self): 131 return self.ptype.swig_predecls --- 168 unchanged lines hidden (view full) --- 300 301 def _check(self): 302 if not self.min <= self.value <= self.max: 303 raise TypeError, 'Integer param out of bounds %d < %d < %d' % \ 304 (self.min, self.value, self.max) 305 306 def __init__(self, value): 307 if isinstance(value, str): | 126 return value 127 return self.ptype(value) 128 129 def cxx_predecls(self): 130 return self.ptype.cxx_predecls 131 132 def swig_predecls(self): 133 return self.ptype.swig_predecls --- 168 unchanged lines hidden (view full) --- 302 303 def _check(self): 304 if not self.min <= self.value <= self.max: 305 raise TypeError, 'Integer param out of bounds %d < %d < %d' % \ 306 (self.min, self.value, self.max) 307 308 def __init__(self, value): 309 if isinstance(value, str): |
308 self.value = toInteger(value) | 310 self.value = convert.toInteger(value) |
309 elif isinstance(value, (int, long, float)): 310 self.value = long(value) 311 self._check() 312 313class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False 314class Unsigned(CheckedInt): cxx_type = 'unsigned'; size = 32; unsigned = True 315 316class Int8(CheckedInt): cxx_type = 'int8_t'; size = 8; unsigned = False --- 18 unchanged lines hidden (view full) --- 335class MemorySize(CheckedInt): 336 cxx_type = 'uint64_t' 337 size = 64 338 unsigned = True 339 def __init__(self, value): 340 if isinstance(value, MemorySize): 341 self.value = value.value 342 else: | 311 elif isinstance(value, (int, long, float)): 312 self.value = long(value) 313 self._check() 314 315class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False 316class Unsigned(CheckedInt): cxx_type = 'unsigned'; size = 32; unsigned = True 317 318class Int8(CheckedInt): cxx_type = 'int8_t'; size = 8; unsigned = False --- 18 unchanged lines hidden (view full) --- 337class MemorySize(CheckedInt): 338 cxx_type = 'uint64_t' 339 size = 64 340 unsigned = True 341 def __init__(self, value): 342 if isinstance(value, MemorySize): 343 self.value = value.value 344 else: |
343 self.value = toMemorySize(value) | 345 self.value = convert.toMemorySize(value) |
344 self._check() 345 346class MemorySize32(CheckedInt): 347 size = 32 348 unsigned = True 349 def __init__(self, value): 350 if isinstance(value, MemorySize): 351 self.value = value.value 352 else: | 346 self._check() 347 348class MemorySize32(CheckedInt): 349 size = 32 350 unsigned = True 351 def __init__(self, value): 352 if isinstance(value, MemorySize): 353 self.value = value.value 354 else: |
353 self.value = toMemorySize(value) | 355 self.value = convert.toMemorySize(value) |
354 self._check() 355 356class Addr(CheckedInt): 357 cxx_type = 'Addr' 358 cxx_predecls = ['#include "targetarch/isa_traits.hh"'] 359 size = 64 360 unsigned = True 361 def __init__(self, value): 362 if isinstance(value, Addr): 363 self.value = value.value 364 else: 365 try: | 356 self._check() 357 358class Addr(CheckedInt): 359 cxx_type = 'Addr' 360 cxx_predecls = ['#include "targetarch/isa_traits.hh"'] 361 size = 64 362 unsigned = True 363 def __init__(self, value): 364 if isinstance(value, Addr): 365 self.value = value.value 366 else: 367 try: |
366 self.value = toMemorySize(value) | 368 self.value = convert.toMemorySize(value) |
367 except TypeError: 368 self.value = long(value) 369 self._check() 370 371 372class MetaRange(type): 373 def __init__(cls, name, bases, dict): 374 super(MetaRange, cls).__init__(name, bases, dict) --- 50 unchanged lines hidden (view full) --- 425 426# Boolean parameter type. Python doesn't let you subclass bool, since 427# it doesn't want to let you create multiple instances of True and 428# False. Thus this is a little more complicated than String. 429class Bool(ParamValue): 430 cxx_type = 'bool' 431 def __init__(self, value): 432 try: | 369 except TypeError: 370 self.value = long(value) 371 self._check() 372 373 374class MetaRange(type): 375 def __init__(cls, name, bases, dict): 376 super(MetaRange, cls).__init__(name, bases, dict) --- 50 unchanged lines hidden (view full) --- 427 428# Boolean parameter type. Python doesn't let you subclass bool, since 429# it doesn't want to let you create multiple instances of True and 430# False. Thus this is a little more complicated than String. 431class Bool(ParamValue): 432 cxx_type = 'bool' 433 def __init__(self, value): 434 try: |
433 self.value = toBool(value) | 435 self.value = convert.toBool(value) |
434 except TypeError: 435 self.value = bool(value) 436 437 def __str__(self): 438 return str(self.value) 439 440 def ini_str(self): 441 if self.value: --- 139 unchanged lines hidden (view full) --- 581 582def getLatency(value): 583 if isinstance(value, Latency) or isinstance(value, Clock): 584 return value.value 585 elif isinstance(value, Frequency) or isinstance(value, RootClock): 586 return 1 / value.value 587 elif isinstance(value, str): 588 try: | 436 except TypeError: 437 self.value = bool(value) 438 439 def __str__(self): 440 return str(self.value) 441 442 def ini_str(self): 443 if self.value: --- 139 unchanged lines hidden (view full) --- 583 584def getLatency(value): 585 if isinstance(value, Latency) or isinstance(value, Clock): 586 return value.value 587 elif isinstance(value, Frequency) or isinstance(value, RootClock): 588 return 1 / value.value 589 elif isinstance(value, str): 590 try: |
589 return toLatency(value) | 591 return convert.toLatency(value) |
590 except ValueError: 591 try: | 592 except ValueError: 593 try: |
592 return 1 / toFrequency(value) | 594 return 1 / convert.toFrequency(value) |
593 except ValueError: 594 pass # fall through 595 raise ValueError, "Invalid Frequency/Latency value '%s'" % value 596 597 598class Latency(NumericParamValue): 599 cxx_type = 'Tick' 600 cxx_predecls = ['#include "sim/host.hh"'] --- 72 unchanged lines hidden (view full) --- 673 raise AttributeError, "Frequency object has no attribute '%s'" % attr 674 675 def ini_str(self): 676 return self.period.ini_str() 677 678class NetworkBandwidth(float,ParamValue): 679 cxx_type = 'float' 680 def __new__(cls, value): | 595 except ValueError: 596 pass # fall through 597 raise ValueError, "Invalid Frequency/Latency value '%s'" % value 598 599 600class Latency(NumericParamValue): 601 cxx_type = 'Tick' 602 cxx_predecls = ['#include "sim/host.hh"'] --- 72 unchanged lines hidden (view full) --- 675 raise AttributeError, "Frequency object has no attribute '%s'" % attr 676 677 def ini_str(self): 678 return self.period.ini_str() 679 680class NetworkBandwidth(float,ParamValue): 681 cxx_type = 'float' 682 def __new__(cls, value): |
681 val = toNetworkBandwidth(value) / 8.0 | 683 val = convert.toNetworkBandwidth(value) / 8.0 |
682 return super(cls, NetworkBandwidth).__new__(cls, val) 683 684 def __str__(self): 685 return str(self.val) 686 687 def ini_str(self): 688 return '%f' % (ticks_per_sec / float(self)) 689 690class MemoryBandwidth(float,ParamValue): 691 cxx_type = 'float' 692 def __new__(self, value): | 684 return super(cls, NetworkBandwidth).__new__(cls, val) 685 686 def __str__(self): 687 return str(self.val) 688 689 def ini_str(self): 690 return '%f' % (ticks_per_sec / float(self)) 691 692class MemoryBandwidth(float,ParamValue): 693 cxx_type = 'float' 694 def __new__(self, value): |
693 val = toMemoryBandwidth(value) | 695 val = convert.toMemoryBandwidth(value) |
694 return super(cls, MemoryBandwidth).__new__(cls, val) 695 696 def __str__(self): 697 return str(self.val) 698 699 def ini_str(self): 700 return '%f' % (ticks_per_sec / float(self)) 701 702# 703# "Constants"... handy aliases for various values. 704# 705 | 696 return super(cls, MemoryBandwidth).__new__(cls, val) 697 698 def __str__(self): 699 return str(self.val) 700 701 def ini_str(self): 702 return '%f' % (ticks_per_sec / float(self)) 703 704# 705# "Constants"... handy aliases for various values. 706# 707 |
708# Special class for NULL pointers. Note the special check in 709# make_param_value() above that lets these be assigned where a 710# SimObject is required. 711# only one copy of a particular node 712class NullSimObject(object): 713 __metaclass__ = Singleton 714 715 def __call__(cls): 716 return cls 717 718 def _instantiate(self, parent = None, path = ''): 719 pass 720 721 def ini_str(self): 722 return 'Null' 723 724 def unproxy(self, base): 725 return self 726 727 def set_path(self, parent, name): 728 pass 729 def __str__(self): 730 return 'Null' 731 732# The only instance you'll ever need... 733NULL = NullSimObject() 734 735def isNullPointer(value): 736 return isinstance(value, NullSimObject) 737 |
|
706# Some memory range specifications use this as a default upper bound. 707MaxAddr = Addr.max 708MaxTick = Tick.max 709AllMemory = AddrRange(0, MaxAddr) 710 711 712##################################################################### 713# --- 102 unchanged lines hidden (view full) --- 816 'Int32', 'UInt32', 'Int64', 'UInt64', 817 'Counter', 'Addr', 'Tick', 'Percent', 818 'TcpPort', 'UdpPort', 'EthernetAddr', 819 'MemorySize', 'MemorySize32', 820 'Latency', 'Frequency', 'RootClock', 'Clock', 821 'NetworkBandwidth', 'MemoryBandwidth', 822 'Range', 'AddrRange', 'TickRange', 823 'MaxAddr', 'MaxTick', 'AllMemory', | 738# Some memory range specifications use this as a default upper bound. 739MaxAddr = Addr.max 740MaxTick = Tick.max 741AllMemory = AddrRange(0, MaxAddr) 742 743 744##################################################################### 745# --- 102 unchanged lines hidden (view full) --- 848 'Int32', 'UInt32', 'Int64', 'UInt64', 849 'Counter', 'Addr', 'Tick', 'Percent', 850 'TcpPort', 'UdpPort', 'EthernetAddr', 851 'MemorySize', 'MemorySize32', 852 'Latency', 'Frequency', 'RootClock', 'Clock', 853 'NetworkBandwidth', 'MemoryBandwidth', 854 'Range', 'AddrRange', 'TickRange', 855 'MaxAddr', 'MaxTick', 'AllMemory', |
824 'Null', 'NULL', 825 'NextEthernetAddr', | 856 'NextEthernetAddr', 'NULL', |
826 'Port', 'VectorPort'] 827 828# see comment on imports at end of __init__.py. | 857 'Port', 'VectorPort'] 858 859# see comment on imports at end of __init__.py. |
829from SimObject import SimObject, isSimObject, isSimObjectSequence, \ 830 isNullPointer | 860from SimObject import isSimObject, isSimObjectSequence, isSimObjectClass |
831import proxy | 861import proxy |
862import objects 863import cc_main |
|