Capture the Rust type used to represent an operand kind.

The Rust type is usually the camel-cased name of the operand kind, but
there are variations, so allow an explicit rust_type='IntCC' when
defining operand kinds.
This commit is contained in:
Jakob Stoklund Olesen
2016-10-12 15:34:50 -07:00
parent b8a537bb13
commit f78baf9c0b
2 changed files with 14 additions and 9 deletions

View File

@@ -290,13 +290,13 @@ class OperandKind(object):
instruction. instruction.
""" """
def __init__(self, name, doc, default_member=None): def __init__(self, name, doc, default_member=None, rust_type=None):
self.name = name self.name = name
self.__doc__ = doc self.__doc__ = doc
self.default_member = default_member self.default_member = default_member
# The camel-cased name of an operand kind is also the Rust type used to # The camel-cased name of an operand kind is also the Rust type used to
# represent it. # represent it.
self.camel_name = camel_case(name) self.rust_type = rust_type or camel_case(name)
def __str__(self): def __str__(self):
return self.name return self.name
@@ -348,8 +348,9 @@ class ImmediateKind(OperandKind):
`InstructionData` data structure. `InstructionData` data structure.
""" """
def __init__(self, name, doc, default_member='imm'): def __init__(self, name, doc, default_member='imm', rust_type=None):
super(ImmediateKind, self).__init__(name, doc, default_member) super(ImmediateKind, self).__init__(
name, doc, default_member, rust_type)
def __repr__(self): def __repr__(self):
return 'ImmediateKind({})'.format(self.name) return 'ImmediateKind({})'.format(self.name)
@@ -362,8 +363,9 @@ class EntityRefKind(OperandKind):
The kind of an entity reference instruction operand. The kind of an entity reference instruction operand.
""" """
def __init__(self, name, doc, default_member=None): def __init__(self, name, doc, default_member=None, rust_type=None):
super(EntityRefKind, self).__init__(name, doc, default_member or name) super(EntityRefKind, self).__init__(
name, doc, default_member or name, rust_type)
def __repr__(self): def __repr__(self):
return 'EntityRefKind({})'.format(self.name) return 'EntityRefKind({})'.format(self.name)

View File

@@ -28,7 +28,10 @@ ieee32 = ImmediateKind('ieee32', 'A 32-bit immediate floating point number.')
ieee64 = ImmediateKind('ieee64', 'A 64-bit immediate floating point number.') ieee64 = ImmediateKind('ieee64', 'A 64-bit immediate floating point number.')
#: A large SIMD vector constant. #: A large SIMD vector constant.
immvector = ImmediateKind('immvector', 'An immediate SIMD vector.') immvector = ImmediateKind(
'immvector',
'An immediate SIMD vector.',
rust_type='ImmVector')
#: A condition code for comparing integer values. #: A condition code for comparing integer values.
#: #:
@@ -37,7 +40,7 @@ immvector = ImmediateKind('immvector', 'An immediate SIMD vector.')
intcc = ImmediateKind( intcc = ImmediateKind(
'intcc', 'intcc',
'An integer comparison condition code.', 'An integer comparison condition code.',
default_member='cond') default_member='cond', rust_type='IntCC')
#: A condition code for comparing floating point values. #: A condition code for comparing floating point values.
#: #:
@@ -46,4 +49,4 @@ intcc = ImmediateKind(
floatcc = ImmediateKind( floatcc = ImmediateKind(
'floatcc', 'floatcc',
'A floating point comparison condition code.', 'A floating point comparison condition code.',
default_member='cond') default_member='cond', rust_type='FloatCC')