params.py (13699:2583bda9b2d8) | params.py (13708:ddebb8202119) |
---|---|
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 --- 440 unchanged lines hidden (view full) --- 449 450 def getValue(self): 451 return self 452 453# superclass for "numeric" parameter values, to emulate math 454# operations in a type-safe way. e.g., a Latency times an int returns 455# a new Latency object. 456class NumericParamValue(ParamValue): | 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 --- 440 unchanged lines hidden (view full) --- 449 450 def getValue(self): 451 return self 452 453# superclass for "numeric" parameter values, to emulate math 454# operations in a type-safe way. e.g., a Latency times an int returns 455# a new Latency object. 456class NumericParamValue(ParamValue): |
457 @staticmethod 458 def unwrap(v): 459 return v.value if isinstance(v, NumericParamValue) else v 460 |
|
457 def __str__(self): 458 return str(self.value) 459 460 def __float__(self): 461 return float(self.value) 462 463 def __long__(self): 464 return long(self.value) 465 466 def __int__(self): 467 return int(self.value) 468 469 # hook for bounds checking 470 def _check(self): 471 return 472 473 def __mul__(self, other): 474 newobj = self.__class__(self) | 461 def __str__(self): 462 return str(self.value) 463 464 def __float__(self): 465 return float(self.value) 466 467 def __long__(self): 468 return long(self.value) 469 470 def __int__(self): 471 return int(self.value) 472 473 # hook for bounds checking 474 def _check(self): 475 return 476 477 def __mul__(self, other): 478 newobj = self.__class__(self) |
475 newobj.value *= other | 479 newobj.value *= NumericParamValue.unwrap(other) |
476 newobj._check() 477 return newobj 478 479 __rmul__ = __mul__ 480 | 480 newobj._check() 481 return newobj 482 483 __rmul__ = __mul__ 484 |
481 def __div__(self, other): | 485 def __truediv__(self, other): |
482 newobj = self.__class__(self) | 486 newobj = self.__class__(self) |
483 newobj.value /= other | 487 newobj.value /= NumericParamValue.unwrap(other) |
484 newobj._check() 485 return newobj 486 | 488 newobj._check() 489 return newobj 490 |
491 def __floordiv__(self, other): 492 newobj = self.__class__(self) 493 newobj.value //= NumericParamValue.unwrap(other) 494 newobj._check() 495 return newobj 496 497 498 def __add__(self, other): 499 newobj = self.__class__(self) 500 newobj.value += NumericParamValue.unwrap(other) 501 newobj._check() 502 return newobj 503 |
|
487 def __sub__(self, other): 488 newobj = self.__class__(self) | 504 def __sub__(self, other): 505 newobj = self.__class__(self) |
489 newobj.value -= other | 506 newobj.value -= NumericParamValue.unwrap(other) |
490 newobj._check() 491 return newobj 492 | 507 newobj._check() 508 return newobj 509 |
510 def __iadd__(self, other): 511 self.value += NumericParamValue.unwrap(other) 512 self._check() 513 return self 514 515 def __isub__(self, other): 516 self.value -= NumericParamValue.unwrap(other) 517 self._check() 518 return self 519 520 def __imul__(self, other): 521 self.value *= NumericParamValue.unwrap(other) 522 self._check() 523 return self 524 525 def __itruediv__(self, other): 526 self.value /= NumericParamValue.unwrap(other) 527 self._check() 528 return self 529 530 def __ifloordiv__(self, other): 531 self.value //= NumericParamValue.unwrap(other) 532 self._check() 533 return self 534 535 def __lt__(self, other): 536 return self.value < NumericParamValue.unwrap(other) 537 538 # Python 2.7 pre __future__.division operators 539 # TODO: Remove these when after "import division from __future__" 540 __div__ = __truediv__ 541 __idiv__ = __itruediv__ 542 |
|
493 def config_value(self): 494 return self.value 495 496 @classmethod 497 def cxx_ini_predecls(cls, code): 498 # Assume that base/str.hh will be included anyway 499 # code('#include "base/str.hh"') 500 pass --- 1609 unchanged lines hidden --- | 543 def config_value(self): 544 return self.value 545 546 @classmethod 547 def cxx_ini_predecls(cls, code): 548 # Assume that base/str.hh will be included anyway 549 # code('#include "base/str.hh"') 550 pass --- 1609 unchanged lines hidden --- |