[PATCH] [llvm-c] Add LLVMPrintModuleToString

Anders Waldenborg anders at 0x63.nu
Wed Oct 16 00:24:48 PDT 2013


  Updated according to comments. Went for LLVMPrintModuleToString as name as it matches LLVMPrintModuleToFile

Hi hans,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1941?vs=4927&id=4945#toc

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
@@ -541,6 +541,14 @@
                                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()
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -147,6 +147,15 @@
   return false;
 }
 
+char *LLVMPrintModuleToString(LLVMModuleRef M) {
+  std::string buf;
+  raw_string_ostream os(buf);
+
+  unwrap(M)->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.2.patch
Type: text/x-patch
Size: 1041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131016/6c88fc8f/attachment.bin>


More information about the llvm-commits mailing list