Generate an InstructionFormat enum.

This is a no-payload enum which will have the same variants as InstructionData.
This makes it possible to talk about the format of an instruction without
actually creating an InstructionData instance.
This commit is contained in:
Jakob Stoklund Olesen
2016-05-13 11:54:05 -07:00
parent 3909cdbc2d
commit e3927e205e
4 changed files with 57 additions and 7 deletions

View File

@@ -335,6 +335,9 @@ class InstructionFormat(object):
# Map (multiple_results, kind, kind, ...) -> InstructionFormat
_registry = dict()
# All existing formats.
all_formats = list()
def __init__(self, *kinds, **kwargs):
self.name = kwargs.get('name', None)
self.kinds = kinds
@@ -346,6 +349,7 @@ class InstructionFormat(object):
"Format '{}' has the same signature as existing format '{}'"
.format(self.name, InstructionFormat._registry[sig]))
InstructionFormat._registry[sig] = self
InstructionFormat.all_formats.append(self)
@staticmethod
def lookup(ins, outs):