[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
This commit is contained in:
Anders Waldenborg 2013-10-16 18:00:54 +00:00
parent fc1604ec72
commit 2906b519d1
2 changed files with 18 additions and 0 deletions

View File

@ -540,6 +540,14 @@ void LLVMDumpModule(LLVMModuleRef M);
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.
*

View File

@ -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));