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 <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-01-17 01:28:07 -08:00
parent c2a980a588
commit 544a172800

View File

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