From 18b9105d02ee152e7f8faab751d6f356428c3054 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Tue, 22 Oct 2013 06:58:34 +0000 Subject: [PATCH] llvm-c: Add LLVMPrintTypeToString Differential Revision: http://llvm-reviews.chandlerc.com/D1963 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193149 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/Core.h | 8 ++++++++ lib/IR/Core.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index f9717cc5f55..a48ea7e7457 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -722,6 +722,14 @@ LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); */ void LLVMDumpType(LLVMTypeRef Val); +/** + * Return a string representation of the type. Use + * LLVMDisposeMessage to free the string. + * + * @see llvm::Type::print() + */ +char *LLVMPrintTypeToString(LLVMTypeRef Val); + /** * @defgroup LLVMCCoreTypeInt Integer Types * diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 7d52386b061..16af7332d3c 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -224,6 +224,16 @@ void LLVMDumpType(LLVMTypeRef Ty) { return unwrap(Ty)->dump(); } +char *LLVMPrintTypeToString(LLVMTypeRef Ty) { + std::string buf; + raw_string_ostream os(buf); + + unwrap(Ty)->print(os); + os.flush(); + + return strdup(buf.c_str()); +} + /*--.. Operations on integer types .........................................--*/ LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {