From cd93b370d5978a37c0eda541b3d594f16c7a28b4 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Wed, 6 Nov 2013 09:21:01 +0000 Subject: [PATCH] [llvm-c] Implement LLVMPrintValueToString Original patch by Chris Wailes llvm-svn: 194135 --- llvm/include/llvm-c/Core.h | 8 ++++++++ llvm/lib/IR/Core.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 89ddf418b2f4..30b1d829d25d 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -1211,6 +1211,14 @@ void LLVMSetValueName(LLVMValueRef Val, const char *Name); */ void LLVMDumpValue(LLVMValueRef Val); +/** + * Return a string representation of the value. Use + * LLVMDisposeMessage to free the string. + * + * @see llvm::Value::print() + */ +char *LLVMPrintValueToString(LLVMValueRef Val); + /** * Replace all uses of a value with another one. * diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 40db69b3700f..63cc2f6f06a1 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -474,6 +474,16 @@ void LLVMDumpValue(LLVMValueRef Val) { unwrap(Val)->dump(); } +char* LLVMPrintValueToString(LLVMValueRef Val) { + std::string buf; + raw_string_ostream os(buf); + + unwrap(Val)->print(os); + os.flush(); + + return strdup(buf.c_str()); +} + void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) { unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal)); }