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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 --- |