arch: Bring closure out of p_global_let
authorGiacomo Travaglini <giacomo.travaglini@arm.com>
Thu, 5 Mar 2020 15:34:34 +0000 (15:34 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Fri, 13 Mar 2020 14:24:07 +0000 (14:24 +0000)
The python interpreter might complain when exec() (the function, not the
python2 keyword) is used in a function and the function contains a nested
block.

See: https://www.python.org/dev/peps/pep-0227/

The patch is moving the nested function out of p_global_let.

Change-Id: Idb3a08a8cd42455af1e5ec2c3ec8f8a1438047d3
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26303
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>

src/arch/isa_parser.py

index b33517485430d10942e165df1984a22fc046fce1..f35083f7194e4e899808d6f40ebd88d0b535678f 100755 (executable)
@@ -2006,20 +2006,23 @@ class ISAParser(Grammar):
         kwargs = { t[2]+'_output' : self.process_output(t[3]) }
         GenCode(self, **kwargs).emit()
 
+    def make_split(self):
+        def _split(sec):
+            return self.split(sec)
+        return _split
+
     # global let blocks 'let {{...}}' (Python code blocks) are
     # executed directly when seen.  Note that these execute in a
     # special variable context 'exportContext' to prevent the code
     # from polluting this script's namespace.
     def p_global_let(self, t):
         'global_let : LET CODELIT SEMI'
-        def _split(sec):
-            return self.split(sec)
         self.updateExportContext()
         self.exportContext["header_output"] = ''
         self.exportContext["decoder_output"] = ''
         self.exportContext["exec_output"] = ''
         self.exportContext["decode_block"] = ''
-        self.exportContext["split"] = _split
+        self.exportContext["split"] = self.make_split()
         split_setup = '''
 def wrap(func):
     def split(sec):