[PATCH] D33901: [Go] Subtypes function

Andrew Wilkins via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 00:33:06 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL304968: [Go] Subtypes function (authored by axw).

Changed prior to commit:
  https://reviews.llvm.org/D33901?vs=101716&id=101863#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33901

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


Index: llvm/trunk/bindings/go/llvm/ir.go
===================================================================
--- llvm/trunk/bindings/go/llvm/ir.go
+++ llvm/trunk/bindings/go/llvm/ir.go
@@ -611,6 +611,12 @@
 }
 
 // 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
Index: llvm/trunk/bindings/go/llvm/ir_test.go
===================================================================
--- llvm/trunk/bindings/go/llvm/ir_test.go
+++ llvm/trunk/bindings/go/llvm/ir_test.go
@@ -134,3 +134,29 @@
 		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")
+	}
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33901.101863.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170608/2bbf8d65/attachment.bin>


More information about the llvm-commits mailing list