decoder/parser: generate methods, not functions
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Mon, 27 Sep 2021 19:30:24 +0000 (19:30 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 28 Sep 2021 11:07:44 +0000 (12:07 +0100)
src/openpower/decoder/pseudo/parser.py

index cb22c6a98a5c36ed0a89d7410c8bb564f19f04f6..cc7f129221f386c33e278a1ed8085c66b5bd88ee 100644 (file)
@@ -378,10 +378,11 @@ class PowerParser:
     def p_parameters(self, p):
         """parameters : LPAR RPAR
                       | LPAR varargslist RPAR"""
-        if len(p) == 3:
-            args = []
-        else:
-            args = p[2]
+        args = []
+        if self.helper:
+            args.append("self")
+        if len(p) != 3:
+            args += p[2]
         p[0] = ast.arguments(args=args, vararg=None, kwarg=None, defaults=[])
         # during the time between parameters identified and suite is not
         # there is a window of opportunity to declare the function parameters
@@ -951,6 +952,8 @@ class GardenSnakeParser(PowerParser):
     def parse(self, code):
         # self.lexer.input(code)
         result = self.parser.parse(code, lexer=self.lexer, debug=self.debug)
+        if self.helper:
+            result = [ast.ClassDef("ISACallerFnHelper", [], [], result, decorator_list=[])]
         return ast.Module(result)