From 2906b519d1f47f1b269ed1be9c70f752b3dca928 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Wed, 16 Oct 2013 18:00:54 +0000 Subject: [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192821 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Core.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 95c516a..cf1c1df 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)); -- cgit v1.1