+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
+
+ listener_modes = ( "on", "off", "auto" )
+
+ # 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("--listener-mode", metavar="{on,off,auto}",
+ choices=listener_modes, default="auto",
+ help="Port (e.g., gdb) listener mode (auto: Enable if running " \
+ "interactively) [Default: %default]")
+ option("--listener-loopback-only", action="store_true", default=False,
+ help="Port listeners will only accept connections over the " \
+ "loopback device")
+ 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]")
+ option("--dot-dvfs-config", metavar="FILE", default=None,
+ help="Create DOT & pdf outputs of the DVFS configuration" + \
+ " [Default: %default]")
+
+ # Debugging options
+ group("Debugging Options")
+ option("--debug-break", metavar="TICK[,TICK]", action='append', split=',',
+ help="Create breakpoint(s) at TICK(s) " \
+ "(kills process if no debugger attached)")
+ option("--debug-help", action='store_true',
+ help="Print help on debug flags")
+ option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',',
+ help="Sets the flags for debug output (-FLAG disables a flag)")
+ option("--debug-start", metavar="TICK", type='int',
+ help="Start debug output at TICK")
+ option("--debug-end", metavar="TICK", type='int',
+ help="End debug output at TICK")
+ option("--debug-file", metavar="FILE", default="cout",
+ help="Sets the output file for debug [Default: %default]")
+ option("--debug-ignore", metavar="EXPR", action='append', split=':',
+ help="Ignore EXPR sim objects")
+ option("--remote-gdb-port", type='int', default=7000,
+ help="Remote gdb base port (set to 0 to disable listening)")
+
+ # 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"
+
+ ipshell = None
+ prompt_in1 = "gem5 \\#> "
+ prompt_out = "gem5 \\#: "
+
+ # Is IPython version 0.10 or earlier available?
+ try:
+ from IPython.Shell import IPShellEmbed
+ ipshell = IPShellEmbed(argv=["-prompt_in1", prompt_in1,
+ "-prompt_out", prompt_out],
+ banner=banner, user_ns=scope)
+ except ImportError:
+ pass
+
+ # Is IPython version 0.11 or later available?
+ if not ipshell:
+ try:
+ import IPython
+ from IPython.config.loader import Config
+ from IPython.terminal.embed import InteractiveShellEmbed
+
+ cfg = Config()
+ cfg.PromptManager.in_template = prompt_in1
+ cfg.PromptManager.out_template = prompt_out
+ ipshell = InteractiveShellEmbed(config=cfg, user_ns=scope,
+ banner1=banner)
+ except ImportError:
+ pass
+
+ if ipshell:
+ ipshell()