params.py (11802:be62996c95d1) params.py (11988:665cd5f8b52b)
1# Copyright (c) 2012-2014 ARM Limited
1# Copyright (c) 2012-2014, 2017 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
9# terms below provided that you ensure that this notice is replicated

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

97
98 # Generate the code needed as a prerequisite for declaring a C++
99 # object of this type. Typically generates one or more #include
100 # statements. Used when declaring parameters of this type.
101 @classmethod
102 def cxx_predecls(cls, code):
103 pass
104
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
9# terms below provided that you ensure that this notice is replicated

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

97
98 # Generate the code needed as a prerequisite for declaring a C++
99 # object of this type. Typically generates one or more #include
100 # statements. Used when declaring parameters of this type.
101 @classmethod
102 def cxx_predecls(cls, code):
103 pass
104
105 @classmethod
106 def pybind_predecls(cls, code):
107 cls.cxx_predecls(code)
108
105 # Generate the code needed as a prerequisite for including a
106 # reference to a C++ object of this type in a SWIG .i file.
107 # Typically generates one or more %import or %include statements.
108 @classmethod
109 def swig_predecls(cls, code):
110 pass
111
112 # default for printing to .ini file is regular string conversion.

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

217 if isNullPointer(value):
218 return NULL
219 return self.ptype(value).pretty_print(value)
220
221 def cxx_predecls(self, code):
222 code('#include <cstddef>')
223 self.ptype.cxx_predecls(code)
224
109 # Generate the code needed as a prerequisite for including a
110 # reference to a C++ object of this type in a SWIG .i file.
111 # Typically generates one or more %import or %include statements.
112 @classmethod
113 def swig_predecls(cls, code):
114 pass
115
116 # default for printing to .ini file is regular string conversion.

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

221 if isNullPointer(value):
222 return NULL
223 return self.ptype(value).pretty_print(value)
224
225 def cxx_predecls(self, code):
226 code('#include <cstddef>')
227 self.ptype.cxx_predecls(code)
228
229 def pybind_predecls(self, code):
230 self.ptype.pybind_predecls(code)
231
225 def swig_predecls(self, code):
226 self.ptype.swig_predecls(code)
227
228 def cxx_decl(self, code):
229 code('${{self.ptype.cxx_type}} ${{self.name}};')
230
231# Vector-valued parameter description. Just like ParamDesc, except
232# that the value is a vector (list) of the specified type instead of a

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

403 cxx_type = self.ptype.cxx_type
404
405 code('%template(vector_$ptype) std::vector< $cxx_type >;')
406
407 def cxx_predecls(self, code):
408 code('#include <vector>')
409 self.ptype.cxx_predecls(code)
410
232 def swig_predecls(self, code):
233 self.ptype.swig_predecls(code)
234
235 def cxx_decl(self, code):
236 code('${{self.ptype.cxx_type}} ${{self.name}};')
237
238# Vector-valued parameter description. Just like ParamDesc, except
239# that the value is a vector (list) of the specified type instead of a

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

410 cxx_type = self.ptype.cxx_type
411
412 code('%template(vector_$ptype) std::vector< $cxx_type >;')
413
414 def cxx_predecls(self, code):
415 code('#include <vector>')
416 self.ptype.cxx_predecls(code)
417
418 def pybind_predecls(self, code):
419 code('#include <vector>')
420 self.ptype.pybind_predecls(code)
421
411 def cxx_decl(self, code):
412 code('std::vector< ${{self.ptype.cxx_type}} > ${{self.name}};')
413
414class ParamFactory(object):
415 def __init__(self, param_desc_class, ptype_str = None):
416 self.param_desc_class = param_desc_class
417 self.ptype_str = ptype_str
418

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

787 return (long(self.end) - long(self.start) + 1) >> self.intlvBits
788
789 @classmethod
790 def cxx_predecls(cls, code):
791 Addr.cxx_predecls(code)
792 code('#include "base/addr_range.hh"')
793
794 @classmethod
422 def cxx_decl(self, code):
423 code('std::vector< ${{self.ptype.cxx_type}} > ${{self.name}};')
424
425class ParamFactory(object):
426 def __init__(self, param_desc_class, ptype_str = None):
427 self.param_desc_class = param_desc_class
428 self.ptype_str = ptype_str
429

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

798 return (long(self.end) - long(self.start) + 1) >> self.intlvBits
799
800 @classmethod
801 def cxx_predecls(cls, code):
802 Addr.cxx_predecls(code)
803 code('#include "base/addr_range.hh"')
804
805 @classmethod
806 def pybind_predecls(cls, code):
807 Addr.pybind_predecls(code)
808 code('#include "base/addr_range.hh"')
809
810 @classmethod
795 def swig_predecls(cls, code):
796 Addr.swig_predecls(code)
797
798 @classmethod
799 def cxx_ini_predecls(cls, code):
800 code('#include <sstream>')
801
802 @classmethod

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

936 return value
937
938 def unproxy(self, base):
939 if self.value == NextEthernetAddr:
940 return EthernetAddr(self.value())
941 return self
942
943 def getValue(self):
811 def swig_predecls(cls, code):
812 Addr.swig_predecls(code)
813
814 @classmethod
815 def cxx_ini_predecls(cls, code):
816 code('#include <sstream>')
817
818 @classmethod

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

952 return value
953
954 def unproxy(self, base):
955 if self.value == NextEthernetAddr:
956 return EthernetAddr(self.value())
957 return self
958
959 def getValue(self):
944 from m5.internal.params import EthAddr
960 from _m5.net import EthAddr
945 return EthAddr(self.value)
946
947 def __str__(self):
948 return self.value
949
950 def ini_str(self):
951 return self.value
952

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

1002 def __ne__(self, other):
1003 return not (self == other)
1004
1005 def verifyIp(self):
1006 if self.ip < 0 or self.ip >= (1 << 32):
1007 raise TypeError, "invalid ip address %#08x" % self.ip
1008
1009 def getValue(self):
961 return EthAddr(self.value)
962
963 def __str__(self):
964 return self.value
965
966 def ini_str(self):
967 return self.value
968

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

1018 def __ne__(self, other):
1019 return not (self == other)
1020
1021 def verifyIp(self):
1022 if self.ip < 0 or self.ip >= (1 << 32):
1023 raise TypeError, "invalid ip address %#08x" % self.ip
1024
1025 def getValue(self):
1010 from m5.internal.params import IpAddress
1026 from _m5.net import IpAddress
1011 return IpAddress(self.ip)
1012
1013# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
1014# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
1015# positional or keyword arguments.
1016class IpNetmask(IpAddress):
1017 cxx_type = 'Net::IpNetmask'
1018 ex_str = "127.0.0.0/24"

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

1081 return False
1082
1083 def verify(self):
1084 self.verifyIp()
1085 if self.netmask < 0 or self.netmask > 32:
1086 raise TypeError, "invalid netmask %d" % netmask
1087
1088 def getValue(self):
1027 return IpAddress(self.ip)
1028
1029# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
1030# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
1031# positional or keyword arguments.
1032class IpNetmask(IpAddress):
1033 cxx_type = 'Net::IpNetmask'
1034 ex_str = "127.0.0.0/24"

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

1097 return False
1098
1099 def verify(self):
1100 self.verifyIp()
1101 if self.netmask < 0 or self.netmask > 32:
1102 raise TypeError, "invalid netmask %d" % netmask
1103
1104 def getValue(self):
1089 from m5.internal.params import IpNetmask
1105 from _m5.net import IpNetmask
1090 return IpNetmask(self.ip, self.netmask)
1091
1092# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
1093# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
1094class IpWithPort(IpAddress):
1095 cxx_type = 'Net::IpWithPort'
1096 ex_str = "127.0.0.1:80"
1097 cmd_line_settable = True

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

1159 return False
1160
1161 def verify(self):
1162 self.verifyIp()
1163 if self.port < 0 or self.port > 0xffff:
1164 raise TypeError, "invalid port %d" % self.port
1165
1166 def getValue(self):
1106 return IpNetmask(self.ip, self.netmask)
1107
1108# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
1109# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
1110class IpWithPort(IpAddress):
1111 cxx_type = 'Net::IpWithPort'
1112 ex_str = "127.0.0.1:80"
1113 cmd_line_settable = True

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

1175 return False
1176
1177 def verify(self):
1178 self.verifyIp()
1179 if self.port < 0 or self.port > 0xffff:
1180 raise TypeError, "invalid port %d" % self.port
1181
1182 def getValue(self):
1167 from m5.internal.params import IpWithPort
1183 from _m5.net import IpWithPort
1168 return IpWithPort(self.ip, self.port)
1169
1170time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
1171 "%a %b %d %H:%M:%S %Y",
1172 "%Y/%m/%d %H:%M:%S",
1173 "%Y/%m/%d %H:%M",
1174 "%Y/%m/%d",
1175 "%m/%d/%Y %H:%M:%S",

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

1219 def __init__(self, value):
1220 self.value = parse_time(value)
1221
1222 def __call__(self, value):
1223 self.__init__(value)
1224 return value
1225
1226 def getValue(self):
1184 return IpWithPort(self.ip, self.port)
1185
1186time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
1187 "%a %b %d %H:%M:%S %Y",
1188 "%Y/%m/%d %H:%M:%S",
1189 "%Y/%m/%d %H:%M",
1190 "%Y/%m/%d",
1191 "%m/%d/%Y %H:%M:%S",

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

1235 def __init__(self, value):
1236 self.value = parse_time(value)
1237
1238 def __call__(self, value):
1239 self.__init__(value)
1240 return value
1241
1242 def getValue(self):
1227 from m5.internal.params import tm
1243 from _m5.core import tm
1244 import calendar
1228
1245
1229 c_time = tm()
1230 py_time = self.value
1246 return tm.gmtime(calendar.timegm(self.value))
1231
1247
1232 # UNIX is years since 1900
1233 c_time.tm_year = py_time.tm_year - 1900;
1234
1235 # Python starts at 1, UNIX starts at 0
1236 c_time.tm_mon = py_time.tm_mon - 1;
1237 c_time.tm_mday = py_time.tm_mday;
1238 c_time.tm_hour = py_time.tm_hour;
1239 c_time.tm_min = py_time.tm_min;
1240 c_time.tm_sec = py_time.tm_sec;
1241
1242 # Python has 0 as Monday, UNIX is 0 as sunday
1243 c_time.tm_wday = py_time.tm_wday + 1
1244 if c_time.tm_wday > 6:
1245 c_time.tm_wday -= 7;
1246
1247 # Python starts at 1, Unix starts at 0
1248 c_time.tm_yday = py_time.tm_yday - 1;
1249
1250 return c_time
1251
1252 def __str__(self):
1253 return time.asctime(self.value)
1254
1255 def ini_str(self):
1256 return str(self)
1257
1258 def get_config_as_dict(self):
1259 assert false

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

1370 code('"$val",')
1371 code.dedent(1)
1372 code('};')
1373
1374 if not cls.wrapper_is_struct:
1375 code('} // namespace $wrapper_name')
1376 code.dedent(1)
1377
1248 def __str__(self):
1249 return time.asctime(self.value)
1250
1251 def ini_str(self):
1252 return str(self)
1253
1254 def get_config_as_dict(self):
1255 assert false

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

1366 code('"$val",')
1367 code.dedent(1)
1368 code('};')
1369
1370 if not cls.wrapper_is_struct:
1371 code('} // namespace $wrapper_name')
1372 code.dedent(1)
1373
1374 def pybind_def(cls, code):
1375 name = cls.__name__
1376 wrapper_name = cls.wrapper_name
1377 enum_name = cls.__name__ if cls.enum_name is None else cls.enum_name
1378
1379 code('''#include "pybind11/pybind11.h"
1380#include "pybind11/stl.h"
1381
1382#include <sim/init.hh>
1383
1384namespace py = pybind11;
1385
1386static void
1387module_init(py::module &m_internal)
1388{
1389 py::module m = m_internal.def_submodule("enum_${name}");
1390
1391 py::enum_<${wrapper_name}::${enum_name}>(m, "enum_${name}")
1392''')
1393
1394 code.indent()
1395 code.indent()
1396 for val in cls.vals:
1397 code('.value("${val}", ${wrapper_name}::${val})')
1398 code('.value("Num_${name}", ${wrapper_name}::Num_${enum_name})')
1399 code('.export_values()')
1400 code(';')
1401 code.dedent()
1402
1403 code('}')
1404 code.dedent()
1405 code()
1406 code('static EmbeddedPyBind embed_enum("enum_${name}", module_init);')
1407
1378 def swig_decl(cls, code):
1379 name = cls.__name__
1380 code('''\
1381%module(package="_m5") enum_$name
1382
1383%{
1384#include "enums/$name.hh"
1385%}

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

1430 code('%s = Enums::%s;' % (dest, elem_name))
1431 code('%s true;' % ret)
1432 code.dedent()
1433 code('} else {')
1434 code(' %s false;' % ret)
1435 code('}')
1436
1437 def getValue(self):
1408 def swig_decl(cls, code):
1409 name = cls.__name__
1410 code('''\
1411%module(package="_m5") enum_$name
1412
1413%{
1414#include "enums/$name.hh"
1415%}

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

1460 code('%s = Enums::%s;' % (dest, elem_name))
1461 code('%s true;' % ret)
1462 code.dedent()
1463 code('} else {')
1464 code(' %s false;' % ret)
1465 code('}')
1466
1467 def getValue(self):
1438 return int(self.map[self.value])
1468 import m5.internal.params
1469 e = getattr(m5.internal.params, "enum_%s" % self.__class__.__name__)
1470 return e(self.map[self.value])
1439
1440 def __str__(self):
1441 return self.value
1442
1443# how big does a rounding error need to be before we warn about it?
1444frequency_tolerance = 0.001 # 0.1%
1445
1446class TickParamValue(NumericParamValue):

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

2035 def connect(self, simobj, ref):
2036 self.makeRef(simobj).connect(ref)
2037
2038 # No need for any pre-declarations at the moment as we merely rely
2039 # on an unsigned int.
2040 def cxx_predecls(self, code):
2041 pass
2042
1471
1472 def __str__(self):
1473 return self.value
1474
1475# how big does a rounding error need to be before we warn about it?
1476frequency_tolerance = 0.001 # 0.1%
1477
1478class TickParamValue(NumericParamValue):

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

2067 def connect(self, simobj, ref):
2068 self.makeRef(simobj).connect(ref)
2069
2070 # No need for any pre-declarations at the moment as we merely rely
2071 # on an unsigned int.
2072 def cxx_predecls(self, code):
2073 pass
2074
2075 def pybind_predecls(self, code):
2076 cls.cxx_predecls(self, code)
2077
2043 # Declare an unsigned int with the same name as the port, that
2044 # will eventually hold the number of connected ports (and thus the
2045 # number of elements for a VectorPort).
2046 def cxx_decl(self, code):
2047 code('unsigned int port_${{self.name}}_connection_count;')
2048
2049class MasterPort(Port):
2050 # MasterPort("description")

--- 81 unchanged lines hidden ---
2078 # Declare an unsigned int with the same name as the port, that
2079 # will eventually hold the number of connected ports (and thus the
2080 # number of elements for a VectorPort).
2081 def cxx_decl(self, code):
2082 code('unsigned int port_${{self.name}}_connection_count;')
2083
2084class MasterPort(Port):
2085 # MasterPort("description")

--- 81 unchanged lines hidden ---