Skip to content

Commit 32ed56c

Browse files
committed
Add Value.String()
This should usually be used instead of Value.Dump() which always writes to stdout (or stderr?).
1 parent 7733695 commit 32ed56c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ir.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,14 @@ func (v Value) SetMetadata(kind int, node Metadata) {
705705
C.LLVMSetMetadata2(v.C, C.unsigned(kind), node.C)
706706
}
707707

708+
// Obtain the string value of the instruction. Same as would be printed with
709+
// Value.Dump() (with two spaces at the start but no newline at the end).
710+
func (v Value) String() string {
711+
cstr := C.LLVMPrintValueToString(v.C)
712+
defer C.LLVMDisposeMessage(cstr)
713+
return C.GoString(cstr)
714+
}
715+
708716
// Conversion functions.
709717
// Return the input value if it is an instance of the specified class, otherwise NULL.
710718
// See llvm::dyn_cast_or_null<>.

0 commit comments

Comments
 (0)