[PATCH] D53883: [bindings/go] Add Go bindings to LLVMGetIndices
Ayke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 30 12:46:11 PDT 2018
aykevl created this revision.
aykevl added reviewers: whitequark, pcc.
Herald added a subscriber: llvm-commits.
This instruction is useful for inspecting generated IR. Unlike most other operations, indices cannot be inspected using the generic Value.Opcode() function so a specialized function needs to be added.
Repository:
rL LLVM
https://reviews.llvm.org/D53883
Files:
bindings/go/llvm/ir.go
Index: bindings/go/llvm/ir.go
===================================================================
--- bindings/go/llvm/ir.go
+++ bindings/go/llvm/ir.go
@@ -1259,6 +1259,19 @@
return
}
+// Operations on aggregates
+func (v Value) Indices() []uint32 {
+ num := C.LLVMGetNumIndices(v.C)
+ indicesPtr := C.LLVMGetIndices(v.C)
+ // https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices
+ rawIndices := (*[1 << 30]C.uint)(unsafe.Pointer(indicesPtr))[:num:num]
+ indices := make([]uint32, num)
+ for i := range indices {
+ indices[i] = uint32(rawIndices[i])
+ }
+ return indices
+}
+
//-------------------------------------------------------------------------
// llvm.Builder
//-------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53883.171766.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181030/501347a1/attachment.bin>
More information about the llvm-commits
mailing list