[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
whitequark 2018-11-08 04:04:04 +00:00
parent 9ac4c44c94
commit 2c000da033

View File

@ -1258,6 +1258,19 @@ func InlineAsm(t Type, asmString, constraints string, hasSideEffects, isAlignSta
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
//-------------------------------------------------------------------------