Add .m5 configuration directory
[gem5.git] / src / python / m5 / __init__.py
index 2d4825b0efc03792208c3bceaca8fef65cd38610..f21bb362eb058a145a52da27436d9233c6e0897e 100644 (file)
 # Authors: Nathan Binkert
 #          Steve Reinhardt
 
-import sys, os, time, atexit, optparse
+import os
+import sys
 
-# import the SWIG-wrapped main C++ functions
-import main
-# import a few SWIG-wrapped items (those that are likely to be used
-# directly by user scripts) completely into this module for
-# convenience
-from main import simulate, SimLoopExitEvent
+import smartdict
 
-# import the m5 compile options
-import defines
+# define a MaxTick parameter
+MaxTick = 2**63 - 1
 
 # define this here so we can use it right away if necessary
 def panic(string):
     print >>sys.stderr, 'panic:', string
     sys.exit(1)
 
+# force scalars to one-element lists for uniformity
+def makeList(objOrList):
+    if isinstance(objOrList, list):
+        return objOrList
+    return [objOrList]
+
 # Prepend given directory to system module search path.  We may not
 # need this anymore if we can structure our config library more like a
 # Python package.
@@ -57,81 +59,41 @@ def AddToPath(path):
     # so place the new dir right after that.
     sys.path.insert(1, path)
 
-
-# Callback to set trace flags.  Not necessarily the best way to do
-# things in the long run (particularly if we change how these global
-# options are handled).
-def setTraceFlags(option, opt_str, value, parser):
-    objects.Trace.flags = value
-
-def setTraceStart(option, opt_str, value, parser):
-    objects.Trace.start = value
-
-def clearPCSymbol(option, opt_str, value, parser):
-    objects.ExecutionTrace.pc_symbol = False
-
-def clearPrintCycle(option, opt_str, value, parser):
-    objects.ExecutionTrace.print_cycle = False
-
-def statsTextFile(option, opt_str, value, parser):
-    objects.Statistics.text_file = value
-
-# Standard optparse options.  Need to be explicitly included by the
-# user script when it calls optparse.OptionParser().
-standardOptions = [
-    optparse.make_option("--traceflags", type="string", action="callback",
-                         callback=setTraceFlags),
-    optparse.make_option("--tracestart", type="int", action="callback",
-                         callback=setTraceStart),
-    optparse.make_option("--nopcsymbol", action="callback",
-                         callback=clearPCSymbol,
-                         help="Turn off printing PC symbols in trace output"),
-    optparse.make_option("--noprintcycle", action="callback",
-                         callback=clearPrintCycle,
-                         help="Turn off printing cycles in trace output"),
-    optparse.make_option("--statsfile", type="string", action="callback",
-                         callback=statsTextFile, metavar="FILE",
-                         help="Sets the output file for the statistics")
-    ]
-
 # make a SmartDict out of the build options for our local use
-import smartdict
 build_env = smartdict.SmartDict()
-build_env.update(defines.m5_build_env)
 
 # make a SmartDict out of the OS environment too
 env = smartdict.SmartDict()
 env.update(os.environ)
 
-# The final hook to generate .ini files.  Called from the user script
-# once the config is built.
-def instantiate(root):
-    config.ticks_per_sec = float(root.clock.frequency)
-    # ugly temporary hack to get output to config.ini
-    sys.stdout = file('config.ini', 'w')
-    root.print_ini()
-    sys.stdout.close() # close config.ini
-    sys.stdout = sys.__stdout__ # restore to original
-    main.initialize()  # load config.ini into C++ and process it
-    noDot = True # temporary until we fix dot
-    if not noDot:
-       dot = pydot.Dot()
-       instance.outputDot(dot)
-       dot.orientation = "portrait"
-       dot.size = "8.5,11"
-       dot.ranksep="equally"
-       dot.rank="samerank"
-       dot.write("config.dot")
-       dot.write_ps("config.ps")
-
-# Export curTick to user script.
-def curTick():
-    return main.cvar.curTick
-
-# register our C++ exit callback function with Python
-atexit.register(main.doExitCleanup)
-
-# This import allows user scripts to reference 'm5.objects.Foo' after
-# just doing an 'import m5' (without an 'import m5.objects').  May not
-# matter since most scripts will probably 'from m5.objects import *'.
+# Since we have so many mutual imports in this package, we should:
+# 1. Put all intra-package imports at the *bottom* of the file, unless
+#    they're absolutely needed before that (for top-level statements
+#    or class attributes).  Imports of "trivial" packages that don't
+#    import other packages (e.g., 'smartdict') can be at the top.
+# 2. Never use 'from foo import *' on an intra-package import since
+#    you can get the wrong result if foo is only partially imported
+#    at the point you do that (i.e., because foo is in the middle of
+#    importing *you*).
+try:
+    import internal
+    running_m5 = True
+except ImportError:
+    running_m5 = False
+
+if running_m5:
+    import defines
+    build_env.update(defines.m5_build_env)
+else:
+    import __scons
+    build_env.update(__scons.m5_build_env)
+
+if running_m5:
+    from event import *
+    from simulate import *
+    from main import options
+    import stats
+
+import SimObject
+import params
 import objects