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
29 import code
, optparse
, os
, socket
, sys
30 from datetime
import datetime
31 from attrdict
import attrdict
38 __all__
= [ 'options', 'arguments', 'main' ]
40 usage
="%prog [m5 options] script.py [script options]"
43 Copyright (c) 2001-2006
44 The Regents of The University of Michigan
48 # there's only one option parsing done, so make it global and add some
49 # helper functions to make it work well.
50 parser
= optparse
.OptionParser(usage
=usage
, version
=version
,
51 description
=brief_copyright
,
52 formatter
=optparse
.TitledHelpFormatter())
53 parser
.disable_interspersed_args()
55 # current option group
58 def set_group(*args
, **kwargs
):
59 '''set the current option group'''
61 if not args
and not kwargs
:
64 group
= parser
.add_option_group(*args
, **kwargs
)
66 class splitter(object):
67 def __init__(self
, split
):
69 def __call__(self
, option
, opt_str
, value
, parser
):
70 getattr(parser
.values
, option
.dest
).extend(value
.split(self
.split
))
72 def add_option(*args
, **kwargs
):
73 '''add an option to the current option group, or global none set'''
75 # if action=split, but allows the option arguments
76 # themselves to be lists separated by the split variable'''
78 if kwargs
.get('action', None) == 'append' and 'split' in kwargs
:
79 split
= kwargs
.pop('split')
80 kwargs
['default'] = []
81 kwargs
['type'] = 'string'
82 kwargs
['action'] = 'callback'
83 kwargs
['callback'] = splitter(split
)
86 return group
.add_option(*args
, **kwargs
)
88 return parser
.add_option(*args
, **kwargs
)
90 def bool_option(name
, default
, help):
91 '''add a boolean option called --name and --no-name.
92 Display help depending on which is the default'''
95 fname
= '--no-%s' % name
96 dest
= name
.replace('-', '_')
98 thelp
= optparse
.SUPPRESS_HELP
102 fhelp
= optparse
.SUPPRESS_HELP
104 add_option(tname
, action
="store_true", default
=default
, help=thelp
)
105 add_option(fname
, action
="store_false", dest
=dest
, help=fhelp
)
108 add_option('-A', "--authors", action
="store_true", default
=False,
109 help="Show author information")
110 add_option('-C', "--copyright", action
="store_true", default
=False,
111 help="Show full copyright information")
112 add_option('-R', "--readme", action
="store_true", default
=False,
113 help="Show the readme")
114 add_option('-N', "--release-notes", action
="store_true", default
=False,
115 help="Show the release notes")
117 # Options for configuring the base simulator
118 add_option('-d', "--outdir", metavar
="DIR", default
=".",
119 help="Set the output directory to DIR [Default: %default]")
120 add_option('-i', "--interactive", action
="store_true", default
=False,
121 help="Invoke the interactive interpreter after running the script")
122 add_option("--pdb", action
="store_true", default
=False,
123 help="Invoke the python debugger before running the script")
124 add_option('-p', "--path", metavar
="PATH[:PATH]", action
='append', split
=':',
125 help="Prepend PATH to the system path when invoking the script")
126 add_option('-q', "--quiet", action
="count", default
=0,
127 help="Reduce verbosity")
128 add_option('-v', "--verbose", action
="count", default
=0,
129 help="Increase verbosity")
132 set_group("Statistics Options")
133 add_option("--stats-file", metavar
="FILE", default
="m5stats.txt",
134 help="Sets the output file for statistics [Default: %default]")
137 set_group("Debugging Options")
138 add_option("--debug-break", metavar
="TIME[,TIME]", action
='append', split
=',',
139 help="Cycle to create a breakpoint")
142 set_group("Trace Options")
143 add_option("--trace-flags", metavar
="FLAG[,FLAG]", action
='append', split
=',',
144 help="Sets the flags for tracing")
145 add_option("--trace-start", metavar
="TIME", default
='0s',
146 help="Start tracing at TIME (must have units)")
147 add_option("--trace-cycle", metavar
="CYCLE", default
='0',
148 help="Start tracing at CYCLE")
149 add_option("--trace-file", metavar
="FILE", default
="cout",
150 help="Sets the output file for tracing [Default: %default]")
151 add_option("--trace-circlebuf", metavar
="SIZE", type="int", default
=0,
152 help="If SIZE is non-zero, turn on the circular buffer with SIZE lines")
153 add_option("--no-trace-circlebuf", action
="store_const", const
=0,
154 dest
='trace_circlebuf', help=optparse
.SUPPRESS_HELP
)
155 bool_option("trace-dumponexit", default
=False,
156 help="Dump trace buffer on exit")
157 add_option("--trace-ignore", metavar
="EXPR", action
='append', split
=':',
158 help="Ignore EXPR sim objects")
160 # Execution Trace options
161 set_group("Execution Trace Options")
162 bool_option("speculative", default
=True,
163 help="Don't capture speculative instructions")
164 bool_option("print-cycle", default
=True,
165 help="Don't print cycle numbers in trace output")
166 bool_option("print-symbol", default
=True,
167 help="Disable PC symbols in trace output")
168 bool_option("print-opclass", default
=True,
169 help="Don't print op class type in trace output")
170 bool_option("print-thread", default
=True,
171 help="Don't print thread number in trace output")
172 bool_option("print-effaddr", default
=True,
173 help="Don't print effective address in trace output")
174 bool_option("print-data", default
=True,
175 help="Don't print result data in trace output")
176 bool_option("print-iregs", default
=False,
177 help="Print fetch sequence numbers in trace output")
178 bool_option("print-fetch-seq", default
=False,
179 help="Print fetch sequence numbers in trace output")
180 bool_option("print-cpseq", default
=False,
181 help="Print correct path sequence numbers in trace output")
182 #bool_option("print-reg-delta", default=False,
183 # help="Print which registers changed to what in trace output")
188 def usage(exitcode
=None):
190 if exitcode
is not None:
194 _opts
,args
= parser
.parse_args()
195 opts
= attrdict(_opts
.__dict
__)
197 # setting verbose and quiet at the same time doesn't make sense
198 if opts
.verbose
> 0 and opts
.quiet
> 0:
201 # store the verbosity in a single variable. 0 is default,
202 # negative numbers represent quiet and positive values indicate verbose
203 opts
.verbose
-= opts
.quiet
208 arguments
.extend(args
)
217 if options
.copyright
:
224 print 'Author information:'
236 if options
.release_notes
:
238 print 'Release Notes:'
240 print info
.RELEASE_NOTES
246 if options
.verbose
>= 0:
247 print "M5 Simulator System"
248 print brief_copyright
250 print "M5 compiled %s" % cc_main
.cvar
.compileDate
;
251 print "M5 started %s" % datetime
.now().ctime()
252 print "M5 executing on %s" % socket
.gethostname()
253 print "command line:",
254 for argv
in sys
.argv
:
258 # check to make sure we can find the listed script
259 if not arguments
or not os
.path
.isfile(arguments
[0]):
260 if arguments
and not os
.path
.isfile(arguments
[0]):
261 print "Script %s not found" % arguments
[0]
264 # tell C++ about output directory
265 cc_main
.setOutputDir(options
.outdir
)
267 # update the system path with elements from the -p option
268 sys
.path
[0:0] = options
.path
273 objects
.Statistics
.text_file
= options
.stats_file
275 # set debugging options
276 objects
.Debug
.break_cycles
= options
.debug_break
278 # set tracing options
279 objects
.Trace
.flags
= options
.trace_flags
280 objects
.Trace
.start
= options
.trace_start
281 objects
.Trace
.cycle
= options
.trace_cycle
282 objects
.Trace
.file = options
.trace_file
283 objects
.Trace
.bufsize
= options
.trace_circlebuf
284 objects
.Trace
.dump_on_exit
= options
.trace_dumponexit
285 objects
.Trace
.ignore
= options
.trace_ignore
287 # set execution trace options
288 objects
.ExecutionTrace
.speculative
= options
.speculative
289 objects
.ExecutionTrace
.print_cycle
= options
.print_cycle
290 objects
.ExecutionTrace
.pc_symbol
= options
.print_symbol
291 objects
.ExecutionTrace
.print_opclass
= options
.print_opclass
292 objects
.ExecutionTrace
.print_thread
= options
.print_thread
293 objects
.ExecutionTrace
.print_effaddr
= options
.print_effaddr
294 objects
.ExecutionTrace
.print_data
= options
.print_data
295 objects
.ExecutionTrace
.print_iregs
= options
.print_iregs
296 objects
.ExecutionTrace
.print_fetchseq
= options
.print_fetch_seq
297 objects
.ExecutionTrace
.print_cpseq
= options
.print_cpseq
298 #objects.ExecutionTrace.print_reg_delta = options.print_reg_delta
301 sys
.path
= [ os
.path
.dirname(sys
.argv
[0]) ] + sys
.path
303 scope
= { '__file__' : sys
.argv
[0] }
305 # we want readline if we're doing anything interactive
306 if options
.interactive
or options
.pdb
:
307 exec("import readline", scope
)
309 # if pdb was requested, execfile the thing under pdb, otherwise,
310 # just do the execfile normally
314 debugger
.run('execfile("%s")' % sys
.argv
[0], scope
)
316 execfile(sys
.argv
[0], scope
)
318 # once the script is done
319 if options
.interactive
:
320 interact
= code
.InteractiveConsole(scope
)
321 interact
.interact("M5 Interactive Console")
323 if __name__
== '__main__':
324 from pprint
import pprint
329 pprint(options
, indent
=4)
333 pprint(arguments
, indent
=4)