[PATCH] D33901: Add GetSubtypes to Go
Ekaterina Vaartis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 10:02:01 PDT 2017
TyanNN created this revision.
This patch adds `LLVMGetSubtypes` to Go API (as `GetSubtypes`), tests included. Please commit this patch if/when everything's OK, as I do not have commit access
https://reviews.llvm.org/D33901
Files:
bindings/go/llvm/ir.go
bindings/go/llvm/ir_test.go
Index: bindings/go/llvm/ir_test.go
===================================================================
--- bindings/go/llvm/ir_test.go
+++ 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 := GetSubtypes(int_pointer);
+ 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 := GetSubtypes(st_pointer)
+ 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")
+ }
+}
Index: bindings/go/llvm/ir.go
===================================================================
--- bindings/go/llvm/ir.go
+++ bindings/go/llvm/ir.go
@@ -611,6 +611,12 @@
}
// Operations on array, pointer, and vector types (sequence types)
+func GetSubtypes(Tp Type) (ret []Type) {
+ ret = make([]Type, C.LLVMGetNumContainedTypes(Tp.C))
+ C.LLVMGetSubtypes(Tp.C, llvmTypeRefPtr(&ret[0]))
+ return
+}
+
func ArrayType(elementType Type, elementCount int) (t Type) {
t.C = C.LLVMArrayType(elementType.C, C.unsigned(elementCount))
return
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33901.101424.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170605/8684ef70/attachment.bin>
More information about the llvm-commits
mailing list