params.py (10427:26fee6c20087) params.py (10458:64809024b924)
1# Copyright (c) 2012-2014 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

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

115 return str(self)
116
117 # default for printing to .json file is regular string conversion.
118 # will be overridden in some cases, mostly to use native Python
119 # types where there are similar JSON types
120 def config_value(self):
121 return str(self)
122
1# Copyright (c) 2012-2014 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

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

115 return str(self)
116
117 # default for printing to .json file is regular string conversion.
118 # will be overridden in some cases, mostly to use native Python
119 # types where there are similar JSON types
120 def config_value(self):
121 return str(self)
122
123 # Prerequisites for .ini parsing with cxx_ini_parse
124 @classmethod
125 def cxx_ini_predecls(cls, code):
126 pass
127
128 # parse a .ini file entry for this param from string expression
129 # src into lvalue dest (of the param's C++ type)
130 @classmethod
131 def cxx_ini_parse(cls, code, src, dest, ret):
132 code('// Unhandled param type: %s' % cls.__name__)
133 code('%s false;' % ret)
134
123 # allows us to blithely call unproxy() on things without checking
124 # if they're really proxies or not
125 def unproxy(self, base):
126 return self
127
128 # Produce a human readable version of the stored value
129 def pretty_print(self, value):
130 return str(value)

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

449 @classmethod
450 def swig_predecls(cls, code):
451 code('%include "std_string.i"')
452
453 def __call__(self, value):
454 self = value
455 return value
456
135 # allows us to blithely call unproxy() on things without checking
136 # if they're really proxies or not
137 def unproxy(self, base):
138 return self
139
140 # Produce a human readable version of the stored value
141 def pretty_print(self, value):
142 return str(value)

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

461 @classmethod
462 def swig_predecls(cls, code):
463 code('%include "std_string.i"')
464
465 def __call__(self, value):
466 self = value
467 return value
468
469 @classmethod
470 def cxx_ini_parse(self, code, src, dest, ret):
471 code('%s = %s;' % (dest, src))
472 code('%s true;' % ret)
473
457 def getValue(self):
458 return self
459
460# superclass for "numeric" parameter values, to emulate math
461# operations in a type-safe way. e.g., a Latency times an int returns
462# a new Latency object.
463class NumericParamValue(ParamValue):
464 def __str__(self):

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

495 newobj = self.__class__(self)
496 newobj.value -= other
497 newobj._check()
498 return newobj
499
500 def config_value(self):
501 return self.value
502
474 def getValue(self):
475 return self
476
477# superclass for "numeric" parameter values, to emulate math
478# operations in a type-safe way. e.g., a Latency times an int returns
479# a new Latency object.
480class NumericParamValue(ParamValue):
481 def __str__(self):

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

512 newobj = self.__class__(self)
513 newobj.value -= other
514 newobj._check()
515 return newobj
516
517 def config_value(self):
518 return self.value
519
520 @classmethod
521 def cxx_ini_predecls(cls, code):
522 # Assume that base/str.hh will be included anyway
523 # code('#include "base/str.hh"')
524 pass
525
526 # The default for parsing PODs from an .ini entry is to extract from an
527 # istringstream and let overloading choose the right type according to
528 # the dest type.
529 @classmethod
530 def cxx_ini_parse(self, code, src, dest, ret):
531 code('%s to_number(%s, %s);' % (ret, src, dest))
532
503# Metaclass for bounds-checked integer parameters. See CheckedInt.
504class CheckedIntType(MetaParamValue):
505 def __init__(cls, name, bases, dict):
506 super(CheckedIntType, cls).__init__(name, bases, dict)
507
508 # CheckedInt is an abstract base class, so we actually don't
509 # want to do any processing on it... the rest of this code is
510 # just for classes that derive from CheckedInt.

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

587 cxx_type = 'Cycles'
588 size = 64
589 unsigned = True
590
591 def getValue(self):
592 from m5.internal.core import Cycles
593 return Cycles(self.value)
594
533# Metaclass for bounds-checked integer parameters. See CheckedInt.
534class CheckedIntType(MetaParamValue):
535 def __init__(cls, name, bases, dict):
536 super(CheckedIntType, cls).__init__(name, bases, dict)
537
538 # CheckedInt is an abstract base class, so we actually don't
539 # want to do any processing on it... the rest of this code is
540 # just for classes that derive from CheckedInt.

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

617 cxx_type = 'Cycles'
618 size = 64
619 unsigned = True
620
621 def getValue(self):
622 from m5.internal.core import Cycles
623 return Cycles(self.value)
624
625 @classmethod
626 def cxx_ini_predecls(cls, code):
627 # Assume that base/str.hh will be included anyway
628 # code('#include "base/str.hh"')
629 pass
630
631 @classmethod
632 def cxx_ini_parse(cls, code, src, dest, ret):
633 code('uint64_t _temp;')
634 code('bool _ret = to_number(%s, _temp);' % src)
635 code('if (_ret)')
636 code(' %s = Cycles(_temp);' % dest)
637 code('%s _ret;' % ret)
638
595class Float(ParamValue, float):
596 cxx_type = 'double'
597 cmdLineSettable = True
598
599 def __init__(self, value):
600 if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
601 self.value = float(value)
602 else:

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

608 return value
609
610 def getValue(self):
611 return float(self.value)
612
613 def config_value(self):
614 return self
615
639class Float(ParamValue, float):
640 cxx_type = 'double'
641 cmdLineSettable = True
642
643 def __init__(self, value):
644 if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
645 self.value = float(value)
646 else:

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

652 return value
653
654 def getValue(self):
655 return float(self.value)
656
657 def config_value(self):
658 return self
659
660 @classmethod
661 def cxx_ini_predecls(cls, code):
662 code('#include <sstream>')
663
664 @classmethod
665 def cxx_ini_parse(self, code, src, dest, ret):
666 code('%s (std::istringstream(%s) >> %s).eof();' % (ret, src, dest))
667
616class MemorySize(CheckedInt):
617 cxx_type = 'uint64_t'
618 ex_str = '512MB'
619 size = 64
620 unsigned = True
621 def __init__(self, value):
622 if isinstance(value, MemorySize):
623 self.value = value.value

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

733 def cxx_predecls(cls, code):
734 Addr.cxx_predecls(code)
735 code('#include "base/addr_range.hh"')
736
737 @classmethod
738 def swig_predecls(cls, code):
739 Addr.swig_predecls(code)
740
668class MemorySize(CheckedInt):
669 cxx_type = 'uint64_t'
670 ex_str = '512MB'
671 size = 64
672 unsigned = True
673 def __init__(self, value):
674 if isinstance(value, MemorySize):
675 self.value = value.value

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

785 def cxx_predecls(cls, code):
786 Addr.cxx_predecls(code)
787 code('#include "base/addr_range.hh"')
788
789 @classmethod
790 def swig_predecls(cls, code):
791 Addr.swig_predecls(code)
792
793 @classmethod
794 def cxx_ini_predecls(cls, code):
795 code('#include <sstream>')
796
797 @classmethod
798 def cxx_ini_parse(cls, code, src, dest, ret):
799 code('uint64_t _start, _end;')
800 code('char _sep;')
801 code('std::istringstream _stream(${src});')
802 code('_stream >> _start;')
803 code('_stream.get(_sep);')
804 code('_stream >> _end;')
805 code('bool _ret = !_stream.fail() &&'
806 '_stream.eof() && _sep == \':\';')
807 code('if (_ret)')
808 code(' ${dest} = AddrRange(_start, _end);')
809 code('${ret} _ret;')
810
741 def getValue(self):
742 # Go from the Python class to the wrapped C++ class generated
743 # by swig
744 from m5.internal.range import AddrRange
745
746 return AddrRange(long(self.start), long(self.end),
747 int(self.intlvHighBit), int(self.intlvBits),
748 int(self.intlvMatch))

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

778 def ini_str(self):
779 if self.value:
780 return 'true'
781 return 'false'
782
783 def config_value(self):
784 return self.value
785
811 def getValue(self):
812 # Go from the Python class to the wrapped C++ class generated
813 # by swig
814 from m5.internal.range import AddrRange
815
816 return AddrRange(long(self.start), long(self.end),
817 int(self.intlvHighBit), int(self.intlvBits),
818 int(self.intlvMatch))

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

848 def ini_str(self):
849 if self.value:
850 return 'true'
851 return 'false'
852
853 def config_value(self):
854 return self.value
855
856 @classmethod
857 def cxx_ini_predecls(cls, code):
858 # Assume that base/str.hh will be included anyway
859 # code('#include "base/str.hh"')
860 pass
861
862 @classmethod
863 def cxx_ini_parse(cls, code, src, dest, ret):
864 code('%s to_bool(%s, %s);' % (ret, src, dest))
865
786def IncEthernetAddr(addr, val = 1):
787 bytes = map(lambda x: int(x, 16), addr.split(':'))
788 bytes[5] += val
789 for i in (5, 4, 3, 2, 1):
790 val,rem = divmod(bytes[i], 256)
791 bytes[i] = rem
792 if val == 0:
793 break

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

845
846 def getValue(self):
847 from m5.internal.params import EthAddr
848 return EthAddr(self.value)
849
850 def ini_str(self):
851 return self.value
852
866def IncEthernetAddr(addr, val = 1):
867 bytes = map(lambda x: int(x, 16), addr.split(':'))
868 bytes[5] += val
869 for i in (5, 4, 3, 2, 1):
870 val,rem = divmod(bytes[i], 256)
871 bytes[i] = rem
872 if val == 0:
873 break

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

925
926 def getValue(self):
927 from m5.internal.params import EthAddr
928 return EthAddr(self.value)
929
930 def ini_str(self):
931 return self.value
932
933 @classmethod
934 def cxx_ini_parse(self, code, src, dest, ret):
935 code('%s = Net::EthAddr(%s);' % (dest, src))
936 code('%s true;' % ret)
937
853# When initializing an IpAddress, pass in an existing IpAddress, a string of
854# the form "a.b.c.d", or an integer representing an IP.
855class IpAddress(ParamValue):
856 cxx_type = 'Net::IpAddress'
857 ex_str = "127.0.0.1"
858 cmd_line_settable = True
859
860 @classmethod

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

1149
1150 def ini_str(self):
1151 return str(self)
1152
1153 def get_config_as_dict(self):
1154 assert false
1155 return str(self)
1156
938# When initializing an IpAddress, pass in an existing IpAddress, a string of
939# the form "a.b.c.d", or an integer representing an IP.
940class IpAddress(ParamValue):
941 cxx_type = 'Net::IpAddress'
942 ex_str = "127.0.0.1"
943 cmd_line_settable = True
944
945 @classmethod

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

1234
1235 def ini_str(self):
1236 return str(self)
1237
1238 def get_config_as_dict(self):
1239 assert false
1240 return str(self)
1241
1242 @classmethod
1243 def cxx_ini_predecls(cls, code):
1244 code('#include <time.h>')
1245
1246 @classmethod
1247 def cxx_ini_parse(cls, code, src, dest, ret):
1248 code('char *_parse_ret = strptime((${src}).c_str(),')
1249 code(' "%a %b %d %H:%M:%S %Y", &(${dest}));')
1250 code('${ret} _parse_ret && *_parse_ret == \'\\0\';');
1251
1157# Enumerated types are a little more complex. The user specifies the
1158# type as Enum(foo) where foo is either a list or dictionary of
1159# alternatives (typically strings, but not necessarily so). (In the
1160# long run, the integer value of the parameter will be the list index
1161# or the corresponding dictionary value. For now, since we only check
1162# that the alternative is valid and then spit it into a .ini file,
1163# there's not much point in using the dictionary.)
1164

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

1301 @classmethod
1302 def cxx_predecls(cls, code):
1303 code('#include "enums/$0.hh"', cls.__name__)
1304
1305 @classmethod
1306 def swig_predecls(cls, code):
1307 code('%import "python/m5/internal/enum_$0.i"', cls.__name__)
1308
1252# Enumerated types are a little more complex. The user specifies the
1253# type as Enum(foo) where foo is either a list or dictionary of
1254# alternatives (typically strings, but not necessarily so). (In the
1255# long run, the integer value of the parameter will be the list index
1256# or the corresponding dictionary value. For now, since we only check
1257# that the alternative is valid and then spit it into a .ini file,
1258# there's not much point in using the dictionary.)
1259

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

1396 @classmethod
1397 def cxx_predecls(cls, code):
1398 code('#include "enums/$0.hh"', cls.__name__)
1399
1400 @classmethod
1401 def swig_predecls(cls, code):
1402 code('%import "python/m5/internal/enum_$0.i"', cls.__name__)
1403
1404 @classmethod
1405 def cxx_ini_parse(cls, code, src, dest, ret):
1406 code('if (false) {')
1407 for elem_name in cls.map.iterkeys():
1408 code('} else if (%s == "%s") {' % (src, elem_name))
1409 code.indent()
1410 code('%s = Enums::%s;' % (dest, elem_name))
1411 code('%s true;' % ret)
1412 code.dedent()
1413 code('} else {')
1414 code(' %s false;' % ret)
1415 code('}')
1416
1309 def getValue(self):
1310 return int(self.map[self.value])
1311
1312 def __str__(self):
1313 return self.value
1314
1315# how big does a rounding error need to be before we warn about it?
1316frequency_tolerance = 0.001 # 0.1%

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

1331
1332 def __call__(self, value):
1333 self.__init__(value)
1334 return value
1335
1336 def getValue(self):
1337 return long(self.value)
1338
1417 def getValue(self):
1418 return int(self.map[self.value])
1419
1420 def __str__(self):
1421 return self.value
1422
1423# how big does a rounding error need to be before we warn about it?
1424frequency_tolerance = 0.001 # 0.1%

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

1439
1440 def __call__(self, value):
1441 self.__init__(value)
1442 return value
1443
1444 def getValue(self):
1445 return long(self.value)
1446
1447 @classmethod
1448 def cxx_ini_predecls(cls, code):
1449 code('#include <sstream>')
1450
1451 # Ticks are expressed in seconds in JSON files and in plain
1452 # Ticks in .ini files. Switch based on a config flag
1453 @classmethod
1454 def cxx_ini_parse(self, code, src, dest, ret):
1455 code('${ret} to_number(${src}, ${dest});')
1456
1339class Latency(TickParamValue):
1340 ex_str = "100ns"
1341
1342 def __init__(self, value):
1343 if isinstance(value, (Latency, Clock)):
1344 self.ticks = value.ticks
1345 self.value = value.value
1346 elif isinstance(value, Frequency):

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

1480
1481 def getValue(self):
1482 value = float(self)
1483 return value
1484
1485 def ini_str(self):
1486 return '%f' % self.getValue()
1487
1457class Latency(TickParamValue):
1458 ex_str = "100ns"
1459
1460 def __init__(self, value):
1461 if isinstance(value, (Latency, Clock)):
1462 self.ticks = value.ticks
1463 self.value = value.value
1464 elif isinstance(value, Frequency):

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

1598
1599 def getValue(self):
1600 value = float(self)
1601 return value
1602
1603 def ini_str(self):
1604 return '%f' % self.getValue()
1605
1606 @classmethod
1607 def cxx_ini_predecls(cls, code):
1608 code('#include <sstream>')
1609
1610 @classmethod
1611 def cxx_ini_parse(self, code, src, dest, ret):
1612 code('%s (std::istringstream(%s) >> %s).eof();' % (ret, src, dest))
1613
1488class Current(float, ParamValue):
1489 cxx_type = 'double'
1490 ex_str = "1mA"
1491 cmd_line_settable = False
1492
1493 def __new__(cls, value):
1494 # convert to current
1495 val = convert.toCurrent(value)

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

1505
1506 def getValue(self):
1507 value = float(self)
1508 return value
1509
1510 def ini_str(self):
1511 return '%f' % self.getValue()
1512
1614class Current(float, ParamValue):
1615 cxx_type = 'double'
1616 ex_str = "1mA"
1617 cmd_line_settable = False
1618
1619 def __new__(cls, value):
1620 # convert to current
1621 val = convert.toCurrent(value)

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

1631
1632 def getValue(self):
1633 value = float(self)
1634 return value
1635
1636 def ini_str(self):
1637 return '%f' % self.getValue()
1638
1639 @classmethod
1640 def cxx_ini_predecls(cls, code):
1641 code('#include <sstream>')
1642
1643 @classmethod
1644 def cxx_ini_parse(self, code, src, dest, ret):
1645 code('%s (std::istringstream(%s) >> %s).eof();' % (ret, src, dest))
1646
1513class NetworkBandwidth(float,ParamValue):
1514 cxx_type = 'float'
1515 ex_str = "1Gbps"
1516 cmd_line_settable = True
1517
1518 def __new__(cls, value):
1519 # convert to bits per second
1520 val = convert.toNetworkBandwidth(value)

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

1536 return float(value)
1537
1538 def ini_str(self):
1539 return '%f' % self.getValue()
1540
1541 def config_value(self):
1542 return '%f' % self.getValue()
1543
1647class NetworkBandwidth(float,ParamValue):
1648 cxx_type = 'float'
1649 ex_str = "1Gbps"
1650 cmd_line_settable = True
1651
1652 def __new__(cls, value):
1653 # convert to bits per second
1654 val = convert.toNetworkBandwidth(value)

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

1670 return float(value)
1671
1672 def ini_str(self):
1673 return '%f' % self.getValue()
1674
1675 def config_value(self):
1676 return '%f' % self.getValue()
1677
1678 @classmethod
1679 def cxx_ini_predecls(cls, code):
1680 code('#include <sstream>')
1681
1682 @classmethod
1683 def cxx_ini_parse(self, code, src, dest, ret):
1684 code('%s (std::istringstream(%s) >> %s).eof();' % (ret, src, dest))
1685
1544class MemoryBandwidth(float,ParamValue):
1545 cxx_type = 'float'
1546 ex_str = "1GB/s"
1547 cmd_line_settable = True
1548
1549 def __new__(cls, value):
1550 # convert to bytes per second
1551 val = convert.toMemoryBandwidth(value)

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

1566 return float(value)
1567
1568 def ini_str(self):
1569 return '%f' % self.getValue()
1570
1571 def config_value(self):
1572 return '%f' % self.getValue()
1573
1686class MemoryBandwidth(float,ParamValue):
1687 cxx_type = 'float'
1688 ex_str = "1GB/s"
1689 cmd_line_settable = True
1690
1691 def __new__(cls, value):
1692 # convert to bytes per second
1693 val = convert.toMemoryBandwidth(value)

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

1708 return float(value)
1709
1710 def ini_str(self):
1711 return '%f' % self.getValue()
1712
1713 def config_value(self):
1714 return '%f' % self.getValue()
1715
1716 @classmethod
1717 def cxx_ini_predecls(cls, code):
1718 code('#include <sstream>')
1719
1720 @classmethod
1721 def cxx_ini_parse(self, code, src, dest, ret):
1722 code('%s (std::istringstream(%s) >> %s).eof();' % (ret, src, dest))
1723
1574#
1575# "Constants"... handy aliases for various values.
1576#
1577
1578# Special class for NULL pointers. Note the special check in
1579# make_param_value() above that lets these be assigned where a
1580# SimObject is required.
1581# only one copy of a particular node

--- 380 unchanged lines hidden ---
1724#
1725# "Constants"... handy aliases for various values.
1726#
1727
1728# Special class for NULL pointers. Note the special check in
1729# make_param_value() above that lets these be assigned where a
1730# SimObject is required.
1731# only one copy of a particular node

--- 380 unchanged lines hidden ---