From: Gabe Black Date: Sun, 17 Jan 2021 09:28:07 +0000 (-0800) Subject: arch: Wrap InstObjParams with a class and not a function. X-Git-Tag: develop-gem5-snapshot~281 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=544a172800e74b706d32024db83b535ef584daef;p=gem5.git arch: Wrap InstObjParams with a class and not a function. When parsing an ISA description, the InstObjParams class needs to have a reference to the current parser. It does that by exposing a wrapper to the description rather than the actual InstObjParams class. That wrapper injects an additional argument into the InstObjParams constructor. Originally, the wrapper which injectect the additional argument was a function which masqueraded as a class. That made it impossible to subclass InstObjParams. Instead, this change replaces that function wrapper with a class wrapper, and injects the extra argument in the __init__ method. This preserves the fact that the InstObjParams name refers to a class, and allows any sort of interaction that's normally allowed with a class like subclassing. Change-Id: I550ea2e60eadac3c7c0b9afa7d71f4607b49a5d2 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39275 Reviewed-by: Giacomo Travaglini Maintainer: Giacomo Travaglini Tested-by: kokoro --- diff --git a/src/arch/isa_parser/isa_parser.py b/src/arch/isa_parser/isa_parser.py index 9ca813e50..a0b9f7411 100755 --- a/src/arch/isa_parser/isa_parser.py +++ b/src/arch/isa_parser/isa_parser.py @@ -1436,11 +1436,12 @@ StaticInstPtr # END OF GRAMMAR RULES def updateExportContext(self): - - # create a continuation that allows us to grab the current parser - def wrapInstObjParams(*args): - return InstObjParams(self, *args) - self.exportContext['InstObjParams'] = wrapInstObjParams + # Create a wrapper class that allows us to grab the current parser. + class InstObjParamsWrapper(InstObjParams): + def __init__(iop, *args, **kwargs): + super(InstObjParamsWrapper, iop).__init__( + self, *args, **kwargs) + self.exportContext['InstObjParams'] = InstObjParamsWrapper self.exportContext.update(self.templateMap) def defFormat(self, id, params, code, lineno):