1 # Copyright (c) 2005 The Regents of The University of Michigan
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Authors: Nathan Binkert
35 from util
import attrdict
38 from options
import OptionParser
41 __all__
= [ 'options', 'arguments', 'main' ]
43 def print_list(items
, indent
=4):
45 for i
,item
in enumerate(items
):
46 if len(line
) + len(item
) > 76:
50 if i
< len(items
) - 1:
56 usage
="%prog [m5 options] script.py [script options]"
59 Copyright (c) 2001-2008
60 The Regents of The University of Michigan
64 options
= OptionParser(usage
=usage
, version
=version
,
65 description
=brief_copyright
)
66 add_option
= options
.add_option
67 set_group
= options
.set_group
71 add_option('-A', "--authors", action
="store_true", default
=False,
72 help="Show author information")
73 add_option('-B', "--build-info", action
="store_true", default
=False,
74 help="Show build information")
75 add_option('-C', "--copyright", action
="store_true", default
=False,
76 help="Show full copyright information")
77 add_option('-R', "--readme", action
="store_true", default
=False,
78 help="Show the readme")
79 add_option('-N', "--release-notes", action
="store_true", default
=False,
80 help="Show the release notes")
82 # Options for configuring the base simulator
83 add_option('-d', "--outdir", metavar
="DIR", default
=".",
84 help="Set the output directory to DIR [Default: %default]")
85 add_option('-i', "--interactive", action
="store_true", default
=False,
86 help="Invoke the interactive interpreter after running the script")
87 add_option("--pdb", action
="store_true", default
=False,
88 help="Invoke the python debugger before running the script")
89 add_option('-p', "--path", metavar
="PATH[:PATH]", action
='append', split
=':',
90 help="Prepend PATH to the system path when invoking the script")
91 add_option('-q', "--quiet", action
="count", default
=0,
92 help="Reduce verbosity")
93 add_option('-v', "--verbose", action
="count", default
=0,
94 help="Increase verbosity")
97 set_group("Statistics Options")
98 add_option("--stats-file", metavar
="FILE", default
="m5stats.txt",
99 help="Sets the output file for statistics [Default: %default]")
102 set_group("Debugging Options")
103 add_option("--debug-break", metavar
="TIME[,TIME]", action
='append', split
=',',
104 help="Cycle to create a breakpoint")
107 set_group("Trace Options")
108 add_option("--trace-help", action
='store_true',
109 help="Print help on trace flags")
110 add_option("--trace-flags", metavar
="FLAG[,FLAG]", action
='append', split
=',',
111 help="Sets the flags for tracing (-FLAG disables a flag)")
112 add_option("--trace-start", metavar
="TIME", type='int',
113 help="Start tracing at TIME (must be in ticks)")
114 add_option("--trace-file", metavar
="FILE", default
="cout",
115 help="Sets the output file for tracing [Default: %default]")
116 add_option("--trace-ignore", metavar
="EXPR", action
='append', split
=':',
117 help="Ignore EXPR sim objects")
125 arguments
= options
.parse_args()
129 if options
.build_info
:
131 print 'Build information:'
133 print 'compiled %s' % internal
.core
.cvar
.compileDate
;
134 print 'started %s' % datetime
.datetime
.now().ctime()
135 print 'executing on %s' % socket
.gethostname()
136 print 'build options:'
137 keys
= defines
.m5_build_env
.keys()
140 val
= defines
.m5_build_env
[key
]
141 print ' %s = %s' % (key
, val
)
144 if options
.copyright
:
151 print 'Author information:'
163 if options
.release_notes
:
165 print 'Release Notes:'
167 print info
.RELEASE_NOTES
170 if options
.trace_help
:
173 print_list(traceflags
.baseFlags
, indent
=4)
175 print "Compound Flags:"
176 for flag
in traceflags
.compoundFlags
:
180 print_list(traceflags
.compoundFlagMap
[flag
], indent
=8)
186 # setting verbose and quiet at the same time doesn't make sense
187 if options
.verbose
> 0 and options
.quiet
> 0:
190 verbose
= options
.verbose
- options
.quiet
191 if options
.verbose
>= 0:
192 print "M5 Simulator System"
193 print brief_copyright
195 print "M5 compiled %s" % internal
.core
.cvar
.compileDate
;
196 print "M5 started %s" % datetime
.datetime
.now().ctime()
197 print "M5 executing on %s" % socket
.gethostname()
199 print "M5 revision %s" % internal
.core
.cvar
.hgRev
200 print "M5 commit date %s" % internal
.core
.cvar
.hgDate
202 print "command line:",
203 for argv
in sys
.argv
:
207 # check to make sure we can find the listed script
208 if not arguments
or not os
.path
.isfile(arguments
[0]):
209 if arguments
and not os
.path
.isfile(arguments
[0]):
210 print "Script %s not found" % arguments
[0]
214 # tell C++ about output directory
215 internal
.core
.setOutputDir(options
.outdir
)
217 # update the system path with elements from the -p option
218 sys
.path
[0:0] = options
.path
223 internal
.stats
.initText(options
.stats_file
)
225 # set debugging options
226 for when
in options
.debug_break
:
227 internal
.debug
.schedBreakCycle(int(when
))
231 for flag
in options
.trace_flags
:
233 if flag
.startswith('-'):
236 if flag
not in traceflags
.allFlags
:
237 print >>sys
.stderr
, "invalid trace flag '%s'" % flag
241 off_flags
.append(flag
)
243 on_flags
.append(flag
)
245 for flag
in on_flags
:
246 internal
.trace
.set(flag
)
248 for flag
in off_flags
:
249 internal
.trace
.clear(flag
)
251 if options
.trace_start
:
253 internal
.trace
.cvar
.enabled
= True
254 event
.create(enable_trace
, int(options
.trace_start
))
256 internal
.trace
.cvar
.enabled
= True
258 internal
.trace
.output(options
.trace_file
)
260 for ignore
in options
.trace_ignore
:
261 internal
.trace
.ignore(ignore
)
264 sys
.path
= [ os
.path
.dirname(sys
.argv
[0]) ] + sys
.path
266 scope
= { '__file__' : sys
.argv
[0],
267 '__name__' : '__m5_main__' }
269 # we want readline if we're doing anything interactive
270 if options
.interactive
or options
.pdb
:
271 exec "import readline" in scope
273 # if pdb was requested, execfile the thing under pdb, otherwise,
274 # just do the execfile normally
278 debugger
.run('execfile("%s")' % sys
.argv
[0], scope
)
280 execfile(sys
.argv
[0], scope
)
282 # once the script is done
283 if options
.interactive
:
284 interact
= code
.InteractiveConsole(scope
)
285 interact
.interact("M5 Interactive Console")
287 if __name__
== '__main__':
288 from pprint
import pprint
293 pprint(options
, indent
=4)
297 pprint(arguments
, indent
=4)