main.py revision 5470
12889Sbinkertn@umich.edu# Copyright (c) 2005 The Regents of The University of Michigan 22889Sbinkertn@umich.edu# All rights reserved. 32889Sbinkertn@umich.edu# 42889Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 52889Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 62889Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 72889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 82889Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 92889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 102889Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 112889Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 122889Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 132889Sbinkertn@umich.edu# this software without specific prior written permission. 142889Sbinkertn@umich.edu# 152889Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162889Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172889Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182889Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192889Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202889Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212889Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222889Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232889Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242889Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252889Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262889Sbinkertn@umich.edu# 272889Sbinkertn@umich.edu# Authors: Nathan Binkert 282889Sbinkertn@umich.edu 294850Snate@binkert.orgimport code 304850Snate@binkert.orgimport datetime 314850Snate@binkert.orgimport os 324850Snate@binkert.orgimport socket 334850Snate@binkert.orgimport sys 344850Snate@binkert.org 355467Snate@binkert.orgfrom util import attrdict 364850Snate@binkert.orgimport defines 375470Snate@binkert.orgfrom options import OptionParser 384053Sbinkertn@umich.eduimport traceflags 392889Sbinkertn@umich.edu 402889Sbinkertn@umich.edu__all__ = [ 'options', 'arguments', 'main' ] 412889Sbinkertn@umich.edu 424053Sbinkertn@umich.edudef print_list(items, indent=4): 434053Sbinkertn@umich.edu line = ' ' * indent 444053Sbinkertn@umich.edu for i,item in enumerate(items): 454053Sbinkertn@umich.edu if len(line) + len(item) > 76: 464053Sbinkertn@umich.edu print line 474053Sbinkertn@umich.edu line = ' ' * indent 484053Sbinkertn@umich.edu 494053Sbinkertn@umich.edu if i < len(items) - 1: 504053Sbinkertn@umich.edu line += '%s, ' % item 514053Sbinkertn@umich.edu else: 524053Sbinkertn@umich.edu line += item 534053Sbinkertn@umich.edu print line 544053Sbinkertn@umich.edu 555470Snate@binkert.orgusage="%prog [m5 options] script.py [script options]" 565470Snate@binkert.orgversion="%prog 2.0" 575470Snate@binkert.orgbrief_copyright=''' 585470Snate@binkert.orgCopyright (c) 2001-2008 595470Snate@binkert.orgThe Regents of The University of Michigan 605470Snate@binkert.orgAll Rights Reserved 615470Snate@binkert.org''' 622889Sbinkertn@umich.edu 635470Snate@binkert.orgoptions = OptionParser(usage=usage, version=version, 645470Snate@binkert.org description=brief_copyright) 655470Snate@binkert.orgadd_option = options.add_option 665470Snate@binkert.orgset_group = options.set_group 675470Snate@binkert.orgusage = options.usage 682889Sbinkertn@umich.edu 692889Sbinkertn@umich.edu# Help options 702889Sbinkertn@umich.eduadd_option('-A', "--authors", action="store_true", default=False, 712889Sbinkertn@umich.edu help="Show author information") 724850Snate@binkert.orgadd_option('-B', "--build-info", action="store_true", default=False, 734850Snate@binkert.org help="Show build information") 742889Sbinkertn@umich.eduadd_option('-C', "--copyright", action="store_true", default=False, 752889Sbinkertn@umich.edu help="Show full copyright information") 762889Sbinkertn@umich.eduadd_option('-R', "--readme", action="store_true", default=False, 772889Sbinkertn@umich.edu help="Show the readme") 782889Sbinkertn@umich.eduadd_option('-N', "--release-notes", action="store_true", default=False, 792889Sbinkertn@umich.edu help="Show the release notes") 802889Sbinkertn@umich.edu 812889Sbinkertn@umich.edu# Options for configuring the base simulator 822889Sbinkertn@umich.eduadd_option('-d', "--outdir", metavar="DIR", default=".", 832889Sbinkertn@umich.edu help="Set the output directory to DIR [Default: %default]") 842889Sbinkertn@umich.eduadd_option('-i', "--interactive", action="store_true", default=False, 852889Sbinkertn@umich.edu help="Invoke the interactive interpreter after running the script") 862899Sbinkertn@umich.eduadd_option("--pdb", action="store_true", default=False, 872899Sbinkertn@umich.edu help="Invoke the python debugger before running the script") 882889Sbinkertn@umich.eduadd_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 892889Sbinkertn@umich.edu help="Prepend PATH to the system path when invoking the script") 902889Sbinkertn@umich.eduadd_option('-q', "--quiet", action="count", default=0, 912889Sbinkertn@umich.edu help="Reduce verbosity") 922889Sbinkertn@umich.eduadd_option('-v', "--verbose", action="count", default=0, 932889Sbinkertn@umich.edu help="Increase verbosity") 942889Sbinkertn@umich.edu 952889Sbinkertn@umich.edu# Statistics options 962889Sbinkertn@umich.eduset_group("Statistics Options") 972889Sbinkertn@umich.eduadd_option("--stats-file", metavar="FILE", default="m5stats.txt", 982889Sbinkertn@umich.edu help="Sets the output file for statistics [Default: %default]") 992889Sbinkertn@umich.edu 1002889Sbinkertn@umich.edu# Debugging options 1012889Sbinkertn@umich.eduset_group("Debugging Options") 1022889Sbinkertn@umich.eduadd_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',', 1032889Sbinkertn@umich.edu help="Cycle to create a breakpoint") 1042889Sbinkertn@umich.edu 1052889Sbinkertn@umich.edu# Tracing options 1062889Sbinkertn@umich.eduset_group("Trace Options") 1074053Sbinkertn@umich.eduadd_option("--trace-help", action='store_true', 1084053Sbinkertn@umich.edu help="Print help on trace flags") 1092889Sbinkertn@umich.eduadd_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1104053Sbinkertn@umich.edu help="Sets the flags for tracing (-FLAG disables a flag)") 1114044Sbinkertn@umich.eduadd_option("--trace-start", metavar="TIME", type='int', 1124044Sbinkertn@umich.edu help="Start tracing at TIME (must be in ticks)") 1132889Sbinkertn@umich.eduadd_option("--trace-file", metavar="FILE", default="cout", 1142889Sbinkertn@umich.edu help="Sets the output file for tracing [Default: %default]") 1152889Sbinkertn@umich.eduadd_option("--trace-ignore", metavar="EXPR", action='append', split=':', 1162889Sbinkertn@umich.edu help="Ignore EXPR sim objects") 1172889Sbinkertn@umich.edu 1182889Sbinkertn@umich.edudef main(): 1194042Sbinkertn@umich.edu import defines 1204167Sbinkertn@umich.edu import event 1214042Sbinkertn@umich.edu import info 1223624Sbinkertn@umich.edu import internal 1232889Sbinkertn@umich.edu 1245470Snate@binkert.org arguments = options.parse_args() 1252889Sbinkertn@umich.edu 1262889Sbinkertn@umich.edu done = False 1274850Snate@binkert.org 1284850Snate@binkert.org if options.build_info: 1294850Snate@binkert.org done = True 1304850Snate@binkert.org print 'Build information:' 1314850Snate@binkert.org print 1324850Snate@binkert.org print 'compiled %s' % internal.core.cvar.compileDate; 1334850Snate@binkert.org print 'started %s' % datetime.datetime.now().ctime() 1344850Snate@binkert.org print 'executing on %s' % socket.gethostname() 1354850Snate@binkert.org print 'build options:' 1364850Snate@binkert.org keys = defines.m5_build_env.keys() 1374850Snate@binkert.org keys.sort() 1384850Snate@binkert.org for key in keys: 1394850Snate@binkert.org val = defines.m5_build_env[key] 1404850Snate@binkert.org print ' %s = %s' % (key, val) 1414850Snate@binkert.org print 1424850Snate@binkert.org 1432889Sbinkertn@umich.edu if options.copyright: 1442889Sbinkertn@umich.edu done = True 1452889Sbinkertn@umich.edu print info.LICENSE 1462889Sbinkertn@umich.edu print 1472889Sbinkertn@umich.edu 1482889Sbinkertn@umich.edu if options.authors: 1492889Sbinkertn@umich.edu done = True 1502889Sbinkertn@umich.edu print 'Author information:' 1512889Sbinkertn@umich.edu print 1522889Sbinkertn@umich.edu print info.AUTHORS 1532889Sbinkertn@umich.edu print 1542889Sbinkertn@umich.edu 1552889Sbinkertn@umich.edu if options.readme: 1562889Sbinkertn@umich.edu done = True 1572889Sbinkertn@umich.edu print 'Readme:' 1582889Sbinkertn@umich.edu print 1592889Sbinkertn@umich.edu print info.README 1602889Sbinkertn@umich.edu print 1612889Sbinkertn@umich.edu 1622889Sbinkertn@umich.edu if options.release_notes: 1632889Sbinkertn@umich.edu done = True 1642889Sbinkertn@umich.edu print 'Release Notes:' 1652889Sbinkertn@umich.edu print 1662889Sbinkertn@umich.edu print info.RELEASE_NOTES 1672889Sbinkertn@umich.edu print 1682889Sbinkertn@umich.edu 1694053Sbinkertn@umich.edu if options.trace_help: 1704053Sbinkertn@umich.edu done = True 1714053Sbinkertn@umich.edu print "Base Flags:" 1724053Sbinkertn@umich.edu print_list(traceflags.baseFlags, indent=4) 1734053Sbinkertn@umich.edu print 1744053Sbinkertn@umich.edu print "Compound Flags:" 1754053Sbinkertn@umich.edu for flag in traceflags.compoundFlags: 1764053Sbinkertn@umich.edu if flag == 'All': 1774053Sbinkertn@umich.edu continue 1784053Sbinkertn@umich.edu print " %s:" % flag 1794053Sbinkertn@umich.edu print_list(traceflags.compoundFlagMap[flag], indent=8) 1804053Sbinkertn@umich.edu print 1814053Sbinkertn@umich.edu 1822889Sbinkertn@umich.edu if done: 1832889Sbinkertn@umich.edu sys.exit(0) 1842889Sbinkertn@umich.edu 1855470Snate@binkert.org # setting verbose and quiet at the same time doesn't make sense 1865470Snate@binkert.org if options.verbose > 0 and options.quiet > 0: 1875470Snate@binkert.org options.usage(2) 1885470Snate@binkert.org 1895470Snate@binkert.org verbose = options.verbose - options.quiet 1902889Sbinkertn@umich.edu if options.verbose >= 0: 1912889Sbinkertn@umich.edu print "M5 Simulator System" 1922889Sbinkertn@umich.edu print brief_copyright 1932889Sbinkertn@umich.edu print 1944123Sbinkertn@umich.edu print "M5 compiled %s" % internal.core.cvar.compileDate; 1954850Snate@binkert.org print "M5 started %s" % datetime.datetime.now().ctime() 1962889Sbinkertn@umich.edu print "M5 executing on %s" % socket.gethostname() 1975456Ssaidi@eecs.umich.edu 1985456Ssaidi@eecs.umich.edu print "M5 revision %s" % internal.core.cvar.hgRev 1995456Ssaidi@eecs.umich.edu print "M5 commit date %s" % internal.core.cvar.hgDate 2005456Ssaidi@eecs.umich.edu 2012967Sktlim@umich.edu print "command line:", 2022967Sktlim@umich.edu for argv in sys.argv: 2032967Sktlim@umich.edu print argv, 2042967Sktlim@umich.edu print 2052889Sbinkertn@umich.edu 2062889Sbinkertn@umich.edu # check to make sure we can find the listed script 2072889Sbinkertn@umich.edu if not arguments or not os.path.isfile(arguments[0]): 2082922Sktlim@umich.edu if arguments and not os.path.isfile(arguments[0]): 2092922Sktlim@umich.edu print "Script %s not found" % arguments[0] 2104053Sbinkertn@umich.edu 2115470Snate@binkert.org options.usage(2) 2122889Sbinkertn@umich.edu 2132889Sbinkertn@umich.edu # tell C++ about output directory 2144123Sbinkertn@umich.edu internal.core.setOutputDir(options.outdir) 2152889Sbinkertn@umich.edu 2162889Sbinkertn@umich.edu # update the system path with elements from the -p option 2172889Sbinkertn@umich.edu sys.path[0:0] = options.path 2182889Sbinkertn@umich.edu 2192889Sbinkertn@umich.edu import objects 2202889Sbinkertn@umich.edu 2212889Sbinkertn@umich.edu # set stats options 2224078Sbinkertn@umich.edu internal.stats.initText(options.stats_file) 2232889Sbinkertn@umich.edu 2242889Sbinkertn@umich.edu # set debugging options 2253645Sbinkertn@umich.edu for when in options.debug_break: 2263645Sbinkertn@umich.edu internal.debug.schedBreakCycle(int(when)) 2272889Sbinkertn@umich.edu 2284053Sbinkertn@umich.edu on_flags = [] 2294053Sbinkertn@umich.edu off_flags = [] 2304042Sbinkertn@umich.edu for flag in options.trace_flags: 2314053Sbinkertn@umich.edu off = False 2324053Sbinkertn@umich.edu if flag.startswith('-'): 2334053Sbinkertn@umich.edu flag = flag[1:] 2344053Sbinkertn@umich.edu off = True 2354053Sbinkertn@umich.edu if flag not in traceflags.allFlags: 2364053Sbinkertn@umich.edu print >>sys.stderr, "invalid trace flag '%s'" % flag 2374053Sbinkertn@umich.edu sys.exit(1) 2384053Sbinkertn@umich.edu 2394053Sbinkertn@umich.edu if off: 2404053Sbinkertn@umich.edu off_flags.append(flag) 2414053Sbinkertn@umich.edu else: 2424053Sbinkertn@umich.edu on_flags.append(flag) 2434053Sbinkertn@umich.edu 2444053Sbinkertn@umich.edu for flag in on_flags: 2454046Sbinkertn@umich.edu internal.trace.set(flag) 2464042Sbinkertn@umich.edu 2474053Sbinkertn@umich.edu for flag in off_flags: 2484053Sbinkertn@umich.edu internal.trace.clear(flag) 2494053Sbinkertn@umich.edu 2504074Sbinkertn@umich.edu if options.trace_start: 2514042Sbinkertn@umich.edu def enable_trace(): 2524074Sbinkertn@umich.edu internal.trace.cvar.enabled = True 2534167Sbinkertn@umich.edu event.create(enable_trace, int(options.trace_start)) 2544074Sbinkertn@umich.edu else: 2554087Sbinkertn@umich.edu internal.trace.cvar.enabled = True 2564042Sbinkertn@umich.edu 2574046Sbinkertn@umich.edu internal.trace.output(options.trace_file) 2584042Sbinkertn@umich.edu 2594042Sbinkertn@umich.edu for ignore in options.trace_ignore: 2604042Sbinkertn@umich.edu internal.trace.ignore(ignore) 2612889Sbinkertn@umich.edu 2622889Sbinkertn@umich.edu sys.argv = arguments 2632889Sbinkertn@umich.edu sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 2642891Sbinkertn@umich.edu 2653887Sbinkertn@umich.edu scope = { '__file__' : sys.argv[0], 2663887Sbinkertn@umich.edu '__name__' : '__m5_main__' } 2672899Sbinkertn@umich.edu 2682899Sbinkertn@umich.edu # we want readline if we're doing anything interactive 2692899Sbinkertn@umich.edu if options.interactive or options.pdb: 2704042Sbinkertn@umich.edu exec "import readline" in scope 2712899Sbinkertn@umich.edu 2722899Sbinkertn@umich.edu # if pdb was requested, execfile the thing under pdb, otherwise, 2732899Sbinkertn@umich.edu # just do the execfile normally 2742899Sbinkertn@umich.edu if options.pdb: 2752899Sbinkertn@umich.edu from pdb import Pdb 2762899Sbinkertn@umich.edu debugger = Pdb() 2772899Sbinkertn@umich.edu debugger.run('execfile("%s")' % sys.argv[0], scope) 2782899Sbinkertn@umich.edu else: 2792899Sbinkertn@umich.edu execfile(sys.argv[0], scope) 2802889Sbinkertn@umich.edu 2812889Sbinkertn@umich.edu # once the script is done 2822889Sbinkertn@umich.edu if options.interactive: 2832889Sbinkertn@umich.edu interact = code.InteractiveConsole(scope) 2842889Sbinkertn@umich.edu interact.interact("M5 Interactive Console") 2852889Sbinkertn@umich.edu 2862889Sbinkertn@umich.eduif __name__ == '__main__': 2872889Sbinkertn@umich.edu from pprint import pprint 2882889Sbinkertn@umich.edu 2892889Sbinkertn@umich.edu parse_args() 2902889Sbinkertn@umich.edu 2912889Sbinkertn@umich.edu print 'opts:' 2922889Sbinkertn@umich.edu pprint(options, indent=4) 2932889Sbinkertn@umich.edu print 2942889Sbinkertn@umich.edu 2952889Sbinkertn@umich.edu print 'args:' 2962889Sbinkertn@umich.edu pprint(arguments, indent=4) 297