arch: Add a mechanism to override methods of the Operand classes.
The classes defined by the ISA description are actually just descriptors which are used to make more specialized Operand classes, and then those classes are instantiated to represent actual operands in a given instruction. There they encode the actual index of the register, any extensions used, etc. To make defining operand types in the ISA more flexible and to take less explicit machinery, this change defines a mechanism to allow overriding individual methods of the operand class. This should for instance make the read_code and write_code members of those classes unnecessary. Change-Id: I1a1f787970ba56bd2884a80df4618a77eb454605 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49740 Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Gabe Black <gabe.black@gmail.com> Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
This commit is contained in:
@@ -518,6 +518,7 @@ class ISAParser(Grammar):
|
||||
symbols = ('makeList', 're')
|
||||
self.exportContext = dict([(s, eval(s)) for s in symbols])
|
||||
self.exportContext.update({
|
||||
'overrideInOperand': overrideInOperand,
|
||||
'IntRegOp': IntRegOperandDesc,
|
||||
'FloatRegOp': FloatRegOperandDesc,
|
||||
'CCRegOp': CCRegOperandDesc,
|
||||
|
||||
@@ -37,6 +37,12 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
def overrideInOperand(func):
|
||||
func.override_in_operand = True
|
||||
return func
|
||||
|
||||
overrideInOperand.overrides = dict()
|
||||
|
||||
class OperandDesc(object):
|
||||
def __init__(self, base_cls, dflt_ext, reg_spec, flags=None,
|
||||
sort_pri=None, read_code=None, write_code=None,
|
||||
@@ -76,6 +82,15 @@ class OperandDesc(object):
|
||||
assert(isinstance(elem_spec, dict))
|
||||
attrs['elems'] = elem_spec
|
||||
|
||||
for key in dir(self):
|
||||
val = getattr(self, key)
|
||||
# If this is a method, extract the function that implements it.
|
||||
if hasattr(val, '__func__'):
|
||||
val = val.__func__
|
||||
# If this should override something in the operand
|
||||
if getattr(val, 'override_in_operand', False):
|
||||
attrs[key] = val
|
||||
|
||||
attrs.update({
|
||||
'base_cls': base_cls,
|
||||
'dflt_ext': dflt_ext,
|
||||
|
||||
Reference in New Issue
Block a user