From 0b1abe7b26d35f11e826111c9fa026d087dd49d5 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Mon, 1 Apr 2013 11:24:19 -0500 Subject: [PATCH] Add isLayoutIdentical --- llvm/core.py | 4 ++++ llvm/test_llvmpy.py | 12 ++++++++++++ llvmpy/src/Type.py | 2 ++ 3 files changed, 18 insertions(+) diff --git a/llvm/core.py b/llvm/core.py index bbe5d01..719c8a4 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -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 diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 8df32b8..945ac41 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -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): diff --git a/llvmpy/src/Type.py b/llvmpy/src/Type.py index 874201e..afc148c 100644 --- a/llvmpy/src/Type.py +++ b/llvmpy/src/Type.py @@ -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))