summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConscript7
-rw-r--r--python/SConscript (renamed from sim/pyconfig/SConscript)4
-rw-r--r--python/m5/__init__.py7
-rw-r--r--python/m5/config.py (renamed from sim/pyconfig/m5config.py)31
-rw-r--r--python/m5/convert.py181
-rw-r--r--python/m5/objects/AlphaConsole.mpy (renamed from objects/AlphaConsole.mpy)0
-rw-r--r--python/m5/objects/AlphaTLB.mpy (renamed from objects/AlphaTLB.mpy)0
-rw-r--r--python/m5/objects/BadDevice.mpy (renamed from objects/BadDevice.mpy)0
-rw-r--r--python/m5/objects/BaseCPU.mpy (renamed from objects/BaseCPU.mpy)2
-rw-r--r--python/m5/objects/BaseCache.mpy (renamed from objects/BaseCache.mpy)0
-rw-r--r--python/m5/objects/BaseSystem.mpy (renamed from objects/BaseSystem.mpy)0
-rw-r--r--python/m5/objects/Bus.mpy (renamed from objects/Bus.mpy)0
-rw-r--r--python/m5/objects/CoherenceProtocol.mpy (renamed from objects/CoherenceProtocol.mpy)0
-rw-r--r--python/m5/objects/Device.mpy (renamed from objects/Device.mpy)0
-rw-r--r--python/m5/objects/DiskImage.mpy (renamed from objects/DiskImage.mpy)0
-rw-r--r--python/m5/objects/Ethernet.mpy (renamed from objects/Ethernet.mpy)0
-rw-r--r--python/m5/objects/Ide.mpy (renamed from objects/Ide.mpy)0
-rw-r--r--python/m5/objects/IntrControl.mpy (renamed from objects/IntrControl.mpy)0
-rw-r--r--python/m5/objects/MemTest.mpy (renamed from objects/MemTest.mpy)0
-rw-r--r--python/m5/objects/Pci.mpy (renamed from objects/Pci.mpy)0
-rw-r--r--python/m5/objects/PhysicalMemory.mpy (renamed from objects/PhysicalMemory.mpy)0
-rw-r--r--python/m5/objects/Platform.mpy (renamed from objects/Platform.mpy)0
-rw-r--r--python/m5/objects/Process.mpy (renamed from objects/Process.mpy)0
-rw-r--r--python/m5/objects/Repl.mpy (renamed from objects/Repl.mpy)0
-rw-r--r--python/m5/objects/Root.mpy (renamed from objects/Root.mpy)0
-rw-r--r--python/m5/objects/SimConsole.mpy (renamed from objects/SimConsole.mpy)0
-rw-r--r--python/m5/objects/SimpleDisk.mpy (renamed from objects/SimpleDisk.mpy)0
-rw-r--r--python/m5/objects/Tsunami.mpy (renamed from objects/Tsunami.mpy)0
-rw-r--r--python/m5/objects/Uart.mpy (renamed from objects/Uart.mpy)0
-rw-r--r--python/m5/smartdict.py85
-rw-r--r--sim/main.cc2
-rwxr-xr-xtest/genini.py13
32 files changed, 304 insertions, 28 deletions
diff --git a/SConscript b/SConscript
index 19f84f913..cff240a69 100644
--- a/SConscript
+++ b/SConscript
@@ -183,6 +183,9 @@ base_sources = Split('''
mem/trace/mem_trace_writer.cc
mem/trace/m5_writer.cc
+ python/pyconfig.cc
+ python/embedded_py.cc
+
sim/builder.cc
sim/configfile.cc
sim/debug.cc
@@ -199,8 +202,6 @@ base_sources = Split('''
sim/stat_control.cc
sim/trace_context.cc
sim/universe.cc
- sim/pyconfig/pyconfig.cc
- sim/pyconfig/embedded_py.cc
''')
# MySql sources
@@ -376,7 +377,7 @@ env.Command(Split('''arch/alpha/decoder.cc
# SConscript-local is the per-config build, which just copies some
# header files into a place where they can be found.
SConscript('libelf/SConscript-local', exports = 'env', duplicate=0)
-SConscript('sim/pyconfig/SConscript', exports = ['env'], duplicate=0)
+SConscript('python/SConscript', exports = ['env'], duplicate=0)
# This function adds the specified sources to the given build
diff --git a/sim/pyconfig/SConscript b/python/SConscript
index 2799ef64f..81bc52286 100644
--- a/sim/pyconfig/SConscript
+++ b/python/SConscript
@@ -193,8 +193,8 @@ EmbedMap %(name)s("%(fname)s",
/* namespace */ }
'''
-embedded_py_files = ['m5config.py', 'importer.py', '../../util/pbs/jobfile.py']
-objpath = os.path.join(env['SRCDIR'], 'objects')
+embedded_py_files = [ 'mpy_importer.py', '../util/pbs/jobfile.py' ]
+objpath = os.path.join(env['SRCDIR'], 'python/m5')
for root, dirs, files in os.walk(objpath, topdown=True):
for i,dir in enumerate(dirs):
if dir == 'SCCS':
diff --git a/python/m5/__init__.py b/python/m5/__init__.py
new file mode 100644
index 000000000..7cb3a32c6
--- /dev/null
+++ b/python/m5/__init__.py
@@ -0,0 +1,7 @@
+from mpy_importer import *
+from config import *
+from objects import *
+
+cpp_classes = MetaSimObject.cpp_classes
+cpp_classes.sort()
+
diff --git a/sim/pyconfig/m5config.py b/python/m5/config.py
index e6201b3ad..2c5a70b25 100644
--- a/sim/pyconfig/m5config.py
+++ b/python/m5/config.py
@@ -27,7 +27,9 @@
from __future__ import generators
import os, re, sys, types, inspect
-from importer import AddToPath, LoadMpyFile
+from mpy_importer import AddToPath, LoadMpyFile
+from smartdict import SmartDict
+from convert import *
noDot = False
try:
@@ -35,7 +37,7 @@ try:
except:
noDot = True
-env = {}
+env = SmartDict()
env.update(os.environ)
def panic(string):
@@ -449,7 +451,7 @@ class MetaConfigNode(type):
# Print instance info to .ini file.
def instantiate(cls, name, parent = None):
- instance = Node(name, cls, cls.type, parent, isParamContext(cls))
+ instance = Node(name, cls, parent, isParamContext(cls))
if hasattr(cls, 'check'):
cls.check()
@@ -584,10 +586,13 @@ class NodeParam(object):
class Node(object):
all = {}
- def __init__(self, name, realtype, type, parent, paramcontext):
+ def __init__(self, name, realtype, parent, paramcontext):
self.name = name
self.realtype = realtype
- self.type = type
+ if isSimObject(realtype):
+ self.type = realtype.type
+ else:
+ self.type = None
self.parent = parent
self.children = []
self.child_names = {}
@@ -973,18 +978,17 @@ VectorParam = _VectorParamProxy(None)
# Integer parameter type.
class _CheckedInt(object):
def _convert(cls, value):
- t = type(value)
- if t == bool:
+ if isinstance(value, bool):
return int(value)
- if t != int and t != long and t != float and t != str:
- raise TypeError, 'Integer parameter of invalid type %s' % t
+ if not isinstance(value, (int, long, float, str)):
+ raise TypeError, 'Integer param of invalid type %s' % type(value)
- if t == str or t == float:
- value = long(value)
+ if isinstance(value, (str, float)):
+ value = long(float(value))
if not cls._min <= value <= cls._max:
- raise TypeError, 'Integer parameter out of bounds %d < %d < %d' % \
+ raise TypeError, 'Integer param out of bounds %d < %d < %d' % \
(cls._min, value, cls._max)
return value
@@ -1298,6 +1302,3 @@ class SimObject(ConfigNode):
type = 'SimObject'
from objects import *
-
-cpp_classes = MetaSimObject.cpp_classes
-cpp_classes.sort()
diff --git a/python/m5/convert.py b/python/m5/convert.py
new file mode 100644
index 000000000..b3f34e4ab
--- /dev/null
+++ b/python/m5/convert.py
@@ -0,0 +1,181 @@
+# metric prefixes
+exa = 1.0e18
+peta = 1.0e15
+tera = 1.0e12
+giga = 1.0e9
+mega = 1.0e6
+kilo = 1.0e3
+
+milli = 1.0e-3
+micro = 1.0e-6
+nano = 1.0e-9
+pico = 1.0e-12
+femto = 1.0e-15
+atto = 1.0e-18
+
+# power of 2 prefixes
+kibi = 1024
+mebi = kibi * 1024
+gibi = mebi * 1024
+tebi = gibi * 1024
+pebi = tebi * 1024
+exbi = pebi * 1024
+
+# memory size configuration stuff
+def to_integer(value):
+ if not isinstance(value, str):
+ result = int(value)
+ elif value.endswith('Ei'):
+ result = int(value[:-2]) * exbi
+ elif value.endswith('Pi'):
+ result = int(value[:-2]) * pebi
+ elif value.endswith('Ti'):
+ result = int(value[:-2]) * tebi
+ elif value.endswith('Gi'):
+ result = int(value[:-2]) * gibi
+ elif value.endswith('Mi'):
+ result = int(value[:-2]) * mebi
+ elif value.endswith('ki'):
+ result = int(value[:-2]) * kibi
+ elif value.endswith('E'):
+ result = int(value[:-1]) * exa
+ elif value.endswith('P'):
+ result = int(value[:-1]) * peta
+ elif value.endswith('T'):
+ result = int(value[:-1]) * tera
+ elif value.endswith('G'):
+ result = int(value[:-1]) * giga
+ elif value.endswith('M'):
+ result = int(value[:-1]) * mega
+ elif value.endswith('k'):
+ result = int(value[:-1]) * kilo
+ elif value.endswith('m'):
+ result = int(value[:-1]) * milli
+ elif value.endswith('u'):
+ result = int(value[:-1]) * micro
+ elif value.endswith('n'):
+ result = int(value[:-1]) * nano
+ elif value.endswith('p'):
+ result = int(value[:-1]) * pico
+ elif value.endswith('f'):
+ result = int(value[:-1]) * femto
+ else:
+ result = int(value)
+
+ return result
+
+def to_bool(val):
+ t = type(val)
+ if t == bool:
+ return val
+
+ if t == None:
+ return False
+
+ if t == int or t == long:
+ return bool(val)
+
+ if t == str:
+ val = val.lower()
+ if val == "true" or val == "t" or val == "yes" or val == "y":
+ return True
+ elif val == "false" or val == "f" or val == "no" or val == "n":
+ return False
+
+ return to_integer(val) != 0
+
+def to_frequency(value):
+ if not isinstance(value, str):
+ result = float(value)
+ elif value.endswith('THz'):
+ result = float(value[:-3]) * tera
+ elif value.endswith('GHz'):
+ result = float(value[:-3]) * giga
+ elif value.endswith('MHz'):
+ result = float(value[:-3]) * mega
+ elif value.endswith('kHz'):
+ result = float(value[:-3]) * kilo
+ elif value.endswith('Hz'):
+ result = float(value[:-2])
+ else:
+ result = float(value)
+
+ return result
+
+def to_latency(value):
+ if not isinstance(value, str):
+ result = float(value)
+ elif value.endswith('c'):
+ result = float(value[:-1])
+ elif value.endswith('ps'):
+ result = float(value[:-2]) * pico
+ elif value.endswith('ns'):
+ result = float(value[:-2]) * nano
+ elif value.endswith('us'):
+ result = float(value[:-2]) * micro
+ elif value.endswith('ms'):
+ result = float(value[:-2]) * milli
+ elif value.endswith('s'):
+ result = float(value[:-1])
+ else:
+ result = float(value)
+
+ return result;
+
+def to_network_bandwidth(value):
+ if not isinstance(value, str):
+ result = float(value)
+ elif value.endswith('Tbps'):
+ result = float(value[:-3]) * tera
+ elif value.endswith('Gbps'):
+ result = float(value[:-3]) * giga
+ elif value.endswith('Mbps'):
+ result = float(value[:-3]) * mega
+ elif value.endswith('kbps'):
+ result = float(value[:-3]) * kilo
+ elif value.endswith('bps'):
+ result = float(value[:-2])
+ else:
+ result = float(value)
+
+ return result
+
+def to_memory_bandwidth(value):
+ if not isinstance(value, str):
+ result = int(value)
+ elif value.endswith('PB/s'):
+ result = int(value[:-4]) * pebi
+ elif value.endswith('TB/s'):
+ result = int(value[:-4]) * tebi
+ elif value.endswith('GB/s'):
+ result = int(value[:-4]) * gibi
+ elif value.endswith('MB/s'):
+ result = int(value[:-4]) * mebi
+ elif value.endswith('kB/s'):
+ result = int(value[:-4]) * kibi
+ elif value.endswith('B/s'):
+ result = int(value[:-3])
+ else:
+ result = int(value)
+
+ return result
+
+def to_memory_size(value):
+ if not isinstance(value, str):
+ result = int(value)
+ elif value.endswith('PB'):
+ result = int(value[:-2]) * pebi
+ elif value.endswith('TB'):
+ result = int(value[:-2]) * tebi
+ elif value.endswith('GB'):
+ result = int(value[:-2]) * gibi
+ elif value.endswith('MB'):
+ result = int(value[:-2]) * mebi
+ elif value.endswith('kB'):
+ result = int(value[:-2]) * kibi
+ elif value.endswith('B'):
+ result = int(value[:-1])
+ else:
+ result = int(value)
+
+ return result
diff --git a/objects/AlphaConsole.mpy b/python/m5/objects/AlphaConsole.mpy
index 79918a01e..79918a01e 100644
--- a/objects/AlphaConsole.mpy
+++ b/python/m5/objects/AlphaConsole.mpy
diff --git a/objects/AlphaTLB.mpy b/python/m5/objects/AlphaTLB.mpy
index 8e7cd62cc..8e7cd62cc 100644
--- a/objects/AlphaTLB.mpy
+++ b/python/m5/objects/AlphaTLB.mpy
diff --git a/objects/BadDevice.mpy b/python/m5/objects/BadDevice.mpy
index 35a12e0bf..35a12e0bf 100644
--- a/objects/BadDevice.mpy
+++ b/python/m5/objects/BadDevice.mpy
diff --git a/objects/BaseCPU.mpy b/python/m5/objects/BaseCPU.mpy
index 484fcccd6..be93e8ad1 100644
--- a/objects/BaseCPU.mpy
+++ b/python/m5/objects/BaseCPU.mpy
@@ -4,7 +4,7 @@ simobj BaseCPU(SimObject):
icache = Param.BaseMem(NULL, "L1 instruction cache object")
dcache = Param.BaseMem(NULL, "L1 data cache object")
- if Bool._convert(env.get('FULL_SYSTEM', 'False')):
+ if env.get('FULL_SYSTEM', 'False'):
dtb = Param.AlphaDTB("Data TLB")
itb = Param.AlphaITB("Instruction TLB")
mem = Param.FunctionalMemory("memory")
diff --git a/objects/BaseCache.mpy b/python/m5/objects/BaseCache.mpy
index 98a422e30..98a422e30 100644
--- a/objects/BaseCache.mpy
+++ b/python/m5/objects/BaseCache.mpy
diff --git a/objects/BaseSystem.mpy b/python/m5/objects/BaseSystem.mpy
index 1cbdf4e99..1cbdf4e99 100644
--- a/objects/BaseSystem.mpy
+++ b/python/m5/objects/BaseSystem.mpy
diff --git a/objects/Bus.mpy b/python/m5/objects/Bus.mpy
index 025d69785..025d69785 100644
--- a/objects/Bus.mpy
+++ b/python/m5/objects/Bus.mpy
diff --git a/objects/CoherenceProtocol.mpy b/python/m5/objects/CoherenceProtocol.mpy
index f3b0026b7..f3b0026b7 100644
--- a/objects/CoherenceProtocol.mpy
+++ b/python/m5/objects/CoherenceProtocol.mpy
diff --git a/objects/Device.mpy b/python/m5/objects/Device.mpy
index 47f8db1cb..47f8db1cb 100644
--- a/objects/Device.mpy
+++ b/python/m5/objects/Device.mpy
diff --git a/objects/DiskImage.mpy b/python/m5/objects/DiskImage.mpy
index 80ef7b072..80ef7b072 100644
--- a/objects/DiskImage.mpy
+++ b/python/m5/objects/DiskImage.mpy
diff --git a/objects/Ethernet.mpy b/python/m5/objects/Ethernet.mpy
index 088df4b93..088df4b93 100644
--- a/objects/Ethernet.mpy
+++ b/python/m5/objects/Ethernet.mpy
diff --git a/objects/Ide.mpy b/python/m5/objects/Ide.mpy
index ce760ad96..ce760ad96 100644
--- a/objects/Ide.mpy
+++ b/python/m5/objects/Ide.mpy
diff --git a/objects/IntrControl.mpy b/python/m5/objects/IntrControl.mpy
index 1ef5a17ee..1ef5a17ee 100644
--- a/objects/IntrControl.mpy
+++ b/python/m5/objects/IntrControl.mpy
diff --git a/objects/MemTest.mpy b/python/m5/objects/MemTest.mpy
index af14ed9c3..af14ed9c3 100644
--- a/objects/MemTest.mpy
+++ b/python/m5/objects/MemTest.mpy
diff --git a/objects/Pci.mpy b/python/m5/objects/Pci.mpy
index 907472727..907472727 100644
--- a/objects/Pci.mpy
+++ b/python/m5/objects/Pci.mpy
diff --git a/objects/PhysicalMemory.mpy b/python/m5/objects/PhysicalMemory.mpy
index d1e4ad4b4..d1e4ad4b4 100644
--- a/objects/PhysicalMemory.mpy
+++ b/python/m5/objects/PhysicalMemory.mpy
diff --git a/objects/Platform.mpy b/python/m5/objects/Platform.mpy
index d0510eaf8..d0510eaf8 100644
--- a/objects/Platform.mpy
+++ b/python/m5/objects/Platform.mpy
diff --git a/objects/Process.mpy b/python/m5/objects/Process.mpy
index 6a91c09c2..6a91c09c2 100644
--- a/objects/Process.mpy
+++ b/python/m5/objects/Process.mpy
diff --git a/objects/Repl.mpy b/python/m5/objects/Repl.mpy
index fff5a2a02..fff5a2a02 100644
--- a/objects/Repl.mpy
+++ b/python/m5/objects/Repl.mpy
diff --git a/objects/Root.mpy b/python/m5/objects/Root.mpy
index 0e531054b..0e531054b 100644
--- a/objects/Root.mpy
+++ b/python/m5/objects/Root.mpy
diff --git a/objects/SimConsole.mpy b/python/m5/objects/SimConsole.mpy
index fb74f1775..fb74f1775 100644
--- a/objects/SimConsole.mpy
+++ b/python/m5/objects/SimConsole.mpy
diff --git a/objects/SimpleDisk.mpy b/python/m5/objects/SimpleDisk.mpy
index c4dd5435b..c4dd5435b 100644
--- a/objects/SimpleDisk.mpy
+++ b/python/m5/objects/SimpleDisk.mpy
diff --git a/objects/Tsunami.mpy b/python/m5/objects/Tsunami.mpy
index cfe23977e..cfe23977e 100644
--- a/objects/Tsunami.mpy
+++ b/python/m5/objects/Tsunami.mpy
diff --git a/objects/Uart.mpy b/python/m5/objects/Uart.mpy
index 76ee8805f..76ee8805f 100644
--- a/objects/Uart.mpy
+++ b/python/m5/objects/Uart.mpy
diff --git a/python/m5/smartdict.py b/python/m5/smartdict.py
new file mode 100644
index 000000000..e282bc07b
--- /dev/null
+++ b/python/m5/smartdict.py
@@ -0,0 +1,85 @@
+from convert import *
+
+class SmartDict(dict):
+ class Proxy(str):
+ def __int__(self):
+ return int(to_integer(str(self)))
+ def __long__(self):
+ return long(to_integer(str(self)))
+ def __float__(self):
+ return float(to_integer(str(self)))
+ def __nonzero__(self):
+ return to_bool(str(self))
+ def convert(self, other):
+ t = type(other)
+ if t == bool:
+ return bool(self)
+ if t == int:
+ return int(self)
+ if t == long:
+ return long(self)
+ if t == float:
+ return float(self)
+ return str(self)
+ def __lt__(self, other):
+ return self.convert(other) < other
+ def __le__(self, other):
+ return self.convert(other) <= other
+ def __eq__(self, other):
+ return self.convert(other) == other
+ def __ne__(self, other):
+ return self.convert(other) != other
+ def __gt__(self, other):
+ return self.convert(other) > other
+ def __ge__(self, other):
+ return self.convert(other) >= other
+
+ def __add__(self, other):
+ return self.convert(other) + other
+ def __sub__(self, other):
+ return self.convert(other) - other
+ def __mul__(self, other):
+ return self.convert(other) * other
+ def __div__(self, other):
+ return self.convert(other) / other
+ def __truediv__(self, other):
+ return self.convert(other) / other
+
+ def __radd__(self, other):
+ return other + self.convert(other)
+ def __rsub__(self, other):
+ return other - self.convert(other)
+ def __rmul__(self, other):
+ return other * self.convert(other)
+ def __rdiv__(self, other):
+ return other / self.convert(other)
+ def __rtruediv__(self, other):
+ return other / self.convert(other)
+
+
+ def __getitem__(self, key):
+ return self.Proxy(dict.__getitem__(self, key))
+
+ def __setitem__(self, key, item):
+ dict.__setitem__(self, key, str(item))
+
+ def values(self):
+ return [ self.Proxy(v) for v in dict.values(self) ]
+
+ def itervalues(self):
+ for value in dict.itervalues(self):
+ yield self.Proxy(value)
+
+ def items(self):
+ return [ (k, self.Proxy(v)) for k,v in dict.items(self) ]
+
+ def iteritems(self):
+ for key,value in dict.iteritems(self):
+ yield key, self.Proxy(value)
+
+ def get(self, key, default=''):
+ return self.Proxy(dict.get(self, key, str(default)))
+
+ def setdefault(self, key, default=''):
+ return self.Proxy(dict.setdefault(self, key, str(default)))
+
diff --git a/sim/main.cc b/sim/main.cc
index c15d24453..ee59cb83b 100644
--- a/sim/main.cc
+++ b/sim/main.cc
@@ -51,6 +51,7 @@
#include "base/time.hh"
#include "cpu/base_cpu.hh"
#include "cpu/full_cpu/smt.hh"
+#include "python/pyconfig.hh"
#include "sim/async.hh"
#include "sim/builder.hh"
#include "sim/configfile.hh"
@@ -61,7 +62,6 @@
#include "sim/stat_control.hh"
#include "sim/stats.hh"
#include "sim/universe.hh"
-#include "sim/pyconfig/pyconfig.hh"
using namespace std;
diff --git a/test/genini.py b/test/genini.py
index f4d1575db..025ba998a 100755
--- a/test/genini.py
+++ b/test/genini.py
@@ -30,12 +30,10 @@ from os.path import join as joinpath, realpath
mypath = sys.path[0]
sys.path.append(joinpath(mypath, '..'))
+sys.path.append(joinpath(mypath, '../python'))
sys.path.append(joinpath(mypath, '../util/pbs'))
-sys.path.append(joinpath(mypath, '../sim/pyconfig'))
-from importer import AddToPath, LoadMpyFile
-
-AddToPath('.')
+pathlist = [ '.' ]
try:
opts, args = getopt.getopt(sys.argv[1:], '-E:I:')
@@ -50,11 +48,14 @@ try:
value = arg[offset+1:]
os.environ[name] = value
if opt == '-I':
- AddToPath(arg)
+ pathlist.append(arg)
except getopt.GetoptError:
sys.exit('Improper Usage')
-from m5config import *
+from m5 import *
+
+for path in pathlist:
+ AddToPath(path)
for arg in args:
LoadMpyFile(arg)