summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorAndrew Wilkins <axwalk@gmail.com>2017-06-08 07:32:29 +0000
committerAndrew Wilkins <axwalk@gmail.com>2017-06-08 07:32:29 +0000
commit6a72c5752519c3fb9ab1ce7bfee526243a3580b1 (patch)
tree66c4e97a0e9688603b63ce55a8ee2c057f2d7747 /bindings
parent5db707b0ff5ce707a78082219658a999b6b6eaa3 (diff)
[Go] Subtypes function
This patch adds LLVMGetSubtypes to Go API (as Type.Subtypes), tests included. Patch by Ekaterina Vaartis! Differential Revision: https://reviews.llvm.org/D33901 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/go/llvm/ir.go6
-rw-r--r--bindings/go/llvm/ir_test.go26
2 files changed, 32 insertions, 0 deletions
diff --git a/bindings/go/llvm/ir.go b/bindings/go/llvm/ir.go
index fe191beb381..22209703430 100644
--- a/bindings/go/llvm/ir.go
+++ b/bindings/go/llvm/ir.go
@@ -611,6 +611,12 @@ func (t Type) StructElementTypes() []Type {
}
// Operations on array, pointer, and vector types (sequence types)
+func (t Type) Subtypes() (ret []Type) {
+ ret = make([]Type, C.LLVMGetNumContainedTypes(t.C))
+ C.LLVMGetSubtypes(t.C, llvmTypeRefPtr(&ret[0]))
+ return
+}
+
func ArrayType(elementType Type, elementCount int) (t Type) {
t.C = C.LLVMArrayType(elementType.C, C.unsigned(elementCount))
return
diff --git a/bindings/go/llvm/ir_test.go b/bindings/go/llvm/ir_test.go
index c823615a429..325ee4890f4 100644
--- a/bindings/go/llvm/ir_test.go
+++ b/bindings/go/llvm/ir_test.go
@@ -134,3 +134,29 @@ func TestDebugLoc(t *testing.T) {
t.Errorf("Got metadata %v as scope, though wanted %v", loc.Scope.C, scope.C)
}
}
+
+func TestSubtypes(t *testing.T) {
+ cont := NewContext()
+ defer cont.Dispose()
+
+ int_pointer := PointerType(cont.Int32Type(), 0)
+ int_inner := int_pointer.Subtypes()
+ if len(int_inner) != 1 {
+ t.Errorf("Got size %d, though wanted 1")
+ }
+ if int_inner[0] != cont.Int32Type() {
+ t.Errorf("Expected int32 type")
+ }
+
+ st_pointer := cont.StructType([]Type{cont.Int32Type(), cont.Int8Type()}, false)
+ st_inner := st_pointer.Subtypes()
+ if len(st_inner) != 2 {
+ t.Errorf("Got size %d, though wanted 2")
+ }
+ if st_inner[0] != cont.Int32Type() {
+ t.Errorf("Expected first struct field to be int32")
+ }
+ if st_inner[1] != cont.Int8Type() {
+ t.Errorf("Expected second struct field to be int8")
+ }
+}