Add isLayoutIdentical

This commit is contained in:
Siu Kwan Lam 2013-04-01 11:24:19 -05:00
commit 0b1abe7b26
3 changed files with 18 additions and 0 deletions

View file

@ -895,6 +895,10 @@ class StructType(Type):
def is_opaque(self):
return self._ptr.isOpaque()
def is_layout_identical(self, other):
return self._ptr.isLayoutIdentical(other._ptr)
class ArrayType(Type):
"""Represents an array type."""
_type_ = api.llvm.ArrayType

View file

@ -1245,6 +1245,18 @@ class TestNamedMetaData(TestCase):
tests.append(TestNamedMetaData)
# ---------------------------------------------------------------------------
class TestStruct(TestCase):
def test_struct_identical(self):
m = Module.new('test_struct_identical')
ta = Type.struct([Type.int(32), Type.float()], name='ta')
tb = Type.struct([Type.int(32), Type.float()])
self.assertTrue(ta.is_layout_identical(tb))
tests.append(TestStruct)
# ---------------------------------------------------------------------------
def run(verbosity=1):

View file

@ -214,6 +214,8 @@ class StructType:
cast(bool, Bool), # is packed
).require_only(2)
isLayoutIdentical = Method(cast(Bool, bool), # identical?
ptr(StructType)) # other
isValidElementType = StaticMethod(cast(Bool, bool), ptr(Type))