diff options
author | Anders Waldenborg <anders@0x63.nu> | 2013-10-16 18:00:54 +0000 |
---|---|---|
committer | Anders Waldenborg <anders@0x63.nu> | 2013-10-16 18:00:54 +0000 |
commit | 84355db7f9dc50cec5de4127d03fc40a84772f78 (patch) | |
tree | 723b9d895aeb7b36b39d26cf3c2e985a66865bd5 | |
parent | a66582470b19616f9eba40efef020f4ad7bde11a (diff) | |
download | bcm5719-llvm-84355db7f9dc50cec5de4127d03fc40a84772f78.tar.gz bcm5719-llvm-84355db7f9dc50cec5de4127d03fc40a84772f78.zip |
[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
llvm-svn: 192821
-rw-r--r-- | llvm/include/llvm-c/Core.h | 8 | ||||
-rw-r--r-- | llvm/lib/IR/Core.cpp | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 57834c52928..caadab1bac2 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -541,6 +541,14 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, 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() diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 95c516a2511..cf1c1df0ed6 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -147,6 +147,16 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, 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)); |