[llvm] r304968 - [Go] Subtypes function

Andrew Wilkins via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 00:32:34 PDT 2017


Author: axw
Date: Thu Jun  8 02:32:29 2017
New Revision: 304968

URL: http://llvm.org/viewvc/llvm-project?rev=304968&view=rev
Log:
[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


Modified:
    llvm/trunk/bindings/go/llvm/ir.go
    llvm/trunk/bindings/go/llvm/ir_test.go

Modified: llvm/trunk/bindings/go/llvm/ir.go
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/go/llvm/ir.go?rev=304968&r1=304967&r2=304968&view=diff
==============================================================================
--- llvm/trunk/bindings/go/llvm/ir.go (original)
+++ llvm/trunk/bindings/go/llvm/ir.go Thu Jun  8 02:32:29 2017
@@ -611,6 +611,12 @@ func (t Type) StructElementTypes() []Typ
 }
 
 // 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

Modified: llvm/trunk/bindings/go/llvm/ir_test.go
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/go/llvm/ir_test.go?rev=304968&r1=304967&r2=304968&view=diff
==============================================================================
--- llvm/trunk/bindings/go/llvm/ir_test.go (original)
+++ llvm/trunk/bindings/go/llvm/ir_test.go Thu Jun  8 02:32:29 2017
@@ -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")
+	}
+}




More information about the llvm-commits mailing list