[llvm-c] Implement LLVMPrintValueToString
authorPeter Zotov <whitequark@whitequark.org>
Wed, 6 Nov 2013 09:21:01 +0000 (09:21 +0000)
committerPeter Zotov <whitequark@whitequark.org>
Wed, 6 Nov 2013 09:21:01 +0000 (09:21 +0000)
Original patch by Chris Wailes

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194135 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/Core.h
lib/IR/Core.cpp

index 89ddf418b2f4328de18891dd1f4512c4494b9b90..30b1d829d25da77f4c86ce54be2aeedd35d443b6 100644 (file)
@@ -1211,6 +1211,14 @@ void LLVMSetValueName(LLVMValueRef Val, const char *Name);
  */
 void LLVMDumpValue(LLVMValueRef Val);
 
  */
 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.
  *
 /**
  * Replace all uses of a value with another one.
  *
index 40db69b3700f8fbe1495cfecdec0bd9c954306c7..63cc2f6f06a12ca588375aaa4485890b06035dd1 100644 (file)
@@ -474,6 +474,16 @@ void LLVMDumpValue(LLVMValueRef Val) {
   unwrap(Val)->dump();
 }
 
   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));
 }
 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
   unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
 }