merge
[gem5.git] / src / python / m5 / main.py
index 0bd5b431a5f161b6225662084648499417c42f14..96f017cb0993ebd3e833cff71582c87d5047c294 100644 (file)
 #
 # Authors: Nathan Binkert
 
-import code, optparse, os, socket, sys
-from datetime import datetime
+import code
+import datetime
+import optparse
+import os
+import socket
+import sys
+
 from attrdict import attrdict
+import defines
+import traceflags
 
 __all__ = [ 'options', 'arguments', 'main' ]
 
@@ -40,6 +47,19 @@ The Regents of The University of Michigan
 All Rights Reserved
 '''
 
+def print_list(items, indent=4):
+    line = ' ' * indent
+    for i,item in enumerate(items):
+        if len(line) + len(item) > 76:
+            print line
+            line = ' ' * indent
+
+        if i < len(items) - 1:
+            line += '%s, ' % item
+        else:
+            line += item
+            print line
+
 # there's only one option parsing done, so make it global and add some
 # helper functions to make it work well.
 parser = optparse.OptionParser(usage=usage, version=version,
@@ -102,6 +122,8 @@ def bool_option(name, default, help):
 # Help options
 add_option('-A', "--authors", action="store_true", default=False,
     help="Show author information")
+add_option('-B', "--build-info", action="store_true", default=False,
+    help="Show build information")
 add_option('-C', "--copyright", action="store_true", default=False,
     help="Show full copyright information")
 add_option('-R', "--readme", action="store_true", default=False,
@@ -135,8 +157,10 @@ add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
 
 # Tracing options
 set_group("Trace Options")
+add_option("--trace-help", action='store_true',
+    help="Print help on trace flags")
 add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
-    help="Sets the flags for tracing")
+    help="Sets the flags for tracing (-FLAG disables a flag)")
 add_option("--trace-start", metavar="TIME", type='int',
     help="Start tracing at TIME (must be in ticks)")
 add_option("--trace-file", metavar="FILE", default="cout",
@@ -144,33 +168,6 @@ add_option("--trace-file", metavar="FILE", default="cout",
 add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
     help="Ignore EXPR sim objects")
 
-# Execution Trace options
-set_group("Execution Trace Options")
-bool_option("speculative", default=True,
-    help="Don't capture speculative instructions")
-bool_option("print-cycle", default=True,
-    help="Don't print cycle numbers in trace output")
-bool_option("print-symbol", default=True,
-    help="Disable PC symbols in trace output")
-bool_option("print-opclass", default=True,
-    help="Don't print op class type in trace output")
-bool_option("print-thread", default=True,
-    help="Don't print thread number in trace output")
-bool_option("print-effaddr", default=True,
-    help="Don't print effective address in trace output")
-bool_option("print-data", default=True,
-    help="Don't print result data in trace output")
-bool_option("print-iregs", default=False,
-    help="Print fetch sequence numbers in trace output")
-bool_option("print-fetch-seq", default=False,
-    help="Print fetch sequence numbers in trace output")
-bool_option("print-cpseq", default=False,
-    help="Print correct path sequence numbers in trace output")
-#bool_option("print-reg-delta", default=False,
-#    help="Print which registers changed to what in trace output")
-bool_option("legion-lock", default=False,
-    help="Compare simulator state with Legion simulator every cycle")
-
 options = attrdict()
 arguments = []
 
@@ -199,12 +196,29 @@ def parse_args():
 
 def main():
     import defines
+    import event
     import info
     import internal
 
     parse_args()
 
     done = False
+
+    if options.build_info:
+        done = True
+        print 'Build information:'
+        print
+        print 'compiled %s' % internal.core.cvar.compileDate;
+        print 'started %s' % datetime.datetime.now().ctime()
+        print 'executing on %s' % socket.gethostname()
+        print 'build options:'
+        keys = defines.m5_build_env.keys()
+        keys.sort()
+        for key in keys:
+            val = defines.m5_build_env[key]
+            print '    %s = %s' % (key, val)
+        print
+
     if options.copyright:
         done = True
         print info.LICENSE
@@ -231,6 +245,19 @@ def main():
         print info.RELEASE_NOTES
         print
 
+    if options.trace_help:
+        done = True
+        print "Base Flags:"
+        print_list(traceflags.baseFlags, indent=4)
+        print
+        print "Compound Flags:"
+        for flag in traceflags.compoundFlags:
+            if flag == 'All':
+                continue
+            print "    %s:" % flag
+            print_list(traceflags.compoundFlagMap[flag], indent=8)
+            print
+
     if done:
         sys.exit(0)
 
@@ -238,8 +265,8 @@ def main():
         print "M5 Simulator System"
         print brief_copyright
         print
-        print "M5 compiled %s" % internal.main.cvar.compileDate;
-        print "M5 started %s" % datetime.now().ctime()
+        print "M5 compiled %s" % internal.core.cvar.compileDate;
+        print "M5 started %s" % datetime.datetime.now().ctime()
         print "M5 executing on %s" % socket.gethostname()
         print "command line:",
         for argv in sys.argv:
@@ -250,10 +277,11 @@ def main():
     if not arguments or not os.path.isfile(arguments[0]):
         if arguments and not os.path.isfile(arguments[0]):
             print "Script %s not found" % arguments[0]
+
         usage(2)
 
     # tell C++ about output directory
-    internal.main.setOutputDir(options.outdir)
+    internal.core.setOutputDir(options.outdir)
 
     # update the system path with elements from the -p option
     sys.path[0:0] = options.path
@@ -261,41 +289,46 @@ def main():
     import objects
 
     # set stats options
-    objects.Statistics.text_file = options.stats_file
+    internal.stats.initText(options.stats_file)
 
     # set debugging options
     for when in options.debug_break:
         internal.debug.schedBreakCycle(int(when))
 
+    on_flags = []
+    off_flags = []
     for flag in options.trace_flags:
-        internal.trace.setFlag(flag)
-
-    if options.trace_start is not None:
-        internal.trace.enabled = False
+        off = False
+        if flag.startswith('-'):
+            flag = flag[1:]
+            off = True
+        if flag not in traceflags.allFlags:
+            print >>sys.stderr, "invalid trace flag '%s'" % flag
+            sys.exit(1)
+
+        if off:
+            off_flags.append(flag)
+        else:
+            on_flags.append(flag)
+
+    for flag in on_flags:
+        internal.trace.set(flag)
+
+    for flag in off_flags:
+        internal.trace.clear(flag)
+
+    if options.trace_start:
         def enable_trace():
-            internal.event.enabled = True
-        internal.event.create(enable_trace, options.trace_start)
+            internal.trace.cvar.enabled = True
+        event.create(enable_trace, int(options.trace_start))
+    else:
+        internal.trace.cvar.enabled = True
 
-    #if options.trace_file is not None:
-    #    internal.trace.file(options.trace_file)
+    internal.trace.output(options.trace_file)
 
     for ignore in options.trace_ignore:
         internal.trace.ignore(ignore)
 
-    # set execution trace options
-    objects.ExecutionTrace.speculative = options.speculative
-    objects.ExecutionTrace.print_cycle = options.print_cycle
-    objects.ExecutionTrace.pc_symbol = options.print_symbol
-    objects.ExecutionTrace.print_opclass = options.print_opclass
-    objects.ExecutionTrace.print_thread = options.print_thread
-    objects.ExecutionTrace.print_effaddr = options.print_effaddr
-    objects.ExecutionTrace.print_data = options.print_data
-    objects.ExecutionTrace.print_iregs = options.print_iregs
-    objects.ExecutionTrace.print_fetchseq = options.print_fetch_seq
-    objects.ExecutionTrace.print_cpseq = options.print_cpseq
-    #objects.ExecutionTrace.print_reg_delta = options.print_reg_delta
-    objects.ExecutionTrace.legion_lockstep = options.legion_lock
-
     sys.argv = arguments
     sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path