Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/15986

Change subject: python: Update use of exec to work with Python 3
......................................................................

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 <[email protected]>
---
M src/python/importer.py
M src/python/m5/internal/params.py
M src/python/m5/main.py
M src/python/m5/objects/__init__.py
M src/python/m5/util/jobfile.py
5 files changed, 18 insertions(+), 17 deletions(-)



diff --git a/src/python/importer.py b/src/python/importer.py
index 33ec267..d7ccda4 100644
--- a/src/python/importer.py
+++ b/src/python/importer.py
@@ -80,7 +80,7 @@
                 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 bbf86ce..d06851a 100644
--- a/src/python/m5/internal/params.py
+++ b/src/python/m5/internal/params.py
@@ -46,4 +46,4 @@

 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 89a319b..0937823 100644
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -148,7 +148,7 @@
     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 @@
         # 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 @@

     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 @@

     if options.debug_help:
         done = True
-        check_tracing()
+        _check_tracing()
         debug.help()

     if options.list_sim_objects:
@@ -366,7 +367,7 @@
         debug.schedBreak(int(when))

     if options.debug_flags:
-        check_tracing()
+        _check_tracing()

         on_flags = []
         off_flags = []
@@ -386,21 +387,21 @@
                 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 @@
                 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 c1b9f1c..b106c6c 100644
--- a/src/python/m5/objects/__init__.py
+++ b/src/python/m5/objects/__init__.py
@@ -39,4 +39,4 @@

 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 492062c..22b7175 100644
--- a/src/python/m5/util/jobfile.py
+++ b/src/python/m5/util/jobfile.py
@@ -418,7 +418,7 @@
             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']

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15986
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I6d390160f58783e1b038a572b64cdf3ff09535fa
Gerrit-Change-Number: 15986
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to