python: Update use of exec to work with Python 3
Python 3 uses 'exec(code, globals)' instead of 'exec code in globals'. Switch to the newer syntax since it is supported by Python 2.7. Also, move check_tracing out of main to work around a bug in Python 2.7. Change-Id: I6d390160f58783e1b038a572b64cdf3ff09535fa Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/15986 Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
@@ -77,7 +77,7 @@ class CodeImporter(object):
|
||||
mod.__package__ = fullname.rpartition('.')[0]
|
||||
mod.__file__ = srcfile
|
||||
|
||||
exec code in mod.__dict__
|
||||
exec(code, mod.__dict__)
|
||||
except Exception:
|
||||
del sys.modules[fullname]
|
||||
raise
|
||||
|
||||
@@ -43,4 +43,4 @@ import _m5
|
||||
|
||||
for name, module in inspect.getmembers(_m5):
|
||||
if name.startswith('param_') or name.startswith('enum_'):
|
||||
exec "from _m5.%s import *" % name
|
||||
exec("from _m5.%s import *" % name)
|
||||
|
||||
@@ -148,7 +148,7 @@ def parse_options():
|
||||
options_file = config.get('options.py')
|
||||
if options_file:
|
||||
scope = { 'options' : options }
|
||||
execfile(options_file, scope)
|
||||
exec(compile(open(options_file).read(), options_file, 'exec'), scope)
|
||||
|
||||
arguments = options.parse_args()
|
||||
return options,arguments
|
||||
@@ -191,6 +191,13 @@ def interact(scope):
|
||||
# isn't available.
|
||||
code.InteractiveConsole(scope).interact(banner)
|
||||
|
||||
|
||||
def _check_tracing():
|
||||
if defines.TRACING_ON:
|
||||
return
|
||||
|
||||
fatal("Tracing is not enabled. Compile with TRACING_ON")
|
||||
|
||||
def main(*args):
|
||||
import m5
|
||||
|
||||
@@ -213,12 +220,6 @@ def main(*args):
|
||||
|
||||
m5.options = options
|
||||
|
||||
def check_tracing():
|
||||
if defines.TRACING_ON:
|
||||
return
|
||||
|
||||
fatal("Tracing is not enabled. Compile with TRACING_ON")
|
||||
|
||||
# Set the main event queue for the main thread.
|
||||
event.mainq = event.getEventQueue(0)
|
||||
event.setEventQueue(event.mainq)
|
||||
@@ -279,7 +280,7 @@ def main(*args):
|
||||
|
||||
if options.debug_help:
|
||||
done = True
|
||||
check_tracing()
|
||||
_check_tracing()
|
||||
debug.help()
|
||||
|
||||
if options.list_sim_objects:
|
||||
@@ -366,7 +367,7 @@ def main(*args):
|
||||
debug.schedBreak(int(when))
|
||||
|
||||
if options.debug_flags:
|
||||
check_tracing()
|
||||
_check_tracing()
|
||||
|
||||
on_flags = []
|
||||
off_flags = []
|
||||
@@ -386,21 +387,21 @@ def main(*args):
|
||||
debug.flags[flag].enable()
|
||||
|
||||
if options.debug_start:
|
||||
check_tracing()
|
||||
_check_tracing()
|
||||
e = event.create(trace.enable, event.Event.Debug_Enable_Pri)
|
||||
event.mainq.schedule(e, options.debug_start)
|
||||
else:
|
||||
trace.enable()
|
||||
|
||||
if options.debug_end:
|
||||
check_tracing()
|
||||
_check_tracing()
|
||||
e = event.create(trace.disable, event.Event.Debug_Enable_Pri)
|
||||
event.mainq.schedule(e, options.debug_end)
|
||||
|
||||
trace.output(options.debug_file)
|
||||
|
||||
for ignore in options.debug_ignore:
|
||||
check_tracing()
|
||||
_check_tracing()
|
||||
trace.ignore(ignore)
|
||||
|
||||
sys.argv = arguments
|
||||
@@ -432,7 +433,7 @@ def main(*args):
|
||||
t = t.tb_next
|
||||
pdb.interaction(t.tb_frame,t)
|
||||
else:
|
||||
exec filecode in scope
|
||||
exec(filecode, scope)
|
||||
|
||||
# once the script is done
|
||||
if options.interactive:
|
||||
|
||||
@@ -36,4 +36,4 @@ except NameError:
|
||||
|
||||
for module in modules.iterkeys():
|
||||
if module.startswith('m5.objects.'):
|
||||
exec "from %s import *" % module
|
||||
exec("from %s import *" % module)
|
||||
|
||||
@@ -417,7 +417,7 @@ def JobFile(jobfile):
|
||||
raise AttributeError("Could not find file '%s'" % jobfile)
|
||||
|
||||
data = {}
|
||||
execfile(filename, data)
|
||||
exec(compile(open(filename).read(), filename, 'exec'), data)
|
||||
if 'conf' not in data:
|
||||
raise ImportError('cannot import name conf from %s' % jobfile)
|
||||
return data['conf']
|
||||
|
||||
Reference in New Issue
Block a user