diff options
-rw-r--r-- | include/llvm-c/Core.h | 8 | ||||
-rw-r--r-- | lib/IR/Core.cpp | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 57834c5292..caadab1bac 100644 --- a/include/llvm-c/Core.h +++ b/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/lib/IR/Core.cpp b/lib/IR/Core.cpp index 95c516a251..cf1c1df0ed 100644 --- a/lib/IR/Core.cpp +++ b/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)); |