[PATCH] [llvm-c] Add LLVMPrintModule.

Anders Waldenborg anders at 0x63.nu
Tue Oct 15 12:56:31 PDT 2013


Hi hans,

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

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

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

Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -532,6 +532,14 @@
 void LLVMDumpModule(LLVMModuleRef M);
 
 /**
+ * Return a string representation of the module. Use
+ * LLVMDisposeMessage to free it.
+ *
+ * @see Module::print()
+ */
+char *LLVMPrintModule(LLVMModuleRef M);
+
+/**
  * Print a representation of a module to a file. The ErrorMessage needs to be
  * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
  *
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -147,6 +147,17 @@
   return false;
 }
 
+char *LLVMPrintModule(LLVMModuleRef M) {
+  Module *p = unwrap(M);
+
+  std::string buf;
+  raw_string_ostream os(buf);
+
+  p->print(os, NULL);
+
+  return strdup(buf.c_str());
+}
+
 /*--.. Operations on inline assembler ......................................--*/
 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
   unwrap(M)->setModuleInlineAsm(StringRef(Asm));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1941.1.patch
Type: text/x-patch
Size: 1098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/be731835/attachment.bin>


More information about the llvm-commits mailing list