[llvm] r192821 - [llvm-c] Add LLVMPrintModuleToString.

Anders Waldenborg anders at 0x63.nu
Wed Oct 16 11:00:54 PDT 2013


Author: andersg
Date: Wed Oct 16 13:00:54 2013
New Revision: 192821

URL: http://llvm.org/viewvc/llvm-project?rev=192821&view=rev
Log:
[llvm-c] Add LLVMPrintModuleToString.

Like LLVMDumpModule but returns the string (that needs to be freed
with LLVMDisposeMessage) instead of printing it to stderr.

Differential Revision: http://llvm-reviews.chandlerc.com/D1941


Modified:
    llvm/trunk/include/llvm-c/Core.h
    llvm/trunk/lib/IR/Core.cpp

Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=192821&r1=192820&r2=192821&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Wed Oct 16 13:00:54 2013
@@ -541,6 +541,14 @@ LLVMBool LLVMPrintModuleToFile(LLVMModul
                                char **ErrorMessage);
 
 /**
+ * Return a string representation of the module. Use
+ * LLVMDisposeMessage to free the string.
+ *
+ * @see Module::print()
+ */
+char *LLVMPrintModuleToString(LLVMModuleRef M);
+
+/**
  * Set inline assembly for a module.
  *
  * @see Module::setModuleInlineAsm()

Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=192821&r1=192820&r2=192821&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Wed Oct 16 13:00:54 2013
@@ -147,6 +147,16 @@ LLVMBool LLVMPrintModuleToFile(LLVMModul
   return false;
 }
 
+char *LLVMPrintModuleToString(LLVMModuleRef M) {
+  std::string buf;
+  raw_string_ostream os(buf);
+
+  unwrap(M)->print(os, NULL);
+  os.flush();
+
+  return strdup(buf.c_str());
+}
+
 /*--.. Operations on inline assembler ......................................--*/
 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
   unwrap(M)->setModuleInlineAsm(StringRef(Asm));





More information about the llvm-commits mailing list