2006-07-11 05:00:13 +02:00
|
|
|
# Copyright (c) 2005 The Regents of The University of Michigan
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met: redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer;
|
|
|
|
# redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution;
|
|
|
|
# neither the name of the copyright holders nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# Authors: Nathan Binkert
|
|
|
|
|
|
|
|
import code, optparse, os, socket, sys
|
|
|
|
from datetime import datetime
|
|
|
|
from attrdict import attrdict
|
2007-02-13 09:16:41 +01:00
|
|
|
import traceflags
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
__all__ = [ 'options', 'arguments', 'main' ]
|
|
|
|
|
|
|
|
usage="%prog [m5 options] script.py [script options]"
|
|
|
|
version="%prog 2.0"
|
|
|
|
brief_copyright='''
|
|
|
|
Copyright (c) 2001-2006
|
|
|
|
The Regents of The University of Michigan
|
|
|
|
All Rights Reserved
|
|
|
|
'''
|
|
|
|
|
2007-02-13 09:16:41 +01:00
|
|
|
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
|
|
|
|
|
2006-07-11 05:00:13 +02:00
|
|
|
# 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,
|
|
|
|
description=brief_copyright,
|
|
|
|
formatter=optparse.TitledHelpFormatter())
|
2006-07-11 17:28:59 +02:00
|
|
|
parser.disable_interspersed_args()
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
# current option group
|
|
|
|
group = None
|
|
|
|
|
|
|
|
def set_group(*args, **kwargs):
|
|
|
|
'''set the current option group'''
|
|
|
|
global group
|
|
|
|
if not args and not kwargs:
|
|
|
|
group = None
|
|
|
|
else:
|
|
|
|
group = parser.add_option_group(*args, **kwargs)
|
|
|
|
|
|
|
|
class splitter(object):
|
|
|
|
def __init__(self, split):
|
|
|
|
self.split = split
|
|
|
|
def __call__(self, option, opt_str, value, parser):
|
|
|
|
getattr(parser.values, option.dest).extend(value.split(self.split))
|
|
|
|
|
|
|
|
def add_option(*args, **kwargs):
|
|
|
|
'''add an option to the current option group, or global none set'''
|
|
|
|
|
|
|
|
# if action=split, but allows the option arguments
|
|
|
|
# themselves to be lists separated by the split variable'''
|
|
|
|
|
|
|
|
if kwargs.get('action', None) == 'append' and 'split' in kwargs:
|
|
|
|
split = kwargs.pop('split')
|
|
|
|
kwargs['default'] = []
|
|
|
|
kwargs['type'] = 'string'
|
|
|
|
kwargs['action'] = 'callback'
|
|
|
|
kwargs['callback'] = splitter(split)
|
|
|
|
|
|
|
|
if group:
|
|
|
|
return group.add_option(*args, **kwargs)
|
|
|
|
|
|
|
|
return parser.add_option(*args, **kwargs)
|
|
|
|
|
|
|
|
def bool_option(name, default, help):
|
|
|
|
'''add a boolean option called --name and --no-name.
|
|
|
|
Display help depending on which is the default'''
|
|
|
|
|
|
|
|
tname = '--%s' % name
|
|
|
|
fname = '--no-%s' % name
|
|
|
|
dest = name.replace('-', '_')
|
|
|
|
if default:
|
|
|
|
thelp = optparse.SUPPRESS_HELP
|
|
|
|
fhelp = help
|
|
|
|
else:
|
|
|
|
thelp = help
|
|
|
|
fhelp = optparse.SUPPRESS_HELP
|
|
|
|
|
|
|
|
add_option(tname, action="store_true", default=default, help=thelp)
|
|
|
|
add_option(fname, action="store_false", dest=dest, help=fhelp)
|
|
|
|
|
|
|
|
# Help options
|
|
|
|
add_option('-A', "--authors", action="store_true", default=False,
|
|
|
|
help="Show author 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=".",
|
|
|
|
help="Set the output directory to DIR [Default: %default]")
|
|
|
|
add_option('-i', "--interactive", action="store_true", default=False,
|
|
|
|
help="Invoke the interactive interpreter after running the script")
|
2006-07-12 21:21:23 +02:00
|
|
|
add_option("--pdb", action="store_true", default=False,
|
|
|
|
help="Invoke the python debugger before running the script")
|
2006-07-11 05:00:13 +02:00
|
|
|
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="m5stats.txt",
|
|
|
|
help="Sets the output file for statistics [Default: %default]")
|
|
|
|
|
|
|
|
# Debugging options
|
|
|
|
set_group("Debugging Options")
|
|
|
|
add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
|
|
|
|
help="Cycle to create a breakpoint")
|
|
|
|
|
|
|
|
# Tracing options
|
|
|
|
set_group("Trace Options")
|
2007-02-13 09:16:41 +01:00
|
|
|
add_option("--trace-help", action='store_true',
|
|
|
|
help="Print help on trace flags")
|
2006-07-11 05:00:13 +02:00
|
|
|
add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
|
2007-02-13 09:16:41 +01:00
|
|
|
help="Sets the flags for tracing (-FLAG disables a flag)")
|
2007-02-10 01:30:06 +01:00
|
|
|
add_option("--trace-start", metavar="TIME", type='int',
|
|
|
|
help="Start tracing at TIME (must be in ticks)")
|
2006-07-11 05:00:13 +02:00
|
|
|
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")
|
|
|
|
|
|
|
|
options = attrdict()
|
|
|
|
arguments = []
|
|
|
|
|
|
|
|
def usage(exitcode=None):
|
2006-07-13 21:48:41 +02:00
|
|
|
parser.print_help()
|
2006-07-11 05:00:13 +02:00
|
|
|
if exitcode is not None:
|
|
|
|
sys.exit(exitcode)
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
_opts,args = parser.parse_args()
|
|
|
|
opts = attrdict(_opts.__dict__)
|
|
|
|
|
|
|
|
# setting verbose and quiet at the same time doesn't make sense
|
|
|
|
if opts.verbose > 0 and opts.quiet > 0:
|
|
|
|
usage(2)
|
|
|
|
|
|
|
|
# store the verbosity in a single variable. 0 is default,
|
|
|
|
# negative numbers represent quiet and positive values indicate verbose
|
|
|
|
opts.verbose -= opts.quiet
|
|
|
|
|
|
|
|
del opts.quiet
|
|
|
|
|
|
|
|
options.update(opts)
|
|
|
|
arguments.extend(args)
|
|
|
|
return opts,args
|
|
|
|
|
|
|
|
def main():
|
2007-02-09 23:39:56 +01:00
|
|
|
import defines
|
2007-03-06 20:13:43 +01:00
|
|
|
import event
|
2007-02-09 23:39:56 +01:00
|
|
|
import info
|
2006-11-13 03:49:16 +01:00
|
|
|
import internal
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
parse_args()
|
|
|
|
|
|
|
|
done = False
|
|
|
|
if options.copyright:
|
|
|
|
done = True
|
|
|
|
print info.LICENSE
|
|
|
|
print
|
|
|
|
|
|
|
|
if options.authors:
|
|
|
|
done = True
|
|
|
|
print 'Author information:'
|
|
|
|
print
|
|
|
|
print info.AUTHORS
|
|
|
|
print
|
|
|
|
|
|
|
|
if options.readme:
|
|
|
|
done = True
|
|
|
|
print 'Readme:'
|
|
|
|
print
|
|
|
|
print info.README
|
|
|
|
print
|
|
|
|
|
|
|
|
if options.release_notes:
|
|
|
|
done = True
|
|
|
|
print 'Release Notes:'
|
|
|
|
print
|
|
|
|
print info.RELEASE_NOTES
|
|
|
|
print
|
|
|
|
|
2007-02-13 09:16:41 +01:00
|
|
|
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
|
|
|
|
|
2006-07-11 05:00:13 +02:00
|
|
|
if done:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if options.verbose >= 0:
|
|
|
|
print "M5 Simulator System"
|
|
|
|
print brief_copyright
|
|
|
|
print
|
2007-03-03 07:24:00 +01:00
|
|
|
print "M5 compiled %s" % internal.core.cvar.compileDate;
|
2006-07-11 05:00:13 +02:00
|
|
|
print "M5 started %s" % datetime.now().ctime()
|
|
|
|
print "M5 executing on %s" % socket.gethostname()
|
2006-07-27 23:37:28 +02:00
|
|
|
print "command line:",
|
|
|
|
for argv in sys.argv:
|
|
|
|
print argv,
|
|
|
|
print
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
# check to make sure we can find the listed script
|
|
|
|
if not arguments or not os.path.isfile(arguments[0]):
|
2006-07-14 23:53:16 +02:00
|
|
|
if arguments and not os.path.isfile(arguments[0]):
|
|
|
|
print "Script %s not found" % arguments[0]
|
2007-02-13 09:16:41 +01:00
|
|
|
|
2006-07-11 05:00:13 +02:00
|
|
|
usage(2)
|
|
|
|
|
|
|
|
# tell C++ about output directory
|
2007-03-03 07:24:00 +01:00
|
|
|
internal.core.setOutputDir(options.outdir)
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
# update the system path with elements from the -p option
|
|
|
|
sys.path[0:0] = options.path
|
|
|
|
|
|
|
|
import objects
|
|
|
|
|
|
|
|
# set stats options
|
2007-02-18 07:52:32 +01:00
|
|
|
internal.stats.initText(options.stats_file)
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
# set debugging options
|
2006-11-13 21:20:08 +01:00
|
|
|
for when in options.debug_break:
|
|
|
|
internal.debug.schedBreakCycle(int(when))
|
2006-07-11 05:00:13 +02:00
|
|
|
|
2007-02-13 09:16:41 +01:00
|
|
|
on_flags = []
|
|
|
|
off_flags = []
|
2007-02-09 23:39:56 +01:00
|
|
|
for flag in options.trace_flags:
|
2007-02-13 09:16:41 +01:00
|
|
|
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:
|
2007-02-11 00:14:50 +01:00
|
|
|
internal.trace.set(flag)
|
2007-02-09 23:39:56 +01:00
|
|
|
|
2007-02-13 09:16:41 +01:00
|
|
|
for flag in off_flags:
|
|
|
|
internal.trace.clear(flag)
|
|
|
|
|
2007-02-18 05:32:39 +01:00
|
|
|
if options.trace_start:
|
2007-02-09 23:39:56 +01:00
|
|
|
def enable_trace():
|
2007-02-18 05:32:39 +01:00
|
|
|
internal.trace.cvar.enabled = True
|
2007-03-06 20:13:43 +01:00
|
|
|
event.create(enable_trace, int(options.trace_start))
|
2007-02-18 05:32:39 +01:00
|
|
|
else:
|
2007-02-21 23:08:13 +01:00
|
|
|
internal.trace.cvar.enabled = True
|
2007-02-09 23:39:56 +01:00
|
|
|
|
2007-02-11 00:14:50 +01:00
|
|
|
internal.trace.output(options.trace_file)
|
2007-02-09 23:39:56 +01:00
|
|
|
|
|
|
|
for ignore in options.trace_ignore:
|
|
|
|
internal.trace.ignore(ignore)
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
sys.argv = arguments
|
|
|
|
sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
|
2006-07-12 21:18:49 +02:00
|
|
|
|
2007-01-03 19:16:22 +01:00
|
|
|
scope = { '__file__' : sys.argv[0],
|
|
|
|
'__name__' : '__m5_main__' }
|
2006-07-12 21:21:23 +02:00
|
|
|
|
|
|
|
# we want readline if we're doing anything interactive
|
|
|
|
if options.interactive or options.pdb:
|
2007-02-09 23:39:56 +01:00
|
|
|
exec "import readline" in scope
|
2006-07-12 21:21:23 +02:00
|
|
|
|
|
|
|
# if pdb was requested, execfile the thing under pdb, otherwise,
|
|
|
|
# just do the execfile normally
|
|
|
|
if options.pdb:
|
|
|
|
from pdb import Pdb
|
|
|
|
debugger = Pdb()
|
|
|
|
debugger.run('execfile("%s")' % sys.argv[0], scope)
|
|
|
|
else:
|
|
|
|
execfile(sys.argv[0], scope)
|
2006-07-11 05:00:13 +02:00
|
|
|
|
|
|
|
# once the script is done
|
|
|
|
if options.interactive:
|
|
|
|
interact = code.InteractiveConsole(scope)
|
|
|
|
interact.interact("M5 Interactive Console")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
parse_args()
|
|
|
|
|
|
|
|
print 'opts:'
|
|
|
|
pprint(options, indent=4)
|
|
|
|
print
|
|
|
|
|
|
|
|
print 'args:'
|
|
|
|
pprint(arguments, indent=4)
|