changeset 4c84e771cca7 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=4c84e771cca7
description:
        python: Move more code into m5.util allow SCons to use that code.
        Get rid of misc.py and just stick misc things in __init__.py
        Move utility functions out of SCons files and into m5.util
        Move utility type stuff from m5/__init__.py to m5/util/__init__.py
        Remove buildEnv from m5 and allow access only from m5.defines
        Rename AddToPath to addToPath while we're moving it to m5.util
        Rename read_command to readCommand while we're moving it
        Rename compare_versions to compareVersions while we're moving it.

diffstat:

66 files changed, 845 insertions(+), 896 deletions(-)
SConstruct                                    |   68 +-----
configs/common/Caches.py                      |    1 
configs/common/FSConfig.py                    |    2 
configs/common/Simulation.py                  |   31 +--
configs/example/fs.py                         |   35 ++-
configs/example/memtest.py                    |    5 
configs/example/ruby_se.py                    |   21 +-
configs/example/se.py                         |   20 +-
configs/splash2/cluster.py                    |   17 +
configs/splash2/run.py                        |    8 
src/SConscript                                |   48 +++-
src/arch/mips/BISystem.py                     |    5 
src/arch/mips/MipsCPU.py                      |    5 
src/arch/mips/MipsSystem.py                   |    6 
src/arch/x86/X86TLB.py                        |    9 
src/cpu/BaseCPU.py                            |   58 +++--
src/cpu/CheckerCPU.py                         |    1 
src/cpu/inorder/InOrderCPU.py                 |    1 
src/cpu/memtest/MemTest.py                    |    1 
src/cpu/o3/O3CPU.py                           |    8 
src/cpu/o3/O3Checker.py                       |    1 
src/cpu/ozone/OzoneCPU.py                     |    6 
src/cpu/ozone/OzoneChecker.py                 |    1 
src/cpu/ozone/SimpleOzoneCPU.py               |    4 
src/cpu/simple/AtomicSimpleCPU.py             |    1 
src/cpu/simple/TimingSimpleCPU.py             |    1 
src/dev/Uart.py                               |    1 
src/mem/Bus.py                                |    4 
src/python/SConscript                         |    5 
src/python/m5/SimObject.py                    |   79 ++++---
src/python/m5/__init__.py                     |  102 +---------
src/python/m5/convert.py                      |  250 -------------------------
src/python/m5/environment.py                  |   43 ----
src/python/m5/main.py                         |    2 
src/python/m5/params.py                       |   33 ++-
src/python/m5/simulate.py                     |    3 
src/python/m5/smartdict.py                    |  154 ---------------
src/python/m5/ticks.py                        |    2 
src/python/m5/trace.py                        |    2 
src/python/m5/util/__init__.py                |  149 ++++++++++++++
src/python/m5/util/convert.py                 |  250 +++++++++++++++++++++++++
src/python/m5/util/jobfile.py                 |   10 -
src/python/m5/util/misc.py                    |   87 --------
src/python/m5/util/smartdict.py               |  154 +++++++++++++++
src/sim/System.py                             |    5 
tests/configs/inorder-timing.py               |    2 
tests/configs/o3-timing-mp-ruby.py            |    2 
tests/configs/o3-timing-mp.py                 |    2 
tests/configs/o3-timing-ruby.py               |    2 
tests/configs/o3-timing.py                    |    2 
tests/configs/t1000-simple-atomic.py          |    2 
tests/configs/tsunami-o3-dual.py              |    2 
tests/configs/tsunami-o3.py                   |    2 
tests/configs/tsunami-simple-atomic-dual.py   |    2 
tests/configs/tsunami-simple-atomic.py        |    2 
tests/configs/tsunami-simple-timing-dual.py   |    2 
tests/configs/tsunami-simple-timing.py        |    2 
tests/configs/twosys-tsunami-simple-atomic.py |    2 
tests/long/00.gzip/test.py                    |    2 
tests/long/10.mcf/test.py                     |    2 
tests/long/20.parser/test.py                  |    2 
tests/long/30.eon/test.py                     |    2 
tests/long/40.perlbmk/test.py                 |    2 
tests/long/50.vortex/test.py                  |    2 
tests/long/60.bzip2/test.py                   |    2 
tests/long/70.twolf/test.py                   |    2 

diffs (truncated from 2876 to 300 lines):

diff -r 9e27313312e6 -r 4c84e771cca7 SConstruct
--- a/SConstruct        Tue Sep 22 15:24:16 2009 -0700
+++ b/SConstruct        Tue Sep 22 15:24:16 2009 -0700
@@ -96,6 +96,7 @@
 """
     raise
 
+# Global Python includes
 import os
 import re
 import subprocess
@@ -106,55 +107,14 @@
 from os.path import exists,  isdir, isfile
 from os.path import join as joinpath, split as splitpath
 
+# SCons includes
 import SCons
 import SCons.Node
 
-def read_command(cmd, **kwargs):
-    """run the command cmd, read the results and return them
-    this is sorta like `cmd` in shell"""
-    from subprocess import Popen, PIPE, STDOUT
+# M5 includes
+sys.path[1:1] = [ Dir('src/python').srcnode().abspath ]
 
-    if isinstance(cmd, str):
-        cmd = cmd.split()
-
-    no_exception = 'exception' in kwargs
-    exception = kwargs.pop('exception', None)
-    
-    kwargs.setdefault('shell', False)
-    kwargs.setdefault('stdout', PIPE)
-    kwargs.setdefault('stderr', STDOUT)
-    kwargs.setdefault('close_fds', True)
-    try:
-        subp = Popen(cmd, **kwargs)
-    except Exception, e:
-        if no_exception:
-            return exception
-        raise
-
-    return subp.communicate()[0]
-
-# helper function: compare arrays or strings of version numbers.
-# E.g., compare_version((1,3,25), (1,4,1)')
-# returns -1, 0, 1 if v1 is <, ==, > v2
-def compare_versions(v1, v2):
-    def make_version_list(v):
-        if isinstance(v, (list,tuple)):
-            return v
-        elif isinstance(v, str):
-            return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
-        else:
-            raise TypeError
-
-    v1 = make_version_list(v1)
-    v2 = make_version_list(v2)
-    # Compare corresponding elements of lists
-    for n1,n2 in zip(v1, v2):
-        if n1 < n2: return -1
-        if n1 > n2: return  1
-    # all corresponding values are equal... see if one has extra values
-    if len(v1) < len(v2): return -1
-    if len(v1) > len(v2): return  1
-    return 0
+from m5.util import compareVersions, readCommand
 
 ########################################################################
 #
@@ -217,7 +177,7 @@
     # 1) Grab repository revision if we know it.
     cmd = "hg id -n -i -t -b"
     try:
-        hg_info = read_command(cmd, cwd=main.root.abspath).strip()
+        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
     except OSError:
         print mercurial_bin_not_found
 
@@ -381,8 +341,8 @@
 # M5_PLY is used by isa_parser.py to find the PLY package.
 main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
 
-CXX_version = read_command([main['CXX'],'--version'], exception=False)
-CXX_V = read_command([main['CXX'],'-V'], exception=False)
+CXX_version = readCommand([main['CXX'],'--version'], exception=False)
+CXX_V = readCommand([main['CXX'],'-V'], exception=False)
 
 main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
 main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
@@ -435,7 +395,7 @@
     Exit(1)
 
 # Check for appropriate SWIG version
-swig_version = read_command(('swig', '-version'), exception='').split()
+swig_version = readCommand(('swig', '-version'), exception='').split()
 # First 3 words should be "SWIG Version x.y.z"
 if len(swig_version) < 3 or \
         swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
@@ -443,7 +403,7 @@
     Exit(1)
 
 min_swig_version = '1.3.28'
-if compare_versions(swig_version[2], min_swig_version) < 0:
+if compareVersions(swig_version[2], min_swig_version) < 0:
     print 'Error: SWIG version', min_swig_version, 'or newer required.'
     print '       Installed version:', swig_version[2]
     Exit(1)
@@ -514,8 +474,8 @@
 try:
     import platform
     uname = platform.uname()
-    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
-        if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
+    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
+        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
             main.Append(CCFLAGS='-arch x86_64')
             main.Append(CFLAGS='-arch x86_64')
             main.Append(LINKFLAGS='-arch x86_64')
@@ -615,9 +575,9 @@
 
 # Check MySQL version.
 if have_mysql:
-    mysql_version = read_command(mysql_config + ' --version')
+    mysql_version = readCommand(mysql_config + ' --version')
     min_mysql_version = '4.1'
-    if compare_versions(mysql_version, min_mysql_version) < 0:
+    if compareVersions(mysql_version, min_mysql_version) < 0:
         print 'Warning: MySQL', min_mysql_version, 'or newer required.'
         print '         Version', mysql_version, 'detected.'
         have_mysql = False
diff -r 9e27313312e6 -r 4c84e771cca7 configs/common/Caches.py
--- a/configs/common/Caches.py  Tue Sep 22 15:24:16 2009 -0700
+++ b/configs/common/Caches.py  Tue Sep 22 15:24:16 2009 -0700
@@ -26,7 +26,6 @@
 #
 # Authors: Lisa Hsu
 
-import m5
 from m5.objects import *
 
 class L1Cache(BaseCache):
diff -r 9e27313312e6 -r 4c84e771cca7 configs/common/FSConfig.py
--- a/configs/common/FSConfig.py        Tue Sep 22 15:24:16 2009 -0700
+++ b/configs/common/FSConfig.py        Tue Sep 22 15:24:16 2009 -0700
@@ -26,8 +26,6 @@
 #
 # Authors: Kevin Lim
 
-import m5
-from m5 import makeList
 from m5.objects import *
 from Benchmarks import *
 
diff -r 9e27313312e6 -r 4c84e771cca7 configs/common/Simulation.py
--- a/configs/common/Simulation.py      Tue Sep 22 15:24:16 2009 -0700
+++ b/configs/common/Simulation.py      Tue Sep 22 15:24:16 2009 -0700
@@ -28,9 +28,13 @@
 
 from os import getcwd
 from os.path import join as joinpath
+
 import m5
+from m5.defines import buildEnv
 from m5.objects import *
-m5.AddToPath('../common')
+from m5.util import *
+
+addToPath('../common')
 
 def setCPUClass(options):
 
@@ -82,10 +86,10 @@
         cptdir = getcwd()
 
     if options.fast_forward and options.checkpoint_restore != None:
-        m5.fatal("Error: Can't specify both --fast-forward and 
--checkpoint-restore")
+        fatal("Can't specify both --fast-forward and --checkpoint-restore")
 
     if options.standard_switch and not options.caches:
-        m5.fatal("Error: Must specify --caches when using --standard-switch")
+        fatal("Must specify --caches when using --standard-switch")
 
     np = options.num_cpus
     max_checkpoints = options.max_checkpoints
@@ -107,7 +111,7 @@
             if options.fast_forward:
                 testsys.cpu[i].max_insts_any_thread = int(options.fast_forward)
             switch_cpus[i].system =  testsys
-            if not m5.build_env['FULL_SYSTEM']:
+            if not buildEnv['FULL_SYSTEM']:
                 switch_cpus[i].workload = testsys.cpu[i].workload
             switch_cpus[i].clock = testsys.cpu[0].clock
             # simulation period
@@ -126,7 +130,7 @@
         for i in xrange(np):
             switch_cpus[i].system =  testsys
             switch_cpus_1[i].system =  testsys
-            if not m5.build_env['FULL_SYSTEM']:
+            if not buildEnv['FULL_SYSTEM']:
                 switch_cpus[i].workload = testsys.cpu[i].workload
                 switch_cpus_1[i].workload = testsys.cpu[i].workload
             switch_cpus[i].clock = testsys.cpu[0].clock
@@ -141,7 +145,7 @@
             # Fast forward to a simpoint (warning: time consuming)
             elif options.simpoint:
                 if testsys.cpu[i].workload[0].simpoint == 0:
-                    m5.fatal('simpoint not found')
+                    fatal('simpoint not found')
                 testsys.cpu[i].max_insts_any_thread = \
                     testsys.cpu[i].workload[0].simpoint
             # No distance specified, just switch
@@ -174,7 +178,7 @@
         if options.simpoint:
             for i in xrange(np):
                 if testsys.cpu[i].workload[0].simpoint == 0:
-                    m5.fatal('no simpoint for testsys.cpu[%d].workload[0]', i)
+                    fatal('no simpoint for testsys.cpu[%d].workload[0]', i)
                 checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + 
offset
                 testsys.cpu[i].max_insts_any_thread = checkpoint_inst
                 # used for output below
@@ -194,14 +198,13 @@
         import re
 
         if not isdir(cptdir):
-            m5.fatal("checkpoint dir %s does not exist!", cptdir)
+            fatal("checkpoint dir %s does not exist!", cptdir)
 
         if options.at_instruction:
             checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % \
                     (options.bench, options.checkpoint_restore))
             if not exists(checkpoint_dir):
-                m5.fatal("Unable to find checkpoint directory %s",
-                         checkpoint_dir)
+                fatal("Unable to find checkpoint directory %s", checkpoint_dir)
 
             print "Restoring checkpoint ..."
             m5.restoreCheckpoint(root, checkpoint_dir)
@@ -209,7 +212,7 @@
         elif options.simpoint:
             # assume workload 0 has the simpoint
             if testsys.cpu[0].workload[0].simpoint == 0:
-                m5.fatal('Unable to find simpoint')
+                fatal('Unable to find simpoint')
 
             options.checkpoint_restore += \
                 int(testsys.cpu[0].workload[0].simpoint)
@@ -217,8 +220,8 @@
             checkpoint_dir = joinpath(cptdir, "cpt.%s.%d" % \
                     (options.bench, options.checkpoint_restore))
             if not exists(checkpoint_dir):
-                m5.fatal("Unable to find checkpoint directory %s.%s",
-                        options.bench, options.checkpoint_restore)
+                fatal("Unable to find checkpoint directory %s.%s",
+                      options.bench, options.checkpoint_restore)
 
             print "Restoring checkpoint ..."
             m5.restoreCheckpoint(root,checkpoint_dir)
@@ -237,7 +240,7 @@
             cpt_num = options.checkpoint_restore
 
             if cpt_num > len(cpts):
-                m5.fatal('Checkpoint %d not found', cpt_num)
+                fatal('Checkpoint %d not found', cpt_num)
 
             ## Adjust max tick based on our starting tick
             maxtick = maxtick - int(cpts[cpt_num - 1])
diff -r 9e27313312e6 -r 4c84e771cca7 configs/example/fs.py
--- a/configs/example/fs.py     Tue Sep 22 15:24:16 2009 -0700
+++ b/configs/example/fs.py     Tue Sep 22 15:24:16 2009 -0700
@@ -26,15 +26,20 @@
 #
 # Authors: Ali Saidi
 
-import optparse, os, sys
+import optparse
+import os
+import sys
 
 import m5
+from m5.defines import buildEnv
+from m5.objects import *
+from m5.util import addToPath, fatal
 
-if not m5.build_env['FULL_SYSTEM']:
-    m5.fatal("This script requires full-system mode (*_FS).")
+if not buildEnv['FULL_SYSTEM']:
+    fatal("This script requires full-system mode (*_FS).")
 
-from m5.objects import *
-m5.AddToPath('../common')
+addToPath('../common')
+
 from FSConfig import *
 from SysPaths import *
 from Benchmarks import *
@@ -98,16 +103,16 @@
 
 np = options.num_cpus
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to