main.py (5767:8e87c0aa1f0b) main.py (5773:7434b2271b0c)
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
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.
14#
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.
26#
27# Authors: Nathan Binkert
28
29import code
30import datetime
31import os
32import socket
33import sys
34
35from util import attrdict
36import config
37from options import OptionParser
38
39__all__ = [ 'options', 'arguments', 'main' ]
40
41def print_list(items, indent=4):
42 line = ' ' * indent
43 for i,item in enumerate(items):
44 if len(line) + len(item) > 76:
45 print line
46 line = ' ' * indent
47
48 if i < len(items) - 1:
49 line += '%s, ' % item
50 else:
51 line += item
52 print line
53
54usage="%prog [m5 options] script.py [script options]"
55version="%prog 2.0"
56brief_copyright='''
57Copyright (c) 2001-2008
58The Regents of The University of Michigan
59All Rights Reserved
60'''
61
62options = OptionParser(usage=usage, version=version,
63 description=brief_copyright)
64add_option = options.add_option
65set_group = options.set_group
66usage = options.usage
67
68# Help options
69add_option('-A', "--authors", action="store_true", default=False,
70 help="Show author information")
71add_option('-B', "--build-info", action="store_true", default=False,
72 help="Show build information")
73add_option('-C', "--copyright", action="store_true", default=False,
74 help="Show full copyright information")
75add_option('-R', "--readme", action="store_true", default=False,
76 help="Show the readme")
77add_option('-N', "--release-notes", action="store_true", default=False,
78 help="Show the release notes")
79
80# Options for configuring the base simulator
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
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.
14#
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.
26#
27# Authors: Nathan Binkert
28
29import code
30import datetime
31import os
32import socket
33import sys
34
35from util import attrdict
36import config
37from options import OptionParser
38
39__all__ = [ 'options', 'arguments', 'main' ]
40
41def print_list(items, indent=4):
42 line = ' ' * indent
43 for i,item in enumerate(items):
44 if len(line) + len(item) > 76:
45 print line
46 line = ' ' * indent
47
48 if i < len(items) - 1:
49 line += '%s, ' % item
50 else:
51 line += item
52 print line
53
54usage="%prog [m5 options] script.py [script options]"
55version="%prog 2.0"
56brief_copyright='''
57Copyright (c) 2001-2008
58The Regents of The University of Michigan
59All Rights Reserved
60'''
61
62options = OptionParser(usage=usage, version=version,
63 description=brief_copyright)
64add_option = options.add_option
65set_group = options.set_group
66usage = options.usage
67
68# Help options
69add_option('-A', "--authors", action="store_true", default=False,
70 help="Show author information")
71add_option('-B', "--build-info", action="store_true", default=False,
72 help="Show build information")
73add_option('-C', "--copyright", action="store_true", default=False,
74 help="Show full copyright information")
75add_option('-R', "--readme", action="store_true", default=False,
76 help="Show the readme")
77add_option('-N', "--release-notes", action="store_true", default=False,
78 help="Show the release notes")
79
80# Options for configuring the base simulator
81add_option('-d', "--outdir", metavar="DIR", default=".",
81add_option('-d', "--outdir", metavar="DIR", default="m5out",
82 help="Set the output directory to DIR [Default: %default]")
83add_option('-r', "--redirect-stdout", action="store_true", default=False,
84 help="Redirect stdout (& stderr, without -e) to file")
85add_option('-e', "--redirect-stderr", action="store_true", default=False,
86 help="Redirect stderr to file")
87add_option("--stdout-file", metavar="FILE", default="simout",
88 help="Filename for -r redirection [Default: %default]")
89add_option("--stderr-file", metavar="FILE", default="simerr",
90 help="Filename for -e redirection [Default: %default]")
91add_option('-i', "--interactive", action="store_true", default=False,
92 help="Invoke the interactive interpreter after running the script")
93add_option("--pdb", action="store_true", default=False,
94 help="Invoke the python debugger before running the script")
95add_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
96 help="Prepend PATH to the system path when invoking the script")
97add_option('-q', "--quiet", action="count", default=0,
98 help="Reduce verbosity")
99add_option('-v', "--verbose", action="count", default=0,
100 help="Increase verbosity")
101
102# Statistics options
103set_group("Statistics Options")
82 help="Set the output directory to DIR [Default: %default]")
83add_option('-r', "--redirect-stdout", action="store_true", default=False,
84 help="Redirect stdout (& stderr, without -e) to file")
85add_option('-e', "--redirect-stderr", action="store_true", default=False,
86 help="Redirect stderr to file")
87add_option("--stdout-file", metavar="FILE", default="simout",
88 help="Filename for -r redirection [Default: %default]")
89add_option("--stderr-file", metavar="FILE", default="simerr",
90 help="Filename for -e redirection [Default: %default]")
91add_option('-i', "--interactive", action="store_true", default=False,
92 help="Invoke the interactive interpreter after running the script")
93add_option("--pdb", action="store_true", default=False,
94 help="Invoke the python debugger before running the script")
95add_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
96 help="Prepend PATH to the system path when invoking the script")
97add_option('-q', "--quiet", action="count", default=0,
98 help="Reduce verbosity")
99add_option('-v', "--verbose", action="count", default=0,
100 help="Increase verbosity")
101
102# Statistics options
103set_group("Statistics Options")
104add_option("--stats-file", metavar="FILE", default="m5stats.txt",
104add_option("--stats-file", metavar="FILE", default="stats.txt",
105 help="Sets the output file for statistics [Default: %default]")
106
105 help="Sets the output file for statistics [Default: %default]")
106
107# Configuration Options
108set_group("Configuration Options")
109add_option("--dump-config", metavar="FILE", default="config.ini",
110 help="Dump configuration output file [Default: %default]")
111
107# Debugging options
108set_group("Debugging Options")
109add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
110 help="Cycle to create a breakpoint")
111add_option("--remote-gdb-port", type='int', default=7000,
112 help="Remote gdb base port")
113
114# Tracing options
115set_group("Trace Options")
116add_option("--trace-help", action='store_true',
117 help="Print help on trace flags")
118add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
119 help="Sets the flags for tracing (-FLAG disables a flag)")
120add_option("--trace-start", metavar="TIME", type='int',
121 help="Start tracing at TIME (must be in ticks)")
122add_option("--trace-file", metavar="FILE", default="cout",
123 help="Sets the output file for tracing [Default: %default]")
124add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
125 help="Ignore EXPR sim objects")
126
127# Help options
128set_group("Help Options")
129add_option("--list-sim-objects", action='store_true', default=False,
130 help="List all built-in SimObjects, their parameters and default values")
131
132def main():
133 import event
134 import info
135 import internal
136
137 # load the options.py config file to allow people to set their own
138 # default options
139 options_file = config.get('options.py')
140 if options_file:
141 scope = { 'options' : options }
142 execfile(options_file, scope)
143
144 arguments = options.parse_args()
145
146 if not os.path.isdir(options.outdir):
147 os.makedirs(options.outdir)
148
149 # These filenames are used only if the redirect_std* options are set
150 stdout_file = os.path.join(options.outdir, options.stdout_file)
151 stderr_file = os.path.join(options.outdir, options.stderr_file)
152
153 # Print redirection notices here before doing any redirection
154 if options.redirect_stdout and not options.redirect_stderr:
155 print "Redirecting stdout and stderr to", stdout_file
156 else:
157 if options.redirect_stdout:
158 print "Redirecting stdout to", stdout_file
159 if options.redirect_stderr:
160 print "Redirecting stderr to", stderr_file
161
162 # Now redirect stdout/stderr as desired
163 if options.redirect_stdout:
164 redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
165 os.dup2(redir_fd, sys.stdout.fileno())
166 if not options.redirect_stderr:
167 os.dup2(redir_fd, sys.stderr.fileno())
168
169 if options.redirect_stderr:
170 redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
171 os.dup2(redir_fd, sys.stderr.fileno())
172
173 done = False
174
175 if options.build_info:
176 import defines
177
178 done = True
179 print 'Build information:'
180 print
181 print 'compiled %s' % internal.core.cvar.compileDate;
182 print "revision %s" % internal.core.cvar.hgRev
183 print "commit date %s" % internal.core.cvar.hgDate
184 print 'build options:'
185 keys = defines.m5_build_env.keys()
186 keys.sort()
187 for key in keys:
188 val = defines.m5_build_env[key]
189 print ' %s = %s' % (key, val)
190 print
191
192 if options.copyright:
193 done = True
194 print info.LICENSE
195 print
196
197 if options.authors:
198 done = True
199 print 'Author information:'
200 print
201 print info.AUTHORS
202 print
203
204 if options.readme:
205 done = True
206 print 'Readme:'
207 print
208 print info.README
209 print
210
211 if options.release_notes:
212 done = True
213 print 'Release Notes:'
214 print
215 print info.RELEASE_NOTES
216 print
217
218 if options.trace_help:
219 import traceflags
220
221 done = True
222 print "Base Flags:"
223 traceflags.baseFlags.sort()
224 print_list(traceflags.baseFlags, indent=4)
225 print
226 print "Compound Flags:"
227 traceflags.compoundFlags.sort()
228 for flag in traceflags.compoundFlags:
229 if flag == 'All':
230 continue
231 print " %s:" % flag
232 print_list(traceflags.compoundFlagMap[flag], indent=8)
233 print
234
235 if options.list_sim_objects:
236 import SimObject
237 done = True
238 print "SimObjects:"
239 objects = SimObject.allClasses.keys()
240 objects.sort()
241 for name in objects:
242 obj = SimObject.allClasses[name]
243 print " %s" % obj
244 params = obj._params.keys()
245 params.sort()
246 for pname in params:
247 param = obj._params[pname]
248 default = getattr(param, 'default', '')
249 print " %s" % pname
250 if default:
251 print " default: %s" % default
252 print " desc: %s" % param.desc
253 print
254 print
255
256 if done:
257 sys.exit(0)
258
259 # setting verbose and quiet at the same time doesn't make sense
260 if options.verbose > 0 and options.quiet > 0:
261 options.usage(2)
262
263 verbose = options.verbose - options.quiet
264 if options.verbose >= 0:
265 print "M5 Simulator System"
266 print brief_copyright
267 print
268 print "M5 compiled %s" % internal.core.cvar.compileDate;
269 print "M5 revision %s" % internal.core.cvar.hgRev
270 print "M5 commit date %s" % internal.core.cvar.hgDate
271
272 print "M5 started %s" % datetime.datetime.now().strftime("%b %e %Y %X")
273 print "M5 executing on %s" % socket.gethostname()
274
275 print "command line:",
276 for argv in sys.argv:
277 print argv,
278 print
279
280 # check to make sure we can find the listed script
281 if not arguments or not os.path.isfile(arguments[0]):
282 if arguments and not os.path.isfile(arguments[0]):
283 print "Script %s not found" % arguments[0]
284
285 options.usage(2)
286
287 # tell C++ about output directory
288 internal.core.setOutputDir(options.outdir)
289
290 # update the system path with elements from the -p option
291 sys.path[0:0] = options.path
292
293 import objects
294
295 # set stats options
296 internal.stats.initText(options.stats_file)
297
298 # set debugging options
299 internal.debug.setRemoteGDBPort(options.remote_gdb_port)
300 for when in options.debug_break:
301 internal.debug.schedBreakCycle(int(when))
302
303 if options.trace_flags:
304 import traceflags
305
306 on_flags = []
307 off_flags = []
308 for flag in options.trace_flags:
309 off = False
310 if flag.startswith('-'):
311 flag = flag[1:]
312 off = True
313 if flag not in traceflags.allFlags and flag != "All":
314 print >>sys.stderr, "invalid trace flag '%s'" % flag
315 sys.exit(1)
316
317 if off:
318 off_flags.append(flag)
319 else:
320 on_flags.append(flag)
321
322 for flag in on_flags:
323 internal.trace.set(flag)
324
325 for flag in off_flags:
326 internal.trace.clear(flag)
327
328 if options.trace_start:
329 def enable_trace():
330 internal.trace.cvar.enabled = True
331
332 e = event.create(enable_trace)
333 event.mainq.schedule(e, options.trace_start)
334 else:
335 internal.trace.cvar.enabled = True
336
337 internal.trace.output(options.trace_file)
338
339 for ignore in options.trace_ignore:
340 internal.trace.ignore(ignore)
341
342 sys.argv = arguments
343 sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
344
345 filename = sys.argv[0]
346 filedata = file(filename, 'r').read()
347 filecode = compile(filedata, filename, 'exec')
348 scope = { '__file__' : filename,
349 '__name__' : '__m5_main__' }
350
351 # we want readline if we're doing anything interactive
352 if options.interactive or options.pdb:
353 exec "import readline" in scope
354
355 # if pdb was requested, execfile the thing under pdb, otherwise,
356 # just do the execfile normally
357 if options.pdb:
358 import pdb
359 import traceback
360
361 pdb = pdb.Pdb()
362 try:
363 pdb.run(filecode, scope)
364 except SystemExit:
365 print "The program exited via sys.exit(). Exit status: ",
366 print sys.exc_info()[1]
367 except:
368 traceback.print_exc()
369 print "Uncaught exception. Entering post mortem debugging"
370 t = sys.exc_info()[2]
371 while t.tb_next is not None:
372 t = t.tb_next
373 pdb.interaction(t.tb_frame,t)
374 else:
375 exec filecode in scope
376
377 # once the script is done
378 if options.interactive:
379 interact = code.InteractiveConsole(scope)
380 interact.interact("M5 Interactive Console")
381
382if __name__ == '__main__':
383 from pprint import pprint
384
385 # load the options.py config file to allow people to set their own
386 # default options
387 options_file = config.get('options.py')
388 if options_file:
389 scope = { 'options' : options }
390 execfile(options_file, scope)
391
392 arguments = options.parse_args()
393
394 print 'opts:'
395 pprint(options, indent=4)
396 print
397
398 print 'args:'
399 pprint(arguments, indent=4)
112# Debugging options
113set_group("Debugging Options")
114add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
115 help="Cycle to create a breakpoint")
116add_option("--remote-gdb-port", type='int', default=7000,
117 help="Remote gdb base port")
118
119# Tracing options
120set_group("Trace Options")
121add_option("--trace-help", action='store_true',
122 help="Print help on trace flags")
123add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
124 help="Sets the flags for tracing (-FLAG disables a flag)")
125add_option("--trace-start", metavar="TIME", type='int',
126 help="Start tracing at TIME (must be in ticks)")
127add_option("--trace-file", metavar="FILE", default="cout",
128 help="Sets the output file for tracing [Default: %default]")
129add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
130 help="Ignore EXPR sim objects")
131
132# Help options
133set_group("Help Options")
134add_option("--list-sim-objects", action='store_true', default=False,
135 help="List all built-in SimObjects, their parameters and default values")
136
137def main():
138 import event
139 import info
140 import internal
141
142 # load the options.py config file to allow people to set their own
143 # default options
144 options_file = config.get('options.py')
145 if options_file:
146 scope = { 'options' : options }
147 execfile(options_file, scope)
148
149 arguments = options.parse_args()
150
151 if not os.path.isdir(options.outdir):
152 os.makedirs(options.outdir)
153
154 # These filenames are used only if the redirect_std* options are set
155 stdout_file = os.path.join(options.outdir, options.stdout_file)
156 stderr_file = os.path.join(options.outdir, options.stderr_file)
157
158 # Print redirection notices here before doing any redirection
159 if options.redirect_stdout and not options.redirect_stderr:
160 print "Redirecting stdout and stderr to", stdout_file
161 else:
162 if options.redirect_stdout:
163 print "Redirecting stdout to", stdout_file
164 if options.redirect_stderr:
165 print "Redirecting stderr to", stderr_file
166
167 # Now redirect stdout/stderr as desired
168 if options.redirect_stdout:
169 redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
170 os.dup2(redir_fd, sys.stdout.fileno())
171 if not options.redirect_stderr:
172 os.dup2(redir_fd, sys.stderr.fileno())
173
174 if options.redirect_stderr:
175 redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
176 os.dup2(redir_fd, sys.stderr.fileno())
177
178 done = False
179
180 if options.build_info:
181 import defines
182
183 done = True
184 print 'Build information:'
185 print
186 print 'compiled %s' % internal.core.cvar.compileDate;
187 print "revision %s" % internal.core.cvar.hgRev
188 print "commit date %s" % internal.core.cvar.hgDate
189 print 'build options:'
190 keys = defines.m5_build_env.keys()
191 keys.sort()
192 for key in keys:
193 val = defines.m5_build_env[key]
194 print ' %s = %s' % (key, val)
195 print
196
197 if options.copyright:
198 done = True
199 print info.LICENSE
200 print
201
202 if options.authors:
203 done = True
204 print 'Author information:'
205 print
206 print info.AUTHORS
207 print
208
209 if options.readme:
210 done = True
211 print 'Readme:'
212 print
213 print info.README
214 print
215
216 if options.release_notes:
217 done = True
218 print 'Release Notes:'
219 print
220 print info.RELEASE_NOTES
221 print
222
223 if options.trace_help:
224 import traceflags
225
226 done = True
227 print "Base Flags:"
228 traceflags.baseFlags.sort()
229 print_list(traceflags.baseFlags, indent=4)
230 print
231 print "Compound Flags:"
232 traceflags.compoundFlags.sort()
233 for flag in traceflags.compoundFlags:
234 if flag == 'All':
235 continue
236 print " %s:" % flag
237 print_list(traceflags.compoundFlagMap[flag], indent=8)
238 print
239
240 if options.list_sim_objects:
241 import SimObject
242 done = True
243 print "SimObjects:"
244 objects = SimObject.allClasses.keys()
245 objects.sort()
246 for name in objects:
247 obj = SimObject.allClasses[name]
248 print " %s" % obj
249 params = obj._params.keys()
250 params.sort()
251 for pname in params:
252 param = obj._params[pname]
253 default = getattr(param, 'default', '')
254 print " %s" % pname
255 if default:
256 print " default: %s" % default
257 print " desc: %s" % param.desc
258 print
259 print
260
261 if done:
262 sys.exit(0)
263
264 # setting verbose and quiet at the same time doesn't make sense
265 if options.verbose > 0 and options.quiet > 0:
266 options.usage(2)
267
268 verbose = options.verbose - options.quiet
269 if options.verbose >= 0:
270 print "M5 Simulator System"
271 print brief_copyright
272 print
273 print "M5 compiled %s" % internal.core.cvar.compileDate;
274 print "M5 revision %s" % internal.core.cvar.hgRev
275 print "M5 commit date %s" % internal.core.cvar.hgDate
276
277 print "M5 started %s" % datetime.datetime.now().strftime("%b %e %Y %X")
278 print "M5 executing on %s" % socket.gethostname()
279
280 print "command line:",
281 for argv in sys.argv:
282 print argv,
283 print
284
285 # check to make sure we can find the listed script
286 if not arguments or not os.path.isfile(arguments[0]):
287 if arguments and not os.path.isfile(arguments[0]):
288 print "Script %s not found" % arguments[0]
289
290 options.usage(2)
291
292 # tell C++ about output directory
293 internal.core.setOutputDir(options.outdir)
294
295 # update the system path with elements from the -p option
296 sys.path[0:0] = options.path
297
298 import objects
299
300 # set stats options
301 internal.stats.initText(options.stats_file)
302
303 # set debugging options
304 internal.debug.setRemoteGDBPort(options.remote_gdb_port)
305 for when in options.debug_break:
306 internal.debug.schedBreakCycle(int(when))
307
308 if options.trace_flags:
309 import traceflags
310
311 on_flags = []
312 off_flags = []
313 for flag in options.trace_flags:
314 off = False
315 if flag.startswith('-'):
316 flag = flag[1:]
317 off = True
318 if flag not in traceflags.allFlags and flag != "All":
319 print >>sys.stderr, "invalid trace flag '%s'" % flag
320 sys.exit(1)
321
322 if off:
323 off_flags.append(flag)
324 else:
325 on_flags.append(flag)
326
327 for flag in on_flags:
328 internal.trace.set(flag)
329
330 for flag in off_flags:
331 internal.trace.clear(flag)
332
333 if options.trace_start:
334 def enable_trace():
335 internal.trace.cvar.enabled = True
336
337 e = event.create(enable_trace)
338 event.mainq.schedule(e, options.trace_start)
339 else:
340 internal.trace.cvar.enabled = True
341
342 internal.trace.output(options.trace_file)
343
344 for ignore in options.trace_ignore:
345 internal.trace.ignore(ignore)
346
347 sys.argv = arguments
348 sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
349
350 filename = sys.argv[0]
351 filedata = file(filename, 'r').read()
352 filecode = compile(filedata, filename, 'exec')
353 scope = { '__file__' : filename,
354 '__name__' : '__m5_main__' }
355
356 # we want readline if we're doing anything interactive
357 if options.interactive or options.pdb:
358 exec "import readline" in scope
359
360 # if pdb was requested, execfile the thing under pdb, otherwise,
361 # just do the execfile normally
362 if options.pdb:
363 import pdb
364 import traceback
365
366 pdb = pdb.Pdb()
367 try:
368 pdb.run(filecode, scope)
369 except SystemExit:
370 print "The program exited via sys.exit(). Exit status: ",
371 print sys.exc_info()[1]
372 except:
373 traceback.print_exc()
374 print "Uncaught exception. Entering post mortem debugging"
375 t = sys.exc_info()[2]
376 while t.tb_next is not None:
377 t = t.tb_next
378 pdb.interaction(t.tb_frame,t)
379 else:
380 exec filecode in scope
381
382 # once the script is done
383 if options.interactive:
384 interact = code.InteractiveConsole(scope)
385 interact.interact("M5 Interactive Console")
386
387if __name__ == '__main__':
388 from pprint import pprint
389
390 # load the options.py config file to allow people to set their own
391 # default options
392 options_file = config.get('options.py')
393 if options_file:
394 scope = { 'options' : options }
395 execfile(options_file, scope)
396
397 arguments = options.parse_args()
398
399 print 'opts:'
400 pprint(options, indent=4)
401 print
402
403 print 'args:'
404 pprint(arguments, indent=4)