Skip to content

Commit

Permalink
Add Value.String()
Browse files Browse the repository at this point in the history
This should usually be used instead of Value.Dump() which always writes
to stdout (or stderr?).
  • Loading branch information
aykevl committed Sep 20, 2023
1 parent 7733695 commit 32ed56c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ func (v Value) SetMetadata(kind int, node Metadata) {
C.LLVMSetMetadata2(v.C, C.unsigned(kind), node.C)
}

// Obtain the string value of the instruction. Same as would be printed with
// Value.Dump() (with two spaces at the start but no newline at the end).
func (v Value) String() string {
cstr := C.LLVMPrintValueToString(v.C)
defer C.LLVMDisposeMessage(cstr)
return C.GoString(cstr)
}

// Conversion functions.
// Return the input value if it is an instance of the specified class, otherwise NULL.
// See llvm::dyn_cast_or_null<>.
Expand Down

0 comments on commit 32ed56c

Please sign in to comment.