summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Waldenborg <anders@0x63.nu>2013-10-16 18:00:54 +0000
committerAnders Waldenborg <anders@0x63.nu>2013-10-16 18:00:54 +0000
commit84355db7f9dc50cec5de4127d03fc40a84772f78 (patch)
tree723b9d895aeb7b36b39d26cf3c2e985a66865bd5
parenta66582470b19616f9eba40efef020f4ad7bde11a (diff)
downloadbcm5719-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.h8
-rw-r--r--llvm/lib/IR/Core.cpp10
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));
OpenPOWER on IntegriCloud