[llvm] r346388 - [bindings/go] Add Go bindings to LLVMGetIndices
whitequark via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 7 20:04:04 PST 2018
Author: whitequark
Date: Wed Nov 7 20:04:04 2018
New Revision: 346388
URL: http://llvm.org/viewvc/llvm-project?rev=346388&view=rev
Log:
[bindings/go] Add Go bindings to LLVMGetIndices
Summary: This instruction is useful for inspecting extractvalue/insertvalue in IR. Unlike most other operations, indices cannot be inspected using the generic Value.Opcode() function so a specialized function needs to be added.
Reviewers: whitequark, pcc
Reviewed By: whitequark
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53883
Modified:
llvm/trunk/bindings/go/llvm/ir.go
Modified: llvm/trunk/bindings/go/llvm/ir.go
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/go/llvm/ir.go?rev=346388&r1=346387&r2=346388&view=diff
==============================================================================
--- llvm/trunk/bindings/go/llvm/ir.go (original)
+++ llvm/trunk/bindings/go/llvm/ir.go Wed Nov 7 20:04:04 2018
@@ -1258,6 +1258,19 @@ func InlineAsm(t Type, asmString, constr
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
//-------------------------------------------------------------------------
More information about the llvm-commits
mailing list