import socket
import sys
-from util import attrdict
-import config
-from options import OptionParser
-
__all__ = [ 'options', 'arguments', 'main' ]
-usage="%prog [m5 options] script.py [script options]"
+usage="%prog [gem5 options] script.py [script options]"
version="%prog 2.0"
-brief_copyright='''
-Copyright (c) 2001-2008
-The Regents of The University of Michigan
-All Rights Reserved
-'''
-
-options = OptionParser(usage=usage, version=version,
- description=brief_copyright)
-add_option = options.add_option
-set_group = options.set_group
-usage = options.usage
-
-# 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,
- help="Show the readme")
-add_option('-N', "--release-notes", action="store_true", default=False,
- help="Show the release notes")
-
-# Options for configuring the base simulator
-add_option('-d', "--outdir", metavar="DIR", default="m5out",
- help="Set the output directory to DIR [Default: %default]")
-add_option('-r', "--redirect-stdout", action="store_true", default=False,
- help="Redirect stdout (& stderr, without -e) to file")
-add_option('-e', "--redirect-stderr", action="store_true", default=False,
- help="Redirect stderr to file")
-add_option("--stdout-file", metavar="FILE", default="simout",
- help="Filename for -r redirection [Default: %default]")
-add_option("--stderr-file", metavar="FILE", default="simerr",
- help="Filename for -e redirection [Default: %default]")
-add_option('-i', "--interactive", action="store_true", default=False,
- help="Invoke the interactive interpreter after running the script")
-add_option("--pdb", action="store_true", default=False,
- help="Invoke the python debugger before running the script")
-add_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
- help="Prepend PATH to the system path when invoking the script")
-add_option('-q', "--quiet", action="count", default=0,
- help="Reduce verbosity")
-add_option('-v', "--verbose", action="count", default=0,
- help="Increase verbosity")
-
-# Statistics options
-set_group("Statistics Options")
-add_option("--stats-file", metavar="FILE", default="stats.txt",
- help="Sets the output file for statistics [Default: %default]")
-
-# Configuration Options
-set_group("Configuration Options")
-add_option("--dump-config", metavar="FILE", default="config.ini",
- help="Dump configuration output file [Default: %default]")
-
-# Debugging options
-set_group("Debugging Options")
-add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
- help="Cycle to create a breakpoint")
-add_option("--remote-gdb-port", type='int', default=7000,
- help="Remote gdb base port")
-
-# 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 (-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",
- help="Sets the output file for tracing [Default: %default]")
-add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
- help="Ignore EXPR sim objects")
-
-# Help options
-set_group("Help Options")
-add_option("--list-sim-objects", action='store_true', default=False,
- help="List all built-in SimObjects, their parameters and default values")
-
-def main():
+brief_copyright=\
+ "gem5 is copyrighted software; use the --copyright option for details."
+
+def parse_options():
+ import config
+ from options import OptionParser
+
+ options = OptionParser(usage=usage, version=version,
+ description=brief_copyright)
+ option = options.add_option
+ group = options.set_group
+
+ # Help options
+ option('-B', "--build-info", action="store_true", default=False,
+ help="Show build information")
+ option('-C', "--copyright", action="store_true", default=False,
+ help="Show full copyright information")
+ option('-R', "--readme", action="store_true", default=False,
+ help="Show the readme")
+
+ # Options for configuring the base simulator
+ option('-d', "--outdir", metavar="DIR", default="m5out",
+ help="Set the output directory to DIR [Default: %default]")
+ option('-r', "--redirect-stdout", action="store_true", default=False,
+ help="Redirect stdout (& stderr, without -e) to file")
+ option('-e', "--redirect-stderr", action="store_true", default=False,
+ help="Redirect stderr to file")
+ option("--stdout-file", metavar="FILE", default="simout",
+ help="Filename for -r redirection [Default: %default]")
+ option("--stderr-file", metavar="FILE", default="simerr",
+ help="Filename for -e redirection [Default: %default]")
+ option('-i', "--interactive", action="store_true", default=False,
+ help="Invoke the interactive interpreter after running the script")
+ option("--pdb", action="store_true", default=False,
+ help="Invoke the python debugger before running the script")
+ option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
+ help="Prepend PATH to the system path when invoking the script")
+ option('-q', "--quiet", action="count", default=0,
+ help="Reduce verbosity")
+ option('-v', "--verbose", action="count", default=0,
+ help="Increase verbosity")
+
+ # Statistics options
+ group("Statistics Options")
+ option("--stats-file", metavar="FILE", default="stats.txt",
+ help="Sets the output file for statistics [Default: %default]")
+
+ # Configuration Options
+ group("Configuration Options")
+ option("--dump-config", metavar="FILE", default="config.ini",
+ help="Dump configuration output file [Default: %default]")
+ option("--json-config", metavar="FILE", default="config.json",
+ help="Create JSON output of the configuration [Default: %default]")
+ option("--dot-config", metavar="FILE", default="config.dot",
+ help="Create DOT & pdf outputs of the configuration [Default: %default]")
+
+ # Debugging options
+ group("Debugging Options")
+ option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
+ help="Cycle to create a breakpoint")
+ option("--debug-help", action='store_true',
+ help="Print help on trace flags")
+ option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
+ help="Sets the flags for tracing (-FLAG disables a flag)")
+ option("--remote-gdb-port", type='int', default=7000,
+ help="Remote gdb base port (set to 0 to disable listening)")
+
+ # Tracing options
+ group("Trace Options")
+ option("--trace-start", metavar="TIME", type='int',
+ help="Start tracing at TIME (must be in ticks)")
+ option("--trace-file", metavar="FILE", default="cout",
+ help="Sets the output file for tracing [Default: %default]")
+ option("--trace-ignore", metavar="EXPR", action='append', split=':',
+ help="Ignore EXPR sim objects")
+
+ # Help options
+ group("Help Options")
+ option("--list-sim-objects", action='store_true', default=False,
+ help="List all built-in SimObjects, their params and default values")
+
+ # load the options.py config file to allow people to set their own
+ # default options
+ options_file = config.get('options.py')
+ if options_file:
+ scope = { 'options' : options }
+ execfile(options_file, scope)
+
+ arguments = options.parse_args()
+ return options,arguments
+
+def interact(scope):
+ banner = "gem5 Interactive Console"
+ sys.argv = []
+ try:
+ from IPython.Shell import IPShellEmbed
+ ipshell = IPShellEmbed(banner=banner,user_ns=scope)
+ ipshell()
+ except ImportError:
+ code.InteractiveConsole(scope).interact(banner)
+
+def main(*args):
+ import m5
+
import core
import debug
import defines
import stats
import trace
+ from util import fatal
+
+ if len(args) == 0:
+ options, arguments = parse_options()
+ elif len(args) == 2:
+ options, arguments = args
+ else:
+ raise TypeError, "main() takes 0 or 2 arguments (%d given)" % len(args)
+
+ m5.options = options
+
def check_tracing():
if defines.TRACING_ON:
return
fatal("Tracing is not enabled. Compile with TRACING_ON")
- # load the options.py config file to allow people to set their own
- # default options
- options_file = config.get('options.py')
- if options_file:
- scope = { 'options' : options }
- execfile(options_file, scope)
-
- arguments = options.parse_args()
-
if not os.path.isdir(options.outdir):
os.makedirs(options.outdir)
print 'Build information:'
print
print 'compiled %s' % defines.compileDate;
- print "revision %s" % defines.hgRev
print 'build options:'
keys = defines.buildEnv.keys()
keys.sort()
if options.copyright:
done = True
- print info.LICENSE
- print
-
- if options.authors:
- done = True
- print 'Author information:'
- print
- print info.AUTHORS
+ print info.COPYING
print
if options.readme:
print info.README
print
- if options.release_notes:
- done = True
- print 'Release Notes:'
- print
- print info.RELEASE_NOTES
- print
-
- if options.trace_help:
+ if options.debug_help:
done = True
check_tracing()
- trace.help()
+ debug.help()
if options.list_sim_objects:
import SimObject
verbose = options.verbose - options.quiet
if options.verbose >= 0:
- print "M5 Simulator System"
+ print "gem5 Simulator System. http://gem5.org"
print brief_copyright
print
- print "M5 compiled %s" % defines.compileDate;
- print "M5 revision %s" % defines.hgRev
+ print "gem5 compiled %s" % defines.compileDate;
- print "M5 started %s" % datetime.datetime.now().strftime("%b %e %Y %X")
- print "M5 executing on %s" % socket.gethostname()
+ print "gem5 started %s" % \
+ datetime.datetime.now().strftime("%b %e %Y %X")
+ print "gem5 executing on %s" % socket.gethostname()
print "command line:",
for argv in sys.argv:
for when in options.debug_break:
debug.schedBreakCycle(int(when))
- if options.trace_flags:
+ if options.debug_flags:
check_tracing()
on_flags = []
off_flags = []
- for flag in options.trace_flags:
+ for flag in options.debug_flags:
off = False
if flag.startswith('-'):
flag = flag[1:]
off = True
- if flag not in trace.flags.all and flag != "All":
- print >>sys.stderr, "invalid trace flag '%s'" % flag
+
+ if flag not in debug.flags:
+ print >>sys.stderr, "invalid debug flag '%s'" % flag
sys.exit(1)
if off:
- off_flags.append(flag)
+ debug.flags[flag].disable()
else:
- on_flags.append(flag)
-
- for flag in on_flags:
- trace.set(flag)
-
- for flag in off_flags:
- trace.clear(flag)
+ debug.flags[flag].enable()
if options.trace_start:
check_tracing()
# once the script is done
if options.interactive:
- interact = code.InteractiveConsole(scope)
- interact.interact("M5 Interactive Console")
+ interact(scope)
if __name__ == '__main__':
from pprint import pprint
- # load the options.py config file to allow people to set their own
- # default options
- options_file = config.get('options.py')
- if options_file:
- scope = { 'options' : options }
- execfile(options_file, scope)
-
- arguments = options.parse_args()
+ options, arguments = parse_options()
print 'opts:'
pprint(options, indent=4)