summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2019-01-25 12:04:31 +0000
committerAndreas Sandberg <andreas.sandberg@arm.com>2019-02-12 16:44:21 +0000
commit31dff7faa0a0be22e70376a49748cf4b8f1eb5f9 (patch)
treea3b3192f81e22fa6c7cd2b382bfbcd192cedc296
parentb3195c455bf5aed70d2543684f3c0bc7f36c8fcf (diff)
downloadgem5-31dff7faa0a0be22e70376a49748cf4b8f1eb5f9.tar.xz
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>
-rw-r--r--src/python/importer.py2
-rw-r--r--src/python/m5/internal/params.py2
-rw-r--r--src/python/m5/main.py27
-rw-r--r--src/python/m5/objects/__init__.py2
-rw-r--r--src/python/m5/util/jobfile.py2
5 files changed, 18 insertions, 17 deletions
diff --git a/src/python/importer.py b/src/python/importer.py
index c54fb4957..224ab3bd9 100644
--- a/src/python/importer.py
+++ b/src/python/importer.py
@@ -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
diff --git a/src/python/m5/internal/params.py b/src/python/m5/internal/params.py
index ef94ad447..400e78062 100644
--- a/src/python/m5/internal/params.py
+++ b/src/python/m5/internal/params.py
@@ -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)
diff --git a/src/python/m5/main.py b/src/python/m5/main.py
index e4619c09d..8a259f3d8 100644
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -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:
diff --git a/src/python/m5/objects/__init__.py b/src/python/m5/objects/__init__.py
index 29402c581..8186c5202 100644
--- a/src/python/m5/objects/__init__.py
+++ b/src/python/m5/objects/__init__.py
@@ -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)
diff --git a/src/python/m5/util/jobfile.py b/src/python/m5/util/jobfile.py
index ad5b5ff5c..613289a81 100644
--- a/src/python/m5/util/jobfile.py
+++ b/src/python/m5/util/jobfile.py
@@ -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']